-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mpi_character.f90
52 lines (44 loc) · 1.07 KB
/
test_mpi_character.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
50
51
52
! DANG Truong
! 29-01-2017
PROGRAM TEST_MPI
IMPLICIT NONE
INCLUDE 'mpif.h'
CHARACTER(2) :: INIT_ARRAY(5)
CHARACTER(2) :: SD_ARRAY(5)
CHARACTER(2) :: RCV_ARRAY(5)
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)
INIT_ARRAY(1) = 'AA'
INIT_ARRAY(2) = 'BB'
INIT_ARRAY(3) = 'CC'
INIT_ARRAY(4) = 'DD'
INIT_ARRAY(5) = 'EE'
PRINT*,'Rank =', RANK
PRINT*,'Initial array:'
DO I = 1, 5
PRINT*,INIT_ARRAY(I)
ENDDO
PRINT*,'*********************'
IF (RANK==0) THEN
SD_ARRAY = INIT_ARRAY
CALL MPI_SEND(SD_ARRAY(1:5),10,MPI_CHARACTER,1,TAG,MPI_COMM_WORLD,IERR)
PRINT*,'RANK =',RANK
PRINT*,'SD_ARRAY ='
DO I = 1, 5
PRINT*, SD_ARRAY(I)
ENDDO
ELSEIF (RANK==1) THEN
CALL MPI_RECV(RCV_ARRAY(1:5),10,MPI_CHARACTER,0,TAG,MPI_COMM_WORLD,STATUS,IERR)
PRINT*,'RANK =',RANK
PRINT*,'RCV_ARRAY ='
DO I = 1, 5
PRINT*, RCV_ARRAY(I)
ENDDO
ENDIF
CALL MPI_FINALIZE(IERR)
STOP
END PROGRAM TEST_MPI