source: LMDZ5/trunk/makelmdz_fcm @ 2238

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

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