Skip to content

Commit f2d4a8d

Browse files
author
Tim Mattox
committed
Replace a bit counting loop with a call to an efficient population count routine
1 parent 955fe85 commit f2d4a8d

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

opal/mca/hwloc/base/hwloc_base_util.c

+3-9
Original file line numberDiff line numberDiff line change
@@ -579,16 +579,10 @@ unsigned int opal_hwloc_base_get_npus(hwloc_topology_t topo,
579579
* one bit for each available pu. We could just
580580
* subtract the first and last indices, but there
581581
* may be "holes" in the bitmap corresponding to
582-
* offline or unallowed cpus - so we have to
583-
* search for them
582+
* offline or unallowed cpus - so we count them with
583+
* the bitmap "weight" (a.k.a. population count) function
584584
*/
585-
for (i=hwloc_bitmap_first(cpuset), cnt=0;
586-
i <= hwloc_bitmap_last(cpuset);
587-
i++) {
588-
if (hwloc_bitmap_isset(cpuset, i)) {
589-
cnt++;
590-
}
591-
}
585+
cnt = hwloc_bitmap_weight(cpuset);
592586
}
593587
/* cache the info */
594588
data = (opal_hwloc_obj_data_t*)obj->userdata; // in case it was added

0 commit comments

Comments
 (0)