program main c*********************************************************************72 c cc MAIN is the main program for BONES. c c Discussion: c c BONES is a simple demonstration of the use of MPI by an F77 program. c c This program should be run on at least two processes. c Only the first two processes will actually get any work to do. c c Licensing: c c This code is distributed under the GNU LGPL license. c c Modified: c c 03 October 2005 c c Author: c c John Burkardt c c Reference: c c William Gropp, Ewing Lusk, Anthony Skjellum, c Using MPI: Portable Parallel Programming with the c Message-Passing Interface, c Second Edition, c MIT Press, 1999, c ISBN: 0262571323, c LC: QA76.642.G76. c c Marc Snir, Steve Otto, Steven Huss-Lederman, David Walker, c Jack Dongarra, c MPI: The Complete Reference, c Volume I: The MPI Core, c Second Edition, c MIT Press, 1998, c ISBN: 0-262-69216-3, c LC: QA76.642.M65. c include 'mpif.h' integer count real data(0:99) integer dest integer i integer ierr integer num_procs integer rank integer status(MPI_Status_size) integer tag real value(200) c c Initialize MPI. c call MPI_Init ( ierr ) c c Determine this process's rank. c call MPI_Comm_rank ( MPI_COMM_WORLD, rank, ierr ) c c Have Process 0 say hello. c if ( rank .eq. 0 ) then call MPI_Comm_size ( MPI_COMM_WORLD, num_procs, ierr ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'BONES:' write ( *, '(a)' ) ' FORTRAN77 version' write ( *, '(a)' ) ' A simple MPI test.' write ( *, '(a,i6)' ) & ' The number of processes available is ', num_procs end if c c Process 0 expects to receive as much as 200 real values, c from any source. c if ( rank .eq. 0 ) then tag = 55 call MPI_Recv ( value, 200, MPI_REAL, MPI_ANY_SOURCE, tag, & MPI_COMM_WORLD, status, ierr ) write ( *, '(a,i1,a,i1)' ) 'P:', rank, & ' Got data from processor ', status(MPI_SOURCE) call MPI_Get_count ( status, MPI_REAL, count, ierr ) write ( *, '(a,i1,a,i3,a)' ) 'P:', rank, ' Got ', & count, ' elements.' write ( *, '(a,i1,a,g14.6)' ) 'P:', rank, & ' value(5) = ', value(5) c c Process 1 sends 100 real values to process 0. c else if ( rank .eq. 1 ) then write ( *, '(a)' ) ' ' write ( *, '(a,i1,a)' ) 'P:', rank, & ' - setting up data to send to process 0.' do i = 0, 99 data(i) = real ( i ) end do dest = 0 tag = 55 call MPI_Send ( data, 100, MPI_REAL, dest, tag, & MPI_COMM_WORLD, ierr ) else write ( *, '(a)' ) ' ' write ( *, '(a,i1,a)' ) 'P:', rank, & ' - MPI has no work for me!' end if call MPI_Finalize ( ierr ) if ( rank .eq. 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'BONES:' write ( *, '(a)' ) ' Normal end of execution.' end if stop end