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

Jeff Hammond jhammond at mcs.anl.gov
Thu Apr 7 10:28:02 CDT 2011


PDF files are occasionally the basis for security exploits (e.g.
http://news.cnet.com/8301-1009_3-10168266-83.html).  Please use plain
text format at every opportunity.  If you need to attach a figure,
which seems not to be the case here, consider using Postscript (.ps)
or JPEG.

Thanks,

Jeff

On Thu, Apr 7, 2011 at 9:50 AM, Hossein Beiramy
<beiramy_hossein at yahoo.com> wrote:
>
>
> 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
>
>
> _______________________________________________
> mpich-discuss mailing list
> mpich-discuss at mcs.anl.gov
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
>

-- 
Jeff Hammond
Argonne Leadership Computing Facility
jhammond at alcf.anl.gov / (630) 252-5381
http://www.linkedin.com/in/jeffhammond


More information about the mpich-discuss mailing list