| 1 | dimitri | 1.6.14.1 | C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/eedie.F,v 1.6 2001/04/10 22:35:24 heimbach Exp $ | 
| 2 |  |  | C $Name: release1_beta1 $ | 
| 3 | cnh | 1.1 |  | 
| 4 | dimitri | 1.6.14.1 | #include "CPP_OPTIONS.h" | 
| 5 | cnh | 1.1 |  | 
| 6 |  |  | CStartOfInterface | 
| 7 |  |  | SUBROUTINE EEDIE | 
| 8 |  |  | C     /==========================================================\ | 
| 9 |  |  | C     | SUBROUTINE EEDIE                                         | | 
| 10 |  |  | C     | o Close execution "environment", particularly perform    | | 
| 11 |  |  | C     |   steps to terminate parallel processing.                | | 
| 12 |  |  | C     |==========================================================| | 
| 13 |  |  | C     | Note: This routine can also be compiled with CPP         | | 
| 14 |  |  | C     | directives set so that no multi-processing is initialised| | 
| 15 |  |  | C     | This is OK and should work fine.                         | | 
| 16 |  |  | C     \==========================================================/ | 
| 17 | adcroft | 1.4 | IMPLICIT NONE | 
| 18 | cnh | 1.1 |  | 
| 19 |  |  | C     == Global variables == | 
| 20 |  |  | #include "SIZE.h" | 
| 21 |  |  | #include "EEPARAMS.h" | 
| 22 |  |  | #include "EESUPPORT.h" | 
| 23 |  |  | CEndOfInterface | 
| 24 |  |  |  | 
| 25 |  |  | C     == Local variables == | 
| 26 |  |  | C     msgBuf       - I/O Buffer | 
| 27 |  |  | C     nThreadsDone - Used to count number of completed threads. | 
| 28 |  |  | C     I            - Loop counter. | 
| 29 |  |  | CHARACTER*(MAX_LEN_MBUF) msgBuf | 
| 30 |  |  | INTEGER nThreadsDone | 
| 31 |  |  | INTEGER I | 
| 32 |  |  | #ifdef ALLOW_USE_MPI | 
| 33 |  |  | C     mpiRC            - Error code reporting variable used | 
| 34 |  |  | C                        with MPI. | 
| 35 |  |  | INTEGER mpiRC | 
| 36 |  |  | #endif /* ALLOW_USE_MPI */ | 
| 37 |  |  |  | 
| 38 |  |  | C--   Check that all the threads have ended | 
| 39 |  |  | C     No thread should reach this loop before all threads have set | 
| 40 |  |  | C     threadIsComplete to TRUE. If they do then either there is a bug | 
| 41 |  |  | C     in the code or the behaviour of the parallel compiler directives | 
| 42 | cnh | 1.3 | C     are not right for this code. In the latter case different | 
| 43 |  |  | C     directives may be available or the compiler itself may have a | 
| 44 |  |  | C     bug or you may need a different parallel compiler for main.F | 
| 45 | cnh | 1.1 | nThreadsDone = 0 | 
| 46 |  |  | DO I = 1, nThreads | 
| 47 |  |  | IF ( threadIsComplete(I) ) nThreadsDone = nThreadsDone+1 | 
| 48 |  |  | ENDDO | 
| 49 |  |  | IF ( nThreadsDone .LT. nThreads ) THEN | 
| 50 | adcroft | 1.4 | WRITE(msgBuf,'(A,I5,A,I5,A)') | 
| 51 | cnh | 1.1 | & 'S/R EEDIE: Only ',nThreadsDone, | 
| 52 | cnh | 1.3 | & ' threads have completed, ',nThreads, | 
| 53 |  |  | & ' are expected for this configuration!' | 
| 54 | heimbach | 1.6 | WRITE(*,*) msgBuf | 
| 55 |  |  | WRITE(*,*) | 
| 56 | cnh | 1.3 | & 'Possibly you have different setenv PARALLEL and nThreads?' | 
| 57 | cnh | 1.1 | eeEndError = .TRUE. | 
| 58 |  |  | fatalError = .TRUE. | 
| 59 |  |  | ENDIF | 
| 60 |  |  |  | 
| 61 |  |  | #ifdef ALLOW_USE_MPI | 
| 62 |  |  | C-- | 
| 63 |  |  | C--   MPI style multiple-process termination | 
| 64 |  |  | C--   ====================================== | 
| 65 |  |  | #ifndef ALWAYS_USE_MPI | 
| 66 |  |  | IF ( usingMPI ) THEN | 
| 67 |  |  | #endif | 
| 68 | dimitri | 1.6.14.1 |  | 
| 69 |  |  | #if !defined(COUPLED_UCLA) || defined(COUPLED_DEBUG) | 
| 70 |  |  |  | 
| 71 | cnh | 1.1 | CALL MPI_FINALIZE  ( mpiRC ) | 
| 72 |  |  | IF ( mpiRC .NE. MPI_SUCCESS ) THEN | 
| 73 |  |  | eeEndError = .TRUE. | 
| 74 |  |  | fatalError = .TRUE. | 
| 75 | adcroft | 1.4 | WRITE(msgBuf,'(A,I5)') | 
| 76 | cnh | 1.1 | &       'S/R FIN_PROCS: MPI_FINALIZE return code', | 
| 77 |  |  | &       mpiRC | 
| 78 |  |  | CALL PRINT_ERROR( msgBuf, 1 ) | 
| 79 |  |  | ENDIF | 
| 80 | dimitri | 1.6.14.1 |  | 
| 81 |  |  | #endif COUPLED_UCLA | 
| 82 |  |  |  | 
| 83 | cnh | 1.1 | #ifndef ALWAYS_USE_MPI | 
| 84 |  |  | ENDIF | 
| 85 |  |  | #endif | 
| 86 |  |  | #endif /* ALLOW_USE_MPI */ | 
| 87 |  |  |  | 
| 88 |  |  |  | 
| 89 |  |  | RETURN | 
| 90 |  |  | END |