-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoverlap_nb.f90
83 lines (63 loc) · 2.26 KB
/
overlap_nb.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
program nb_overlap
use mpi
use iso_fortran_env, only : real64
implicit none
integer :: i,me,np,n,tmp
integer :: req,ierr
integer :: status(MPI_STATUS_SIZE)
real(real64), allocatable :: x(:),y(:)
real(real64) :: start_time, end_time
n = 100000
allocate(x(n),y(n))
call MPI_Init(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,me,ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,np,ierr)
! Send/Recv to start communication
if(me == 0) call MPI_Send(me,1,MPI_INT,np-1,0,MPI_COMM_WORLD,ierr)
if(me == np-1) call MPI_Recv(tmp,1,MPI_INT,0,0,MPI_COMM_WORLD,status,ierr)
do i=1,n
x(i) = real(i,kind=real64)
enddo
y = 0.0d0
if(me == np-1) then
call MPI_Irecv(y, n, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, req, ierr)
endif
call MPI_Barrier(MPI_COMM_WORLD,ierr)
if(me == 0) then
start_time = MPI_Wtime()
call MPI_Isend(x, n, MPI_DOUBLE, np-1, 0 ,MPI_COMM_WORLD, req, ierr)
call sleep(2)
call MPI_Wait(req,status,ierr)
end_time = MPI_Wtime()
write(*,*) "Process",me,"spent",end_time-start_time,"seconds processing and sending data (2 seconds for computation)"
else if(me == np-1) then
start_time = MPI_Wtime()
call MPI_Wait(req,status,ierr)
end_time = MPI_Wtime()
write(*,*) "Process",me,"spent",end_time-start_time,"seconds waiting"
write(*,*) "Value received y(10)=",y(10),". Expected",10.0
endif
call MPI_Barrier(MPI_COMM_WORLD,ierr)
y = 0.0d0
if(me == np-1) then
call MPI_Irecv(y, n, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, req, ierr)
endif
if(me == 0) write(*,*) 'Second transfer'
call MPI_Barrier(MPI_COMM_WORLD,ierr)
if(me == 0) then
start_time = MPI_Wtime()
call MPI_Isend(x, n, MPI_DOUBLE, np-1, 0 ,MPI_COMM_WORLD, req, ierr)
call sleep(2)
call MPI_Wait(req,status,ierr)
end_time = MPI_Wtime()
write(*,*) "Process",me,"spent",end_time-start_time,"seconds processing and sending data (2 seconds for computation)"
else if(me == np-1) then
start_time = MPI_Wtime()
call MPI_Wait(req,status,ierr)
end_time = MPI_Wtime()
write(*,*) "Process",me,"spent",end_time-start_time,"seconds waiting"
write(*,*) "Value received y(10)=",y(10),". Expected",10.0
endif
call MPI_Barrier(MPI_COMM_WORLD,ierr)
call MPI_Finalize(ierr)
end program nb_overlap