source: XIOS3/branches/xios-3.0-beta/make_xios

Last change on this file was 2611, checked in by jderouillat, 5 months ago

Fix in detecting if the environment enables parallel compression

  • Property svn:executable set to *
File size: 12.5 KB
Line 
1#!/bin/bash
2install_dir=$PWD
3compil_full="false"
4use_oasis="false"
5oasis="oasis3_mct"
6build_path="./"
7build_dir="./"
8build_suffixed="false"
9use_extern_boost="false"
10use_extern_blitz="false"
11use_memtrack="false"
12job="1"
13netcdf_lib="netcdf4_par"
14compil_mode="prod"
15arch_path=$PWD/"arch"
16arch_default_path=$PWD/"arch"
17arch_defined="FALSE"
18arch_path_defined="FALSE"
19fcm_version=new
20
21# Traitement de la ligne de commande
22while (($# > 0))
23   do
24      case $1 in
25         "-h"|"--help"|"-help")
26            echo "make_xios - installs XIOS on your architecture"
27            echo "make_xios [options]"
28            echo "options :"
29            echo "       [--prod] : compilation in production mode (default)"
30            echo "       [--dev] : compilation in development mode"
31            echo "       [--debug] : compilation in debug mode"
32            echo "       --arch arch : to choose target architecture"
33            echo "       [--avail] : to know available target architectures "
34            echo "       [--full] : to generate dependencies and recompile from scratch"
35            echo "       [--use_oasis 'oasis3' 'oasis3_mct' : default oasis3_mct] : to use Oasis coupler"
36        echo "       [--build_path : absolute path to the build directory"
37        echo "       [--build_dir : name of the build directory"
38        echo "       [--build_suffixed : generate automatically suffixed name of the build directory (e.g. config_X64_CURIE_prod)"
39        echo "       [--use_extern_boost : to use external boost library"
40        echo "       [--use_extern_blitz : to use external blitz library"
41            echo "       [--doc] : to generate Doxygen documentation (not available yet)"
42            echo "       [--job ntasks] : to use parallel compilation with ntasks"
43            echo "       [--netcdf_lib 'netcdf4_par'/'netcdf4_seq'/'netcdf4_internal' : default netcdf4_par] : choice of netcdf library"
44            echo "       [--memtrack full/light] : tracking memory leak - developper only"
45            echo "       [--fcm] : fcm version compatibility : 'new'/'old'"
46            echo "Example : ./make_xios --prod --arch PW6_VARGAS"
47            echo "Example : ./make_xios --avail"
48            exit;;
49         "--prod")  compil_mode="prod"  ; shift ;;
50         "--dev")   compil_mode="dev"   ; shift ;;
51         "--debug") compil_mode="debug" ; shift ;;
52         "--arch")  arch=$2     ; arch_defined="TRUE"; shift ; shift ;;
53         "--arch_path")  arch_path=$2     ; arch_path_defined="TRUE"; shift ; shift ;;
54         "--avail") ls arch/*.fcm | cut -d"-" -f2 | cut -d"." -f1 ; exit ;;
55         "--full")  compil_full="true"  ; shift ;;
56         "--use_oasis")  use_oasis="true" oasis=$2 ; shift ; shift  ;;
57         "--build_path")  build_path=$2     ; shift ; shift ;;
58         "--build_dir")  build_dir=$2     ; shift ; shift ;;
59         "--build_suffixed")  build_suffixed="true" ; shift  ;;
60         "--use_extern_boost")  use_extern_boost="true" ; shift  ;;
61         "--use_extern_blitz")  use_extern_blitz="true" ; shift  ;;
62         "--doc")   doc="true"          ; shift ;;
63         "--job")   job=$2              ; shift ; shift ;;
64         "--netcdf_lib")   netcdf_lib=$2 ; shift ; shift ;;
65         "--memtrack")  use_memtrack="true" memtrack=$2  ; shift ; shift ;;
66         "--fcm")       fcm_version=$2  ; shift ; shift ;;
67         *)         code="$1"           ; shift ;;
68      esac
69   done
70
71# Installation des sources
72nb_files_gz=`ls $install_dir/tools/archive | grep tar.gz | wc -l`
73if [ ${nb_files_gz} -ne 0 ]               
74then
75    echo -e "- uncompress archives ..."         
76    for tarname in `ls $install_dir/tools/archive/*.tar.gz` ; do
77        if  ( [[ ${tarname} == "${install_dir}/tools/archive/boost.tar.gz" ]] && [[ "$use_extern_boost" == "true" ]] ) || ( [[ ${tarname} == "${install_dir}/tools/archive/blitz.tar.gz" ]] && [[ "$use_extern_blitz" == "true" ]] )
78        then
79                continue
80        fi
81        gunzip -f "$tarname"
82        tar -xf ${tarname%.gz}
83    done
84fi
85
86# Definition of the root directory of the build
87
88if [[ "$build_path" == "./" ]]; then
89  install_dir=$PWD
90else
91  install_dir=${build_path}
92fi
93
94if [[ "$build_suffixed" == "true" ]]; then
95    install_dir="${install_dir}/config_${arch}_${compil_mode}"
96else
97    install_dir="${install_dir}/${build_dir}"
98fi
99
100mkdir -p $install_dir
101
102rm -f ${PWD}/bld_dir.cfg
103echo "inc    ${install_dir}/arch.fcm" >> ${PWD}/bld_dir.cfg
104echo "inc    ${install_dir}/config.fcm" >> ${PWD}/bld_dir.cfg
105echo "dir::root  ${install_dir}"   >> ${PWD}/bld_dir.cfg
106
107# Vérification de la présence d'un identifiant d'architecture.
108
109###############################################################
110# lecture des chemins propres a l'architecture de la machine #
111#           et configuration de l'environnement              #
112###############################################################
113
114rm -f .void_file
115echo > .void_file
116rm -rf .void_dir
117mkdir .void_dir
118
119if [[ "$arch_defined" == "TRUE" ]]
120then
121  rm -f ${install_dir}/arch.path
122  rm -f ${install_dir}/arch.fcm
123  rm -f ${install_dir}/arch.env
124
125  if test -f $arch_path/arch-${arch}.path
126  then
127    ln -s $arch_path/arch-${arch}.path ${install_dir}/arch.path
128  elif test -f $arch_default_path/arch-${arch}.path
129  then
130    ln -s $arch_default_path/arch-${arch}.path ${install_dir}/arch.path
131  fi
132       
133  if test -f $arch_path/arch-${arch}.fcm
134  then
135    ln -s $arch_path/arch-${arch}.fcm ${install_dir}/arch.fcm
136  elif test -f $arch_default_path/arch-${arch}.fcm
137  then
138    ln -s $arch_default_path/arch-${arch}.fcm ${install_dir}/arch.fcm
139  fi
140
141  if test -f $arch_path/arch-${arch}.env
142  then
143    ln -s $arch_path/arch-${arch}.env ${install_dir}/arch.env
144  elif test -f $arch_default_path/arch-${arch}.env
145  then
146    ln -s $arch_default_path/arch-${arch}.env ${install_dir}/arch.env
147  else
148    ln -s .void_file ${install_dir}/arch.env
149  fi
150  source ${install_dir}/arch.env
151  source ${install_dir}/arch.path
152else
153      echo "Please choose a target achitecture --> list all available architecture using make_xios --avail!"
154      exit 1
155fi
156
157# Vérification de la présence d'un mode de compilation.
158
159if [[ "$compil_mode" == "prod" ]]
160   then
161      COMPIL_CFLAGS="%PROD_CFLAGS"
162      COMPIL_FFLAGS="%PROD_FFLAGS"
163elif [[ "$compil_mode" == "dev" ]]
164   then
165      COMPIL_CFLAGS="%DEV_CFLAGS"
166      COMPIL_FFLAGS="%DEV_FFLAGS"
167elif [[ "$compil_mode" == "debug" ]]
168   then
169      COMPIL_CFLAGS="%DEBUG_CFLAGS"
170      COMPIL_FFLAGS="%DEBUG_FFLAGS"
171fi
172
173rm -r $PWD/extern/netcdf4
174
175if [[ "$netcdf_lib" == "netcdf4_par" ]]
176   then
177     ln -s $PWD/.void_dir $PWD/extern/netcdf4
178     XIOS_CPPKEY="$XIOS_CPPKEY USING_NETCDF_PAR"
179elif [[ "$netcdf_lib" == "netcdf4_seq" ]]
180  then
181    ln -s $PWD/.void_dir $PWD/extern/netcdf4
182elif [[ "$netcdf_lib" == "netcdf4_internal" ]]
183  then
184    ln -s $PWD/extern/src_netcdf4 $PWD/extern/netcdf4
185    XIOS_CPPKEY="$XIOS_CPPKEY USING_NETCDF_PAR USING_NETCDF_INTERNAL"
186    export NETCDF_INCDIR="-I${PWD}/extern/netcdf4"
187    export NETCDF_LIBDIR=""
188    export NETCDF_LIB=""
189else
190   echo "Bad choice for --netcdf_lib argument : choose between 'netcdf4_par','netcdf4_seq' or 'netcdf4_internal'"
191   exit
192fi
193
194if [[ "$use_oasis" == "true" ]]
195   then
196    if [[ "$oasis" == "oasis3_mct" ]]
197    then
198        XIOS_CPPKEY="$XIOS_CPPKEY USE_OMCT"
199    elif [[ "$oasis" == "oasis3"  ]]
200    then
201        XIOS_CPPKEY="$XIOS_CPPKEY USE_OASIS"
202        OASIS_INCDIR="-I$PWD/../../prism/X64/build/lib/psmile.MPI1"
203        OASIS_LIBDIR="-L$PWD/../../prism/X64/lib"
204        OASIS_LIB="-lpsmile.MPI1 -lmpp_io"
205    else
206        echo "Bad choice for --use_oasis argument : choose between 'oasis3','oasis3_mct'"
207        exit
208    fi
209    NETCDF_LIB="-lnetcdff -lnetcdf"
210    XIOS_FINCDIR="$OASIS_INCDIR $XIOS_FINCDIR"
211    XIOS_LIB="$OASIS_LIBDIR $OASIS_LIB $XIOS_LIB"
212fi 
213
214
215# Detecting if parallel compression is available :
216#   - NetCDF is HDF5 based and >= 4.7.4  ?
217#   - HDF5   is parallel   and >= 1.10.3 ?
218USE_HDF5=0
219if [[ ! -z $NETCDF_INCDIR ]]
220then
221    NETCDF_LOOKUP=`echo ${NETCDF_INCDIR} | sed 's/\-I/\ /g'`
222    netcdf_meta_file=`find $NETCDF_LOOKUP -name netcdf_meta.h 2> /dev/null`
223else
224    for dir in `echo $CPATH | sed 's/\:/\ /g'` ; do
225        if [ -f "$dir/netcdf_meta.h" ]
226        then
227            netcdf_meta_file=$dir/netcdf_meta.h
228            break
229        fi
230    done
231fi
232if [[ ! -z $netcdf_meta_file ]]
233then
234    NC_MAJOR=`grep "NC_VERSION_MAJOR" $netcdf_meta_file | awk '{ print $3 }'`
235    NC_MINOR=`grep "NC_VERSION_MINOR" $netcdf_meta_file | awk '{ print $3 }'`
236    NC_PATCH=`grep "NC_VERSION_PATCH" $netcdf_meta_file | awk '{ print $3 }'`
237    if ( [[ "$NC_MAJOR" -ge 5 || ( "$NC_MAJOR" -eq 4 &&  "$NC_MINOR" -ge 8 )|| ( "$NC_MAJOR" -eq 4 && "$NC_MINOR" -eq 7 && "$NC_PATCH" -ge 4 ) ]] )
238    then
239        USE_HDF5=`grep NC_HAS_HDF5 $netcdf_meta_file | awk '{ print $3 }'`
240    fi
241fi
242
243if [ "$USE_HDF5" == "1" ]
244then
245    # https://forum.hdfgroup.org/t/parallel-compression-support-detection/5398   
246    if [[ ! -z $HDF5_LIBDIR ]]
247    then
248        HDF5_LOOKUP=`echo ${HDF5_LIBDIR} | sed 's/\-L/\ /g'`
249        hdf5_settings_file=`find $HDF5_LOOKUP -name libhdf5.settings 2> /dev/null`
250    else
251        for dir in `echo $LD_LIBRARY_PATH | sed 's/\:/\ /g'` ; do
252            if [ -f "$dir/libhdf5.settings" ]
253            then
254                hdf5_settings_file=$dir/libhdf5.settings
255                break
256            fi
257        done
258    fi
259    if [[ ! -z $hdf5_settings_file ]]
260    then
261        HDF5_VERSION=`grep "HDF5 Version" $hdf5_settings_file | awk -F  ':' '{ print $2 }'`
262        HDF5_MAJOR_VERSION=`echo $HDF5_VERSION | awk -F  '.' '{ print $2 }'`
263        HDF5_MINOR_VERSION=`echo $HDF5_VERSION | awk -F  '.' '{ print $3 }'`
264        HDF5_PARALLEL=`grep "Parallel HDF5" $hdf5_settings_file | awk -F  ':' '{ print $2 }'`
265        HDF5_DEFLATE=`grep "I/O filters (external)" $hdf5_settings_file | awk -F  ':' '{ print $2 }'`
266        if ( [[ "$HDF5_MAJOR_VERSION" -ge 11 || ( "$HDF5_MAJOR_VERSION" -eq 10 &&  "$HDF5_MINOR_VERSION" -ge 3 ) ]] )
267        then
268            if [[ "$HDF5_PARALLEL" =~ "yes" && "$HDF5_DEFLATE" =~ "zlib" ]]
269            then
270                XIOS_CPPKEY="$XIOS_CPPKEY PARALLEL_COMPRESSION"
271            fi
272        fi         
273    fi # hdf5_settings_file
274fi
275if [[ "$XIOS_CPPKEY" =~ "PARALLEL_COMPRESSION" ]]
276then
277    echo "->Parallel compression is available"
278else
279    echo "->Parallel compression is NOT available"   
280fi
281# End "Detecting if parallel compression is available"
282
283
284# Setting path for boost
285if [[ "$use_extern_boost" == "true" ]]
286then
287   rm -r $PWD/extern/boost
288   ln -s $PWD/.void_dir $PWD/extern/boost
289else
290   export BOOST_INCDIR="-I${PWD}/extern/boost"
291   export BOOST_LIBDIR=""
292   export BOOST_LIB=""
293fi
294
295# Setting path for blitz
296if [[ "$use_extern_blitz" == "true" ]]
297then
298   rm -r $PWD/extern/blitz
299   ln -s $PWD/.void_dir $PWD/extern/blitz
300else
301   echo "src::blitz $PWD/extern/blitz/src" >> ${PWD}/bld_dir.cfg
302   export BLITZ_INCDIR="-I${PWD}/extern/blitz"
303   export BLITZ_LIBDIR=""
304   export BLITZ_LIB=""
305fi
306
307
308if [[ "$use_memtrack" == "true" ]]
309   then
310   XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK"
311
312    if [[ "$memtrack" == "light" ]]
313    then
314        XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK_LIGHT"
315    elif [[ "$memtrack" == "full"  ]]
316    then
317      XIOS_CPPKEY="$XIOS_CPPKEY XIOS_MEMTRACK_FULL"
318    else
319        echo "Bad choice for --memtrack argument : choose between 'light','full'"
320        exit
321    fi
322fi
323
324XIOS_CINCDIR="$NETCDF_INCDIR $HDF5_INCDIR $MPI_INCDIR $BOOST_INCDIR $BLITZ_INCDIR"
325XIOS_FINCDIR="$NETCDF_INCDIR $XIOS_FINCDIR $MPI_INCDIR $BOOST_INCDIR $BLITZ_INCDIR"
326
327XIOS_LIB="$XIOS_LIB $NETCDF_LIBDIR $HDF5_LIBDIR $MPI_LIBDIR $NETCDF_LIB $HDF5_LIB $MPI_LIB"
328
329rm -f ${install_dir}/config.fcm
330echo "%COMPIL_CFLAGS $COMPIL_CFLAGS" >> ${install_dir}/config.fcm
331echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> ${install_dir}/config.fcm
332echo "%CPP_KEY       $XIOS_CPPKEY"   >> ${install_dir}/config.fcm
333
334echo "%CBASE_INC     $XIOS_CINCDIR" >> ${install_dir}/config.fcm     
335echo "%FBASE_INC     $XIOS_FINCDIR" >> ${install_dir}/config.fcm
336echo "%ARCH_LD       $XIOS_LIB"     >> ${install_dir}/config.fcm
337
338echo "=> Using "$compil_mode" mode for compiling under architecture \""$arch"\" !"
339
340# Création de la documentation doxygen.
341if [[ !(-z $doc) ]]
342   then
343      echo -e "- Create Doxygen documentation (disabled)..."
344      #doxygen -s
345fi
346
347make_dir=$PWD
348
349if [[ "$fcm_version" == "new" ]]
350then
351  export PATH=$PWD/tools/FCM_NEW/bin:$PATH
352elif [[ "$fcm_version" == "old" ]]
353then
354  export PATH=$PWD/tools/FCM_OLD/bin:$PATH
355else
356  echo "=> Bad option for --fcm flag : "$fcm_version" , only 'new' or 'old' permitted"
357fi
358 
359if [[ "$compil_full" == "true" ]]
360   then
361   fcm build --clean --ignore-lock
362   fcm build -f --ignore-lock -j $job
363else
364  fcm build --ignore-lock -j $job
365fi
366
367build_exit_status=$?
368
369if [[ $build_exit_status == 0 ]]
370  then
371  set nothing
372#    cd $WORKDIR/XIOS_NEMO_COUPLE/modeles/NEMO/WORK
373#    cd $WORKDIR/XIOS_NEMO/modeles/NEMO/WORK
374#    make
375fi
376
377exit $build_exit_status
Note: See TracBrowser for help on using the repository browser.