forked from csc-training/advanced-mpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskeleton.F90
74 lines (54 loc) · 1.81 KB
/
skeleton.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
program basic
use mpi_f08
use iso_fortran_env, only : REAL64
implicit none
integer, parameter :: size = 10000000
integer :: rc, myid, ntasks
integer :: message(size)
integer :: receiveBuffer(size)
integer :: status(MPI_STATUS_SIZE)
integer :: requests(2)
real(REAL64) :: t0, t1
integer :: source, destination
call mpi_init(rc)
call mpi_comm_rank(MPI_COMM_WORLD, myid, rc)
call mpi_comm_size(MPI_COMM_WORLD, ntasks, rc)
message = myid
! TODO: set source and destination ranks
! Treat boundaries with MPI_PROC_NULL
! You may utilize also Cartesian topology and MPI_Cart_shift
! instead manual determination
! end TODO
! Start measuring the time spent in communication
call mpi_barrier(mpi_comm_world, rc)
t0 = mpi_wtime()
! TODO: Send and receive messages
write(*,'(A10,I3,A20,I8,A,I3,A,I3)') 'Sender: ', myid, &
' Sent elements: ',size, &
'. Tag: ', myid+1, '. Receiver: ', destination
write(*,'(A10,I3,A,I3)') 'Receiver: ', myid, &
' First element: ', receiveBuffer(1)
! Finalize measuring the time and print it out
t1 = mpi_wtime()
call mpi_barrier(mpi_comm_world, rc)
call flush(6)
call print_ordered(t1 - t0)
call mpi_finalize(rc)
contains
subroutine print_ordered(t)
implicit none
real(REAL64) :: t
integer i
if (myid == 0) then
write(*, '(A20, I3, A, F6.3)') 'Time elapsed in rank', myid, ':', t
do i=1, ntasks-1
call mpi_recv(t, 1, MPI_DOUBLE_PRECISION, i, 11, &
MPI_COMM_WORLD, MPI_STATUS_IGNORE, rc)
write(*, '(A20, I3, A, F6.3)') 'Time elapsed in rank', i, ':', t
end do
else
call mpi_send(t, 1, MPI_DOUBLE_PRECISION, 0, 11, &
MPI_COMM_WORLD, rc)
end if
end subroutine print_ordered
end program basic