pre_req 11.7 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1
2
#! /bin/bash

3
4
5
6
function haveProg() {
    [ -x "$(command -v $1)" ]
}

incardon's avatar
incardon committed
7
8
function pre_req()
{
Pietro Incardona's avatar
Pietro Incardona committed
9
source script/discover_package_manager
incardon's avatar
incardon committed
10
source script/discover_os
incardon's avatar
incardon committed
11
source script/solve_gpp
incardon's avatar
incardon committed
12
source script/solve_gfortran
incardon's avatar
incardon committed
13
14
15
16
source script/solve_cmake
source script/solve_git
source script/solve_wget
source script/solve_brew
Pietro Incardona's avatar
Pietro Incardona committed
17
source script/solve_gsed
incardon's avatar
incardon committed
18
source script/solve_libtool
Pietro Incardona's avatar
Pietro Incardona committed
19
20
source script/detect_gcc
source script/detect_osx
21
source script/show_solutions
Pietro Incardona's avatar
Pietro Incardona committed
22
source script/detect_fortran
Pietro Incardona's avatar
Pietro Incardona committed
23

incardon's avatar
incardon committed
24
discover_os
Pietro Incardona's avatar
Pietro Incardona committed
25
discover_package_manager $platform
Incardona Pietro's avatar
Incardona Pietro committed
26
pcman=$discover_package_manager_ret
Pietro Incardona's avatar
Pietro Incardona committed
27

Incardona Pietro's avatar
Incardona Pietro committed
28
if [ x"$platform" = x"osx" -a x"$pcman" = x""  ]; then
incardon's avatar
incardon committed
29
30
  echo -e "\033[30;43;5;1m WARNING \033[0m No package manager has been found on this system"
  solve_brew $platform
Incardona Pietro's avatar
Incardona Pietro committed
31
32
33
34
35
36

  discover_package_manager $platform
  pcman=$discover_package_manager_ret
  if [ x"$pcman" != x"brew" ]; then
    echo -e "brew \033[91;5;1m FAILED \033[0m"
  fi
Pietro Incardona's avatar
Pietro Incardona committed
37
38
fi

39
### Additional package required for apt-get based distros
40
if [ x"$platform" = x"linux" -a x"$pcman" = x"apt-get"  ]; then
41
42
43
44
45
46
47
48
49
50
  dpkg-query -l libbz2-dev
  ret1=$?
  dpkg-query -l python-dev
  ret2=$?
  dpkg-query -l libxml2-dev
  ret3=$?
  dpkg-query -l libxslt-dev
  ret4=$?
  if [ $ret1 -ne 0 -o $ret2 -ne 0 -o $ret3 -ne 0 -o $ret4 -ne 0 ]; then
    echo "OpenFPM require additional packages in order to install correctly"
51
    commands[0]="sudo $pcman install libbz2-dev python-dev libxml2-dev libxslt-dev"
52
53
54
55
    possible_solutions "${commands[@]}"
  fi
fi

56
57
58
59
60
61
### Additional package required for yum based distros
if [ x"$platform" = x"linux" -a x"$pcman" = x"yum"  ]; then
  rpm -V bzip2-devel
  ret1=$?
  rpm -V python-devel
  ret2=$?
62
63
64
65
66
  if [ $ret2 -ne 0 ]; then
    echo "Cheking python2-devel"
    rpm -V python2-devel
    ret2=$?
  fi
67
68
69
70
71
72
73
74
75
76
77
78
  rpm -V libxml2-devel
  ret3=$?
  rpm -V libxslt-devel
  ret4=$?
  if [ $ret1 -ne 0 -o $ret2 -ne 0 -o $ret3 -ne 0 -o $ret4 -ne 0 ]; then
    echo "OpenFPM require additional packages in order to install correctly"
    commands[0]="su -c \"$pcman install bzip2-devel python-devel libxml2-devel libxslt-devel\""
    commands[1]="sudo $pcman install bzip2-devel python-devel libxml2-devel libxslt-devel"
    possible_solutions "${commands[@]}"
  fi
fi

79
80
#### if we are on OSX we install gnu-sed

Pietro Incardona's avatar
Pietro Incardona committed
81
if [ x"$platform" == x"osx" ]; then
82
83
84
  if haveProg gsed; then
    echo -e "gsed\033[92;1m SUCCESS \033[0m"
  else
85
86
87
    echo >&2
    echo -e "gsed\033[91;5;1m FAILED \033[0m"
    echo "OpenFPM require gnu-sed but it's not installed, searching a solution... "
88
    solve_gsed $platform
89
90
91
    if haveProg gsed; then
      echo -e "gsed\033[92;1m SUCCESS \033[0m"
    else
92
93
94
95
96
97
      echo -e "gsed\033[91;5;1m FAILED \033[0m"
      exit 1
    fi
  fi
fi

98
99
100
101
## cmake
if haveProg cmake; then
  echo -e "cmake\033[92;1m SUCCESS \033[0m"
else
102
  echo >&2
incardon's avatar
incardon committed
103
104
  echo -e "cmake\033[91;5;1m FAILED \033[0m"
  echo "OpenFPM require cmake but it's not installed, searching a solution... "
incardon's avatar
incardon committed
105
  solve_cmake $platform
106
107
108
  if haveProg cmake; then
    echo -e "cmake\033[92;1m SUCCESS \033[0m"
  else
incardon's avatar
incardon committed
109
    echo -e "cmake\033[91;5;1m FAILED \033[0m"
110
111
112
    exit 1
  fi
fi
113
114
115
116
## wget
if haveProg wget; then
  echo -e "wget \033[92;1m SUCCESS \033[0m"
else
Pietro Incardona's avatar
Pietro Incardona committed
117
118
119
  echo >&2
  echo -e "wget\033[91;5;1m FAILED \033[0m"
  echo "OpenFPM require wget but it's not installed, searching a solution... "
incardon's avatar
incardon committed
120
  solve_wget $platform
121
122
123
  if haveProg wget; then
    echo -e "wget\033[92;1m SUCCESS \033[0m"
  else
Pietro Incardona's avatar
Pietro Incardona committed
124
125
126
127
    echo -e "wget\033[91;5;1m FAILED \033[0m"
    exit 1
  fi
fi
128
129
130
131
## git
if haveProg git; then
  echo -e "git \033[92;1m SUCCESS \033[0m"
else
Pietro Incardona's avatar
Pietro Incardona committed
132
133
134
  echo >&2
  echo -e "git\033[91;5;1m FAILED \033[0m"
  echo "OpenFPM require git but it's not installed, searching a solution... "
incardon's avatar
incardon committed
135
  solve_git $platform
136
137
138
  if haveProg git; then
    echo -e "git\033[92;1m SUCCESS \033[0m"
  else
Pietro Incardona's avatar
Pietro Incardona committed
139
140
141
142
    echo -e "git\033[91;5;1m FAILED \033[0m"
    exit 1
  fi
fi
Pietro Incardona's avatar
Pietro Incardona committed
143
#### Detecting g++
144
detect_compiler
Pietro Incardona's avatar
Pietro Incardona committed
145
if [ $dgc_ret -eq 0 ]; then
incardon's avatar
incardon committed
146
  echo -e "g++ \033[91;5;1m FAILED \033[0m"
Pietro Incardona's avatar
Pietro Incardona committed
147
  solve_gpp $platform
Pietro Incardona's avatar
Pietro Incardona committed
148
  detect_compiler
Pietro Incardona's avatar
Pietro Incardona committed
149
150
  if [ $dgc_ret -eq 0 ]; then
    exit 1
Pietro Incardona's avatar
Pietro Incardona committed
151
  fi
Pietro Incardona's avatar
Pietro Incardona committed
152
153
154
155
156
157
elif [ $dgc_ret -eq 2 ]; then
  detect_osx $platform
  if [ $dosx_ret -eq 1 ]; then
    echo -e "\033[30;43;5;1m------------------------------- WARNING --------------------------------\033[0m"
    echo "g++ seem to be present, but we failed to detect the version. Your system $dosx_major.$dosx_middle.$dosx_minor seem to be recent enough, so we will continue the installation"
    sleep 10    
Pietro Incardona's avatar
Pietro Incardona committed
158
  fi
Pietro Incardona's avatar
Pietro Incardona committed
159
160
fi

Pietro Incardona's avatar
Pietro Incardona committed
161
162
163
#### Detection gfortran
detect_fortran gfortran
if [ $dgc_ret -eq 0 ]; then
incardon's avatar
incardon committed
164
  echo -e "gfortran\033[91;5;1m FAILED \033[0m"
Pietro Incardona's avatar
Pietro Incardona committed
165
166
167
168
169
170
171
172
173
  solve_gfortran $platform
  detect_fortran $compiler_fortran
  if [ $dgc_ret -eq 0 ]; then
    exit 1
  fi
else
  echo -e "gfortran \033[92;1m SUCCESS \033[0m"
fi

Pietro Incardona's avatar
Pietro Incardona committed
174
MPI_valid=no
175
if haveProg mpirun; then
Pietro Incardona's avatar
Pietro Incardona committed
176
177
178
179
180
181
182
183
184
  # Here we check if we are running openmpi  mpich or unknown

  version=$(mpirun --version 2>&1 | grep mpirun | sed 's/.*Open MPI.*/openmpi/g')
  if [ x"$version" == x"" ]; then
    version=$(mpirun --version 2>&1 | grep HYDRA | sed 's/HYDRA.*/mpich/g')
  fi

  if [ x"$version" == x"openmpi" ]; then

Pietro Incardona's avatar
Pietro Incardona committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
    # Check if we are compiling with GPU support

    if [ x"$gpu_support" == x"1" ]; then
	
	is_openmpi_cuda_aware

	if [ x"$cuda_mpi_support" == x"false" ]; then
		echo -e " \033[91;5;1m OpenMPI has been compiled without GPU support \033[0m"
		echo -e "\033[1m OpenFPM use GPUDirect RDMA to move data from one GPU to another GPU (intranode and extranode) without moving the data on host. This feature requires that OpenMPI is compiled with CUDA support. OpenFPM can works also without this feature using GPUDirect old version (1.0). In practice it requires that MPI work with host pinned memory allocated with CUDA. This feature has been introduced with CUDA 5.0 in 2010. At best of our knowledge this feature should work without special compilation options for OpenMPI. On the other end we found several problems with GPUDirect v1.0 and Infiniband cards, when OpenMPI is not compiled with CUDA support. If you are on a super-computer or a machine you did not set-up, we suggest to re-install OpenMPI with CUDA support using the same options used to compile the one detected (option 1). Alternatively you can reinstall OpenMPI using the default options (option 2), or use the OpenMPI detected (option 3) \033[0m"

		unset commands
  		commands[0]="Reinstall MPI and mirror the one detected"
		commands[1]="Reinstall MPI, use the default arguments"
		commands[2]="Continue with the detected one"
  		possible_solutions_no_execute "${commands[@]}"

201
202
203
		# Remove old MPI
		rm -rf $i_dir/MPI

Pietro Incardona's avatar
Pietro Incardona committed
204
205
		if [ x"$possible_solutions_ret" == x"0" ]; then
			get_openmpi_compilation_options
206
			call_test_working_mpi_options=1
Pietro Incardona's avatar
Pietro Incardona committed
207
		fi
208
209
	else
		echo "OpenMPI is CUDA aware"
Pietro Incardona's avatar
Pietro Incardona committed
210
211
212
	fi
    fi

Pietro Incardona's avatar
Pietro Incardona committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    major=$(mpirun --version 2>&1 | grep mpirun | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1/g')
    middle=$(mpirun --version 2>&1 | grep mpirun | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\2/g')
    minor=$(mpirun --version 2>&1 | grep mpirun | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\3/g')
    if [ $major -gt 1 ]; then
      echo -e "openmpi $major.$middle.$minor \033[92;1m SUCCESS \033[0m"
      MPI_valid=yes
    elif [ $major -lt 1 ]; then
      echo -e "openmpi $major.$middle.$minor \033[33;5;1m WARNING \033[0m is too old, 1.8.1 at least required, (Automatic fix activated)"
    elif [ $middle -gt 8  ]; then
      echo -e "openmpi $major.$middle.$minor \033[92;1m SUCCESS \033[0m"
      MPI_valid=yes
    elif [ $middle -lt 8 ]; then
      echo -e "opnmpi $major.$middle.$minor \033[33;5;1m WARNING \033[0m is too old, 1.8.1 at least required (Automatic fix activated)"
    elif [ $minor -gt 0  ]; then
      echo -e "openmpi $major.$middle.$minor \033[92;1m SUCCESS \033[0m"
      MPI_valid=yes
    else
      echo -e "openmpi $major.$middle.$minor \033[33;5;1m WARNING \033[0m is too old, 1.8.1 at least required, (Automatic fix activated)"
    fi
  elif [ x"$version" == x"mpich" ]; then 
    major=$(mpirun --version 2>&1 | grep Version | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1/g')
    middle=$(mpirun --version 2>&1 | grep Version | sed 's/.*\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\2/g')
    if [ $major -gt 3 ]; then
      echo -e "mpich $major.$middle \033[92;1m SUCCESS \033[0m"
      MPI_valid=yes
    elif [ $major -lt 3 ]; then
      echo -e "mpich $major.$middle \033[33;5;1m WARNING \033[0m is too old, 3.2 at least required, (Automatic fix activated)"
    elif [ $middle -gt 1  ]; then
      echo -e "mpich $major.$middle \033[92;1m SUCCESS \033[0m"
      MPI_valid=yes
    elif [ $middle -lt 1 ]; then
      echo -e "mpich $major.$middle \033[33;5;1m WARNING \033[0m is too old, 3.2 at least required (Automatic fix activated)"
    else
      echo -e "mpich $major.$middle \033[33;5;1m WARNING \033[0m is too old, 3.2 at least required, (Automatic fix activated)"
    fi
Pietro Incardona's avatar
Pietro Incardona committed
248
  else
Pietro Incardona's avatar
Pietro Incardona committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266

    #### Unkown version of MPI print a warning

    echo -e "\033[43;30;1;5mWARNING: \033[0m Found an unkown version of MPI, OpenFPM work with any MPI version that implement MPI-3.0 interface. If you know that the installed MPI implement the MPI-3.0 interface choose 1) continue. If you are not sure, or you do not even know what this message mean choose 2) install OpenMPI"

    echo "1) Continue"
    echo "2) Install OpenMPI"

    choose=1
    if [ $sq -eq 0 ]; then
      read choose
    fi

    if [ $choose -eq 1 ]; then
      MPI_valid=yes
    fi

  fi
267
268
else
  echo -e "No MPI"
Pietro Incardona's avatar
Pietro Incardona committed
269
fi
Pietro Incardona's avatar
Pietro Incardona committed
270
271
272
273
274
275
276
277

if [ x"$MPI_valid" == x"yes"  ]; then
  ## Check for potential problem in the MPI installation

  if [ -d $1/MPI ]; then
    where_mpi=$(which mpic++)

    if [ x"$where_mpi" != x"$1/MPI/bin/mpic++" ]; then
278
        echo -e "\033[91;5;1m MPI instalation: CONFLICT \033[0m"
Pietro Incardona's avatar
Pietro Incardona committed
279
280
281
        echo "Performing a \"which mpic++\", we found that you have installed one system wide MPI "
        echo -e "\033[1m $where_mpi \033[0m"
        echo "this MPI has priority over OpenFPM MPI installation in: "
282
283
        echo -e "\033[1m $1/MPI/bin/mpic++ \033[0m"
        echo "Such configuration is not supported, one MPI must be uniquely selected"
Pietro Incardona's avatar
Pietro Incardona committed
284
285
286
287
288
289
290
        echo "The possible solutions are: "
        echo -e "\033[1m 1) Set your PATH to give priority to $1/MPI/bin \033[0m"
        echo -e "\033[1m 2) Eliminate OpenFPM MPI removing $1/MPI \033[0m"
        echo -e "\033[1m 3) Eliminate the system wide MPI \033[0m"
      exit 1
    fi
  fi
291
292
293
294
295

  #### Detect a potential dangerous situation ###
  #### In which g++ is different from mpic++ ###

  output_mpi=$(mpic++ --version)
296
  output_gcc=$($dgc_compiler --version)
297
298
299

  if [ x"$output_mpi" != x"$output_gcc" ]; then
    echo -e "\033[91;5;1m MPI dangerous installation \033[0m"
300
301
302
303
304
    echo -e "Performing a \033[1m  \"mpic++ --version\" \033[0m, we detect that your installed mpic++ does not wrap the standard command g++"
    echo "In general we strongly disencourage to override the default compiler(s), this configuration not only is not supported by OpenFPM, but can lead potentialy to several problems at system level. For the following reasons"
    echo -e "\033[1m 1) All system wide dependencies become potentially useless \033[0m"
    echo -e "\033[1m 2) A package maneger (apt-get or brew) installing a packege from source can potentialy generate incompatible system packages \033[0m"
    echo -e "\033[1m 3) It is not easy to discover which compiler has been used to compile one dependency \033[0m"
305
    echo -e "For just the time of the installation the installer will realign mpic++ to g++, unfortunately this could be not enough to ensure that all the dependencies has been compiled with the same compiler"
306
307
    echo -e "\033[1m Installation will resume in 20 seconds \033[0m"
    export OMPI_CXX=g++
308
309
310
    sleep 20
  fi

311
  output_mpi=$(mpic++ --version)
Pietro Incardona's avatar
Pietro Incardona committed
312
  output_gcc=$($dgc_compiler --version)
313
314
315
316
317
318

  if [ x"$output_mpi" != x"$output_gcc" ]; then
    echo -e "\033[91;5;1m MPI dangerous installation \033[0m"
    echo -e "\033[1m The realign operation failed the installation will continue \033[0m"
    sleep 10
  fi
Pietro Incardona's avatar
Pietro Incardona committed
319
320
fi

incardon's avatar
incardon committed
321
}
Pietro Incardona's avatar
Pietro Incardona committed
322