install_PETSC.sh 11.8 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1
2
3
4
5
6
7
8
9
#! /bin/bash

# check if the directory $1/PETSC exist

if [ -d "$1/PETSC" ]; then
  echo "PETSC already installed"
  exit 0
fi

10
11
12
# Detect gcc pr clang

source script/detect_gcc
Pietro Incardona's avatar
Pietro Incardona committed
13
source script/discover_os
Pietro Incardona's avatar
Pietro Incardona committed
14
detect_compiler g++
Pietro Incardona's avatar
Pietro Incardona committed
15
discover_os
16

Pietro Incardona's avatar
Pietro Incardona committed
17
18
19
20
21
22
23
24
25
##### if we are on osx we use gsed

if [ x"$platform" == x"osx" ]; then
  sed_command=gsed
else
  sed_command=sed
fi

####
26

Pietro Incardona's avatar
Pietro Incardona committed
27
28
29
30
31
32
33
## If some dependencies has been installed feed them to PETSC

MUMPS_extra_libs=""

configure_options=""
configure_options_scalapack=""
configure_options_superlu=""
34
configure_trilinos_options=" -D TPL_ENABLE_MPI=ON "
Pietro Incardona's avatar
Pietro Incardona committed
35
36
configure_options_hypre=""

Pietro Incardona's avatar
Pietro Incardona committed
37
### Here we install OpenBLAS and SUITESPARSE
Pietro Incardona's avatar
Pietro Incardona committed
38
39
40
41
42
43
44
45
46
47
48


if [ -d "$1/PARMETIS" ]; then
  configure_options="$configure_options --with-parmetis=yes  --with-parmetis-dir=$1/PARMETIS/ "
  configure_options_superlu="-DTPL_PARMETIS_INCLUDE_DIRS=$1/PARMETIS/include;$1/METIS/include -DTPL_PARMETIS_LIBRARIES=$1/PARMETIS/lib/libparmetis.a;$1/METIS/lib/libmetis.so $configure_options_superlu"
fi

if [ -d "$1/METIS" ]; then
  configure_options="$configure_options --with-metis=yes --with-metis-dir=$1/METIS  "
fi

Pietro Incardona's avatar
Pietro Incardona committed
49
50
51
#if [ -d "$1/HDF5" ]; then
#  configure_options="$configure_options --with-hdf5=yes --with-hdf5-dir=$1/HDF5  "
#fi
Pietro Incardona's avatar
Pietro Incardona committed
52

Pietro Incardona's avatar
Pietro Incardona committed
53
if [ -d "$1/BOOST" ]; then  
Pietro Incardona's avatar
Pietro Incardona committed
54
  configure_options="$configure_options --with-boost=yes --with-boost-dir=$1/BOOST "
55
  configure_trilinos_options="$configure_trilinos_options -D TPL_ENABLE_Boost=ON  -D TPL_ENABLE_BoostLib=ON  -D Boost_INCLUDE_DIRS=$1/BOOST/include -D BoostLib_LIBRARY_DIRS=$1/BOOST/lib -D BoostLib_INCLUDE_DIRS=$1/BOOST/include"
Pietro Incardona's avatar
Pietro Incardona committed
56
57
58
59
fi

if [ -d "$1/MPI" ]; then
  configure_trilinos_options="$configure_trilinos_options -D MPI_BASE_DIR=$1/MPI "
60
61
62
  mpi_dir="$1/MPI"
else
  mpi_dir=$(dirname "$(dirname "$(which mpic++)")")
Pietro Incardona's avatar
Pietro Incardona committed
63
64
65
fi

### It seem that the PETSC --download-packege option has several problems and cannot produce
Pietro Incardona's avatar
Pietro Incardona committed
66
### a valid compilation command for most of the packages + it seem also that some library
Pietro Incardona's avatar
Pietro Incardona committed
67
68
### are compiled without optimization enabled, so we provide manual installation for that packages

