1 | #!/bin/bash |
---|
2 | # $Id: makelmdz_fcm 1327 2010-03-16 10:23:17Z musat $ |
---|
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 | compil_mod=prod |
---|
27 | io=ioipsl |
---|
28 | LIBPREFIX="" |
---|
29 | fcm_path=none |
---|
30 | cosp=false |
---|
31 | |
---|
32 | LMDGCM=`/bin/pwd` |
---|
33 | LIBOGCM=$LMDGCM/libo |
---|
34 | LIBFGCM=$LMDGCM/libf |
---|
35 | COSP_PATH=$LMDGCM/.void_dir |
---|
36 | |
---|
37 | ######################################################################## |
---|
38 | # Quelques initialisations de variables du shell. |
---|
39 | ######################################################################## |
---|
40 | |
---|
41 | CPP_KEY="" |
---|
42 | INCLUDE="" |
---|
43 | LIB="" |
---|
44 | adjnt="" |
---|
45 | COMPIL_FFLAGS="%PROD_FFLAGS" |
---|
46 | PARA_FFLAGS="" |
---|
47 | PARA_LD="" |
---|
48 | EXT_SRC="" |
---|
49 | |
---|
50 | ######################################################################## |
---|
51 | # lecture des options de mymake |
---|
52 | ######################################################################## |
---|
53 | |
---|
54 | while (($# > 0)) |
---|
55 | do |
---|
56 | case $1 in |
---|
57 | "-h") cat <<fin |
---|
58 | manuel complet sur http://... |
---|
59 | Usage : |
---|
60 | makegcm [options] -m arch exec |
---|
61 | [-h] : manuel abrégé |
---|
62 | [-d [[IMx]JMx]LM] : IM, JM, LM sont les dims en x, y, z (def: $dim) |
---|
63 | [-p PHYS] : compilation avec la physique libf/phyPHYS, (def: lmd) |
---|
64 | [-prod / -dev / -debug] : compilation en mode production (default) / developpement / debug . |
---|
65 | [-c false/MPI1/MPI2] : couplé océan : MPI1/MPI2/false (def: false) |
---|
66 | [-v false/true] : avec ou sans végétation (def: false) |
---|
67 | [-chimie INCA/false] : avec ou sans model de chimie INCA (def: false) |
---|
68 | [-parallel none/mpi/omp/mpi_omp] : parallelisation (default: none) : mpi, openmp ou mixte mpi_openmp |
---|
69 | [-g GRI] : conf. grille dans dyn3d/GRI_xy.h (def: reg inclue un zoom) |
---|
70 | [-io IO] : choix d'une librairie I/O, experts (def: ioipsl) |
---|
71 | [-include INCLUDES] : variables supplementaires pour include |
---|
72 | [-cpp CPP_KEY] : cle cpp supplementaires |
---|
73 | [-adjnt] : adjoint, a remettre en route ... |
---|
74 | [-filtre NOMFILTRE] : prend le filtre dans libf/NOMFILTRE (def: filtrez) |
---|
75 | [-link LINKS] : liens optionels avec d'autres librairies |
---|
76 | [-fcm_path path] : chemin pour fcm (def: le chemin est suppose deja exister dans le PATH) |
---|
77 | [-ext_src path] : chemin d'un repertoire source avec des sources externe a compiler avec le modele |
---|
78 | -arch nom_arch : nom de l'architecture cible |
---|
79 | exec : exécutable généré |
---|
80 | fin |
---|
81 | exit;; |
---|
82 | |
---|
83 | "-d") |
---|
84 | dim=$2 ; shift ; shift ;; |
---|
85 | |
---|
86 | "-O") |
---|
87 | echo "option obsolete dans cette version intermediaire de makegcm" |
---|
88 | exit;; |
---|
89 | |
---|
90 | "-p") |
---|
91 | physique="$2" ; shift ; shift ;; |
---|
92 | |
---|
93 | "-g") |
---|
94 | grille="$2" ; shift ; shift ;; |
---|
95 | |
---|
96 | "-c") |
---|
97 | couple="$2" ; shift ; shift ;; |
---|
98 | |
---|
99 | "-prod") |
---|
100 | compil_mod="prod" ; shift ;; |
---|
101 | |
---|
102 | "-dev") |
---|
103 | compil_mod="dev" ; shift ;; |
---|
104 | |
---|
105 | "-debug") |
---|
106 | compil_mod="debug" ; shift ;; |
---|
107 | |
---|
108 | "-io") |
---|
109 | io="$2" ; shift ; shift ;; |
---|
110 | |
---|
111 | "-v") |
---|
112 | veget="$2" ; shift ; shift ;; |
---|
113 | |
---|
114 | "-chimie") |
---|
115 | chimie="$2" ; shift ; shift ;; |
---|
116 | |
---|
117 | "-parallel") |
---|
118 | parallel="$2" ; shift ; shift ;; |
---|
119 | |
---|
120 | "-include") |
---|
121 | INCLUDE="$INCLUDE -I$2" ; shift ; shift ;; |
---|
122 | |
---|
123 | "-cpp") |
---|
124 | CPP_KEY="$CPP_KEY $2" ; shift ; shift ;; |
---|
125 | |
---|
126 | "-adjnt") |
---|
127 | echo "otpion a reactiver ";exit |
---|
128 | opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d " |
---|
129 | optim="$optim -Dadj" ; shift ;; |
---|
130 | |
---|
131 | "-cosp") |
---|
132 | cosp="$2" ; shift ; shift ;; |
---|
133 | |
---|
134 | |
---|
135 | "-filtre") |
---|
136 | filtre=$2 ; shift ; shift ;; |
---|
137 | |
---|
138 | "-link") |
---|
139 | LIB="$LIB $2" ; shift ; shift ;; |
---|
140 | |
---|
141 | "-fcm_path") |
---|
142 | fcm_path=$2 ; shift ; shift ;; |
---|
143 | |
---|
144 | "-ext_src") |
---|
145 | EXT_SRC=$2 ; shift ; shift ;; |
---|
146 | |
---|
147 | "-arch") |
---|
148 | arch=$2 ; shift ; shift ;; |
---|
149 | |
---|
150 | *) |
---|
151 | code="$1" ; shift ;; |
---|
152 | esac |
---|
153 | done |
---|
154 | |
---|
155 | ############################################################### |
---|
156 | # mettre le chemin du fcm dans le path |
---|
157 | ############################################################### |
---|
158 | if [[ "$fcm_path" != "none" ]] |
---|
159 | then |
---|
160 | export PATH=${fcm_path}:${PATH} |
---|
161 | fi |
---|
162 | |
---|
163 | echo "Chemin du fcm utlise :" |
---|
164 | which fcm |
---|
165 | |
---|
166 | ############################################################### |
---|
167 | # lecture des chemins propres à l'architecture de la machine # |
---|
168 | ############################################################### |
---|
169 | rm -f .void_file |
---|
170 | echo > .void_file |
---|
171 | rm -rf .void_dir |
---|
172 | mkdir .void_dir |
---|
173 | rm -f arch.path |
---|
174 | ln -s arch/arch-${arch}.path ./arch.path |
---|
175 | source arch.path |
---|
176 | |
---|
177 | ######################################################################## |
---|
178 | # Definition des clefs CPP, des chemins des includes et modules |
---|
179 | # et des libraries |
---|
180 | ######################################################################## |
---|
181 | |
---|
182 | if [[ "$compil_mod" == "prod" ]] |
---|
183 | then |
---|
184 | COMPIL_FFLAGS="%PROD_FFLAGS" |
---|
185 | elif [[ "$compil_mod" == "dev" ]] |
---|
186 | then |
---|
187 | COMPIL_FFLAGS="%DEV_FFLAGS" |
---|
188 | elif [[ "$compil_mod" == "debug" ]] |
---|
189 | then |
---|
190 | COMPIL_FFLAGS="%DEBUG_FFLAGS" |
---|
191 | fi |
---|
192 | |
---|
193 | if [[ "$physique" != "nophys" ]] |
---|
194 | then |
---|
195 | #Default planet type is Earth |
---|
196 | CPP_KEY="$CPP_KEY CPP_EARTH" |
---|
197 | fi |
---|
198 | |
---|
199 | if [[ "$chimie" == "INCA" ]] |
---|
200 | then |
---|
201 | CPP_KEY="$CPP_KEY INCA" |
---|
202 | INCLUDE="$INCLUDE -I${INCA_INCDIR}" |
---|
203 | LIB="$LIB -L${INCA_LIBDIR} -lchimie" |
---|
204 | fi |
---|
205 | |
---|
206 | if [[ "$couple" != "false" ]] |
---|
207 | then |
---|
208 | CPP_KEY="$CPP_KEY CPP_COUPLE" |
---|
209 | INCLUDE="$INCLUDE -I${OASIS_INCDIR}" |
---|
210 | LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io" |
---|
211 | fi |
---|
212 | |
---|
213 | if [[ "$parallel" == "mpi" ]] |
---|
214 | then |
---|
215 | CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI" |
---|
216 | PARA_FFLAGS="%MPI_FFLAGS" |
---|
217 | PARA_LD="%MPI_LD" |
---|
218 | elif [[ "$parallel" == "omp" ]] |
---|
219 | then |
---|
220 | CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP" |
---|
221 | PARA_FFLAGS="%OMP_FFLAGS" |
---|
222 | PARA_LD="%OMP_LD" |
---|
223 | elif [[ "$parallel" == "mpi_omp" ]] |
---|
224 | then |
---|
225 | CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP" |
---|
226 | PARA_FFLAGS="%MPI_FFLAGS %OMP_FFLAGS" |
---|
227 | PARA_LD="%MPI_LD %OMP_LD" |
---|
228 | fi |
---|
229 | |
---|
230 | if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \ |
---|
231 | && "$compil_mod" == "debug" ]] |
---|
232 | then |
---|
233 | echo "Usually, parallelization with OpenMP requires some optimization." |
---|
234 | echo "We suggest switching to \"-dev\"." |
---|
235 | fi |
---|
236 | |
---|
237 | if [[ "$veget" == "true" ]] |
---|
238 | then |
---|
239 | CPP_KEY="$CPP_KEY CPP_VEGET" |
---|
240 | INCLUDE="${INCLUDE} -I${ORCH_INCDIR}" |
---|
241 | LIB="${LIB} -L${ORCH_LIBDIR} -l${LIBPREFIX}sechiba -l${LIBPREFIX}parameters -l${LIBPREFIX}stomate -l${LIBPREFIX}parallel -l${LIBPREFIX}orglob" |
---|
242 | fi |
---|
243 | |
---|
244 | if [[ $io == ioipsl ]] |
---|
245 | then |
---|
246 | CPP_KEY="$CPP_KEY CPP_IOIPSL" |
---|
247 | INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}" |
---|
248 | LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl" |
---|
249 | fi |
---|
250 | if [[ "$cosp" == "true" ]] |
---|
251 | then |
---|
252 | CPP_KEY="$CPP_KEY CPP_COSP" |
---|
253 | COSP_PATH="$LIBFGCM/cosp" |
---|
254 | # LIB="${LIB} -l${LIBPREFIX}cosp" |
---|
255 | fi |
---|
256 | INCLUDE="$INCLUDE -I${NETCDF_INCDIR}" |
---|
257 | LIB="$LIB -L${NETCDF_LIBDIR} -lnetcdf" |
---|
258 | |
---|
259 | ######################################################################## |
---|
260 | # calcul du nombre de dimensions |
---|
261 | ######################################################################## |
---|
262 | |
---|
263 | |
---|
264 | dim_full=$dim |
---|
265 | dim=`echo $dim | sed -e 's/[^0-9]/ /g'` |
---|
266 | set $dim |
---|
267 | dimc=$# |
---|
268 | echo calcul de la dimension |
---|
269 | echo dim $dim |
---|
270 | echo dimc $dimc |
---|
271 | |
---|
272 | |
---|
273 | ######################################################################## |
---|
274 | # Gestion des dimensions du modele. |
---|
275 | # on cree ou remplace le fichier des dimensions |
---|
276 | ######################################################################## |
---|
277 | |
---|
278 | cd $LIBFGCM/grid/dimension |
---|
279 | ./makdim $dim |
---|
280 | cat $LIBFGCM/grid/dimensions.h |
---|
281 | cd $LMDGCM |
---|
282 | |
---|
283 | |
---|
284 | ######################################################################## |
---|
285 | # Differentes dynamiques (3d, 2d, 1d) |
---|
286 | ######################################################################## |
---|
287 | |
---|
288 | dimension=`echo $dim | wc -w` |
---|
289 | echo dimension $dimension |
---|
290 | |
---|
291 | if (( $dimension == 3 )) |
---|
292 | then |
---|
293 | cd $LIBFGCM/grid |
---|
294 | \rm fxyprim.h |
---|
295 | cp -p fxy_${grille}.h fxyprim.h |
---|
296 | else |
---|
297 | echo "Probleme dans les dimensions de la dynamique !!" |
---|
298 | echo "Non reactive pour l'instant !!!" |
---|
299 | fi |
---|
300 | |
---|
301 | ###################################################################### |
---|
302 | # Traitement special pour le nouveau rayonnement de Laurent Li. |
---|
303 | # ---> YM desactive pour le traitemement en parallele |
---|
304 | ###################################################################### |
---|
305 | |
---|
306 | #if [[ -f $libf/phy$physique/raddim.h ]] |
---|
307 | #then |
---|
308 | # if [[ -f $libf/phy$physique/raddim.$dimh.h ]] |
---|
309 | #then |
---|
310 | # \rm -f $libf/phy$physique/raddim.h |
---|
311 | # cp -p $libf/phy$physique/raddim.$dimh.h $libf/phy$physique/raddim.h |
---|
312 | # echo $libf/phy$physique/raddim.$dimh.h |
---|
313 | # cat $libf/phy$physique/raddim.h |
---|
314 | # else |
---|
315 | # echo On peut diminuer la taille de l executable en creant |
---|
316 | # echo le fichier $libf/phy$physique/raddim.$dimh.h |
---|
317 | # \cp -p $libf/phy$physique/raddim.defaut.h $libf/phy$physique/raddim.h |
---|
318 | # fi |
---|
319 | #fi |
---|
320 | |
---|
321 | ###################################################################### |
---|
322 | # Gestion du filtre qui n'existe qu'en 3d. |
---|
323 | ###################################################################### |
---|
324 | |
---|
325 | if (( `expr $dimc \> 2` == 1 )) |
---|
326 | then |
---|
327 | filtre="FILTRE=$filtre" |
---|
328 | else |
---|
329 | filtre="FILTRE= L_FILTRE= " |
---|
330 | fi |
---|
331 | echo MACRO FILTRE $filtre |
---|
332 | |
---|
333 | echo $dimc |
---|
334 | |
---|
335 | |
---|
336 | |
---|
337 | ###################################################################### |
---|
338 | # Creation du suffixe de la configuration |
---|
339 | ###################################################################### |
---|
340 | |
---|
341 | |
---|
342 | SUFF_NAME=_${dim_full} |
---|
343 | SUFF_NAME=${SUFF_NAME}_phy${physique} |
---|
344 | |
---|
345 | if [[ "$parallel" != "none" ]] |
---|
346 | then |
---|
347 | SUFF_NAME=${SUFF_NAME}_para |
---|
348 | DYN=dyn${dimc}dpar |
---|
349 | else |
---|
350 | SUFF_NAME=${SUFF_NAME}_seq |
---|
351 | DYN=dyn${dimc}d |
---|
352 | fi |
---|
353 | |
---|
354 | if [[ $veget == "true" ]] |
---|
355 | then |
---|
356 | SUFF_NAME=${SUFF_NAME}_orch |
---|
357 | fi |
---|
358 | |
---|
359 | if [[ $couple != "false" ]] |
---|
360 | then |
---|
361 | SUFF_NAME=${SUFF_NAME}_couple |
---|
362 | fi |
---|
363 | |
---|
364 | if [[ $chimie == "INCA" ]] |
---|
365 | then |
---|
366 | SUFF_NAME=${SUFF_NAME}_inca |
---|
367 | fi |
---|
368 | |
---|
369 | cd $LMDGCM |
---|
370 | config_fcm="config.fcm" |
---|
371 | rm -f $config_fcm |
---|
372 | touch $config_fcm |
---|
373 | rm -f bin/${code}${SUFF_NAME}.e |
---|
374 | rm -f arch.fcm |
---|
375 | rm -f arch.opt |
---|
376 | |
---|
377 | echo "%ARCH $arch" >> $config_fcm |
---|
378 | echo "%INCDIR $INCLUDE" >> $config_fcm |
---|
379 | echo "%LIB $LIB" >> $config_fcm |
---|
380 | echo "%ROOT_PATH $PWD" >> $config_fcm |
---|
381 | echo "%LIBF $LIBFGCM" >> $config_fcm |
---|
382 | echo "%LIBO $LIBOGCM" >> $config_fcm |
---|
383 | echo "%DYN $DYN" >> $config_fcm |
---|
384 | echo "%PHYS phy${physique}" >> $config_fcm |
---|
385 | echo "%COSP $COSP_PATH" >> $config_fcm |
---|
386 | echo "%CPP_KEY $CPP_KEY" >> $config_fcm |
---|
387 | echo "%EXEC $code" >> $config_fcm |
---|
388 | echo "%SUFF_NAME $SUFF_NAME" >> $config_fcm |
---|
389 | echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> $config_fcm |
---|
390 | echo "%PARA_FFLAGS $PARA_FFLAGS" >> $config_fcm |
---|
391 | echo "%PARA_LD $PARA_LD" >> $config_fcm |
---|
392 | echo "%EXT_SRC $EXT_SRC" >> $config_fcm |
---|
393 | |
---|
394 | |
---|
395 | |
---|
396 | ln -s arch/arch-${arch}.fcm arch.fcm |
---|
397 | if test -f arch/arch-${arch}.opt && [ $compil_mod = "prod" ] |
---|
398 | then |
---|
399 | ln -s arch/arch-${arch}.opt arch.opt |
---|
400 | else |
---|
401 | ln -s .void_file arch.opt |
---|
402 | fi |
---|
403 | |
---|
404 | |
---|
405 | rm -f $LIBOGCM/${arch}${SUFF_NAME}/.config/fcm.bld.lock |
---|
406 | ./build_gcm |
---|
407 | |
---|
408 | rm -rf tmp_src |
---|
409 | rm -rf config |
---|
410 | ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config config |
---|
411 | ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/tmp tmp_src |
---|