source: branches/ORCHIDEE_2_2/ORCHIDEE_OL/compile_orchidee_ol.sh @ 8562

Last change on this file since 8562 was 8562, checked in by josefine.ghattas, 6 weeks ago

Add compression by tar option now also in this branche, as done in the trunk. Done by Karine Laurent

  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL
File size: 14.0 KB
Line 
1#!/bin/bash
2#set -vx
3# ================================================================================================================================
4#  compile_orchidee_ol.sh
5#
6#  CONTACT      : orchidee-help _at_ listes.ipsl.fr
7#
8#  LICENCE      : IPSL (2006)
9#  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
10#
11#  DESCRIPTION  : This script is used to compile all components needed for the ORCHIDEE offline drivers. The following components
12#                 will be compiled: IOIPSL, XIOS and ORCHIDEE.
13#                 Default compilation is set up for the machines irene/TGCC, jean-zay/IDRIS, obelix/LSCE and ciclad and
14#                 climserv/IPSL. For other machines compiling option needs to be specified for each of the components.
15#                 The script first sources a arch.env file, from folder ARCH, containing modules needed for the current machine.
16#                 This means that the modules do not need to be sourced before starting the compilation. Output from compilation
17#                 are stored in a separate file out_compile_orchidee.date.
18#                 For help about the script, use: ./compile_orchidee_ol.sh -h
19#
20# $HeadURL$
21# $Date$
22# $Revision$
23# ================================================================================================================================
24
25date
26
27#### 1  Set up the compiling options
28#### Define some directories
29submitdir=$( pwd )
30modipsl=$submitdir/../..
31arch_path=$submitdir/ARCH
32
33#### Set default options
34# Optimization mode
35# optmode=prod/dev/debug
36optmode=prod
37
38# fcm_arch
39fcm_arch=default
40
41# parallel: mpi or seq
42parallel=mpi
43
44export fcm_arch parallel xios
45full_flag=""
46full_xios=""
47full_orch=""
48
49# Compile with linking to XIOS: xios=xios (default)
50# Use argument -without_xios for compilation without linking to XIOS: xios=noxios
51xios=xios
52
53# Compile other executables: if otherexec="-otherexec", then
54otherexec=""
55
56# Default netcdf_lib is used for XIOS but can be change by argument
57netcdf_lib=""
58
59## Arguments in order to compress temporary files after compilation
60tar=no
61comp_tar=yes
62
63#### Read arguments
64# Loop over all arguments to modify default set up
65while (($# > 0)) ; do
66    case $1 in
67        "-h") cat <<end_help
68########################################################################
69# Usage of the script compile_orchidee_ol.sh
70#
71########################################################################
72
73./compile_orchidee_ol.sh [Options]
74
75Options:
76  [-full]: full recompilation of all components
77  [-full_orch], [-full_xios]: recompile only orchidee or xios component
78  [-arch XXX]: Force to use arch-XXX.fcm and arch-XXX.path files with specific compilation options for current platform. The files must be
79   available in modles/ORCHIDEE/arch, modeles/XIOS/arch and modeles/IOIPSL/arch folders. If the file config/ORCHIDEE_OL/ARCH/arch-XXX.env
80   exist, it'll be sourced in the beginning of this compilation script.
81  [-debug], [-dev], [-prod](default): use compilation options for debug, dev or production mode, only one option can be used
82  [-all_exec]: also compile other exectables than the drivers (testrouting, forcesoil and teststomate)
83  [-without_xios]: no compilation or linking to XIOS. Default compilation is done with XIOS
84  [-parallel seq] / [-parallel mpi](default): compile without MPI for use in sequential mode / with MPI (default).
85   When using [-parallel seq], [-without_xios] must as well be set.
86  [-netcdf_lib_seq]: option to tell XIOS that linking with netcdf4 sequential library will be used instead of default netcdf4 parallel library
87  [-tar]: option to compress XIOS repository that takes many inodes without compilation
88  [-comp_tar]: option to compile and compress XIOS repository if compilation succed
89  [-notar]: do not compress XIOS repository
90
91
92Example 1: Default compilation of ORCHIDEE with XIOS and IOIPSL
93./compile_orchidee_ol.sh
94
95Example 2: Compile in debug mode
96./compile_orchidee_ol.sh -debug
97
98Example 3: Default compilation with full recompilation of all components
99./compile_orchidee_ol.sh -full
100
101Example 4: No compilation or linking to XIOS
102./compile_orchidee_ol.sh -without_xios
103
104Example 5: Compilation without MPI for sequential use only. Note that XIOS must be deactivated as well.
105./compile_orchidee_ol.sh -parallel seq -without_xios
106
107
108end_help
109exit;;
110        "-parallel")        parallel="$2" ; shift ; shift ;;
111        "-arch")            fcm_arch="$2" ; shift ; shift ;;
112        "-without_xios")    xios=noxios ; shift ;;
113        "-debug")           optmode=debug ; shift ;;
114        "-dev")             optmode=dev ; shift ;;
115        "-prod")            optmode=prod ; shift ;;
116        "-full")            full_flag="-full"; full_xios="--full" ; full_orch="-full" ; shift ;;
117        "-full_xios")       full_xios="--full" ; shift ;;  # Note only full_xios is using double dash: --full
118        "-full_orch")       full_orch="-full"  ; shift ;;
119        "-all_exec")        otherexec="-otherexec" ; shift ;;
120        "-netcdf_lib_seq")  netcdf_lib="--netcdf_lib netcdf4_seq"; shift ;;
121        "-tar")             tar=yes ; shift ;;
122        "-comp_tar")        comp_tar=yes ; shift ;;
123        "-notar")           comp_tar=no ; shift ;;
124        *)                  echo "unknown option "$1" , exiting..." ; exit
125    esac
126done
127
128
129# Create text output file
130datestr=`LC_ALL=C date +"%Y%m%dT%H%M"`
131outfile=$submitdir/out_compile_orchidee.$datestr
132echo > $outfile
133echo; echo "Text output from compilation will be stored in file out_compile_orchidee.$datestr"; echo
134
135
136echo "Following options are set in current compiling:" >> $outfile 
137echo "   optmode = $optmode, parallel = $parallel, fcm_arch = $fcm_arch " >> $outfile 
138echo "   full_flag=$full_flag, full_xios=$full_xios, full_orch=$full_orch" >> $outfile 
139echo "   tar=$tar, comp_tar=$comp_tar" >> $outfile
140echo >> $outfile
141
142if [ $parallel = seq ] && [ $xios = y ] ; then
143    echo "It is not possible to compile ORCHIDEE in sequential mode using XIOS."
144    echo "Option -without_xios must be set if option [-parallel seq] is set"
145    echo "Option -without_xios must be set if option [-parallel seq] is set" >> $outfile 
146    exit
147fi
148
149# Compress XIOS without compiling if tar=yes
150if [ $tar == yes ] ; then
151    cd $modipsl/modeles
152    echo "Option tar activated to compress XIOS. No compilation will be done."
153    echo >> $outfile
154    echo "option tar activated" >> $outfile
155    if [[ -d $modipsl/modeles/XIOS ]] ; then
156        tar -cf XIOS.tar XIOS
157        rm -rf XIOS
158        echo " Tar XIOS repository"
159        echo " Tar XIOS repository" >> $outfile
160    else
161        echo " No XIOS repository to compress"
162        echo " No XIOS repository to compress" >> $outfile
163    fi
164    echo "END OF SCRIPT"
165    echo "END OF SCRIPT" >> $outfile
166    exit
167fi
168
169### Read host dependent default values
170### These variables will not be changed if they were set as argument
171###./host.sh $host
172# Later : Following lines should be set in host.sh file
173# begin host.sh
174if [ $fcm_arch == default ] ; then
175    # Find out current host and source specific paths and commands for the host
176    case $( hostname -s ) in
177        jean-zay*)
178            fcm_arch=X64_JEANZAY;;
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_2023;;
185        ciclad*|climserv*|loholt*|camelot*|merlin*)
186            fcm_arch=ifort_CICLAD;;
187        spirit*)
188            fcm_arch=ifort_MESOIPSL;;
189        *)
190            echo Current host is not known. You must use option -arch to specify which architecuture files to use.
191            echo Exit now.
192            exit
193    esac
194fi
195
196echo "The fcm_arch has been changed to: $fcm_arch" >> $outfile 
197
198# Set a link to arch.env if arch-${fcm_arch}.env file exist for current fcm_arch.
199# The link arch.env is also set in config.card and will be used by libIGCM to ensure the same running environnement.
200if [ -f ARCH/arch-${fcm_arch}.env ] ; then
201    echo >> $outfile
202    echo "The file ARCH/arch-${fcm_arch}.env will now be sourced with modules needed for compilation for all components."
203    echo "Note that this new environement might be kept after compilation." 
204    echo "If this is the case, source again your personal environment after compilation. "
205
206    # Make a link to this file, to be used also in config.card
207    rm -f ARCH/arch.env
208    ln -s arch-${fcm_arch}.env ARCH/arch.env
209
210    # Source the file
211    source ARCH/arch.env   >> $outfile 2>&1
212    echo >> $outfile 
213    echo "New module list after sourcing of ARCH/arch.env file:"    >> $outfile 
214    module list   >> $outfile 2>&1
215else
216    echo "No specific ARCH/arch-${fcm_arch}.env have been found. No change in environnement will be done."
217    echo "Previous loaded module modules will be used."    >> $outfile 
218    module list   >> $outfile 2>&1
219fi
220
221
222#### 2 Do the compilation component by component
223## 2.1 Compile ioipsl
224cd $modipsl/modeles/IOIPSL
225echo; echo "NOW COMPILE IOIPSL"
226echo >> $outfile ; echo " NOW COMPILE IOIPSL"   >> $outfile 
227
228# Check if compilation with fcm is included in IOIPSL
229if [ ! -f makeioipsl_fcm ] ; then
230  echo "The file makeiopsl_fcm do not exist. Probably this is not the right version of IOIPSL."
231  echo "Version of IOIPSL with fcm compilation is needed to compile with this script. Stop now."
232  exit
233fi
234
235echo ./makeioipsl_fcm -$optmode -arch ${fcm_arch} -arch_path $arch_path -j 8 $full_flag   >> $outfile 
236     ./makeioipsl_fcm -$optmode -arch ${fcm_arch} -arch_path $arch_path -j 8 $full_flag   >> $outfile 2>&1
237# Test if compiling succeded
238if [[ $? != 0 ]] ; then
239    echo "THERE IS A PROBLEM IN IOIPSL COMPILATION - STOP"
240    exit
241fi
242
243## 2.2 Compile xios
244if [ $xios == xios ] ; then
245    cd $modipsl/modeles
246    # First check if XIOS needs to be decompressed
247    # In priority search for modeles/XIOS_${optmode}.tar but if it doesn't exist take
248    # the first which is found.
249    echo; echo "NOW DECOMPRESS XIOS IF NEEDED"
250    if [[ -d $modipsl/modeles/XIOS ]] ; then
251        echo "Found XIOS -> no decompress needs to be done";  >> $outfile
252    elif [[ -f $modipsl/modeles/XIOS_${optmode}.tar ]]; then
253        echo >> $outfile
254        echo "Found XIOS_${optmode}.tar -> decompress repository" >> $outfile
255        tar -xf XIOS_${optmode}.tar >> $outfile 2>&1
256    elif [[ -f $modipsl/modeles/XIOS_prod.tar ]]; then
257        echo >> $outfile
258        echo "Found XIOS_prod.tar -> decompress repository" >> $outfile
259        tar -xf XIOS_prod.tar >> $outfile 2>&1
260    elif [[ -f $modipsl/modeles/XIOS_debug.tar ]]; then
261        echo >> $outfile
262        echo "Found XIOS_debug.tar -> decompress repository" >> $outfile
263        tar -xf XIOS_debug.tar >> $outfile 2>&1
264    elif [[ -f $modipsl/modeles/XIOS_dev.tar ]]; then
265        echo >> $outfile
266        echo "Found XIOS_dev.tar -> decompress repository" >> $outfile
267        tar -xf XIOS_dev.tar >> $outfile 2>&1
268    elif [[ -f $modipsl/modeles/XIOS.tar ]]; then
269        echo >> $outfile
270        echo "Found XIOS.tar -> decompress repository" >> $outfile
271        tar -xf XIOS.tar >> $outfile 2>&1
272    else
273        echo "XIOS source code was not found. Exit"
274        echo "XIOS source code was not found. Exit" >> $outfile
275        exit
276    fi
277   
278    cd $modipsl/modeles/XIOS
279    echo; echo "NOW COMPILE XIOS"
280    echo >> $outfile ; echo " NOW COMPILE XIOS"   >> $outfile 
281    echo ./make_xios --$optmode --arch $fcm_arch --arch_path $arch_path ${netcdf_lib} --job 4 $full_xios   >> $outfile 
282    ./make_xios --$optmode --arch $fcm_arch --arch_path $arch_path ${netcdf_lib} --job 4 $full_xios   >> $outfile 2>&1
283    # Test if compiling succeded
284    if [[ $? != 0 ]] ; then
285        echo "THERE IS A PROBLEM IN XIOS COMPILATION - STOP"
286        exit
287    fi
288    # Move executables to modipsl/bin
289    if [ -f $modipsl/modeles/XIOS/bin/xios_server.exe ] ; then
290        mv $modipsl/modeles/XIOS/bin/xios_server.exe $modipsl/bin/xios_server_${optmode}.exe
291    else
292        echo "THERE IS A PROBLEM IN XIOS COMPILATION EXECUTABLE MISSING - STOP"
293        exit
294    fi
295fi
296
297
298## 2.3 Compile orchidee
299cd $modipsl/modeles/ORCHIDEE
300echo; echo "NOW COMPILE ORCHIDEE"
301echo >> $outfile ; echo " NOW COMPILE ORCHIDEE"   >> $outfile 
302
303# Check if the compilation of ORCHIDEE was previsouly interupted prematured.
304# In that case, the files fcm.bld.lock exist. If the file exist, it is here removed to avoid makeorchidee_fcm
305# to ask question and wait for interactivly answer from the user.
306if [ -f build/fcm.bld.lock ] ; then
307    echo >> $outfile
308    echo " WARNING!! The file ORCHIDEE/build/fcm.bld.lock exist. "   >> $outfile
309    echo "           This means that the compilation is either currently on going in another terminal was previous interupted before the end."   >> $outfile
310    echo "           The file will now be removed. "   >> $outfile
311    echo >> $outfile
312    rm -f build/fcm.bld.lock
313fi
314
315echo    ./makeorchidee_fcm -j 8 -$xios -parallel $parallel -$optmode -arch ${fcm_arch} -arch_path $arch_path $full_orch -driver $otherexec   >> $outfile 
316        ./makeorchidee_fcm -j 8 -$xios -parallel $parallel -$optmode -arch ${fcm_arch} -arch_path $arch_path $full_orch -driver $otherexec   >> $outfile 2>&1
317# Test if compiling finished
318if [[ $? != 0 ]] ; then
319    echo "THERE IS A PROBLEM IN ORCHIDEE COMPILATION - STOP"
320    exit
321fi
322
323# Rename executables to contain $optmode
324if [ -f $modipsl/bin/orchidee_ol ] ; then mv $modipsl/bin/orchidee_ol  $modipsl/bin/orchidee_ol_${optmode} ; fi
325if [ -f $modipsl/bin/orchideedriver ] ; then mv $modipsl/bin/orchideedriver  $modipsl/bin/orchideedriver_${optmode} ; fi
326if [ -f $modipsl/bin/testrouting ] ; then mv $modipsl/bin/testrouting  $modipsl/bin/testrouting_${optmode} ; fi
327if [ -f $modipsl/bin/forcesoil ] ; then mv $modipsl/bin/forcesoil  $modipsl/bin/forcesoil_${optmode} ; fi
328if [ -f $modipsl/bin/teststomate ] ; then mv $modipsl/bin/teststomate  $modipsl/bin/teststomate_${optmode} ; fi
329
330if [ $comp_tar == yes ] && [ -d $modipsl/modeles/XIOS ] ; then
331    cd $modipsl/modeles
332    echo "Option comp_tar activated, now compress XIOS"
333    echo "Option comp_tar activated, now compress XIOS" >> $outfile
334    tar -cf XIOS_${optmode}.tar XIOS
335    rm -rf XIOS
336fi
337
338echo >>$outfile ; echo "ALL COMPILING FINISHED" >> $outfile
339echo ls -lrt modipsl/bin >> $outfile
340ls -lrt $modipsl/bin >> $outfile
341
342echo; echo "ALL COMPILING FINISHED" ; echo
343echo "Executables are found in modipsl/bin"
344echo ls -lrt modipsl/bin
345ls -lrt $modipsl/bin
346
347date
348
349exit
350
Note: See TracBrowser for help on using the repository browser.