[mpich-discuss] How does the fortran binding work?

Ruini Xue xueruini at gmail.com
Thu Jul 31 08:46:22 CDT 2008


On Wed, Jul 30, 2008 at 11:54 PM, Jayesh Krishna <jayesh at mcs.anl.gov> wrote:
>  Hi,
>   In MPICH2 implementation on windows the fortran bindings work as below,
>
> 1) Fortran bindings (see src/binding/f77/*) are wrapper funcs which do
> minimal work and call PMPI_* funcs to do the real work (This is done by
> fmpich2.dll).
>
> 2) PMPI_* (read as "Profiling"MPI_* -- check the standard,
> http://www.mpi-forum.org/docs/mpi-11-html/mpi-report.html, for more
> information on the MPI Profiling interface ) are defined to be MPI_*
> functions if no profiling library (MPE -- see section "Runtime
> environment"--> "Performance Analysis" in the windows developer's guide,
> available at
> http://www.mcs.anl.gov/research/projects/mpich2/documentation/index.php?s=docs,
> for information on how you can use MPE with your programs) is provided or
> are defined as PMPI_* functions when a profiling library is provided. (This
> is done by mpich2mpi.dll)
>
> 3) Either the profiling library (mpe.dll) or the windows binding library
> (mpich2mpi.dll) calls the MPI_* functions defined in mpich2.dll (for single
> threaded sock channel - in case of other channels variants of mpich2.dll) to
> do the real work.
>
>  Let us know if you have any questions.
After going through the source today, I got a deep understand how
these three DLLs work together:
- fmpich2.dll: the Fortran binding, it calls PMPI version in mpich2mpi.dll.

- mpich2mpi.dll: the "windows" c binding. This dll is very
interesting. It exports all MPI_* and PMPI_* functions, and contains a
big function pointer struct holding all standard MPI_* and PMPI_*
interface. This dll is loaded if your application is linked with the
default mpi.lib.  It  would load mpich2.dll dynamically to map the
function pointers to the corresponding functions in mpich2.dll. The
codes seem like this (src/ util/ multichannel/mpi.c):
//////////////////////////
static struct fn_table
{
int (*MPI_Send)(void*, int, MPI_Datatype, int, int, MPI_Comm);
int (*PMPI_Send)(void*, int, MPI_Datatype, int, int, MPI_Comm);
.....
};

#define MPICH_CHECK_INIT(a) if ((fn. a) == NULL && LoadMPILibrary() ==
FALSE) return MPI_ERR_INTERN;

#undef FCNAME
#define FCNAME MPI_Send
int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag,
	     MPI_Comm comm)
{
    MPICH_CHECK_INIT(FCNAME);
    return fn.MPI_Send(buf, count, datatype, dest, tag, comm);
}
/////////////////////////////////////

It is clear that mpich2mpi.dll has its own MPI_* and PMPI_*, and they
are simple wrappers to the functions in mpich2.dll.
mpich2.dll is loaded by LoadMPILibrary() which is called by the first
MPI call (since LoadLibrary() is not allowed in DllMain).

- mpich2.dll: the real worker also the real c binding (for socket
implementation). It contains real implementation of PMPI_*, and
  MPI_* are weakly defined to them.

Now, we can understand why a fortran application need fmpich2.dll and
mpich2mpi.dll, and a c application needs only mpich2mpi.dll, but
none of them explicitly depends on mpich2.dll.

PS, why I dive so deep into these dlls is because I am working on a
MPI replay project, which use binary instrumentation to hook MPI
calls. Therefore, I want to make sure who is the most underlying
worker. Now, I want to know whether I am right. :)

Best

Andrew

>
> (PS: This is different from the way its handled in MPICH2 on unix.)
>
> Regards,
> Jayesh
>
> -----Original Message-----
> From: owner-mpich-discuss at mcs.anl.gov
> [mailto:owner-mpich-discuss at mcs.anl.gov] On Behalf Of Anthony Chan
> Sent: Wednesday, July 30, 2008 9:46 AM
> To: mpich-discuss at mcs.anl.gov
> Cc: mpich-discuss at mcs.anl.gov
> Subject: Re: [mpich-discuss] How does the fortran binding work?
>
>
> No.  PMPI is the MPI profiling interface and is standardized by the MPI
> forum.
> Fortran/C++ MPI binding just calls the C MPI routine.
>
> A.Chan
>
> ----- "Ruini Xue" <xueruini at gmail.com> wrote:
>
>> On Wed, Jul 30, 2008 at 8:54 PM, Dave Goodell < goodell at mcs.anl.gov >
>> wrote:
>>
>>
>> Hi Andrew,
>>
>> Yes, the fortran and c++ bindings are just wrappers over the C
>> bindings. The C binding implements the functionality directly.
>>
>> Are they wrappers of MPI_XXX() or PMPI_XXX()?
>>
>> Best
>>
>> Andrew
>>
>>
>>
>>
>> -Dave
>>
>>
>>
>>
>> On Jul 30, 2008, at 6:11 AM, Ruini Xue wrote:
>>
>>
>>
>> Hello, everyone,
>>
>> I am working with MPICH2 on Windows platfrom. The fortran MIP
>> application is linked to fmpich.lib, and fmpich2.dll is loaded in
>> runtime, which in turn loads mipch2mpi.dll.
>> mpich2mpi.dll contains all MPI APIs which exported C interface. What I
>> want to know is: what is the 'underlying' relation between fmpich2.dll
>> and mpich2mip.dll? Do all Fortran MPI calls are converted to c
>> bindings in mpich2mpi.dll? For example, does MPI_BCAST() in fmich2.dll
>> directly calls MPI_Bcast() in mpich2mpi.dll? Is MPI_BCAST() just a
>> stub while MPI_Bcast() do the real job?
>>
>> Thanks
>>
>> Andrew
>
>




More information about the mpich-discuss mailing list