Conversation
…value of `max_cores` - the allocated number of CPU cores can never be greater than the value of `max_cores`
b2f355a to
e532ce2
Compare
| # An additional environment variable (local to this specific run) | ||
| # must also be set to avoid allocating all the available CPU cores. | ||
| # Thus, allocated CPU cores = max number of CPU cores used | ||
| khiops_env["KHIOPS_PROC_NUMBER"] = system_settings.max_cores |
There was a problem hiding this comment.
This is too late: KHIOPS_PROC_NUMBER needs to be set in a specific environment in which khiops_env --env is launched, because it is therein that KHIOPS_MPI_COMMAND is computed with respect to KHIOPS_PROC_NUMBER (basically, -n $KHIOPS_PROC_NUMBER is added to mpiexec). Otherwise, khiops_process_args still contains the mpiexec command without the -n option set according to KHIOPS_PROC_NUMBER: indeed, the MPI command is given by KhiopsLocalRunner._mpi_command_args, which is computed when khiops_env is read.
Hence, IMHO the way forward is to build and propagate a custom environment (a copy of os.environ, with a KHIOPS_PROC_NUMBER set according to max_cores) to the khiops_env --env subprocess. To this end, I would create a new KhiopsLocalRunner instance and set via set_runner, within the _run_task method. For this to work on custom environments, IMHO we need to add an environment parameter to KhiopsLocalRunner (cf. the changes in https://github.com/KhiopsML/khiops-python/pull/624/changes#diff-d3a8e2b402a205257210c09d4cdb06e74ddc307bb2b5b9079467a9c79934bce2).
| if initial_home: | ||
| os.environ["HOME"] = initial_home | ||
|
|
||
| def test_runner_environment_max_cores_sets_proc_number_env(self): |
There was a problem hiding this comment.
The relevant test is to:
- set
max_coreson an API function; - call the function and capture its local runner's state;
- on this state, check that
._mpi_command_args contains-n ...according tomax_cores`.
For 2., use the wrapt-based aproach (cf. test_sklearn.py, where the wrap_with_parameter_trace is used). On first thought, I'd go for defining a wrap_with_runner_trace helper, whereby I'd trace the runner used when running the API function, by:
- wrapping the
KhiopsRunner.runmethod inside thewrap_with_runner_traceto traceself(selfbeing theKhiopsLocalRunnerinstance). - then, on that
selftrace, I'd checkself._mpi_command_argsfor the existence of the["-n", max_cores]sublist.
max_coresFixes #585
TODO Before Asking for a Review
main(ormain-v10)Unreleasedsection ofCHANGELOG.md(no date)index.html