Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

From: Wang, Peng (pewang_at_[hidden])
Date: 2006-09-01 09:26:52


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