[mpich-discuss] Is MPI developed for Fortran as well as C?

Anthony Chan chan at mcs.anl.gov
Thu Apr 7 11:06:00 CDT 2011



----- Original Message -----
> Dear all,
> Is MPI developed for Fortran as well as C?
> 

MPI standard defines a Fortran binding which is provided by MPICH2.
Do you have trouble in compiling/running the sample code or you have
trouble install MPICH2.

A.Chan

> 
> 
> I work on a Fortran project and I want to do massage passing works
> between nodes with MPI routines. I was able to send and receive simple
> arrays but for sending and receiving an array of data type, it did not
> work. In the attached files I have sent my previous Email that I had
> sent to MPICH Discuss mailing list. In the Email I have reported
> examination result of an example that I have gotten from Prof.
> zkovacs. In that Email someone else, also have discussed. Prof.
> zkovacs had wanted to send and receive an array of data type in C
> programming language. I want to do similar work in Fortran.
> 
> 
> 
> 
> 
> 
> Please give your opinion or in case that development of MPICH for
> Fortran is not completed, introduce other implementation of MPI for
> Fortran.
> Another question. I want to write equivalent code of following C code
> in Fortran. C code works truly but Fortran code does not. What is the
> problem?
> Attached files contain *.pdf file of previous Email and following
> example. Also source code files are attached.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> #include "mpi.h"
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main (int argc, char *argv[])
> {
> int position, i, j, a[2], myrank, num_proc;
> char buff[1000];
> MPI_Status stat;
> MPI_Init(&argc, &argv);
> MPI_Comm_size(MPI_COMM_WORLD, &num_proc );
> MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
> if (myrank == 0)
> {
> /* SENDER CODE */
> i = 1; j = 2; a[0] = 3;
> printf( "Proc %d: sending %u %u %u.th portion to proc 0.\n", myrank,
> i, j, a );
> position = 0;
> MPI_Pack(&i, 1, MPI_INT, buff, 1000, &position, MPI_COMM_WORLD);
> MPI_Pack(&j, 1, MPI_INT, buff, 1000, &position, MPI_COMM_WORLD);
> MPI_Send( buff, position, MPI_PACKED, 1, 0, MPI_COMM_WORLD);
> }
> else /* RECEIVER CODE */
> {
> MPI_Recv( a, 2, MPI_INT, 0, 0, MPI_COMM_WORLD,&stat);
> printf( "Proc %d: reciving %u %u %u.th portion to proc 0.\n", myrank,
> i, j, a[0] );
> }
> MPI_Finalize();
> return 0;
> }
> 
> 
> 
> program main
> implicit none
> include 'mpif.h'
> integer a(0:1)
> integer position, i, j, a(0:1), rank, numtasks;
> character buff(0:1000);
> integer stat(MPI_STATUS_SIZE)
> call MPI_INIT(ierr)
> call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
> call MPI_COMM_SIZE(MPI_COMM_WORLD, numtasks, ierr)
> if (rank == 0) then
> !/* SENDER CODE */
> position = 0;
> i=1;j=2;
> CALL MPI_Pack(i, 1, MPI_INTEGER, buff, 1000, position, MPI_COMM_WORLD,
> ierr);
> CALL MPI_Pack(j, 1, MPI_INTEGER, buff, 1000, position, MPI_COMM_WORLD,
> ierr);
> CALL MPI_Send( buff, position, MPI_PACKED, 1, 0, MPI_COMM_WORLD,
> ierr);
> else !/* RECEIVER CODE */
> CALL MPI_Recv( a, 2, MPI_INTEGER, 0, 0, MPI_COMM_WORLD, ierr);
> position = 0;
> CALL MPI_Unpack(a, 2, position, i, 1, MPI_INTEGER, MPI_COMM_WORLD,
> ierr);
> CALL MPI_Unpack(a, 2, position, j, 1, MPI_INTEGER, MPI_COMM_WORLD,
> ierr);
> Write(*,*) 'i , j = ' , i,j
> END IF
> call MPI_FINALIZE(ierr)
> end program main
> 
> 
> 
> Best Regards,
> --
> Hossein Beyrami
> 
> 
> 
> 
> _______________________________________________
> mpich-discuss mailing list
> mpich-discuss at mcs.anl.gov
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss


More information about the mpich-discuss mailing list