CMake (via CTest) can run tests in parallel. Some tests need to be run not in parallel, for example tests using MPI that use lots of CPU cores, or tests that use a lot of RAM, or tests that must access a common file or hardware device. We have found that using the RUN_SERIAL makes whole groups of tests run sequentially instead of individually running sequentially when fixtures are used. That is, all the FIXTURES_SETUP run, then all FIXTURES_REQUIRED that have RUN_SERIAL. This is not necessarily desired, because we had consuming fixtures that didn’t have to wait for all the fixtures to be setup.
We found that using RESOURCE_LOCK did not suffer from this issue, and allows the proper test dependencies and the expected parallelism.
CMake Resource Groups are orthogonal to Resource Locks, and are much more complicated to use. There may be some systems that would benefit from Groups, but many can just use the simple Locks.
For simplicity, this example omits the necessary
add_test() and just show the properties.
The test has an MPI-using quick setup “Quick1” and then a long test “Long1” also using MPI. Finally, we have a quick Python script “Script1” checking the output.
In the real setup, we have Quick1, Quick2, … QuickN and so on. When we used RUN_SERIAL, we had to wait for ALL Quick* before Long* would start. With RESOURCE_LOCK the tests intermingle, making better use of CPU particularly on large CPU count systems, and with lots of tests.
The name “cpu_mpi” is arbitrary like the other names.
set_property(TEST Quick1 PROPERTY RESOURCE_LOCK cpu_mpi) set_property(TEST Quick1 PROPERTY FIXTURES_SETUP Q1) set_property(TEST Long1 PROPERTY RESOURCE_LOCK cpu_mpi) set_property(TEST Long1 PROPERTY FIXTURES_REQUIRED Q1) set_property(TEST Long1 PROPERTY FIXTURES_SETUP L1) set_property(TEST Script1 PROPERTY FIXTURES_REQUIRED L1)