-
Notifications
You must be signed in to change notification settings - Fork 0
/
diffuse.f90
168 lines (135 loc) · 6.4 KB
/
diffuse.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
!Crown Copyright 2014 AWE.
!
! This file is part of TeaLeaf.
!
! TeaLeaf is free software: you can redistribute it and/or modify it under
! the terms of the GNU General Public License as published by the
! Free Software Foundation, either version 3 of the License, or (at your option)
! any later version.
!
! TeaLeaf is distributed in the hope that it will be useful, but
! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
! FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
! details.
!
! You should have received a copy of the GNU General Public License along with
! TeaLeaf. If not, see http://www.gnu.org/licenses/.
!> @brief Controls the main diffusion cycle.
!> @author David Beckingsale, Wayne Gaudin
!> @details Controls the top level cycle, invoking all the drivers and checks
!> for outputs and completion.
SUBROUTINE diffuse
USE tea_module
USE timestep_module
USE tea_leaf_module
IMPLICIT NONE
INTEGER :: loc(1)
REAL(KIND=8) :: timer,timerstart,wall_clock,step_clock
REAL(KIND=8) :: grind_time,cells,rstep
REAL(KIND=8) :: step_time,step_grind
REAL(KIND=8) :: first_step,second_step
REAL(KIND=8) :: kernel_total,totals(parallel%max_task)
timerstart = timer()
second_step=0.0 ! In order to prevent unused error
DO
step_time = timer()
step = step + 1
CALL timestep()
CALL tea_leaf()
time = time + dt
IF(summary_frequency.NE.0) THEN
IF(MOD(step, summary_frequency).EQ.0) CALL field_summary()
ENDIF
IF(visit_frequency.NE.0) THEN
IF(MOD(step, visit_frequency).EQ.0) CALL visit()
ENDIF
! Sometimes there can be a significant start up cost that appears in the first step.
! Sometimes it is due to the number of MPI tasks, or OpenCL kernel compilation.
! On the short test runs, this can skew the results, so should be taken into account
! in recorded run times.
IF(step.EQ.1) first_step=(timer() - step_time)
IF(step.EQ.2) second_step=(timer() - step_time)
IF (parallel%boss) THEN
wall_clock=timer()-timerstart
step_clock=timer()-step_time
WRITE(g_out,*)"Wall clock ",wall_clock
WRITE(0 ,*)"Wall clock ",wall_clock
cells = grid%x_cells * grid%y_cells
rstep = step
grind_time = wall_clock/(rstep * cells)
step_grind = step_clock/cells
WRITE(0 ,*)"Average time per cell ",grind_time
WRITE(g_out,*)"Average time per cell ",grind_time
WRITE(0 ,*)"Step time per cell ",step_grind
WRITE(g_out,*)"Step time per cell ",step_grind
END IF
IF(time+g_small.GT.end_time.OR.step.GE.end_step) THEN
complete=.TRUE.
CALL field_summary()
IF(visit_frequency.NE.0) CALL visit()
wall_clock=timer() - timerstart
IF ( parallel%boss ) THEN
WRITE(g_out,*)
WRITE(g_out,*) 'Calculation complete'
WRITE(g_out,*) 'Tea is finishing'
WRITE(g_out,*) 'First step overhead', first_step-second_step
WRITE(g_out,*) 'Wall clock ', wall_clock
WRITE( 0,*) 'First step overhead', first_step-second_step
WRITE( 0,*) 'Wall clock ', wall_clock
ENDIF
EXIT
ENDIF
ENDDO
IF ( profiler_on ) THEN
! First we need to find the maximum kernel time for each task. This
! seems to work better than finding the maximum time for each kernel and
! adding it up, which always gives over 100%. I think this is because it
! does not take into account compute overlaps before syncronisations
! caused by halo exhanges.
kernel_total=profiler%timestep+profiler%halo_exchange+profiler%summary+profiler%visit+&
profiler%tea_init+profiler%set_field+profiler%tea_solve+profiler%tea_reset+profiler%dot_product+&
profiler%halo_update
CALL tea_allgather(kernel_total,totals)
! So then what I do is use the individual kernel times for the
! maximum kernel time task for the profile print
loc=MAXLOC(totals)
kernel_total=totals(loc(1))
CALL tea_allgather(profiler%timestep,totals)
profiler%timestep=totals(loc(1))
CALL tea_allgather(profiler%halo_exchange,totals)
profiler%halo_exchange=totals(loc(1))
CALL tea_allgather(profiler%halo_update,totals)
profiler%halo_update=totals(loc(1))
CALL tea_allgather(profiler%summary,totals)
profiler%summary=totals(loc(1))
CALL tea_allgather(profiler%dot_product,totals)
profiler%dot_product=totals(loc(1))
CALL tea_allgather(profiler%visit,totals)
profiler%visit=totals(loc(1))
CALL tea_allgather(profiler%tea_init,totals)
profiler%tea_init=totals(loc(1))
CALL tea_allgather(profiler%tea_solve,totals)
profiler%tea_solve=totals(loc(1))
CALL tea_allgather(profiler%tea_reset,totals)
profiler%tea_reset=totals(loc(1))
CALL tea_allgather(profiler%set_field,totals)
profiler%set_field=totals(loc(1))
IF ( parallel%boss ) THEN
WRITE(g_out,*)
WRITE(g_out,'(a58,2f16.4)')"Profiler Output Time Percentage"
WRITE(g_out,'(a23,2f16.4)')"Timestep :",profiler%timestep,100.0*(profiler%timestep/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"MPI Halo Exchange :",profiler%halo_exchange,100.0*(profiler%halo_exchange/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Self Halo Update :",profiler%halo_update,100.0*(profiler%halo_update/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Summary :",profiler%summary,100.0*(profiler%summary/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Visit :",profiler%visit,100.0*(profiler%visit/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Tea Init :",profiler%tea_init,100.0*(profiler%tea_init/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Dot Product :",profiler%dot_product,100.0*(profiler%dot_product/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Tea Solve :",profiler%tea_solve,100.0*(profiler%tea_solve/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Tea Reset :",profiler%tea_reset,100.0*(profiler%tea_reset/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Set Field :",profiler%set_field,100.0*(profiler%set_field/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"Total :",kernel_total,100.0*(kernel_total/wall_clock)
WRITE(g_out,'(a23,2f16.4)')"The Rest :",wall_clock-kernel_total,100.0*(wall_clock-kernel_total)/wall_clock
ENDIF
ENDIF
CALL tea_finalize
END SUBROUTINE diffuse