install_PETSC.sh 12.7 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1
2
3
4
#! /bin/bash

# check if the directory $1/PETSC exist

5
6
CXX=$4
CC=$3
incardon's avatar
incardon committed
7
8
9
F77=$5
FC=$6

Pietro Incardona's avatar
Pietro Incardona committed
10
11
12
13
14
if [ -d "$1/PETSC" ]; then
  echo "PETSC already installed"
  exit 0
fi

15
16
# Detect gcc pr clang

Pietro Incardona's avatar
Pietro Incardona committed
17
18
source script/discover_os
discover_os
19

Pietro Incardona's avatar
Pietro Incardona committed
20
21
22
23
24
25
26
27
28
##### if we are on osx we use gsed

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

####
29

Pietro Incardona's avatar
Pietro Incardona committed
30
31
32
33
34
35
36
## If some dependencies has been installed feed them to PETSC

MUMPS_extra_libs=""

configure_options=""
configure_options_scalapack=""
configure_options_superlu=""
37
configure_trilinos_options=" -D TPL_ENABLE_MPI=ON "
Pietro Incardona's avatar
Pietro Incardona committed
38
39
configure_options_hypre=""

incardon's avatar
incardon committed
40
### Here we install OpenBLAS and SUITESPARSE
Pietro Incardona's avatar
Pietro Incardona committed
41
42
43
44
45
46
47
48
49
50
51


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

incardon's avatar
incardon committed
52
53
54
#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
55

incardon's avatar
incardon committed
56
if [ -d "$1/BOOST" ]; then  
Pietro Incardona's avatar
Pietro Incardona committed
57
  configure_options="$configure_options --with-boost=yes --with-boost-dir=$1/BOOST "
58
  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
59
60
61
62
fi

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

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

incardon's avatar
incardon committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
98
99
100
101
102
103
104
105
106
107
108
109
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
110
111

  ### On clang we have no openMP
Pietro Incardona's avatar
Pietro Incardona committed
112
  petsc_openmp=""
113
  if [ x"$CXX" == x"clang++" ]; then
114
    conf_trl_openmp="-D Trilinos_ENABLE_OpenMP=OFF"
115
  elif [ x"$CXX" == x"icpc" ]; then
incardon's avatar
incardon committed
116
117
    
    configure_trilinos_options="$configure_trilinos_options -D Trilinos_ENABLE_Xpetra=OFF -D Trilinos_ENABLE_Amesos2=OFF -D Trilinos_ENABLE_Ifpack2=OFF -D Trilinos_ENABLE_Teko=OFF "
118
119
  else
    conf_trl_openmp="-D Trilinos_ENABLE_OpenMP=ON"
incardon's avatar
incardon committed
120
#    petsc_openmp="--with-openmp=yes"
121
122
123
  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
124

incardon's avatar
incardon committed
125
  make -j $2
Pietro Incardona's avatar
Pietro Incardona committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  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
incardon's avatar
incardon committed
149
  echo "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 ../."
Pietro Incardona's avatar
Pietro Incardona committed
150
  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 ../.
incardon's avatar
incardon committed
151
  make -j $2
Pietro Incardona's avatar
Pietro Incardona committed
152
153
154
155
156
157
158
159
160
161
162
163
  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

incardon's avatar
incardon committed
164
165
166
167
168
169
170
171
172
173
174
175
if [ x"$CXX" != x"icpc" ]; then
  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
176
 
incardon's avatar
incardon committed
177
    # Installation for linux
Pietro Incardona's avatar
Pietro Incardona committed
178

incardon's avatar
incardon committed
179
180
181
    $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
182

incardon's avatar
incardon committed
183
184
    $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
185

incardon's avatar
incardon committed
186
187
188
    $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
189

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

incardon's avatar
incardon committed
192
193
    $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
incardon's avatar
incardon committed
194

incardon's avatar
incardon committed
195
    make -j $2
