Repository navigation
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·214 lines (181 loc) · 7.68 KB
/
Copy pathconfigure
File metadata and controls
executable file
·214 lines (181 loc) · 7.68 KB
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
#!/bin/sh
# configure: probe BLAS/LAPACK for single- and double-precision
# procedures used by Armadillo and generate src/Makevars with the
# appropriate build flags.
#
# Procedures checked (Fortran calling convention):
# single-precision BLAS: sdot_
# single-precision LAPACK: sgetrf_
# double-precision BLAS: ddot_
# double-precision LAPACK: dgetrf_
#
# Scalar type selection:
# single-precision routines available -> SCALAR = float
# otherwise -> SCALAR = double (-DHARMONY_SCALAR_DOUBLE)
#
# Armadillo BLAS/LAPACK flags are then set for the chosen precision:
# ARMA_DONT_USE_BLAS -- added when the chosen-precision BLAS is absent
# ARMA_DONT_USE_LAPACK -- added when the chosen-precision LAPACK is absent
PKG_ROOT="$(cd "$(dirname "$0")"; pwd)"
# Retrieve R build configuration
BLAS_LIBS=`"${R_HOME}/bin/R" CMD config BLAS_LIBS`
LAPACK_LIBS=`"${R_HOME}/bin/R" CMD config LAPACK_LIBS`
FLIBS=`"${R_HOME}/bin/R" CMD config FLIBS`
CC=`"${R_HOME}/bin/R" CMD config CC`
CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS`
LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`
PKG_CXXFLAGS="-DARMA_USE_CURRENT"
PKG_LIBS="${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS}"
## Uncomment to include openmp parallelization
# PKG_CXXFLAGS="${PKG_CXXFLAGS} $(SHLIB_OPENMP_CXXFLAGS)"
# Temporary directory for test programs
CONFTMP="${TMPDIR:-/tmp}/harmony_configure_$$"
mkdir -p "${CONFTMP}"
# ---------------------------------------------------------------------------
# Check precision BLAS procedures: sdot_,ddot_
# ---------------------------------------------------------------------------
echo "checking for single-precision BLAS procedures (sdot_)..."
cat > "${CONFTMP}/single_blas_test.c" << 'SINGLE_BLAS_EOF'
extern float sdot_ (const int *n, const float *x, const int *incx,
const float *y, const int *incy);
int main(void) {
float A = 0.0f, B = 0.0f, C = 0.0f, sc = 0.0f;
int dim = 1;
char tr = 'N', ul = 'U';
sdot_ (&dim, &A, &dim, &B, &dim);
return 0;
}
SINGLE_BLAS_EOF
SINGLE_BLAS_OK=no
if ${CC} ${CFLAGS} -o "${CONFTMP}/single_blas_test" "${CONFTMP}/single_blas_test.c" \
${BLAS_LIBS} ${FLIBS} ${LDFLAGS} 2>/dev/null; then
SINGLE_BLAS_OK=yes
elif ${CC} ${CFLAGS} -o "${CONFTMP}/single_blas_test" "${CONFTMP}/single_blas_test.c" \
${BLAS_LIBS} ${FLIBS} ${LDFLAGS} -L"${R_HOME}/lib" -lR 2>/dev/null; then
SINGLE_BLAS_OK=yes
fi
if [ "${SINGLE_BLAS_OK}" = "yes" ]; then
echo " single-precision BLAS found"
else
echo " single-precision BLAS NOT found"
echo "checking for double-precision BLAS procedures (dasum_, ddot_, dnrm2_, dgemv_, dgemm_, dsyrk_)..."
cat > "${CONFTMP}/double_blas_test.c" << 'DOUBLE_BLAS_EOF'
extern double ddot_ (const int *n, const double *x, const int *incx,
const double *y, const int *incy);
int main(void) {
double A = 0.0, B = 0.0, C = 0.0, sc = 0.0;
int dim = 1;
char tr = 'N', ul = 'U';
ddot_ (&dim, &A, &dim, &B, &dim);
return 0;
}
DOUBLE_BLAS_EOF
DOUBLE_BLAS_OK=no
if ${CC} ${CFLAGS} -o "${CONFTMP}/double_blas_test" "${CONFTMP}/double_blas_test.c" \
${BLAS_LIBS} ${FLIBS} ${LDFLAGS} 2>/dev/null; then
DOUBLE_BLAS_OK=yes
elif ${CC} ${CFLAGS} -o "${CONFTMP}/double_blas_test" "${CONFTMP}/double_blas_test.c" \
${BLAS_LIBS} ${FLIBS} ${LDFLAGS} -L"${R_HOME}/lib" -lR 2>/dev/null; then
DOUBLE_BLAS_OK=yes
fi
if [ "${DOUBLE_BLAS_OK}" = "yes" ]; then
echo " double-precision BLAS found"
else
echo " double-precision BLAS NOT found"
fi
fi
# ---------------------------------------------------------------------------
# Check for LAPACK procedures: sgetrf_, dgetrf_
# ---------------------------------------------------------------------------
echo "checking for single-precision LAPACK procedures (sgetrf_)..."
cat > "${CONFTMP}/single_lapack_test.c" << 'SINGLE_LAPACK_EOF'
extern void sgetrf_(const int *m, const int *n, float *A, const int *lda,
int *ipiv, int *info);
int main(void) {
float A = 0.0f, work = 0.0f;
int dim = 1, ipiv = 0, info = 0, lwork = 1;
char ul = 'U', dg = 'N';
sgetrf_(&dim, &dim, &A, &dim, &ipiv, &info);
return 0;
}
SINGLE_LAPACK_EOF
SINGLE_LAPACK_OK=no
if ${CC} ${CFLAGS} -o "${CONFTMP}/single_lapack_test" "${CONFTMP}/single_lapack_test.c" \
${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} ${LDFLAGS} 2>/dev/null; then
SINGLE_LAPACK_OK=yes
elif ${CC} ${CFLAGS} -o "${CONFTMP}/single_lapack_test" "${CONFTMP}/single_lapack_test.c" \
${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} ${LDFLAGS} -L"${R_HOME}/lib" -lR 2>/dev/null; then
SINGLE_LAPACK_OK=yes
fi
if [ "${SINGLE_LAPACK_OK}" = "yes" ]; then
echo " single-precision LAPACK found"
else
echo " single-precision LAPACK NOT found"
echo "checking for double-precision LAPACK procedures (dgetrf_)..."
cat > "${CONFTMP}/double_lapack_test.c" << 'DOUBLE_LAPACK_EOF'
extern void dgetrf_(const int *m, const int *n, double *A, const int *lda,
int *ipiv, int *info);
int main(void) {
double A = 0.0, work = 0.0;
int dim = 1, ipiv = 0, info = 0, lwork = 1;
char ul = 'U', dg = 'N';
dgetrf_(&dim, &dim, &A, &dim, &ipiv, &info);
return 0;
}
DOUBLE_LAPACK_EOF
DOUBLE_LAPACK_OK=no
if ${CC} ${CFLAGS} -o "${CONFTMP}/double_lapack_test" "${CONFTMP}/double_lapack_test.c" \
${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} ${LDFLAGS} 2>/dev/null; then
DOUBLE_LAPACK_OK=yes
elif ${CC} ${CFLAGS} -o "${CONFTMP}/double_lapack_test" "${CONFTMP}/double_lapack_test.c" \
${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} ${LDFLAGS} -L"${R_HOME}/lib" -lR 2>/dev/null; then
DOUBLE_LAPACK_OK=yes
fi
if [ "${DOUBLE_LAPACK_OK}" = "yes" ]; then
echo " double-precision LAPACK found"
else
echo " double-precision LAPACK NOT found"
fi
fi
# ---------------------------------------------------------------------------
# Select scalar precision and set Armadillo flags accordingly
# ---------------------------------------------------------------------------
if [ "${SINGLE_BLAS_OK}" = "yes" ] && [ "${SINGLE_LAPACK_OK}" = "yes" ]; then
echo " single-precision routines fully available -- using float scalar"
USE_DOUBLE=no
else
echo " single-precision routines not fully available -- using double scalar"
USE_DOUBLE=yes
PKG_CXXFLAGS="${PKG_CXXFLAGS} -DHARMONY_SCALAR_DOUBLE"
fi
if [ "${USE_DOUBLE}" = "no" ]; then
# float path: Armadillo needs single-precision BLAS/LAPACK
if [ "${SINGLE_BLAS_OK}" = "no" ]; then
echo " disabling BLAS for Armadillo (single-precision routines absent)"
PKG_CXXFLAGS="${PKG_CXXFLAGS} -DARMA_DONT_USE_BLAS"
fi
if [ "${SINGLE_LAPACK_OK}" = "no" ]; then
echo " disabling LAPACK for Armadillo (single-precision routines absent)"
PKG_CXXFLAGS="${PKG_CXXFLAGS} -DARMA_DONT_USE_LAPACK"
fi
else
# double path: Armadillo needs double-precision BLAS/LAPACK
if [ "${DOUBLE_BLAS_OK}" = "no" ]; then
echo " disabling BLAS for Armadillo (double-precision routines absent)"
PKG_CXXFLAGS="${PKG_CXXFLAGS} -DARMA_DONT_USE_BLAS"
fi
if [ "${DOUBLE_LAPACK_OK}" = "no" ]; then
echo " disabling LAPACK for Armadillo (double-precision routines absent)"
PKG_CXXFLAGS="${PKG_CXXFLAGS} -DARMA_DONT_USE_LAPACK"
fi
fi
# ---------------------------------------------------------------------------
# Clean up and generate src/Makevars
# ---------------------------------------------------------------------------
rm -rf "${CONFTMP}"
sed -e "s|@PKG_CXXFLAGS@|${PKG_CXXFLAGS}|g" \
-e "s|@PKG_LIBS@|${PKG_LIBS}|g" \
"${PKG_ROOT}/src/Makevars.in" > "${PKG_ROOT}/src/Makevars"
echo "configure: src/Makevars written"
echo " PKG_CXXFLAGS = ${PKG_CXXFLAGS}"
echo " PKG_LIBS = ${PKG_LIBS}"