Skip to content

Support OpenMPI #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions src/pnetcdf/_Variable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ cimport numpy
numpy.import_array()


ctypedef MPI.Datatype Datatype
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary to fix the OpenMPI issue? this should just create an alias



cdef class Variable:
Expand Down Expand Up @@ -699,7 +698,7 @@ cdef class Variable:
self._put(dataput,a,b,c)


def _put_var1(self, value, tuple index, bufcount, Datatype buftype, collective = True):
def _put_var1(self, value, tuple index, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef size_t *indexp
cdef MPI_Offset buffcount
Expand Down Expand Up @@ -735,7 +734,7 @@ cdef class Variable:
_check_err(ierr)
free(indexp)

def _put_var(self, ndarray data, bufcount, Datatype buftype, collective = True):
def _put_var(self, ndarray data, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -765,7 +764,7 @@ cdef class Variable:
PyArray_DATA(data), buffcount, bufftype)
_check_err(ierr)

def _put_vara(self, start, count, ndarray data, bufcount, Datatype buftype, collective = True):
def _put_vara(self, start, count, ndarray data, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -802,7 +801,7 @@ cdef class Variable:
PyArray_DATA(data), buffcount, bufftype)
_check_err(ierr)

def _put_varn(self, ndarray data, num, starts, counts=None, bufcount=None, buftype=None, collective = True):
def _put_varn(self, ndarray data, num, starts, counts=None, bufcount=None, MPI.Datatype buftype=None, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -862,7 +861,7 @@ cdef class Variable:
bufftype)
_check_err(ierr)

def put_varn_all(self, data, num, starts, counts=None, bufcount=None, buftype=None):
def put_varn_all(self, data, num, starts, counts=None, bufcount=None, MPI.Datatype buftype=None):
"""
put_varn_all(self, data, num, starts, counts=None, bufcount=None, buftype=None)

Expand Down Expand Up @@ -967,7 +966,7 @@ cdef class Variable:
self._put_varn(data, num, starts, counts, bufcount = bufcount,
buftype = buftype, collective = True)

def put_varn(self, data, num, starts, counts=None, bufcount=None, buftype=None):
def put_varn(self, data, num, starts, counts=None, bufcount=None, MPI.Datatype buftype=None):
"""
put_varn(self, data, num, starts, counts=None, bufcount=None, buftype=None)

Expand All @@ -979,7 +978,7 @@ cdef class Variable:
self._put_varn(data, num, starts, counts, bufcount = bufcount,
buftype = buftype, collective = False)

def iput_varn(self, data, num, starts, counts=None, bufcount=None, buftype=None):
def iput_varn(self, data, num, starts, counts=None, bufcount=None, MPI.Datatype buftype=None):
"""
iput_varn(self, data, num, starts, counts=None, bufcount=None, buftype=None)

Expand Down Expand Up @@ -1008,7 +1007,7 @@ cdef class Variable:
return self._iput_varn(data, num, starts, counts, bufcount, buftype,
buffered=False)

def bput_varn(self, data, num, starts, counts=None, bufcount=None, buftype=None):
def bput_varn(self, data, num, starts, counts=None, bufcount=None, MPI.Datatype buftype=None):
"""
bput_varn(self, data, num, starts, counts=None, bufcount=None, buftype=None)

Expand All @@ -1035,7 +1034,7 @@ cdef class Variable:
"""
return self._iput_varn(data, num, starts, counts, bufcount, buftype, buffered=True)

def _put_vars(self, start, count, stride, ndarray data, bufcount, Datatype buftype, collective = True):
def _put_vars(self, start, count, stride, ndarray data, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -1078,7 +1077,7 @@ cdef class Variable:
_check_err(ierr)


def _put_varm(self, ndarray data, start, count, stride, imap, bufcount, Datatype buftype, collective = True):
def _put_varm(self, ndarray data, start, count, stride, imap, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -1131,7 +1130,7 @@ cdef class Variable:



def put_var_all(self, data, start=None, count=None, stride=None, imap=None, bufcount=None, buftype=None):
def put_var_all(self, data, start=None, count=None, stride=None, imap=None, bufcount=None, MPI.Datatype buftype=None):
"""
put_var_all(self, data, start=None, count=None, stride=None, imap=None, bufcount=None, buftype=None)

Expand Down Expand Up @@ -1423,7 +1422,7 @@ cdef class Variable:
free(countp)
free(stridep)

def _get_var1(self, ndarray buff, index, bufcount, Datatype buftype, collective = True):
def _get_var1(self, ndarray buff, index, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef size_t *indexp
cdef MPI_Offset buffcount
Expand Down Expand Up @@ -1453,7 +1452,7 @@ cdef class Variable:
free(indexp)


def _get_var(self, ndarray buff, bufcount, Datatype buftype, collective = True):
def _get_var(self, ndarray buff, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand All @@ -1479,7 +1478,7 @@ cdef class Variable:
_check_err(ierr)


def _get_vara(self, ndarray buff, start, count, bufcount, Datatype buftype, collective = True):
def _get_vara(self, ndarray buff, start, count, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -1513,7 +1512,7 @@ cdef class Variable:

_check_err(ierr)

def _get_varn(self, ndarray data, num, starts, counts, bufcount, Datatype buftype, collective = True):
def _get_varn(self, ndarray data, num, starts, counts, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -1569,7 +1568,7 @@ cdef class Variable:

_check_err(ierr)

def _get_vars(self, ndarray buff, start, count, stride, bufcount, Datatype buftype, collective = True):
def _get_vars(self, ndarray buff, start, count, stride, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -1606,7 +1605,7 @@ cdef class Variable:

_check_err(ierr)

def _get_varm(self, ndarray buff, start, count, stride, imap, bufcount, Datatype buftype, collective = True):
def _get_varm(self, ndarray buff, start, count, stride, imap, bufcount, MPI.Datatype buftype, collective = True):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -2058,7 +2057,7 @@ cdef class Variable:
else:
return data

def _iput_var(self, ndarray data, bufcount, Datatype buftype, buffered = False):
def _iput_var(self, ndarray data, bufcount, MPI.Datatype buftype, buffered = False):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -2090,7 +2089,7 @@ cdef class Variable:
_check_err(ierr)
return request

def _iput_var1(self, value, index, bufcount, Datatype buftype, buffered=False):
def _iput_var1(self, value, index, bufcount, MPI.Datatype buftype, buffered=False):
cdef int ierr, ndims
cdef size_t *indexp
cdef MPI_Offset buffcount
Expand Down Expand Up @@ -2127,7 +2126,7 @@ cdef class Variable:
_check_err(ierr)
return request

def _iput_vara(self, start, count, ndarray data, bufcount, Datatype buftype, buffered=False):
def _iput_vara(self, start, count, ndarray data, bufcount, MPI.Datatype buftype, buffered=False):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -2166,7 +2165,7 @@ cdef class Variable:
_check_err(ierr)
return request

def _iput_vars(self, start, count, stride, ndarray data, bufcount, Datatype buftype, buffered=False):
def _iput_vars(self, start, count, stride, ndarray data, bufcount, MPI.Datatype buftype, buffered=False):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -2206,7 +2205,7 @@ cdef class Variable:
_check_err(ierr)
return request

def _iput_varn(self, ndarray data, num, starts, counts, bufcount, Datatype buftype, buffered=False):
def _iput_varn(self, ndarray data, num, starts, counts, bufcount, MPI.Datatype buftype, buffered=False):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -2270,7 +2269,7 @@ cdef class Variable:
_check_err(ierr)
return request

def _iput_varm(self, ndarray data, start, count, stride, imap, bufcount, Datatype buftype, buffered=False):
def _iput_varm(self, ndarray data, start, count, stride, imap, bufcount, MPI.Datatype buftype, buffered=False):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -2405,7 +2404,7 @@ cdef class Variable:
else:
raise ValueError("Invalid input arguments for iput_var")

def _iget_var(self, ndarray data, bufcount, Datatype buftype):
def _iget_var(self, ndarray data, bufcount, MPI.Datatype buftype):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand All @@ -2425,7 +2424,7 @@ cdef class Variable:
return request


def _iget_var1(self, ndarray buff, index, bufcount, Datatype buftype):
def _iget_var1(self, ndarray buff, index, bufcount, MPI.Datatype buftype):
cdef int ierr, ndims
cdef size_t *indexp
cdef MPI_Offset buffcount
Expand All @@ -2452,7 +2451,7 @@ cdef class Variable:
return request


def _iget_vara(self, ndarray data, start, count, bufcount, Datatype buftype):
def _iget_vara(self, ndarray data, start, count, bufcount, MPI.Datatype buftype):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -2481,7 +2480,7 @@ cdef class Variable:
_check_err(ierr)
return request

def _iget_vars(self, ndarray buff, start, count, stride, bufcount, Datatype buftype):
def _iget_vars(self, ndarray buff, start, count, stride, bufcount, MPI.Datatype buftype):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down Expand Up @@ -2513,7 +2512,7 @@ cdef class Variable:
_check_err(ierr)
return request

def iget_varn(self, ndarray data, num, starts, counts=None, bufcount=None, Datatype buftype=None):
def iget_varn(self, ndarray data, num, starts, counts=None, bufcount=None, MPI.Datatype buftype=None):
"""
iget_varn(self, data, num, starts, counts=None, bufcount=None, buftype=None)

Expand Down Expand Up @@ -2585,7 +2584,7 @@ cdef class Variable:
_check_err(ierr)
return request

def _iget_varm(self, ndarray buff, start, count, stride, imap, bufcount, Datatype buftype):
def _iget_varm(self, ndarray buff, start, count, stride, imap, bufcount, MPI.Datatype buftype):
cdef int ierr, ndims
cdef MPI_Offset buffcount
cdef MPI_Datatype bufftype
Expand Down
22 changes: 11 additions & 11 deletions src/pnetcdf/_utils.pyx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix the OpenMPI compatibility issue. mpi4py.MPI are Python-level objects that safely wrap the underlying MPI_Datatype, regardless of whether it is an integer (as in MPICH) or a pointer (as in OpenMPI).

Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ _nptonctype = {'S1' : NC_CHAR_C,
'f4' : NC_FLOAT_C,
'f8' : NC_DOUBLE_C}

_nptompitype = {'S1' : MPI_CHAR,
'i1' : MPI_BYTE,
'u1' : MPI_UNSIGNED_CHAR,
'i2' : MPI_SHORT,
'u2' : MPI_UNSIGNED_SHORT,
'i4' : MPI_INT,
'u4' : MPI_UNSIGNED,
'i8' : MPI_LONG_LONG,
'u8' : MPI_UNSIGNED_LONG_LONG,
'f4' : MPI_FLOAT,
'f8' : MPI_DOUBLE}
_nptompitype = {'S1' : MPI.CHAR,
'i1' : MPI.BYTE,
'u1' : MPI.UNSIGNED_CHAR,
'i2' : MPI.SHORT,
'u2' : MPI.UNSIGNED_SHORT,
'i4' : MPI.INT,
'u4' : MPI.UNSIGNED,
'i8' : MPI.LONG_LONG,
'u8' : MPI.UNSIGNED_LONG_LONG,
'f4' : MPI.FLOAT,
'f8' : MPI.DOUBLE}


"""_nptompitype = {'S1' : MPI_CHAR,
Expand Down