uniomni / pypar

Automatically exported from code.google.com/p/pypar
0 stars 0 forks source link

Library not found on OS X #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When attempting to 'import pypar', the following error message is generated

Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pypar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pypar.py", line 863, in <module>
    mpi = CDLL('libmpi.so.0', RTLD_GLOBAL)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ctypes/_
_init__.py",
line 345, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libmpi.so.0, 10): image not found
>>> 

This problem is occuring due to these lines in pypar.py:

    # Work around bug in OpenMPI (December 2009): 
    # https://bugs.launchpad.net/ubuntu/+source/petsc4py/+bug/232036
    from ctypes import *
    mpi = CDLL('libmpi.so.0', RTLD_GLOBAL)

The problem is that (at least on OS X machines), 'libmpi.so.0' does not
exist (tested with both MPICH2 and OpenMPI). However, 'libmpi.0.dylib' is
the corresponding library on OS X. So the solution would be to use some
more sophisticated way of choosing which library file to use. 

For the record, changing the string to 'libmpi.0.dylib' on OS X fixes the
problem with importing pypar

>>> import pypar
Pypar (version 2.1.4) initialised MPI OK with 1 processors
>>> 

Original issue reported on code.google.com by romesh.a...@gmail.com on 22 Dec 2009 at 10:26

GoogleCodeExporter commented 9 years ago
I second this.  In a recent Ubuntu systemn(10.04) with mpich2, there is only a 
file called 'libmpi.so', not 'libmpi.so.0'.

Original comment by xing....@gmail.com on 25 Dec 2010 at 3:15

GoogleCodeExporter commented 9 years ago
I know this is very old, but this issue is resolved with simple switches:
    if sys.platform == 'darwin': # works on OSX
        mpi = CDLL('libmpi.0.dylib', RTLD_GLOBAL)
    else:
        try:
            mpi = CDLL('libmpi.so.0', RTLD_GLOBAL)
        except OSError:
            mpi = CDLL('libmpi.so', RTLD_GLOBAL)

and an 'import sys' up top, of course.

Original comment by benjami...@gmail.com on 18 Mar 2011 at 6:46