Skip to content

Set number of OpenMP threads to something reasonable in tests#740

Open
mmuetzel wants to merge 2 commits intoElmerCSC:develfrom
mmuetzel:ctest
Open

Set number of OpenMP threads to something reasonable in tests#740
mmuetzel wants to merge 2 commits intoElmerCSC:develfrom
mmuetzel:ctest

Conversation

@mmuetzel
Copy link
Contributor

@mmuetzel mmuetzel commented Dec 29, 2025

Determine the number of physical processors of the build host and limit the number of OpenMP threads to that for each test.
If a test is involving multiple MPI processes, divide the number of physical processors by the number of used MPI processes. Set the number of OpenMP threads to the integer floor of that result.

If a user sets OMP_NUM_THREADS explicitly in the environment that takes precedence over the automatic selection.

With that, remove explicitly setting OMP_NUM_THREADS in the build rules for Windows MinGW.

That is essentially what @juharu suggested in #725 (comment).

@mmuetzel
Copy link
Contributor Author

mmuetzel commented Dec 29, 2025

I don't know why the test TopoOptHeat2DCompMin is failing for some runners.
Re-running the tests didn't make a difference. So, the error is likely deterministic.

The failing Ubuntu runner has the following in its stderr:

 Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x7fe28be23e59 in ??? #1 0x7fe28be22e75 in ??? #2 0x7fe28ba4532f in ??? #3 0x7fe28c94d5d0 in __matrixassembly_MOD_uselocalmatrixstorage #4 0x7fe28c7abc05 in __defutils_MOD_defaultupdateequationsr #5 0x7fe28bc278fd in localmatrix.8.isra.0 #6 0x7fe28bc2ab51 in heatsolver_._omp_fn.0 #7 0x7fe28bc8d79e in ??? #8 0x7fe28ba9caa3 in ??? #9 0x7fe28bb29c6b in ??? #10 0xffffffffffffffff in ??? 

I don't know if that helps.

@mmuetzel
Copy link
Contributor Author

Fwiw, the number of physical processors of the GitHub-hosted Ubuntu runners is 2. I.e., OMP_NUM_THREADS is set to 2 (for tests that don't involve multiple MPI processes like the failing one).

Determine the number of physical processors of the build host and limit the number of OpenMP threads to that for each test. If a test is involving multiple MPI processes, divide the number of physical processors by the number of used MPI processes. Set the number of OpenMP threads to the integer floor of that result. If a user sets `OMP_NUM_THREADS` explicitly in the environment, that takes precedence over the automatic selection.
The tests are limiting the number of OpenMP threads by themselves.
@mmuetzel
Copy link
Contributor Author

The number of failing tests when running with more than one OpenMP thread seems to have increased to 3 since the last time this was run in CI:

The following tests FAILED:	612 - TopoOptHeat2DCompMin (Failed) quick serial	733 - mgdyn2D_bh_relfun (Failed) serial	742 - mgdyn2D_scan_homogenization_elementary_solutions (Failed) 2D harmonic mgdyn scanning serial 
@juharu
Copy link
Contributor

juharu commented Jan 28, 2026 via email

@mmuetzel
Copy link
Contributor Author

I agree with what @juhanikataja wrote in #761 (comment). It would be useful to run the tests with more than one OpenMP threads. Otherwise, potential issues with OpenMP won't be noticed by the CI tests.
There might still be other issues that aren't uncovered using the GitHub hosted runners (because they only provide two physical processor cores and some tests might only fail with more than 2 threads). But at least, it would increase the coverage in that respect.

@juharu
Copy link
Contributor

juharu commented Jan 28, 2026

TopoOptHeat2DCompMin

test fails because the solver "HeatSolverVec" activates threading if OMP_NUM_THREADS>1, but the code these keywords:

Local Matrix Identical = Logical True
Local Matrix Storage = Logical True

leads to is not ready for that....

@juhanikataja
Copy link
Contributor

juhanikataja commented Jan 29, 2026

I think threaded testing is successful if it revealed bugs in code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants