source: LMDZ5/trunk/makelmdz_fcm @ 2232

Last change on this file since 2232 was 2202, checked in by lguez, 9 years ago

Added tests in the compilation scripts: iim should be a multiple of 8 and dyn3dpar should not be used.

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