install_PETSC.sh 4.69 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

incardon's avatar
incardon committed
10
if [ -d "$1/PETSC" -a -f "$1/PETSC/include/petsc.h" ]; then
11
  echo "PETSC is already installed"
Pietro Incardona's avatar
Pietro Incardona committed
12 13 14
  exit 0
fi

incardon's avatar
incardon committed
15 16 17 18 19 20
# Detect gcc pr clang

source script/discover_os
source script/solve_python
discover_os

incardon's avatar
incardon committed
21
function test_configure_options() {
22
  cd petsc-3.10.2
23
  $python_command ./configure COPTFLAGS="-O3 -g" CXXOPTFLAGS="-O3 -g" FOPTFLAGS="-O3 -g" $ldflags_petsc  --with-cxx-dialect=C++11 $petsc_openmp --with-mpi-dir=$mpi_dir $configure_options2 --with-debugging=0
24
  error=$?
25
  cd ..
incardon's avatar
incardon committed
26 27
}

incardon's avatar
incardon committed
28 29 30 31
function haveProg() {
    [ -x "$(command -v $1)" ]
}

32 33 34 35 36 37 38
if haveProg python2; then
  python_command=python2
else
  python_command=python
fi


39 40
##### if we are on osx we use gsed

41
ldflags_petsc=
42 43
if [ x"$platform" == x"osx" ]; then
  sed_command=gsed
44
  ldflags_petsc=
45 46
else
  sed_command=sed
47
  ldflags_petsc=
48 49
fi

50 51 52 53 54 55 56 57 58 59
#### Download and uncompress petsc

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

61
####
62

Pietro Incardona's avatar
Pietro Incardona committed
63 64 65 66 67 68 69
## If some dependencies has been installed feed them to PETSC

MUMPS_extra_libs=""

configure_options=""


incardon's avatar
incardon committed
70
configure_options="$configure_options --download-metis --download-parmetis"
Pietro Incardona's avatar
Pietro Incardona committed
71

72
if [ -d "$1/BOOST" ]; then
incardon's avatar
incardon committed
73 74

  ### We check incrementaly the options
Pietro Incardona's avatar
Pietro Incardona committed
75 76 77 78
  configure_options="$configure_options --with-boost=yes --with-boost-dir=$1/BOOST "
fi

if [ -d "$1/MPI" ]; then
79 80 81
  mpi_dir="$1/MPI"
else
  mpi_dir=$(dirname "$(dirname "$(which mpic++)")")
Pietro Incardona's avatar
Pietro Incardona committed
82 83 84
fi

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

incardon's avatar
incardon committed
88
if [ ! -d "$1/OPENBLAS" ]; then
89
  CXX="$CXX" CC="$CC" FC="$FC" F77="$F77" ./script/install_OPENBLAS.sh $1
incardon's avatar
incardon committed
90 91 92 93 94 95 96
  if [ $? -eq 0 ]; then
    configure_options="$configure_options --with-blas-lib=$1/OPENBLAS/lib/libopenblas.a --with-lapack-lib=$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"
fi

97
if [ -d "$1/SUITESPARSE"  -a -f "$1/SUITESPARSE/include/umfpack.h" ]; then
98
  CXX="$CXX" CC="$CC" FC="$FC" F77="$F77" ./script/install_SUITESPARSE.sh $1 $2
incardon's avatar
incardon committed
99
fi
incardon's avatar
incardon committed
100

incardon's avatar
incardon committed
101
#### OK here we check if we can configure work with SUITESPARSE
102 103 104 105 106 107 108 109 110
if [ -d "$1/SUITESPARSE"  -a -f "$1/SUITESPARSE/include/umfpack.h" ]; then
  echo "Testing if PETSC work with SUITESPARSE"
  configure_options2="$configure_options --with-suitesparse=yes --with-suitesparse-dir=$1/SUITESPARSE "
  test_configure_options

  if [ $error -eq 0 ]; then
    echo "SUITESPARSE work with PETSC"
    configure_options="$configure_options --with-suitesparse=yes --with-suitesparse-dir=$1/SUITESPARSE "
  fi
