source: LMDZ5/trunk/makelmdz @ 1492

Last change on this file since 1492 was 1492, checked in by Laurent Fairhead, 13 years ago

Merge of development branch LMDZ5V2.0-dev r1455:r1491 into the trunk.
Validation made locally: restart files are strictly equal between the HEAD of the trunk
and r1491 of LMDZ5V2.0-dev


Synchro de la branche de développement LMDZ5V2.0-dev r1455:r1491 et de la trunk
Validation faite en local: les fichiers restart sont équivalents entre la HEAD de la trunk
et la révision r1491 de LMDZ5V2.0-dev

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