program nasa_ex2 !-- Template for any mpi program ! Starting from template.f, write a program that given a !common value of x (e.g. x=5 in all processes), computes: ! * y=x2 in process 0 ! * y=x3 in process 1 ! * y=x4 in process 2 ! and writes a statement from each process that identifies the !process and reports the values of x and y from that process. !--Include the mpi header file use mpi implicit none ! highly recommended. It will make ! debugging infinitely easier. !--Declare all variables and arrays. integer :: ierr,myid,numprocs,itag integer :: irc real :: x,y !--Initialize MPI call MPI_INIT( ierr ) ! --> Required statement !--Who am I? --- get my rank=myid call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr ) !--How many processes in the global group? call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr ) !set the value of x on all processors x=5 ! compute based which proc I am if (myid == 0) then y=x**2 else if (myid == 1) then y=x**3 else if (myid == 2) then y=x**4 end if !-- print y write(*,*)'On process ',myid,' x=',x,', y=',y !--Finalize MPI call MPI_FINALIZE(irc) ! ---> Required statement stop end