source: codes/icosagcm/branches/SATURN_DYNAMICO/LMDZ.COMMON/makelmdz_fcm @ 264

Last change on this file since 264 was 264, checked in by milmd, 10 years ago

Architecture files and some modifications to compile and run on ada.

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