Open MPI logo

Hardware Locality Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Users mailing list

Subject: [hwloc-users] Finding closest host bridge
From: Rolf vandeVaart (rvandevaart_at_[hidden])
Date: 2014-01-28 17:12:21

I cam up with this snippet of code so I could find the PCI devices closest to where a process was running. This works fine on a NUMA node. However, on a non-NUMA node, it appears that the HWLOC bridge is not connected to anything. Therefore, I believe I just need to do something like hwloc_get_obj_by_type(topology, HWLOC_OBJ_BRIDGE, 0) when running on a non-NUMA node. Does that seem correct? Should I special case where I do not find a HWLOC_OBJ_NODE object?

    retval = hwloc_topology_init(&topology);
    retval = hwloc_topology_set_flags(topology, flags);
    retval = hwloc_topology_load(topology);
    newset = hwloc_bitmap_alloc();
    retval = hwloc_get_last_cpu_location(topology, newset, 0);

    /* Get the object that contains the cpuset */
    node = hwloc_get_first_largest_obj_inside_cpuset(topology, newset);

    /* Climb up from that object until we find HWLOC_OBJ_NODE */
    while (node->type != HWLOC_OBJ_NODE) {
        node = node->parent;

    /* Now look for the HWLOC_OBJ_BRIDGE. All PCI busses hanging off the
     * node will have one of these */
    bridge = hwloc_get_next_child(topology, node, NULL);
    while (bridge != NULL && bridge->type != HWLOC_OBJ_BRIDGE) {
        bridge = hwloc_get_next_child(topology, node, bridge);
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.