Newsgroups: comp.parallel.mpi
From: "A. Bose" <abose@cfdlab.ae.utexas.edu>
Subject: Q: mising C/C++ with Fortran in MPI
Organization: The University of Texas at Austin - CFD Lab
Date: Fri, 12 Jul 1996 12:29:42 -0500
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <31E68B86.212E90AD@cfdlab.ae.utexas.edu>

Hi,

I have a need to use a mixed language model for development
of a large software. Most of the code (at least the data structure/
setup portion) is written in C++ while some of the numerically
intensive calculations are accomplished by calling vectorized
Fortran routines. My job is to make the code parallel.  I would like
to initialize MPI in the C++ portion of the code. For example,

C++/C Code
-----------

#include "mpi.h"
#include  <otherfiles.h...>

#include "FotranDefs.h"       // defines all fortran routines as extern
                              // "C" function calls and pads data etc.
                              // according to C-Fortran protocols.  

main( )
{
   int n, myid, numprocs;
    MPI_Init( );
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &myid);

    if (myid == 0 ) {

           // calling some Fortran routine to do a broadcast 

                    MyFortranSub(&n, &myid); }
                    
    MPI_Finalize( );
}

Fortran Code
------------

        subroutine MyFortranSub(n, myid)

        include "mpif.h"
        integer  n, myid
        real*8   start
        start = MPI_WTIME( )
        call MPI_BCAST(n,1,MPI_INTEGER, 0 , MPI_COMM_WORLD, ierr)
        return
        end


Comments
----------

In the above example, C++ portion isn't really doing anything as far as
MPI is concerned so I could as well initiate MPI from within the 
Fortran call. But, in the real application, C++ portion of the code
will use MPI to set up the data structure and scatter some  arrays
across the processors. So I do have to initialize MPI from the C++ main. 

I will appreciate if any of you can shed some light into this aspect. I
believe that more and more applications with mixed language models will
have to be ported on to parallel machines in the near future so this 
should be an important topic to discuss. Thanks, in advance.

A.Bose
CFD Lab, UT-Austin.

