-
Notifications
You must be signed in to change notification settings - Fork 9
/
ChildProcess.jl
81 lines (69 loc) · 2.14 KB
/
ChildProcess.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Flag to run to a new julia
process. Useful e.g. to dynamically control
the number of threads to use or to use MPI on a
single machine.
Fields:
$FIELDS
"""
@kwdef struct ChildProcess <: Submission
"""
The number of threads to provide in the
child julia process, the same as the current
process by default.
"""
n_threads::Int = Threads.nthreads()
"""
Julia modules (if of type `Module`) or paths to include
(if of type `String`) needed by the child
process.
"""
dependencies::Vector = []
"""
If greater than one, run the code locally
over MPI using that many MPI processes.
In most cases, this is useful only for debugging purpose,
as multi-threading should typically perform
better. This could also potentially be useful if using a
third-party target distribution which somehow
does not support multi-threading.
"""
n_local_mpi_processes::Int = 1
"""
If wait is false, the process runs asynchronously.
When wait is false, the process' I/O streams are directed to devnull.
"""
wait::Bool = true
"""
Extra arguments passed to mpiexec.
"""
mpiexec_args::Cmd = ``
end
"""
$SIGNATURES
Run Parallel Tempering in a new process.
See [`ChildProcess`](@ref).
"""
function pigeons(pt_arguments, new_process::ChildProcess)
exec_folder = next_exec_folder()
julia_cmd = launch_cmd(
pt_arguments,
exec_folder,
new_process.dependencies,
new_process.n_threads,
new_process.n_local_mpi_processes > 1
)
if new_process.n_local_mpi_processes == 1
# # workaround used to investigate Documenter.jl bugs
# # (Documenter.jl gobbles the stdout/stderr)
# c2 = Cmd(julia_cmd; ignorestatus = true)
# oc = OutputCollector(c2; verbose = false)
# write("output.txt", merge(oc))
run(julia_cmd, wait = new_process.wait)
else
mpi_cmd = `$(mpiexec()) $(new_process.mpiexec_args) -n $(new_process.n_local_mpi_processes)`
cmd = `$mpi_cmd $julia_cmd`
run(cmd, wait = new_process.wait)
end
return Result{PT}(exec_folder)
end