Bindings for more SF calls
I'd like to add bindings for the PetscSF communication calls (PetscSFReduceBegin/End
and friends).
But, there's a problem. The C signatures for these calls are all of the form:
PetscSFReduceBegin(SF sf, MPI_Datatype unit, const void* leaddata, void* rootdata, MPI_Op op);
But, this requires that any petsc4py binding references mpi4py, since I need to be able to either pass in (or create) the unit
datatype, as well as the MPI_Op
.
I know that right now petsc4py does not depend on mpi4py (since PETSc can be built without MPI).
What's the best way to square this circle? Hide these implementations behind a compile time cython DEF WITH_MPI4PY
?
Comments (6)
-
-
So, in short, you have to implement
mpi4py_{Datatype|Op}_Get
, just cust&paste&replace, and cross fingers this is still working. -
reporter Hmm, Maybe I was mislead by this: https://cython.readthedocs.io/en/latest/src/userguide/language_basics.html#conditional-statements, where I think they say you can do something like:
DEF MY_CONDITIONAL = False IF MY_CONDITIONAL: raise RuntimeError ELSE: print("All good")
And then that will only compile the
ELSE
branch. -
Oh, OK, you are right. Sorry about the confusion. Still, the approach I suggested my prove better, that way mpi4py becomes a runtime dependency rather than a compile time one. And given that we already do that for Comm, why not following the pattern for Op and Datatype?
-
reporter I'm giving your approach a go now.
-
reporter - changed status to resolved
Fixed by pull request #106.
- Log in to comment
I think the compile time time
DEF WITH_MPI4PY
will not work as you expect,DEF
defines compile time constants, it cannot be used for conditional compilation. I'm afraid that the only way to go is to follow the nasty low level code we already use for communicators, look atpetscmpi.pxi
.