Pietro Incardona's avatar
Pietro Incardona committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
if [ ! -d "$1/OPENBLAS" ]; then
  ./script/install_OPENBLAS.sh $1
  if [ $? -eq 0 ]; then
    configure_options="$configure_options --with-blas-lib=$1/OPENBLAS/lib/libopenblas.a --with-lapack-lib=$1/OPENBLAS/lib/libopenblas.a"
    configure_trilinos_options="$configure_trilinos_options -D TPL_ENABLE_BLAS=ON -D BLAS_LIBRARY_NAMES=openblas -D BLAS_LIBRARY_DIRS=$1/OPENBLAS/lib -D TPL_ENABLE_LAPACK=ON -D LAPACK_LIBRARY_NAMES=openblas -D LAPACK_LIBRARY_DIRS=$1/OPENBLAS/lib -D TPL_ENABLE_Netcdf=OFF -DTPL_ENABLE_GLM=OFF -D TPL_ENABLE_X11=OFF  "
    configure_options_superlu="$configure_options_superlu -Denable_blaslib=OFF  -DTPL_BLAS_LIBRARIES=$1/OPENBLAS/lib/libopenblas.a "
    configure_options_hypre="--with-blas-libs=-lopenblas --with-blas-lib-dirs=$1/OPENBLAS/lib --with-lapack-libs=-lopenblas  --with-lapack-lib-dirs=$1/OPENBLAS/lib "
    configure_options_scalapack="$configure_options_scalapack -D LAPACK_LIBRARIES=$1/OPENBLAS/lib/libopenblas.a -D BLAS_LIBRARIES=$1/OPENBLAS/lib/libopenblas.a"
  fi
else
    configure_options="$configure_options --with-blas-lib=$1/OPENBLAS/lib/libopenblas.a --with-lapack-lib=$1/OPENBLAS/lib/libopenblas.a"
    configure_trilinos_options="$configure_trilinos_options -D TPL_ENABLE_BLAS=ON -D BLAS_LIBRARY_NAMES=openblas -D BLAS_LIBRARY_DIRS=$1/OPENBLAS/lib -D TPL_ENABLE_LAPACK=ON -D LAPACK_LIBRARY_NAMES=openblas -D LAPACK_LIBRARY_DIRS=$1/OPENBLAS/lib -D TPL_ENABLE_Netcdf=OFF -DTPL_ENABLE_GLM=OFF -D TPL_ENABLE_X11=OFF  "
    configure_options_superlu="$configure_options_superlu -Denable_blaslib=OFF  -DTPL_BLAS_LIBRARIES=$1/OPENBLAS/lib/libopenblas.a "
    configure_options_hypre="--with-blas-libs=-lopenblas --with-blas-lib-dirs=$1/OPENBLAS/lib --with-lapack-libs=-lopenblas  --with-lapack-lib-dirs=$1/OPENBLAS/lib "
    configure_options_scalapack="$configure_options_scalapack -D LAPACK_LIBRARIES=$1/OPENBLAS/lib/libopenblas.a -D BLAS_LIBRARIES=$1/OPENBLAS/lib/libopenblas.a"
fi

if [ ! -d "$1/SUITESPARSE" ]; then
  ./script/install_SUITESPARSE.sh $1
  if [ $? -eq 0 ]; then
    configure_options="$configure_options --with-suitesparse=yes --with-suitesparse-dir=$1/SUITESPARSE "
  fi
else
  configure_options="$configure_options --with-suitesparse=yes --with-suitesparse-dir=$1/SUITESPARSE "
fi

Pietro Incardona's avatar
Pietro Incardona committed
95
96
97
98
99
100
101
102
103
104
105
106
if [ ! -d "$1/TRILINOS" ]; then
  rm trilinos-12.6.1-Source.tar.gz
  rm -rf trilinos-12.6.1-Source
  wget http://ppmcore.mpi-cbg.de/upload/trilinos-12.6.1-Source.tar.gz
  if [ $? -ne 0 ]; then
    echo -e "\033[91;5;1m FAILED Installation require an Internet connection \033[0m"
    exit 1
  fi
  tar -xf trilinos-12.6.1-Source.tar.gz
  cd trilinos-12.6.1-Source
  mkdir build
  cd build
107
108

  ### On clang we have no openMP
Pietro Incardona's avatar
Pietro Incardona committed
109
  petsc_openmp=""
110
111
112
113
  if [ x"$dgc_compiler" == x"clang++" ]; then
    conf_trl_openmp="-D Trilinos_ENABLE_OpenMP=OFF"
  else
    conf_trl_openmp="-D Trilinos_ENABLE_OpenMP=ON"
Pietro Incardona's avatar
Pietro Incardona committed
114
#    petsc_openmp="--with-openmp=yes"
115
116
117
  fi

  cmake -D CMAKE_INSTALL_PREFIX:PATH=$1/TRILINOS -D CMAKE_BUILD_TYPE=RELEASE $conf_trl_openmp -D Trilinos_ENABLE_TESTS=OFF  -D Trilinos_ENABLE_ALL_PACKAGES=ON $configure_trilinos_options  ../.
