diff --git a/hwloc/distrib.c b/hwloc/distrib.c index bb34f15923..f3e77fced3 100644 --- a/hwloc/distrib.c +++ b/hwloc/distrib.c @@ -49,10 +49,10 @@ static size_t* shuffled_range(const size_t n){ if ((ret = malloc(n*sizeof(*ret))) == NULL) { free(index); return NULL; } srand(time(NULL)); - for(i=n-1;i>=0;i--){ - val = rand()%(i+1); - ret[i] = index[val]; - index[val] = index[i]; + for(i=n;i>0;i--){ + val = rand()%(i); + ret[i-1] = index[val]; + index[val] = index[i-1]; } free(index); return ret; @@ -233,6 +233,8 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology, if ((obj->cpuset != NULL && !hwloc_bitmap_iszero(obj->cpuset)) && hwloc_get_type_depth(topology, obj->type) >= 0) n++; + if (obj->type == type) + break; obj = obj->first_child; } @@ -245,6 +247,8 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology, levels[n-1-i] = obj->type; i++; } + if (obj->type == type) + break; obj = obj->first_child; } @@ -257,7 +261,7 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology, *it->roots = root; it->n_roots = 1; it->root_coord = 0; - it->n_levels = 1; + it->n_levels = n; it->levels = (struct hwloc_distrib_level **)((char*)it + sizeof(*it) + sizeof(hwloc_obj_t)); diff --git a/tests/hwloc/hwloc_distrib.c b/tests/hwloc/hwloc_distrib.c index 55e610fbe6..7a0bdfe846 100644 --- a/tests/hwloc/hwloc_distrib.c +++ b/tests/hwloc/hwloc_distrib.c @@ -138,7 +138,7 @@ static void test_scatter(hwloc_topology_t topology) if ( !is_tleaf(topology) ) return; - ssize_t i=0, j, r, n=0, c, val, nleaves=1; + ssize_t i=0, j, r, n_levels=0, n=0, c, val, nleaves=1; hwloc_obj_t item, obj, root = hwloc_get_obj_by_depth(topology, 0, 0); struct hwloc_distrib_iterator *it; @@ -172,12 +172,13 @@ static void test_scatter(hwloc_topology_t topology) item = obj; goto next_level; } - + + n_levels=n; for (i = 0; hwloc_distrib_iterator_next(topology, it, &item); i++) { c = i; n = nleaves; val = 0; - for (j = (n-2); j >= 0; j--) { + for (j = (n_levels-1); j > 0; j--) { r = c % arities[j]; n = n / arities[j]; c = c / arities[j]; diff --git a/utils/hwloc/test-hwloc-distrib.output b/utils/hwloc/test-hwloc-distrib.output index 83194d171f..14df40815e 100644 --- a/utils/hwloc/test-hwloc-distrib.output +++ b/utils/hwloc/test-hwloc-distrib.output @@ -1,11 +1,3 @@ -0x0000000f -0x000000f0 - -0x00000003 -0x0000000c -0x00000030 -0x000000c0 - 0x00000001 0x00000002 0x00000004 @@ -16,112 +8,108 @@ 0x00000080 0x00000001 -0x00000001 -0x00000002 0x00000002 0x00000004 -0x00000004 0x00000008 0x00000010 -0x00000010 0x00000020 0x00000040 -0x00000040 0x00000080 - -0x00000001 0x00000001 0x00000002 -0x00000002 0x00000004 -0x00000004 -0x00000008 0x00000008 0x00000010 -0x00000010 -0x00000020 0x00000020 0x00000040 +0x00000080 +0x00000001 +0x00000002 +0x00000004 +0x00000008 +0x00000010 +0x00000020 0x00000040 0x00000080 +0x00000001 +0x00000002 +0x00000004 +0x00000008 +0x00000010 +0x00000020 +0x00000040 0x00000080 -0x00000007 -0x000001f8 -0x0003fe00 -0x07fc0000 - 0x00000001 +0x00000002 +0x00000004 0x00000008 -0x00000200 -0x00040000 - -0x07000000 -0x00fc0000 -0x0003fe00 -0x000001ff 0x04000000 +0x02000000 +0x01000000 0x00800000 -0x00020000 -0x00000100 -0x000000ff -0x0000ff00 +0 +1 +2 +3 -0x00000001 -0x00000100 +0 +1 +2 +3 -0x00008000 -0x00000080 +0x00000001 +0x00000002 +0x00000004 +0x00000008 -0x000000ff -0x0000ff00 -0xffff0000 -0x0000ffff,0x0 -0xffff0000,0x0 -0x000000ff,,0x0 -0x0000ff00,,0x0 -0xffff0000,,0x0 -0x0000ffff,,,0x0 -0xffff0000,,,0x0 -0x000000ff,,,,0x0 -0x0000ff00,,,,0x0 -0xffff0000,,,,0x0 -0x0000ffff,,,,,0x0 -0xffff0000,,,,,0x0 -0x0000ffff,,,,,,0x0 -0xffff0000,,,,,,0x0 -0x0000ffff,,,,,,,0x0 -0xffff0000,,,,,,,0x0 +0x00000001 +0x00000001,,0x0 +0x00000001,,,,0x0 +0x00000001,,,,,,0x0 +0x00000010 +0x00000010,,0x0 +0x00000010,,,,0x0 +0x00000010,,,,,,0x0 0x00000001 -0x00000002 -0x0000000c -0x00000030 -0x000000c0 -0x00000300 -0x00000c00 -0x00003000 -0x0000c000 +0x00000001,,0x0 +0x00000001,,,,0x0 +0x00000001,,,,,,0x0 +0x00010000 +0x00010000,,0x0 +0x00010000,,,,0x0 +0x00010000,,,,,,0x0 +0x00000001,0x0 +0x00000001,,,0x0 +0x00000001,,,,,0x0 +0x00000001,,,,,,,0x0 +0x00010000,0x0 +0x00010000,,,0x0 +0x00010000,,,,,0x0 +0x00010000,,,,,,,0x0 +0x00000010 +0x00000010,,0x0 +0x00000010,,,,0x0 0x00000001 -0x00000006 -0x00000018 -0x00000060 +0x00000002 +0x00000004 +0x00000008 +0x00000010 +0x00000020 +0x00000040 0x00000080 -0x00000300 -0x00000c00 -0x00003000 -0x0000c000 +0x00000100 -0x00000003 -0x00000003 -0x0000000c -0x00000030 -0x000000c0 -0x00000300 -0x00000c00 -0x00003000 -0x0000c000 +8 +196 +132 +68 +4 +192 +128 +64 diff --git a/utils/hwloc/test-hwloc-distrib.sh.in b/utils/hwloc/test-hwloc-distrib.sh.in index b6e5a4ae8c..27adfbebc2 100644 --- a/utils/hwloc/test-hwloc-distrib.sh.in +++ b/utils/hwloc/test-hwloc-distrib.sh.in @@ -35,38 +35,27 @@ file="$tmp/test-hwloc-distrib.output" set -e ( - $distrib --if synthetic --input "2 2 2" 2 + $distrib pu --if synthetic --input "4 4 4 4" -n 8 echo - $distrib --if synthetic --input "2 2 2" 4 + $distrib pu --if synthetic --input "1 2 2 2" -n 32 echo - $distrib --if synthetic --input "2 2 2" 8 + $distrib pu --if synthetic --input "3 3 3" -n 4 --single echo - $distrib --if synthetic --input "2 2 2" 13 + $distrib pu --if synthetic --input "3 3 3" -n 4 --reverse echo - $distrib --if synthetic --input "2 2 2" 16 + $distrib pu --if synthetic --input "3 3 3" -n 4 --logical-index echo - $distrib --if synthetic --input "3 3 3" 4 + $distrib pu --if synthetic --input "3 3 3" -n 4 --physical-index echo - $distrib --if synthetic --input "3 3 3" 4 --single + $distrib pu --if synthetic --input "3 3 3" -n 4 --from 0 echo - $distrib --if synthetic --input "3 3 3" 4 --reverse + $distrib pu:core:package --if synthetic --input "4 4 4 4" -n 8 + echo + $distrib scatter pu --if synthetic --input "4 4 4 4" -n 19 echo - $distrib --if synthetic --input "3 3 3" 4 --reverse --single + $distrib round-robin pu --if synthetic --input "2 2 2 2" -n 9 echo - $distrib --if synthetic --input "4 4" 2 - echo - $distrib --if synthetic --input "4 4" 2 --single - echo - $distrib --if synthetic --input "4 4" 2 --reverse --single - echo - $distrib --if synthetic --input "4 4 4 4" 19 - echo - - $distrib --if synthetic --input "2 2 2 2" 9 - echo - $distrib --if synthetic --input "2 2 2 2" --from pu 9 - echo - $distrib --if synthetic --input "2 2 2 2" --to core 9 + $distrib pu:core:package --if synthetic --input "4 4 4 4" -n 8 --logical-index --single --reverse --from 8 echo ) > "$file" @DIFF@ @HWLOC_DIFF_U@ @HWLOC_DIFF_W@ $srcdir/test-hwloc-distrib.output "$file"