int main(void) { #define N 10 hwloc_bitmap_t sets[N]; unsigned i,j; unsigned stats[5]; memset(stats, 0, sizeof(stats)); sets[0] = hwloc_bitmap_alloc(); sets[1] = hwloc_bitmap_alloc_full(); sets[2] = hwloc_bitmap_alloc_full(); hwloc_bitmap_clr_range(sets[2], 56, 129); sets[3] = hwloc_bitmap_alloc_full(); hwloc_bitmap_clr_range(sets[3], 0, 33); hwloc_bitmap_clr_range(sets[3], 50, 135); sets[4] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[4], 0, 24); sets[5] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[5], 0, 178); sets[6] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[6], 0, 191); hwloc_bitmap_set_range(sets[6], 1031, 2035); sets[7] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[7], 324, 456); sets[8] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[8], 323, 455); hwloc_bitmap_set_range(sets[8], 136, 177); sets[9] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[9], 3, 6); for(i=0; i<N; i++) { for(j=0; j<N; j++) { int res = check_compare(sets[i], sets[j]); stats[res]++; } } for(i=0; i<N; i++) hwloc_bitmap_free(sets[i]); printf("got %u EQUAL\n", stats[0]); printf("got %u INCLUDED\n", stats[1]); printf("got %u CONTAINS\n", stats[2]); printf("got %u INTERSECTS\n", stats[3]); printf("got %u DIFFERENT\n", stats[4]); return 0; }
int main(void) { static hwloc_topology_t oldtopology, topology; hwloc_bitmap_t cpuset = hwloc_bitmap_alloc(); unsigned node_indexes[3], core_indexes[6]; float node_distances[9], core_distances[36]; unsigned i,j; int err; for(i=0; i<3; i++) { node_indexes[i] = i; for(j=0; j<3; j++) node_distances[i*3+j] = (i == j ? 10.f : 20.f); } for(i=0; i<6; i++) { core_indexes[i] = i; for(j=0; j<6; j++) core_distances[i*6+j] = (i == j ? 4.f : 8.f); } hwloc_topology_init(&oldtopology); printf("building fake 'node:3 core:2 pu:4' topology\n"); hwloc_topology_set_synthetic(oldtopology, "node:3 core:2 pu:4"); printf("adding node and core matrices\n"); hwloc_topology_set_distance_matrix(oldtopology, HWLOC_OBJ_NUMANODE, 3, node_indexes, node_distances); hwloc_topology_set_distance_matrix(oldtopology, HWLOC_OBJ_CORE, 6, core_indexes, core_distances); hwloc_topology_load(oldtopology); printf("duplicating\n"); hwloc_topology_dup(&topology, oldtopology); printf("destroying the old topology\n"); hwloc_topology_destroy(oldtopology); /* remove the entire third node */ printf("removing one node\n"); hwloc_bitmap_fill(cpuset); hwloc_bitmap_clr_range(cpuset, 16, 23); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); printf("checking the result\n"); assert(hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NUMANODE) == 2); hwloc_topology_destroy(topology); hwloc_bitmap_free(cpuset); return 0; }
int main(void) { static hwloc_topology_t oldtopology, topology; hwloc_bitmap_t cpuset = hwloc_bitmap_alloc(); struct hwloc_distances_s *distances; hwloc_obj_t nodes[3], cores[6]; uint64_t node_distances[9], core_distances[36]; unsigned i,j,nr; int err; hwloc_topology_init(&oldtopology); hwloc_topology_set_synthetic(oldtopology, "node:3 core:2 pu:4"); hwloc_topology_load(oldtopology); for(i=0; i<3; i++) { nodes[i] = hwloc_get_obj_by_type(oldtopology, HWLOC_OBJ_NUMANODE, i); for(j=0; j<3; j++) node_distances[i*3+j] = (i == j ? 10 : 20); } err = hwloc_distances_add(oldtopology, 3, nodes, node_distances, HWLOC_DISTANCES_KIND_MEANS_LATENCY|HWLOC_DISTANCES_KIND_FROM_USER, HWLOC_DISTANCES_FLAG_GROUP); assert(!err); for(i=0; i<6; i++) { cores[i] = hwloc_get_obj_by_type(oldtopology, HWLOC_OBJ_CORE, i); for(j=0; j<6; j++) core_distances[i*6+j] = (i == j ? 4 : 8); } err = hwloc_distances_add(oldtopology, 6, cores, core_distances, HWLOC_DISTANCES_KIND_MEANS_LATENCY|HWLOC_DISTANCES_KIND_FROM_USER, HWLOC_DISTANCES_FLAG_GROUP); assert(!err); printf("duplicating\n"); err = hwloc_topology_dup(&topology, oldtopology); assert(!err); printf("destroying the old topology\n"); hwloc_topology_destroy(oldtopology); /* remove the entire third node */ printf("removing one node\n"); hwloc_bitmap_fill(cpuset); hwloc_bitmap_clr_range(cpuset, 16, 23); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_REMOVE_CPULESS); assert(!err); printf("checking the result\n"); assert(hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NUMANODE) == 2); nr = 1; err = hwloc_distances_get_by_type(topology, HWLOC_OBJ_NUMANODE, &nr, &distances, 0, 0); assert(!err); assert(nr == 1); assert(distances->nbobjs == 2); assert(distances->kind == (HWLOC_DISTANCES_KIND_MEANS_LATENCY|HWLOC_DISTANCES_KIND_FROM_USER)); hwloc_distances_release(topology, distances); nr = 1; err = hwloc_distances_get_by_type(topology, HWLOC_OBJ_CORE, &nr, &distances, 0, 0); assert(!err); assert(nr == 1); assert(distances->nbobjs == 4); assert(distances->kind == (HWLOC_DISTANCES_KIND_MEANS_LATENCY|HWLOC_DISTANCES_KIND_FROM_USER)); hwloc_distances_release(topology, distances); hwloc_topology_destroy(topology); hwloc_bitmap_free(cpuset); return 0; }
int main(void) { hwloc_bitmap_t set; /* check an empty bitmap */ set = hwloc_bitmap_alloc(); assert(hwloc_bitmap_to_ulong(set) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL); /* check a non-empty bitmap */ hwloc_bitmap_from_ith_ulong(set, 4, 0xff); assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff); assert(hwloc_bitmap_to_ulong(set) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL); /* check a zeroed bitmap */ hwloc_bitmap_zero(set); assert(hwloc_bitmap_to_ulong(set) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL); hwloc_bitmap_free(set); /* check a full bitmap */ set = hwloc_bitmap_alloc_full(); assert(hwloc_bitmap_to_ulong(set) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL); /* check a almost full bitmap */ hwloc_bitmap_set_ith_ulong(set, 4, 0xff); assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff); assert(hwloc_bitmap_to_ulong(set) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL); /* check a almost empty bitmap */ hwloc_bitmap_from_ith_ulong(set, 4, 0xff); assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff); assert(hwloc_bitmap_to_ulong(set) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL); hwloc_bitmap_free(set); /* check ranges */ set = hwloc_bitmap_alloc(); assert(hwloc_bitmap_weight(set) == 0); /* 23-45 */ hwloc_bitmap_set_range(set, 23, 45); assert(hwloc_bitmap_weight(set) == 23); /* 23-45,78- */ hwloc_bitmap_set_range(set, 78, -1); assert(hwloc_bitmap_weight(set) == -1); /* 23- */ hwloc_bitmap_set_range(set, 44, 79); assert(hwloc_bitmap_weight(set) == -1); assert(hwloc_bitmap_first(set) == 23); assert(!hwloc_bitmap_isfull(set)); /* 0- */ hwloc_bitmap_set_range(set, 0, 22); assert(hwloc_bitmap_weight(set) == -1); assert(hwloc_bitmap_isfull(set)); /* 0-34,57- */ hwloc_bitmap_clr_range(set, 35, 56); assert(hwloc_bitmap_weight(set) == -1); assert(!hwloc_bitmap_isfull(set)); /* 0-34,57 */ hwloc_bitmap_clr_range(set, 58, -1); assert(hwloc_bitmap_weight(set) == 36); assert(hwloc_bitmap_last(set) == 57); assert(hwloc_bitmap_next(set, 34) == 57); /* 0-34 */ hwloc_bitmap_clr(set, 57); assert(hwloc_bitmap_weight(set) == 35); assert(hwloc_bitmap_last(set) == 34); /* empty */ hwloc_bitmap_clr_range(set, 0, 34); assert(hwloc_bitmap_weight(set) == 0); assert(hwloc_bitmap_first(set) == -1); hwloc_bitmap_free(set); return 0; }
int main(void) { hwloc_bitmap_t cpuset = hwloc_bitmap_alloc(); unsigned node_indexes[3], core_indexes[6]; float node_distances[9], core_distances[36]; unsigned i,j; int err; for(i=0; i<3; i++) { node_indexes[i] = i; for(j=0; j<3; j++) node_distances[i*3+j] = (i == j ? 10.f : 20.f); } for(i=0; i<6; i++) { core_indexes[i] = i; for(j=0; j<6; j++) core_distances[i*6+j] = (i == j ? 4.f : 8.f); } hwloc_topology_init(&topology); hwloc_topology_set_synthetic(topology, "node:3 core:2 pu:4"); hwloc_topology_set_distance_matrix(topology, HWLOC_OBJ_NODE, 3, node_indexes, node_distances); hwloc_topology_set_distance_matrix(topology, HWLOC_OBJ_CORE, 6, core_indexes, core_distances); hwloc_topology_load(topology); /* entire topology */ printf("starting from full topology\n"); check(3, 6, 24); check_distances(3, 6); /* restrict to nothing, impossible */ printf("restricting to nothing, must fail\n"); hwloc_bitmap_zero(cpuset); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(err < 0 && errno == EINVAL); check(3, 6, 24); check_distances(3, 6); /* restrict to everything, will do nothing */ printf("restricting to nothing, does nothing\n"); hwloc_bitmap_fill(cpuset); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); check(3, 6, 24); check_distances(3, 6); /* remove a single pu (second PU of second core of second node) */ printf("removing one PU\n"); hwloc_bitmap_fill(cpuset); hwloc_bitmap_clr(cpuset, 13); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); check(3, 6, 23); check_distances(3, 6); /* remove the entire second core of first node */ printf("removing one core\n"); hwloc_bitmap_fill(cpuset); hwloc_bitmap_clr_range(cpuset, 4, 7); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); check(3, 5, 19); check_distances(3, 5); /* remove the entire third node */ printf("removing one node\n"); hwloc_bitmap_fill(cpuset); hwloc_bitmap_clr_range(cpuset, 16, 23); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); check(2, 3, 11); check_distances(2, 3); /* restrict to the third node, impossible */ printf("restricting to only some already removed node, must fail\n"); hwloc_bitmap_zero(cpuset); hwloc_bitmap_set_range(cpuset, 16, 23); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(err == -1 && errno == EINVAL); check(2, 3, 11); check_distances(2, 3); /* only keep three PUs (first and last of first core, and last of last core of second node) */ printf("restricting to 3 PUs\n"); hwloc_bitmap_zero(cpuset); hwloc_bitmap_set(cpuset, 0); hwloc_bitmap_set(cpuset, 3); hwloc_bitmap_set(cpuset, 15); err = hwloc_topology_restrict(topology, cpuset, 0); assert(!err); check(2, 2, 3); check_distances(0, 0); /* only keep one PU (last of last core of second node) */ printf("restricting to a single PU\n"); hwloc_bitmap_zero(cpuset); hwloc_bitmap_set(cpuset, 15); err = hwloc_topology_restrict(topology, cpuset, 0); assert(!err); check(1, 1, 1); check_distances(0, 0); hwloc_topology_destroy(topology); /* check that restricting exactly on a Misc object keeps things coherent */ printf("restricting to a Misc covering only the of the PU level\n"); hwloc_topology_init(&topology); hwloc_topology_set_synthetic(topology, "pu:4"); hwloc_topology_load(topology); hwloc_bitmap_zero(cpuset); hwloc_bitmap_set_range(cpuset, 1, 2); hwloc_topology_insert_misc_object_by_cpuset(topology, cpuset, "toto"); hwloc_topology_restrict(topology, cpuset, 0); hwloc_topology_check(topology); hwloc_topology_destroy(topology); hwloc_bitmap_free(cpuset); return 0; }