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