1 | #!/bin/ksh |
---|
2 | |
---|
3 | #************************************************************** |
---|
4 | # Author: Sebastien Denvil |
---|
5 | # Contact: Sebastien.Denvil__at__ipsl.jussieu.fr |
---|
6 | # $Revision:: $ Revision of last commit |
---|
7 | # $Author:: $ Author of last commit |
---|
8 | # $Date:: $ Date of last commit |
---|
9 | # IPSL (2006) |
---|
10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
11 | # |
---|
12 | #************************************************************** |
---|
13 | |
---|
14 | #========================================================= |
---|
15 | # The documentation of this file can be automatically generated |
---|
16 | # if you use the prefix #D- for comments to be extracted. |
---|
17 | # Extract with command: cat lib* | grep "^#D-" | cut -c "4-" |
---|
18 | #========================================================= |
---|
19 | |
---|
20 | #D-#================================================== |
---|
21 | #D-LibIGCM_sys for ciclad |
---|
22 | #D-#================================================== |
---|
23 | #D- |
---|
24 | #D- This ksh library if a layer under some usefull |
---|
25 | #D-environment variables and shell commands. |
---|
26 | #D-All those definitions depend on host particularities. |
---|
27 | #D-It manages a stack mechanism and test validity of operations. |
---|
28 | #D-All function described bellow must be prefixed by IGCM_sys. |
---|
29 | |
---|
30 | #==================================================== |
---|
31 | # libIGCM_sys PARAMETERS |
---|
32 | #==================================================== |
---|
33 | |
---|
34 | #==================================================== |
---|
35 | # set DEBUG_sys to true to output calls of function |
---|
36 | typeset -r DEBUG_sys=${DEBUG_sys:=true} |
---|
37 | |
---|
38 | #==================================================== |
---|
39 | # Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get) |
---|
40 | typeset -r DRYRUN=${DRYRUN:=0} |
---|
41 | |
---|
42 | # YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE ! |
---|
43 | # ------------------------------------------------------------------------------------- |
---|
44 | # | DRYRUN= | Date computations, | sys_Get | Exe | sys_Put_Out; sys_Put_Rest | |
---|
45 | # | | Cp/Exe/param/files | | | | |
---|
46 | # | | Chmod Qsub | | | | |
---|
47 | # ------------------------------------------------------------------------------------- |
---|
48 | # | 0 | yes | yes | yes | yes | |
---|
49 | # ------------------------------------------------------------------------------------- |
---|
50 | # | 1 | yes | yes | yes | no | |
---|
51 | # ------------------------------------------------------------------------------------- |
---|
52 | # | 2 | yes | yes | no | no | |
---|
53 | # ------------------------------------------------------------------------------------- |
---|
54 | # | 3 | yes | no | no | no | |
---|
55 | # ------------------------------------------------------------------------------------- |
---|
56 | |
---|
57 | #===================================================== |
---|
58 | # Global Variables : |
---|
59 | #===================================================== |
---|
60 | # Language : "fr" or "en" |
---|
61 | typeset -r MYLANG="fr" |
---|
62 | |
---|
63 | #===================================================== |
---|
64 | # Host user names project maxCpuTime |
---|
65 | # $hostname ou hostname |
---|
66 | typeset HOST=${HOST:=$( hostname )} |
---|
67 | # $username ou whoami |
---|
68 | typeset LOGIN=${LOGIN:=$( whoami )} |
---|
69 | # $hostname of the MASTER job |
---|
70 | typeset MASTER=${MASTER:=$( hostname )} |
---|
71 | # project name |
---|
72 | typeset PROJECT=NONE |
---|
73 | # jobWarningDelay in seconds |
---|
74 | typeset jobWarningDelay=${PBS_WALLTIME} |
---|
75 | |
---|
76 | #D- |
---|
77 | #D-#================================================== |
---|
78 | #D-Program used in libIGCM |
---|
79 | #D-#================================================== |
---|
80 | |
---|
81 | # Submit command |
---|
82 | typeset SUBMIT=${SUBMIT:=qsub} |
---|
83 | # rsync with path |
---|
84 | typeset -r RSYNC=/usr/bin/rsync |
---|
85 | # RSYNC_opt args to rsync |
---|
86 | typeset -r RSYNC_opt="-va" |
---|
87 | # ie storage filesystem |
---|
88 | typeset -r STOREHOST=${MASTER} |
---|
89 | |
---|
90 | #==================================================== |
---|
91 | # Access to module command |
---|
92 | #==================================================== |
---|
93 | . /usr/share/Modules/init/ksh |
---|
94 | |
---|
95 | #==================================================== |
---|
96 | # Set environment tools (ferret, nco, cdo, rebuild, ...) |
---|
97 | #==================================================== |
---|
98 | if [ X${TaskType} = Xcomputing ] ; then |
---|
99 | IGCM_debug_Print 1 "Modules will be loaded later in IGCM_sys_activ_variables." |
---|
100 | else |
---|
101 | if [ $CENTER == IPSL-ciclad ] ; then |
---|
102 | # At ciclad |
---|
103 | . /home/igcmg/MachineEnvironment/ciclad/atlas_env_ciclad |
---|
104 | else |
---|
105 | # At climserv use the same files stored at ciclad but adapt the path |
---|
106 | . /ciclad-home/igcmg/MachineEnvironment/climserv/atlas_env_climserv |
---|
107 | fi |
---|
108 | fi |
---|
109 | |
---|
110 | # Load python |
---|
111 | module load python/2.7-anaconda > /dev/null 2>&1 |
---|
112 | |
---|
113 | [ ! X${TaskType} = Xchecking ] && IGCM_debug_Print 1 "List of loaded modules:" |
---|
114 | [ ! X${TaskType} = Xchecking ] && module list |
---|
115 | |
---|
116 | #==================================================== |
---|
117 | # Host specific DIRECTORIES |
---|
118 | #==================================================== |
---|
119 | # For rebuild |
---|
120 | if [ $CENTER == IPSL-ciclad ] ; then |
---|
121 | export PATH=${PATH}:/home/igcmg/rebuild/src_X64_CICLAD/modipsl_v2_2_3_netcdf4.2/bin/ |
---|
122 | else |
---|
123 | export PATH=${PATH}:/ciclad-home/igcmg/rebuild/src_X64_CICLAD/modipsl_v2_2_3_netcdf4.2/bin/ |
---|
124 | fi |
---|
125 | #==================================================== |
---|
126 | #- MirrorlibIGCM for frontend |
---|
127 | typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false} |
---|
128 | |
---|
129 | #==================================================== |
---|
130 | #- libIGCM_POST for frontend |
---|
131 | typeset -r libIGCM_POST=${libIGCM} |
---|
132 | |
---|
133 | #==================================================== |
---|
134 | #- R_EXE (==> BIN_DIR = ${MODIPSL}/bin ) |
---|
135 | typeset -r R_EXE="${MODIPSL}/bin" |
---|
136 | |
---|
137 | #==================================================== |
---|
138 | #- SUBMIT_DIR : submission dir |
---|
139 | if [ X${PBS_O_WORKDIR} != X ] ; then |
---|
140 | typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}} |
---|
141 | else |
---|
142 | typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${PWD}} |
---|
143 | fi |
---|
144 | |
---|
145 | #==================================================== |
---|
146 | #- IN |
---|
147 | typeset -r R_IN=${R_IN:=/prodigfs/ipslfs/igcmg/IGCM} |
---|
148 | |
---|
149 | #==================================================== |
---|
150 | #- RUN_DIR_PATH : Temporary working directory (=> TMP) |
---|
151 | if [ X${PBS_JOBID} != X ] ; then |
---|
152 | if [ $CENTER == IPSL-ciclad ] ; then |
---|
153 | typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/data/${LOGIN}/RUN_DIR/${PBS_JOBID}_${$}} |
---|
154 | else |
---|
155 | typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/homedata/${LOGIN}/RUN_DIR/${PBS_JOBID}_${$}} |
---|
156 | fi |
---|
157 | else |
---|
158 | typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/tmp/tmp$$} |
---|
159 | fi |
---|
160 | |
---|
161 | #==================================================== |
---|
162 | #- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs |
---|
163 | typeset -r OUTCOMMAND_PATH=/tmp |
---|
164 | |
---|
165 | #==================================================== |
---|
166 | #- HOST_MPIRUN_COMMAND |
---|
167 | typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"} |
---|
168 | |
---|
169 | #==================================================== |
---|
170 | #- Max number of arguments passed to nco operator or demigration command |
---|
171 | UNIX_MAX_LIMIT=360 |
---|
172 | |
---|
173 | #==================================================== |
---|
174 | #- set PackDefault to false on ciclad |
---|
175 | PackDefault=false |
---|
176 | |
---|
177 | #==================================================== |
---|
178 | #- Default number of MPI task for IPSL coupled model |
---|
179 | #- required for backward compatibility |
---|
180 | #- |
---|
181 | DEFAULT_NUM_PROC_OCE=5 |
---|
182 | DEFAULT_NUM_PROC_CPL=1 |
---|
183 | (( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL )) |
---|
184 | |
---|
185 | #D-#================================================== |
---|
186 | #D-function IGCM_sys_defineArchives |
---|
187 | #D-* Purpose: |
---|
188 | #D-* Define ARCHIVE : Dedicated to large files |
---|
189 | #D-* Define STORAGE : Dedicated to small/medium files |
---|
190 | #D-* Define R_OUT : Output tree located on ARCHIVE |
---|
191 | #D-* Define R_FIG : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files) |
---|
192 | #D-* Define R_BUF : Output tree located on STORAGE hosting files waiting for rebuild or pack processes |
---|
193 | #D-* if SpaceName=TEST nothing special will hapen |
---|
194 | #D-* Examples: |
---|
195 | #D- |
---|
196 | function IGCM_sys_defineArchives { |
---|
197 | IGCM_debug_PushStack "IGCM_sys_defineArchives" |
---|
198 | |
---|
199 | if [ ! X${config_UserChoices_ARCHIVE} = X ]; then |
---|
200 | #==================================================== |
---|
201 | #- ARCHIVE (dedicated to large files) |
---|
202 | ARCHIVE=${config_UserChoices_ARCHIVE} |
---|
203 | else |
---|
204 | #==================================================== |
---|
205 | #- ARCHIVE (dedicated to large files) |
---|
206 | if [ $CENTER == IPSL-ciclad ] ; then |
---|
207 | # At ciclad |
---|
208 | ARCHIVE=${ARCHIVE:=/data/${LOGIN}} |
---|
209 | else |
---|
210 | # At climserv |
---|
211 | ARCHIVE=${ARCHIVE:=/homedata/${LOGIN}} |
---|
212 | fi |
---|
213 | fi |
---|
214 | |
---|
215 | if [ ! X${config_UserChoices_STORAGE} = X ]; then |
---|
216 | #==================================================== |
---|
217 | #- STORAGE (dedicated to small/medium files) |
---|
218 | STORAGE=${config_UserChoices_STORAGE} |
---|
219 | else |
---|
220 | #==================================================== |
---|
221 | #- STORAGE (dedicated to small/medium files) |
---|
222 | STORAGE=${ARCHIVE} |
---|
223 | fi |
---|
224 | |
---|
225 | # ON CICLAD NO SPECIAL CASE WHEN X${config_UserChoices_SpaceName} = XTEST |
---|
226 | |
---|
227 | #==================================================== |
---|
228 | #- R_OUT |
---|
229 | R_OUT=${ARCHIVE}/IGCM_OUT |
---|
230 | |
---|
231 | #==================================================== |
---|
232 | #- R_FIG (hosting figures : monitoring and atlas, and/or small files) |
---|
233 | R_FIG=${STORAGE}/IGCM_OUT |
---|
234 | |
---|
235 | #==================================================== |
---|
236 | #- CMIP6 (hosting CMIP6 files produced by XIOS2 and configured by dr2xml) |
---|
237 | CMIP6_BUF=${STORAGE}/IGCM_OUT |
---|
238 | |
---|
239 | #==================================================== |
---|
240 | #- R_BUF (ONLY FOR double copy an scratch) |
---|
241 | R_BUF=${STORAGE}/IGCM_OUT |
---|
242 | |
---|
243 | IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}" |
---|
244 | IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}" |
---|
245 | IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}" |
---|
246 | |
---|
247 | IGCM_debug_PopStack "IGCM_sys_defineArchives" |
---|
248 | } |
---|
249 | |
---|
250 | #D-#================================================== |
---|
251 | #D-function IGCM_sys_RshArchive |
---|
252 | #D-* Purpose: Archive rsh command |
---|
253 | #D-* Examples: |
---|
254 | #D- |
---|
255 | function IGCM_sys_RshArchive { |
---|
256 | IGCM_debug_PushStack "IGCM_sys_RshArchive" $@ |
---|
257 | /bin/ksh <<-EOF |
---|
258 | ${@} |
---|
259 | EOF |
---|
260 | status=$? |
---|
261 | if [ ${status} -gt 0 ] ; then |
---|
262 | IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}" |
---|
263 | IGCM_debug_Exit "IGCM_sys_RshArchive" |
---|
264 | fi |
---|
265 | IGCM_debug_PopStack "IGCM_sys_RshArchive" |
---|
266 | } |
---|
267 | |
---|
268 | #D-#================================================== |
---|
269 | #D-function IGCM_sys_RshArchive_NoError |
---|
270 | #D-* Purpose: Archive rsh command, without error |
---|
271 | #D-* used only in monitoring.job |
---|
272 | #D-* Examples: |
---|
273 | #D- |
---|
274 | function IGCM_sys_RshArchive_NoError { |
---|
275 | IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@ |
---|
276 | /bin/ksh <<-EOF |
---|
277 | ${@} 2> /dev/null |
---|
278 | EOF |
---|
279 | IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError" |
---|
280 | } |
---|
281 | |
---|
282 | #D-#================================================== |
---|
283 | #D-function IGCM_sys_MkdirArchive |
---|
284 | #D-* Purpose: Mkdir on Archive |
---|
285 | #D-* Examples: |
---|
286 | #D- |
---|
287 | function IGCM_sys_MkdirArchive { |
---|
288 | IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@ |
---|
289 | if ( $DEBUG_sys ) ; then |
---|
290 | echo "IGCM_sys_MkdirArchive :" $@ |
---|
291 | fi |
---|
292 | #- creation de repertoire sur le serveur fichier |
---|
293 | if [ ! -d ${1} ]; then |
---|
294 | \mkdir -p $1 |
---|
295 | status=$? |
---|
296 | |
---|
297 | if [ ${status} -gt 0 ] ; then |
---|
298 | IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}" |
---|
299 | IGCM_debug_Exit "IGCM_sys_MkdirArchive" |
---|
300 | fi |
---|
301 | fi |
---|
302 | IGCM_debug_PopStack "IGCM_sys_MkdirArchive" |
---|
303 | } |
---|
304 | |
---|
305 | #D-#================================================== |
---|
306 | #D-function IGCM_sys_TestDirArchive |
---|
307 | #D-* Purpose: Test Directory that must exists on Archive |
---|
308 | #D-* Examples: |
---|
309 | #D- |
---|
310 | function IGCM_sys_TestDirArchive { |
---|
311 | IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@ |
---|
312 | if ( $DEBUG_sys ) ; then |
---|
313 | echo "IGCM_sys_TestDirArchive :" $@ |
---|
314 | fi |
---|
315 | typeset ExistFlag |
---|
316 | ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 ) |
---|
317 | IGCM_debug_PopStack "IGCM_sys_TestDirArchive" |
---|
318 | return ${ExistFlag} |
---|
319 | } |
---|
320 | |
---|
321 | #D-#================================================== |
---|
322 | #D-function IGCM_sys_IsFileArchived |
---|
323 | #D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only |
---|
324 | #D-* Examples: |
---|
325 | #D- |
---|
326 | function IGCM_sys_IsFileArchived { |
---|
327 | IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@ |
---|
328 | if ( $DEBUG_sys ) ; then |
---|
329 | echo "IGCM_sys_IsFileArchived :" $@ |
---|
330 | fi |
---|
331 | typeset IsArchivedFlag |
---|
332 | # Never archived for this system |
---|
333 | IsArchivedFlag=1 |
---|
334 | IGCM_debug_PopStack "IGCM_sys_IsFileArchived" |
---|
335 | |
---|
336 | return ${IsArchivedFlag} |
---|
337 | } |
---|
338 | |
---|
339 | #D-#================================================== |
---|
340 | #D-function IGCM_sys_TestFileArchive |
---|
341 | #D-* Purpose: Test file that must NOT EXISTS on Archive |
---|
342 | #D-* Examples: |
---|
343 | #D- |
---|
344 | function IGCM_sys_TestFileArchive { |
---|
345 | IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@ |
---|
346 | typeset ExistFlag |
---|
347 | ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 ) |
---|
348 | IGCM_debug_PopStack "IGCM_sys_TestFileArchive" |
---|
349 | |
---|
350 | return ${ExistFlag} |
---|
351 | } |
---|
352 | |
---|
353 | #D-#================================================== |
---|
354 | #D-function IGCM_sys_CountFileArchive |
---|
355 | #D-* Purpose: Count files on Archive filesystem |
---|
356 | #D-* Examples: |
---|
357 | #D- |
---|
358 | function IGCM_sys_CountFileArchive { |
---|
359 | IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@ |
---|
360 | ls ${@} 2>/dev/null | wc -l |
---|
361 | if [ $? -gt 0 ] ; then |
---|
362 | echo "IGCM_sys_CountFileArchive : erreur." |
---|
363 | fi |
---|
364 | IGCM_debug_PopStack "IGCM_sys_CountFileArchive" |
---|
365 | } |
---|
366 | |
---|
367 | #D-#================================================== |
---|
368 | #D-function IGCM_sys_Tree |
---|
369 | #D-* Purpose: Tree directories with files on ${ARCHIVE} |
---|
370 | #D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT} |
---|
371 | #D- |
---|
372 | function IGCM_sys_Tree { |
---|
373 | IGCM_debug_PushStack "IGCM_sys_Tree" $@ |
---|
374 | if ( $DEBUG_sys ) ; then |
---|
375 | echo "IGCM_sys_Tree :" $@ |
---|
376 | fi |
---|
377 | |
---|
378 | \ls -lR ${@} |
---|
379 | |
---|
380 | IGCM_debug_PopStack "IGCM_sys_Tree" |
---|
381 | } |
---|
382 | |
---|
383 | #D-#================================================== |
---|
384 | #D-function IGCM_sys_Qsub |
---|
385 | #D-* Purpose: Qsub new job |
---|
386 | #D-* Examples: |
---|
387 | #D- |
---|
388 | function IGCM_sys_Qsub { |
---|
389 | IGCM_debug_PushStack "IGCM_sys_Qsub" $@ |
---|
390 | if ( $DEBUG_sys ) ; then |
---|
391 | echo "IGCM_sys_Qsub :" $@ |
---|
392 | fi |
---|
393 | typeset options status |
---|
394 | options="-o ${SUBMIT_DIR}/${Script_Output}" |
---|
395 | /usr/bin/qsub ${options} $1 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
396 | status=$? |
---|
397 | |
---|
398 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
399 | if [ ${status} -gt 0 ] ; then |
---|
400 | IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}" |
---|
401 | IGCM_debug_Exit "IGCM_sys_Qsub" |
---|
402 | else |
---|
403 | JobID=$( gawk {'print $1'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ ) |
---|
404 | fi |
---|
405 | IGCM_debug_PopStack "IGCM_sys_Qsub" |
---|
406 | } |
---|
407 | |
---|
408 | #D-#================================================== |
---|
409 | #D-function IGCM_sys_QsubPost |
---|
410 | #D-* Purpose: Qsub new job on scalaire |
---|
411 | #D-* Examples: |
---|
412 | #D- |
---|
413 | function IGCM_sys_QsubPost { |
---|
414 | IGCM_debug_PushStack "IGCM_sys_QsubPost" $@ |
---|
415 | if ( $DEBUG_sys ) ; then |
---|
416 | echo "IGCM_sys_QsubPost :" $@ |
---|
417 | fi |
---|
418 | typeset options status |
---|
419 | options="-o ${POST_DIR}/${Script_Post_Output}.out -v ${listVarEnv}" |
---|
420 | /usr/bin/qsub ${options} ${libIGCM_POST}/$1.job > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
421 | status=$? |
---|
422 | |
---|
423 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
424 | if [ ${status} -gt 0 ] ; then |
---|
425 | IGCM_debug_Print 2 "IGCM_sys_QsubPost ${options} ${libIGCM_POST}/$1.job : error code ${status}" |
---|
426 | IGCM_debug_Exit "IGCM_sys_QsubPost" |
---|
427 | else |
---|
428 | JobID=$( gawk {'print $1'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ ) |
---|
429 | fi |
---|
430 | IGCM_debug_PopStack "IGCM_sys_QsubPost" |
---|
431 | } |
---|
432 | |
---|
433 | #D-************************* |
---|
434 | #D- File transfer functions |
---|
435 | #D-************************* |
---|
436 | #D- |
---|
437 | |
---|
438 | #D-#================================================== |
---|
439 | #D-function IGCM_sys_RmRunDir |
---|
440 | #D-* Purpose: rm tmpdir (dummy function most of the time batch |
---|
441 | #D- scheduler will do the job) |
---|
442 | #D-* Examples: |
---|
443 | #D- |
---|
444 | function IGCM_sys_RmRunDir { |
---|
445 | IGCM_debug_PushStack "IGCM_sys_RmRunDir" $@ |
---|
446 | if ( $DEBUG_sys ) ; then |
---|
447 | echo "IGCM_sys_RmRunDir :" $@ |
---|
448 | fi |
---|
449 | |
---|
450 | typeset status |
---|
451 | |
---|
452 | echo rm $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
453 | \rm $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
454 | status=$? |
---|
455 | |
---|
456 | if [ ${status} -gt 0 ] ; then |
---|
457 | IGCM_debug_Print 1 "IGCM_sys_RmRunDir : rm error code is ${status}." |
---|
458 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
459 | IGCM_debug_Exit "IGCM_sys_RmRunDir" |
---|
460 | else |
---|
461 | \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
462 | fi |
---|
463 | IGCM_debug_PopStack "IGCM_sys_RmRunDir" |
---|
464 | } |
---|
465 | |
---|
466 | #D-#================================================== |
---|
467 | #D-function IGCM_sys_Put_Dir |
---|
468 | #D-* Purpose: Copy a complete directory on $(ARCHIVE) |
---|
469 | #D-* Examples: |
---|
470 | #D- |
---|
471 | function IGCM_sys_Put_Dir { |
---|
472 | IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@ |
---|
473 | if ( $DEBUG_sys ) ; then |
---|
474 | echo "IGCM_sys_Put_Dir :" $@ |
---|
475 | fi |
---|
476 | if [ $DRYRUN = 0 ]; then |
---|
477 | if [ ! -d ${1} ] ; then |
---|
478 | echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ." |
---|
479 | IGCM_debug_PopStack "IGCM_sys_Put_Dir" |
---|
480 | return |
---|
481 | fi |
---|
482 | |
---|
483 | typeset status |
---|
484 | |
---|
485 | # Only if we use rsync |
---|
486 | #IGCM_sys_TestDirArchive $( dirname $2 ) |
---|
487 | # |
---|
488 | #USUAL WAY |
---|
489 | \cp -r $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
490 | status=$? |
---|
491 | |
---|
492 | if [ ${status} -gt 0 ] ; then |
---|
493 | IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}" |
---|
494 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
495 | IGCM_debug_Exit "IGCM_sys_Put_Dir" |
---|
496 | else |
---|
497 | \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
498 | fi |
---|
499 | fi |
---|
500 | IGCM_debug_PopStack "IGCM_sys_Put_Dir" |
---|
501 | } |
---|
502 | |
---|
503 | #D-#================================================== |
---|
504 | #D-function IGCM_sys_Get_Dir |
---|
505 | #D-* Purpose: Copy a complete directory from ${ARCHIVE} |
---|
506 | #D-* Examples: |
---|
507 | #D- |
---|
508 | function IGCM_sys_Get_Dir { |
---|
509 | IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@ |
---|
510 | if ( $DEBUG_sys ) ; then |
---|
511 | echo "IGCM_sys_Get_Dir :" $@ |
---|
512 | fi |
---|
513 | if [ $DRYRUN = 0 ]; then |
---|
514 | typeset NB_ESSAI DELAI status i |
---|
515 | # number of tentative |
---|
516 | NB_ESSAI=3 |
---|
517 | # time delay between tentative |
---|
518 | DELAI=2 |
---|
519 | |
---|
520 | # |
---|
521 | # USUAL WAY |
---|
522 | i=0 |
---|
523 | while [ $i -lt $NB_ESSAI ] ; do |
---|
524 | \cp -ur $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
525 | status=$? |
---|
526 | if [ ${status} -gt 0 ] ; then |
---|
527 | IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}" |
---|
528 | IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again." |
---|
529 | sleep $DELAI |
---|
530 | else |
---|
531 | break |
---|
532 | fi |
---|
533 | (( i = i + 1 )) |
---|
534 | done |
---|
535 | |
---|
536 | if [ ${status} -gt 0 ] ; then |
---|
537 | IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}" |
---|
538 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
539 | IGCM_debug_Exit "IGCM_sys_Get_Dir" |
---|
540 | else |
---|
541 | \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
542 | fi |
---|
543 | fi |
---|
544 | IGCM_debug_PopStack "IGCM_sys_Get_Dir" |
---|
545 | } |
---|
546 | |
---|
547 | #D-#================================================== |
---|
548 | #D-function IGCM_sys_Put_Rest |
---|
549 | #D-* Purpose: Put computied restarts on ${ARCHIVE}. |
---|
550 | #D- File and target directory must exist. |
---|
551 | #D-* Examples: |
---|
552 | #D- |
---|
553 | function IGCM_sys_Put_Rest { |
---|
554 | IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@ |
---|
555 | if ( $DEBUG_sys ) ; then |
---|
556 | echo "IGCM_sys_Put_Rest :" $@ |
---|
557 | fi |
---|
558 | if [ $DRYRUN = 0 ]; then |
---|
559 | if [ ! -f ${1} ] ; then |
---|
560 | echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ." |
---|
561 | IGCM_debug_Exit "IGCM_sys_Put_Rest" |
---|
562 | fi |
---|
563 | |
---|
564 | typeset status |
---|
565 | # |
---|
566 | # USUAL WAY |
---|
567 | \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
568 | status=$? |
---|
569 | |
---|
570 | # #RSYNC WITH NETWORK SSH CALL |
---|
571 | # echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
572 | # ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
573 | |
---|
574 | # #RSYNC WITH NFS USE |
---|
575 | # echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
576 | # ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
577 | |
---|
578 | # status=$? |
---|
579 | # IGCM_sys_Rsync_out $status |
---|
580 | |
---|
581 | # ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
582 | # (( status=status+$? )) |
---|
583 | |
---|
584 | if [ ${status} -gt 0 ] ; then |
---|
585 | IGCM_debug_Print 2 "IGCM_sys_Put_Rest : cp failed error code ${status}" |
---|
586 | [ -f ${1} ] && ls -l ${1} |
---|
587 | [ -f ${2} ] && ls -l ${2} |
---|
588 | [ -f ${2}/${1} ] && ls -l ${2}/${1} |
---|
589 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
590 | IGCM_debug_Exit "IGCM_sys_Put_Rest" |
---|
591 | else |
---|
592 | |
---|
593 | if [ X${JobType} = XRUN ] ; then |
---|
594 | [ -f ${2} ] && IGCM_sys_Chmod 444 ${2} |
---|
595 | [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1} |
---|
596 | fi |
---|
597 | |
---|
598 | \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
599 | fi |
---|
600 | fi |
---|
601 | IGCM_debug_PopStack "IGCM_sys_Put_Rest" |
---|
602 | } |
---|
603 | |
---|
604 | #D-#================================================== |
---|
605 | #D-function IGCM_sys_Put_Out |
---|
606 | #D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly |
---|
607 | #D-* Examples: |
---|
608 | #D- |
---|
609 | function IGCM_sys_Put_Out { |
---|
610 | IGCM_debug_PushStack "IGCM_sys_Put_Out" $@ |
---|
611 | if ( $DEBUG_sys ) ; then |
---|
612 | echo "IGCM_sys_Put_Out :" $@ |
---|
613 | fi |
---|
614 | |
---|
615 | typeset status |
---|
616 | |
---|
617 | if [ $DRYRUN = 0 ]; then |
---|
618 | if [ ! -f ${1} ] ; then |
---|
619 | echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ." |
---|
620 | IGCM_debug_PopStack "IGCM_sys_Put_Out" |
---|
621 | return 1 |
---|
622 | fi |
---|
623 | # |
---|
624 | IGCM_sys_MkdirArchive $( dirname $2 ) |
---|
625 | # |
---|
626 | if [ X${JobType} = XRUN ] ; then |
---|
627 | if [ X${3} = X ] ; then |
---|
628 | IGCM_sys_Chmod 444 ${1} |
---|
629 | fi |
---|
630 | fi |
---|
631 | # |
---|
632 | |
---|
633 | echo ${RSYNC} ${RSYNC_opt} $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
634 | ${RSYNC} ${RSYNC_opt} $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
635 | status=$? |
---|
636 | IGCM_sys_Rsync_out $status |
---|
637 | |
---|
638 | ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
639 | (( status=status+$? )) |
---|
640 | |
---|
641 | if [ ${status} -gt 0 ] ; then |
---|
642 | IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}" |
---|
643 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
644 | IGCM_debug_Exit "IGCM_sys_Put_Out" |
---|
645 | else |
---|
646 | \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
647 | fi |
---|
648 | fi |
---|
649 | IGCM_debug_PopStack "IGCM_sys_Put_Out" |
---|
650 | return 0 |
---|
651 | } |
---|
652 | |
---|
653 | #D-#================================================== |
---|
654 | #D-function IGCM_sys_Get |
---|
655 | #D-* Purpose: Get a file from ${ARCHIVE} |
---|
656 | #D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX |
---|
657 | #D- IGCM_sys_Get /l Array_contain_myfiles /destpath/ |
---|
658 | function IGCM_sys_Get { |
---|
659 | IGCM_debug_PushStack "IGCM_sys_Get" $@ |
---|
660 | |
---|
661 | typeset DEST status dm_liste |
---|
662 | |
---|
663 | if ( $DEBUG_sys ) ; then |
---|
664 | echo "IGCM_sys_Get :" $@ |
---|
665 | fi |
---|
666 | if [ $DRYRUN -le 2 ]; then |
---|
667 | if [ X${1} = X'/l' ] ; then |
---|
668 | eval set +A dm_liste \${${2}} |
---|
669 | else |
---|
670 | dm_liste=${1} |
---|
671 | fi |
---|
672 | eval DEST=\${${#}} |
---|
673 | |
---|
674 | # test if the (first) file is present in the old computation : |
---|
675 | IGCM_sys_TestFileArchive ${dm_liste[0]} |
---|
676 | status=$? |
---|
677 | if [ ${status} -gt 0 ] ; then |
---|
678 | echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ." |
---|
679 | IGCM_debug_Exit "IGCM_sys_Get" |
---|
680 | return |
---|
681 | fi |
---|
682 | |
---|
683 | #USUAL WAY |
---|
684 | \cp ${dm_liste[*]} ${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
685 | status=$? |
---|
686 | |
---|
687 | if [ ${status} -gt 0 ] ; then |
---|
688 | IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}" |
---|
689 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
690 | IGCM_debug_Exit "IGCM_sys_Get" |
---|
691 | else |
---|
692 | \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
693 | fi |
---|
694 | fi |
---|
695 | IGCM_debug_PopStack "IGCM_sys_Get" |
---|
696 | } |
---|
697 | |
---|
698 | #D-#================================================== |
---|
699 | #D-function IGCM_sys_GetDate_Monitoring |
---|
700 | #D-* Purpose: get the last year for which the monitoring has been computed |
---|
701 | #D-* Examples: |
---|
702 | #D- |
---|
703 | function IGCM_sys_GetDate_Monitoring { |
---|
704 | IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@ |
---|
705 | if ( $DEBUG_sys ) ; then |
---|
706 | echo "IGCM_sys_GetDate_Monitoring :" $@ |
---|
707 | fi |
---|
708 | |
---|
709 | eval ${2}=$( cdo showyear ${1} 2> /dev/null | gawk '{ print $NF }' ) |
---|
710 | |
---|
711 | IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring" |
---|
712 | } |
---|
713 | |
---|
714 | #D-#================================================== |
---|
715 | #D-function IGCM_sys_Dods_Rm |
---|
716 | #D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole. |
---|
717 | #D-* Examples: |
---|
718 | #D- |
---|
719 | function IGCM_sys_Dods_Rm { |
---|
720 | if ( $DEBUG_sys ) ; then |
---|
721 | echo "IGCM_sys_Dods_Rm :" $@ |
---|
722 | fi |
---|
723 | return 0 |
---|
724 | } |
---|
725 | |
---|
726 | #D-#================================================== |
---|
727 | #D-function IGCM_sys_Dods_Cp |
---|
728 | #D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole. |
---|
729 | #D-* Examples: |
---|
730 | #D- |
---|
731 | function IGCM_sys_Dods_Cp { |
---|
732 | if ( $DEBUG_sys ) ; then |
---|
733 | echo "IGCM_sys_Dods_Cp :" $@ |
---|
734 | fi |
---|
735 | return 0 |
---|
736 | } |
---|
737 | |
---|
738 | #D-#================================================== |
---|
739 | #D-function IGCM_sys_Put_Dods |
---|
740 | #D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here |
---|
741 | #D-* Examples: |
---|
742 | #D- |
---|
743 | function IGCM_sys_Put_Dods { |
---|
744 | IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@ |
---|
745 | if ( $DEBUG_sys ) ; then |
---|
746 | echo "IGCM_sys_Put_Dods :" $@ |
---|
747 | fi |
---|
748 | IGCM_debug_PopStack "IGCM_sys_Put_Dods" |
---|
749 | } |
---|
750 | |
---|
751 | ############################################################## |
---|
752 | # REBUILD OPERATOR |
---|
753 | |
---|
754 | #D-#================================================== |
---|
755 | #D-function IGCM_sys_sync |
---|
756 | #D-* Purpose: flush buffer on disk (dummy function on Ciclad) |
---|
757 | #D-* Examples: |
---|
758 | #D- |
---|
759 | function IGCM_sys_sync { |
---|
760 | IGCM_debug_PushStack "IGCM_sys_sync" $@ |
---|
761 | if ( $DEBUG_sys ) ; then |
---|
762 | echo "IGCM_sys_sync :" $@ |
---|
763 | echo "Dummy call, let the system do that." |
---|
764 | fi |
---|
765 | IGCM_debug_PopStack "IGCM_sys_sync" |
---|
766 | } |
---|
767 | |
---|
768 | ############################################################ |
---|
769 | # Activate Running Environnment Variables |
---|
770 | |
---|
771 | #D-#================================================== |
---|
772 | #D-function IGCM_sys_activ_variables |
---|
773 | #D-* Purpose: set environement variables prior to execution |
---|
774 | #D-* Examples: |
---|
775 | #D- |
---|
776 | function IGCM_sys_activ_variables { |
---|
777 | IGCM_debug_PushStack "IGCM_sys_activ_variables" |
---|
778 | if ( $DEBUG_sys ) ; then |
---|
779 | echo "IGCM_sys_activ_variables" |
---|
780 | fi |
---|
781 | |
---|
782 | # -------------------------------------------------------------------- |
---|
783 | #D- MODULE specifications |
---|
784 | # -------------------------------------------------------------------- |
---|
785 | # Source the file EnvFile containing all module load needed to run the model. |
---|
786 | # EnvFile can be specified in config.card. If this is the case and if the file exists, |
---|
787 | # it will be used. Otherwise a default file will be used. |
---|
788 | if [ ! X${config_UserChoices_EnvFile} = X ] && [ -f ${config_UserChoices_EnvFile} ] ; then |
---|
789 | # EnvFile is set in config.card and the file exists |
---|
790 | IGCM_debug_Print 1 "EnvFile set in config.card will be used" |
---|
791 | EnvFile=${config_UserChoices_EnvFile} |
---|
792 | else |
---|
793 | IGCM_debug_Print 1 "IGCM_sys_active_variables : Default modules will be used" |
---|
794 | if [ $CENTER == IPSL-ciclad ] ; then |
---|
795 | # At ciclad |
---|
796 | EnvFile=/home/igcmg/.atlas_env_ciclad_ksh |
---|
797 | else |
---|
798 | # At climserv use the same files stored at ciclad but adapt the path |
---|
799 | EnvFile=/ciclad-home/igcmg/.atlas_env_ciclad_ksh |
---|
800 | fi |
---|
801 | fi |
---|
802 | IGCM_debug_Print 1 "IGCM_sys_active_variables : Following EnvFile will be used :" |
---|
803 | IGCM_debug_Print 1 ${EnvFile} |
---|
804 | . ${EnvFile} |
---|
805 | |
---|
806 | IGCM_debug_Print 1 "IGCM_sys_active_variables : Now loaded modules for ciclad/climserv. " |
---|
807 | module list |
---|
808 | |
---|
809 | # -------------------------------------------------------------------- |
---|
810 | #D- MPI specifications |
---|
811 | # -------------------------------------------------------------------- |
---|
812 | |
---|
813 | # -------------------------------------------------------------------- |
---|
814 | #D- Other specifications |
---|
815 | # -------------------------------------------------------------------- |
---|
816 | |
---|
817 | ulimit -s unlimited |
---|
818 | |
---|
819 | IGCM_debug_PopStack "IGCM_sys_activ_variables" |
---|
820 | } |
---|
821 | |
---|
822 | ############################################################ |
---|
823 | # Desactivate Running Environnment Variables |
---|
824 | |
---|
825 | #D-#================================================== |
---|
826 | #D-function IGCM_sys_desactiv_variables |
---|
827 | #D-* Purpose: unset environement variables after execution |
---|
828 | #D-* Examples: |
---|
829 | #D- |
---|
830 | function IGCM_sys_desactiv_variables { |
---|
831 | IGCM_debug_PushStack "IGCM_sys_desactiv_variables" |
---|
832 | if ( $DEBUG_sys ) ; then |
---|
833 | echo "IGCM_sys_desactiv_variables" |
---|
834 | fi |
---|
835 | # -------------------------------------------------------------------- |
---|
836 | #D- MPI specifications |
---|
837 | # -------------------------------------------------------------------- |
---|
838 | |
---|
839 | # -------------------------------------------------------------------- |
---|
840 | #D- Other specifications |
---|
841 | # -------------------------------------------------------------------- |
---|
842 | |
---|
843 | IGCM_debug_PopStack "IGCM_sys_desactiv_variables" |
---|
844 | } |
---|
845 | |
---|
846 | ############################################################ |
---|
847 | # Update job headers to be used by the scheduler |
---|
848 | |
---|
849 | #D-#================================================== |
---|
850 | #D-function IGCM_sys_updateHeaders |
---|
851 | #D-* Purpose: Update job headers to be used by the scheduler |
---|
852 | #D-* Examples: IGCM_sys_updateHeaders /path/to/Job_MYEXP |
---|
853 | #D- |
---|
854 | function IGCM_sys_updateHeaders { |
---|
855 | IGCM_debug_PushStack "IGCM_sys_updateHeaders" |
---|
856 | if ( $DEBUG_sys ) ; then |
---|
857 | echo "IGCM_sys_updateHeaders" |
---|
858 | fi |
---|
859 | typeset file |
---|
860 | file=$1 |
---|
861 | |
---|
862 | if [ ${executionType} -eq 1 ] ; then |
---|
863 | # MPMD + MPI |
---|
864 | sed -e "/::openMPthreads::/d" \ |
---|
865 | -e "s/::JobNumProcTot::/${coreNumber}/" \ |
---|
866 | ${file} > ${file}.tmp |
---|
867 | |
---|
868 | elif [ ${executionType} -eq 2 ] ; then |
---|
869 | # MPMD + MPI + OMP |
---|
870 | sed -e "s/::openMPthreads::/${openMPthreads}/" \ |
---|
871 | -e "s/::JobNumProcTot::/${coreNumber}/" \ |
---|
872 | ${file} > ${file}.tmp |
---|
873 | |
---|
874 | elif [ ${executionType} -eq 3 ] ; then |
---|
875 | # SPMD + MPI/OMP |
---|
876 | sed -e "s/::openMPthreads::/${openMPthreads}/" \ |
---|
877 | -e "s/::JobNumProcTot::/${mpiTasks}/" \ |
---|
878 | ${file} > ${file}.tmp |
---|
879 | |
---|
880 | elif [ ${executionType} -eq 4 ] ; then |
---|
881 | # SPMD + MPI only |
---|
882 | sed -e "s/::JobNumProcTot::/${mpiTasks}/" \ |
---|
883 | -e "/::openMPthreads::/d" \ |
---|
884 | ${file} > ${file}.tmp |
---|
885 | |
---|
886 | elif [ ${executionType} -eq 5 ] ; then |
---|
887 | # SPMD + OMP only |
---|
888 | sed -e "s/::openMPthreads::/${openMPthreads}/" \ |
---|
889 | -e "/::JobNumProcTot::/d" \ |
---|
890 | ${file} > ${file}.tmp |
---|
891 | |
---|
892 | elif [ ${executionType} -eq 6 ] ; then |
---|
893 | # SEQUENTIAL THEN |
---|
894 | sed -e "s/::JobNumProcTot::/1/" \ |
---|
895 | -e "/::openMPthreads::/d" \ |
---|
896 | ${file} > ${file}.tmp |
---|
897 | |
---|
898 | fi |
---|
899 | |
---|
900 | IGCM_sys_Mv ${file}.tmp ${file} |
---|
901 | |
---|
902 | IGCM_debug_PopStack "IGCM_sys_updateHeaders" |
---|
903 | } |
---|
904 | |
---|
905 | ############################################################ |
---|
906 | # Build MPI/OMP scripts run file (dummy function) |
---|
907 | |
---|
908 | #D-#================================================== |
---|
909 | #D-function IGCM_sys_build_run_file |
---|
910 | #D-* Purpose: build run file (deprecated) |
---|
911 | #D-* Examples: |
---|
912 | #D- |
---|
913 | function IGCM_sys_build_run_file { |
---|
914 | IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file " |
---|
915 | } |
---|
916 | |
---|
917 | ############################################################ |
---|
918 | # Build MPI/OMP scripts |
---|
919 | |
---|
920 | #D-#================================================== |
---|
921 | #D-function IGCM_sys_build_execution_scripts |
---|
922 | #D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND} |
---|
923 | #D-* Examples: |
---|
924 | #D- |
---|
925 | function IGCM_sys_build_execution_scripts |
---|
926 | { |
---|
927 | IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@ |
---|
928 | if ( $DEBUG_sys ) ; then |
---|
929 | echo "IGCM_sys_build_execution_scripts " $@ |
---|
930 | fi |
---|
931 | |
---|
932 | EXECUTION=${HOST_MPIRUN_COMMAND} |
---|
933 | |
---|
934 | # MPMD mode |
---|
935 | if ( ${OK_PARA_MPMD} ) ; then |
---|
936 | |
---|
937 | # Only MPI (MPMD) |
---|
938 | if ( ! ${OK_PARA_OMP} ) ; then |
---|
939 | |
---|
940 | if [ -f run_file ] ; then |
---|
941 | IGCM_sys_Rm -f run_file |
---|
942 | fi |
---|
943 | touch run_file |
---|
944 | |
---|
945 | # Build run_file |
---|
946 | |
---|
947 | # First loop on the components for the coupler ie oasis (only if oasis3) |
---|
948 | # the coupler ie oasis3 must be the first one |
---|
949 | for comp in ${config_ListOfComponents[*]} ; do |
---|
950 | |
---|
951 | eval ExeNameIn=\${config_Executable_${comp}[0]} |
---|
952 | eval ExeNameOut=\${config_Executable_${comp}[1]} |
---|
953 | |
---|
954 | # for CPL component only |
---|
955 | if [ "X${comp}" = "XCPL" ] && [ "X${ExeNameOut}" != X\"\" ] ; then |
---|
956 | eval comp_proc_mpi_loc=\${${comp}_PROC_MPI} |
---|
957 | eval comp_proc_omp_loc=\${${comp}_PROC_OMP} |
---|
958 | echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file |
---|
959 | fi |
---|
960 | done |
---|
961 | |
---|
962 | # Then second loop on the components |
---|
963 | for comp in ${config_ListOfComponents[*]} ; do |
---|
964 | |
---|
965 | eval ExeNameIn=\${config_Executable_${comp}[0]} |
---|
966 | eval ExeNameOut=\${config_Executable_${comp}[1]} |
---|
967 | |
---|
968 | # Only if we really have an executable for the component and not the coupler ie oasis: |
---|
969 | if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then |
---|
970 | |
---|
971 | eval comp_proc_mpi_loc=\${${comp}_PROC_MPI} |
---|
972 | eval comp_proc_omp_loc=\${${comp}_PROC_OMP} |
---|
973 | echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file |
---|
974 | fi |
---|
975 | done |
---|
976 | |
---|
977 | EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file" |
---|
978 | |
---|
979 | IGCM_sys_Chmod u+x run_file |
---|
980 | if ( $DEBUG_sys ) ; then |
---|
981 | echo "run_file contains : " |
---|
982 | cat run_file |
---|
983 | fi |
---|
984 | |
---|
985 | # MPI-OpenMP (MPMD) |
---|
986 | else |
---|
987 | |
---|
988 | # Hosts treatment |
---|
989 | ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp |
---|
990 | |
---|
991 | i=0 |
---|
992 | rm -f hosts |
---|
993 | IGCM_debug_Print 1 "sys Ciclad, Hosts available :" |
---|
994 | for nodes in `cat hosts.tmp` ; do |
---|
995 | host[$i]=$nodes |
---|
996 | echo "${host[$i]} slots=1 max_slots=1" >> hosts |
---|
997 | IGCM_debug_Print 1 ${host[$i]} |
---|
998 | i=$((i+1)) |
---|
999 | done |
---|
1000 | rm -f hosts.tmp |
---|
1001 | |
---|
1002 | listnodes=${host[*]} |
---|
1003 | |
---|
1004 | EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts" |
---|
1005 | |
---|
1006 | # Initialisation |
---|
1007 | rank=0 |
---|
1008 | current_core=0 |
---|
1009 | core_per_node=8 |
---|
1010 | init_exec=n |
---|
1011 | |
---|
1012 | # Loop on the components |
---|
1013 | for comp in ${config_ListOfComponents[*]} ; do |
---|
1014 | |
---|
1015 | eval ExeNameIn=\${config_Executable_${comp}[0]} |
---|
1016 | eval ExeNameOut=\${config_Executable_${comp}[1]} |
---|
1017 | |
---|
1018 | # Not possible if oasis has an executable (i.e old version of oasis3) |
---|
1019 | if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" = "XCPL" ] ) ; then |
---|
1020 | IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version" |
---|
1021 | IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler" |
---|
1022 | IGCM_debug_Verif_Exit |
---|
1023 | fi |
---|
1024 | |
---|
1025 | # Only if we really have an executable for the component : |
---|
1026 | if [ "X${ExeNameOut}" != X\"\" ] ; then |
---|
1027 | |
---|
1028 | eval comp_proc_mpi_loc=\${${comp}_PROC_MPI} |
---|
1029 | eval comp_proc_omp_loc=\${${comp}_PROC_OMP} |
---|
1030 | |
---|
1031 | echo "#!/bin/ksh" > script_${ExeNameOut}.ksh |
---|
1032 | echo "" >> script_${ExeNameOut}.ksh |
---|
1033 | if [ ${comp_proc_omp_loc} -gt 1 ] ; then |
---|
1034 | |
---|
1035 | # Check if the number of threads is correct |
---|
1036 | case ${comp_proc_omp_loc} in |
---|
1037 | 2|4|8) |
---|
1038 | IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads" |
---|
1039 | ;; |
---|
1040 | *) |
---|
1041 | IGCM_debug_Exit "ERROR with OMP parameters !" |
---|
1042 | IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads" |
---|
1043 | IGCM_debug_Print 2 "Only 2,4,8 as number of OMP threads are possible " |
---|
1044 | IGCM_debug_Verif_Exit |
---|
1045 | ;; |
---|
1046 | esac |
---|
1047 | #echo "export KMP_STACKSIZE=3g" >> script_${ExeNameOut}.ksh |
---|
1048 | #echo "export KMP_LIBRARY=turnaround" >> script_${ExeNameOut}.ksh |
---|
1049 | #echo "export MKL_SERIAL=YES" >> script_${ExeNameOut}.ksh |
---|
1050 | echo "export OMP_STACKSIZE=200M" >> script_${ExeNameOut}.ksh |
---|
1051 | echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh |
---|
1052 | fi |
---|
1053 | |
---|
1054 | #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh |
---|
1055 | echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK )) " >> script_${ExeNameOut}.ksh |
---|
1056 | echo "MYMPIRANK=\$(printf '%3.3d\n' \${MYMPIRANK})" >> script_${ExeNameOut}.ksh |
---|
1057 | echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}" >> script_${ExeNameOut}.ksh |
---|
1058 | IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh |
---|
1059 | |
---|
1060 | if [ ${init_exec} = y ] ; then |
---|
1061 | EXECUTION="${EXECUTION} : -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh" |
---|
1062 | else |
---|
1063 | EXECUTION="${EXECUTION} -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh" |
---|
1064 | init_exec=y |
---|
1065 | fi |
---|
1066 | |
---|
1067 | # Build rankfile : method used to assign cores and nodes for the MPI process |
---|
1068 | # Ex : |
---|
1069 | #rank 0=curie5296 slot=0,1,2,3 |
---|
1070 | #rank 1=curie5296 slot=4,5,6,7 |
---|
1071 | # Example of final command : |
---|
1072 | # mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh |
---|
1073 | # with script_lmdz.x.ksh : |
---|
1074 | # #!/bin/ksh |
---|
1075 | #export OMP_STACKSIZE=200M |
---|
1076 | #export OMP_NUM_THREADS=4 |
---|
1077 | #./lmdz.x |
---|
1078 | |
---|
1079 | for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do |
---|
1080 | (( index_host = current_core / core_per_node )) |
---|
1081 | host_value=${host[${index_host}]} |
---|
1082 | (( slot = current_core % core_per_node )) |
---|
1083 | virg="," |
---|
1084 | string_final="" |
---|
1085 | for index in `seq $slot $(($slot+$comp_proc_omp_loc-1))`; do |
---|
1086 | string=$index$virg |
---|
1087 | string_final=$string_final$string |
---|
1088 | done |
---|
1089 | string_final=$( echo $string_final | sed "s/.$//" ) |
---|
1090 | echo "rank $rank=$host_value slot=$string_final" >> rankfile |
---|
1091 | (( rank = rank + 1 )) |
---|
1092 | (( current_core = current_core + comp_proc_omp_loc )) |
---|
1093 | done |
---|
1094 | fi |
---|
1095 | done |
---|
1096 | fi |
---|
1097 | |
---|
1098 | # Only one executable (SPMD mode). |
---|
1099 | else |
---|
1100 | |
---|
1101 | for comp in ${config_ListOfComponents[*]} ; do |
---|
1102 | |
---|
1103 | # Only if we really have an executable for the component : |
---|
1104 | eval ExeNameOut=\${config_Executable_${comp}[1]} |
---|
1105 | if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then |
---|
1106 | |
---|
1107 | echo "#!/bin/ksh" > script_${ExeNameOut}.ksh |
---|
1108 | echo "" >> script_${ExeNameOut}.ksh |
---|
1109 | if ( ${OK_PARA_OMP} ) ; then |
---|
1110 | eval comp_proc_omp_loc=\${${comp}_PROC_OMP} |
---|
1111 | echo "export OMP_STACKSIZE=200M" >> script_${ExeNameOut}.ksh |
---|
1112 | echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh |
---|
1113 | fi |
---|
1114 | if ( ${OK_PARA_MPI} ) ; then |
---|
1115 | # Default : mpirun used if nb_proc gt 1 |
---|
1116 | # pour sortie out/err par process |
---|
1117 | echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}" >> script_${ExeNameOut}.ksh |
---|
1118 | #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh |
---|
1119 | IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh |
---|
1120 | EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh" |
---|
1121 | else |
---|
1122 | # Default : mpirun is NOT used if nb_proc eq 1 |
---|
1123 | # pour sortie out/err par process |
---|
1124 | echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh |
---|
1125 | #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh |
---|
1126 | IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh |
---|
1127 | EXECUTION="time ./script_${ExeNameOut}.ksh" |
---|
1128 | fi |
---|
1129 | |
---|
1130 | IGCM_debug_Print 1 "sys Ciclad : script_${ExeNameOut}.ksh contains" |
---|
1131 | cat script_${ExeNameOut}.ksh |
---|
1132 | |
---|
1133 | fi |
---|
1134 | |
---|
1135 | done |
---|
1136 | |
---|
1137 | fi |
---|
1138 | |
---|
1139 | IGCM_debug_Print 1 "sys Ciclad : execution command is" |
---|
1140 | IGCM_debug_Print 1 "$EXECUTION" |
---|
1141 | |
---|
1142 | IGCM_debug_PopStack "IGCM_sys_build_execution_scripts" |
---|
1143 | } |
---|
1144 | |
---|
1145 | #D-#================================================== |
---|
1146 | #D-function IGCM_sys_check_path |
---|
1147 | #D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine |
---|
1148 | #D-* do not point to an important use directory. Stop immediately in that case. |
---|
1149 | #D-* Examples: |
---|
1150 | #D- |
---|
1151 | function IGCM_sys_check_path { |
---|
1152 | IGCM_debug_PushStack "IGCM_sys_check_path" |
---|
1153 | if ( $DEBUG_sys ) ; then |
---|
1154 | echo "IGCM_sys_check_path" |
---|
1155 | fi |
---|
1156 | |
---|
1157 | if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then |
---|
1158 | IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}" |
---|
1159 | IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}" |
---|
1160 | IGCM_debug_Exit "This will stop the job" |
---|
1161 | fi |
---|
1162 | IGCM_debug_PopStack "IGCM_sys_check_path" |
---|
1163 | } |
---|
1164 | |
---|
1165 | #D-#================================================== |
---|
1166 | #D-function IGCM_sys_check_quota. Dummy call here |
---|
1167 | #D-* Purpose: check user quota. Stop the simulation if quota above 90% |
---|
1168 | #D-* Examples: |
---|
1169 | #D- |
---|
1170 | function IGCM_sys_check_quota { |
---|
1171 | IGCM_debug_PushStack "IGCM_sys_check_quota" |
---|
1172 | if ( $DEBUG_sys ) ; then |
---|
1173 | echo "IGCM_sys_check_quota" |
---|
1174 | fi |
---|
1175 | |
---|
1176 | # TO BE IMPLEMENTED |
---|
1177 | |
---|
1178 | IGCM_debug_PopStack "IGCM_sys_check_quota" |
---|
1179 | } |
---|
1180 | |
---|
1181 | #D-#================================================== |
---|
1182 | #D-function IGCM_sys_projectAccounting |
---|
1183 | #D-* Purpose: store project accounting information in a file |
---|
1184 | #D-* Examples: |
---|
1185 | #D- |
---|
1186 | function IGCM_sys_projectAccounting { |
---|
1187 | IGCM_debug_PushStack "IGCM_sys_projectAccounting" |
---|
1188 | if ( $DEBUG_sys ) ; then |
---|
1189 | echo "IGCM_sys_check_quota" |
---|
1190 | fi |
---|
1191 | |
---|
1192 | touch $1 |
---|
1193 | |
---|
1194 | IGCM_debug_PopStack "IGCM_sys_projectAccounting" |
---|
1195 | } |
---|
1196 | |
---|
1197 | #D-#================================================== |
---|
1198 | #D-function IGCM_sys_getJobSchedulerID |
---|
1199 | #D-* Purpose: Get the job ID during execution |
---|
1200 | #D-* Examples: IGCM_sys_getJobSchedulerID jobSchedulerID |
---|
1201 | #D- |
---|
1202 | function IGCM_sys_getJobSchedulerID { |
---|
1203 | IGCM_debug_PushStack "IGCM_sys_getJobSchedulerID" |
---|
1204 | if ( $DEBUG_sys ) ; then |
---|
1205 | echo "IGCM_sys_getJobSchedulerID" |
---|
1206 | fi |
---|
1207 | |
---|
1208 | eval ${1}=$( echo ${PBS_JOBID} | awk -F. '{print $1}' ) |
---|
1209 | |
---|
1210 | IGCM_debug_PopStack "IGCM_sys_getJobSchedulerID" |
---|
1211 | } |
---|
1212 | |
---|
1213 | #D-#================================================== |
---|
1214 | #D-function IGCM_sys_GetJobID |
---|
1215 | #D-* Purpose: Get the job ID from the JobName |
---|
1216 | #D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID |
---|
1217 | #D- |
---|
1218 | function IGCM_sys_GetJobID { |
---|
1219 | IGCM_debug_PushStack "IGCM_sys_GetJobID" |
---|
1220 | if ( $DEBUG_sys ) ; then |
---|
1221 | echo "IGCM_sys_GetJobID" |
---|
1222 | fi |
---|
1223 | |
---|
1224 | # With -f option, the full job name is given in the last column |
---|
1225 | ID="$( qstat -u $2 | grep -w $1 | gawk '-F ' '{print $10}' )" |
---|
1226 | |
---|
1227 | eval ${3}=${ID} |
---|
1228 | IGCM_debug_PopStack "IGCM_sys_GetJobID" |
---|
1229 | } |
---|
1230 | |
---|
1231 | #D-#================================================== |
---|
1232 | #D-function IGCM_sys_CountJobInQueue |
---|
1233 | #D-* Purpose: Count number of users job |
---|
1234 | #D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun |
---|
1235 | #D- |
---|
1236 | function IGCM_sys_CountJobInQueue { |
---|
1237 | IGCM_debug_PushStack "IGCM_sys_CountJobInQueue" |
---|
1238 | if ( $DEBUG_sys ) ; then |
---|
1239 | echo "IGCM_sys_CountJobInQueue" |
---|
1240 | fi |
---|
1241 | IGCM_debug_PopStack "IGCM_sys_CountJobInQueue" |
---|
1242 | } |
---|
1243 | |
---|
1244 | #D-#================================================== |
---|
1245 | #D-function IGCM_sys_atlas |
---|
1246 | #D-* Purpose: encapsulate atlas call so as to manage error code and curie specificity |
---|
1247 | #D-* Examples: |
---|
1248 | #D- |
---|
1249 | function IGCM_sys_atlas { |
---|
1250 | IGCM_debug_PushStack "IGCM_sys_atlas" $@ |
---|
1251 | if ( $DEBUG_sys ) ; then |
---|
1252 | echo "IGCM_sys_atlas :" $@ |
---|
1253 | fi |
---|
1254 | |
---|
1255 | typeset status |
---|
1256 | |
---|
1257 | \atlas $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 |
---|
1258 | status=$? |
---|
1259 | if [ ${status} -gt 0 ] ; then |
---|
1260 | echo "IGCM_sys_atlas : error code ${status}" |
---|
1261 | cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
1262 | \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ |
---|
1263 | IGCM_debug_PopStack "IGCM_sys_atlas" |
---|
1264 | return 1 |
---|
1265 | else |
---|
1266 | IGCM_debug_PopStack "IGCM_sys_atlas" |
---|
1267 | return 0 |
---|
1268 | fi |
---|
1269 | |
---|
1270 | IGCM_debug_PopStack "IGCM_sys_atlas" |
---|
1271 | } |
---|
1272 | |
---|
1273 | #D-#================================================== |
---|
1274 | #D-function IGCM_sys_rebuild_nemo |
---|
1275 | #D-* Purpose: rebuild nemo parallel files with general rebuild |
---|
1276 | #D-* Examples: |
---|
1277 | #D- |
---|
1278 | |
---|
1279 | function IGCM_sys_rebuild_nemo { |
---|
1280 | IGCM_debug_PushStack "IGCM_sys_rebuild_nemo" $@ |
---|
1281 | if ( $DEBUG_sys ) ; then |
---|
1282 | echo "IGCM_sys_rebuild_nemo :" $@ |
---|
1283 | fi |
---|
1284 | |
---|
1285 | nemo_generic_restart_file_name_out=${1} |
---|
1286 | nemo_extension_out=${3} |
---|
1287 | shift ; shift ; shift |
---|
1288 | |
---|
1289 | IGCM_sys_rebuild -o ${nemo_generic_restart_file_name_out}.${nemo_extension_out} $@ |
---|
1290 | |
---|
1291 | IGCM_debug_PopStack "IGCM_sys_rebuild_nemo" |
---|
1292 | } |
---|
1293 | |
---|
1294 | |
---|
1295 | |
---|