Open MPI logo

Hardware Locality Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |  

This web mail archive is frozen.

This page is part of a frozen web archive of this mailing list.

You can still navigate around this archive, but know that no new mails have been added to it since July of 2016.

Click here to be taken to the new web archives of this list; it includes all the mails that are in this frozen archive plus all new mails that have been sent to the list since it was migrated to the new archives.

Subject: Re: [hwloc-devel] SWIG bindings
From: Bernd Kallies (kallies_at_[hidden])
Date: 2010-12-02 04:25:23


I have a perl-wrapper lib for hwloc based on hwloc-1.0.2. It is written
manually because of the pointer things. However, the lib is not
complete. I use it mainly for discovering topologies. Supporting pinning
does not make sense for perl scripts to my opinion

I'm thinking about either submitting this to CPAN or to the hwloc dev
team. However, I first wanted to wait how things with hwloc 1.1 will
look, when the dust has settled somehow.

Any hints or ideas?

Attached you find the man page.

On Tue, 2010-11-30 at 11:07 -0500, Jeff Squyres wrote:
> Would anyone object if I take a whack at making some SWIG bindings for hwloc? I'm thinking specifically for perl (because that's my scripting language of choice), but I could probably be convinced to look at python as well.
> (this would be for 1.2 at the earliest -- definitely not for 1.1)

Dr. Bernd Kallies
Konrad-Zuse-Zentrum für Informationstechnik Berlin
Takustr. 7
14195 Berlin
Tel: +49-30-84185-270
Fax: +49-30-84185-311
e-mail: kallies_at_[hidden]

    Hwloc - Perl Access to Portable Hardware Locality (hwloc)

           use Hwloc;

           # Load topology
           my $topology = hwloc_topology_init();
           die "Failed to init topology" unless $topology;
           my $rc = hwloc_topology_load($topology);
           die "Failed to load topology" if $rc;

           # Determine number of sockets and processors
           my $nProcs = hwloc_get_nbobjs_by_type($topology,HWLOC_OBJ_PU);
           die "Failed to determine number of processors" unless $nProcs;
           my $nSockets = hwloc_get_nbobjs_by_type($topology,HWLOC_OBJ_SOCKET);
           die "Failed to determine number of sockets" unless $nSockets;
           printf "Topology contains %d processors on %d sockets.\n", $nProcs, $nSockets;

           # Browse through processors, retrieve data
           my $proc = undef;
           while ($proc = hwloc_get_next_obj_by_type($topology,HWLOC_OBJ_PU,$proc)) {
             my $idx = hwloc_get_obj_data($proc,HWLOC_ObjLogicalIndex);
             my $id = hwloc_get_obj_data($proc,HWLOC_ObjOsIndex);
             my $rank = hwloc_get_obj_data($proc,HWLOC_ObjSiblingRank);
             printf "Processor %2d: os_index %2d, sibling_rank %2d\n", $idx, $id, $rank;

           # Calculate distance between first and last processor
           my $firstProc = hwloc_get_obj_by_type($topology,HWLOC_OBJ_PU,0);
           my $lastProc = hwloc_get_obj_by_type($topology,HWLOC_OBJ_PU,$nProcs-1);
           my $ancestor = hwloc_get_common_ancestor_obj($topology,$firstProc,$lastProc);
           die "Failed to determine common ancestor of first and last processor" unless $ancestor;
           my $distance = hwloc_get_obj_data($firstProc,HWLOC_ObjDepth) +
                           hwloc_get_obj_data($lastProc,HWLOC_ObjDepth) -
           printf "Processors %2d and %2d are %2d levels apart.\n",

           # Destroy topology

    The Hwloc module provides a perl API for selected functions of the hwloc
    C API.

    Visit <> for information about

    The Hwloc module treats objects of C type *hwloc_topology_t* and
    *hwloc_obj_t* as perl integers. The perl value *undef* is used to
    represent the C value NULL.

    To access the properties of a *hwloc_obj_t* object, the Hwloc module
    provides the method hwloc_get_obj_data, which is not part of the hwloc C

    The following constants are exported by the Hwloc module:

  Type of topology objects

  Topology flags

  Properties of topology objects
    These constants are used by the hwloc_get_obj_data method.



    The following methods are exported:

  Create and destroy topologies
            $t = hwloc_topology_init()
            $rc = hwloc_topology_set_flags($t,$flags)
            $rc = hwloc_topology_load($t)

  Get some topology information
            $val = hwloc_topology_get_depth($t)
            $val = hwloc_topology_get_type_depth($t,$type)
            $val = hwloc_topology_get_depth_type($t,$depth)
            $val = hwloc_get_nbobjs_by_depth($t,$depth)
            $val = hwloc_get_nbobjs_by_type($t,$type)
            $val = hwloc_topology_is_thissystem($t)

  Retrieve objects and their properties
            $obj = hwloc_get_obj_by_depth($t,$depth,$idx)
            $obj = hwloc_get_obj_by_type($t,$type,$idx)
            $val = hwloc_get_obj_data($obj,$spec)

  Traversal helpers
            $obj = hwloc_get_root_obj($t)
            $obj = hwloc_get_ancestor_obj_by_depth($t,$depth,$obj)
            $obj = hwloc_get_ancestor_obj_by_type($t,$type,$obj)
            $obj = hwloc_get_next_obj_by_depth($t,$depth,$obj)
            $obj = hwloc_get_next_obj_by_type($t,$type,$obj)
            $obj = hwloc_get_pu_obj_by_os_index($t,$idx)
            $obj = hwloc_get_next_child($t,$obj,$obj)
            $obj = hwloc_get_common_ancestor_obj($t,$obj,$obj)
            $val = hwloc_obj_is_in_subtree($t,$obj,$obj)

    Bernd Kallies, <kallies_at_[hidden]>

    Copyright (C) 2010 by Bernd Kallies

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself, either Perl version 5.10.1 or, at
    your option, any later version of Perl 5 you may have available.