Back to home page

MITgcm

 
 

    


File indexing completed on 2018-03-02 18:36:09 UTC

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
b043311a0b Jean*0001 #include "CPP_EEOPTIONS.h"
                0002 
924557e60a Chri*0003 C--   File global_max.F: Routines that perform global max reduction on an array
                0004 C                        of thread values.
                0005 C      Contents
b043311a0b Jean*0006 C      o GLOBAL_MAX_R4
                0007 C      o GLOBAL_MAX_R8
924557e60a Chri*0008 
b043311a0b Jean*0009 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
4c563c2ee9 Chri*0010 CBOP
                0011 C     !ROUTINE: GLOBAL_MAX_R4
                0012 
                0013 C     !INTERFACE:
b043311a0b Jean*0014       SUBROUTINE GLOBAL_MAX_R4(
78c96bee2f Alis*0015      U                       maxPhi,
924557e60a Chri*0016      I                       myThid )
b043311a0b Jean*0017 
4c563c2ee9 Chri*0018 C     !DESCRIPTION:
                0019 C     *==========================================================*
b043311a0b Jean*0020 C     | SUBROUTINE GLOBAL\_MAX\_R4
                0021 C     | o Handle max for real*4 data.
4c563c2ee9 Chri*0022 C     *==========================================================*
b043311a0b Jean*0023 C     | Perform max on array of one value per thread and then
                0024 C     | max result of all the processes.
                0025 C     | Notes
                0026 C     | =====
                0027 C     | Within a process only one thread does the max, each
                0028 C     | thread is assumed to have already maxed  its local data.
                0029 C     | The same thread also does the inter-process max for
                0030 C     | example with MPI and then writes the result into a shared
                0031 C     | location. All threads wait until the max is avaiailable.
4c563c2ee9 Chri*0032 C     *==========================================================*
                0033 
                0034 C     !USES:
b043311a0b Jean*0035       IMPLICIT NONE
                0036 
924557e60a Chri*0037 C     == Global data ==
                0038 #include "SIZE.h"
                0039 #include "EEPARAMS.h"
                0040 #include "EESUPPORT.h"
aea29c8517 Alis*0041 #include "GLOBAL_MAX.h"
924557e60a Chri*0042 
4c563c2ee9 Chri*0043 C     !INPUT/OUTPUT PARAMETERS:
924557e60a Chri*0044 C     == Routine arguments ==
4c563c2ee9 Chri*0045 C     maxPhi :: Result of max.
                0046 C     myThid :: My thread id.
924557e60a Chri*0047       Real*4 maxPhi
                0048       INTEGER myThid
                0049 
4c563c2ee9 Chri*0050 C     !LOCAL VARIABLES:
924557e60a Chri*0051 C     == Local variables ==
4c563c2ee9 Chri*0052 C     I      :: Loop counters
                0053 C     mpiRC  :: MPI return code
924557e60a Chri*0054       INTEGER I
                0055       Real*4  tmp
ca1d7a672f Jean*0056 #ifdef ALLOW_USE_MPI
924557e60a Chri*0057       INTEGER mpiRC
                0058 #endif /* ALLOW_USE_MPI */
4c563c2ee9 Chri*0059 CEOP
924557e60a Chri*0060 
78c96bee2f Alis*0061 C--   write local max into array
b043311a0b Jean*0062       phiGMR4(1,myThid) = maxPhi
78c96bee2f Alis*0063 
46dc4f419b Chri*0064 C--   Can not start until everyone is ready
aea29c8517 Alis*0065       CALL BAR2( myThid )
924557e60a Chri*0066 
                0067 C--   Max within the process first
                0068       _BEGIN_MASTER( myThid )
b043311a0b Jean*0069        tmp = phiGMR4(1,1)
924557e60a Chri*0070        DO I=2,nThreads
b043311a0b Jean*0071         tmp = MAX(tmp,phiGMR4(1,I))
924557e60a Chri*0072        ENDDO
                0073        maxPhi = tmp
ca1d7a672f Jean*0074 #ifdef ALLOW_USE_MPI
924557e60a Chri*0075        IF ( usingMPI ) THEN
                0076         CALL MPI_Allreduce(tmp,maxPhi,1,MPI_REAL,MPI_MAX,
ed584e7d0c Jean*0077      &                   MPI_COMM_MODEL,mpiRC)
924557e60a Chri*0078        ENDIF
ca1d7a672f Jean*0079 #endif /* ALLOW_USE_MPI */
b043311a0b Jean*0080        phiGMR4(1,0) = maxPhi
924557e60a Chri*0081       _END_MASTER( myThid )
ca1d7a672f Jean*0082 
                0083 C--   Do not leave until we are sure that the max is done
aea29c8517 Alis*0084       CALL BAR2( myThid )
78c96bee2f Alis*0085 
                0086 C--   set result for every process