Pietro Incardona's avatar
Pietro Incardona committed
118

119
  make -j $2
Pietro Incardona's avatar
Pietro Incardona committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  if [ $? -eq 0 ]; then
    make install
    configure_options="$configure_options --with-trilinos=yes -with-trilinos-dir=$1/TRILINOS"
  fi
else
  echo "Trilinos already installed"
  configure_options="$configure_options --with-trilinos=yes -with-trilinos-dir=$1/TRILINOS"
fi

### Scalapack installation

if [ ! -d "$1/SCALAPACK" ]; then
  rm scalapack-2.0.2.tgz
  rm -rf scalapack-2.0.2
  wget http://ppmcore.mpi-cbg.de/upload/scalapack-2.0.2.tgz
  if [ $? -ne 0 ]; then
    echo -e "\033[91;5;1m FAILED Installation require an Internet connection \033[0m"
    exit 1
  fi
  tar -xf scalapack-2.0.2.tgz
  cd scalapack-2.0.2
  mkdir build
  cd build
  cmake -D CMAKE_EXE_LINKER_FLAGS=-pthread  -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_Fortran_FLAGS_RELEASE=-fpic -D MPI_C_COMPILER_FLAGS=-fpic -D MPI_Fortran_COMPILER_FLAGS=-fpic -D CMAKE_C_FLAGS=-fpic -D CMAKE_INSTALL_PREFIX="$1/SCALAPACK" $configure_options_scalapack ../.
144
  make -j $2
Pietro Incardona's avatar
Pietro Incardona committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  if [ $? -eq 0 ]; then
    make install
    configure_options="$configure_options --with-scalapack=yes -with-scalapack-dir=$1/SCALAPACK"
  fi
else
  echo "Scalapack already installed"
  configure_options="$configure_options --with-scalapack=yes -with-scalapack-dir=$1/SCALAPACK"
fi


### MUMPS installation

if [ ! -d "$1/MUMPS" ]; then
  rm MUMPS_5.0.1.tar.gz
  rm -rf MUMPS_5.0.1
  wget http://ppmcore.mpi-cbg.de/upload/MUMPS_5.0.1.tar.gz
  if [ $? -ne 0 ]; then
    echo -e "\033[91;5;1m FAILED Installation require an Internet connection \033[0m"
    exit 1
  fi
  tar -xf MUMPS_5.0.1.tar.gz
  cd MUMPS_5.0.1
  cp Make.inc/Makefile.inc.generic Makefile.inc
 
Pietro Incardona's avatar
Pietro Incardona committed
169
  # Installation for linux
Pietro Incardona's avatar
Pietro Incardona committed
170

Pietro Incardona's avatar
Pietro Incardona committed
171
172
173
  $sed_command -i "/CC\s\+=\scc/c\CC = mpicc" Makefile.inc
  $sed_command -i "/FC\s\+=\sf90/c\FC = mpif90" Makefile.inc
  $sed_command -i "/FL\s\+=\sf90/c\FL = mpif90" Makefile.inc
Pietro Incardona's avatar
Pietro Incardona committed
174

Pietro Incardona's avatar
Pietro Incardona committed
175
176
  $sed_command -i "/SCALAP\s\+=\s-lscalapack\s-lblacs/c\SCALAP = -L$1/SCALAPACK/lib -L$1/OPENBLAS/lib -lscalapack" Makefile.inc
  $sed_command -i "/LIBBLAS\s\+=\s\-lopenblas/c\LIBBLAS = -lopenblas" Makefile.inc
Pietro Incardona's avatar
Pietro Incardona committed
177

Pietro Incardona's avatar
Pietro Incardona committed
178
179
180
  $sed_command -i "/OPTF\s\+=\s\-O/c\OPTF = -fpic -O3" Makefile.inc
  $sed_command -i "/OPTC\s\+=\s\-O\s-I./c\OPTC = -fpic -O3 -I." Makefile.inc
  $sed_command -i "/OPTL\s\+=\s\-O/c\OPTL = -fpic -O3" Makefile.inc
Pietro Incardona's avatar
Pietro Incardona committed
181

Pietro Incardona's avatar
Pietro Incardona committed
182
  $sed_command -i "/LIBBLAS\s=\s-lblas/c\LIBBLAS = -lopenblas" Makefile.inc
Pietro Incardona's avatar
Pietro Incardona committed
183

