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

Hossein Beiramy beiramy_hossein at yahoo.com
Thu Apr 7 09:50:02 CDT 2011
















Dear all,
Is MPI developed for Fortran as well as C?



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 



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20110407/a1b7972d/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: array_of_data_type.pdf
Type: application/pdf
Size: 138434 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20110407/a1b7972d/attachment-0002.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MPI_Pack.pdf
Type: application/pdf
Size: 22935 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20110407/a1b7972d/attachment-0003.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: array_of_data_type.F90
Type: application/octet-stream
Size: 4816 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20110407/a1b7972d/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MPI_Pack.C
Type: text/x-csrc
Size: 880 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20110407/a1b7972d/attachment-0001.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MPI_Pack.f90
Type: application/octet-stream
Size: 922 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20110407/a1b7972d/attachment-0003.obj>


More information about the mpich-discuss mailing list