source: BOL/script_install/install.sh @ 2031

Last change on this file since 2031 was 2031, checked in by fhourdin, 10 years ago

Simplification

File size: 19.0 KB
Line 
1#!/bin/bash
2
3###########################################################################
4# Author : Frédéric Hourdin/LMD/hourdin@lmd.jussieu.fr
5# Usage  : install.sh
6#
7# bash installation script of the LMDZ model on a Linux PC.
8# the model is downloaded in the following direcory tree
9# $MODEL/modipsl/modeles/...
10# using the "modipsl" infrastructure created by the "IPSL"
11# for coupled (atmosphere/ocean/vegetation/chemistry) climate modeling
12# activities.
13# Here we only download atmospheric (LMDZ) and vegetation (ORCHIDEE)
14# components.
15#
16# The sources of the models can be found in the "modeles" directory.
17# In the present case, LMDZ5, ORCHIDEE and IOIPSL (handling of input-outputs
18# using the NetCDF library.
19#
20# The script downloads various source files (including a version of NetCDF)
21# and utilities, compiles the model, and runs a test simulation in a
22# munimal configuration.
23#
24# Prerequisites : g95/pgf90/gfortran, ksh, wget , gunzip, tar, ...
25#
26# Modif 18/11/2011
27#    changes for option real 8.
28#      We comopile with -r8 (or equivalent) and -DNC_DOUBLE for the GCM
29#      but with -r4 for netcdf. Variable real must be set to
30#      r4 or r8 at the beginning of the script below.
31#
32###########################################################################
33
34echo install.sh DEBUT `date`
35
36set -e
37
38echo '################################################################'
39echo  Choice of installation options
40echo '################################################################'
41
42
43#real=r4
44real=r8
45
46# WARNING !!!! For versions before october 2009, use
47# install.v2.sh instead of install.sh
48
49version=20130716.trunk
50version=testing
51compilo=gfortran # compilo=pgf90 or g95 or gfortran or ifort sur PC linux
52
53#Chemin pour placer le modele
54MODEL=./LMDZ$version
55
56
57getlmdzor=1
58netcdf=1   #  1 for automatic installation
59           #  0 for no installation
60           #  /.../../netcdf-4.0.1 if wanting to link with an already
61           #  compiled netcdf library (implies to check option compatibility)
62check_linux=1
63ioipsl=1
64veget=1
65bench=1
66pclinux=1
67
68# choose the resolution for the bench runs
69# grid_resolution= 32x24x11 or 48x36x19 for tests (test without ORCHIDEE)
70#                  96x71x19  standard configuration
71grid_resolution=48x36x19
72
73## compile_with_fcm=1 : use makelmdz_fcm, possible a of version 20111103.trunk (LMDZ5/trunk rev 1578)
74## compile_with_fcm=0 : use makelmdz
75compile_with_fcm=0
76
77
78#####################################################################
79# Test for old gfortran compilers
80# If the compiler is too old (older than 4.3.x) we test if the
81# temporary gfortran44 patch is available on the computer in which
82# case the compiler is changed from gfortran to gfortran44
83# Must be aware than parallelism can not be activated in this case
84#####################################################################
85
86if [ $compilo = gfortran ] ; then
87   gfortran=gfortran
88   gfortranv=`gfortran --version | \
89   head -1 | awk ' { print $NF } ' | awk -F. ' { print $1 * 10 + $2 } '`
90   if [ $gfortranv -le 43 ] ; then
91       echo ERROR : Your gfortran compiler is too old
92       echo 'Please choose a new one (g95, ifort) and change the line'
93       echo compilo=xxx
94       echo in the install.sh script and rerun it
95       if [ `which gfortran44 | wc -w` -ne 0 ] ; then
96          gfortran=gfortran44
97       else
98          echo gfotran trop vieux ; exit
99       fi
100   fi
101   compilo=$gfortran
102fi
103#####################################################################
104
105
106
107OPTPREC=""
108echo '################################################################'
109echo  Choix des options de compilation
110echo '################################################################'
111
112OPTIMNC=$OPTIM
113export FC=$compilo
114export F90=$compilo
115export F77=$compilo
116export CPPFLAGS=
117BASE_LD=
118if [ $compilo = g95 ] ; then
119# Set the appropriate compilation options
120   OPTIM='-i4 -O3'
121   OPTDEB="-g -O0 -Wall -ftrace=full -fbounds-check -freal=nan"
122   OPTDEV="-g -O1 -Wall"
123   fmod='fmod='
124   BASE_LD=""
125   if [ $real = r8 ] ; then OPTPREC="-r8 -DNC_DOUBLE" ; fi
126   export F90FLAGS=" -cpp -ffree-form $OPTIMNC"
127   export FFLAGS=" -cpp $OPTIMNC"
128   export CPPFLAGS=-Df2cFortran
129   export CC=gcc
130   export CXX=g++
131elif [ $compilo = $gfortran ] ; then
132   OPTIM='-O3'
133   OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all"
134   OPTDEV="-Wall -fbounds-check"
135   fmod='I '
136   if [ $real = r8 ] ; then OPTPREC="-fdefault-real-8 -DNC_DOUBLE" ; fi
137   export F90FLAGS=" -ffree-form $OPTIMNC"
138   export FFLAGS=" $OPTIMNC"
139   export CC=gcc
140   export CXX=g++
141elif [ $compilo = mpif90 ] ; then
142   OPTIM='-O3'
143   OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all"
144   OPTDEV="-Wall -fbounds-check"
145   BASE_LD="-lblas"
146   fmod='I '
147   if [ $real = r8 ] ; then OPTPREC="-fdefault-real-8 -DNC_DOUBLE -fcray-pointer" ; fi
148   export F90FLAGS=" -ffree-form $OPTIMNC"
149   export FFLAGS=" $OPTIMNC"
150   export CC=gcc
151   export CXX=g++
152elif [ $compilo = pgf90 ] ; then
153   OPTIM='-O2 -Munroll -Mnoframe -Mautoinline -Mcache_align'
154   fmod='module '
155   if [ $real = r8 ] ; then OPTPREC="-r8 -DNC_DOUBLE" ; fi
156   export CPPFLAGS="-DNDEBUG -DpgiFortran"
157   export CC=pgcc
158   export CFLAGS="-Msignextend"
159   export CXX=pgCC
160   export CXXFLAGS="-Msignextend"
161   export FFLAGS="$OPTIMNC"
162   export F90FLAGS="$OPTIMNC"
163   compile_with_fcm=1
164elif [ $compilo = ifort ] ; then
165   OPTIM="-O2 -fp-model strict -ip -align all "
166   OPTDEV="-p -g -O2 -traceback -fp-stack-check -ftrapuv -check"
167   OPTDEB="-g -no-ftz -traceback -ftrapuv -fp-stack-check -check"
168   fmod='module '
169   if [ $real = r8 ] ; then OPTPREC="-real-size 64 -DNC_DOUBLE" ; fi
170   export CPP="icc -E"
171   export FFLAGS="-O2 -ip -fpic -mcmodel=large"
172   export FCFLAGS="-O2 -ip -fpic -mcmodel=large"
173   export CC=icc
174   export CFLAGS="-O2 -ip -fpic -mcmodel=large"
175   export CXX=icpc
176   export CXXFLAGS="-O2 -ip -fpic -mcmodel=large"
177   compile_with_fcm=1
178else
179   echo unexpected compiler $compilo ; exit
180fi
181
182OPTIMGCM="$OPTIM $OPTPREC"
183
184hostname=`hostname`
185
186##########################################################################
187# If installing on know machines such as IBM x3750 (Ada)
188# at IDRIS, don't check for available software and don"t install netcdf
189if [ ${hostname:0:5} = ada33 ] ; then
190  netcdf=0 # no need to recompile netcdf, alreday available
191  check_linux=0
192  pclinux=0
193  ioipsl=0 # no need to recompile ioipsl, already available
194  #netcdf="/smplocal/pub/NetCDF/4.1.3"
195  compilo="ifort"
196  fmod='module '
197  if [ $real = r8 ] ; then OPTPREC="-real-size 64 -DNC_DOUBLE" ; fi
198  OPTIM="-O2 -fp-model strict -ip -axAVX,SSE4.2 -align all "
199  OPTIMGCM="$OPTIM $OPTPREC"
200fi
201##########################################################################
202
203
204mkdir -p $MODEL
205echo $MODEL
206MODEL=`( cd $MODEL ; pwd )` # to get absolute path, if necessary
207
208
209
210# Option -fendian=big is only to be used with ARPEGE1D.
211# The -r8 should probably be avoided if running on 32 bit machines
212# Option r8 is not mandatory and generates larger executables.
213# It is however mandatory if using ARPEGE1D
214# Better optimization options might be a better choice (e.g. -O3)
215
216
217echo '################################################################'
218if [ "$check_linux" = 1 ] ; then
219echo   Check if required software is available
220echo '################################################################'
221
222#### Ehouarn: test if ksh and/or bash are available
223use_shell="ksh" # default: use ksh
224if [ "`which ksh`" = "" ] ; then
225  echo "no ksh ... we will use bash"
226  use_shell="bash"
227  if [ "`which bash`" = "" ] ; then
228    echo "ksh (or bash) needed!! Install it!"
229  fi
230fi
231
232
233for logiciel in csh wget tar gzip make $compilo gcc ; do
234if [ "`which $logiciel`" = "" ] ; then
235echo You must first install $logiciel on your system
236exit
237fi
238done
239
240if [ $pclinux = 1 ] ; then
241cd $MODEL
242cat <<eod > tt.f90
243print*,'coucou'
244end
245eod
246$compilo tt.f90 -o a.out
247./a.out >| tt
248if [ "`cat tt | sed -e 's/ //g' `" != "coucou" ] ; then
249echo problem installing with compiler $compilo ; exit ; fi
250\rm tt a.out tt.f90
251fi
252fi
253
254###########################################################################
255if [ $getlmdzor = 1 ] ; then
256echo '##########################################################'
257echo  Download a slightly modified version of  LMDZ
258echo '##########################################################'
259cd $MODEL
260wget http://www.lmd.jussieu.fr/~lmdz/DistribG95/modipsl.$version.tar.gz
261echo install.sh wget_OK `date`
262gunzip modipsl.$version.tar.gz
263tar xvf modipsl.$version.tar
264\rm modipsl.$version.tar
265
266# We download LMDZ and make some modifications to make it
267#compatible with $compilo
268# and we use an old stable but robust and well tested version of ORCHIDEE
269# That version of ORCHIDEE can be obtained using
270# wget http://www.lmd.jussieu.fr/~lmdz/DistribG95/getlmdzor.x
271fi
272
273echo OK1
274
275if [ $netcdf = 1 ] ; then
276echo '##########################################################'
277echo Compiling the Netcdf library
278echo '##########################################################'
279cd $MODEL
280wget http://www.lmd.jussieu.fr/~lmdz/DistribG95/netcdf-4.0.1.tar.gz
281gunzip netcdf-4.0.1.tar.gz
282tar xvf netcdf-4.0.1.tar
283\rm -f netcdf-4.0.1.tar
284
285cd netcdf-4.0.1
286
287sed -e 's/gfortran/'$gfortran'/g' configure >| tmp ; mv -f tmp configure ; chmod +x configure
288localdir=`pwd -P`
289./configure --prefix=$localdir
290sed -e 's/gfortran/'$gfortran'/g' Makefile >| tmp ; mv -f tmp Makefile
291make check
292make install
293echo install.sh netcdf_OK `date`
294fi # of if [ $netcdf = 1 ]
295
296
297#=======================================================================================
298echo OK2 ioipsl=$ioipsl
299echo '##########################################################'
300echo 'Installing MODIPSL, the installation package manager for the '
301echo 'IPSL models and tools'
302echo '##########################################################'
303
304if [ $netcdf = 0 -o $netcdf = 1 ] ; then
305ncdfdir=$MODEL/netcdf-4.0.1
306else
307ncdfdir=$netcdf
308fi
309
310if [ $ioipsl = 1 ] ; then
311  cd $MODEL/modipsl
312  \rm -rf lib/*
313
314  cd util
315
316  cp AA_make.gdef AA_make.orig
317  F_C="$compilo -c " ; if [ "$compilo" = "$gfortran" -o "$compilo" = "mpif90" ] ; then F_C="$compilo -c -cpp " ; fi
318  sed -e 's/^\#.*.g95.*.\#.*.$/\#/' AA_make.gdef > tmp
319  sed -e "s:F_L = g95:F_L = $compilo:" -e "s:F_C = g95 -c:F_C = $F_C": \
320  -e 's/g95.*.w_w.*.(F_D)/g95      w_w = '"$OPTIMGCM"'/' \
321  -e 's:g95.*.NCDF_INC.*.$:g95      NCDF_INC= '"$ncdfdir"'/include:' \
322  -e 's:g95.*.NCDF_LIB.*.$:g95      NCDF_LIB= -L'"$ncdfdir"'/lib -lnetcdf:' \
323  -e "s:-fmod=:-$fmod:" -e 's/-fno-second-underscore//' \
324  -e 's:#-Q- g95      M_K = gmake:#-Q- g95      M_K = make:' \
325  tmp >| AA_make.gdef
326
327
328  if [ "$use_shell" = "ksh" ] ; then
329    if [ "$pclinux" = 1 ] ; then
330       ./ins_make -t g95 # We use lines for g95 even for the other compilers
331    fi
332  else # bash
333    sed -e s:/bin/ksh:/bin/bash:g ins_make > ins_make.bash
334    chmod u=rwx ins_make.bash
335    if [ "$pclinux" = 1 ] ; then
336    ./ins_make.bash -t g95 # We use lines for g95 even for the other compilers
337    else
338    ./ins_make.bash
339    fi
340  fi # of if [ "$use_shell" = "ksh" ]
341
342#=======================================================================================
343  echo '##########################################################'
344  echo 'Compiling IOIPSL, the interface library with Netcdf'
345  echo '##########################################################'
346
347  cd $MODEL/modipsl/modeles/IOIPSL/src
348  if [ "$use_shell" = "bash" ] ; then
349    cp Makefile Makefile.ksh
350    sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
351  fi
352  if [ "$pclinux" = 1 ] ; then
353    # Build IOIPSL modules and library
354    if [ $compilo = g95 ] ; then
355       cp restcom.f90 restcom.f90.orig
356       sed -e 's:cmode=or(NF90_NOCLOBBER,NF90_64BIT_OFFSET):cmode=NF90_NOCLOBBER:' restcom.f90.orig > restcom.f90 
357    fi
358    make clean
359    make
360    if [ "$compilo" = "$gfortran" -o "$compilo" = "mpif90" ] ; then # copy module files to lib
361      cp -f *.mod ../../../lib
362    fi
363    # Build IOIPSL tools (ie: "rebuild", if present)
364    if [ -f $MODEL/modipsl/modeles/IOIPSL/tools/rebuild ] ; then
365      cd $MODEL/modipsl/modeles/IOIPSL/tools
366      # adapt Makefile & rebuild script if in bash
367      if [ "$use_shell" = "bash" ] ; then
368        cp Makefile Makefile.ksh
369        sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
370        cp rebuild rebuild.ksh
371        sed -e 's:/bin/ksh:/bin/bash:g' \
372            -e 's:print -u2:echo:g' \
373            -e 's:print:echo:g' rebuild.ksh > rebuild
374      fi
375      make clean
376      make
377    fi
378  fi # of if [ "$pclinux" = 1 ]
379
380else # of if [ $ioipsl = 1 ]
381  if [ ${hostname:0:5} = ada33 ] ; then
382    cd $MODEL/modipsl
383    cd util
384
385    cp AA_make.gdef AA_make.orig
386    sed -e 's/^\#.*.g95.*.\#.*.$/\#/' AA_make.gdef > tmp
387    sed -e "s:F_L = g95:F_L = $compilo:" -e "s:F_C = g95 -c:F_C = $compilo -c": \
388    -e 's/g95.*.w_w.*.(F_D)/g95      w_w = '"$OPTIMGCM"'/' \
389    -e 's:g95.*.NCDF_INC.*.$:g95      NCDF_INC= -I/smplocal/pub/HDF5/1.8.9/seq/include -I/smplocal/pub/NetCDF/4.1.3/include:' \
390    -e 's:g95.*.NCDF_LIB.*.$:g95      NCDF_LIB= -L/smplocal/pub/NetCDF/4.1.3/lib -lnetcdff -lnetcdf:' \
391    -e "s:-fmod=:-$fmod:" -e 's/-fno-second-underscore//' \
392    -e 's:#-Q- g95      M_K = gmake:#-Q- g95      M_K = make:' \
393    tmp >| AA_make.gdef
394
395    ./ins_make -t g95 # We use lines for g95 even for the other compilers
396
397    # on Ada, IOIPSL is already installed in ~rpsl035/IOIPSL_PLUS
398    # so link it to current settings
399    cd $MODEL/modipsl/modeles/
400    \rm -r -f IOIPSL
401    ln -s ~rpsl035/IOIPSL_PLUS IOIPSL
402    cd ..
403    ln -s ~rpsl035/IOIPSL_PLUS/modipsl/bin/* bin/
404    ln -s ~rpsl035/IOIPSL_PLUS/modipsl/lib/* lib/
405
406  fi # of if [ ${hostname:0:5} = ada33 ]
407  echo install.sh ioipsl_OK `date`
408fi # of if [ $ioipsl = 1 ]
409
410
411#============================================================================
412veget_version=false
413if [ "$veget" = 1 ] ; then
414  echo '########################################################'
415  echo 'Compiling ORCHIDEE, the continental surfaces model '
416  echo '########################################################'
417  cd $MODEL/modipsl/modeles/ORCHIDEE
418  echo OKpwd ; pwd
419  if [ -d src_parallel ] ; then
420     liste_src="parallel parameters global stomate sechiba driver"
421     veget_version=orchidee2.0
422  else
423     # Obsolete, for ORCHIDEE_beton only
424     liste_src="parameters stomate sechiba "
425     # A trick to compile ORCHIDEE depending on if we are using real*4 or real*8
426     cd src_parameters ; \cp reqdprec.$real reqdprec.f90 ; cd ..
427     veget_version=orchidee1.9
428  fi
429  echo liste_strc $liste_src
430
431  for d in $liste_src ; do src_d=src_$d
432      echo src_d $src_d
433      echo ls ; ls
434      if [ ! -d $src_d ] ; then echo Problem orchidee : no $src_d ; exit ; fi
435      cd $src_d ; \rm -f *.mod make ; make clean
436      make ; if [ "$compilo" = "$gfortran" -o "$compilo" = "mpif90" ] ; then cp -f *.mod ../../../lib ; fi
437      cd ..
438  done
439  echo install.sh orchidee_OK `date`
440fi # of if [ "$veget" = 1 ]
441
442
443#============================================================================
444# Ehouarn: it may be directory LMDZ4 or LMDZ5 depending on tar file...
445if [ -d $MODEL/modipsl/modeles/LMDZ[45] ] ; then
446  echo '##########################################################'
447  echo 'Compiling LMDZ'
448  echo '##########################################################'
449  cd $MODEL/modipsl/modeles/LMDZ[45]
450else
451  echo "ERROR: No LMDZ4 (or LMDZ5) directory !!!"
452  exit
453fi
454
455###########################################################
456# For those who want to use fcm to compile via :
457#  makelmdz_fcm -arch local .....
458############################################################
459
460if [ "$pclinux" = "1" ] ; then
461
462# create local 'arch' files (if on Linux PC):
463cd arch
464# arch-local.path file
465echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib -lnetcdf\"" > arch-local.path
466echo OK3
467echo "NETCDF_INCDIR=-I${ncdfdir}/include" >> arch-local.path
468echo 'IOIPSL_INCDIR=$LMDGCM/../../lib' >> arch-local.path
469echo 'IOIPSL_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
470echo 'ORCH_INCDIR=$LMDGCM/../../lib' >> arch-local.path
471echo 'ORCH_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
472# arch-local.fcm file (adapted from arch-linux-32bit.fcm)
473
474if [ $real = r8 ] ; then FPP_DEF=NC_DOUBLE ; else FPP_DEF="" ; fi
475sed -e s:"%COMPILER        .*.$":"%COMPILER            $compilo":1 \
476    -e s:"%LINK            .*.$":"%LINK                $compilo":1 \
477    -e s:"%PROD_FFLAGS     .*.$":"%PROD_FFLAGS         $OPTIM":1 \
478    -e s:"%DEV_FFLAGS      .*.$":"%DEV_FFLAGS          $OPTDEV":1 \
479    -e s:"%DEBUG_FFLAGS    .*.$":"%DEBUG_FFLAGS        $OPTDEB":1 \
480    -e s:"%BASE_FFLAGS     .*.$":"%BASE_FFLAGS         $OPTPREC":1 \
481    arch-linux-32bit.fcm > arch-local.fcm
482
483cd ..
484### Adapt "bld.cfg" (add the shell):
485whereisthatshell=$(which ${use_shell})
486echo "bld::tool::SHELL   $whereisthatshell" >> bld.cfg
487
488fi # of if [ "$pclinux" = 1 ]
489
490
491cd $MODEL/modipsl/modeles/LMDZ?
492
493##################################################################
494# Compile LMDZ
495##################################################################
496echo install.sh avant_compilation `date`
497if [ $compile_with_fcm = 1 ] ; then makelmdz=makelmdz_fcm ; else makelmdz=makelmdz ; fi
498
499./$makelmdz -d ${grid_resolution} -v $veget_version gcm
500echo install.sh apres_compilation `date`
501
502
503if [ -f gcm.e ] || [ -f bin/gcm_${grid_resolution}_phylmd_seq_orch.e ] || [ -f bin/gcm_${grid_resolution}_phylmd_seq.e ] ; then
504echo '##########################################################'
505echo 'Compilation successfull !! '
506echo '##########################################################'
507else
508echo 'Compilation failed !!'
509exit
510fi
511
512##################################################################
513# Below, we run a benchmark test (if bench=0)
514##################################################################
515if [ $bench = 0 ] ; then
516                exit
517fi
518
519echo '##########################################################'
520echo ' Running a test run '
521echo '##########################################################'
522
523\rm -rf BENCH${grid_resolution}
524bench=bench_lmdz_${grid_resolution}
525echo install.sh avant_chargement_bench  `date`
526wget http://www.lmd.jussieu.fr/~lmdz/DistribG95/$bench.tar.gz
527echo install.sh apres_chargement_bench  `date`
528gunzip $bench.tar.gz
529tar xvf $bench.tar
530
531if [ -f gcm.e ] ; then 
532    cp gcm.e BENCH${grid_resolution}/
533elif [ -f bin/gcm_${grid_resolution}_phylmd_seq_orch.e ] ; then
534    cp bin/gcm_${grid_resolution}_phylmd_seq_orch.e  BENCH${grid_resolution}/gcm.e
535elif [ -f bin/gcm_${grid_resolution}_phylmd_seq.e ] ; then
536    cp bin/gcm_${grid_resolution}_phylmd_seq.e  BENCH${grid_resolution}/gcm.e
537else
538    echo "No gcm.e found"
539    exit
540fi
541
542
543cd BENCH${grid_resolution}
544./bench.sh > bench.out  2>&1
545
546
547echo '##########################################################'
548echo ' Bench results '
549echo '##########################################################'
550
551cat ./bench.out
552echo install.sh FIN_du_BENCH  `date`
553
554echo '##########################################################'
555echo 'Simulation finished in' `pwd`
556echo 'You may re-run it with : cd ' `pwd` ' ; gcm.e'
557echo 'or ./bench.sh'
558echo '##########################################################'
559
560if [ "$gfortran" = "gfortran44" ] ; then
561    echo Your gfortran compiler was too old so that the model was automatically
562    echo compiled with gfortran44 instead. It can not be used in parallel mode.
563    echo You can change the compiler at the begining of the install.sh
564    echo script and reinstall.
565fi
Note: See TracBrowser for help on using the repository browser.