/
configure
executable file
·427 lines (389 loc) · 13.2 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/bin/bash
# Configure script for R package generation
#
#
#
#Sys.setenv(PKG_CONFIG_PATH=paste(Sys.getenv("PKG_CONFIG_PATH"),paste(.libPaths(),"exageostat/lib/pkgconfig",sep='/',collapse=':'),sep=':'))
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${R_HOME}/exageostat/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$R_LIBS_USER/exageostat/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$R_LIBS/exageostat/lib/pkgconfig
#Get the number of CPUs
cpucores=`getconf _NPROCESSORS_ONLN`
#cpucores=1
#VARIABLES
MAKE=${MAKE:-make -j $(cpucores) -l $((cpucores + 1))}
BASEDIR=$(pwd)
TMPDIR=$BASEDIR/_$$
BUILD_DEPENDENCIES='true'
err=0
CUDAVALUE="OFF"
MPIVALUE="OFF"
mkdir -p $TMPDIR
SETUP_DIR=${R_PACKAGE_DIR:-''}
print_usage() {
echo "usage: $0 [--enable-mpi|--disable-mpi] [--prefix /path/to/install]"
}
while [ -n "$1" ]
do
case "$1" in
--enable-cuda)
CUDAVALUE="ON"
shift
;;
--enable-mpi)
MPIVALUE="ON"
shift
;;
--disable-mpi)
MPIVALUE="OFF"
shift
;;
--build-deps)
BUILD_DEPENDENCIES='true'
shift
;;
--no-build-deps)
BUILD_DEPENDENCIES='false'
shift
;;
--prefix)
shift
SETUP_DIR=$1
# Set this paths as rpath during compilation
rpaths="-Wl,-rpath=$SETUP_DIR/lib -L$SETUP_DIR/lib "
echo "LDFLAGS += $rpaths " >> $BASEDIR/src/Makefile
shift
;;
--help|-h)
print_usage
exit 0
;;
*)
print_usage
exit 1
;;
esac
done
if [ -z "$SETUP_DIR" ]; then
# Use RLIBS for setup dir
arr=(`Rscript -e '.libPaths()' | awk '{printf "%s ",$2}'`)
for i in ${!arr[*]};
do
dir=`echo ${arr[$i]}|tr -d \"`
if [ -d "$dir" ] && [ -w "$dir" ]
then
SETUP_DIR="$dir/exageostat"
break
fi
done
fi
mkdir -p $SETUP_DIR
if [ -z "$SETUP_DIR" ]
then
echo "Check your .libPaths() in R. Could not find a writable directory."
exit 1;
fi
PREFIX=$SETUP_DIR
############################## Check OS
echo "Finding the current os type"
echo
osType=$(uname)
case "$osType" in
"Darwin")
{
echo "Running on Mac OSX."
CURRENT_OS="OSX"
LIBEXT="dylib"
export DYLD_LIBRARY_PATH=$PREFIX/lib:$DYLD_LIBRARY_PATH
} ;;
"Linux")
{
echo "Running on LINUX."
CURRENT_OS="LINUX"
LIBEXT="so"
export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
} ;;
*)
{
echo "Unsupported OS, exiting"
exit
} ;;
esac
# check submodules just in case
#git submodule update --init --recursive 2>&1 >/dev/null || true
##### check and build dependencies
# prepare environment
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
if [ -n "$MKLROOT" ] && [ -d "$MKLROOT" ]; then
echo "mkl_dir directory exists!"
echo "Great... continue set-up"
source ${MKLROOT}/bin/mklvars.sh intel64
DEFINE_BLAS_LIBS_CMAKE="-DBLAS_LIBRARIES='-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl'"
#DEFINE_BLAS_LIBS_CMAKE="-DBLAS_LIBRARIES='-L${MKLROOT}/lib\ -Wl,-rpath,${MKLROOT}/lib\ -lmkl_intel_lp64\ -lmkl_sequential\ -lmkl_core\ -lpthread\ -lm\ -ldl'"
XFLAG="-DBLA_VENDOR=Intel"
else
echo "MKL not found, trying to compile and use OpenBLAS"
XFLAG="-DBLA_VENDOR=Open"
USE_OPENBLAS='true'
fi
#set pkgconfig path including possible installation dir
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$SETUP_DIR/lib/pkgconfig
# openblas
if [ "true" == "$USE_OPENBLAS" ]
then
_OPENBLAS='false'
if pkg-config --exists openblas
then
#check for lapacke.h
_LOCATION=`pkg-config --variable=includedir openblas`
if stat "${_LOCATION}/lapacke.h" >/dev/null 2>&1
then
_LOCATION=`pkg-config --variable=libdir openblas`
echo "OpenBLAS FOUND in [$_LOCATION]"
_OPENBLAS='true'
fi
fi
if [ "false" == "${_OPENBLAS}" ]
then
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building OpenBLAS..."
cd $TMPDIR
wget https://github.com/xianyi/OpenBLAS/archive/v0.3.7.tar.gz -O - | tar -zx
cd OpenBLAS-0.3.7
$MAKE -j PREFIX=$PREFIX >/dev/null|| $MAKE PREFIX=$PREFIX || { echo 'OpenBLAS installation failed' ; exit 1; }
$MAKE install PREFIX=$PREFIX
export CPATH=$PREFIX/include:$CPATH
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
OPENBLAS_CFLAGS=`pkg-config --variable=includedir openblas`
OPENBLAS_LIBS=`pkg-config --variable=libdir openblas`
PKG_CPPFLAGS=`pkg-config --variable=includedir openblas`
PKG_LIBS=-l$PREFIX/lib/libopenblas.so
echo "========================="
echo $PKG_LIBS
echo "+++++++++++++++++++++++++="
#DEFINE_BLAS_LIBS_CMAKE="-DBLAS_DIR='${PREFIX}' -DCBLAS_DIR='${PREFIX}' -DLAPACK_DIR='${PREFIX}' -DLAPACKE_DIR='${PREFIX}' -DTMG='${PREFIX}'"
#export OPENBLAS_CFLAGS=-I$PREFIX/include
#export OPENBLAS_LIBS=-L$PREFIX/lib
#export BLAS_OPENBLAS_CFLAGS=-I{$PREFIX/include
export BLAS_OPENBLAS_LIBS=-l$PREFIX/lib/libopenblas.so
#cp $PREFIX/lib/libopenblas.so $BASEDIR/src
#export BLAS_LIBS=-L{$PREFIX}/lib
else
echo "####################"
echo "OpenBLAS NOT FOUND"
echo "Please download it from: https://github.com/xianyi/OpenBLAS/releases"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
fi
# gsl
if pkg-config --exists --atleast-version=2 gsl
then
_LOCATION=`pkg-config --variable=prefix gsl`
echo "gsl FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building GSL..."
cd $TMPDIR
wget https://ftp.gnu.org/gnu/gsl/gsl-2.4.tar.gz -O - | tar -zx
cd gsl-2.4
./configure --prefix=$PREFIX
$MAKE || $MAKE VERBOSE=1 || { echo 'GSL installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "gsl NOT FOUND"
echo "Please download it from: https://ftp.gnu.org/gnu/gsl/gsl-2.4.tar.gz"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
echo "==========================================="
#EXAGEOSTAT_CONFIG=`Rscript -e '.libPaths()' | awk '{printf "%s/exageostat/lib/pkgconfig:",substr($2,2,length($2)-2)}'`
echo ${R_HOME}
echo "==========================================="
echo $R_LIBS_USER
echo "==========================================="
echo $R_LIBS
echo "==========================================="
#Rscript -e '.libPaths()'
echo $PKG_LIBS
echo "==========================================="
echo $PKG_CXXFLAGS
echo "==========================================="
echo $PKG_CONFIG_PATH
echo "==========================================="
echo $PKG_CPPFLAGS
echo "==========================================="
nm $PREFIX/lib/libopenblas.so | grep "LAPACKE_slarfb_work"
echo "==========================================="
# nlopt
if pkg-config --exists --atleast-version=2.4 nlopt
then
_LOCATION=`pkg-config --variable=prefix nlopt`
echo "nlopt FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building NLOPT..."
cd $TMPDIR
wget http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz -O - | tar -zx
cd nlopt-2.4.2
./configure --enable-shared --without-guile --prefix=$PREFIX
$MAKE || $MAKE VERBOSE=1 || { echo 'NLOPT installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "nlopt NOT FOUND"
echo "Please download it from: http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# hwloc
if pkg-config --exists hwloc
then
_LOCATION=`pkg-config --variable=prefix hwloc`
echo "hwloc FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building Hwloc..."
cd $TMPDIR
wget https://www.open-mpi.org/software/hwloc/v1.11/downloads/hwloc-1.11.5.tar.gz -O - | tar -zx
cd hwloc-1.11.5
./configure --prefix=$PREFIX
$MAKE || $MAKE VERBOSE=1 || { echo 'HWLOC installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "hwloc NOT FOUND"
echo "Please download it from: https://www.open-mpi.org/software/hwloc/v1.11/downloads/hwloc-1.11.5.tar.gz"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# StarPU
if pkg-config --exists --atleast-version=1.2 libstarpu
then
_LOCATION=`pkg-config --variable=prefix libstarpu`
echo "StarPU FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building StarPU..."
cd $TMPDIR
wget http://starpu.gforge.inria.fr/files/starpu-1.2.5/starpu-1.2.5.tar.gz -O - | tar -zx
cd starpu-1.2.5
if [ "$CUDAVALUE" == "ON" ]; then
./configure --enable-cuda --disable-opencl --prefix=$PREFIX --enable-blas-lib=none
else
./configure --disable-cuda --disable-opencl --prefix=$PREFIX --enable-blas-lib=none
fi
$MAKE || $MAKE VERBOSE=1 || { echo 'STARPU installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "StarPU NOT FOUND"
echo "Please download it from: http://starpu.gforge.inria.fr/files/"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
cd $BASEDIR
set -x
# CHAMELEON
if pkg-config --exists chameleon
then
_LOCATION=`pkg-config --variable=prefix chameleon`
echo "CHAMELEON FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building CHAMELEON..."
cd $BASEDIR/src/hicma/chameleon
mkdir -p build && cd build
rm -rf ./CMake*
cmake -DCHAMELEON_USE_MPI=$MPIVALUE -DCHAMELEON_USE_CUDA=$CUDAVALUE -DCHAMELEON_ENABLE_EXAMPLE=OFF -DCHAMELEON_ENABLE_TESTING=OFF -DCHAMELEON_ENABLE_TIMING=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$PREFIX "$DEFINE_BLAS_LIBS_CMAKE" ..
$MAKE || $MAKE VERBOSE=1 || { echo 'CHAMELEON installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "CHAMELEON NOT FOUND"
echo "Please download it from: https://gitlab.inria.fr/solverstack/chameleon.git"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# starsh
if pkg-config --exists --atleast-version=0.1.1 starsh
then
_LOCATION=`pkg-config --variable=prefix starsh`
echo "starsh FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building STARS-H..."
cd $BASEDIR/src/stars-h
mkdir -p build && cd build
rm -rf ./CMake*
cmake -DCMAKE_C_FLAGS=-fPIC -DOPENMP=OFF -DSTARPU=OFF -DEXAMPLES=OFF -DTESTING=OFF -DMPI=$MPIVALUE -DCMAKE_INSTALL_PREFIX=$PREFIX "$XFLAG" "$DEFINE_BLAS_LIBS_CMAKE" ..
$MAKE || $MAKE VERBOSE=1 || { echo 'STARS-H installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "starsh NOT FOUND"
echo "Please download it from: https://github.com/ecrc/stars-h"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# hicma
if pkg-config --exists hicma
then
_LOCATION=`pkg-config --variable=prefix hicma`
echo "hicma FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building HiCMA..."
cd $BASEDIR/src/hicma/
mkdir -p build && cd build
rm -rf ./CMake*
cmake -DHICMA_USE_MPI=$MPIVALUE -DBUILD_SHARED_LIBS=ON -DHICMA_ENABLE_TESTING=OFF -DHICMA_ENABLE_TIMING=OFF -DCMAKE_INSTALL_PREFIX=$PREFIX "$XFLAG" "$DEFINE_BLAS_LIBS_CMAKE" ..
$MAKE || $MAKE VERBOSE=1 || { echo 'HICMA installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "hicma NOT FOUND"
echo "Please download it from: https://github.com/ecrc/hicma"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# use rpaths in makefile
# TODO use a R defined value por PREFIX and have this directly in the Makefile
#Dummy makefile in src to trigger real one from cmake.
cd $BASEDIR/
rm -rf ./CMakeFiles ./CMakeCache.txt
cmake -DCMAKE_BUILD_TYPE="Release" -DCMAKE_C_FLAGS_RELEASE="-O3 -Ofast" -DBUILD_SHARED_LIBS=ON -DEXAGEOSTAT_EXAMPLES=OFF "$XFLAG" "$DEFINE_BLAS_LIBS_CMAKE" -DEXAGEOSTAT_USE_MPI=$MPIVALUE -DEXAGEOSTAT_USE_HICMA=ON ./src
echo "======================================"
echo "$(ls $PREFIX/lib)"
echo "======================================"
cat > src/Makefile << EOF
.PHONY: all clean
all:
(cd .. && make VERBOSE=1 && cp ./lib*.${LIBEXT} ./src/exageostat.so)
EOF
exit $err