Explicitly specify build and test jobs parallelism count#1959
Conversation
ISSOtm
left a comment
There was a problem hiding this comment.
Soon we'll be free from the shackles of these tiny incremental improvements. 🫂
|
[EDIT] The OP that this responds to has been edited.
Or you can use the
Well, this adds extra CLI parsing complexity to that script, and at this point I suggested in my review that
Actually,
As mentioned above, let's use |
| # Approximate number of CPU cores in GitHub's runners as of 2026-03-18: | ||
| # https://docs.github.com/en/actions/reference/runners/github-hosted-runners#standard-github-hosted-runners-for-public-repositories | ||
| CTEST_PARALLEL_LEVEL: 0 # `ctest` now implies `--parallel 0` (number of logical CPUs). | ||
| CTEST_PARALLEL_LEVEL: 4 # `ctest` now implies `--parallel 4`. |
There was a problem hiding this comment.
--parallel 0 was not the "number of logical CPUs", it's "unbounded", same as make -j.
https://cmake.org/cmake/help/latest/manual/ctest.1.html#cmdoption-ctest-j:
Otherwise, if the value is omitted, parallelism is limited by the number of processors, or 2, whichever is larger.
Otherwise, if the value is 0, parallelism is unbounded.
There was a problem hiding this comment.
Annoying how this is inconsistent with other instances of -j 0 or -j. Thanks for noticing.
There was a problem hiding this comment.
Aaah, wait, the behaviour is different for the environment variable!
Changed in version 3.29: The value may be empty, or
0, to let ctest use a default level of parallelism, or unbounded parallelism, respectively, as documented by thectest --paralleloption.CTest will interpret a whitespace-only string as empty.
In CMake 3.28 and earlier, an empty or
0value was equivalent to1.
There was a problem hiding this comment.
| CTEST_PARALLEL_LEVEL: 4 # `ctest` now implies `--parallel 4`. | |
| CTEST_PARALLEL_LEVEL: '' # `ctest` now implies `--parallel` (number of logical CPUs). |
There was a problem hiding this comment.
A blank CTEST_PARALLEL_LEVEL value wouldn't be reusable for passing to the individual third-party repos as make -j$ENV{CTEST_PARALLEL_LEVEL}. If you'd still prefer this to be empty as the number of logical CPUs, do you have any suggestion for what to do about that? (Also, should CMAKE_BUILD_PARALLEL_LEVEL and CMAKE_INSTALL_PARALLEL_LEVEL be set to '' instead of 4 in create-release-artifacts.yml?)
There was a problem hiding this comment.
The $ENV concern is obsoleted by #1959 (comment). As for those other two variables, they have different behaviour... BUILD_ uses the native tool's default (number of CPUs for Ninja, but 1 for Make); INSTALL_... doesn't specify, but I expect that it would reject 0 like BUILD_ does (I just tested that).
Note also that since we aren't enabling the INSTALL_PARALLEL global property, the latter actually turns out to do nothing lol
| COMMAND bash -- run-tests.sh --jobs $ENV{CTEST_PARALLEL_LEVEL} --only-external ${ONLY_FREE} ${OS_NAME} | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| set_tests_properties(external PROPERTIES DEPENDS "rgbasm;rgblink;rgbfix;rgbgfx" # Only attempt building whole projects if each tool passes muster on its own. | ||
| PROCESSORS 4 | ||
| PROCESSORS $ENV{CTEST_PARALLEL_LEVEL} |
There was a problem hiding this comment.
We cannot rely on this environment variable, as the parallelism may be specified via the CLI only, and this would plainly error out without the env var. We don't have access to that parameter at configure time, anyway, and the env var could also be set only when running ctest itself.
We could try querying the number of logical CPUs (cmake_host_system_information(RESULT n QUERY NUMBER_OF_LOGICAL_CORES) according to CMake's docs) and using that, but I don't know how that would interact with ctest -j 1.
There was a problem hiding this comment.
Presumably the worst that could happen is the config-time NUMBER_OF_LOGICAL_CORES value being used instead of the run-time -j value... but that's still better than what we have now, using PROCESSORS 4 no matter what -j is.
Fixes #1944
This PR uses
getconf _NPROCESSORS_ONLNto set the job counts becausenprocis not available on macOS.