source: LMDZ5/trunk/makelmdz_fcm @ 2273

Last change on this file since 2273 was 2266, checked in by lguez, 9 years ago

Avoid cryptic compilation errors when trying to create ce0l in
parallel: give a clear message in compilation script instead.

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