1 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
2 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
3 | !----------------------------------------------------------------------- |
---|
4 | ! CVS m_AttrVectReduce.F90,v 1.17 2008-05-12 01:46:11 jacob Exp |
---|
5 | ! CVS MCT_2_8_0 |
---|
6 | !BOP ------------------------------------------------------------------- |
---|
7 | ! |
---|
8 | ! !MODULE: m_AttrVectReduce - Local/Distributed AttrVect Reduction Ops. |
---|
9 | ! |
---|
10 | ! !DESCRIPTION: This module provides routines to perform reductions on |
---|
11 | ! the {\tt AttrVect} datatype. These reductions can either be the types |
---|
12 | ! of operations supported by MPI (currently, summation, minimum and |
---|
13 | ! maximum are available) that are applied either to all the attributes |
---|
14 | ! (both integer and real), or specific reductions applicable only to the |
---|
15 | ! real attributes of an {\tt AttrVect}. This module provides services |
---|
16 | ! for both local (i.e., one address space) and global (distributed) |
---|
17 | ! reductions. The type of reduction is defined through use of one of |
---|
18 | ! the public data members of this module: |
---|
19 | !\begin{table}[htbp] |
---|
20 | !\begin{center} |
---|
21 | !\begin{tabular}{|c|c|} |
---|
22 | !\hline |
---|
23 | !{\bf Value} & {\bf Action} \\ |
---|
24 | !\hline |
---|
25 | !{\tt AttrVectSUM} & Sum \\ |
---|
26 | !\hline |
---|
27 | !{\tt AttrVectMIN} & Minimum \\ |
---|
28 | !\hline |
---|
29 | !{\tt AttrVectMAX} & Maximum \\ |
---|
30 | !\hline |
---|
31 | !\end{tabular} |
---|
32 | !\end{center} |
---|
33 | !\end{table} |
---|
34 | ! |
---|
35 | ! !INTERFACE: |
---|
36 | |
---|
37 | module m_AttrVectReduce |
---|
38 | ! |
---|
39 | ! !USES: |
---|
40 | ! |
---|
41 | ! No modules are used in the declaration section of this module. |
---|
42 | |
---|
43 | implicit none |
---|
44 | |
---|
45 | private ! except |
---|
46 | |
---|
47 | ! !PUBLIC MEMBER FUNCTIONS: |
---|
48 | |
---|
49 | public :: LocalReduce ! Local reduction of all attributes |
---|
50 | public :: LocalReduceRAttr ! Local reduction of REAL attributes |
---|
51 | public :: AllReduce ! AllReduce for distributed AttrVect |
---|
52 | public :: GlobalReduce ! Local Reduce followed by AllReduce |
---|
53 | public :: LocalWeightedSumRAttr ! Local weighted sum of |
---|
54 | ! REAL attributes |
---|
55 | public :: GlobalWeightedSumRAttr ! Global weighted sum of REAL |
---|
56 | ! attributes for a distrubuted |
---|
57 | ! AttrVect |
---|
58 | |
---|
59 | interface LocalReduce ; module procedure LocalReduce_ ; end interface |
---|
60 | interface LocalReduceRAttr |
---|
61 | module procedure LocalReduceRAttr_ |
---|
62 | end interface |
---|
63 | interface AllReduce |
---|
64 | module procedure AllReduce_ |
---|
65 | end interface |
---|
66 | interface GlobalReduce |
---|
67 | module procedure GlobalReduce_ |
---|
68 | end interface |
---|
69 | interface LocalWeightedSumRAttr; module procedure & |
---|
70 | LocalWeightedSumRAttrSP_, & |
---|
71 | LocalWeightedSumRAttrDP_ |
---|
72 | end interface |
---|
73 | interface GlobalWeightedSumRAttr; module procedure & |
---|
74 | GlobalWeightedSumRAttrSP_, & |
---|
75 | GlobalWeightedSumRAttrDP_ |
---|
76 | end interface |
---|
77 | |
---|
78 | ! !PUBLIC DATA MEMBERS: |
---|
79 | |
---|
80 | public :: AttrVectSUM |
---|
81 | public :: AttrVectMIN |
---|
82 | public :: AttrVectMAX |
---|
83 | |
---|
84 | integer, parameter :: AttrVectSUM = 1 |
---|
85 | integer, parameter :: AttrVectMIN = 2 |
---|
86 | integer, parameter :: AttrVectMAX = 3 |
---|
87 | |
---|
88 | ! !REVISION HISTORY: |
---|
89 | ! |
---|
90 | ! 7May02 - J.W. Larson <larson@mcs.anl.gov> - Created module |
---|
91 | ! using routines originally prototyped in m_AttrVect. |
---|
92 | !EOP ___________________________________________________________________ |
---|
93 | |
---|
94 | character(len=*),parameter :: myname='MCT::m_AttrVectReduce' |
---|
95 | |
---|
96 | contains |
---|
97 | |
---|
98 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
99 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
100 | !BOP ------------------------------------------------------------------- |
---|
101 | ! |
---|
102 | ! !IROUTINE: LocalReduce_ - Local Reduction of INTEGER and REAL Attributes |
---|
103 | ! |
---|
104 | ! !DESCRIPTION: |
---|
105 | ! |
---|
106 | ! The subroutine {\tt LocalReduce\_()} takes the input {\tt AttrVect} |
---|
107 | ! argument {\tt inAV}, and reduces each of its integer and real |
---|
108 | ! attributes, returning them in the output {\tt AttrVect} argument |
---|
109 | ! {\tt outAV} (which is created by this routine). The type of |
---|
110 | ! reduction is defined by the input {\tt INTEGER} argument {\tt action}. |
---|
111 | ! Allowed values for action are defined as public data members to this |
---|
112 | ! module, and are summarized below: |
---|
113 | ! |
---|
114 | !\begin{table}[htbp] |
---|
115 | !\begin{center} |
---|
116 | !\begin{tabular}{|c|c|} |
---|
117 | !\hline |
---|
118 | !{\bf Value} & {\bf Action} \\ |
---|
119 | !\hline |
---|
120 | !{\tt AttrVectSUM} & Sum \\ |
---|
121 | !\hline |
---|
122 | !{\tt AttrVectMIN} & Minimum \\ |
---|
123 | !\hline |
---|
124 | !{\tt AttrVectMAX} & Maximum \\ |
---|
125 | !\hline |
---|
126 | !\end{tabular} |
---|
127 | !\end{center} |
---|
128 | !\end{table} |
---|
129 | ! |
---|
130 | ! {\bf N.B.}: The output {\tt AttrVect} argument {\tt outAV} is |
---|
131 | ! allocated memory, and must be destroyed by invoking the routine |
---|
132 | ! {\tt AttrVect\_clean()} when it is no longer needed. Failure to |
---|
133 | ! do so will result in a memory leak. |
---|
134 | ! |
---|
135 | ! !INTERFACE: |
---|
136 | |
---|
137 | subroutine LocalReduce_(inAV, outAV, action) |
---|
138 | ! |
---|
139 | ! !USES: |
---|
140 | ! |
---|
141 | use m_realkinds, only : FP |
---|
142 | use m_die , only : die |
---|
143 | use m_stdio , only : stderr |
---|
144 | use m_AttrVect, only : AttrVect |
---|
145 | use m_AttrVect, only : AttrVect_init => init |
---|
146 | use m_AttrVect, only : AttrVect_zero => zero |
---|
147 | use m_AttrVect, only : AttrVect_nIAttr => nIAttr |
---|
148 | use m_AttrVect, only : AttrVect_nRAttr => nRAttr |
---|
149 | use m_AttrVect, only : AttrVect_lsize => lsize |
---|
150 | |
---|
151 | implicit none |
---|
152 | |
---|
153 | ! !INPUT PARAMETERS: |
---|
154 | ! |
---|
155 | type(AttrVect), intent(IN) :: inAV |
---|
156 | integer, intent(IN) :: action |
---|
157 | |
---|
158 | ! !OUTPUT PARAMETERS: |
---|
159 | ! |
---|
160 | type(AttrVect), intent(OUT) :: outAV |
---|
161 | |
---|
162 | ! !REVISION HISTORY: |
---|
163 | ! 16Apr02 - J.W. Larson <larson@mcs.anl.gov> - initial prototype |
---|
164 | !EOP ___________________________________________________________________ |
---|
165 | |
---|
166 | character(len=*),parameter :: myname_=myname//'::LocalReduce_' |
---|
167 | |
---|
168 | integer :: i,j |
---|
169 | |
---|
170 | ! First Step: create outAV from inAV (but with one element) |
---|
171 | |
---|
172 | call AttrVect_init(outAV, inAV, lsize=1) |
---|
173 | |
---|
174 | call AttrVect_zero(outAV) |
---|
175 | |
---|
176 | select case(action) |
---|
177 | case(AttrVectSUM) ! sum up each attribute... |
---|
178 | |
---|
179 | ! Compute INTEGER and REAL attribute sums: |
---|
180 | |
---|
181 | do j=1,AttrVect_lsize(inAV) |
---|
182 | do i=1,AttrVect_nIAttr(outAV) |
---|
183 | outAV%iAttr(i,1) = outAV%iAttr(i,1) + inAV%iAttr(i,j) |
---|
184 | end do |
---|
185 | end do |
---|
186 | |
---|
187 | do j=1,AttrVect_lsize(inAV) |
---|
188 | do i=1,AttrVect_nRAttr(outAV) |
---|
189 | outAV%rAttr(i,1) = outAV%rAttr(i,1) + inAV%rAttr(i,j) |
---|
190 | end do |
---|
191 | end do |
---|
192 | |
---|
193 | case(AttrVectMIN) ! find the minimum of each attribute... |
---|
194 | |
---|
195 | ! Initialize INTEGER and REAL attribute minima: |
---|
196 | |
---|
197 | do i=1,AttrVect_nIAttr(outAV) |
---|
198 | outAV%iAttr(i,1) = inAV%iAttr(i,1) |
---|
199 | end do |
---|
200 | |
---|
201 | do i=1,AttrVect_nRAttr(outAV) |
---|
202 | outAV%rAttr(i,1) = inAV%rAttr(i,1) |
---|
203 | end do |
---|
204 | |
---|
205 | ! Compute INTEGER and REAL attribute minima: |
---|
206 | |
---|
207 | do j=1,AttrVect_lsize(inAV) |
---|
208 | do i=1,AttrVect_nIAttr(outAV) |
---|
209 | if(inAV%iAttr(i,j) < outAV%iAttr(i,1)) then |
---|
210 | outAV%iAttr(i,1) = inAV%iAttr(i,j) |
---|
211 | endif |
---|
212 | end do |
---|
213 | end do |
---|
214 | |
---|
215 | do j=1,AttrVect_lsize(inAV) |
---|
216 | do i=1,AttrVect_nRAttr(outAV) |
---|
217 | if(inAV%rAttr(i,j) < outAV%rAttr(i,1)) then |
---|
218 | outAV%rAttr(i,1) = inAV%rAttr(i,j) |
---|
219 | endif |
---|
220 | end do |
---|
221 | end do |
---|
222 | |
---|
223 | case(AttrVectMAX) ! find the maximum of each attribute... |
---|
224 | |
---|
225 | ! Initialize INTEGER and REAL attribute maxima: |
---|
226 | |
---|
227 | do i=1,AttrVect_nIAttr(outAV) |
---|
228 | outAV%iAttr(i,1) = inAV%iAttr(i,1) |
---|
229 | end do |
---|
230 | |
---|
231 | do i=1,AttrVect_nRAttr(outAV) |
---|
232 | outAV%rAttr(i,1) = inAV%rAttr(i,1) |
---|
233 | end do |
---|
234 | |
---|
235 | ! Compute INTEGER and REAL attribute maxima: |
---|
236 | |
---|
237 | do j=1,AttrVect_lsize(inAV) |
---|
238 | do i=1,AttrVect_nIAttr(outAV) |
---|
239 | if(inAV%iAttr(i,j) > outAV%iAttr(i,1)) then |
---|
240 | outAV%iAttr(i,1) = inAV%iAttr(i,j) |
---|
241 | endif |
---|
242 | end do |
---|
243 | end do |
---|
244 | |
---|
245 | do j=1,AttrVect_lsize(inAV) |
---|
246 | do i=1,AttrVect_nRAttr(outAV) |
---|
247 | if(inAV%rAttr(i,j) > outAV%rAttr(i,1)) then |
---|
248 | outAV%rAttr(i,1) = inAV%rAttr(i,j) |
---|
249 | endif |
---|
250 | end do |
---|
251 | end do |
---|
252 | |
---|
253 | case default |
---|
254 | |
---|
255 | write(stderr,'(2a,i8)') myname_,':: unrecognized action = ',action |
---|
256 | call die(myname_) |
---|
257 | |
---|
258 | end select |
---|
259 | |
---|
260 | end subroutine LocalReduce_ |
---|
261 | |
---|
262 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
263 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
264 | !BOP ------------------------------------------------------------------- |
---|
265 | ! |
---|
266 | ! !IROUTINE: LocalReduceRAttr_ - Local Reduction of REAL Attributes |
---|
267 | ! |
---|
268 | ! !DESCRIPTION: |
---|
269 | ! |
---|
270 | ! The subroutine {\tt LocalReduceRAttr\_()} takes the input |
---|
271 | ! {\tt AttrVect} argument {\tt inAV}, and reduces each of its {\tt REAL} |
---|
272 | ! attributes, returning them in the output {\tt AttrVect} argument |
---|
273 | ! {\tt outAV} (which is created by this routine). The type of reduction |
---|
274 | ! is defined by the input {\tt INTEGER} argument {\tt action}. Allowed |
---|
275 | ! values for action are defined as public data members to this module |
---|
276 | ! (see the declaration section of {\tt m\_AttrVect}, and are summarized below: |
---|
277 | ! |
---|
278 | !\begin{table}[htbp] |
---|
279 | !\begin{center} |
---|
280 | !\begin{tabular}{|c|c|} |
---|
281 | !\hline |
---|
282 | !{\bf Value} & {\bf Action} \\ |
---|
283 | !\hline |
---|
284 | !{\tt AttrVectSUM} & Sum \\ |
---|
285 | !\hline |
---|
286 | !{\tt AttrVectMIN} & Minimum \\ |
---|
287 | !\hline |
---|
288 | !{\tt AttrVectMAX} & Maximum \\ |
---|
289 | !\hline |
---|
290 | !\end{tabular} |
---|
291 | !\end{center} |
---|
292 | !\end{table} |
---|
293 | ! |
---|
294 | ! {\bf N.B.}: The output {\tt AttrVect} argument {\tt outAV} is |
---|
295 | ! allocated memory, and must be destroyed by invoking the routine |
---|
296 | ! {\tt AttrVect\_clean()} when it is no longer needed. Failure to |
---|
297 | ! do so will result in a memory leak. |
---|
298 | ! |
---|
299 | ! !INTERFACE: |
---|
300 | ! |
---|
301 | subroutine LocalReduceRAttr_(inAV, outAV, action) |
---|
302 | |
---|
303 | ! |
---|
304 | ! !USES: |
---|
305 | ! |
---|
306 | use m_realkinds, only : FP |
---|
307 | |
---|
308 | use m_die , only : die |
---|
309 | use m_stdio , only : stderr |
---|
310 | |
---|
311 | use m_List, only : List |
---|
312 | use m_List, only : List_copy => copy |
---|
313 | use m_List, only : List_exportToChar => exportToChar |
---|
314 | use m_List, only : List_clean => clean |
---|
315 | |
---|
316 | use m_AttrVect, only : AttrVect |
---|
317 | use m_AttrVect, only : AttrVect_init => init |
---|
318 | use m_AttrVect, only : AttrVect_zero => zero |
---|
319 | use m_AttrVect, only : AttrVect_nIAttr => nIAttr |
---|
320 | use m_AttrVect, only : AttrVect_nRAttr => nRAttr |
---|
321 | use m_AttrVect, only : AttrVect_lsize => lsize |
---|
322 | |
---|
323 | implicit none |
---|
324 | |
---|
325 | ! !INPUT PARAMETERS: |
---|
326 | ! |
---|
327 | type(AttrVect), intent(IN) :: inAV |
---|
328 | integer, intent(IN) :: action |
---|
329 | |
---|
330 | ! !OUTPUT PARAMETERS: |
---|
331 | ! |
---|
332 | type(AttrVect), intent(OUT) :: outAV |
---|
333 | |
---|
334 | ! !REVISION HISTORY: |
---|
335 | ! 16Apr02 - J.W. Larson <larson@mcs.anl.gov> - initial prototype |
---|
336 | ! 6May02 - J.W. Larson <larson@mcs.anl.gov> - added optional |
---|
337 | ! argument weights(:) |
---|
338 | ! 8May02 - J.W. Larson <larson@mcs.anl.gov> - modified interface |
---|
339 | ! to return it to being a pure reduction operation. |
---|
340 | ! 9May02 - J.W. Larson <larson@mcs.anl.gov> - renamed from |
---|
341 | ! LocalReduceReals_() to LocalReduceRAttr_() to make |
---|
342 | ! the name more consistent with other module procedure |
---|
343 | ! names in this module. |
---|
344 | !EOP ___________________________________________________________________ |
---|
345 | |
---|
346 | character(len=*),parameter :: myname_=myname//'::LocalReduceRAttr_' |
---|
347 | |
---|
348 | integer :: i,j |
---|
349 | type(List) :: rList_copy |
---|
350 | |
---|
351 | |
---|
352 | ! First Step: create outAV from inAV (but with one element) |
---|
353 | |
---|
354 | ! Superflous list copy circumvents SGI compiler bug |
---|
355 | call List_copy(rList_copy,inAV%rList) |
---|
356 | call AttrVect_init(outAV, rList=List_exportToChar(rList_copy), lsize=1) |
---|
357 | call AttrVect_zero(outAV) |
---|
358 | call List_clean(rList_copy) |
---|
359 | |
---|
360 | select case(action) |
---|
361 | case(AttrVectSUM) ! sum up each attribute... |
---|
362 | |
---|
363 | ! Compute REAL attribute sums: |
---|
364 | |
---|
365 | do j=1,AttrVect_lsize(inAV) |
---|
366 | do i=1,AttrVect_nRAttr(outAV) |
---|
367 | outAV%rAttr(i,1) = outAV%rAttr(i,1) + inAV%rAttr(i,j) |
---|
368 | end do |
---|
369 | end do |
---|
370 | |
---|
371 | case(AttrVectMIN) ! find the minimum of each attribute... |
---|
372 | |
---|
373 | ! Initialize REAL attribute minima: |
---|
374 | |
---|
375 | do i=1,AttrVect_nRAttr(outAV) |
---|
376 | outAV%rAttr(i,1) = inAV%rAttr(i,1) |
---|
377 | end do |
---|
378 | |
---|
379 | ! Compute REAL attribute minima: |
---|
380 | |
---|
381 | do j=1,AttrVect_lsize(inAV) |
---|
382 | do i=1,AttrVect_nRAttr(outAV) |
---|
383 | if(inAV%rAttr(i,j) < outAV%rAttr(i,1)) then |
---|
384 | outAV%rAttr(i,1) = inAV%rAttr(i,j) |
---|
385 | endif |
---|
386 | end do |
---|
387 | end do |
---|
388 | |
---|
389 | case(AttrVectMAX) ! find the maximum of each attribute... |
---|
390 | |
---|
391 | ! Initialize REAL attribute maxima: |
---|
392 | |
---|
393 | do i=1,AttrVect_nRAttr(outAV) |
---|
394 | outAV%rAttr(i,1) = inAV%rAttr(i,1) |
---|
395 | end do |
---|
396 | |
---|
397 | ! Compute REAL attribute maxima: |
---|
398 | |
---|
399 | do j=1,AttrVect_lsize(inAV) |
---|
400 | do i=1,AttrVect_nRAttr(outAV) |
---|
401 | if(inAV%rAttr(i,j) > outAV%rAttr(i,1)) then |
---|
402 | outAV%rAttr(i,1) = inAV%rAttr(i,j) |
---|
403 | endif |
---|
404 | end do |
---|
405 | end do |
---|
406 | |
---|
407 | case default |
---|
408 | |
---|
409 | write(stderr,'(2a,i8)') myname_,':: unrecognized action = ',action |
---|
410 | call die(myname_) |
---|
411 | |
---|
412 | end select |
---|
413 | |
---|
414 | end subroutine LocalReduceRAttr_ |
---|
415 | |
---|
416 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
417 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
418 | !BOP ------------------------------------------------------------------- |
---|
419 | ! |
---|
420 | ! !IROUTINE: AllReduce_ - Reduction of INTEGER and REAL Attributes |
---|
421 | ! |
---|
422 | ! !DESCRIPTION: |
---|
423 | ! |
---|
424 | ! The subroutine {\tt AllReduce\_()} takes the distributed input |
---|
425 | ! {\tt AttrVect} argument {\tt inAV}, and performs a global reduction |
---|
426 | ! of all its attributes across the MPI communicator associated with |
---|
427 | ! the Fortran90 {\tt INTEGER} handle {\tt comm}, and returns these |
---|
428 | ! reduced values to all processes in the {\tt AttrVect} argument |
---|
429 | ! {\tt outAV} (which is created by this routine). The reduction |
---|
430 | ! operation is specified by the user, and must have one of the values |
---|
431 | ! listed in the table below: |
---|
432 | !\begin{table}[htbp] |
---|
433 | !\begin{center} |
---|
434 | !\begin{tabular}{|c|c|} |
---|
435 | !\hline |
---|
436 | !{\bf Value} & {\bf Action} \\ |
---|
437 | !\hline |
---|
438 | !{\tt AttrVectSUM} & Sum \\ |
---|
439 | !\hline |
---|
440 | !{\tt AttrVectMIN} & Minimum \\ |
---|
441 | !\hline |
---|
442 | !{\tt AttrVectMAX} & Maximum \\ |
---|
443 | !\hline |
---|
444 | !\end{tabular} |
---|
445 | !\end{center} |
---|
446 | !\end{table} |
---|
447 | ! |
---|
448 | ! {\bf N.B.}: The output {\tt AttrVect} argument {\tt outAV} is |
---|
449 | ! allocated memory, and must be destroyed by invoking the routine |
---|
450 | ! {\tt AttrVect\_clean()} when it is no longer needed. Failure to |
---|
451 | ! do so will result in a memory leak. |
---|
452 | ! |
---|
453 | ! !INTERFACE: |
---|
454 | ! |
---|
455 | |
---|
456 | subroutine AllReduce_(inAV, outAV, ReductionOp, comm, ierr) |
---|
457 | |
---|
458 | ! |
---|
459 | ! !USES: |
---|
460 | ! |
---|
461 | use m_die |
---|
462 | use m_stdio , only : stderr |
---|
463 | use m_mpif90 |
---|
464 | |
---|
465 | use m_List, only : List |
---|
466 | use m_List, only : List_exportToChar => exportToChar |
---|
467 | use m_List, only : List_allocated => allocated |
---|
468 | |
---|
469 | use m_AttrVect, only : AttrVect |
---|
470 | use m_AttrVect, only : AttrVect_init => init |
---|
471 | use m_AttrVect, only : AttrVect_zero => zero |
---|
472 | use m_AttrVect, only : AttrVect_lsize => lsize |
---|
473 | use m_AttrVect, only : AttrVect_nIAttr => nIAttr |
---|
474 | use m_AttrVect, only : AttrVect_nRAttr => nRAttr |
---|
475 | |
---|
476 | implicit none |
---|
477 | |
---|
478 | ! !INPUT PARAMETERS: |
---|
479 | ! |
---|
480 | type(AttrVect), intent(IN) :: inAV |
---|
481 | integer, intent(IN) :: ReductionOp |
---|
482 | integer, intent(IN) :: comm |
---|
483 | |
---|
484 | ! !OUTPUT PARAMETERS: |
---|
485 | ! |
---|
486 | type(AttrVect), intent(OUT) :: outAV |
---|
487 | integer, optional, intent(OUT) :: ierr |
---|
488 | |
---|
489 | ! !REVISION HISTORY: |
---|
490 | ! 8May02 - J.W. Larson <larson@mcs.anl.gov> - initial version. |
---|
491 | ! 9Jul02 - J.W. Larson <larson@mcs.anl.gov> - slight modification; |
---|
492 | ! use List_allocated() to determine if there is attribute |
---|
493 | ! data to be reduced (this patch is to support the Sun |
---|
494 | ! F90 compiler). |
---|
495 | !EOP ___________________________________________________________________ |
---|
496 | |
---|
497 | character(len=*),parameter :: myname_=myname//'::AllReduce_' |
---|
498 | |
---|
499 | integer :: BufferSize, myID, ier |
---|
500 | |
---|
501 | ! Initialize ierr (if present) to "success" value |
---|
502 | if(present(ierr)) ierr = 0 |
---|
503 | |
---|
504 | call MPI_COMM_RANK(comm, myID, ier) |
---|
505 | if(ier /= 0) then |
---|
506 | write(stderr,'(2a)') myname_,':: MPI_COMM_RANK() failed.' |
---|
507 | call MP_perr_die(myname_, 'MPI_COMM_RANK() failed.', ier) |
---|
508 | endif |
---|
509 | |
---|
510 | call AttrVect_init(outAV, inAV, lsize=AttrVect_lsize(inAV)) |
---|
511 | call AttrVect_zero(outAV) |
---|
512 | |
---|
513 | if(List_allocated(inAV%rList)) then ! invoke MPI_AllReduce() for the real |
---|
514 | ! attribute data. |
---|
515 | BufferSize = AttrVect_lsize(inAV) * AttrVect_nRAttr(inAV) |
---|
516 | |
---|
517 | select case(ReductionOp) |
---|
518 | case(AttrVectSUM) |
---|
519 | call MPI_AllReduce(inAV%rAttr, outAV%rAttr, BufferSize, & |
---|
520 | MP_Type(inAV%rAttr(1,1)), MP_SUM, & |
---|
521 | comm, ier) |
---|
522 | case(AttrVectMIN) |
---|
523 | call MPI_AllReduce(inAV%rAttr, outAV%rAttr, BufferSize, & |
---|
524 | MP_Type(inAV%rAttr(1,1)), MP_MIN, & |
---|
525 | comm, ier) |
---|
526 | case(AttrVectMAX) |
---|
527 | call MPI_AllReduce(inAV%rAttr, outAV%rAttr, BufferSize, & |
---|
528 | MP_Type(inAV%rAttr(1,1)), MP_MAX, & |
---|
529 | comm, ier) |
---|
530 | case default |
---|
531 | write(stderr,'(2a,i8,a)') myname_, & |
---|
532 | '::FATAL ERROR--value of RedctionOp=', & |
---|
533 | ReductionOp,' not supported.' |
---|
534 | end select |
---|
535 | |
---|
536 | if(ier /= 0) then |
---|
537 | write(stderr,*) myname_, & |
---|
538 | ':: Fatal Error in MPI_AllReduce(), myID = ',myID |
---|
539 | call MP_perr_die(myname_, 'MPI_AllReduce() failed.', ier) |
---|
540 | endif |
---|
541 | |
---|
542 | endif ! if(List_allocated(inAV%rList))... |
---|
543 | |
---|
544 | if(List_allocated(inAV%iList)) then ! invoke MPI_AllReduce() for the |
---|
545 | ! integer attribute data. |
---|
546 | |
---|
547 | BufferSize = AttrVect_lsize(inAV) * AttrVect_nIAttr(inAV) |
---|
548 | |
---|
549 | select case(ReductionOp) |
---|
550 | case(AttrVectSUM) |
---|
551 | call MPI_AllReduce(inAV%iAttr, outAV%iAttr, BufferSize, & |
---|
552 | MP_Type(inAV%iAttr(1,1)), MP_SUM, & |
---|
553 | comm, ier) |
---|
554 | case(AttrVectMIN) |
---|
555 | call MPI_AllReduce(inAV%iAttr, outAV%iAttr, BufferSize, & |
---|
556 | MP_Type(inAV%iAttr(1,1)), MP_MIN, & |
---|
557 | comm, ier) |
---|
558 | case(AttrVectMAX) |
---|
559 | call MPI_AllReduce(inAV%iAttr, outAV%iAttr, BufferSize, & |
---|
560 | MP_Type(inAV%iAttr(1,1)), MP_MAX, & |
---|
561 | comm, ier) |
---|
562 | case default |
---|
563 | write(stderr,'(2a,i8,a)') myname_, & |
---|
564 | '::FATAL ERROR--value of RedctionOp=', & |
---|
565 | ReductionOp,' not supported.' |
---|
566 | end select |
---|
567 | |
---|
568 | if(ierr /= 0) then |
---|
569 | write(stderr,*) myname_, & |
---|
570 | ':: Fatal Error in MPI_AllReduce(), myID = ',myID |
---|
571 | call MP_perr_die(myname_, 'MPI_AllReduce() failed.', ier) |
---|
572 | endif |
---|
573 | endif ! if(List_allocated(inAV%iList))... |
---|
574 | |
---|
575 | if(present(ierr)) ierr = ier |
---|
576 | |
---|
577 | end subroutine AllReduce_ |
---|
578 | |
---|
579 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
580 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
581 | !BOP ------------------------------------------------------------------- |
---|
582 | ! |
---|
583 | ! !IROUTINE: GlobalReduce_ - Reduction of INTEGER and REAL Attributes |
---|
584 | ! |
---|
585 | ! !DESCRIPTION: |
---|
586 | ! |
---|
587 | ! The subroutine {\tt GlobalReduce\_()} takes the distributed input |
---|
588 | ! {\tt AttrVect} argument {\tt inAV}, and performs a local reduction of |
---|
589 | ! all its integer and real attributes, followed by a an {\tt AllReduce} |
---|
590 | ! of all the result of the local reduction across the MPI communicator |
---|
591 | ! associated with the Fortran90 {\tt INTEGER} handle {\tt comm}, and |
---|
592 | ! returns these reduced values to all processes in the {\tt AttrVect} |
---|
593 | ! argument {\tt outAV} (which is created by this routine). The reduction |
---|
594 | ! operation is specified by the user, and must have one of the values |
---|
595 | ! listed in the table below: |
---|
596 | !\begin{table}[htbp] |
---|
597 | !\begin{center} |
---|
598 | !\begin{tabular}{|c|c|} |
---|
599 | !\hline |
---|
600 | !{\bf Value} & {\bf Action} \\ |
---|
601 | !\hline |
---|
602 | !{\tt AttrVectSUM} & Sum \\ |
---|
603 | !\hline |
---|
604 | !{\tt AttrVectMIN} & Minimum \\ |
---|
605 | !\hline |
---|
606 | !{\tt AttrVectMAX} & Maximum \\ |
---|
607 | !\hline |
---|
608 | !\end{tabular} |
---|
609 | !\end{center} |
---|
610 | !\end{table} |
---|
611 | ! |
---|
612 | ! {\bf N.B.}: The output {\tt AttrVect} argument {\tt outAV} is |
---|
613 | ! allocated memory, and must be destroyed by invoking the routine |
---|
614 | ! {\tt AttrVect\_clean()} when it is no longer needed. Failure to |
---|
615 | ! do so will result in a memory leak. |
---|
616 | ! |
---|
617 | ! !INTERFACE: |
---|
618 | ! |
---|
619 | |
---|
620 | subroutine GlobalReduce_(inAV, outAV, ReductionOp, comm, ierr) |
---|
621 | |
---|
622 | ! |
---|
623 | ! !USES: |
---|
624 | ! |
---|
625 | use m_die |
---|
626 | use m_stdio , only : stderr |
---|
627 | use m_mpif90 |
---|
628 | |
---|
629 | use m_AttrVect, only : AttrVect |
---|
630 | use m_AttrVect, only : AttrVect_clean => clean |
---|
631 | |
---|
632 | implicit none |
---|
633 | |
---|
634 | ! !INPUT PARAMETERS: |
---|
635 | ! |
---|
636 | type(AttrVect), intent(IN) :: inAV |
---|
637 | integer, intent(IN) :: ReductionOp |
---|
638 | integer, intent(IN) :: comm |
---|
639 | |
---|
640 | ! !OUTPUT PARAMETERS: |
---|
641 | ! |
---|
642 | type(AttrVect), intent(OUT) :: outAV |
---|
643 | integer, optional, intent(OUT) :: ierr |
---|
644 | |
---|
645 | ! !REVISION HISTORY: |
---|
646 | ! 6May03 - J.W. Larson <larson@mcs.anl.gov> - initial version. |
---|
647 | !EOP ___________________________________________________________________ |
---|
648 | |
---|
649 | character(len=*),parameter :: myname_=myname//'::GlobalReduce_' |
---|
650 | type(AttrVect) :: LocalResult |
---|
651 | |
---|
652 | ! Step One: On-PE reduction |
---|
653 | |
---|
654 | call LocalReduce_(inAV, LocalResult, ReductionOp) |
---|
655 | |
---|
656 | ! Step Two: An AllReduce on the distributed local reduction results |
---|
657 | |
---|
658 | if(present(ierr)) then |
---|
659 | call AllReduce_(LocalResult, outAV, ReductionOp, comm, ierr) |
---|
660 | else |
---|
661 | call AllReduce_(LocalResult, outAV, ReductionOp, comm) |
---|
662 | endif |
---|
663 | |
---|
664 | ! Step Three: Clean up and return. |
---|
665 | |
---|
666 | call AttrVect_clean(LocalResult) |
---|
667 | |
---|
668 | end subroutine GlobalReduce_ |
---|
669 | |
---|
670 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
671 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
672 | !BOP ------------------------------------------------------------------- |
---|
673 | ! |
---|
674 | ! !IROUTINE: LocalWeightedSumRAttrSP_ - Local Weighted Sum of REAL Attributes |
---|
675 | ! |
---|
676 | ! !DESCRIPTION: |
---|
677 | ! |
---|
678 | ! The subroutine {\tt LocalWeightedSumRAttr\_()} takes the input |
---|
679 | ! {\tt AttrVect} argument {\tt inAV}, and performs a weighted sum |
---|
680 | ! of each of its {\tt REAL} attributes, returning them in the output |
---|
681 | ! {\tt AttrVect} argument {\tt outAV} (which is created by this routine |
---|
682 | ! and will contain {\em no} integer attributes). The weights used |
---|
683 | ! for the summation are provided by the user in the input argument |
---|
684 | ! {\tt Weights(:)}. If the sum of the weights is desired, this can be |
---|
685 | ! returned as an attribute in {\tt outAV} if the optional {\tt CHARACTER} |
---|
686 | ! argument {\tt WeightSumAttr} is provided (which will be concatenated |
---|
687 | ! onto the list of real attributes in {\tt inAV}). |
---|
688 | ! |
---|
689 | ! {\bf N.B.}: The argument {\tt WeightSumAttr} must not be identical |
---|
690 | ! to any of the real attribute names in {\tt inAV}. |
---|
691 | ! |
---|
692 | ! {\bf N.B.}: The output {\tt AttrVect} argument {\tt outAV} is |
---|
693 | ! allocated memory, and must be destroyed by invoking the routine |
---|
694 | ! {\tt AttrVect\_clean()} when it is no longer needed. Failure to |
---|
695 | ! do so will result in a memory leak. |
---|
696 | ! |
---|
697 | ! !INTERFACE: |
---|
698 | ! |
---|
699 | subroutine LocalWeightedSumRAttrSP_(inAV, outAV, Weights, WeightSumAttr) |
---|
700 | |
---|
701 | ! |
---|
702 | ! !USES: |
---|
703 | ! |
---|
704 | use m_die , only : die |
---|
705 | use m_stdio , only : stderr |
---|
706 | use m_realkinds, only : SP, FP |
---|
707 | |
---|
708 | use m_List, only : List |
---|
709 | use m_List, only : List_init => init |
---|
710 | use m_List, only : List_clean => clean |
---|
711 | use m_List, only : List_exportToChar => exportToChar |
---|
712 | use m_List, only : List_concatenate => concatenate |
---|
713 | |
---|
714 | use m_AttrVect, only : AttrVect |
---|
715 | use m_AttrVect, only : AttrVect_init => init |
---|
716 | use m_AttrVect, only : AttrVect_zero => zero |
---|
717 | use m_AttrVect, only : AttrVect_nIAttr => nIAttr |
---|
718 | use m_AttrVect, only : AttrVect_nRAttr => nRAttr |
---|
719 | use m_AttrVect, only : AttrVect_lsize => lsize |
---|
720 | |
---|
721 | implicit none |
---|
722 | |
---|
723 | ! !INPUT PARAMETERS: |
---|
724 | ! |
---|
725 | type(AttrVect), intent(IN) :: inAV |
---|
726 | real(SP), dimension(:), pointer :: Weights |
---|
727 | character(len=*), optional, intent(IN) :: WeightSumAttr |
---|
728 | |
---|
729 | ! !OUTPUT PARAMETERS: |
---|
730 | ! |
---|
731 | type(AttrVect), intent(OUT) :: outAV |
---|
732 | |
---|
733 | ! !REVISION HISTORY: |
---|
734 | ! 8May02 - J.W. Larson <larson@mcs.anl.gov> - initial version. |
---|
735 | ! 14Jun02 - J.W. Larson <larson@mcs.anl.gov> - bug fix regarding |
---|
736 | ! accumulation of weights when invoked with argument |
---|
737 | ! weightSumAttr. Now works in MCT unit tester. |
---|
738 | !EOP ___________________________________________________________________ |
---|
739 | |
---|
740 | character(len=*),parameter :: myname_=myname//'::LocalWeightedSumRAttrSP_' |
---|
741 | |
---|
742 | integer :: i,j |
---|
743 | type(List) dummyList1, dummyList2 |
---|
744 | |
---|
745 | ! Check for consistencey between inAV and the weights array |
---|
746 | |
---|
747 | if(size(weights) /= AttrVect_lsize(inAV)) then |
---|
748 | write(stderr,'(4a)') myname_,':: ERROR--mismatch in lengths of ', & |
---|
749 | 'input array array argument weights(:) and input AttrVect ',& |
---|
750 | 'inAV.' |
---|
751 | write(stderr,'(2a,i8)') myname_,':: size(weights)=',size(weights) |
---|
752 | write(stderr,'(2a,i8)') myname_,':: length of inAV=', & |
---|
753 | AttrVect_lsize(inAV) |
---|
754 | call die(myname_) |
---|
755 | endif |
---|
756 | |
---|
757 | ! First Step: create outAV from inAV (but with one element) |
---|
758 | |
---|
759 | if(present(WeightSumAttr)) then |
---|
760 | call List_init(dummyList1,WeightSumAttr) |
---|
761 | call List_concatenate(inAV%rList, dummyList1, dummyList2) |
---|
762 | call AttrVect_init(outAV, rList=List_exportToChar(dummyList2), & |
---|
763 | lsize=1) |
---|
764 | call List_clean(dummyList1) |
---|
765 | call List_clean(dummyList2) |
---|
766 | else |
---|
767 | call AttrVect_init(outAV, rList=List_exportToChar(inAV%rList), lsize=1) |
---|
768 | endif |
---|
769 | |
---|
770 | ! Initialize REAL attribute sums: |
---|
771 | call AttrVect_zero(outAV) |
---|
772 | |
---|
773 | ! Compute REAL attribute sums: |
---|
774 | |
---|
775 | if(present(WeightSumAttr)) then ! perform weighted sum AND sum weights |
---|
776 | |
---|
777 | do j=1,AttrVect_lsize(inAV) |
---|
778 | |
---|
779 | do i=1,AttrVect_nRAttr(inAV) |
---|
780 | outAV%rAttr(i,1) = outAV%rAttr(i,1) + inAV%rAttr(i,j) * weights(j) |
---|
781 | end do |
---|
782 | ! The final attribute is the sum of the weights |
---|
783 | outAV%rAttr(AttrVect_nRAttr(outAV),1) = & |
---|
784 | outAV%rAttr(AttrVect_nRAttr(outAV),1) + weights(j) |
---|
785 | end do |
---|
786 | |
---|
787 | else ! only perform weighted sum |
---|
788 | |
---|
789 | do j=1,AttrVect_lsize(inAV) |
---|
790 | do i=1,AttrVect_nRAttr(inAV) |
---|
791 | outAV%rAttr(i,1) = outAV%rAttr(i,1) + inAV%rAttr(i,j) * weights(j) |
---|
792 | end do |
---|
793 | end do |
---|
794 | |
---|
795 | endif ! if(present(WeightSumAttr))... |
---|
796 | |
---|
797 | end subroutine LocalWeightedSumRAttrSP_ |
---|
798 | |
---|
799 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
800 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
801 | ! ---------------------------------------------------------------------- |
---|
802 | ! |
---|
803 | ! !IROUTINE: LocalWeightedSumRAttrDP_ - Local Weighted Sum of REAL Attributes |
---|
804 | ! |
---|
805 | ! !DESCRIPTION: |
---|
806 | ! Double precision version of LocalWeightedSumRAttrSP_ |
---|
807 | ! |
---|
808 | ! !INTERFACE: |
---|
809 | ! |
---|
810 | subroutine LocalWeightedSumRAttrDP_(inAV, outAV, Weights, WeightSumAttr) |
---|
811 | |
---|
812 | ! |
---|
813 | ! !USES: |
---|
814 | ! |
---|
815 | use m_die , only : die |
---|
816 | use m_stdio , only : stderr |
---|
817 | use m_realkinds, only : DP, FP |
---|
818 | |
---|
819 | use m_List, only : List |
---|
820 | use m_List, only : List_init => init |
---|
821 | use m_List, only : List_clean => clean |
---|
822 | use m_List, only : List_exportToChar => exportToChar |
---|
823 | use m_List, only : List_concatenate => concatenate |
---|
824 | |
---|
825 | use m_AttrVect, only : AttrVect |
---|
826 | use m_AttrVect, only : AttrVect_init => init |
---|
827 | use m_AttrVect, only : AttrVect_zero => zero |
---|
828 | use m_AttrVect, only : AttrVect_nIAttr => nIAttr |
---|
829 | use m_AttrVect, only : AttrVect_nRAttr => nRAttr |
---|
830 | use m_AttrVect, only : AttrVect_lsize => lsize |
---|
831 | |
---|
832 | implicit none |
---|
833 | |
---|
834 | ! !INPUT PARAMETERS: |
---|
835 | ! |
---|
836 | type(AttrVect), intent(IN) :: inAV |
---|
837 | real(DP), dimension(:), pointer :: Weights |
---|
838 | character(len=*), optional, intent(IN) :: WeightSumAttr |
---|
839 | |
---|
840 | ! !OUTPUT PARAMETERS: |
---|
841 | ! |
---|
842 | type(AttrVect), intent(OUT) :: outAV |
---|
843 | |
---|
844 | ! !REVISION HISTORY: |
---|
845 | ! 8May02 - J.W. Larson <larson@mcs.anl.gov> - initial version. |
---|
846 | ! 14Jun02 - J.W. Larson <larson@mcs.anl.gov> - bug fix regarding |
---|
847 | ! accumulation of weights when invoked with argument |
---|
848 | ! weightSumAttr. Now works in MCT unit tester. |
---|
849 | ! ______________________________________________________________________ |
---|
850 | |
---|
851 | character(len=*),parameter :: myname_=myname//'::LocalWeightedSumRAttrDP_' |
---|
852 | |
---|
853 | integer :: i,j |
---|
854 | type(List) dummyList1, dummyList2 |
---|
855 | |
---|
856 | ! Check for consistencey between inAV and the weights array |
---|
857 | |
---|
858 | if(size(weights) /= AttrVect_lsize(inAV)) then |
---|
859 | write(stderr,'(4a)') myname_,':: ERROR--mismatch in lengths of ', & |
---|
860 | 'input array array argument weights(:) and input AttrVect ',& |
---|
861 | 'inAV.' |
---|
862 | write(stderr,'(2a,i8)') myname_,':: size(weights)=',size(weights) |
---|
863 | write(stderr,'(2a,i8)') myname_,':: length of inAV=', & |
---|
864 | AttrVect_lsize(inAV) |
---|
865 | call die(myname_) |
---|
866 | endif |
---|
867 | |
---|
868 | ! First Step: create outAV from inAV (but with one element) |
---|
869 | |
---|
870 | if(present(WeightSumAttr)) then |
---|
871 | call List_init(dummyList1,WeightSumAttr) |
---|
872 | call List_concatenate(inAV%rList, dummyList1, dummyList2) |
---|
873 | call AttrVect_init(outAV, rList=List_exportToChar(dummyList2), & |
---|
874 | lsize=1) |
---|
875 | call List_clean(dummyList1) |
---|
876 | call List_clean(dummyList2) |
---|
877 | else |
---|
878 | call AttrVect_init(outAV, rList=List_exportToChar(inAV%rList), lsize=1) |
---|
879 | endif |
---|
880 | |
---|
881 | ! Initialize REAL attribute sums: |
---|
882 | call AttrVect_zero(outAV) |
---|
883 | |
---|
884 | ! Compute REAL attribute sums: |
---|
885 | |
---|
886 | if(present(WeightSumAttr)) then ! perform weighted sum AND sum weights |
---|
887 | |
---|
888 | do j=1,AttrVect_lsize(inAV) |
---|
889 | |
---|
890 | do i=1,AttrVect_nRAttr(inAV) |
---|
891 | outAV%rAttr(i,1) = outAV%rAttr(i,1) + inAV%rAttr(i,j) * weights(j) |
---|
892 | end do |
---|
893 | ! The final attribute is the sum of the weights |
---|
894 | outAV%rAttr(AttrVect_nRAttr(outAV),1) = & |
---|
895 | outAV%rAttr(AttrVect_nRAttr(outAV),1) + weights(j) |
---|
896 | end do |
---|
897 | |
---|
898 | else ! only perform weighted sum |
---|
899 | |
---|
900 | do j=1,AttrVect_lsize(inAV) |
---|
901 | do i=1,AttrVect_nRAttr(inAV) |
---|
902 | outAV%rAttr(i,1) = outAV%rAttr(i,1) + inAV%rAttr(i,j) * weights(j) |
---|
903 | end do |
---|
904 | end do |
---|
905 | |
---|
906 | endif ! if(present(WeightSumAttr))... |
---|
907 | |
---|
908 | end subroutine LocalWeightedSumRAttrDP_ |
---|
909 | |
---|
910 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
911 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
912 | !BOP ------------------------------------------------------------------- |
---|
913 | ! |
---|
914 | ! !IROUTINE: GlobalWeightedSumRAttrSP_ - Global Weighted Sum of REAL Attributes |
---|
915 | ! |
---|
916 | ! !DESCRIPTION: |
---|
917 | ! |
---|
918 | ! The subroutine {\tt GlobalWeightedSumRAttr\_()} takes the |
---|
919 | ! distributed input {\tt AttrVect} argument {\tt inAV}, and performs |
---|
920 | ! a weighted global sum across the MPI communicator associated with |
---|
921 | ! the Fortran90 {\tt INTEGER} handle {\tt comm} of each of its |
---|
922 | ! {\tt REAL} attributes, returning the sums to each process in the |
---|
923 | ! {\tt AttrVect} argument {\tt outAV} (which is created by this routine |
---|
924 | ! and will contain {\em no} integer attributes). The weights used for |
---|
925 | ! the summation are provided by the user in the input argument |
---|
926 | ! {\tt weights(:)}. If the sum of the weights is desired, this can be |
---|
927 | ! returned as an attribute in {\tt outAV} if the optional {\tt CHARACTER} |
---|
928 | ! argument {\tt WeightSumAttr} is provided (which will be concatenated |
---|
929 | ! onto the list of real attributes in {\tt inAV} to form the list of |
---|
930 | ! real attributes for {\tt outAV}). |
---|
931 | ! |
---|
932 | ! {\bf N.B.}: The argument {\tt WeightSumAttr} must not be identical |
---|
933 | ! to any of the real attribute names in {\tt inAV}. |
---|
934 | ! |
---|
935 | ! {\bf N.B.}: The output {\tt AttrVect} argument {\tt outAV} is |
---|
936 | ! allocated memory, and must be destroyed by invoking the routine |
---|
937 | ! {\tt AttrVect\_clean()} when it is no longer needed. Failure to |
---|
938 | ! do so will result in a memory leak. |
---|
939 | ! |
---|
940 | ! !INTERFACE: |
---|
941 | ! |
---|
942 | subroutine GlobalWeightedSumRAttrSP_(inAV, outAV, Weights, comm, & |
---|
943 | WeightSumAttr) |
---|
944 | |
---|
945 | ! |
---|
946 | ! !USES: |
---|
947 | ! |
---|
948 | use m_die |
---|
949 | use m_stdio , only : stderr |
---|
950 | use m_mpif90 |
---|
951 | use m_realkinds, only : SP |
---|
952 | |
---|
953 | use m_List, only : List |
---|
954 | use m_List, only : List_exportToChar => exportToChar |
---|
955 | |
---|
956 | use m_AttrVect, only : AttrVect |
---|
957 | use m_AttrVect, only : AttrVect_clean => clean |
---|
958 | use m_AttrVect, only : AttrVect_lsize => lsize |
---|
959 | |
---|
960 | implicit none |
---|
961 | |
---|
962 | ! !INPUT PARAMETERS: |
---|
963 | ! |
---|
964 | type(AttrVect), intent(IN) :: inAV |
---|
965 | real(SP), dimension(:), pointer :: Weights |
---|
966 | integer, intent(IN) :: comm |
---|
967 | character(len=*), optional, intent(IN) :: WeightSumAttr |
---|
968 | |
---|
969 | ! !OUTPUT PARAMETERS: |
---|
970 | ! |
---|
971 | type(AttrVect), intent(OUT) :: outAV |
---|
972 | |
---|
973 | ! !REVISION HISTORY: |
---|
974 | ! 8May02 - J.W. Larson <larson@mcs.anl.gov> - initial version. |
---|
975 | !EOP ___________________________________________________________________ |
---|
976 | |
---|
977 | character(len=*),parameter :: myname_=myname//'::GlobalWeightedSumRAttrSP_' |
---|
978 | |
---|
979 | type(AttrVect) :: LocallySummedAV |
---|
980 | integer :: myID, ierr |
---|
981 | |
---|
982 | ! Get local process rank (for potential error reporting purposes) |
---|
983 | |
---|
984 | call MPI_COMM_RANK(comm, myID, ierr) |
---|
985 | if(ierr /= 0) then |
---|
986 | call MP_perr_die(myname_,':: MPI_COMM_RANK() error.',ierr) |
---|
987 | endif |
---|
988 | |
---|
989 | ! Check for consistencey between inAV and the weights array |
---|
990 | |
---|
991 | if(size(weights) /= AttrVect_lsize(inAV)) then |
---|
992 | write(stderr,'(2a,i8,3a)') myname_,':: myID=',myID, & |
---|
993 | 'ERROR--mismatch in lengths of ', & |
---|
994 | 'input array array argument weights(:) and input AttrVect ',& |
---|
995 | 'inAV.' |
---|
996 | write(stderr,'(2a,i8)') myname_,':: size(weights)=',size(weights) |
---|
997 | write(stderr,'(2a,i8)') myname_,':: length of inAV=', & |
---|
998 | AttrVect_lsize(inAV) |
---|
999 | call die(myname_) |
---|
1000 | endif |
---|
1001 | |
---|
1002 | if(present(WeightSumAttr)) then |
---|
1003 | call LocalWeightedSumRAttrSP_(inAV, LocallySummedAV, Weights, & |
---|
1004 | WeightSumAttr) |
---|
1005 | else |
---|
1006 | call LocalWeightedSumRAttrSP_(inAV, LocallySummedAV, Weights) |
---|
1007 | endif |
---|
1008 | |
---|
1009 | call AllReduce_(LocallySummedAV, outAV, AttrVectSUM, comm, ierr) |
---|
1010 | |
---|
1011 | ! Clean up intermediate local sums |
---|
1012 | |
---|
1013 | call AttrVect_clean(LocallySummedAV) |
---|
1014 | |
---|
1015 | end subroutine GlobalWeightedSumRAttrSP_ |
---|
1016 | |
---|
1017 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
1018 | ! Math and Computer Science Division, Argonne National Laboratory ! |
---|
1019 | ! ---------------------------------------------------------------------- |
---|
1020 | ! |
---|
1021 | ! !IROUTINE: GlobalWeightedSumRAttrDP_ - Global Weighted Sum of REAL Attributes |
---|
1022 | ! |
---|
1023 | ! !DESCRIPTION: |
---|
1024 | ! Double precision version of GlobalWeightedSumRAttrSP_ |
---|
1025 | ! |
---|
1026 | ! !INTERFACE: |
---|
1027 | ! |
---|
1028 | subroutine GlobalWeightedSumRAttrDP_(inAV, outAV, Weights, comm, & |
---|
1029 | WeightSumAttr) |
---|
1030 | |
---|
1031 | ! |
---|
1032 | ! !USES: |
---|
1033 | ! |
---|
1034 | use m_die |
---|
1035 | use m_stdio , only : stderr |
---|
1036 | use m_mpif90 |
---|
1037 | use m_realkinds, only : DP |
---|
1038 | |
---|
1039 | use m_List, only : List |
---|
1040 | use m_List, only : List_exportToChar => exportToChar |
---|
1041 | |
---|
1042 | use m_AttrVect, only : AttrVect |
---|
1043 | use m_AttrVect, only : AttrVect_clean => clean |
---|
1044 | use m_AttrVect, only : AttrVect_lsize => lsize |
---|
1045 | |
---|
1046 | implicit none |
---|
1047 | |
---|
1048 | ! !INPUT PARAMETERS: |
---|
1049 | ! |
---|
1050 | type(AttrVect), intent(IN) :: inAV |
---|
1051 | real(DP), dimension(:), pointer :: Weights |
---|
1052 | integer, intent(IN) :: comm |
---|
1053 | character(len=*), optional, intent(IN) :: WeightSumAttr |
---|
1054 | |
---|
1055 | ! !OUTPUT PARAMETERS: |
---|
1056 | ! |
---|
1057 | type(AttrVect), intent(OUT) :: outAV |
---|
1058 | |
---|
1059 | ! !REVISION HISTORY: |
---|
1060 | ! 8May02 - J.W. Larson <larson@mcs.anl.gov> - initial version. |
---|
1061 | ! ______________________________________________________________________ |
---|
1062 | |
---|
1063 | character(len=*),parameter :: myname_=myname//'::GlobalWeightedSumRAttrDP_' |
---|
1064 | |
---|
1065 | type(AttrVect) :: LocallySummedAV |
---|
1066 | integer :: myID, ierr |
---|
1067 | |
---|
1068 | ! Get local process rank (for potential error reporting purposes) |
---|
1069 | |
---|
1070 | call MPI_COMM_RANK(comm, myID, ierr) |
---|
1071 | if(ierr /= 0) then |
---|
1072 | call MP_perr_die(myname_,':: MPI_COMM_RANK() error.',ierr) |
---|
1073 | endif |
---|
1074 | |
---|
1075 | ! Check for consistencey between inAV and the weights array |
---|
1076 | |
---|
1077 | if(size(weights) /= AttrVect_lsize(inAV)) then |
---|
1078 | write(stderr,'(2a,i8,3a)') myname_,':: myID=',myID, & |
---|
1079 | 'ERROR--mismatch in lengths of ', & |
---|
1080 | 'input array array argument weights(:) and input AttrVect ',& |
---|
1081 | 'inAV.' |
---|
1082 | write(stderr,'(2a,i8)') myname_,':: size(weights)=',size(weights) |
---|
1083 | write(stderr,'(2a,i8)') myname_,':: length of inAV=', & |
---|
1084 | AttrVect_lsize(inAV) |
---|
1085 | call die(myname_) |
---|
1086 | endif |
---|
1087 | |
---|
1088 | if(present(WeightSumAttr)) then |
---|
1089 | call LocalWeightedSumRAttrDP_(inAV, LocallySummedAV, Weights, & |
---|
1090 | WeightSumAttr) |
---|
1091 | else |
---|
1092 | call LocalWeightedSumRAttrDP_(inAV, LocallySummedAV, Weights) |
---|
1093 | endif |
---|
1094 | |
---|
1095 | call AllReduce_(LocallySummedAV, outAV, AttrVectSUM, comm, ierr) |
---|
1096 | |
---|
1097 | ! Clean up intermediate local sums |
---|
1098 | |
---|
1099 | call AttrVect_clean(LocallySummedAV) |
---|
1100 | |
---|
1101 | end subroutine GlobalWeightedSumRAttrDP_ |
---|
1102 | |
---|
1103 | end module m_AttrVectReduce |
---|
1104 | !. |
---|
1105 | |
---|
1106 | |
---|
1107 | |
---|
1108 | |
---|