Pietro Incardona's avatar
Pietro Incardona committed
196
  
incardon's avatar
incardon committed
197
198
    if [ $? -eq 0 ]; then
      ## Copy LIB and include in the target directory
Pietro Incardona's avatar
Pietro Incardona committed
199

incardon's avatar
incardon committed
200
201
202
      mkdir $1/MUMPS
      cp -r include $1/MUMPS
      cp -r lib $1/MUMPS
incardon's avatar
incardon committed
203

incardon's avatar
incardon committed
204
205
      MUMPS_extra_lib="--with-mumps-lib=\"$1/MUMPS/lib/libdmumps.a $1/MUMPS/lib/libmumps_common.a $1/MUMPS/lib/libpord.a\""
      configure_options="$configure_options --with-mumps=yes  --with-mumps-include=$1/MUMPS/include"
incardon's avatar
incardon committed
206

incardon's avatar
incardon committed
207
208
209
210
211
    fi
  else
    echo "MUMPS already installed"
    MUMPS_extra_lib="--with-mumps-lib=\"$1/MUMPS/lib/libdmumps.a $1/MUMPS/lib/libmumps_common.a $1/MUMPS/lib/libpord.a\""
    configure_options="$configure_options --with-mumps=yes --with-mumps-lib=\"$MUMPS_extra_lib\"  --with-mumps-include=$1/MUMPS/include"
Pietro Incardona's avatar
Pietro Incardona committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  fi
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
228
  # Installation for linux
Pietro Incardona's avatar
Pietro Incardona committed
229

Pietro Incardona's avatar
Pietro Incardona committed
230
231
232
233
  $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
234

Pietro Incardona's avatar
Pietro Incardona committed
235
236
  $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
237

Pietro Incardona's avatar
Pietro Incardona committed
238
239
240
  $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
241

incardon's avatar
incardon committed
242
  if [ x"$CXX" == x"clang++" ]; then
Pietro Incardona's avatar
Pietro Incardona committed
243
244
245
    $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
246
  fi
Pietro Incardona's avatar
Pietro Incardona committed
247
  $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
248
249
250
251
252
253

  make

  if [ $? -eq 0 ]; then
    mkdir $1/SUPERLU_DIST
    mkdir $1/SUPERLU_DIST/include
Pietro Incardona's avatar
Pietro Incardona committed
254
    cp -r lib $1/SUPERLU_DIST
Pietro Incardona's avatar
Pietro Incardona committed
255
    cp SRC/*.h $1/SUPERLU_DIST/include
256
257
258
259
260
    if [ x"$CXX" == x"icpc" ]; then
      configure_options="$configure_options"
    else
      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
Pietro Incardona's avatar
Pietro Incardona committed
261
262
263
264
  fi

else
  echo "SUPERLU already installed"
265
266
267
268
269
  if [ x"$CXX" == x"icpc" ]; then
    configure_options="$configure_options"
  else
    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
Pietro Incardona's avatar
Pietro Incardona committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
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

287
  ./configure CC=mpicc CXX=mpic++ CFLAGS=-fpic  $configure_options_hypre --prefix=$1/HYPRE
incardon's avatar
incardon committed
288
  make -j $2
Pietro Incardona's avatar
Pietro Incardona committed
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

  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

incardon's avatar
incardon committed
311
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
312

313
./configure --with-cxx-dialect=C++11 $petsc_openmp --with-mpi-dir=$mpi_dir $MUMPS_extra_lib  $configure_options  --prefix=$1/PETSC --with-debugging=0
Pietro Incardona's avatar
Pietro Incardona committed
314
315
316
317
318
319
make all test
make install

# if empty remove the folder
if [ ! "$(ls -A $1/PETSC)" ]; then
   rm -rf $1/PETSC
incardon's avatar
incardon committed
320
321
else
   exit 0
Pietro Incardona's avatar
Pietro Incardona committed
322
fi
incardon's avatar
incardon committed
323