hwloc_obj_t * rmaps_lama_find_nth_subtree_match(hwloc_topology_t hwloc_topo, hwloc_obj_t parent_obj, int nth, rmaps_lama_level_type_t lama_key) { int ret; hwloc_obj_t *cur_child = NULL; hwloc_obj_type_t hwloc_key; int depth; int num_found; #if 0 char str[128]; #endif cur_child = (hwloc_obj_t*)malloc(sizeof(hwloc_obj_t) * 1); /* * Convert LAMA key to HWLOC key */ rmaps_lama_convert_lama_key_to_hwloc_key(lama_key, &hwloc_key, &depth); /* * Decend tree looking for the n'th matching subtree */ num_found = -1; ret = rmaps_lama_find_nth_subtree_match_core(hwloc_topo, parent_obj, nth, &num_found, hwloc_key, depth, cur_child); /* * Check to see if we found it */ #if 0 hwloc_obj_snprintf(str, sizeof(str), hwloc_topo, *cur_child, "#", 0); if( nth == num_found ) { printf("--> FOUND : %-20s \t -- \t %2d of %2d\n", str, nth, num_found); } else { printf("--> MISSING : %-20s \t -- \t %2d of %2d\n", str, nth, num_found); } #endif if( nth == num_found ) { return cur_child; } else { free(cur_child); return NULL; } }
hwloc_obj_t * rmaps_lama_find_parent(hwloc_topology_t hwloc_topo, hwloc_obj_t *child_obj, rmaps_lama_level_type_t lama_key) { hwloc_obj_t *cur_parent = NULL; hwloc_obj_type_t hwloc_key; int depth; /* * Convert LAMA key to HWLOC key */ rmaps_lama_convert_lama_key_to_hwloc_key(lama_key, &hwloc_key, &depth); /* * Sanity check */ if( hwloc_key == (*child_obj)->type ) { if( HWLOC_OBJ_CACHE == (*child_obj)->type && depth == (int)(*child_obj)->attr->cache.depth ) { return child_obj; } else { return child_obj; } } cur_parent = (hwloc_obj_t*)malloc(sizeof(hwloc_obj_t) * 1); if (NULL == cur_parent) { return NULL; } /* * Accend tree to find mathing parent */ *cur_parent = (*child_obj)->parent; while(NULL != *cur_parent ) { if( hwloc_key == (*cur_parent)->type ) { if( HWLOC_OBJ_CACHE == (*cur_parent)->type && depth == (int)(*cur_parent)->attr->cache.depth ) { return cur_parent; } else { return cur_parent; } } *cur_parent = (*cur_parent)->parent; } free(cur_parent); return NULL; }