| 1 | #!/bin/bash |
|---|
| 2 | # $Id: makelmdz_fcm 1615 2012-02-10 15:42:26Z 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 | compil_mod=prod |
|---|
| 27 | io=ioipsl |
|---|
| 28 | LIBPREFIX="" |
|---|
| 29 | cosp=false |
|---|
| 30 | |
|---|
| 31 | LMDGCM=`/bin/pwd` |
|---|
| 32 | LIBOGCM=$LMDGCM/libo |
|---|
| 33 | LIBFGCM=$LMDGCM/libf |
|---|
| 34 | COSP_PATH=$LMDGCM/.void_dir |
|---|
| 35 | fcm_path=$LMDGCM/tools/fcm/bin |
|---|
| 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: tools/fcm/bin) |
|---|
| 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 | export PATH=${fcm_path}:${PATH} |
|---|
| 159 | |
|---|
| 160 | echo "Chemin du fcm utlise :" |
|---|
| 161 | which fcm |
|---|
| 162 | |
|---|
| 163 | ############################################################### |
|---|
| 164 | # lecture des chemins propres à l'architecture de la machine # |
|---|
| 165 | ############################################################### |
|---|
| 166 | rm -f .void_file |
|---|
| 167 | echo > .void_file |
|---|
| 168 | rm -rf .void_dir |
|---|
| 169 | mkdir .void_dir |
|---|
| 170 | rm -f arch.path |
|---|
| 171 | ln -s arch/arch-${arch}.path ./arch.path |
|---|
| 172 | source arch.path |
|---|
| 173 | |
|---|
| 174 | ######################################################################## |
|---|
| 175 | # Definition des clefs CPP, des chemins des includes et modules |
|---|
| 176 | # et des libraries |
|---|
| 177 | ######################################################################## |
|---|
| 178 | |
|---|
| 179 | if [[ "$compil_mod" == "prod" ]] |
|---|
| 180 | then |
|---|
| 181 | COMPIL_FFLAGS="%PROD_FFLAGS" |
|---|
| 182 | elif [[ "$compil_mod" == "dev" ]] |
|---|
| 183 | then |
|---|
| 184 | COMPIL_FFLAGS="%DEV_FFLAGS" |
|---|
| 185 | elif [[ "$compil_mod" == "debug" ]] |
|---|
| 186 | then |
|---|
| 187 | COMPIL_FFLAGS="%DEBUG_FFLAGS" |
|---|
| 188 | fi |
|---|
| 189 | |
|---|
| 190 | if [[ "$physique" != "nophys" ]] |
|---|
| 191 | then |
|---|
| 192 | #We'll use some physics |
|---|
| 193 | CPP_KEY="$CPP_KEY CPP_PHYS" |
|---|
| 194 | if [[ "${physique:0:3}" == "lmd" ]] |
|---|
| 195 | then |
|---|
| 196 | #For lmd physics, default planet type is Earth |
|---|
| 197 | CPP_KEY="$CPP_KEY CPP_EARTH" |
|---|
| 198 | fi |
|---|
| 199 | fi |
|---|
| 200 | |
|---|
| 201 | if [[ "$chimie" == "INCA" ]] |
|---|
| 202 | then |
|---|
| 203 | CPP_KEY="$CPP_KEY INCA" |
|---|
| 204 | INCLUDE="$INCLUDE -I${INCA_INCDIR}" |
|---|
| 205 | LIB="$LIB -L${INCA_LIBDIR} -lchimie" |
|---|
| 206 | fi |
|---|
| 207 | |
|---|
| 208 | if [[ "$couple" != "false" ]] |
|---|
| 209 | then |
|---|
| 210 | CPP_KEY="$CPP_KEY CPP_COUPLE" |
|---|
| 211 | INCLUDE="$INCLUDE -I${OASIS_INCDIR}" |
|---|
| 212 | LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io" |
|---|
| 213 | fi |
|---|
| 214 | |
|---|
| 215 | if [[ "$parallel" == "mpi" ]] |
|---|
| 216 | then |
|---|
| 217 | CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI" |
|---|
| 218 | PARA_FFLAGS="%MPI_FFLAGS" |
|---|
| 219 | PARA_LD="%MPI_LD" |
|---|
| 220 | elif [[ "$parallel" == "omp" ]] |
|---|
| 221 | then |
|---|
| 222 | CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP" |
|---|
| 223 | PARA_FFLAGS="%OMP_FFLAGS" |
|---|
| 224 | PARA_LD="%OMP_LD" |
|---|
| 225 | elif [[ "$parallel" == "mpi_omp" ]] |
|---|
| 226 | then |
|---|
| 227 | CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP" |
|---|
| 228 | PARA_FFLAGS="%MPI_FFLAGS %OMP_FFLAGS" |
|---|
| 229 | PARA_LD="%MPI_LD %OMP_LD" |
|---|
| 230 | fi |
|---|
| 231 | |
|---|
| 232 | if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \ |
|---|
| 233 | && "$compil_mod" == "debug" ]] |
|---|
| 234 | then |
|---|
| 235 | echo "Usually, parallelization with OpenMP requires some optimization." |
|---|
| 236 | echo "We suggest switching to \"-dev\"." |
|---|
| 237 | fi |
|---|
| 238 | |
|---|
| 239 | if [[ "$veget" == "true" ]] |
|---|
| 240 | then |
|---|
| 241 | CPP_KEY="$CPP_KEY CPP_VEGET" |
|---|
| 242 | INCLUDE="${INCLUDE} -I${ORCH_INCDIR}" |
|---|
| 243 | LIB="${LIB} -L${ORCH_LIBDIR} -l${LIBPREFIX}sechiba -l${LIBPREFIX}parameters -l${LIBPREFIX}stomate -l${LIBPREFIX}parallel -l${LIBPREFIX}orglob" |
|---|
| 244 | fi |
|---|
| 245 | |
|---|
| 246 | if [[ $io == ioipsl ]] |
|---|
| 247 | then |
|---|
| 248 | CPP_KEY="$CPP_KEY CPP_IOIPSL" |
|---|
| 249 | INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}" |
|---|
| 250 | LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl" |
|---|
| 251 | fi |
|---|
| 252 | if [[ "$cosp" == "true" ]] |
|---|
| 253 | then |
|---|
| 254 | CPP_KEY="$CPP_KEY CPP_COSP" |
|---|
| 255 | COSP_PATH="$LIBFGCM/cosp" |
|---|
| 256 | # LIB="${LIB} -l${LIBPREFIX}cosp" |
|---|
| 257 | fi |
|---|
| 258 | |
|---|
| 259 | INCLUDE="$INCLUDE ${NETCDF_INCDIR}" |
|---|
| 260 | LIB="$LIB ${NETCDF_LIBDIR}" |
|---|
| 261 | |
|---|
| 262 | ######################################################################## |
|---|
| 263 | # calcul du nombre de dimensions |
|---|
| 264 | ######################################################################## |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | dim_full=$dim |
|---|
| 268 | dim=`echo $dim | sed -e 's/[^0-9]/ /g'` |
|---|
| 269 | set $dim |
|---|
| 270 | dimc=$# |
|---|
| 271 | echo calcul de la dimension |
|---|
| 272 | echo dim $dim |
|---|
| 273 | echo dimc $dimc |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | ######################################################################## |
|---|
| 277 | # Gestion des dimensions du modele. |
|---|
| 278 | # on cree ou remplace le fichier des dimensions |
|---|
| 279 | ######################################################################## |
|---|
| 280 | |
|---|
| 281 | cd $LIBFGCM/grid/dimension |
|---|
| 282 | ./makdim $dim |
|---|
| 283 | cat $LIBFGCM/grid/dimensions.h |
|---|
| 284 | cd $LMDGCM |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | ######################################################################## |
|---|
| 288 | # Differentes dynamiques (3d, 2d, 1d) |
|---|
| 289 | ######################################################################## |
|---|
| 290 | |
|---|
| 291 | dimension=`echo $dim | wc -w` |
|---|
| 292 | echo dimension $dimension |
|---|
| 293 | |
|---|
| 294 | if (( $dimension == 3 )) |
|---|
| 295 | then |
|---|
| 296 | cd $LIBFGCM/grid |
|---|
| 297 | \rm fxyprim.h |
|---|
| 298 | cp -p fxy_${grille}.h fxyprim.h |
|---|
| 299 | else |
|---|
| 300 | echo "Probleme dans les dimensions de la dynamique !!" |
|---|
| 301 | echo "Non reactive pour l'instant !!!" |
|---|
| 302 | fi |
|---|
| 303 | |
|---|
| 304 | ###################################################################### |
|---|
| 305 | # Traitement special pour le nouveau rayonnement de Laurent Li. |
|---|
| 306 | # ---> YM desactive pour le traitemement en parallele |
|---|
| 307 | ###################################################################### |
|---|
| 308 | |
|---|
| 309 | #if [[ -f $libf/phy$physique/raddim.h ]] |
|---|
| 310 | #then |
|---|
| 311 | # if [[ -f $libf/phy$physique/raddim.$dimh.h ]] |
|---|
| 312 | #then |
|---|
| 313 | # \rm -f $libf/phy$physique/raddim.h |
|---|
| 314 | # cp -p $libf/phy$physique/raddim.$dimh.h $libf/phy$physique/raddim.h |
|---|
| 315 | # echo $libf/phy$physique/raddim.$dimh.h |
|---|
| 316 | # cat $libf/phy$physique/raddim.h |
|---|
| 317 | # else |
|---|
| 318 | # echo On peut diminuer la taille de l executable en creant |
|---|
| 319 | # echo le fichier $libf/phy$physique/raddim.$dimh.h |
|---|
| 320 | # \cp -p $libf/phy$physique/raddim.defaut.h $libf/phy$physique/raddim.h |
|---|
| 321 | # fi |
|---|
| 322 | #fi |
|---|
| 323 | |
|---|
| 324 | ###################################################################### |
|---|
| 325 | # Gestion du filtre qui n'existe qu'en 3d. |
|---|
| 326 | ###################################################################### |
|---|
| 327 | |
|---|
| 328 | if (( `expr $dimc \> 2` == 1 )) |
|---|
| 329 | then |
|---|
| 330 | filtre="FILTRE=$filtre" |
|---|
| 331 | else |
|---|
| 332 | filtre="FILTRE= L_FILTRE= " |
|---|
| 333 | fi |
|---|
| 334 | echo MACRO FILTRE $filtre |
|---|
| 335 | |
|---|
| 336 | echo $dimc |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | ###################################################################### |
|---|
| 341 | # Creation du suffixe de la configuration |
|---|
| 342 | ###################################################################### |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | SUFF_NAME=_${dim_full} |
|---|
| 346 | SUFF_NAME=${SUFF_NAME}_phy${physique} |
|---|
| 347 | |
|---|
| 348 | if [[ "$parallel" != "none" ]] |
|---|
| 349 | then |
|---|
| 350 | SUFF_NAME=${SUFF_NAME}_para |
|---|
| 351 | DYN=dyn${dimc}dpar |
|---|
| 352 | else |
|---|
| 353 | SUFF_NAME=${SUFF_NAME}_seq |
|---|
| 354 | DYN=dyn${dimc}d |
|---|
| 355 | fi |
|---|
| 356 | |
|---|
| 357 | if [[ $veget == "true" ]] |
|---|
| 358 | then |
|---|
| 359 | SUFF_NAME=${SUFF_NAME}_orch |
|---|
| 360 | fi |
|---|
| 361 | |
|---|
| 362 | if [[ $couple != "false" ]] |
|---|
| 363 | then |
|---|
| 364 | SUFF_NAME=${SUFF_NAME}_couple |
|---|
| 365 | fi |
|---|
| 366 | |
|---|
| 367 | if [[ $chimie == "INCA" ]] |
|---|
| 368 | then |
|---|
| 369 | SUFF_NAME=${SUFF_NAME}_inca |
|---|
| 370 | fi |
|---|
| 371 | |
|---|
| 372 | cd $LMDGCM |
|---|
| 373 | config_fcm="config.fcm" |
|---|
| 374 | rm -f $config_fcm |
|---|
| 375 | touch $config_fcm |
|---|
| 376 | rm -f bin/${code}${SUFF_NAME}.e |
|---|
| 377 | rm -f arch.fcm |
|---|
| 378 | rm -f arch.opt |
|---|
| 379 | |
|---|
| 380 | echo "%ARCH $arch" >> $config_fcm |
|---|
| 381 | echo "%INCDIR $INCLUDE" >> $config_fcm |
|---|
| 382 | echo "%LIB $LIB" >> $config_fcm |
|---|
| 383 | echo "%ROOT_PATH $PWD" >> $config_fcm |
|---|
| 384 | echo "%LIBF $LIBFGCM" >> $config_fcm |
|---|
| 385 | echo "%LIBO $LIBOGCM" >> $config_fcm |
|---|
| 386 | echo "%DYN $DYN" >> $config_fcm |
|---|
| 387 | echo "%PHYS phy${physique}" >> $config_fcm |
|---|
| 388 | echo "%COSP $COSP_PATH" >> $config_fcm |
|---|
| 389 | echo "%CPP_KEY $CPP_KEY" >> $config_fcm |
|---|
| 390 | echo "%EXEC $code" >> $config_fcm |
|---|
| 391 | echo "%SUFF_NAME $SUFF_NAME" >> $config_fcm |
|---|
| 392 | echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> $config_fcm |
|---|
| 393 | echo "%PARA_FFLAGS $PARA_FFLAGS" >> $config_fcm |
|---|
| 394 | echo "%PARA_LD $PARA_LD" >> $config_fcm |
|---|
| 395 | echo "%EXT_SRC $EXT_SRC" >> $config_fcm |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | ln -s arch/arch-${arch}.fcm arch.fcm |
|---|
| 400 | if test -f arch/arch-${arch}.opt && [ $compil_mod = "prod" ] |
|---|
| 401 | then |
|---|
| 402 | ln -s arch/arch-${arch}.opt arch.opt |
|---|
| 403 | else |
|---|
| 404 | ln -s .void_file arch.opt |
|---|
| 405 | fi |
|---|
| 406 | |
|---|
| 407 | |
|---|
| 408 | rm -f $LIBOGCM/${arch}${SUFF_NAME}/.config/fcm.bld.lock |
|---|
| 409 | ./build_gcm |
|---|
| 410 | |
|---|
| 411 | rm -rf tmp_src |
|---|
| 412 | rm -rf config |
|---|
| 413 | ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config config |
|---|
| 414 | ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/tmp tmp_src |
|---|