From f2d4a8d266f7df24fc0faf4a0cc2df034656c7fb Mon Sep 17 00:00:00 2001 From: Tim Mattox Date: Tue, 12 Jan 2016 10:48:56 -0500 Subject: [PATCH] Replace a bit counting loop with a call to an efficient population count routine --- opal/mca/hwloc/base/hwloc_base_util.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/opal/mca/hwloc/base/hwloc_base_util.c b/opal/mca/hwloc/base/hwloc_base_util.c index cd429eeb00..a5c30b21f9 100644 --- a/opal/mca/hwloc/base/hwloc_base_util.c +++ b/opal/mca/hwloc/base/hwloc_base_util.c @@ -579,16 +579,10 @@ unsigned int opal_hwloc_base_get_npus(hwloc_topology_t topo, * one bit for each available pu. We could just * subtract the first and last indices, but there * may be "holes" in the bitmap corresponding to - * offline or unallowed cpus - so we have to - * search for them + * offline or unallowed cpus - so we count them with + * the bitmap "weight" (a.k.a. population count) function */ - for (i=hwloc_bitmap_first(cpuset), cnt=0; - i <= hwloc_bitmap_last(cpuset); - i++) { - if (hwloc_bitmap_isset(cpuset, i)) { - cnt++; - } - } + cnt = hwloc_bitmap_weight(cpuset); } /* cache the info */ data = (opal_hwloc_obj_data_t*)obj->userdata; // in case it was added