Open MPI logo

Open MPI User's Mailing List Archives

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

Subject: Re: [OMPI users] Issue with Profiling Fortran code
From: George Bosilca (bosilca_at_[hidden])
Date: 2008-12-05 14:11:18


On Dec 5, 2008, at 03:16 , Anthony Chan wrote:

> void mpi_comm_rank_(MPI_Comm *comm, int *rank, int *info) {
> printf("mpi_comm_rank call successfully intercepted\n");
> *info = PMPI_Comm_rank(comm,rank);
> }

Unfortunately this example is not correct. The real Fortran prototype
for the MPI_Comm_rank function is
void mpi_comm_rank_(MPI_Fint *comm, MPI_Fint *rank, MPI_Fint *ierr).

As you might notice there is no MPI_Comm (and believe me for Open MPI
MPI_Comm is different than MPI_Fint), and there is no guarantee that
the C int is the same as the Fortran int (looks weird but true).
Therefore, several conversions are required in order to be able to go
from the Fortran layer into the C one.

As a result, a tool should never cross the language boundary by
itself. Instead it should call the pmpi function as provided by the
MPI library. This doesn't really fix the issue that started this email
thread, but at least clarify it a little bit.

   george.

>
> A.Chan
>
> ----- "Nick Wright" <nwright_at_[hidden]> wrote:
>
>> Hi
>>
>> I am trying to use the PMPI interface with OPENMPI to profile a
>> fortran
>> program.
>>
>> I have tried with 1.28 and 1.3rc1 with --enable-mpi-profile switched
>> on.
>>
>> The problem seems to be that if one eg. intercepts to call to
>> mpi_comm_rank_ (the fortran hook) then calls pmpi_comm_rank_ this
>> then
>>
>> calls MPI_Comm_rank (the C hook) not PMPI_Comm_rank as it should.
>>
>> So if one wants to create a library that can profile C and Fortran
>> codes
>> at the same time one ends up intercepting the mpi call twice. Which
>> is
>>
>> not desirable and not what should happen (and indeed doesn't happen
>> in
>>
>> other MPI implementations).
>>
>> A simple example to illustrate is below. If somebody knows of a fix
>> to
>>
>> avoid this issue that would be great !
>>
>> Thanks
>>
>> Nick.
>>
>> pmpi_test.c: mpicc pmpi_test.c -c
>>
>> #include<stdio.h>
>> #include "mpi.h"
>> void mpi_comm_rank_(MPI_Comm *comm, int *rank, int *info) {
>> printf("mpi_comm_rank call successfully intercepted\n");
>> pmpi_comm_rank_(comm,rank,info);
>> }
>> int MPI_Comm_rank(MPI_Comm comm, int *rank) {
>> printf("MPI_comm_rank call successfully intercepted\n");
>> PMPI_Comm_rank(comm,rank);
>> }
>>
>> hello_mpi.f: mpif77 hello_mpi.f pmpi_test.o
>>
>> program hello
>> implicit none
>> include 'mpif.h'
>> integer ierr
>> integer myid,nprocs
>> character*24 fdate,host
>> call MPI_Init( ierr )
>> myid=0
>> call mpi_comm_rank(MPI_COMM_WORLD, myid, ierr )
>> call mpi_comm_size(MPI_COMM_WORLD , nprocs, ierr )
>> call getenv('HOST',host)
>> write (*,*) 'Hello World from proc',myid,' out of',nprocs,host
>> call mpi_finalize(ierr)
>> end
>>
>>
>>
>> _______________________________________________
>> users mailing list
>> users_at_[hidden]
>> http://www.open-mpi.org/mailman/listinfo.cgi/users
> _______________________________________________
> users mailing list
> users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/users