source: LMDZ5/trunk/makelmdz_fcm @ 1829

Last change on this file since 1829 was 1811, checked in by Ehouarn Millour, 11 years ago

Small fix in makelmdz to enable linking with orchidee2.0 library. Added same handling of library dependencies in makelmdz_fcm.
EM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.7 KB
RevLine 
[1279]1#!/bin/bash
2# $Id: makelmdz_fcm 1811 2013-07-24 09:42:06Z idelkadi $
3# This is a script in Bash.
4
[1140]5# FH : on ne crée plus le fichier arch.mk qui est supposé exister par
[783]6# FH : ailleurs.
[1140]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.
[783]12#
[1279]13##set -x
[783]14########################################################################
15# options par defaut pour la commande make
16########################################################################
17
[1279]18dim="96x72x19"
19physique=lmd
20filtre=filtrez
21grille=reg
22couple=false
23veget=false
24chimie=false
25parallel=none
[1680]26paramem="par"
[1279]27compil_mod=prod
28io=ioipsl
29LIBPREFIX=""
30cosp=false
[1802]31job=1
32full=''
[783]33
[1279]34LMDGCM=`/bin/pwd`
35LIBOGCM=$LMDGCM/libo
36LIBFGCM=$LMDGCM/libf
[1327]37COSP_PATH=$LMDGCM/.void_dir
[1578]38fcm_path=$LMDGCM/tools/fcm/bin
[783]39
40########################################################################
41#  Quelques initialisations de variables du shell.
42########################################################################
43
[1279]44CPP_KEY="" 
45INCLUDE=""
46LIB=""
47adjnt=""
48COMPIL_FFLAGS="%PROD_FFLAGS"
49PARA_FFLAGS=""
50PARA_LD=""
51EXT_SRC=""
[783]52
53########################################################################
54# lecture des options de mymake
55########################################################################
56
[1279]57while (($# > 0))
58  do
59  case $1 in
60      "-h") cat <<fin
[783]61Usage :
[1772]62makelmdz_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
[1802]83[-j n]                     : active parallel compiling on ntask
84[-full]                    : full recompiling
[1772]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
[783]89fin
[1279]90          exit;;
[783]91
[1279]92      "-d")
93          dim=$2 ; shift ; shift ;;
94     
95      "-p")
96          physique="$2" ;  shift ; shift ;;
[783]97
[1279]98      "-g")
99          grille="$2" ; shift ; shift ;;
[783]100
[1279]101      "-c")
102          couple="$2" ; shift ; shift ;;
[783]103
[1279]104      "-prod")
105          compil_mod="prod" ; shift ;;
[1002]106
[1279]107      "-dev")
108          compil_mod="dev" ; shift ;;
[1002]109
[1279]110      "-debug")
111          compil_mod="debug" ; shift ;;
[1002]112
[1279]113      "-io")
114          io="$2" ; shift ; shift ;;
[783]115
[1279]116      "-v")
117          veget="$2" ; shift ; shift ;;
[783]118
[1279]119      "-chimie")
120          chimie="$2" ; shift ; shift ;;
[783]121
[1279]122      "-parallel")
123          parallel="$2" ; shift ; shift ;;
124     
125      "-include")
126          INCLUDE="$INCLUDE -I$2" ; shift ; shift ;;
[783]127
[1279]128      "-cpp")
129          CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
[1132]130
[1279]131      "-adjnt")
[1772]132          echo "not operational ... work to be done here ";exit
[1279]133          opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
134          optim="$optim -Dadj" ; shift ;;
[783]135
[1279]136      "-cosp")
137          cosp="$2" ; shift ; shift ;;
[1680]138     
139      "-mem")
140          paramem="mem" ; shift ;;
[783]141
[1279]142      "-filtre")
143          filtre=$2 ; shift ; shift ;;
[783]144
[1279]145      "-link")
146          LIB="$LIB $2" ; shift ; shift ;;
[1136]147
[1279]148      "-fcm_path")
149          fcm_path=$2 ; shift ; shift ;;
[783]150
[1279]151      "-ext_src")
152          EXT_SRC=$2 ; shift ; shift ;;
[1802]153      "-j")
154          job=$2 ; shift ; shift ;;
155      "-full")
156          full="-full" ; shift ;;
[783]157
[1279]158      "-arch")
159          arch=$2 ; shift ; shift ;;
[783]160
[1279]161      *)
162          code="$1" ; shift ;;
163  esac
164done
165
[1136]166###############################################################
[1755]167# path to fcm
[1136]168###############################################################
[1755]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
171if [[ ${fcm_path:0:1} != "/" ]] ; then
172  # prepend with makelmdz_fcm location
173  fcm_path=$(cd $(dirname $0) ; pwd)"/"${fcm_path}
174fi
[783]175
[1757]176# add fcm_path to PATH
177export PATH=${fcm_path}:${PATH}
178
[1755]179echo "Path to fcm:"
180echo ${fcm_path}
[1136]181
[783]182###############################################################
[1140]183# lecture des chemins propres à l'architecture de la machine #
[783]184###############################################################
[1279]185rm -f .void_file
186echo > .void_file
[1327]187rm -rf .void_dir
188mkdir .void_dir
[1279]189rm -f arch.path
190ln -s arch/arch-${arch}.path ./arch.path
[783]191source arch.path
192
193########################################################################
194# Definition des clefs CPP, des chemins des includes et modules
195#  et des libraries
196########################################################################
197
[1279]198if [[ "$compil_mod" == "prod" ]]
199then
200  COMPIL_FFLAGS="%PROD_FFLAGS"
201elif [[ "$compil_mod" == "dev" ]]
202then
203  COMPIL_FFLAGS="%DEV_FFLAGS"
204elif [[ "$compil_mod" == "debug" ]]
205then
206  COMPIL_FFLAGS="%DEBUG_FFLAGS"
207fi
[783]208
[1279]209if [[ "$physique" != "nophys" ]]
210then
[1615]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
[1279]216   CPP_KEY="$CPP_KEY CPP_EARTH"
[1615]217   fi
[1279]218fi
[783]219
[1279]220if [[ "$chimie" == "INCA" ]]
221then
222   CPP_KEY="$CPP_KEY INCA"
223   INCLUDE="$INCLUDE -I${INCA_INCDIR}"
224   LIB="$LIB -L${INCA_LIBDIR} -lchimie"
225fi
[783]226
[1279]227if [[ "$couple" != "false" ]]
228then
229   CPP_KEY="$CPP_KEY CPP_COUPLE"
230   INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
231   LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io"
232fi
[783]233
[1279]234if [[ "$parallel" == "mpi" ]]
235then
236   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI"
237   PARA_FFLAGS="%MPI_FFLAGS"
238   PARA_LD="%MPI_LD"
239elif [[ "$parallel" == "omp" ]]
240then
241   CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP"
242   PARA_FFLAGS="%OMP_FFLAGS"
243   PARA_LD="%OMP_LD"
244elif [[ "$parallel" == "mpi_omp" ]]
245then
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"
249fi
[783]250
[1279]251if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \
252   && "$compil_mod" == "debug" ]]
253then
254    echo "Usually, parallelization with OpenMP requires some optimization."
255    echo "We suggest switching to \"-dev\"."
256fi
[783]257
[1811]258if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ]
[1279]259then
[1811]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
[1279]263   INCLUDE="${INCLUDE} -I${ORCH_INCDIR}"
[1772]264   CPP_KEY="$CPP_KEY CPP_VEGET"
[1811]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=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
280elif [[ "$veget" != "false" ]] ; then
[1772]281   echo "Option -v $veget does not exist"
282   echo "Use ./makelmdz_fcm -h for more information"
283   exit 
[1279]284fi
[783]285
[1279]286if [[ $io == ioipsl ]]
287then
288   CPP_KEY="$CPP_KEY CPP_IOIPSL"
289   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}"
290   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
291fi
292if [[ "$cosp" == "true" ]]
293then
294   CPP_KEY="$CPP_KEY CPP_COSP"
[1327]295   COSP_PATH="$LIBFGCM/cosp"
[1279]296#   LIB="${LIB} -l${LIBPREFIX}cosp"
297fi
[783]298
[1551]299INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
300LIB="$LIB ${NETCDF_LIBDIR}"
301
[783]302########################################################################
303# calcul du nombre de dimensions
304########################################################################
305
306
[1279]307dim_full=$dim
308dim=`echo $dim | sed -e 's/[^0-9]/ /g'` 
309set $dim
310dimc=$#
[783]311echo calcul de la dimension
312echo dim $dim
313echo dimc $dimc
314
315
316########################################################################
317# Gestion des dimensions du modele.
[1114]318# on cree ou remplace le fichier des dimensions
[783]319########################################################################
320
[1695]321cd $LIBFGCM/grid
322if [[ -f dimensions.h ]]
323then
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?"
[1755]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?"
[1695]335  read reponse
[1755]336  if [[ $reponse == "oui" || $reponse == "yes" ]]
[1695]337  then
[1696]338    \rm -f $LIBFGCM/grid/dimensions.h
[1695]339  else
340    exit
341  fi
342fi
343
344
[783]345cd $LIBFGCM/grid/dimension
[1114]346./makdim $dim
[783]347cat $LIBFGCM/grid/dimensions.h
348cd $LMDGCM
349
350
351########################################################################
352# Differentes dynamiques (3d, 2d, 1d)
353########################################################################
354
[1279]355dimension=`echo $dim | wc -w`
[783]356echo dimension $dimension
357
[1279]358if (( $dimension == 3 ))
359then
[783]360  cd $LIBFGCM/grid
361  \rm fxyprim.h
362  cp -p fxy_${grille}.h fxyprim.h
[1279]363else
364  echo "Probleme dans les dimensions de la dynamique !!"
365  echo "Non reactive pour l'instant !!!"
366fi
[783]367
368######################################################################
369#   Traitement special pour le nouveau rayonnement de Laurent Li.
370#   ---> YM desactive pour le traitemement en parallele
371######################################################################
372
[1279]373#if [[ -f $libf/phy$physique/raddim.h ]]
374#then
375# if [[ -f $libf/phy$physique/raddim.$dimh.h ]]
376#then
[783]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
[1279]385# fi
386#fi
[783]387
388######################################################################
389# Gestion du filtre qui n'existe qu'en 3d.
390######################################################################
391
[1279]392if (( `expr $dimc \> 2` == 1 ))
393then
394   filtre="FILTRE=$filtre"
[783]395else
[1279]396   filtre="FILTRE= L_FILTRE= "
397fi
[783]398echo MACRO FILTRE $filtre
399
400echo $dimc
401
402
403
404######################################################################
405# Creation du suffixe de la configuration
406######################################################################
407
408
[1279]409SUFF_NAME=_${dim_full}
410SUFF_NAME=${SUFF_NAME}_phy${physique}
[783]411
[1279]412if [[ "$parallel" != "none" ]]
413then
414  SUFF_NAME=${SUFF_NAME}_para
[1680]415  DYN=dyn${dimc}d${paramem}
416  if [[ "$paramem" == "mem" ]]
417  then
418   SUFF_NAME=${SUFF_NAME}_${paramem}
419  fi
[783]420else
[1279]421  SUFF_NAME=${SUFF_NAME}_seq
422  DYN=dyn${dimc}d
423fi
[783]424
[1772]425if [[ $veget != "false" ]]
[1279]426then
427  SUFF_NAME=${SUFF_NAME}_orch
428fi
[783]429
[1279]430if [[ $couple != "false" ]]
431then
432  SUFF_NAME=${SUFF_NAME}_couple
433fi
[783]434
[1279]435if [[ $chimie == "INCA" ]]
436then
437  SUFF_NAME=${SUFF_NAME}_inca
438fi
[783]439
440cd $LMDGCM
[1279]441config_fcm="config.fcm"
[783]442rm -f $config_fcm
443touch $config_fcm
444rm -f bin/${code}${SUFF_NAME}.e
445rm -f arch.fcm
[1279]446rm -f arch.opt
[783]447
448echo "%ARCH          $arch"          >> $config_fcm
449echo "%INCDIR        $INCLUDE"       >> $config_fcm 
450echo "%LIB           $LIB"           >> $config_fcm
451echo "%ROOT_PATH     $PWD"           >> $config_fcm
452echo "%LIBF          $LIBFGCM"       >> $config_fcm
453echo "%LIBO          $LIBOGCM"       >> $config_fcm
454echo "%DYN           $DYN"           >> $config_fcm
455echo "%PHYS          phy${physique}" >> $config_fcm
[1327]456echo "%COSP          $COSP_PATH"     >> $config_fcm
[783]457echo "%CPP_KEY       $CPP_KEY"       >> $config_fcm
458echo "%EXEC          $code"          >> $config_fcm
459echo "%SUFF_NAME     $SUFF_NAME"     >> $config_fcm
[1002]460echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> $config_fcm
461echo "%PARA_FFLAGS   $PARA_FFLAGS"   >> $config_fcm
462echo "%PARA_LD       $PARA_LD"       >> $config_fcm
[1279]463echo "%EXT_SRC       $EXT_SRC"       >> $config_fcm
[783]464
[1002]465
466
[1137]467ln -s arch/arch-${arch}.fcm arch.fcm
[1279]468if test -f arch/arch-${arch}.opt &&  [ $compil_mod = "prod" ]
469  then
470  ln -s arch/arch-${arch}.opt arch.opt
471else
472  ln -s .void_file arch.opt
473fi
474
475
[1002]476rm -f $LIBOGCM/${arch}${SUFF_NAME}/.config/fcm.bld.lock
[1802]477./build_gcm ${fcm_path} -j $job $full
[783]478
[1279]479rm -rf tmp_src
480rm -rf config
[783]481ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config config
482ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/tmp tmp_src
[1695]483
[1696]484if [[ -r $LIBFGCM/grid/dimensions.h ]]
[1695]485then
486  # Cleanup: remove dimension.h file
[1696]487  \rm -f $LIBFGCM/grid/dimensions.h
[1695]488fi
Note: See TracBrowser for help on using the repository browser.