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