예제 #1
1
static int rmaps_lama_find_nth_subtree_match_core(hwloc_topology_t hwloc_topo,
                                                  hwloc_obj_t parent_obj,
                                                  int nth,
                                                  int *num_found,
                                                  hwloc_obj_type_t hwloc_key,
                                                  int depth,
                                                  hwloc_obj_t *cur_child)
{
    unsigned i;
    bool found = false;

#if 0
    {
        char str[128];
        hwloc_obj_snprintf(str, sizeof(str), hwloc_topo, parent_obj, "#", 0);
        printf("--> Checking -- %-20s \t -- \t %2d of %2d\n", str, nth, *num_found);
    }
#endif

    /*
     * Check if the keys match
     */
    if( hwloc_key == parent_obj->type ) {
        if( HWLOC_OBJ_CACHE == parent_obj->type &&
            depth == (int)parent_obj->attr->cache.depth ) {
            *num_found += 1;
            found = true;
        } else {
            *num_found += 1;
            found = true;
        }
    }

    /*
     * Basecase:
     * If we have found the correct item, return
     */
    if( nth == *num_found ) {
        *cur_child = parent_obj;
        return ORTE_SUCCESS;
    }

    /*
     * Do no go any deeper in the tree than we have to
     */
    if( !found ) {
        for(i = 0; i < parent_obj->arity; ++i ) {
            rmaps_lama_find_nth_subtree_match_core(hwloc_topo,
                                                   parent_obj->children[i],
                                                   nth,
                                                   num_found,
                                                   hwloc_key,
                                                   depth,
                                                   cur_child);
            if( nth == *num_found ) {
                return ORTE_SUCCESS;
            }
        }
    }

    return ORTE_SUCCESS;
}
예제 #2
0
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;
    }
}