Le 29/09/2014 19:01, Aulwes, Rob a écrit : > Hi, > > I'm trying to allocate and bind memory on the same NUMA domain as the > calling thread. The code I use is as follows. > > /* retrieve the single PU where the current thread actually > runs within this process binding */ > > > int err = hwloc_get_last_cpu_location(topo, set, > HWLOC_CPUBIND_THREAD); > > if (err < 0) { > > fprintf(stderr, "failed to get last cpu location\n"); > > return NULL; > > } > > > int idx = hwloc_bitmap_first(set); > > auto obj = hwloc_get_pu_obj_by_os_index(topo, idx); > > > // get NUMA node containing PU > > obj = hwloc_get_ancestor_obj_by_type(topo, HWLOC_OBJ_NODE, obj); > > void * buffer = hwloc_alloc_membind_nodeset(topo, len, > obj->nodeset, > > HWLOC_MEMBIND_BIND, > > HWLOC_MEMBIND_THREAD | > HWLOC_MEMBIND_STRICT); > > if (!buffer) { > > fprintf(stderr, "failed to manually allocate memory on > node %u\n", obj->os_index); > > return NULL; > > } > > > However, for some allocations, if I print out where the allocation was > bound, it doesn't match the node of the thread. Any ideas about what > I'm doing wrong? >
Hello I don't see any problem with your code. Are you sure the threads are bound within a single node? Random optimization idea: instead of bitmap_first()+get_pu_obj_by_os_index()+get_ancestor_by_type(), you can directly get the first NUMA node involved in cpuset "set" by calling hwloc_get_next_obj_covering_cpuset_by_type(topo, set, HWLOC_OBJ_NODE, NULL) Brice