Question

hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth_CORE,MyRank%4);
hwloc_cpuset_t cpuset = hwloc_bitmap_dup(obj->cpuset);
hwloc_set_cpubind(topology, cpuset, 0)

Is there anyway in hwloc to know if a thread is already binded to that "cpuset". Reason why I need to know this: Suppose I have a quad core. But if I issue 8 processors at runtime. So it happens to bind 2 process to each core. However I want to bind process to core only when it is free. So is there anyway I could know that core has been already binded to process.

Was it helpful?

Solution

It seems that the only way to do so is to enumerate all processes and check whether some of them are bound to the specified core. You can get an idea how to do that by examining the source code of the hwloc-ps utility. What it does is that it reads through the /proc filesystem and extracts process PIDs form there, then uses hwloc_get_proc_cpubind() to obtain the binding mask. This should work on Linux and Solaris, as well as *BSD systems with mounted /proc. On Windows one should use the system-specific API from the Tool Help library to obtain the list of PIDs. OS X does not support processor affinity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top