source: LMDZ5/trunk/makelmdz_fcm @ 2085

Last change on this file since 2085 was 2084, checked in by Ehouarn Millour, 10 years ago

Small cosmetic change in makelmdz_fcm, use an empty dir strategy for optional packages rather than overwriting the bld.cfg file (causes issues when the later is a symbolic link).
EM

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