Pietro Incardona's avatar
Pietro Incardona committed
184
185
186
  $sed_command -i "/INCPAR\s\+=\s\-I\/usr\/include/c\INCPAR =" Makefile.inc
  $sed_command -i "/LIBPAR\s\+=\s\$(SCALAP)\s\-L\/usr\/lib\s\-lmpi/c\LIBPAR = \$(SCALAP)" Makefile.inc

187
  make -j $2
Pietro Incardona's avatar
Pietro Incardona committed
188
189
190
191
192
193
194
  
  if [ $? -eq 0 ]; then
    ## Copy LIB and include in the target directory

    mkdir $1/MUMPS
    cp -r include $1/MUMPS
    cp -r lib $1/MUMPS
Pietro Incardona's avatar
Pietro Incardona committed
195
196
197
198

    configure_options="$configure_options --with-mumps=yes --with-mumps-include=$1/MUMPS/include"
    MUMPS_extra_lib="$1/MUMPS/lib/libdmumps.a $1/MUMPS/lib/libmumps_common.a $1/MUMPS/lib/libpord.a"

Pietro Incardona's avatar
Pietro Incardona committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  fi

else
  echo "MUMPS already installed"
  configure_options="$configure_options --with-mumps=yes --with-mumps-include=$1/MUMPS/include"
  MUMPS_extra_lib="$1/MUMPS/lib/libdmumps.a $1/MUMPS/lib/libmumps_common.a $1/MUMPS/lib/libpord.a"
fi

## SuperLU installation

if [ ! -d "$1/SUPERLU_DIST" ]; then
  rm superlu_dist_4.3.tar.gz
  rm -rf SuperLU_DIST_4.3
  wget http://ppmcore.mpi-cbg.de/upload/superlu_dist_4.3.tar.gz
  if [ $? -ne 0 ]; then
    echo -e "\033[91;5;1m FAILED Installation require an Internet connection \033[0m"
    exit 1
  fi
  tar -xf superlu_dist_4.3.tar.gz
  cd SuperLU_DIST_4.3

Pietro Incardona's avatar
Pietro Incardona committed
220
  # Installation for linux
Pietro Incardona's avatar
Pietro Incardona committed
221

Pietro Incardona's avatar
Pietro Incardona committed
222
223
224
225
  $sed_command -i "/DSuperLUroot\s\+=\s\${HOME}\/Release_Codes\/SuperLU_DIST_4.3/c\DSuperLUroot = ../" make.inc
  $sed_command -i "/BLASLIB\s\+=/c\BLASLIB = $1/OPENBLAS/lib/libopenblas.a" make.inc
  $sed_command -i "/LOADOPTS\s\+=\s-openmp/c\LOADOPTS = -fopenmp" make.inc
  $sed_command -i "/PARMETIS_DIR\s\+=\/project\/projectdirs\/mp127\/parmetis-4.0.3-g/c\PARMETIS_DIR := $1/PARMETIS" make.inc
Pietro Incardona's avatar
Pietro Incardona committed
226

Pietro Incardona's avatar
Pietro Incardona committed
227
228
  $sed_command -i "/METISLIB\s:=\s-L\${PARMETIS_DIR}\/build\/Linux-x86_64\/libmetis\s-lmetis/c\METISLIB := -L$1/METIS/lib -lmetis" make.inc
  $sed_command -i "/PARMETISLIB\s:=\s-L\${PARMETIS_DIR}\/build\/Linux-x86_64\/libparmetis\s-lparmetis/c\PARMETISLIB := -L$1/PARMETIS/lib -lparmetis" make.inc
Pietro Incardona's avatar
Pietro Incardona committed
229

Pietro Incardona's avatar
Pietro Incardona committed
230
231
232
  $sed_command -i "/I_PARMETIS\s:=\s-I\${PARMETIS_DIR}\/include\s-I\${PARMETIS_DIR}\/metis\/include/c\I_PARMETIS := -I$1/PARMETIS/include -I$1/METIS/include" make.inc
  $sed_command -i "/CC\s\+=\scc/c\CC = mpicc" make.inc
  $sed_command -i "/FORTRAN\s\+=\sftn/c\FORTRAN = mpif90" make.inc
Pietro Incardona's avatar
Pietro Incardona committed
233

