source: LMDZ5/trunk/makelmdz_fcm @ 1806

Last change on this file since 1806 was 1802, checked in by yann meurdesoif, 11 years ago

Add parallel compiling functionality through fcm
=> 2 new options for the makelmdz_fcm

-j n : enable parallel compiling on 8 tasks
-full : recreate dependency and recompile form scratch

YM

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