# Testing parallelization with MPI and Test

**URL:** <https://discourse.julialang.org/t/testing-parallelization-with-mpi-and-test/114040>\
**Category:** General Usage\
**Tags:** testing, parallel, mpi\
**Created:** [May 9, 2024, 8:01am UTC](https://discourse.julialang.org/t/testing-parallelization-with-mpi-and-test/114040 "2024-05-09T08:01:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mesonepigreco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mesonepigreco/32/46262_2.png) [@mesonepigreco](https://discourse.julialang.org/u/mesonepigreco)\
**Post date:** [May 9, 2024, 8:01am UTC](https://discourse.julialang.org/t/testing-parallelization-with-mpi-and-test/114040/1 "2024-05-09T08:01:58Z")

</div>

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:

```julia
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?

---

<div class="post-metadata">

**Author:** ![jsjie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsjie/32/22477_2.png) [@jsjie](https://discourse.julialang.org/u/jsjie)\
**Post date:** [September 23, 2024, 1:14am UTC](https://discourse.julialang.org/t/testing-parallelization-with-mpi-and-test/114040/2 "2024-09-23T01:14:34Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [September 23, 2024, 4:40am UTC](https://discourse.julialang.org/t/testing-parallelization-with-mpi-and-test/114040/3 "2024-09-23T04:40:06Z")

</div>

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