Pietro Incardona's avatar
Pietro Incardona committed
234
235
236
237
  if [ x"$dgc_compiler" == x"clang++" ]; then
    $sed_command -i "/CFLAGS\s\+=\s-fast\s-m64\s-std=c99\s-Wall\s-openmp\s\\\/c\CFLAGS =-fpic -O3 -m64 -std=c99 -Wall \$(I_PARMETIS) -DDEBUGlevel=0 -DPRNTlevel=0 -DPROFlevel=0" make.inc
  else
    $sed_command -i "/CFLAGS\s\+=\s-fast\s-m64\s-std=c99\s-Wall\s-openmp\s\\\/c\CFLAGS =-fpic -O3 -m64 -std=c99 -Wall -fopenmp \$(I_PARMETIS) -DDEBUGlevel=0 -DPRNTlevel=0 -DPROFlevel=0" make.inc
Pietro Incardona's avatar
Pietro Incardona committed
238
  fi
Pietro Incardona's avatar
Pietro Incardona committed
239
  $sed_command -i "/\s\$(I_PARMETIS)\s-DDEBUGlevel=0\s-DPRNTlevel=0\s-DPROFlevel=0\s\\\/c\ " make.inc
Pietro Incardona's avatar
Pietro Incardona committed
240
241
242
243
244
245

  make

  if [ $? -eq 0 ]; then
    mkdir $1/SUPERLU_DIST
    mkdir $1/SUPERLU_DIST/include
Pietro Incardona's avatar
Pietro Incardona committed
246
    cp -r lib $1/SUPERLU_DIST
Pietro Incardona's avatar
Pietro Incardona committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    cp SRC/*.h $1/SUPERLU_DIST/include
    configure_options="$configure_options --with-superlu_dist=yes --with-superlu_dist-lib=$1/SUPERLU_DIST/lib/libsuperlu_dist_4.3.a --with-superlu_dist-include=$1/SUPERLU_DIST/include/"
  fi

else
  echo "SUPERLU already installed"
  configure_options="$configure_options --with-superlu_dist=yes --with-superlu_dist-lib=$1/SUPERLU_DIST/lib/libsuperlu_dist_4.3.a --with-superlu_dist-include=$1/SUPERLU_DIST/include/"
fi

## HYPRE installation

if [ ! -d "$1/HYPRE" ]; then
  rm hypre-2.11.0.tar.gz
  rm -rf hypre-2.11.0
  wget http://ppmcore.mpi-cbg.de/upload/hypre-2.11.0.tar.gz
  if [ $? -ne 0 ]; then
    echo -e "\033[91;5;1m FAILED Installation require an Internet connection \033[0m"
    exit 1
  fi
  tar -xf hypre-2.11.0.tar.gz
  cd hypre-2.11.0

  cd src

  ./configure CFLAGS=-fpic  $configure_options_hypre --prefix=$1/HYPRE
272
  make -j $2
Pietro Incardona's avatar
Pietro Incardona committed
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294

  if [ $? -eq 0 ]; then
    make install
    configure_options="$configure_options --with-hypre=yes -with-hypre-dir=$1/HYPRE"
  fi

else
  echo "HYPRE already installed"
  configure_options="$configure_options --with-hypre=yes -with-hypre-dir=$1/HYPRE"
fi
 

rm petsc-lite-3.6.4.tar.gz
rm -rf petsc-3.6.4
wget http://ppmcore.mpi-cbg.de/upload/petsc-lite-3.6.4.tar.gz
if [ $? -ne 0 ]; then
  echo -e "\033[91;5;1m FAILED Installation require an Internet connection \033[0m"
  exit 1
fi
tar -xf petsc-lite-3.6.4.tar.gz
cd petsc-3.6.4

Pietro Incardona's avatar
Pietro Incardona committed
295
echo "./configure --with-cxx-dialect=C++11 --with-mpi-dir=$mpi_dir  $configure_options  --prefix=$1/PETSC --with-debugging=0"
Pietro Incardona's avatar
Pietro Incardona committed
296

Pietro Incardona's avatar
Pietro Incardona committed
297
./configure --with-cxx-dialect=C++11 $petsc_openmp --with-mpi-dir=$mpi_dir  $configure_options --with-mumps-lib="$MUMPS_extra_lib"  --prefix=$1/PETSC --with-debugging=0
Pietro Incardona's avatar
Pietro Incardona committed
298
299
300
301
302
303
make all test
make install

# if empty remove the folder
if [ ! "$(ls -A $1/PETSC)" ]; then
   rm -rf $1/PETSC
304
305
else
   exit 0
Pietro Incardona's avatar
Pietro Incardona committed
306
fi
307