Octopus
mpi_debug.F90
Go to the documentation of this file.
1!! Copyright (C) 2005-2006 Heiko Appel, Florian Lorenzen
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19! Routines to support MPI debugging.
20
21#include "global.h"
22
23module mpi_debug_oct_m
24#ifdef HAVE_MPI
25 use mpi_f08
26#else
28#endif
29 use, intrinsic :: iso_fortran_env
30 use loct_oct_m
31
32 implicit none
33
34 private
35
36 public :: &
41
42 integer, parameter :: C_NUM_MPI_ROUTINES = 12
43
44 integer, public, parameter :: &
45 C_MPI_BARRIER = 1, &
46 c_mpi_scatterv = 2, &
47 c_mpi_gatherv = 3, &
48 c_mpi_gather = 4, &
49 c_mpi_alltoallv = 5, &
50 c_mpi_allgatherv = 6, &
51 c_mpi_bcast = 7, &
52 c_mpi_allreduce = 8, &
53 c_mpi_alltoall = 9, &
54 c_mpi_allgather = 10, &
55 c_mpi_file_read = 11, &
57
58 character(len=14), dimension(C_NUM_MPI_ROUTINES), public :: mpi_rlabel = &
59 (/ &
60 'MPI_BARRIER ', &
61 'MPI_SCATTERV ', &
62 'MPI_GATHERV ', &
63 'MPI_GATHER ', &
64 'MPI_ALLTOALLV ', &
65 'MPI_ALLGATHERV', &
66 'MPI_BCAST ', &
67 'MPI_ALLREDUCE ', &
68 'MPI_ALLTOALL ', &
69 'MPI_ALLGATHER ', &
70 'MPI_FILE_READ ', &
71 'MPI_FILE_WRITE' &
72 /)
73
74 integer, public :: call_counter(C_NUM_MPI_ROUTINES) = 0
75 real(real64), public :: sec_accum(C_NUM_MPI_ROUTINES) = 0_real64
76
77 real(real64) :: sec_in
78
79 logical :: debug_info
80 integer :: mpi_rank
81
83 integer, parameter :: unit_offset = 1000
84
85contains
86
87 ! ---------------------------------------------------------
88 subroutine mpi_debug_init(rank, info)
89 integer, intent(in) :: rank
90 logical, intent(in) :: info
91
92 mpi_rank = rank
93 debug_info = info
94 end subroutine mpi_debug_init
95
96 ! ---------------------------------------------------------
97 subroutine mpi_debug_open_trace(iunit)
98 integer, intent(out) :: iunit
99
100 character(len=6) :: filenum
101
102 iunit = mpi_rank + unit_offset
103 write(filenum, '(i6.6)') iunit - unit_offset
104 call loct_mkdir('debug')
105 open(iunit, file = 'debug/debug_trace.node.'//filenum, &
106 action='write', status='unknown', position='append')
107
108 end subroutine mpi_debug_open_trace
109
110 ! ---------------------------------------------------------
111 subroutine mpi_debug_statistics()
112#if defined(HAVE_MPI)
113 integer :: j, iunit
114 real(real64) :: usec_call(C_NUM_MPI_ROUTINES)
115#endif
117 if (.not. debug_info) return
118#if defined(HAVE_MPI)
119
120 call mpi_debug_open_trace(iunit)
121
122 write(iunit,*)
123 write(iunit,'(A)') '--------------------------------------------------------------------'
124 write(iunit,*)
125 write(iunit, '(23x,a,4x,a,8x,a)') 'total time', 'calls', 'usec/call'
126 do j = 1, c_num_mpi_routines
127 if (call_counter(j) <= 0) then
128 usec_call(j) = 0
129 else
130 usec_call(j) = (sec_accum(j)*1000000)/call_counter(j)
131 end if
132
133 write(iunit,'(a,f13.6,6x,i4,6x,f13.0)') &
134 mpi_rlabel(j)//' : ', sec_accum(j), &
135 call_counter(j), usec_call(j)
136 end do
137 write(iunit,*)
138 write(iunit,'(A)') '--------------------------------------------------------------------'
139
140 close(iunit)
141#endif
142
143 end subroutine mpi_debug_statistics
144
145
146 ! ---------------------------------------------------------
147 subroutine mpi_debug_in(comm, index)
148 type(mpi_comm), intent(in) :: comm
149 integer, intent(in) :: index
150
151 integer :: iunit
152
153 if (.not. debug_info) return
154
155 call mpi_debug_open_trace(iunit)
156
157 call_counter(index) = call_counter(index) + 1
158#if defined(HAVE_MPI)
159 sec_in = mpi_wtime()
160#endif
161 write(iunit,'(a,f18.6,a,z8.8,a,i6.6,a,f13.6)') '* MPI_I ', &
162 sec_in, ' '//mpi_rlabel(index)//' : 0x', comm%MPI_VAL, ' | ', &
163 call_counter(index), ' - ', sec_accum(index)
164
165 close(iunit)
166
167 end subroutine mpi_debug_in
169
170 ! ---------------------------------------------------------
171 subroutine mpi_debug_out(comm, index)
172 type(mpi_comm), intent(in) :: comm
173 integer, intent(in) :: index
174
175 integer :: iunit
176 real(real64) :: sec_out, sec_diff
177
178 if (.not. debug_info) return
179
180 call mpi_debug_open_trace(iunit)
182#if defined(HAVE_MPI)
183 sec_out = mpi_wtime()
184#endif
185 call mpi_time_accum(index, sec_out, sec_diff)
186 write(iunit,'(a,f18.6,a,z8.8,a,i6.6,a,f13.6,a,f13.6)') &
187 '* MPI_O ', sec_out, ' '//mpi_rlabel(index)//' : 0x', comm%MPI_VAL, ' | ', &
188 call_counter(index), ' - ', sec_accum(index), ' - ', sec_diff
189
190 close(iunit)
191
192 end subroutine mpi_debug_out
193
194
195 ! ---------------------------------------------------------
196 subroutine mpi_time_accum(index, sec, sec_diff)
197 integer, intent(in) :: index
198 real(real64), intent(in) :: sec
199 real(real64), intent(out) :: sec_diff
200
201 sec_diff = sec - sec_in
202 sec_accum(index) = sec_accum(index) + sec_diff
203
204 end subroutine mpi_time_accum
205
206end module mpi_debug_oct_m
207
208
209!! Local Variables:
210!! mode: f90
211!! coding: utf-8
212!! End:
File-handling.
Definition: loct.F90:216
subroutine mpi_time_accum(index, sec, sec_diff)
Definition: mpi_debug.F90:290
integer, parameter, public c_mpi_allgatherv
Definition: mpi_debug.F90:137
integer, parameter, public c_mpi_allreduce
Definition: mpi_debug.F90:137
integer, parameter, public c_mpi_gatherv
Definition: mpi_debug.F90:137
integer, parameter, public c_mpi_file_read
Definition: mpi_debug.F90:137
subroutine, public mpi_debug_init(rank, info)
Definition: mpi_debug.F90:182
integer, parameter, public c_mpi_scatterv
Definition: mpi_debug.F90:137
subroutine, public mpi_debug_in(comm, index)
Definition: mpi_debug.F90:241
integer, parameter, public c_mpi_allgather
Definition: mpi_debug.F90:137
subroutine, public mpi_debug_statistics()
Definition: mpi_debug.F90:205
integer, parameter, public c_mpi_bcast
Definition: mpi_debug.F90:137
integer, parameter, public c_mpi_alltoallv
Definition: mpi_debug.F90:137
integer, parameter, public c_mpi_gather
Definition: mpi_debug.F90:137
subroutine, public mpi_debug_out(comm, index)
Definition: mpi_debug.F90:265
subroutine mpi_debug_open_trace(iunit)
Definition: mpi_debug.F90:191
integer, parameter, public c_mpi_alltoall
Definition: mpi_debug.F90:137
integer, parameter, public c_mpi_file_write
Definition: mpi_debug.F90:137