source: LMDZ5/trunk/makelmdz_fcm @ 2239

Last change on this file since 2239 was 2239, checked in by Ehouarn Millour, 9 years ago

Reorganizing physics/dynamics interface:

  • what is related to dynamics-physics interface is now in a seperate directory: dynlmdz_phy* for physics in phy*
  • 1d model and related dependencies (including a couple from "dynamics", set up as symbolic links) is now in subdirectory "dyn1d" of phy*.
  • "bibio" directory is now "misc" and should only contain autonomous utilities.
  • "cosp" is now a subdirectory of phylmd.

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