Le 20/02/2012 17:41, Albert Solernou a écrit :
> Hi,
> I'd like to bind a process to a cpuset, so that when it spawns on
> several threads, those are trapped on that cpuset.
>
> In order to do so, I want to define my own cpuset. Let's say I want it
> to include HWLOC_OBJ_CORE 2 and 5. How can I create this cpuset? The
> bitmap api sounds like the solution to me, but I couldn't relate the
> indexes in there into HWLOC_OBJects of any type...
If you want to bind to cores #2 and #5, do:
hwloc_bitmap_t cpuset;
hwloc_obj_t core1, core2;
core1 = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, 2);
if (!core1)
error...
core2 = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, 5);
if (!core2)
error...
cpuset = hwloc_bitmap_alloc();
if (!cpuset);
error...
hwloc_bitmap_or(cpuset, cpuset, core1->cpuset);
hwloc_bitmap_or(cpuset, cpuset, core2->cpuset);
...
hwloc_set_cpubind(... cpuset, HWLOC_CPUBIND_PROCESS)
...
hwloc_bitmap_free(cpuset);
This uses core logical indexes. If you want physical indexes, let me
know (but those makes sense for PUs, not really for Cores).
> On the other hand, I'd like to know if binding a process in there
> would lock its spawned threads.
Each thread inside the process basically gets the same binding as the
entire process.
Brice
|