source: CONFIG/UNIFORM/v6/LMDZOR_v6.2/compile_lmdzor.sh

Last change on this file was 6787, checked in by jgipsl, 3 weeks ago

Add option to compress XIOS and LMDZ/libo in tar files after compilation. By default compression is done but can be deactivated with option -notar.
See -h for more information. Done by Karine Laurent

  • Property svn:executable set to *
File size: 18.2 KB
Line 
1#!/bin/bash
2#set -vx
3# Default options
4#
5#
6#
7date
8#### 1  Set up the compiling options
9#### Define some directories
10submitdir=$( pwd )
11modipsl=$submitdir/../..
12arch_path=$submitdir/ARCH
13
14#### Set default options
15# Optimization mode
16# optmode=prod/dev/debug
17optmode=prod
18# Resolution of LMDZ in regular mode
19resol_atm=144x142x79
20# Also compile ce0l subprogram to LMDZ (y/n)
21ce0l=y
22
23# fcm_arch
24fcm_arch=default
25# Default values to be overritten
26parallel=mpi_omp
27# Compilation with rrtm or ecrad radiative code (default rad=rrtm)
28rad=rrtm
29opt_rad=""
30# Compilation with Cosp (cosp=NONE/v1/v2 ; default=NONE)
31cosp=NONE
32
33# Compilation with flag StratAer (option -strataer)
34opt_strataer=""
35
36export fcm_arch parallel xios
37full_flag=""
38full_xios=""
39full_lmdz=""
40full_orch=""
41
42# Default netcdf_lib is used for XIOS but can be change by argument
43netcdf_lib=""
44
45## Arguments in order to compress temporary files after compilation
46tar=no
47comp_tar=yes
48
49# Output text file for compilation of each component
50datestr=`LC_ALL=C date +"%Y%m%dT%H%M"`
51outfile=$submitdir/out_compile_lmdzor.$datestr
52echo > $outfile
53echo; echo "Text output from compilation will be stored in file out_compile_lmdzor.$datestr"; echo 
54
55#### Read arguments
56# Loop over all arguments to modify default set up
57while (($# > 0)) ; do
58    case $1 in
59        "-h") cat <<end_help
60########################################################################
61# Usage of the script compile_lmdzor.sh
62#
63########################################################################
64
65./compile_config [Options]
66
67Options:
68  [-full]: full recompilation of all components
69  [-debug], [-dev], [-prod](default): use compilation options for debug, dev or production mode, only one option can be used
70  [-resol_atm]: set resolution of LMDZ in regular mode
71  [-tar]: option to compress XIOS and/or LMDZ/libo repositories that takes many inodes without compilation
72  [-comp_tar]: option to compile and compress XIOS and LMDZ/libo repositories if compilation succed (default option)
73  [-notar]: do not compress XIOS and LMDZ/libo repositories
74
75Example 1: Default compilation of LMDZ-ORCHIDEE with XIOS and IOIPSL
76./compile_lmdzor.sh
77
78Example 2: Compile in debug mode
79./compile_lmdzor.sh -debug
80
81Example 3: Default compilation with full recompilation of all components
82./compile_lmdzor.sh -full
83
84Example 4: Compilation of LMDZ in regular lat-lon for other dimensions (default: 144x142x79)
85The dimension can be changed to any other 3d dimension.
86./compile_lmdzor.sh -resol_atm 96x95x79
87
88Example 5: Compile without compressing XIOS and LMDZ/libo in tar files
89./compile_lmdzor.sh -notar
90
91end_help
92exit;;
93        "-parallel")        parallel=$2 ; shift ; shift ;;
94        "-rad")             rad=$2 ; shift ; shift ;;
95        "-cosp")            cosp=$2 ; shift ; shift ;;
96        "-strataer")        opt_strataer="-strataer true" ; shift ; shift ;;
97        "-arch")            fcm_arch="$2" ; shift ; shift ;;
98        "-xios")            xios="$2" ; shift ; shift ;;
99        "-debug")           optmode=debug ; shift ;;
100        "-dev")             optmode=dev ; shift ;;
101        "-prod")            optmode=prod ; shift ;;
102        "-resol_atm")       resol_atm=$2 ; shift ; shift ;;
103        "CE0L")             ce0l=y ; shift ;;
104        "-full")            full_flag="-full"; full_xios="--full" ; full_lmdz="-full" ; full_orch="-full" ; shift ;;
105        "-full_xios")       full_xios="--full" ; shift ;;  # Note only full_xios is using double dash: --full
106        "-full_lmdz")       full_lmdz="-full"  ; shift ;;
107        "-full_orch")       full_orch="-full"  ; shift ;;
108        "-netcdf_lib_seq")  netcdf_lib="--netcdf_lib netcdf4_seq"; shift ;;
109        "-tar")             tar=yes ; shift ;;
110        "-comp_tar")        comp_tar=yes ; shift ;;
111        "-notar")           comp_tar=no ; shift ;;
112        *)                  echo "unknown option "$1" , exiting..." ; exit
113    esac
114done
115
116echo "Following options are set in current compiling:" >> $outfile 
117echo "   resol_atm=${resol_atm}" >> $outfile 
118echo "   ce0l=${ce0l}" >> $outfile 
119echo "   optmode = $optmode, parallel = $parallel, fcm_arch = $fcm_arch " >> $outfile 
120echo "   full_flag=$full_flag, full_xios=$full_xios, full_lmdz=$full_lmdz, full_orch=$full_orch" >> $outfile 
121echo "   tar=$tar, comp_tar=$comp_tar" >> $outfile
122echo >> $outfile
123
124if [ $cosp = v1 ] ; then
125    opt_cosp="-cosp true"
126elif [ $cosp = v2 ] ; then
127    opt_cosp="-cospv2 true"
128else
129    opt_cosp=""
130fi
131
132
133# Compress XIOS and LMDZ/libo without compiling if tar=yes
134if [ $tar == yes ] ; then
135    echo "Option tar activated to compress XIOS and LMDZ/libo. No compilation will be done."
136    echo >> $outfile
137    echo "Option tar activated to compress XIOS and LMDZ/libo. No compilation will be done." >> $outfile
138    if [[ -d $modipsl/modeles/XIOS ]] ; then
139        echo " Now tar XIOS repository"
140        echo " Now tar XIOS repository" >> $outfile
141        tar -cf $modipsl/modeles/XIOS.tar $modipsl/modeles/XIOS
142        rm -rf $modipsl/modeles/XIOS
143    else
144        echo " No XIOS repository to compress"
145        echo " No XIOS repository to compress" >> $outfile
146    fi
147
148    if [[ -d $modipsl/modeles/LMDZ/libo ]] ; then
149        echo "Now tar LMDZ/libo repository"
150        echo "Now tar LMDZ/libo repository" >> $outfile
151        tar -cf $modipsl/modeles/LMDZ/libo.tar $modipsl/modeles/LMDZ/libo
152        rm -rf $modipsl/modeles/LMDZ/libo
153    else
154        echo " No LMDZ/libo repository to compress"
155        echo " No LMDZ/libo repository to compress" >> $outfile
156    fi
157       
158    echo "END OF SCRIPT"
159    echo "END OF SCRIPT" >> $outfile
160    exit
161fi
162
163### Read host dependent default values
164### These variables will not be changed if they were set as argument
165###./host.sh $host
166# Later : Following lines should be set in host.sh file
167# begin host.sh
168if [ $fcm_arch == default ] ; then
169    # Find out current host and source specific paths and commands for the host
170    case $( hostname -s ) in
171        jean-zay*)
172            if [[ $( hostname -s ) != *"pp"* ]] ; then
173                echo "Warning! You MUST compile on jean-zay-pp."
174                echo "EXIT"
175                exit
176            else
177                fcm_arch=X64_JEANZAY
178            fi ;;
179        irene170|irene171|irene190|irene191|irene192|irene193)
180            fcm_arch=X64_IRENE;;
181        irene172|irene173|irene194|irene195)
182            fcm_arch=X64_IRENE-AMD;;
183        asterix*|obelix*)
184            fcm_arch=ifort_LSCE
185            if [ "${parallel}" == "mpi_omp" ] ; then
186                echo "Warning!! Currently at Obelix hybrid mode is not possible."
187                echo "          Option -parallel mpi_omp is now changed to -parallel mpi"
188                echo ""
189                parallel=mpi
190            else
191                echo "You used -parallel" $parallel
192            fi ;;
193        spirit*)
194            fcm_arch=ifort_MESOIPSL;;
195        ciclad*|climserv*|loholt*|camelot*)
196            fcm_arch=ifort_CICLAD;;
197        *)
198            echo Current host is not known. You must use option -arch to specify which architecuture files to use.
199            echo Exit now.
200            exit
201    esac
202fi
203
204# Set a link to arch.env if arch-${fcm_arch}.env file exist for current fcm_arch.
205# The link arch.env is also set in config.card and will be used by libIGCM to ensure the same running environnement.
206if [ -f ARCH/arch-${fcm_arch}.env ] ; then
207    echo >> $outfile
208    echo "The file ARCH/arch-${fcm_arch}.env will now be sourced with modules needed for compilation for all components."
209    echo "Note that this new environement might be kept after compilation." 
210    echo "If this is the case, source again your personal environment after compilation. "
211    echo " Personal module list before sourcing of ARCH/arch.env file:"    >> $outfile 
212    module list   >> $outfile 2>&1
213    # Get initial svn version
214    svn_version=$(module list -t | grep subversion)
215   
216    # Make a link to this file, to be used also in config.card
217    rm -f ARCH/arch.env
218    ln -s arch-${fcm_arch}.env ARCH/arch.env
219
220    # Source the file
221    source ARCH/arch.env   >> $outfile 2>&1
222    if [ X$svn_version != X ] ; then
223        # Put back initial version of svn
224        module load ${svn_version}
225    fi
226
227    echo >> $outfile 
228    echo " New module list after sourcing of ARCH/arch.env file:"    >> $outfile 
229    module list   >> $outfile 2>&1
230fi
231
232
233#### 2 Do the compilation
234## 2.1 Compile ioipsl
235cd $modipsl/modeles/IOIPSL
236echo; echo "NOW COMPILE IOIPSL"
237echo >> $outfile ; echo " NOW COMPILE IOIPSL"   >> $outfile 
238
239# Check if compilation with fcm is included in IOIPSL
240if [ ! -f makeioipsl_fcm ] ; then
241  echo "The file makeiopsl_fcm do not exist. Probably this is not the right version of IOIPSL."
242  echo "Version of IOIPSL with fcm compilation is needed to compile with this script. Stop now."
243  exit
244fi
245
246echo ./makeioipsl_fcm -$optmode -arch ${fcm_arch} -arch_path $arch_path -j 8 $full_flag   >> $outfile 
247     ./makeioipsl_fcm -$optmode -arch ${fcm_arch} -arch_path $arch_path -j 8 $full_flag   >> $outfile 2>&1
248# Test if compiling succeded
249if [[ $? != 0 ]] ; then
250    echo "THERE IS A PROBLEM IN IOIPSL COMPILATION - STOP"
251    exit
252fi
253
254## 2.2 Compile xios
255
256echo; echo "NOW DECOMPRESS XIOS IF NEEDED"
257# First check if XIOS needs to be decompressed
258# In priority search for modeles/XIOS_${optmode}.tar but if it doesn't exist take
259# the first which is found.
260if [[ -d $modipsl/modeles/XIOS ]] ; then
261    echo "Found XIOS -> no decompress needs to be do";  >> $outfile
262elif [[ -f $modipsl/modeles/XIOS_${optmode}.tar ]]; then
263    echo >> $outfile
264    echo "Found XIOS_${optmode}.tar -> decompress repository" >> $outfile
265    # Do not write "tar -xf ... -C $modipsl/modeles because it's modeles/XIOS that is compressed, not only XIOS/
266    tar -xf $modipsl/modeles/XIOS_${optmode}.tar -C $modipsl/ >> $outfile 2>&1
267elif [[ -f $modipsl/modeles/XIOS_prod.tar ]]; then
268    echo >> $outfile
269    echo "Found XIOS_prod.tar -> decompress repository" >> $outfile
270    tar -xf $modipsl/modeles/XIOS_prod.tar -C $modipsl/ >> $outfile 2>&1
271elif [[ -f $modipsl/modeles/XIOS_debug.tar ]]; then
272    echo >> $outfile
273    echo "Found XIOS_debug.tar -> decompress repository" >> $outfile
274    tar -xf $modipsl/modeles/XIOS_debug.tar -C $modipsl/ >> $outfile 2>&1
275elif [[ -f $modipsl/modeles/XIOS_dev.tar ]]; then
276    echo >> $outfile
277    echo "Found XIOS_dev.tar -> decompress repository" >> $outfile
278    tar -xf $modipsl/modeles/XIOS_dev.tar -C $modipsl/ >> $outfile 2>&1
279elif [[ -f $modipsl/modeles/XIOS.tar ]]; then
280    echo >> $outfile
281    echo "Found XIOS.tar -> decompress repository" >> $outfile
282    tar -xf $modipsl/modeles/XIOS.tar -C $modipsl/ >> $outfile 2>&1
283else
284    echo "XIOS source code was not found. Exit"
285    echo "XIOS source code was not found. Exit" >> $outfile
286    exit
287fi
288
289
290cd $modipsl/modeles/XIOS
291echo; echo "NOW COMPILE XIOS"
292echo >> $outfile ; echo " NOW COMPILE XIOS"   >> $outfile 
293echo ./make_xios --$optmode --arch $fcm_arch --arch_path $arch_path ${netcdf_lib} --job 4 $full_xios   >> $outfile 
294     ./make_xios --$optmode --arch $fcm_arch --arch_path $arch_path ${netcdf_lib} --job 4 $full_xios   >> $outfile 2>&1
295# Test if compiling succeded
296if [[ $? != 0 ]] ; then
297    echo "THERE IS A PROBLEM IN XIOS COMPILATION - STOP"
298    exit
299fi
300# Move executables to modipsl/bin
301if [ -f $modipsl/modeles/XIOS/bin/xios_server.exe ] ; then
302    mv $modipsl/modeles/XIOS/bin/xios_server.exe $modipsl/bin/xios_server_${optmode}.exe
303else
304    echo "THERE IS A PROBLEM IN XIOS COMPILATION EXECUTABLE MISSING - STOP"
305    exit
306fi
307
308
309## 2.3 Compile orchidee
310cd $modipsl/modeles/ORCHIDEE
311echo; echo "NOW COMPILE ORCHIDEE"
312echo >> $outfile ; echo " NOW COMPILE ORCHIDEE"   >> $outfile 
313
314
315# Check if the compilation of ORCHIDEE was previsouly interupted prematured.
316# In that case, the files fcm.bld.lock exist. If the file exist, it is here removed to avoid makeorchidee_fcm
317# to ask question and wait for interactivly answer from the user.
318if [ -f build/fcm.bld.lock ] ; then
319    echo >> $outfile
320    echo " WARNING!! The file ORCHIDEE/build/fcm.bld.lock exist. "   >> $outfile
321    echo "           This means that the compilation is either currently on going in another terminal was previous interupted before the end."   >> $outfile
322    echo "           The file will now be removed. "   >> $outfile
323    echo >> $outfile
324    rm -f build/fcm.bld.lock
325fi
326
327echo    ./makeorchidee_fcm -j 8 -xios -parallel $parallel -$optmode -arch ${fcm_arch} -arch_path $arch_path $full_orch -driver   >> $outfile 
328        ./makeorchidee_fcm -j 8 -xios -parallel $parallel -$optmode -arch ${fcm_arch} -arch_path $arch_path $full_orch -driver    >> $outfile 2>&1
329# Test if compiling finished
330if [[ $? != 0 ]] ; then
331    echo "THERE IS A PROBLEM IN ORCHIDEE COMPILATION - STOP"
332    exit
333fi
334
335# Rename executables to contain $optmode
336if [ -f $modipsl/bin/orchidee_ol ] ; then mv $modipsl/bin/orchidee_ol  $modipsl/bin/orchidee_ol_${optmode} ; fi
337if [ -f $modipsl/bin/orchideedriver ] ; then mv $modipsl/bin/orchideedriver  $modipsl/bin/orchideedriver_${optmode} ; fi
338
339
340## 2.4 Compile LMDZ for regular latlon configuration
341cd $modipsl/modeles/LMDZ
342
343# First check if LMDZ/libo exist or if it could be decompressed
344# If neither LMDZ/libo or LMDZ/libo_${optmode}.tar exists, nothing is done. It'll be created
345# during the compilation.
346echo; echo "NOW DECOMPRESS LMDZ/libo IF NEEDED"
347if [[ -d $modipsl/modeles/LMDZ/libo ]] ; then
348    echo "Found LMDZ/libo -> no decompress needs to be done"; >> $outfile
349elif [[ -f $modipsl/modeles/LMDZ/libo_${optmode}.tar ]]; then
350    echo "Found LMDZ/libo_${optmode}.tar -> decompress repository"; >> $outfile
351    echo >> $outfile
352    tar -xf $modipsl/modeles/LMDZ/libo_${optmode}.tar -C $modipsl/ >> $outfile 2>&1
353fi
354
355
356# Compile LMDZ regular lat-lon executable
357echo; echo "NOW COMPILE LMDZ REGULAR LAT-LON MODE. Resolution = ${resol_atm}"
358echo >> $outfile ; echo " NOW COMPILE LMDZ REGULAR LAT-LON MODE. Resolution = ${resol_atm}"   >> $outfile 
359# Retrieve the final svn release number, needed for radiative code suffix of executable
360lmdzsvn=`svnversion . | egrep -o "[0-9]+"  | awk 'NR==1'`
361echo >> $outfile ; echo "lmdzsvn= $lmdzsvn "   >> $outfile
362
363# Check if the compilation of LMDZ was previsouly interupted prematured.
364# In that case, the files dimension.h and .lock exist. If the files exist, they are here removed to avoid makelmdz_fcm
365# to ask question and wait for interactivly answer from the user.
366if [ -f libf/grid/dimensions.h ] || [ -f .lock ] ; then
367  echo >> $outfile
368  echo " WARNING!! The file LMDZ/libf/grid/dimension.h and/or the LMDZ/.lock exist. "   >> $outfile
369  echo "           This means that the compilation is either currently on going in another terminal was previous interupted before the end."   >> $outfile
370  echo "           The files dimension.h and .lock will now be removed. "   >> $outfile
371  echo >> $outfile
372  rm -f libf/grid/dimensions.h
373  rm -f .lock
374fi
375
376# Need to define the proper option for radiative code compilation. By default, we use rrtm
377case $rad in
378    oldrad) opt_rad="" ;;
379    rrtm)   if [ $lmdzsvn -le 4185 ] ; then opt_rad="-rrtm true" ; else opt_rad="-rad rrtm" ; fi ;;
380    ecrad)  opt_rad="-rad ecrad" ;;
381    *) echo Only oldrad rrtm ecrad for rad option ; exit
382esac
383
384if [ $lmdzsvn -le 4185 -a $rad = "ecrad" ] ; then echo "ecrad only available for LMDZ rev starting with 4186 " ; exit ; fi
385
386
387echo ./makelmdz_fcm -d ${resol_atm} -p lmd  $opt_rad $opt_cosp $opt_strataer -$optmode -parallel $parallel -io xios -v orchidee2.1 -arch $fcm_arch -arch_path $arch_path -j 8 $full_lmdz gcm    >> $outfile 
388./makelmdz_fcm -d ${resol_atm} -p lmd  $opt_rad $opt_strataer -$optmode -parallel $parallel -io xios -v orchidee2.1 -arch $fcm_arch -arch_path $arch_path -j 8 $full_lmdz gcm    >> $outfile 2>&1
389# Test if compiling finished
390if [[ $? != 0 ]] ; then
391    echo "THERE IS A PROBLEM IN LMDZ REGULAR LATLON COMPILATION - STOP"
392    exit
393fi
394
395# Move executables to modipsl/bin folder
396echo >> $outfile
397echo "Move gcm.e executable to modipsl/bin" >> $outfile
398echo ls -lrt $modipsl/modeles/LMDZ/bin   >> $outfile
399ls -lrt $modipsl/modeles/LMDZ/bin  >> $outfile
400echo >> $outfile
401
402suffix=${resol_atm}_phylmd
403if [ $lmdzsvn -ge 4186 ] ; then suffix=${suffix}_${rad} ; fi
404if [ $parallel == seq ] || [ $parallel == none ] ; then
405    suffix=_${suffix}_seq_orch.e
406else
407    suffix=_${suffix}_para_mem_orch.e
408fi
409echo gcm suffix = $suffix
410
411if [ -f $modipsl/modeles/LMDZ/bin/gcm${suffix} ] ;  then
412    mv $modipsl/modeles/LMDZ/bin/gcm${suffix} $modipsl/bin/gcm_${resol_atm}_${optmode}.e
413else
414    echo "ERROR gcm${suffix} executable does not exist." 
415    echo "THERE IS A PROBLEM IN LMDZ REGULAR LATLON COMPILATION - STOP"
416    exit
417fi 
418
419
420# Compile ce0l initialization program for LMDZ regular lat-lon exectuable
421if [ $ce0l == y ] ; then
422    echo; echo "NOW COMPILE CE0L OF LMDZ. Resolution = ${resol_atm}"
423    echo >> $outfile ; echo " NOW COMPILE CE0L OF LMDZ. Resolution = ${resol_atm}"   >> $outfile 
424   
425    echo ./makelmdz_fcm -d ${resol_atm} -p lmd  $opt_rad -$optmode -arch $fcm_arch -arch_path $arch_path -j 8 $full_lmdz ce0l    >> $outfile 
426    ./makelmdz_fcm -d ${resol_atm} -p lmd  $opt_rad -$optmode -arch $fcm_arch -arch_path $arch_path -j 8 $full_lmdz ce0l    >> $outfile 2>&1
427    # Test if compiling finished
428    if [[ $? != 0 ]] ; then
429        echo "THERE IS A PROBLEM IN CE0L (LMDZ) REGULAR LATLON COMPILATION - STOP"
430        exit
431    fi
432
433   
434    # Move executables to modipsl/bin folder
435    echo >> $outfile
436    echo "Move ce0l.e executable to modipsl/bin" >> $outfile
437    echo ls -lrt $modipsl/modeles/LMDZ/bin   >> $outfile
438    ls -lrt $modipsl/modeles/LMDZ/bin  >> $outfile
439    echo >> $outfile
440    suffix=_${resol_atm}_phylmd_seq.e
441    if [ $lmdzsvn -ge 4186 ] ; then suffix=_${resol_atm}_phylmd_${rad}_seq.e ; fi
442    echo ce0l suffix = $suffix
443
444    if [ -f $modipsl/modeles/LMDZ/bin/ce0l${suffix} ] ;  then
445        mv $modipsl/modeles/LMDZ/bin/ce0l${suffix} $modipsl/bin/ce0l_${resol_atm}_${optmode}.e
446    else
447        echo "ERROR ce0l${suffix} executable does not exist." 
448        echo "THERE IS A PROBLEM IN CE0L (LMDZ) REGULAR LATLON COMPILATION - STOP"
449        exit
450    fi 
451fi
452
453# Compress XIOS and LMDZ/libo
454if [ $comp_tar == yes ] && [ -d $modipsl/modeles/XIOS ] ; then
455    echo "Option comp_tar activated, now compress XIOS and LMDZ/libo"
456    echo "Option comp_tar activated, now compress XIOS and LMDZ/libo" >> $outfile 
457    tar -cf $modipsl/modeles/XIOS_${optmode}.tar $modipsl/modeles/XIOS
458    rm -rf $modipsl/modeles/XIOS
459    tar -cf $modipsl/modeles/LMDZ/libo_${optmode}.tar $modipsl/modeles/LMDZ/libo
460    rm -rf $modipsl/modeles/LMDZ/libo
461fi
462
463echo >>$outfile ; echo "ALL COMPILING FINISHED" >> $outfile
464echo ls -lrt modipsl/bin >> $outfile
465ls -lrt $modipsl/bin >> $outfile
466
467echo; echo "ALL COMPILING FINISHED" ; echo
468echo "Executables are found in modipsl/bin"
469echo "Check that executable names correspond with the name set in config.card before launching the job"
470echo ls -lrt modipsl/bin
471ls -lrt $modipsl/bin
472
473date
474
475exit
Note: See TracBrowser for help on using the repository browser.