Open MPI logo

Hardware Locality Development Mailing List Archives

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

Subject: Re: [hwloc-devel] python bindings
From: Guy Streeter (streeter_at_[hidden])
Date: 2011-01-18 11:56:30

On 01/18/2011 06:47 AM, Jeff Squyres wrote:
> Are the abstractions anything like Bernd's perl bindings, perchance?
> On Jan 17, 2011, at 3:02 PM, Guy Streeter wrote:
>> I am currently working to get a public git repository set up so that I can share the work. In the meantime, my first pass at python bindings for hwloc are available from
>> There are rpm files and a source tarball there. The tarball has implementations of some of the tests and utils in python.
>> It assumes hwloc-1.1 and python-2.6 or later. Let me know what you think.
>> --Guy
>> _______________________________________________
>> hwloc-devel mailing list
>> hwloc-devel_at_[hidden]

I am not familiar enough with Perl to examine the source and say if the
implementations are similar.

In my python bindings (like all of python) everything is an object. Anything
that requires the topology is a method or property of the topology object.
Things that just need a hwloc_obj are methods or properties of the hwloc_obj
object. Same for bitmaps.

It tried to make things easy and obvious. There is an iterator for children of
an object, and one for set bits in a bitmap, so you can do
  for child in obj.children:
  for idx in bitmap:

You can compare bitmaps with the equality operator, you can use the bitwise &
and | operators on them as well. A bitmap used in string context will get a
string representation.

I made asprintf instead of snprintf methods because allocating a string buffer
to write into doesn't make sense in python. Objects are freed when they go out
of context, in cases where that is appropriate.

There are some python-specific test files in the tests directory, which I
tried to comment as examples.