1 | #!/bin/bash |
---|
2 | # $Id: makelmdz_fcm 1864 2013-09-11 09:45:01Z fairhead $ |
---|
3 | # This is a script in Bash. |
---|
4 | |
---|
5 | # FH : on ne crée plus le fichier arch.mk qui est supposé exister par |
---|
6 | # FH : ailleurs. |
---|
7 | # FH : ulterieurement, ce fichier sera pré-existant pour une série |
---|
8 | # FH : de configurations en versions optimisées et debug qui seront |
---|
9 | # FH : liés (ln -s) avec arch.mk en fonction de l'architecture. |
---|
10 | # FH : Pour le moment, cette version est en test et on peut créer les |
---|
11 | # FH : arch.mk en lançant une première fois makegcm. |
---|
12 | # |
---|
13 | ##set -x |
---|
14 | ######################################################################## |
---|
15 | # options par defaut pour la commande make |
---|
16 | ######################################################################## |
---|
17 | |
---|
18 | dim="96x72x19" |
---|
19 | physique=lmd |
---|
20 | filtre=filtrez |
---|
21 | grille=reg |
---|
22 | couple=false |
---|
23 | veget=false |
---|
24 | chimie=false |
---|
25 | parallel=none |
---|
26 | paramem="par" |
---|
27 | compil_mod=prod |
---|
28 | io=ioipsl |
---|
29 | LIBPREFIX="" |
---|
30 | cosp=false |
---|
31 | job=1 |
---|
32 | full='' |
---|
33 | |
---|
34 | LMDGCM=`/bin/pwd` |
---|
35 | LIBOGCM=$LMDGCM/libo |
---|
36 | LIBFGCM=$LMDGCM/libf |
---|
37 | COSP_PATH=$LMDGCM/.void_dir |
---|
38 | fcm_path=$LMDGCM/tools/fcm/bin |
---|
39 | |
---|
40 | ######################################################################## |
---|
41 | # Quelques initialisations de variables du shell. |
---|
42 | ######################################################################## |
---|
43 | |
---|
44 | CPP_KEY="" |
---|
45 | INCLUDE="" |
---|
46 | LIB="" |
---|
47 | adjnt="" |
---|
48 | COMPIL_FFLAGS="%PROD_FFLAGS" |
---|
49 | PARA_FFLAGS="" |
---|
50 | PARA_LD="" |
---|
51 | EXT_SRC="" |
---|
52 | |
---|
53 | ######################################################################## |
---|
54 | # lecture des options de mymake |
---|
55 | ######################################################################## |
---|
56 | |
---|
57 | while (($# > 0)) |
---|
58 | do |
---|
59 | case $1 in |
---|
60 | "-h") cat <<fin |
---|
61 | Usage : |
---|
62 | makelmdz_fcm [options] -arch nom_arch exec |
---|
63 | [-h] : brief help |
---|
64 | [-d [[IMx]JMx]LM] : IM, JM, LM are the dimensions in x, y, z (default: $dim) |
---|
65 | [-p PHYS] : set of physical parametrizations (in libf/phyPHYS), (default: lmd) |
---|
66 | [-prod / -dev / -debug] : compilation mode production (default) / developement / debug |
---|
67 | [-c false/MPI1/MPI2] : coupling with ocean model : MPI1/MPI2/false (default: false) |
---|
68 | [-v false/orchidee2.0/orchidee1.9/true] : version of the vegetation model to include (default: false) |
---|
69 | false : no vegetation model |
---|
70 | orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version) |
---|
71 | orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6 |
---|
72 | true : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6 |
---|
73 | [-chimie INCA/false] : with INCA chemistry model or without (default: false) |
---|
74 | [-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp |
---|
75 | [-g GRI] : grid configuration in dyn3d/GRI_xy.h (default: reg, inclues a zoom) |
---|
76 | [-io IO] : Input/Output library (default: ioipsl) |
---|
77 | [-include INCLUDES] : extra include path to add |
---|
78 | [-cpp CPP_KEY] : additional preprocessing definitions |
---|
79 | [-adjnt] : adjoint model, not operational ... |
---|
80 | [-mem] : reduced memory dynamics (if in parallel mode) |
---|
81 | [-filtre NOMFILTRE] : use filtre from libf/NOMFILTRE (default: filtrez) |
---|
82 | [-link LINKS] : additional links with other libraries |
---|
83 | [-j n] : active parallel compiling on ntask |
---|
84 | [-full] : full recompiling |
---|
85 | [-fcm_path path] : path to the fcm tool (default: tools/fcm/bin) |
---|
86 | [-ext_src path] : path to an additional set of routines to compile with the model |
---|
87 | -arch nom_arch : target architecture |
---|
88 | exec : executable to build |
---|
89 | fin |
---|
90 | exit;; |
---|
91 | |
---|
92 | "-d") |
---|
93 | dim=$2 ; shift ; shift ;; |
---|
94 | |
---|
95 | "-p") |
---|
96 | physique="$2" ; shift ; shift ;; |
---|
97 | |
---|
98 | "-g") |
---|
99 | grille="$2" ; shift ; shift ;; |
---|
100 | |
---|
101 | "-c") |
---|
102 | couple="$2" ; shift ; shift ;; |
---|
103 | |
---|
104 | "-prod") |
---|
105 | compil_mod="prod" ; shift ;; |
---|
106 | |
---|
107 | "-dev") |
---|
108 | compil_mod="dev" ; shift ;; |
---|
109 | |
---|
110 | "-debug") |
---|
111 | compil_mod="debug" ; shift ;; |
---|
112 | |
---|
113 | "-io") |
---|
114 | io="$2" ; shift ; shift ;; |
---|
115 | |
---|
116 | "-v") |
---|
117 | veget="$2" ; shift ; shift ;; |
---|
118 | |
---|
119 | "-chimie") |
---|
120 | chimie="$2" ; shift ; shift ;; |
---|
121 | |
---|
122 | "-parallel") |
---|
123 | parallel="$2" ; shift ; shift ;; |
---|
124 | |
---|
125 | "-include") |
---|
126 | INCLUDE="$INCLUDE -I$2" ; shift ; shift ;; |
---|
127 | |
---|
128 | "-cpp") |
---|
129 | CPP_KEY="$CPP_KEY $2" ; shift ; shift ;; |
---|
130 | |
---|
131 | "-adjnt") |
---|
132 | echo "not operational ... work to be done here ";exit |
---|
133 | opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d " |
---|
134 | optim="$optim -Dadj" ; shift ;; |
---|
135 | |
---|
136 | "-cosp") |
---|
137 | cosp="$2" ; shift ; shift ;; |
---|
138 | |
---|
139 | "-mem") |
---|
140 | paramem="mem" ; shift ;; |
---|
141 | |
---|
142 | "-filtre") |
---|
143 | filtre=$2 ; shift ; shift ;; |
---|
144 | |
---|
145 | "-link") |
---|
146 | LIB="$LIB $2" ; shift ; shift ;; |
---|
147 | |
---|
148 | "-fcm_path") |
---|
149 | fcm_path=$2 ; shift ; shift ;; |
---|
150 | |
---|
151 | "-ext_src") |
---|
152 | EXT_SRC=$2 ; shift ; shift ;; |
---|
153 | "-j") |
---|
154 | job=$2 ; shift ; shift ;; |
---|
155 | "-full") |
---|
156 | full="-full" ; shift ;; |
---|
157 | |
---|
158 | "-arch") |
---|
159 | arch=$2 ; shift ; shift ;; |
---|
160 | |
---|
161 | *) |
---|
162 | code="$1" ; shift ;; |
---|
163 | esac |
---|
164 | done |
---|
165 | |
---|
166 | ############################################################### |
---|
167 | # path to fcm |
---|
168 | ############################################################### |
---|
169 | # handle case when provided path to fcm was given as a relative |
---|
170 | # path (from makelmdz_fcm script directory) and not an absolute path |
---|
171 | if [[ ${fcm_path:0:1} != "/" ]] ; then |
---|
172 | # prepend with makelmdz_fcm location |
---|
173 | fcm_path=$(cd $(dirname $0) ; pwd)"/"${fcm_path} |
---|
174 | fi |
---|
175 | |
---|
176 | # add fcm_path to PATH |
---|
177 | export PATH=${fcm_path}:${PATH} |
---|
178 | |
---|
179 | echo "Path to fcm:" |
---|
180 | echo ${fcm_path} |
---|
181 | |
---|
182 | ############################################################### |
---|
183 | # lecture des chemins propres à l'architecture de la machine # |
---|
184 | ############################################################### |
---|
185 | rm -f .void_file |
---|
186 | echo > .void_file |
---|
187 | rm -rf .void_dir |
---|
188 | mkdir .void_dir |
---|
189 | rm -f arch.path |
---|
190 | ln -s arch/arch-${arch}.path ./arch.path |
---|
191 | source arch.path |
---|
192 | |
---|
193 | ######################################################################## |
---|
194 | # Definition des clefs CPP, des chemins des includes et modules |
---|
195 | # et des libraries |
---|
196 | ######################################################################## |
---|
197 | |
---|
198 | if [[ "$compil_mod" == "prod" ]] |
---|
199 | then |
---|
200 | COMPIL_FFLAGS="%PROD_FFLAGS" |
---|
201 | elif [[ "$compil_mod" == "dev" ]] |
---|
202 | then |
---|
203 | COMPIL_FFLAGS="%DEV_FFLAGS" |
---|
204 | elif [[ "$compil_mod" == "debug" ]] |
---|
205 | then |
---|
206 | COMPIL_FFLAGS="%DEBUG_FFLAGS" |
---|
207 | fi |
---|
208 | |
---|
209 | if [[ "$physique" != "nophys" ]] |
---|
210 | then |
---|
211 | #We'll use some physics |
---|
212 | CPP_KEY="$CPP_KEY CPP_PHYS" |
---|
213 | if [[ "${physique:0:3}" == "lmd" ]] |
---|
214 | then |
---|
215 | #For lmd physics, default planet type is Earth |
---|
216 | CPP_KEY="$CPP_KEY CPP_EARTH" |
---|
217 | fi |
---|
218 | fi |
---|
219 | |
---|
220 | if [[ "$chimie" == "INCA" ]] |
---|
221 | then |
---|
222 | CPP_KEY="$CPP_KEY INCA" |
---|
223 | INCLUDE="$INCLUDE -I${INCA_INCDIR}" |
---|
224 | LIB="$LIB -L${INCA_LIBDIR} -lchimie" |
---|
225 | fi |
---|
226 | |
---|
227 | if [[ "$couple" != "false" ]] |
---|
228 | then |
---|
229 | CPP_KEY="$CPP_KEY CPP_COUPLE" |
---|
230 | INCLUDE="$INCLUDE -I${OASIS_INCDIR}" |
---|
231 | LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io" |
---|
232 | fi |
---|
233 | |
---|
234 | if [[ "$parallel" == "mpi" ]] |
---|
235 | then |
---|
236 | CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI" |
---|
237 | PARA_FFLAGS="%MPI_FFLAGS" |
---|
238 | PARA_LD="%MPI_LD" |
---|
239 | elif [[ "$parallel" == "omp" ]] |
---|
240 | then |
---|
241 | CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP" |
---|
242 | PARA_FFLAGS="%OMP_FFLAGS" |
---|
243 | PARA_LD="%OMP_LD" |
---|
244 | elif [[ "$parallel" == "mpi_omp" ]] |
---|
245 | then |
---|
246 | CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP" |
---|
247 | PARA_FFLAGS="%MPI_FFLAGS %OMP_FFLAGS" |
---|
248 | PARA_LD="%MPI_LD %OMP_LD" |
---|
249 | fi |
---|
250 | |
---|
251 | if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \ |
---|
252 | && "$compil_mod" == "debug" ]] |
---|
253 | then |
---|
254 | echo "Usually, parallelization with OpenMP requires some optimization." |
---|
255 | echo "We suggest switching to \"-dev\"." |
---|
256 | fi |
---|
257 | |
---|
258 | if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ] |
---|
259 | then |
---|
260 | #NB: option 'true': for backward compatibility. To be used with ORCHIDEE tag 1.9-1.9.6 |
---|
261 | # For this case, cpp flag ORCHIDEE_NOOPENMP must be added to the makelmdz_fcm arguments |
---|
262 | # option orchidee1.9 : Compile with ORCHIDEE version up to the inclusion of OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6 |
---|
263 | INCLUDE="${INCLUDE} -I${ORCH_INCDIR}" |
---|
264 | CPP_KEY="$CPP_KEY CPP_VEGET" |
---|
265 | # temporary, for Orchidee versions 1.9.* (before openmp activation) |
---|
266 | if [[ "$veget" == "orchidee1.9" ]] ; then |
---|
267 | CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP" |
---|
268 | fi |
---|
269 | if [[ "$veget" == "orchidee2.0" ]] ; then |
---|
270 | orch_libs="sechiba parameters stomate parallel orglob orchidee" |
---|
271 | else |
---|
272 | orch_libs="sechiba parameters stomate parallel orglob" |
---|
273 | fi |
---|
274 | LIB="${LIB} -L${ORCH_LIBDIR}" |
---|
275 | for lib in ${orch_libs} ; do |
---|
276 | if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then |
---|
277 | LIB="${LIB} -l${LIBPREFIX}$lib " |
---|
278 | fi |
---|
279 | done |
---|
280 | elif [[ "$veget" != "false" ]] ; then |
---|
281 | echo "Option -v $veget does not exist" |
---|
282 | echo "Use ./makelmdz_fcm -h for more information" |
---|
283 | exit |
---|
284 | fi |
---|
285 | |
---|
286 | if [[ $io == ioipsl ]] |
---|
287 | then |
---|
288 | CPP_KEY="$CPP_KEY CPP_IOIPSL" |
---|
289 | INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}" |
---|
290 | LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl" |
---|
291 | fi |
---|
292 | if [[ "$cosp" == "true" ]] |
---|
293 | then |
---|
294 | CPP_KEY="$CPP_KEY CPP_COSP" |
---|
295 | COSP_PATH="$LIBFGCM/cosp" |
---|
296 | # LIB="${LIB} -l${LIBPREFIX}cosp" |
---|
297 | fi |
---|
298 | |
---|
299 | INCLUDE="$INCLUDE ${NETCDF_INCDIR}" |
---|
300 | LIB="$LIB ${NETCDF_LIBDIR}" |
---|
301 | |
---|
302 | ######################################################################## |
---|
303 | # calcul du nombre de dimensions |
---|
304 | ######################################################################## |
---|
305 | |
---|
306 | |
---|
307 | dim_full=$dim |
---|
308 | dim=`echo $dim | sed -e 's/[^0-9]/ /g'` |
---|
309 | set $dim |
---|
310 | dimc=$# |
---|
311 | echo calcul de la dimension |
---|
312 | echo dim $dim |
---|
313 | echo dimc $dimc |
---|
314 | |
---|
315 | |
---|
316 | ######################################################################## |
---|
317 | # Gestion des dimensions du modele. |
---|
318 | # on cree ou remplace le fichier des dimensions |
---|
319 | ######################################################################## |
---|
320 | |
---|
321 | cd $LIBFGCM/grid |
---|
322 | if [[ -f dimensions.h ]] |
---|
323 | then |
---|
324 | echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs' |
---|
325 | echo "Attendez que la premiere compilation soit terminee pour relancer la suivante." |
---|
326 | echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs," |
---|
327 | echo vous pouvez continuer en repondant oui. |
---|
328 | echo "Voulez-vous vraiment continuer?" |
---|
329 | echo "" |
---|
330 | echo "WARNING: you are probably already compiling the model somewhere else." |
---|
331 | echo "Wait until the first compilation is finished before launching this one." |
---|
332 | echo "If you are sure that you are not compiling elsewhere, just answer " |
---|
333 | echo "yes (or 'oui') to the question below to proceed." |
---|
334 | echo "Do you wish to continue?" |
---|
335 | read reponse |
---|
336 | if [[ $reponse == "oui" || $reponse == "yes" ]] |
---|
337 | then |
---|
338 | \rm -f $LIBFGCM/grid/dimensions.h |
---|
339 | else |
---|
340 | exit |
---|
341 | fi |
---|
342 | fi |
---|
343 | |
---|
344 | |
---|
345 | cd $LIBFGCM/grid/dimension |
---|
346 | ./makdim $dim |
---|
347 | cat $LIBFGCM/grid/dimensions.h |
---|
348 | cd $LMDGCM |
---|
349 | |
---|
350 | |
---|
351 | ######################################################################## |
---|
352 | # Differentes dynamiques (3d, 2d, 1d) |
---|
353 | ######################################################################## |
---|
354 | |
---|
355 | dimension=`echo $dim | wc -w` |
---|
356 | echo dimension $dimension |
---|
357 | |
---|
358 | if (( $dimension == 3 )) |
---|
359 | then |
---|
360 | cd $LIBFGCM/grid |
---|
361 | \rm fxyprim.h |
---|
362 | cp -p fxy_${grille}.h fxyprim.h |
---|
363 | else |
---|
364 | echo "Probleme dans les dimensions de la dynamique !!" |
---|
365 | echo "Non reactive pour l'instant !!!" |
---|
366 | fi |
---|
367 | |
---|
368 | ###################################################################### |
---|
369 | # Traitement special pour le nouveau rayonnement de Laurent Li. |
---|
370 | # ---> YM desactive pour le traitemement en parallele |
---|
371 | ###################################################################### |
---|
372 | |
---|
373 | #if [[ -f $libf/phy$physique/raddim.h ]] |
---|
374 | #then |
---|
375 | # if [[ -f $libf/phy$physique/raddim.$dimh.h ]] |
---|
376 | #then |
---|
377 | # \rm -f $libf/phy$physique/raddim.h |
---|
378 | # cp -p $libf/phy$physique/raddim.$dimh.h $libf/phy$physique/raddim.h |
---|
379 | # echo $libf/phy$physique/raddim.$dimh.h |
---|
380 | # cat $libf/phy$physique/raddim.h |
---|
381 | # else |
---|
382 | # echo On peut diminuer la taille de l executable en creant |
---|
383 | # echo le fichier $libf/phy$physique/raddim.$dimh.h |
---|
384 | # \cp -p $libf/phy$physique/raddim.defaut.h $libf/phy$physique/raddim.h |
---|
385 | # fi |
---|
386 | #fi |
---|
387 | |
---|
388 | ###################################################################### |
---|
389 | # Gestion du filtre qui n'existe qu'en 3d. |
---|
390 | ###################################################################### |
---|
391 | |
---|
392 | if (( `expr $dimc \> 2` == 1 )) |
---|
393 | then |
---|
394 | filtre="FILTRE=$filtre" |
---|
395 | else |
---|
396 | filtre="FILTRE= L_FILTRE= " |
---|
397 | fi |
---|
398 | echo MACRO FILTRE $filtre |
---|
399 | |
---|
400 | echo $dimc |
---|
401 | |
---|
402 | |
---|
403 | |
---|
404 | ###################################################################### |
---|
405 | # Creation du suffixe de la configuration |
---|
406 | ###################################################################### |
---|
407 | |
---|
408 | |
---|
409 | SUFF_NAME=_${dim_full} |
---|
410 | SUFF_NAME=${SUFF_NAME}_phy${physique} |
---|
411 | |
---|
412 | if [[ "$parallel" != "none" ]] |
---|
413 | then |
---|
414 | SUFF_NAME=${SUFF_NAME}_para |
---|
415 | DYN=dyn${dimc}d${paramem} |
---|
416 | if [[ "$paramem" == "mem" ]] |
---|
417 | then |
---|
418 | SUFF_NAME=${SUFF_NAME}_${paramem} |
---|
419 | fi |
---|
420 | else |
---|
421 | SUFF_NAME=${SUFF_NAME}_seq |
---|
422 | DYN=dyn${dimc}d |
---|
423 | fi |
---|
424 | |
---|
425 | if [[ $veget != "false" ]] |
---|
426 | then |
---|
427 | SUFF_NAME=${SUFF_NAME}_orch |
---|
428 | fi |
---|
429 | |
---|
430 | if [[ $couple != "false" ]] |
---|
431 | then |
---|
432 | SUFF_NAME=${SUFF_NAME}_couple |
---|
433 | fi |
---|
434 | |
---|
435 | if [[ $chimie == "INCA" ]] |
---|
436 | then |
---|
437 | SUFF_NAME=${SUFF_NAME}_inca |
---|
438 | fi |
---|
439 | |
---|
440 | cd $LMDGCM |
---|
441 | config_fcm="config.fcm" |
---|
442 | rm -f $config_fcm |
---|
443 | touch $config_fcm |
---|
444 | rm -f bin/${code}${SUFF_NAME}.e |
---|
445 | rm -f arch.fcm |
---|
446 | rm -f arch.opt |
---|
447 | |
---|
448 | echo "%ARCH $arch" >> $config_fcm |
---|
449 | echo "%INCDIR $INCLUDE" >> $config_fcm |
---|
450 | echo "%LIB $LIB" >> $config_fcm |
---|
451 | echo "%ROOT_PATH $PWD" >> $config_fcm |
---|
452 | echo "%LIBF $LIBFGCM" >> $config_fcm |
---|
453 | echo "%LIBO $LIBOGCM" >> $config_fcm |
---|
454 | echo "%DYN $DYN" >> $config_fcm |
---|
455 | echo "%PHYS phy${physique}" >> $config_fcm |
---|
456 | echo "%COSP $COSP_PATH" >> $config_fcm |
---|
457 | echo "%CPP_KEY $CPP_KEY" >> $config_fcm |
---|
458 | echo "%EXEC $code" >> $config_fcm |
---|
459 | echo "%SUFF_NAME $SUFF_NAME" >> $config_fcm |
---|
460 | echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> $config_fcm |
---|
461 | echo "%PARA_FFLAGS $PARA_FFLAGS" >> $config_fcm |
---|
462 | echo "%PARA_LD $PARA_LD" >> $config_fcm |
---|
463 | echo "%EXT_SRC $EXT_SRC" >> $config_fcm |
---|
464 | |
---|
465 | |
---|
466 | |
---|
467 | ln -s arch/arch-${arch}.fcm arch.fcm |
---|
468 | if test -f arch/arch-${arch}.opt && [ $compil_mod = "prod" ] |
---|
469 | then |
---|
470 | ln -s arch/arch-${arch}.opt arch.opt |
---|
471 | else |
---|
472 | ln -s .void_file arch.opt |
---|
473 | fi |
---|
474 | |
---|
475 | |
---|
476 | rm -f $LIBOGCM/${arch}${SUFF_NAME}/.config/fcm.bld.lock |
---|
477 | ./build_gcm ${fcm_path} -j $job $full |
---|
478 | |
---|
479 | rm -rf tmp_src |
---|
480 | rm -rf config |
---|
481 | ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config config |
---|
482 | ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/tmp tmp_src |
---|
483 | |
---|
484 | if [[ -r $LIBFGCM/grid/dimensions.h ]] |
---|
485 | then |
---|
486 | # Cleanup: remove dimension.h file |
---|
487 | \rm -f $LIBFGCM/grid/dimensions.h |
---|
488 | fi |
---|