Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shell wrapper around
mpiexec
(#386)
* Add Julia wrapper around `mpiexec` * Simplify extraction of project flag Co-authored-by: Simon Byrne <simonbyrne@gmail.com> * Move mpiexecjl script to bin/ * Use `mpiexecjl` in documentation * Add tests for `mpiexecjl` * Run `mpiexecjl` test only on Unix systems * Fix error in `mpiexecjl` and improve test * Make `mpiexecjl` a POSIX shell script instead of a Julia one * Update bin/mpiexecjl [skip ci] Co-authored-by: Simon Byrne <simonbyrne@gmail.com> * Print usage with `-h` and `--help` and with no non-project argument * add shellcheck action * disable shellcheck on variable * Update bin/mpiexecjl Co-authored-by: Simon Byrne <simonbyrne@gmail.com> Co-authored-by: Simon Byrne <simonbyrne@gmail.com>
- Loading branch information
1 parent
b16fc92
commit c5ab8ac
Showing
9 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,18 @@ | ||
name: shellcheck | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
shellcheck: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install dependencies | ||
run: sudo apt install shellcheck | ||
- name: Check scripts | ||
run: shellcheck bin/* |
This file contains 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,64 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright (C) 2020 Simon Byrne, Mosè Giordano | ||
# License is MIT "Expat" | ||
# | ||
### Commentary: | ||
# | ||
# Command line utility to call the `mpiexec` binary used by the `MPI.jl` version | ||
# in the given Julia project. It has the same syntax as the `mpiexec` binary | ||
# that would be called, with the additional `--project=...` flag to select a | ||
# different Julia project. | ||
# | ||
# Examples of usage (the MPI flags available depend on the MPI implementation | ||
# called): | ||
# | ||
# $ mpiexecjl --version | ||
# $ mpiexecjl -n 40 julia mpi-script.jl | ||
# $ mpiexecjl --project=my_experiment -n 80 --oversubscribe julia mpi-script.jl | ||
# | ||
### Code: | ||
|
||
usage () { | ||
echo "Usage: ${0} [--project=...] MPIEXEC_ARGUMENTS..." | ||
echo "Call the mpiexec binary in the Julia environment specified by the --project option." | ||
echo "If no project is specified, the MPI associated with the global Julia environment will be used." | ||
echo "All other arguments are forwarded to mpiexec." | ||
} | ||
|
||
for arg; do | ||
shift | ||
case "${arg}" in | ||
--project | --project=*) | ||
PROJECT_ARG="${arg}" | ||
;; | ||
-h | --help) | ||
usage | ||
echo "Below is the help of the current mpiexec." | ||
echo | ||
set -- "${@}" "${arg}" | ||
;; | ||
*) | ||
set -- "${@}" "${arg}" | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z "${*}" ]; then | ||
echo "ERROR: no arguments specified." 1>&2 | ||
echo | ||
usage | ||
exit 1 | ||
fi | ||
|
||
# shellcheck disable=SC2016 | ||
SCRIPT=' | ||
using MPI | ||
ENV["JULIA_PROJECT"] = dirname(Base.active_project()) | ||
mpiexec(exe -> run(`$exe $ARGS`))' | ||
|
||
if [ -n "${PROJECT_ARG}" ]; then | ||
julia "${PROJECT_ARG}" --color=yes --startup-file=no -q --compile=min -O0 -e "${SCRIPT}" -- "${@}" | ||
else | ||
julia --color=yes --startup-file=no -q --compile=min -O0 -e "${SCRIPT}" -- "${@}" | ||
fi |
This file contains 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 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 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
```@docs | ||
mpiexec | ||
MPI.install_mpiexecjl | ||
``` | ||
|
||
## Enums | ||
|
This file contains 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 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,24 @@ | ||
""" | ||
MPI.install_mpiexecjl(; command::String = "mpiexecjl", | ||
destdir::String = joinpath(DEPOT_PATH[1], "bin"), | ||
force::Bool = false, verbose::Bool = true) | ||
Install the `mpiexec` wrapper to `destdir` directory, with filename `command`. | ||
Set `force` to `true` to overwrite an existing destination file with the same | ||
path. If `verbose` is `true`, the installation prints information about the | ||
progress of the process. | ||
""" | ||
function install_mpiexecjl(; command::String = "mpiexecjl", | ||
destdir::String = joinpath(DEPOT_PATH[1], "bin"), | ||
force::Bool = false, verbose::Bool = true) | ||
# Adapted from https://github.com/fredrikekre/jlpkg. | ||
destdir = abspath(expanduser(destdir)) | ||
exec = joinpath(destdir, command) | ||
if ispath(exec) && !force | ||
error("file `$(exec)` already exists; use `MPI.install_mpiexecjl(force=true)` to overwrite.") | ||
end | ||
mkpath(destdir) | ||
verbose && @info "Installing `$(command)` to `$(destdir)`..." | ||
cp(joinpath(@__DIR__, "..", "bin", "mpiexecjl"), exec; force = force) | ||
verbose && @info "Done!" | ||
end |
This file contains 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,26 @@ | ||
using Test, Pkg | ||
using MPI | ||
|
||
@testset "mpiexecjl" begin | ||
mktempdir() do dir | ||
# Install MPI locally, so that we can test the `--project` flag to | ||
# `mpiexecjl` | ||
Pkg.activate(dir) | ||
Pkg.add("MPI") | ||
# Test installation | ||
@test_logs (:info, r"Installing") (:info, r"Done") MPI.install_mpiexecjl(; destdir = dir) | ||
# Test a run of mpiexec | ||
mpiexecjl = joinpath(dir, "mpiexecjl") | ||
julia = joinpath(Sys.BINDIR, Base.julia_exename()) | ||
example = joinpath(@__DIR__, "..", "docs", "examples", "01-hello.jl") | ||
@test success(`$(mpiexecjl) --project=$(dir) $(julia) --startup-file=no -q $(example)`) | ||
# Test help messages | ||
for help_flag in ("-h", "--help") | ||
help_message = read(`$(mpiexecjl) --project=$(dir) --help`, String) | ||
@test occursin(r"Usage:.*MPIEXEC_ARGUMENTS", help_message) | ||
end | ||
# Without arguments, or only with the `--project` option, the wrapper will fail | ||
@test !success(`$(mpiexecjl) --project=$(dir)`) | ||
@test !success(`$(mpiexecjl)`) | ||
end | ||
end |
This file contains 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