Skip to content

Commit c61806d

Browse files
author
ndenoyelle
committed
tests ok
1 parent 9f41aab commit c61806d

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

hwloc/distrib.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ static size_t* shuffled_range(const size_t n){
4949
if ((ret = malloc(n*sizeof(*ret))) == NULL) { free(index); return NULL; }
5050

5151
srand(time(NULL));
52-
for(i=n-1;i>=0;i--){
53-
val = rand()%(i+1);
54-
ret[i] = index[val];
55-
index[val] = index[i];
52+
for(i=n;i>0;i--){
53+
val = rand()%(i);
54+
ret[i-1] = index[val];
55+
index[val] = index[i-1];
5656
}
5757
free(index);
5858
return ret;
@@ -233,6 +233,8 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology,
233233
if ((obj->cpuset != NULL && !hwloc_bitmap_iszero(obj->cpuset)) &&
234234
hwloc_get_type_depth(topology, obj->type) >= 0)
235235
n++;
236+
if (obj->type == type)
237+
break;
236238
obj = obj->first_child;
237239
}
238240

@@ -245,6 +247,8 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology,
245247
levels[n-1-i] = obj->type;
246248
i++;
247249
}
250+
if (obj->type == type)
251+
break;
248252
obj = obj->first_child;
249253
}
250254

@@ -257,7 +261,7 @@ hwloc_distrib_iterator_scatter(hwloc_topology_t topology,
257261
*it->roots = root;
258262
it->n_roots = 1;
259263
it->root_coord = 0;
260-
it->n_levels = 1;
264+
it->n_levels = n;
261265
it->levels = (struct hwloc_distrib_level **)((char*)it +
262266
sizeof(*it) +
263267
sizeof(hwloc_obj_t));

tests/hwloc/hwloc_distrib.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void test_scatter(hwloc_topology_t topology)
138138
if ( !is_tleaf(topology) )
139139
return;
140140

141-
ssize_t i=0, j, r, n=0, c, val, nleaves=1;
141+
ssize_t i=0, j, r, n_levels=0, n=0, c, val, nleaves=1;
142142
hwloc_obj_t item, obj, root = hwloc_get_obj_by_depth(topology, 0, 0);
143143
struct hwloc_distrib_iterator *it;
144144

@@ -172,12 +172,13 @@ static void test_scatter(hwloc_topology_t topology)
172172
item = obj;
173173
goto next_level;
174174
}
175-
175+
176+
n_levels=n;
176177
for (i = 0; hwloc_distrib_iterator_next(topology, it, &item); i++) {
177178
c = i;
178179
n = nleaves;
179180
val = 0;
180-
for (j = (n-2); j >= 0; j--) {
181+
for (j = (n_levels-1); j > 0; j--) {
181182
r = c % arities[j];
182183
n = n / arities[j];
183184
c = c / arities[j];

utils/hwloc/test-hwloc-distrib.sh.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ set -e
6060
) > "$file"
6161
@DIFF@ @HWLOC_DIFF_U@ @HWLOC_DIFF_W@ $srcdir/test-hwloc-distrib.output "$file"
6262
rm -rf "$tmp"
63+
return 0

0 commit comments

Comments
 (0)