-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mpi_sendrcv_2d_array.f90
49 lines (42 loc) · 1.08 KB
/
test_mpi_sendrcv_2d_array.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
! DANG Truong
! 29-01-2017
PROGRAM TEST_MPI
IMPLICIT NONE
INCLUDE 'mpif.h'
REAL(8) :: INIT_ARRAY(10,2)
REAL(8) :: SD_ARRAY(10,2)
REAL(8) :: RCV_ARRAY(10,2)
INTEGER(4) :: IERR, RANK,TAG,COMM,NSIZE
INTEGER(4) :: STATUS(MPI_STATUS_SIZE)
INTEGER(4) :: I
CALL MPI_INIT(IERR)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD,NSIZE,IERR)
CALL MPI_COMM_RANK(MPI_COMM_WORLD,RANK,IERR)
CALL RANDOM_SEED
CALL RANDOM_NUMBER(INIT_ARRAY)
PRINT*,'Rank =', RANK
PRINT*,'Initial array:'
DO I = 1, 10
PRINT*,INIT_ARRAY(I,:)
ENDDO
PRINT*,'*********************'
CALL MPI_COMM_RANK(MPI_COMM_WORLD,RANK,IERR)
IF (RANK==0) THEN
SD_ARRAY = INIT_ARRAY
CALL MPI_SEND(SD_ARRAY(1:10,1:2),20,MPI_DOUBLE_PRECISION,1,TAG,MPI_COMM_WORLD,IERR)
PRINT*,'RANK =',RANK
PRINT*,'SD_ARRAY ='
DO I = 1, 10
PRINT*, SD_ARRAY(I,:)
ENDDO
ENDIF
IF (RANK==1) THEN
CALL MPI_RECV(RCV_ARRAY(1:10,1:2),20,MPI_DOUBLE_PRECISION,0,TAG,MPI_COMM_WORLD,STATUS,IERR)
PRINT*,'RANK =',RANK
PRINT*,'RCV_ARRAY ='
DO I = 1, 10
PRINT*, RCV_ARRAY(I,:)
ENDDO
ENDIF
CALL MPI_FINALIZE(IERR)
END PROGRAM TEST_MPI