b043311a0b Jean*0087       maxPhi = phiGMR4(1,0)
78c96bee2f Alis*0088 
924557e60a Chri*0089       RETURN
                0090       END
                0091 
b043311a0b Jean*0092 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
                0093 CBOP
4c563c2ee9 Chri*0094 C     !ROUTINE: GLOBAL_MAX_R8
                0095 
                0096 C     !INTERFACE:
b043311a0b Jean*0097       SUBROUTINE GLOBAL_MAX_R8(
924557e60a Chri*0098      O                       maxPhi,
                0099      I                       myThid )
b043311a0b Jean*0100 
4c563c2ee9 Chri*0101 C     !DESCRIPTION:
                0102 C     *==========================================================*
b043311a0b Jean*0103 C     | SUBROUTINE GLOBAL\_MAX\_R8
                0104 C     | o Handle max for real*8 data.
4c563c2ee9 Chri*0105 C     *==========================================================*
b043311a0b Jean*0106 C     | Perform max on array of one value per thread and then
                0107 C     | max result of all the processes.
                0108 C     | Notes
                0109 C     | =====
                0110 C     | Within a process only one thread does the max, each
                0111 C     | thread is assumed to have already maxed  its local data.
                0112 C     | The same thread also does the inter-process max for
                0113 C     | example with MPI and then writes the result into a shared
                0114 C     | location. All threads wait until the max is avaiailable.
4c563c2ee9 Chri*0115 C     *==========================================================*
                0116 
                0117 C     !USES:
b043311a0b Jean*0118       IMPLICIT NONE
                0119 
924557e60a Chri*0120 C     === Global data ===
                0121 #include "SIZE.h"
                0122 #include "EEPARAMS.h"
                0123 #include "EESUPPORT.h"
aea29c8517 Alis*0124 #include "GLOBAL_MAX.h"
924557e60a Chri*0125 
4c563c2ee9 Chri*0126 C     !INPUT/OUTPUT PARAMETERS:
924557e60a Chri*0127 C     === Routine arguments ===
4c563c2ee9 Chri*0128 C     maxPhi :: Result of max.
                0129 C     myThid :: My thread id.
924557e60a Chri*0130       Real*8 maxPhi
                0131       INTEGER myThid
                0132 
4c563c2ee9 Chri*0133 C     !LOCAL VARIABLES:
924557e60a Chri*0134 C     === Local variables ===
4c563c2ee9 Chri*0135 C     I      :: Loop counters
                0136 C     mpiRC  :: MPI return code
924557e60a Chri*0137       INTEGER I
                0138       Real*8  tmp
ca1d7a672f Jean*0139 #ifdef ALLOW_USE_MPI
924557e60a Chri*0140       INTEGER mpiRC
                0141 #endif   /* ALLOW_USE_MPI */
4c563c2ee9 Chri*0142 CEOP
924557e60a Chri*0143 
78c96bee2f Alis*0144 C--   write local max into array
b043311a0b Jean*0145       phiGMR8(1,myThid) = maxPhi
78c96bee2f Alis*0146 
46dc4f419b Chri*0147 C--   Can not start until everyone is ready
aea29c8517 Alis*0148       CALL BAR2( myThid )
924557e60a Chri*0149 
                0150 C--   Max within the process first
                0151       _BEGIN_MASTER( myThid )
b043311a0b Jean*0152        tmp = phiGMR8(1,1)
924557e60a Chri*0153        DO I=2,nThreads
b043311a0b Jean*0154         tmp = MAX(tmp,phiGMR8(1,I))
924557e60a Chri*0155        ENDDO
                0156        maxPhi = tmp
ca1d7a672f Jean*0157 #ifdef ALLOW_USE_MPI
924557e60a Chri*0158        IF ( usingMPI ) THEN
                0159         CALL MPI_Allreduce(tmp,maxPhi,1,MPI_DOUBLE_PRECISION,MPI_MAX,
ed584e7d0c Jean*0160      &                   MPI_COMM_MODEL,mpiRC)
924557e60a Chri*0161        ENDIF
ca1d7a672f Jean*0162 #endif /* ALLOW_USE_MPI */
924557e60a Chri*0163 C--     Write solution to place where all threads can see it
b043311a0b Jean*0164        phiGMR8(1,0) = maxPhi
924557e60a Chri*0165       _END_MASTER( myThid )
                0166 
46dc4f419b Chri*0167 C--   Do not leave until we are sure that the max is done
aea29c8517 Alis*0168       CALL BAR2( myThid )
78c96bee2f Alis*0169 
                0170 C--   set result for every process
b043311a0b Jean*0171       maxPhi = phiGMR8(1,0)
78c96bee2f Alis*0172 
924557e60a Chri*0173       RETURN
                0174       END