Your example is pretty close to spot on.  You want to convert the
Fortran handle (integer) into a C handle (something else).  Then use the
C handle to call C functions.  The one thing of note is that you should
use the type MPI_Fint instead of int for the type of the Fortran
handles.  So your parallel_info function's prototype would be:

  void parallel_info_(int *rank, MPI_Fint *comm);

Hope this helps,

Brian


On Fri, 2006-09-01 at 09:26 -0400, Wang, Peng wrote:
> Hello, I am wondering in openmpi how is the passing of MPI communcator 
> from Fortran to C is handled? Assuming I have a Fortran 90 subroutine 
> calling a C function passing MPI_COMM_WORLD in, in the C function, do I 
> need to first do MPI_Comm_f2c
> to convert to MPI handle, then use that handle afterward? Or is there 
> any better way to do this? Here is some test code:
> 
> Fortran 90:
> 
>         program test1
> 
>         include 'mpif.h'
> 
>         integer myrank,ierr
> 
>         call MPI_Init(ierr)
> 
>         call parallel_info(myrank,MPI_COMM_WORLD)
>         write(*,*) 'hello, I am process #',myrank
> 
>         call MPI_Finalize(ierr)
> 
>         end program test1
> 
> 
> C:
> 
> #include <mpi.h>
> 
> void parallel_info_(int * rank, int* comm)
> {
>     MPI_Comm ccomm;
> 
>     ccomm=MPI_Comm_f2c(*comm);
>     MPI_Comm_rank(ccomm, rank);
> }
> 
> void parallel_info(int * rank, int * comm)
> {
>     MPI_Comm ccomm;
> 
>     ccomm=MPI_Comm_f2c(*comm);
> 
>     MPI_Comm_rank(ccomm, rank);
> }
> 
> 
> Thanks,
> Peng
> 
> 
> _______________________________________________
> users mailing list
> us...@open-mpi.org
> http://www.open-mpi.org/mailman/listinfo.cgi/users

Reply via email to