forked from FluidityProject/fluidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acx_blas.m4
249 lines (222 loc) · 7.05 KB
/
acx_blas.m4
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
dnl @synopsis ACX_BLAS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
dnl
dnl This macro looks for a library that implements the BLAS
dnl linear-algebra interface (see http://www.netlib.org/blas/).
dnl On success, it sets the BLAS_LIBS output variable to
dnl hold the requisite library linkages.
dnl
dnl To link with BLAS, you should link with:
dnl
dnl $BLAS_LIBS $LIBS $FCLIBS
dnl
dnl in that order. FCLIBS is the output variable of the
dnl AC_FC_LIBRARY_LDFLAGS macro (called if necessary by ACX_BLAS),
dnl and is sometimes necessary in order to link with FC libraries.
dnl Users will also need to use AC_FC_DUMMY_MAIN (see the autoconf
dnl manual), for the same reason.
dnl
dnl Many libraries are searched for, from ATLAS to CXML to ESSL.
dnl The user may also use --with-blas=<lib> in order to use some
dnl specific BLAS library <lib>. In order to link successfully,
dnl however, be aware that you will probably need to use the same
dnl Fortran compiler (which can be set via the FC env. var.) as
dnl was used to compile the BLAS library.
dnl
dnl ACTION-IF-FOUND is a list of shell commands to run if a BLAS
dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
dnl to run it if it is not found. If ACTION-IF-FOUND is not specified,
dnl the default action will define HAVE_BLAS.
dnl
dnl This macro requires autoconf 2.50 or later.
dnl
dnl @version $Id$
dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
dnl
dnl Modified by Jonas Juselius <jonas@iki.fi>
dnl
AC_DEFUN([ACX_BLAS], [
AC_PREREQ(2.59)
acx_blas_ok=no
acx_blas_save_LIBS="$LIBS"
acx_blas_save_LDFLAGS="$LDFLAGS"
acx_blas_save_FFLAGS="$FFLAGS"
acx_blas_libs=""
acx_blas_dir=""
AC_ARG_WITH(blas,
[AC_HELP_STRING([--with-blas=<lib>], [use BLAS library <lib>])])
case $with_blas in
yes | "") ;;
no) acx_blas_ok=disable ;;
-l* | */* | *.a | *.so | *.so.* | *.o) acx_blas_libs="$with_blas" ;;
*) acx_blas_libs="-l$with_blas" ;;
esac
AC_ARG_WITH(blas_dir,
[AC_HELP_STRING([--with-blas-dir=<dir>], [look for BLAS library in <dir>])])
case $with_blas_dir in
yes | no | "") ;;
-L*) LDFLAGS="$LDFLAGS $with_blas_dir"
acx_blas_dir="$with_blas_dir" ;;
*) LDFLAGS="$LDFLAGS -L$with_blas_dir"
acx_blas_dir="-L$with_blas_dir" ;;
esac
# Are we linking from C?
case "$ac_ext" in
f*|F*) sgemm="sgemm" ;;
*)
AC_FC_FUNC([sgemm])
LIBS="$LIBS $FCLIBS"
;;
esac
# If --with-blas is defined, then look for THIS AND ONLY THIS blas lib
if test $acx_blas_ok = no; then
case $with_blas in
""|yes) ;;
*) save_LIBS="$LIBS"; LIBS="$acx_blas_libs $LIBS"
AC_MSG_CHECKING([for $sgemm in $acx_blas_libs])
AC_TRY_LINK_FUNC($sgemm, [acx_blas_ok=yes])
AC_MSG_RESULT($acx_blas_ok)
LIBS="$save_LIBS"
acx_blas_ok=specific
;;
esac
fi
# First, check BLAS_LIBS environment variable
if test $acx_blas_ok = no; then
if test "x$BLAS_LIBS" != x; then
save_LIBS="$LIBS"; LIBS="$BLAS_LIBS $LIBS"
AC_MSG_CHECKING([for $sgemm in $BLAS_LIBS])
AC_TRY_LINK_FUNC($sgemm, [acx_blas_ok=yes; acx_blas_libs=$BLAS_LIBS])
AC_MSG_RESULT($acx_blas_ok)
LIBS="$save_LIBS"
fi
fi
# BLAS linked to by default? (happens on some supercomputers)
if test $acx_blas_ok = no; then
AC_MSG_CHECKING([for builtin $sgemm])
AC_TRY_LINK_FUNC($sgemm, [acx_blas_ok=yes])
AC_MSG_RESULT($acx_blas_ok)
fi
# Intel mkl BLAS. Unfortunately some of Intel's blas routines are
# in their lapack library...
if test $acx_blas_ok = no; then
AC_CHECK_LIB(mkl_def, $sgemm,
[acx_blas_ok=yes; acx_blas_libs="-lmkl_def -lm"],
[],[-lm])
fi
if test $acx_blas_ok = no; then
AC_CHECK_LIB(mkl_ipf, $sgemm,
[acx_blas_ok=yes; acx_blas_libs="-lmkl_ipf -lguide -lm"],
[],[-lguide -lm])
fi
# check for older mkl
if test $acx_blas_ok = no; then
AC_MSG_NOTICE([trying Intel MKL < 7:])
unset ac_cv_lib_mkl_def_sgemm
AC_CHECK_LIB(mkl_lapack, lsame, [
acx_lapack_ok=yes;
AC_CHECK_LIB(mkl_def, $sgemm,
[acx_blas_ok=yes;
acx_blas_libs="-lmkl_def -lmkl_lapack -lm -lpthread"],
[],[-lm -lpthread
])
])
AC_MSG_NOTICE([Intel MKL < 7... $acx_blas_ok])
fi
# BLAS in ACML (pgi)
if test $acx_blas_ok = no; then
AC_CHECK_LIB(acml, $sgemm, [acx_blas_ok=yes; acx_blas_libs="-lacml"])
fi
# BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
if test $acx_blas_ok = no; then
AC_CHECK_LIB(f77blas, $sgemm,
[acx_blas_ok=yes; acx_blas_libs="-lf77blas -latlas"],
[], [-latlas])
fi
# ia64-hp-hpux11.22 BLAS library?
if test $acx_blas_ok = no; then
AC_CHECK_LIB(veclib, $sgemm,
[acx_blas_ok=yes; acx_blas_libs="-lveclib8"])
fi
# BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
if test $acx_blas_ok = no; then
AC_MSG_NOTICE([trying PhiPACK:])
AC_CHECK_LIB(blas, $sgemm,
[AC_CHECK_LIB(dgemm, dgemm,
[AC_CHECK_LIB(sgemm, $sgemm,
[acx_blas_ok=yes; acx_blas_libs="-lsgemm -ldgemm -lblas"],
[], [-lblas])],
[], [-lblas])
])
AC_MSG_NOTICE([PhiPACK... $acx_blas_ok])
fi
# BLAS in Alpha CXML library?
if test $acx_blas_ok = no; then
AC_CHECK_LIB(cxml, $sgemm, [acx_blas_ok=yes;acx_blas_libs="-lcxml"])
fi
# BLAS in Alpha DXML library? (now called CXML, see above)
if test $acx_blas_ok = no; then
AC_CHECK_LIB(dxml, $sgemm, [acx_blas_ok=yes;acx_blas_libs="-ldxml"])
fi
# BLAS in Sun Performance library?
if test $acx_blas_ok = no; then
if test "x$GCC" != xyes; then # only works with Sun CC
AC_CHECK_LIB(sunmath, acosp,
[AC_CHECK_LIB(sunperf, $sgemm,
[acx_blas_libs="-xlic_lib=sunperf -lsunmath"
acx_blas_ok=yes],[],[-lsunmath])
])
fi
fi
# BLAS in SCSL library? (SGI/Cray Scientific Library)
if test $acx_blas_ok = no; then
AC_CHECK_LIB(scs, $sgemm, [acx_blas_ok=yes; acx_blas_libs="-lscs"])
fi
# BLAS in SGIMATH library?
if test $acx_blas_ok = no; then
AC_CHECK_LIB(complib.sgimath, $sgemm,
[acx_blas_ok=yes; acx_blas_libs="-lcomplib.sgimath"])
fi
# BLAS in IBM ESSL library? (requires generic BLAS lib, too)
if test $acx_blas_ok = no; then
unset ac_cv_lib_blas_sgemm
AC_MSG_NOTICE([trying IBM ESSL:])
AC_CHECK_LIB(blas, $sgemm,
[AC_CHECK_LIB(essl, $sgemm,
[acx_blas_ok=yes; acx_blas_libs="-lessl -lblas"],
[], [-lblas])
])
AC_MSG_NOTICE([IBM ESSL... $acx_blas_ok])
fi
# Generic BLAS library?
if test $acx_blas_ok = no; then
unset ac_cv_lib_blas_sgemm
AC_CHECK_LIB(blas, $sgemm, [acx_blas_ok=yes; acx_blas_libs="-lblas"])
fi
# blas on SGI/CRAY
if test $acx_blas_ok = no; then
unset ac_cv_lib_blas_sgemm
AC_CHECK_LIB(blas, $sgemm,
[acx_blas_ok=yes; acx_blas_libs="-lblas -lcraylibs"],[],[-lcraylibs])
fi
# Check for vecLib framework (Darwin)
if test $acx_blas_ok = no; then
save_LIBS="$LIBS"; LIBS="-framework vecLib $LIBS"
AC_MSG_CHECKING([for $sgemm in vecLib])
AC_TRY_LINK_FUNC($sgemm, [acx_blas_ok=yes; acx_blas_libs="-framework vecLib"])
AC_MSG_RESULT($acx_blas_ok)
LIBS="$save_LIBS"
fi
BLAS_LIBS="$acx_blas_libs"
AC_SUBST(BLAS_LIBS)
LIBS="$acx_blas_save_LIBS"
LDFLAGS="$acx_blas_save_LDFLAGS $acx_blas_dir"
test x"$acx_blas_ok" = xspecific && acx_blas_ok=yes
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
if test x"$acx_blas_ok" = xyes; then
ifelse([$1],,AC_DEFINE(HAVE_BLAS,1,[Define if you have a BLAS library.]),[$1])
:
else
acx_blas_ok=no
$2
fi
])dnl ACX_BLAS