From b8af3b7c4adc8decf28bf1cc0c0038774319c91a Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Mon, 25 Apr 2011 16:55:27 +0000 Subject: [PATCH] New comment explains it all -- previous code was failing to find the Nth core, so it fell over to try to find the Nth PU. ----- hwloc isn't able to find cores on all platforms. Example: PPC64 running RHEL 5.4 (linux kernel 2.6.18) only reports NUMA nodes and PU's. Fine. However, note that hwloc_get_obj_by_type() will return NULL in 2 (effectively) different cases: - no objects of the requested type were found - the Nth object of the requested type was not found So first we have to see if we can find *any* cores by looking for the 0th core. If we find it, then try to find the Nth core. Otherwise, try to find the Nth PU. This commit was SVN r24632. --- .../paffinity/hwloc/paffinity_hwloc_module.c | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/opal/mca/paffinity/hwloc/paffinity_hwloc_module.c b/opal/mca/paffinity/hwloc/paffinity_hwloc_module.c index e08d787c8f..6b6d7af78e 100644 --- a/opal/mca/paffinity/hwloc/paffinity_hwloc_module.c +++ b/opal/mca/paffinity/hwloc/paffinity_hwloc_module.c @@ -412,19 +412,32 @@ static int module_get_core_info(int socket, int *num_cores) static int module_get_physical_processor_id(int logical_processor_id, int *physical_processor_id) { + int obj_type = HWLOC_OBJ_CORE; hwloc_obj_t obj; hwloc_bitmap_t good; hwloc_topology_t *t = &mca_paffinity_hwloc_component.topology; /* hwloc isn't able to find cores on all platforms. Example: PPC64 running RHEL 5.4 (linux kernel 2.6.18) only reports NUMA - nodes and PU's. Fine. So just use PUs in that situation. */ - obj = hwloc_get_obj_by_type(*t, HWLOC_OBJ_CORE, logical_processor_id); + nodes and PU's. Fine. + + However, note that hwloc_get_obj_by_type() will return NULL in + 2 (effectively) different cases: + + - no objects of the requested type were found + - the Nth object of the requested type was not found + + So first we have to see if we can find *any* cores by looking + for the 0th core. If we find it, then try to find the Nth + core. Otherwise, try to find the Nth PU. */ + if (NULL == hwloc_get_obj_by_type(*t, HWLOC_OBJ_CORE, 0)) { + obj_type = HWLOC_OBJ_PU; + } + + /* Now do the actual lookup. */ + obj = hwloc_get_obj_by_type(*t, obj_type, logical_processor_id); if (NULL == obj) { - obj = hwloc_get_obj_by_type(*t, HWLOC_OBJ_PU, logical_processor_id); - if (NULL == obj) { - return OPAL_ERR_NOT_FOUND; - } + return OPAL_ERR_NOT_FOUND; } /* Found the right core (or PU). Now find the processor ID of the