1 |
C $Header: /u/gcmpack/MITgcm/verification/cpl_aim+ocn/code_ocn/eeboot_minimal.F,v 1.1 2004/10/27 23:19:43 edhill Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: EEBOOT_MINIMAL |
8 |
|
9 |
C !INTERFACE: |
10 |
SUBROUTINE EEBOOT_MINIMAL |
11 |
IMPLICIT NONE |
12 |
|
13 |
C !DESCRIPTION: |
14 |
C *==========================================================* |
15 |
C | SUBROUTINE EEBOOT\_MINIMAL |
16 |
C | o Set an initial environment that is predictable i.e. |
17 |
C | behaves in a similar way on all machines and stable. |
18 |
C *==========================================================* |
19 |
C | Under MPI this routine calls MPI\_INIT to setup the |
20 |
C | mpi environment ( on some systems the code is running as |
21 |
C | a single process prior to MPI\_INIT, on others the mpirun |
22 |
C | script has already created multiple processes). Until |
23 |
C | MPI\_Init is called it is unclear what state the |
24 |
C | application is in. Once this routine has been run it is |
25 |
C | "safe" to do things like I/O to report erros and to get |
26 |
C | run parameters. |
27 |
C | Note: This routine can also be compiled with CPP |
28 |
C | directives set so that no multi-processing is initialise. |
29 |
C | This is OK and will work fine. |
30 |
C *==========================================================* |
31 |
|
32 |
C !USES: |
33 |
C == Global data == |
34 |
#include "SIZE.h" |
35 |
#include "EEPARAMS.h" |
36 |
#include "EESUPPORT.h" |
37 |
|
38 |
C !LOCAL VARIABLES: |
39 |
C == Local variables == |
40 |
C myThid :: Temp. dummy thread number. |
41 |
C fNam :: Used to build name of file for standard |
42 |
C output and error output. |
43 |
INTEGER myThid |
44 |
CHARACTER*13 fNam |
45 |
#ifdef ALLOW_USE_MPI |
46 |
C mpiRC :: Error code reporting variable used |
47 |
C with MPI. |
48 |
C msgBuffer :: Used to build messages for printing. |
49 |
CHARACTER*(MAX_LEN_MBUF) msgBuffer |
50 |
INTEGER mpiRC |
51 |
INTEGER nptmp |
52 |
INTEGER mpiMyWid |
53 |
#endif /* ALLOW_USE_MPI */ |
54 |
CEOP |
55 |
|
56 |
C-- Default values set to single processor case |
57 |
numberOfProcs = 1 |
58 |
myProcId = 0 |
59 |
pidIO = myProcId |
60 |
myProcessStr = '------' |
61 |
C Set a dummy value for myThid because we are not multi-threading |
62 |
C yet. |
63 |
myThid = 1 |
64 |
#ifdef ALLOW_USE_MPI |
65 |
C-- |
66 |
C-- MPI style multiple-process initialisation |
67 |
C-- ========================================= |
68 |
#ifndef ALWAYS_USE_MPI |
69 |
IF ( usingMPI ) THEN |
70 |
#endif |
71 |
C-- Initialise MPI multi-process parallel environment. |
72 |
C On some systems program forks at this point. Others have already |
73 |
C forked within mpirun - now thats an open standard! |
74 |
CALL MPI_INIT( mpiRC ) |
75 |
IF ( mpiRC .NE. MPI_SUCCESS ) THEN |
76 |
eeBootError = .TRUE. |
77 |
WRITE(msgBuffer,'(A,I5)') |
78 |
& 'S/R INI_PROCS: MPI_INIT return code', |
79 |
& mpiRC |
80 |
CALL PRINT_ERROR( msgBuffer , myThid) |
81 |
GOTO 999 |
82 |
ENDIF |
83 |
|
84 |
C-- Set the running directory |
85 |
C CALL SETENV |
86 |
CALL MPI_COMM_RANK( MPI_COMM_WORLD, mpiMyWId, mpiRC ) |
87 |
CALL SETDIR( mpiMyWId ) |
88 |
|
89 |
C-- MPI has now been initialized but now we need to either |
90 |
C ask for a communicator or pretend that we have: |
91 |
C Pretend that we have asked for a communicator |
92 |
MPI_COMM_MODEL = MPI_COMM_WORLD |
93 |
#ifdef COMPONENT_MODULE |
94 |
C- jmc: test: |
95 |
C add a 1rst preliminary call EESET_PARAMS to set useCoupler |
96 |
C (needed to decide either to call CPL_INIT or not) |
97 |
CALL EESET_PARMS |
98 |
IF ( eeBootError ) GOTO 999 |
99 |
C- jmc: test end ; otherwise, uncomment next line: |
100 |
c useCoupler = .TRUE. |
101 |
C-- Ask coupler interface for a communicator |
102 |
IF ( useCoupler) CALL CPL_INIT |
103 |
#endif |
104 |
|
105 |
C-- Get my process number |
106 |
CALL MPI_COMM_RANK( MPI_COMM_MODEL, mpiMyId, mpiRC ) |
107 |
IF ( mpiRC .NE. MPI_SUCCESS ) THEN |
108 |
eeBootError = .TRUE. |
109 |
WRITE(msgBuffer,'(A,I5)') |
110 |
& 'S/R INI_PROCS: MPI_COMM_RANK return code', |
111 |
& mpiRC |
112 |
CALL PRINT_ERROR( msgBuffer , myThid) |
113 |
GOTO 999 |
114 |
ENDIF |
115 |
myProcId = mpiMyId |
116 |
WRITE(myProcessStr,'(I4.4)') myProcId |
117 |
mpiPidIo = myProcId |
118 |
pidIO = mpiPidIo |
119 |
IF ( mpiPidIo .EQ. myProcId ) THEN |
120 |
WRITE(fNam,'(A,A)') 'STDERR.', myProcessStr(1:4) |
121 |
OPEN(errorMessageUnit,FILE=fNam,STATUS='unknown') |
122 |
WRITE(fNam,'(A,A)') 'STDOUT.', myProcessStr(1:4) |
123 |
OPEN(standardMessageUnit,FILE=fNam,STATUS='unknown') |
124 |
ENDIF |
125 |
|
126 |
C-- Synchronise all processes |
127 |
C Strictly this is superfluous, but by using it we can guarantee to |
128 |
C find out about processes that did not start up. |
129 |
CALL MPI_BARRIER( MPI_COMM_MODEL, mpiRC ) |
130 |
IF ( mpiRC .NE. MPI_SUCCESS ) THEN |
131 |
eeBootError = .TRUE. |
132 |
WRITE(msgBuffer,'(A,I5)') |
133 |
& 'S/R INI_PROCS: MPI_BARRIER return code', |
134 |
& mpiRC |
135 |
CALL PRINT_ERROR( msgBuffer , myThid) |
136 |
GOTO 999 |
137 |
ENDIF |
138 |
|
139 |
C-- Get number of MPI processes |
140 |
CALL MPI_COMM_SIZE ( MPI_COMM_MODEL, mpiNProcs, mpiRC ) |
141 |
IF ( mpiRC .NE. MPI_SUCCESS ) THEN |
142 |
eeBootError = .TRUE. |
143 |
WRITE(msgBuffer,'(A,I5)') |
144 |
& 'S/R INI_PROCS: MPI_COMM_SIZE return code', |
145 |
& mpiRC |
146 |
CALL PRINT_ERROR( msgBuffer , myThid) |
147 |
GOTO 999 |
148 |
ENDIF |
149 |
numberOfProcs = mpiNProcs |
150 |
|
151 |
C-- Can not have more processes than compile time MAX_NO_PROCS |
152 |
IF ( numberOfProcs .GT. MAX_NO_PROCS ) THEN |
153 |
eeBootError = .TRUE. |
154 |
WRITE(msgBuffer,'(A)') |
155 |
& 'S/R INI_PROCS: No. of processes too large' |
156 |
CALL PRINT_ERROR( msgBuffer , myThid) |
157 |
GOTO 999 |
158 |
ENDIF |
159 |
C-- Under MPI only allow same number of processes as proc. |
160 |
C-- grid size. |
161 |
C Strictly we are allowed more procs. but knowing there |
162 |
C is an exact match makes things easier. |
163 |
IF ( numberOfProcs .NE. nPx*nPy ) THEN |
164 |
eeBootError = .TRUE. |
165 |
nptmp = nPx*nPy |
166 |
WRITE(msgBuffer,'(A,2I5)') |
167 |
& 'S/R INI_PROCS: No. of processes not equal to nPx*nPy', |
168 |
& numberOfProcs, nptmp |
169 |
CALL PRINT_ERROR( msgBuffer , myThid) |
170 |
GOTO 999 |
171 |
ENDIF |
172 |
|
173 |
#ifndef ALWAYS_USE_MPI |
174 |
ENDIF |
175 |
#endif |
176 |
|
177 |
#else /* ALLOW_USE_MPI */ |
178 |
|
179 |
WRITE(myProcessStr,'(I4.4)') myProcId |
180 |
WRITE(fNam,'(A,A)') 'STDERR.', myProcessStr(1:4) |
181 |
OPEN(errorMessageUnit,FILE=fNam,STATUS='unknown') |
182 |
c WRITE(fNam,'(A,A)') 'STDOUT.', myProcessStr(1:4) |
183 |
c OPEN(standardMessageUnit,FILE=fNam,STATUS='unknown') |
184 |
|
185 |
#endif /* ALLOW_USE_MPI */ |
186 |
|
187 |
999 CONTINUE |
188 |
|
189 |
RETURN |
190 |
END |
191 |
|