Skip to content

Adding sysimage generation to mpi tests #48

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 15 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ jobs:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/julia-buildpkg@v1
- run: julia --project=. --color=yes --check-bounds=yes test/mpi/runtests.jl
- run: cd test/mpi/compile; ./compile.sh PoissonTests.jl
- run: julia --project=. --color=yes --check-bounds=yes test/mpi/runtests.jl test/mpi/compile/GridapDistributedMPIBackend.so
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand Down
62 changes: 62 additions & 0 deletions test/mpi/compile/compile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Pkg
Pkg.add("PackageCompiler")
using PackageCompiler

@assert length(ARGS)==1
test_script=ARGS[1]
@assert isfile("../../"*test_script)
modulename=split(test_script,".")[1]

function generate_precompile_execution_file(modulename)
source_code="""
module sysimagegenerator

using PartitionedArrays
const PArrays = PartitionedArrays
using MPI

if ! MPI.Initialized()
MPI.Init()
end

include(\"../../$(modulename).jl\")

@assert MPI.Comm_size(MPI.COMM_WORLD) == 1
parts = get_part_ids(mpi,(1,1))

display(parts)

t = PArrays.PTimer(parts,verbose=true)
PArrays.tic!(t)

eval(Meta.parse(\"$(modulename).main(parts)\"))
PArrays.toc!(t,\"$(modulename)\")
display(t)

MPI.Finalize()

end #module
"""
open("sysimagegenerator.jl","w") do io
println(io,source_code)
end
end

@assert length(ARGS)==1
test_script=ARGS[1]
@assert isfile("../../"*test_script)
modulename=split(test_script,".")[1]
generate_precompile_execution_file(modulename)

pkgs = Symbol[]
push!(pkgs, :GridapDistributed)

if VERSION >= v"1.4"
append!(pkgs, [Symbol(v.name) for v in values(Pkg.dependencies()) if v.is_direct_dep],)
else
append!(pkgs, [Symbol(name) for name in keys(Pkg.installed())])
end

create_sysimage(pkgs,
sysimage_path=joinpath(@__DIR__,"GridapDistributedMPIBackend.so"),
precompile_execution_file=joinpath(@__DIR__,"sysimagegenerator.jl"))
21 changes: 21 additions & 0 deletions test/mpi/compile/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
test_paths=$(ls ../../*Tests.jl)
test_names=""
for i in $test_paths
do
name=$(basename $i)
test_names="$test_names $name"
done
echo "Illegal number of parameters"
echo "Usage: $0 TESTNAME.jl, where TESTNAME.jl=$test_names"
exit 1
fi

# This script is to be executed from this folder (compile/)
julia --project=../../.. --color=yes -e 'using Pkg; Pkg.instantiate()'
# See https://juliaparallel.github.io/MPI.jl/latest/knownissues/#Julia-module-precompilation-1
# for a justification of this line
julia --project=../../.. --color=yes -e 'using Pkg; pkg"precompile"'
julia --project=../../.. -O3 --check-bounds=no --color=yes compile.jl $1
21 changes: 16 additions & 5 deletions test/mpi/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@ module MPITests
using MPI
using Test

#Sysimage
sysimage=nothing
if length(ARGS)==1
@assert isfile(ARGS[1]) "$(ARGS[1]) must be a valid Julia sysimage file"
sysimage=ARGS[1]
end

mpidir = @__DIR__
testdir = joinpath(mpidir,"..")
repodir = joinpath(testdir,"..")

function run_driver(procs,file)
function run_driver(procs,file,sysimage)
mpiexec() do cmd
run(`$cmd -n $procs $(Base.julia_cmd()) --project=$repodir $(joinpath(mpidir,file))`)
if sysimage!=nothing
extra_args="-J$(sysimage)"
run(`$cmd -n $procs $(Base.julia_cmd()) $(extra_args) --project=$repodir $(joinpath(mpidir,file))`)
else
run(`$cmd -n $procs $(Base.julia_cmd()) --project=$repodir $(joinpath(mpidir,file))`)
end
@test true
end
end

run_driver(4,"runtests_np4.jl")
run_driver(1,"runtests_np4.jl") # Check that the degenerated case works
run_driver(4,"runtests_np4.jl",sysimage)
run_driver(1,"runtests_np4.jl",sysimage) # Check that the degenerated case works


end # module