Testing parallelization with MPI and Test

Hello everyone,
I am developing a package that implements multiprocessing with MPI.jl for applications in HPC facilities.
I have a full test suite for my package, which can be run with the usual “]” test from the REPL once the environment is activated.

However, I would like to test the parallel implementation, as it has already happened many times that some small mistake broke only the parallelization (if the code is run on 1 core, it works as expected).

Therefore, I would like to introduce a testing function as the following:

using Test
function test_mpi()
    result_2 = execute a function with 2 processors
    result_1 = execute a function with 1 processor on MPI
    @test result_1 ≈ result_2
end 

Is it possible to invoke only this test with MPI without running the whole test suite on 2 processors?

1 Like

I’ve once used the run technique, which roughly like this:

mpiexec() do cmd
    runcmd = `$cmd -n 4 xxx`
    ps = run(runcmd; wait=true)
end

However, it has been long since I last use it, not sure whether it still works now.
Besides, it is far from satisfactory, because I want to compile my package using PackageCompiler.jl, but in this way, the functions are compiled in new processes, so the result binary will still have no compiled code for these functions. I end up manually adding all related functions with the precompile function, which is painful and tedious.

I recommend you take a look at how MPI.jl runs MPI tests. Or ThreadPinning.jl or other packages supporting MPI.

1 Like