@@ -10,6 +10,8 @@ program mpi_pass
1010
1111implicit none
1212
13+ integer :: mpipasstype
14+
1315integer :: mcount, ierr
1416real :: dat(0 :99 ), val(200 )
1517integer :: dest, i, num_procs, id, tag
@@ -18,6 +20,16 @@ program mpi_pass
1820! type(MPI_STATUS) :: status
1921integer :: status (MPI_STATUS_SIZE)
2022
23+
24+ if (storage_size(dat) == 32 ) then
25+ mpipasstype = MPI_REAL
26+ else if (storage_size(dat) == 64 ) then
27+ mpipasstype = MPI_DOUBLE_PRECISION
28+ else
29+ error stop " Unsupported data type size"
30+ endif
31+
32+
2133call system_clock (tic)
2234
2335call MPI_Init(ierr)
@@ -44,12 +56,12 @@ program mpi_pass
4456select case (id)
4557case (0 )
4658 print * , id, " waiting for MPI_send() from image 1"
47- call MPI_Recv (val, size (val), MPI_REAL , MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, status, ierr)
59+ call MPI_Recv (val, size (val), mpipasstype , MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, status, ierr)
4860 if (ierr /= MPI_SUCCESS) error stop " MPI_Recv failed"
4961
5062 ! print '(i0,a,i0,a,i0)', id, ' Got data from processor ', status%MPI_SOURCE, ' tag ',status%MPI_TAG
5163
52- call MPI_Get_count(status, MPI_REAL , mcount, ierr)
64+ call MPI_Get_count(status, mpipasstype , mcount, ierr)
5365 if (ierr /= MPI_SUCCESS) error stop " MPI_Get_count failed"
5466
5567 print ' (i0,a,i0,a)' , id, ' Got ' , mcount, ' elements.'
@@ -64,7 +76,7 @@ program mpi_pass
6476
6577 dest = 0
6678 tag = 55
67- call MPI_Send(dat, size (dat), MPI_REAL , dest, tag, MPI_COMM_WORLD, ierr)
79+ call MPI_Send(dat, size (dat), mpipasstype , dest, tag, MPI_COMM_WORLD, ierr)
6880 if (ierr /= MPI_SUCCESS) error stop " MPI_Send failed"
6981
7082case default
0 commit comments