-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpiauxroutines.f90
executable file
·240 lines (177 loc) · 6.49 KB
/
mpiauxroutines.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! !
! FILE: HdfRoutines.F90 !
! CONTAINS: subroutines MPI* !
! !
! PURPOSE: Wrappers for MPI Routines !
! !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine MpiBcastInt(n)
use mpih
implicit none
integer, intent(inout) :: n
call MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
return
end subroutine MpiBcastInt
!==============================================================================
subroutine MpiBcastReal(n)
use mpih
implicit none
real, intent(inout) :: n
call MPI_BCAST(n,1,MDP,0,MPI_COMM_WORLD,ierr)
return
end subroutine MpiBcastReal
!==============================================================================
subroutine MpiBcastReal1DArray(var,sx)
use mpih
implicit none
integer, intent(in) :: sx
real, dimension(1:sx), intent(inout) :: var
call MPI_BCAST(var,sx,MDP,0,MPI_COMM_WORLD,ierr)
return
end subroutine MpiBcastReal1DArray
!==============================================================================
subroutine MpiBcastReal2DArray(var,sx,sy)
use mpih
implicit none
integer, intent(in) :: sx,sy
real, dimension(1:sx,1:sy), intent(inout) :: var
call MPI_BCAST(var,sx*sy,MDP,0,MPI_COMM_WORLD,ierr)
return
end subroutine MpiBcastReal2DArray
!==============================================================================
subroutine MpiBarrier
use mpih
implicit none
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
return
end subroutine MpiBarrier
!==============================================================================
subroutine MpiSumRealScalar(var)
use mpih
implicit none
real, intent(inout) :: var
real :: buf
call MPI_REDUCE(var,buf,1, &
MPI_DOUBLE_PRECISION,MPI_SUM,0,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiSumRealScalar
!==============================================================================
subroutine MpiAllSumRealScalar(var)
use mpih
implicit none
real, intent(inout) :: var
real :: buf
call MPI_ALLREDUCE(var,buf,1, &
MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiAllSumRealScalar
!==============================================================================
subroutine MpiAllSumIntScalar(var)
use mpih
implicit none
integer, intent(inout) :: var
integer :: buf
call MPI_ALLREDUCE(var,buf,1, &
MPI_INTEGER,MPI_SUM,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiAllSumIntScalar
!==============================================================================
subroutine MpiMaxRealScalar(var)
use mpih
implicit none
real, intent(inout) :: var
real :: buf
call MPI_REDUCE(var,buf,1, &
MPI_DOUBLE_PRECISION,MPI_MAX,0,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiMaxRealScalar
!==============================================================================
subroutine MpiAllMaxRealScalar(var)
use mpih
implicit none
real, intent(inout) :: var
real :: buf
call MPI_ALLREDUCE(var,buf,1, &
MPI_DOUBLE_PRECISION,MPI_MAX,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiAllMaxRealScalar
!==============================================================================
subroutine MpiAllMinRealScalar(var)
use mpih
implicit none
real, intent(inout) :: var
real :: buf
! call MPI_REDUCE(var,buf,1, &
! MPI_DOUBLE_PRECISION,MPI_MIN,0,MPI_COMM_WORLD,ierr)
call MPI_ALLREDUCE(var,buf,1, &
MPI_DOUBLE_PRECISION,MPI_MIN,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiAllMinRealScalar
!==============================================================================
subroutine MpiSumReal1D(var,sz)
use mpih
implicit none
integer, intent(in) :: sz
real, intent(inout), dimension(1:sz) :: var
real, dimension(1:sz) :: buf
call MPI_REDUCE(var,buf,sz, &
MPI_DOUBLE_PRECISION,MPI_SUM,0,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiSumReal1D
!==============================================================================
subroutine MpiAllSumReal1D(var,sz)
use mpih
implicit none
integer, intent(in) :: sz
real, intent(inout), dimension(1:sz) :: var
real, dimension(1:sz) :: buf
call MPI_ALLREDUCE(var,buf,sz, &
MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiAllSumReal1D
!==============================================================================
subroutine MpiAllSumReal2D(var,sx,sy)
use mpih
implicit none
integer, intent(in) :: sx,sy
real, intent(inout), dimension(1:sx,1:sy) :: var
real, dimension(1:sx,1:sy) :: buf
call MPI_ALLREDUCE(var,buf,sx*sy, &
MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)
var = buf
return
end subroutine MpiAllSumReal2D
!==============================================================================
subroutine MpiAbort
use mpih
implicit none
call MPI_ABORT(MPI_COMM_WORLD,1,ierr)
return
end subroutine MpiAbort
!==============================================================================
subroutine InitializeMPI
use mpih
use param, only: ismaster
implicit none
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,numtasks,ierr)
if(myid.eq.0) ismaster = .true.
return
end subroutine InitializeMPI
!==============================================================================
subroutine FinalizeMPI
use mpih
implicit none
call MPI_FINALIZE(ierr)
return
end subroutine FinalizeMPI