incardon's avatar
incardon committed
111 112
fi

incardon's avatar
incardon committed
113 114 115 116 117 118 119
configure_options="$configure_options --download-scalapack --download-mumps"
configure_options="$configure_options --download-superlu_dist"
configure_options="$configure_options --download-hypre"

rm petsc-lite-3.10.2.tar.gz
rm -rf petsc-3.10.2
wget http://ppmcore.mpi-cbg.de/upload/petsc-lite-3.10.2.tar.gz
Pietro Incardona's avatar
Pietro Incardona committed
120
if [ $? -ne 0 ]; then
121
  echo -e "\033[91;5;1m FAILED! Installation requires an Internet connection \033[0m"
Pietro Incardona's avatar
Pietro Incardona committed
122 123
  exit 1
fi
incardon's avatar
incardon committed
124 125
tar -xf petsc-lite-3.10.2.tar.gz
cd petsc-3.10.2
Pietro Incardona's avatar
Pietro Incardona committed
126

incardon's avatar
incardon committed
127
if [ x"$CXX" != x"icpc" ]; then
Pietro Incardona's avatar
Pietro Incardona committed
128

incardon's avatar
incardon committed
129
  echo "./configure COPTFLAGS="-O3 -g" CXXOPTFLAGS="-O3 -g" FOPTFLAGS="-O3 -g" $ldflags_petsc --with-cxx-dialect=C++11 $petsc_openmp  --with-mpi-dir=$mpi_dir $configure_options  --prefix=$1/PETSC --with-debugging=0"
incardon's avatar
incardon committed
130 131 132 133

  function haveProg() {
      [ -x "$(command -v $1)" ]
  }
134

incardon's avatar
incardon committed
135 136 137 138 139
  if [ x"$platform" != x"cygwin" ]; then
  	$python_command ./configure COPTFLAGS="-O3 -g" CXXOPTFLAGS="-O3 -g" FOPTFLAGS="-O3 -g" $ldflags_petsc  --with-cxx-dialect=C++11 $petsc_openmp --with-mpi-dir=$mpi_dir $configure_options --prefix=$1/PETSC --with-debugging=0
  else
	echo "Sorry PETSC installation in not supported on CYGWIN"
  fi
Pietro Incardona's avatar
Pietro Incardona committed
140

incardon's avatar
incardon committed
141 142 143 144 145 146 147 148 149 150 151
else

  echo "./configure COPTFLAGS="-O3 -g" CXXOPTFLAGS="-O3 -g" FOPTFLAGS="-O3 -g" $ldflags_petsc --with-cxx-dialect=C++11 $petsc_openmp  --with-mpi-dir=$mpi_dir $configure_options  --prefix=$1/PETSC --with-debugging=0"

  function haveProg() {
      [ -x "$(command -v $1)" ]
  }

  $python_command ./configure COPTFLAGS="-O3 -g" CXXOPTFLAGS="-O3 -g" FOPTFLAGS="-O3 -g" $ldflags_petsc  --with-cxx-dialect=C++11 $petsc_openmp --with-mpi-dir=$mpi_dir $configure_options --prefix=$1/PETSC --with-debugging=0

fi
incardon's avatar
incardon committed
152

incardon's avatar
incardon committed
153
make all
Pietro Incardona's avatar
Pietro Incardona committed
154 155 156 157 158
make install

# if empty remove the folder
if [ ! "$(ls -A $1/PETSC)" ]; then
   rm -rf $1/PETSC
159
else
160
   #Mark the installation
incardon's avatar
incardon committed
161
   echo 2 > $1/PETSC/version
162
   exit 0
Pietro Incardona's avatar
Pietro Incardona committed
163
fi
164