source: LMDZ5/trunk/makelmdz @ 1690

Last change on this file since 1690 was 1690, checked in by Ehouarn Millour, 12 years ago

Update makelmdz script to keep up with recent updates in makelmdz_fcm (possibility to use the -mem option and correctly set CPP_PHYS and CPP_EARTH).
EM

  • Property svn:executable set to *
File size: 16.4 KB
Line 
1#!/bin/bash
2#
3# $Id $
4#
5#
6########################################################################
7# for debug, uncomment line below
8#set -xv
9########################################################################
10# options par defaut pour la commande make
11########################################################################
12dim="96x72x19"
13physique=lmd
14code=gcm
15filtre=filtrez
16grille=reg
17couple=false
18veget=false
19chimie=false
20parallel=none
21paramem="par"
22compil_mod=prod
23io=ioipsl
24LIBPREFIX=""
25fcm_path=none
26cosp=false
27
28# guess a default 'arch'
29arch="local" # start with assuming we're on a local machine with local arch file
30## try to recognise machine and infer arch from it
31machine=`hostname`
32if [[ "$machine" == "brodie" ]]
33then
34  arch="SX8_BRODIE"
35fi
36if [[ "${machine:0:6}" == "vargas" ]]
37then
38  arch="PW6_VARGAS"
39fi
40if [[ "${machine:0:6}" == "ciclad" ]]
41then
42  arch="AMD64_CICLAD"
43fi
44if [[ "${machine:0:7}" == "platine" ]]
45then
46  arch="IA64_PLATINE"
47fi
48if [[ "${machine:0:6}" == "titane" ]]
49then
50  arch="X64_TITANE"
51fi
52if [[ "${machine:0:8}" == "mercure1" ]]
53then
54  arch="SX8_MERCURE"
55fi
56if [[ "${machine:0:8}" == "mercure2" ]]
57then
58  arch="SX9_MERCURE"
59fi
60
61LMDGCM=`pwd -P`
62LIBFGCM=$LMDGCM/libf
63LIBOGCM=$LMDGCM/libo
64if [[ ! -d $LIBOGCM ]]
65then
66  # create the directory
67  mkdir $LIBOGCM
68  if [[ ! $? ]]
69  then
70  echo "Failed to create directory $LIBOGCM"
71  exit
72  fi
73fi
74COSP_PATH=$LMDGCM/.void_dir
75
76
77
78localdir=`pwd -P`
79########################################################################
80#  Quelques initialisations de variables du shell.
81########################################################################
82
83CPP_KEY="" 
84INCLUDE='-I$(LIBF)/grid -I$(LIBF)/bibio -I$(LIBF)/filtrez -I. '
85LIB=""
86adjnt=""
87##COMPIL_FFLAGS="%PROD_FFLAGS"
88PARA_FFLAGS=""
89PARA_LD=""
90EXT_SRC=""
91
92########################################################################
93# lecture des options
94########################################################################
95
96while (($# > 0))
97  do
98  case $1 in
99      "-h") cat <<fin
100manuel complet sur http://...
101Usage :
102makegcm [options] exec
103[-h]                       : manuel abrege
104[-d [[IMx]JMx]LM]          : IM, JM, LM sont les dims en x, y, z (def: $dim)
105[-p PHYS]                  : compilation avec la physique libf/phyPHYS, (def: lmd)
106[-prod / -dev / -debug]    : compilation en mode production (default) / developpement / debug .
107[-c false/MPI1/MPI2]       : couple ocean : MPI1/MPI2/false (def: false)
108[-v false/true]            : avec ou sans vegetation (def: false)
109[-chimie INCA/false]       : avec ou sans model de chimie INCA (def: false)
110[-parallel none/mpi/omp/mpi_omp] : parallelisation (default: none) : mpi, openmp ou mixte mpi_openmp
111[-g GRI]                   : conf. grille dans dyn3d/GRI_xy.h  (def: reg inclue un zoom)
112[-io IO]                   : choix d une librairie I/O, experts (def: ioipsl)
113[-include INCLUDES]        : variables supplementaires pour include
114[-cpp CPP_KEY]             : cle cpp supplementaires
115[-adjnt]                   : adjoint, a remettre en route ...
116[-mem]                     : version memoire reduite (si en mode parallele)
117[-filtre NOMFILTRE]        : prend le filtre dans libf/NOMFILTRE (def: filtrez)
118[-link LINKS]              : liens optionels avec d autres librairies
119[-ext_src path]            : chemin d un repertoire source avec des sources externe a compiler avec le modele
120[-arch nom_arch]           : nom de l architecture cible
121 exec                      : executable genere
122fin
123          exit;;
124      "-d")
125          dim=$2 ; shift ; shift ;;
126     
127      "-O")
128          echo "option obsolete dans ce makegcm"
129          exit;;
130
131      "-p")
132          physique="$2" ;  shift ; shift ;;
133
134      "-g")
135          grille="$2" ; shift ; shift ;;
136
137      "-c")
138          couple="$2" ; shift ; shift ;;
139
140      "-prod")
141          compil_mod="prod" ; shift ;;
142
143      "-dev")
144          compil_mod="dev" ; shift ;;
145
146      "-debug")
147          compil_mod="debug" ; shift ;;
148
149      "-io")
150          io="$2" ; shift ; shift ;;
151
152      "-v")
153          veget="$2" ; shift ; shift ;;
154
155      "-chimie")
156          chimie="$2" ; shift ; shift ;;
157
158      "-parallel")
159          parallel="$2" ; shift ; shift ;;
160     
161      "-include")
162          INCLUDE="$INCLUDE -I$2" ; shift ; shift ;;
163
164      "-cpp")
165          CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
166
167      "-adjnt")
168          echo "option a reactiver ";exit
169          opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
170          optim="$optim -Dadj" ; shift ;;
171
172      "-cosp")
173          cosp="$2" ; shift ; shift ;;
174     
175      "-mem")
176          paramem="mem" ; shift ;;
177
178      "-filtre")
179          filtre=$2 ; shift ; shift ;;
180
181      "-link")
182          LIB="$LIB $2" ; shift ; shift ;;
183
184      "-fcm_path")
185          fcm_path=$2 ; shift ; shift ;;
186
187      "-ext_src")
188          EXT_SRC=$2 ; shift ; shift ;;
189
190      "-arch")
191          arch=$2 ; shift ; shift ;;
192
193      *)
194          code="$1" ; shift ;;
195  esac
196done
197
198###############################################################
199# lecture des chemins propres à l'architecture de la machine #
200###############################################################
201rm -f .void_file
202echo > .void_file
203rm -rf .void_dir
204mkdir .void_dir
205rm -f arch.path
206if [[ -r arch/arch-${arch}.path ]]
207then
208  ln -s arch/arch-${arch}.path ./arch.path
209  source arch.path
210else
211  echo "Error: missing arch/arch-${arch}.path file !"
212  exit
213fi
214rm -f arch.fcm
215if [[ -r arch/arch-${arch}.fcm ]]
216then
217  ln -s arch/arch-${arch}.fcm arch.fcm
218else
219  echo "Error: missing arch/arch-${arch}.fcm file !"
220  exit
221fi
222########################################################################
223# Definition des clefs CPP, des chemins des includes et modules
224#  et des libraries
225########################################################################
226
227# basic compile flags from arch.fcm file
228archfileline=$( grep -i '^%BASE_FFLAGS' arch.fcm )
229COMPIL_FFLAGS=$( echo ${archfileline##%BASE_FFLAGS} )
230
231# other compile flags, depending on compilation mode
232if [[ "$compil_mod" == "prod" ]]
233then
234## read COMPIL_FFLAGS from arch.fcm file
235  archfileline=$( grep -i '^%PROD_FFLAGS' arch.fcm )
236  archfileopt=$( echo ${archfileline##%PROD_FFLAGS} )
237  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
238elif [[ "$compil_mod" == "dev" ]]
239then
240## read %DEV_FFLAGS from arch.fcm file
241  archfileline=$( grep -i '^%DEV_FFLAGS' arch.fcm )
242  archfileopt=$( echo ${archfileline##%DEV_FFLAGS} )
243  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
244elif [[ "$compil_mod" == "debug" ]]
245then
246## read %DEBUG_FFLAGS from arch.fcm file
247  archfileline=$( grep -i '^%DEBUG_FFLAGS' arch.fcm )
248  archfileopt=$( echo ${archfileline##%DEBUG_FFLAGS} )
249  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
250fi
251
252# add CPP_KEY defined in arch.fcm file
253archfileline=$( grep -i '^%FPP_DEF' arch.fcm )
254archfileopt=$( echo ${archfileline##%FPP_DEF} )
255CPP_KEY="$CPP_KEY ${archfileopt}"
256
257# get compiler name from arch.fcm file
258archfileline=$( grep -i '^%COMPILER' arch.fcm )
259fcompiler=$( echo ${archfileline##%COMPILER} )
260
261# get linker name from arch.fcm file
262archfileline=$( grep -i '^%LINK' arch.fcm )
263linker=$( echo ${archfileline##%LINK} )
264
265# get ar command from arch.fcm file
266archfileline=$( grep -i '^%AR' arch.fcm )
267arcommand=$( echo ${archfileline##%AR} )
268
269# get make utility from arch.fcm file
270archfileline=$( grep -i '^%MAKE' arch.fcm )
271makecommand=$( echo ${archfileline##%MAKE} )
272
273# get basic libraries to link with arch.fcm file
274archfileline=$( grep -i '^%BASE_LD' arch.fcm )
275archfileopt=$( echo ${archfileline##%BASE_LD} )
276LIB="$LIB  ${archfileopt}"
277
278if [[ "$physique" != "nophys" ]]
279then
280   #We'll use some physics
281   CPP_KEY="$CPP_KEY CPP_PHYS"
282   if [[ "${physique:0:3}" == "lmd" ]]
283   then
284   #For lmd physics, default planet type is Earth
285   CPP_KEY="$CPP_KEY CPP_EARTH"
286   fi
287fi
288
289if [[ "$chimie" == "INCA" ]]
290then
291   CPP_KEY="$CPP_KEY INCA"
292   INCLUDE="$INCLUDE -I${INCA_INCDIR}"
293   LIB="$LIB -L${INCA_LIBDIR} -lchimie"
294   libchimie=" -L${INCA_LIBDIR} -lchimie"
295fi
296
297if [[ "$couple" != "false" ]]
298then
299   CPP_KEY="$CPP_KEY CPP_COUPLE"
300   INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
301   LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io"
302fi
303
304if [[ "$parallel" == "none" ]]
305then
306  FLAG_PARA=''
307else
308  FLAG_PARA="par"
309fi
310
311if [[ "$parallel" == "mpi" ]]
312then
313   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI"
314  # MPI additional compilation options
315  archfileline=$( grep -i '^%MPI_FFLAGS' arch.fcm )
316  PARA_FFLAGS=$( echo ${archfileline##%MPI_FFLAGS} )
317  # MPI additional links
318  archfileline=$( grep -i '^%MPI_LD' arch.fcm )
319  PARA_LD=$( echo ${archfileline##%MPI_LD} )
320elif [[ "$parallel" == "omp" ]]
321then
322   CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP"
323  # OMP additional compilation options
324  archfileline=$( grep -i '^%OMP_FFLAGS' arch.fcm )
325  PARA_FFLAGS=$( echo ${archfileline##%OMP_FFLAGS} )
326  # OMP additional links
327  archfileline=$( grep -i '^%OMP_LD' arch.fcm )
328  PARA_LD=$( echo ${archfileline##%OMP_LD} )
329elif [[ "$parallel" == "mpi_omp" ]]
330then
331   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP"
332  # MPI additional compilation options
333  archfileline=$( grep -i '^%MPI_FFLAGS' arch.fcm )
334  PARA_FFLAGS=$( echo ${archfileline##%MPI_FFLAGS} )
335  # OMP additional compilation options
336  archfileline=$( grep -i '^%OMP_FFLAGS' arch.fcm )
337  PARA_FFLAGS="${PARA_FFLAGS} "$( echo $archfileopt ${archfileline##%OMP_FFLAGS} )
338  # MPI additional links
339  archfileline=$( grep -i '^%MPI_LD' arch.fcm )
340  PARA_LD=$( echo ${archfileline##%MPI_LD} )
341  # OMP additional links
342  archfileline=$( grep -i '^%OMP_LD' arch.fcm )
343  PARA_LD="${PARA_LD} "$( echo $archfileopt ${archfileline##%OMP_LD} )
344fi
345
346if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \
347   && "$compil_mod" == "debug" ]]
348then
349    echo "Usually, parallelization with OpenMP requires some optimization."
350    echo "We suggest switching to \"-dev\"."
351fi
352
353if [[ "$veget" == "true" ]]
354then
355   CPP_KEY="$CPP_KEY CPP_VEGET"
356   INCLUDE="${INCLUDE} -I${ORCH_INCDIR}"
357   LIB="${LIB} -L${ORCH_LIBDIR} -l${LIBPREFIX}sechiba -l${LIBPREFIX}parameters -l${LIBPREFIX}stomate -l${LIBPREFIX}parallel -l${LIBPREFIX}orglob"
358fi
359
360if [[ $io == ioipsl ]]
361then
362   CPP_KEY="$CPP_KEY CPP_IOIPSL"
363   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}"
364   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
365fi
366
367if [[ "$cosp" == "true" ]]
368then
369   CPP_KEY="$CPP_KEY CPP_COSP"
370   COSP_PATH="$LIBFGCM/cosp"
371#   LIB="${LIB} -l${LIBPREFIX}cosp"
372   opt_dep="$opt_dep cosp"
373   lcosp="-l${LIBPREFIX}cosp"
374   INCLUDE="$INCLUDE"' -I$(LIBF)/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/dimension
400./makdim $dim
401cat $LIBFGCM/grid/dimensions.h
402cd $LMDGCM
403
404
405########################################################################
406# Differentes dynamiques (3d, 2d, 1d)
407########################################################################
408
409dimension=`echo $dim | wc -w`
410echo dimension $dimension
411
412if (( $dimension == 3 ))
413then
414  cd $LIBFGCM/grid
415  \rm fxyprim.h
416  cp -p fxy_${grille}.h fxyprim.h
417else
418  echo "Probleme dans les dimensions de la dynamique !!"
419  echo "Non reactive pour l'instant !!!"
420fi
421
422######################################################################
423# Gestion du filtre qui n'existe qu'en 3d.
424######################################################################
425
426if (( `expr $dimc \> 2` == 1 ))
427then
428   filtre="FILTRE=$filtre"
429else
430   filtre="FILTRE= L_FILTRE= "
431fi
432echo MACRO FILTRE $filtre
433
434echo $dimc
435
436######################################################################
437# Creation du suffixe de la configuration
438######################################################################
439
440
441SUFF_NAME=_${dim_full}
442SUFF_NAME=${SUFF_NAME}_phy${physique}
443
444if [[ "$parallel" != "none" ]]
445then
446  SUFF_NAME=${SUFF_NAME}_para
447  DYN=dyn${dimc}d${paramem}
448  if [[ "$paramem" == "mem" ]]
449  then
450   SUFF_NAME=${SUFF_NAME}_${paramem}
451  fi
452else
453  SUFF_NAME=${SUFF_NAME}_seq
454  DYN=dyn${dimc}d
455fi
456
457if [[ $veget == "true" ]]
458then
459  SUFF_NAME=${SUFF_NAME}_orch
460fi
461
462if [[ $couple != "false" ]]
463then
464  SUFF_NAME=${SUFF_NAME}_couple
465fi
466
467if [[ $chimie == "INCA" ]]
468then
469  SUFF_NAME=${SUFF_NAME}_inca
470fi
471
472cd $LMDGCM
473
474
475########################################################################
476#  Avant de lancer le make, on recree le makefile si necessaire
477########################################################################
478########################################################################
479# c'est a dire dans 3 cas:
480# 1. si la liste des fichiers .F et .h a ete modifiee depuis la
481#    derniere creation du makefile
482# 2. si le fichier contenant cette liste "liste_des_sources"
483#    n'existe pas.
484# 3. Si le makefile n'existe pas.
485########################################################################
486cd $LMDGCM
487find libf -name '*.[Fh]' -print > tmp77
488find libf -name '*.[Fh]' -exec egrep -i " *use *ioipsl" {} \; -print > tmp90
489find libf -name '*.[Fh90]' -print >> tmp90
490
491if [[ ! ( -r makefile ) || ! ( -r liste_des_sources_f90 ) || ! ( -r liste_des_sources_f77 ) || ` diff tmp77 liste_des_sources_f77 | wc -w ` -ne 0 || ` diff tmp90 liste_des_sources_f90 | wc -w ` -ne 0 ]]
492then
493  echo "les fichiers suivants ont ete crees ou detruits"
494  echo "ou les fichiers suivants sont passes ou ne sont plus en Fortran 90"
495  diff liste_des_sources_f77 tmp77
496  diff liste_des_sources_f90 tmp90
497  \cp -f tmp77 liste_des_sources_f77
498  \cp -f tmp90 liste_des_sources_f90
499  echo "on recree le makefile"
500  ./create_make_gcm > tmp
501  \mv -f tmp makefile
502  echo "Nouveau makefile cree"
503fi
504
505#################################################################
506# Preparation de l'execution de la comande make
507#################################################################
508
509source_code=${code}.F
510if [[ -r $LMDGCM/libf/dyn${dimc}d${FLAG_PARA}/${code}.F90 ]]
511then
512  source_code=${code}.F90
513fi
514
515# library directory name:
516if [[ "$parallel" == "none" ]]
517then 
518  nomlib=${arch}_${physique}_${dim_full}_${grille}_${compil_mod}
519else
520  nomlib=${arch}_${physique}_${dim_full}_${grille}_${compil_mod}_${FLAG_PARA}
521fi
522
523if [[ ! -d "${LIBOGCM}/${nomlib}" ]]
524then
525  mkdir ${LIBOGCM}/${nomlib}
526  # check we indeed managed to create the directory
527  if [[ ! $? ]]
528  then
529    echo "Error: could not create directory ${LIBOGCM}/${nomlib}"
530    exit
531  fi
532fi
533
534# where module files are created
535mod_loc_dir=$localdir
536
537if [[ "$physique" != "nophys" ]]
538then
539  INCLUDE="$INCLUDE"' -I$(LIBF)/phy'"$physique"
540fi
541INCLUDE="$INCLUDE"' -I$(LIBF)/dyn'${dimc}'d'$FLAG_PARA' -I'${LIBOGCM}/${nomlib}
542
543# ranlib utility (check it exists or else default to ls)
544if [[ `which ranlib > /dev/null 2>&1 ; echo $?` -eq 0 ]]
545then
546  ranlib="ranlib"
547else
548  ranlib="ls"
549fi
550
551# add CPP keys to COMPIL_FLAGS
552# (but first add -D before all CPP_KEY items)
553cpp_definitions=`echo $CPP_KEY | sed -e 's/[A-Za-z_=0-9]*/-D&/g'`
554# (but add a -WF,-D before all CPP_KEY items) => for xlf on Vargas
555if [[ "${fcompiler:0:3}" == "xlf" ]]
556then
557cpp_definitions=`echo $CPP_KEY | sed -e 's/[A-Za-z_=0-9]*/-WF,-D&/g'`
558fi
559COMPIL_FFLAGS="${COMPIL_FFLAGS} ${cpp_definitions}"
560
561#################################################################
562# Execution du make
563#################################################################
564echo $makecommand RANLIB=$ranlib -f $LMDGCM/makefile \
565OPTION_DEP="$opt_dep" OPTION_LINK="$LIB ${PARA_LD}" \
566OPTIM90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
567OPTIMTRU90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
568OPTIM="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
569INCLUDE="$INCLUDE" \
570$filtre \
571LIBO=${LIBOGCM}/${nomlib} \
572"PHYS=$physique" \
573DIM=$dimc \
574FLAG_PARA=$FLAG_PARA \
575L_ADJNT=$adjnt \
576L_COSP="$lcosp" \
577L_CHIMIE="$libchimie" \
578LOCAL_DIR="$localdir"  \
579F77="$fcompiler" \
580F90="$fcompiler" \
581OPLINK="$LIB" \
582LINK="$linker" \
583GCM="$LMDGCM" \
584MOD_LOC_DIR=$mod_loc_dir \
585MOD_SUFFIX="mod" \
586AR=$arcommand \
587SOURCE=$source_code \
588PROG=$code
589
590$makecommand RANLIB=$ranlib -f $LMDGCM/makefile \
591OPTION_DEP="$opt_dep" OPTION_LINK="$LIB ${PARA_LD}" \
592OPTIM90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
593OPTIMTRU90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
594OPTIM="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
595INCLUDE="$INCLUDE" \
596$filtre \
597LIBO=${LIBOGCM}/${nomlib} \
598"PHYS=$physique" \
599DIM=$dimc \
600FLAG_PARA=$FLAG_PARA \
601L_ADJNT="$adjnt" \
602L_COSP="$lcosp" \
603L_CHIMIE="$libchimie" \
604LOCAL_DIR="$localdir"  \
605F77="$fcompiler" \
606F90="$fcompiler" \
607OPLINK="$LIB" \
608LINK="$linker" \
609GCM="$LMDGCM" \
610MOD_LOC_DIR=$mod_loc_dir \
611MOD_SUFFIX="mod" \
612AR=$arcommand \
613SOURCE=$source_code \
614PROG=$code
615
616if [[ -r $libf/grid/dimensions.h ]]
617then
618  # Cleanup: remove dimension.h file
619  \rm -f $libf/grid/dimensions.h
620fi
Note: See TracBrowser for help on using the repository browser.