Test code with multi-threading

Hello,

I am writing a multi-threading of my code, but I would like to write unit tests to make sure I get the same results as in the serial case.

I am thinking of doing:

  1. execute export JULIA_NUM_THREADS=6 in the bash
  2. open julia and activate the environment of my package
  3. run the tests

Is it the way to do?

yes that should work,

also if you’re working with CI:

2 Likes

Yet another way:

PerformanceTestTools.@include_foreach(
    "tests_using_threads.jl",
    [nothing, ["JULIA_NUM_THREADS" => Threads.nthreads() > 1 ? "1" : "6"]],
)

ref Home · PerformanceTestTools.jl

4 Likes

Thank you for the references!