/[MITgcm]/MITgcm/eesupp/src/global_sum_singlecpu.F
ViewVC logotype

Contents of /MITgcm/eesupp/src/global_sum_singlecpu.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download)
Mon Sep 3 19:36:29 2012 UTC (11 years, 7 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint63s, checkpoint64, checkpoint65, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, HEAD
Changes since 1.4: +16 -16 lines
add "if usingMPI" test where needed (+ start to remove ALWAYS_USE_MPI)

1 C $Header: /u/gcmpack/MITgcm/eesupp/src/global_sum_singlecpu.F,v 1.4 2009/06/10 03:47:03 jmc Exp $
2 C $Name: $
3
4 #include "PACKAGES_CONFIG.h"
5 #include "CPP_EEOPTIONS.h"
6
7 C-- File global_sum_singlecpu.F: Routines that perform global sum
8 C on a single CPU
9 C Contents
10 C o GLOBAL_SUM_SINGLECPU_RL
11 C o GLOBAL_SUM_SINGLECPU_RS <- not yet coded
12
13 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
14 CBOP
15 C !ROUTINE: GLOBAL_SUM_SINGLECPU_RL
16
17 C !INTERFACE:
18 SUBROUTINE GLOBAL_SUM_SINGLECPU_RL(
19 I phiLocal,
20 O sumPhi,
21 I oLi, oLj, myThid )
22 IMPLICIT NONE
23 C !DESCRIPTION:
24 C *==========================================================*
25 C | SUBROUTINE GLOBAL\_SUM\_SINGLECPU\_RL
26 C | o Handle sum for _RL data.
27 C *==========================================================*
28 C | Global sum of 2d array
29 C | independent of tiling as sum is performed on a single CPU
30 C | sum is performed in REAL*8
31 C *==========================================================*
32
33 C !USES:
34 C == Global data ==
35 #include "SIZE.h"
36 #include "EEPARAMS.h"
37 #include "EESUPPORT.h"
38 #include "GLOBAL_SUM.h"
39 #ifdef ALLOW_EXCH2
40 #include "W2_EXCH2_SIZE.h"
41 #include "W2_EXCH2_TOPOLOGY.h"
42 #endif
43 #include "EEBUFF_SCPU.h"
44
45 C !INPUT/OUTPUT PARAMETERS:
46 C == Routine arguments ==
47 C phiLocal :: local input array without overlap regions.
48 C sumPhi :: Result of sum.
49 C oLi, oLj :: overlap size of input array in I & J direction.
50 C myThid :: My thread id.
51 INTEGER oLi, oLj
52 _RL phiLocal(1-oLi:sNx+oLi,1-oLj:sNy+oLj,nSx,nSy)
53 _RL sumPhi
54 INTEGER myThid
55
56 C !LOCAL VARIABLES:
57 C == Local variables ==
58 C- type declaration of: sumAll, globalBuf :
59 C sumAll needs to have the same length as MPI_DOUBLE_PRECISION
60 LOGICAL useExch2GlobLayOut, zeroBuff
61 INTEGER xSize, ySize
62 INTEGER i, j, ij
63 INTEGER bi, bj
64 Real*8 sumAll
65 #ifdef ALLOW_USE_MPI
66 INTEGER pId, idest, itag
67 INTEGER istatus(MPI_STATUS_SIZE), ierr
68 #endif /* ALLOW_USE_MPI */
69 CEOP
70
71 #ifdef ALLOW_EXCH2
72 zeroBuff = .TRUE.
73 useExch2GlobLayOut = .TRUE.
74 xSize = exch2_global_Nx
75 ySize = exch2_global_Ny
76 #else /* ALLOW_EXCH2 */
77 zeroBuff = .FALSE.
78 useExch2GlobLayOut = .FALSE.
79 xSize = Nx
80 ySize = Ny
81 #endif /* ALLOW_EXCH2 */
82 #ifdef ALLOW_USE_MPI
83 idest = 0
84 itag = 0
85 #endif
86
87 C-- copy (and conversion to real*8) to Shared buffer:
88 DO bj = myByLo(myThid), myByHi(myThid)
89 DO bi = myBxLo(myThid), myBxHi(myThid)
90 DO j=1,sNy
91 DO i=1,sNx
92 sharedLocBuf_r8(i,j,bi,bj) = phiLocal(i,j,bi,bj)
93 ENDDO
94 ENDDO
95 ENDDO
96 ENDDO
97
98 C-- Master thread does the communications and the global sum
99 C-- Master thread cannot start until everyone is ready:
100 CALL BAR2( myThid )
101 _BEGIN_MASTER( myThid )
102
103 C-- Gather local arrays
104 CALL GATHER_2D_R8(
105 O xy_buffer_r8,
106 I sharedLocBuf_r8,
107 I xSize, ySize,
108 I useExch2GlobLayOut, zeroBuff, myThid )
109
110 IF ( myProcId.EQ.0 ) THEN
111
112 C-- Process 0 sums the global array
113 sumAll = 0. _d 0
114 DO ij=1,xSize*ySize
115 sumAll = sumAll + xy_buffer_r8(ij)
116 ENDDO
117
118 #ifdef ALLOW_USE_MPI
119 C-- Process 0 sends result to all other processes
120 IF ( usingMPI ) THEN
121 DO pId = 1, (nPx*nPy)-1
122 CALL MPI_SEND (sumAll, 1, MPI_DOUBLE_PRECISION,
123 & pId, itag, MPI_COMM_MODEL, ierr)
124 ENDDO
125 ENDIF
126
127 ELSEIF ( usingMPI ) THEN
128
129 C-- All proceses except 0 receive result from process 0
130 CALL MPI_RECV (sumAll, 1, MPI_DOUBLE_PRECISION,
131 & idest, itag, MPI_COMM_MODEL, istatus, ierr)
132
133 #endif /* ALLOW_USE_MPI */
134
135 ENDIF
136
137 C-- Write solution to shared buffer (all threads can see it)
138 phiGSR8(1,0) = sumAll
139
140 _END_MASTER( myThid )
141 C-- Everyone wait for Master thread to be ready
142 CALL BAR2( myThid )
143
144 C-- set result for every threads
145 sumPhi = phiGSR8(1,0)
146
147 RETURN
148 END

  ViewVC Help
Powered by ViewVC 1.1.22