Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find maximum number of CPUs given within a cgroup #1646

Open
tomgreen66 opened this issue Jan 16, 2024 · 0 comments
Open

Find maximum number of CPUs given within a cgroup #1646

tomgreen66 opened this issue Jan 16, 2024 · 0 comments

Comments

@tomgreen66
Copy link

On a HPC cluster environment, CPUs can be given to it via job schedulers, such as Slurm, using cgroups to provide a cpuset to a job. Currently Alicevision (and hence Meshroom) will report the maximum number of processors on the compute node, whilst the job scheduler may have own given access to a limited set of CPUs. Therefore the user has to remember to limit the number of CPUs to what Slurm has given it.

Would it be worth changing the code for get_total_cpus at:

#if defined linux || defined __linux__ || defined __sun
#include <sys/sysinfo.h>
#include <unistd.h>
namespace aliceVision {
namespace system {
int get_total_cpus(void) { return sysconf(_SC_NPROCESSORS_ONLN); }
} // namespace system
} // namespace aliceVision
#define GET_TOTAL_CPUS_DEFINED
#endif

to be instead use:

#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <sched.h>
int get_total_cpus()
{
 cpu_set_t cs;
 sched_getaffinity(0, sizeof(cs), &cs);
 return CPU_COUNT_S(sizeof(cs), &cs);
}

This should return the actual CPUs which are available to the software rather than the total maximum on the node. This may need updates to Cmake to test for existence of sched_getaffinity so fallback to current method can be used, something like:

list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
CHECK_SYMBOL_EXISTS(sched_getaffinity sched.h HAVE_SCHED_GETAFFINITY)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant