mpi4py ctypes wrapper for Fortran 2008 #276
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Next time, please do not post screenshots. Just paste the test and use proper markdown formatting. Otherwise, you make things harder to try and play around for those trying to help you. The code you are using would be appropriate for C toYou should learn elsewehre make it work in any platform with any MPI implementation. But it is not correct for Fortran 77 or Fortran 90/08. First, you should uncomment Next, you need to do things the following way in Python : MPI_Fint = ctypes.c_int
MPI_Fint_p = ctypes.POINTER(MPI_Fint)
lib.sayhello.restype = None
lib.sayhello.argtypes = [MPI_Fint_p] # by default, Fortran pass arguments by address
comm = MPI.COMM_WORLD
fcomm = MPI_Fint(comm.py2f())
lib.sayhello(fcomm) This is not the only way to do things. In your fortran code, you could use: type(MPI_Comm), intent(in), value :: comm Note the use of As you pass the comm argument by value, then in Python you just need:
|
Beta Was this translation helpful? Give feedback.
-
@apoorv-2-8 I've put together a couple examples with the stuff we discussed here. The new examples are in this (branch)[https://github.com/mpi4py/mpi4py/tree/feature/demo-ctypes-fortran], commit 29c898e. Could you please take a quick look and tell me whether this is good enough to merge into master? |
Beta Was this translation helpful? Give feedback.
Next time, please do not post screenshots. Just paste the test and use proper markdown formatting. Otherwise, you make things harder to try and play around for those trying to help you.
The code you are using would be appropriate for C toYou should learn elsewehre make it work in any platform with any MPI implementation. But it is not correct for Fortran 77 or Fortran 90/08.
First, you should uncomment
bind(C)
for maximum portability.Next, you need to do things the following way in Python :