-
Notifications
You must be signed in to change notification settings - Fork 5
Improved OnLocalhost
#25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e03073
renamed OnLocalhost --> LocalRun + allow julia flags and dir for Loca…
theHenks 6513b2c
Update tests
theHenks afbc8d4
Renamed all *Run DynamicProcsMode to On* modes
theHenks 7a9f063
Fix dir command on windows
theHenks 4168800
Add comment
theHenks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# This file is a part of ParallelProcessingTools.jl, licensed under the MIT License (MIT). | ||
|
||
""" | ||
OnLocalhost(; | ||
n::Integer = 1 | ||
env::Dict{String,String} = Dict{String,String}() | ||
julia_flags::Cmd = _default_julia_flags() | ||
dir = pwd() | ||
) isa DynamicAddProcsMode | ||
|
||
Mode that runs `n` worker processes on the current host. | ||
|
||
Example: | ||
|
||
```julia | ||
runmode = OnLocalhost(n = 4) | ||
task, n = runworkers(runmode) | ||
|
||
Threads.@async begin | ||
wait(task) | ||
@info "SLURM workers have terminated." | ||
end | ||
|
||
@wait_while nprocs()-1 < n) | ||
``` | ||
|
||
Workers can also be started manually, use | ||
[`worker_start_command(runmode)`](@ref) to get the system (shell) command and | ||
run it from a separate process or so. | ||
""" | ||
@with_kw struct OnLocalhost <: DynamicAddProcsMode | ||
n::Int | ||
julia_flags::Cmd = _default_julia_flags() | ||
dir = pwd() | ||
env::Dict{String,String} = Dict{String,String}() | ||
end | ||
export OnLocalhost | ||
|
||
function worker_start_command(runmode::OnLocalhost, manager::ElasticManager) | ||
julia_flags = runmode.julia_flags | ||
dir = replace(runmode.dir, '\\' => '/') | ||
|
||
jl_threads_flag = any(occursin.(Ref("--threads"), string.(julia_flags))) ? `` : `--threads=$(nthreads())` | ||
jl_dir_flags = `-e "cd(\"$(dir)\")"` | ||
additional_julia_flags = `$jl_threads_flag $julia_flags $jl_dir_flags` | ||
|
||
worker_cmd = worker_local_startcmd( | ||
manager; | ||
julia_flags = additional_julia_flags, | ||
env = runmode.env | ||
) | ||
return worker_cmd, runmode.n, runmode.n | ||
end | ||
|
||
function runworkers(runmode::OnLocalhost, manager::ElasticManager) | ||
start_cmd, m, n = worker_start_command(runmode, manager) | ||
|
||
task = Threads.@async begin | ||
processes = Base.Process[] | ||
for _ in 1:m | ||
push!(processes, open(start_cmd)) | ||
end | ||
@wait_while any(isactive, processes) | ||
end | ||
|
||
return task, n | ||
end | ||
|
||
|
||
#= | ||
# ToDo: Add SSHWorkers or similar: | ||
|
||
@with_kw struct SSHWorkers <: RunProcsMode | ||
hosts::Vector{Any} | ||
ssd_flags::Cmd = _default_slurm_flags() | ||
julia_flags::Cmd = _default_julia_flags() | ||
dir = ... | ||
env = ... | ||
tunnel::Bool = false | ||
multiplex::Bool = false | ||
shell::Symbol = :posix | ||
max_parallel::Int = 10 | ||
enable_threaded_blas::Bool = true | ||
topology::Symbol = :all_to_all | ||
lazy_connections::Bool = true | ||
end | ||
=# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.