Skip to content

Commit

Permalink
Try to detect LAPACK/BLAS better
Browse files Browse the repository at this point in the history
This includes detecting ATLAS, as well as looking for static versions
of LAPACK/BLAS that can be linked into a shared object (-fPIC). The
only such library found on Ubuntu systems seems to be OpenBLAS (but
only with -lm and -lpthread dynamically linked, since -lm -lpthread
are not compiled with -fPIC).
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Dec 16, 2015
1 parent 59c32f1 commit 4865156
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -106,7 +106,7 @@ Makefile: Makefile.in config.status common/m4/*.m4

config.status: configure
./config.status -recheck
configure: configure.ac
configure: configure.ac m4/lapack.m4 common/m4/*.m4
autoconf

emcc: msl-external-libs-emcc emcc-simulationruntime
Expand Down
7 changes: 5 additions & 2 deletions SimulationRuntime/fmi/export/buildproject/Makefile.in
Expand Up @@ -7,9 +7,12 @@ default: install

all: configure

configure: configure.ac
configure: configure.ac $(top_builddir)/m4/lapack.m4
autoconf

install: all
mkdir -p $(PROJECTDIR)
cp -a configure $(top_builddir)/config.guess $(top_builddir)/config.sub $(top_builddir)/install-sh $(PROJECTDIR)/
cp -a configure "$(top_builddir)/config.guess" "$(top_builddir)/config.sub" "$(top_builddir)/install-sh" $(PROJECTDIR)/

Makefile: Makefile.in
cd "$(top_builddir)" && ./config.status
19 changes: 7 additions & 12 deletions SimulationRuntime/fmi/export/buildproject/configure.ac
Expand Up @@ -115,18 +115,13 @@ dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(strdup strerror)

# Cannot use AX_LAPACK since it assumes a Fortran compiler is used
AC_ARG_WITH(lapack, [ --with-lapack=[-llapack -lblas] (use -llapack -lblas to use system-provided version.)],[LD_LAPACK="$withval"],[
LD_LAPACK="-Wl,-Bstatic -llapack -lblas -Wl,-Bdynamic"
])

AC_MSG_CHECKING([LAPACK/BLAS flags])

OLDLIBS="$LIBS"
LIBS="$LIBS $LD_LAPACK"
AC_LINK_IFELSE([AC_LANG_CALL([], [dgesv_])],[
AC_LINK_IFELSE([AC_LANG_CALL([], [dswap_])],[AC_MSG_RESULT([$LD_LAPACK])],[LIBS="$OLDLIBS"; NEED_DGESV=1; AC_MSG_RESULT([dswap (BLAS) linking failed using $LD_LAPACK])])
],[LIBS="$OLDLIBS"; NEED_DGESV=1; AC_MSG_RESULT([dgesv (LAPACK) linking failed using $LD_LAPACK])])
m4_include([../../../../m4/lapack.m4])
OMC_AC_LAPACK(static)
if test -z "$LD_LAPACK"; then
NEED_DGESV=1
else
LIBS="$LIBS $LD_LAPACK"
fi

AC_MSG_CHECKING([for static pthreads])
OLDLIBS=$LIBS
Expand Down
35 changes: 2 additions & 33 deletions configure.ac
Expand Up @@ -94,6 +94,7 @@ FINAL_MESSAGES="\nConfigured OpenModelica successfully using the following optio
m4_include([common/m4/pre-commit.m4])
cp common/install-sh common/config.guess common/config.sub ./
m4_include([common/m4/ombuilddir.m4])
m4_include([m4/lapack.m4])

AC_CANONICAL_BUILD
AC_CANONICAL_HOST
Expand Down Expand Up @@ -514,39 +515,7 @@ fi

fi

# Cannot use AX_LAPACK since it assumes a Fortran compiler is used
AC_ARG_WITH(lapack, [ --with-lapack=[-llapack -lblas] (use -llapack -lblas to use system-provided version instead of OpenBLAS. Use openblas for automatically detected OpenBLAS. Use --with-lapack=openblas-NEHALEM or other OpenBLAS target to compile against a certain architecture. Note that you need to include BLAS in this.)],[LD_LAPACK="$withval"],
[
if test ! -z "$MINGWNUM"; then
LD_LAPACK="-Wl,-Bstatic -lopenblas -lgfortran -lquadmath -Wl,-Bdynamic"
else
LD_LAPACK="-llapack -lblas"
fi
])

if test "$LD_LAPACK" = "no"; then
FINAL_MESSAGES="$FINAL_MESSAGES\nLAPACK IS NOT AVAILABLE! ONLY USED FOR CROSS-COMPILING/BOOTSTRAPPING"
LD_LAPACK=""
NO_LAPACK="#define NO_LAPACK"
else

AC_MSG_CHECKING([LAPACK/BLAS flags])
if echo "$LD_LAPACK" | grep -oq "^openblas"; then
LD_LAPACK=`echo $LD_LAPACK | sed s/"^openblas-//"`
if test "$LD_LAPACK" = "openblas"; then
AC_MSG_RESULT([OpenBLAS compiled using auto detected architecture])
else
OPENBLAS_EXTRA_ARGS="TARGET=$LD_LAPACK"
AC_MSG_RESULT([OpenBLAS compiled using architecture $LD_LAPACK])
fi
LD_LAPACK="-lopenblas_openmodelica"
LAPACK_TARGET="openblas"
else
LIBS="$LD_LAPACK"
AC_LINK_IFELSE([AC_LANG_CALL([], [dgesv_])],[],[AC_MSG_ERROR([dgesv (LAPACK) linking failed using $LD_LAPACK])])
AC_LINK_IFELSE([AC_LANG_CALL([], [dswap_])],[AC_MSG_RESULT([$LD_LAPACK])],[AC_MSG_ERROR([dswap (BLAS) linking failed using $LD_LAPACK])])
fi
fi
OMC_AC_LAPACK(RequireFound)

AC_CHECK_HEADERS(kinsol/kinsol.h kinsol/kinsol_dense.h nvector/nvector_serial.h sundials/sundials_types.h sundials/sundials_math.h,[],[NO_SUNDIALS="yes"])
SUNDIALS_LDFLAGS="-lsundials_kinsol -lsundials_nvecserial $LD_LAPACK"
Expand Down
74 changes: 74 additions & 0 deletions m4/lapack.m4
@@ -0,0 +1,74 @@
AC_DEFUN([OMC_AC_LAPACK], [
# Cannot use AX_LAPACK since it assumes a Fortran compiler is used
AC_ARG_WITH(lapack, [ --with-lapack=[auto] Use --with-lapack="-llapack -lblas", or let OMC auto-detect using pkg-config, etc.],
[LD_LAPACK="$withval"],
[LD_LAPACK="auto"])
if test "$LD_LAPACK" = "no"; then
FINAL_MESSAGES="$FINAL_MESSAGES\nLAPACK IS NOT AVAILABLE! ONLY USED FOR CROSS-COMPILING/BOOTSTRAPPING"
LD_LAPACK=""
NO_LAPACK="#define NO_LAPACK"
else
AC_LANG_PUSH([C])
AC_MSG_CHECKING([LAPACK/BLAS flags])
OLDLIBS="$LIBS"
if test "$LD_LAPACK" = "auto"; then
LD_LAPACK=""
if test "$1" = "static" || test "$2" = "static"; then
PKGCONFIG="pkg-config --static --libs --silence-errors"
LD_LAPACK_STATIC_HEAD="-Wl,-Bstatic"
LD_LAPACK_STATIC_TAIL="-Wl,-Bdynamic"
else
PKGCONFIG="pkg-config --libs --silence-errors"
fi
for flags in "-lopenblas" "`$PKGCONFIG lapack`" "`$PKGCONFIG lapack blas`" "-llapack -lblas" "-llapack -lblas -lm -latlas"; do
for extra in "" "-lgfortran" "-lgfortran -lquadmath"; do
THESELIBS="$LD_LAPACK_STATIC_HEAD $flags $extra $LD_LAPACK_STATIC_TAIL"
LIBS="-shared $THESELIBS -Wl,--no-undefined"
AC_LINK_IFELSE([AC_LANG_CALL([], [dgesv_])],[
AC_LINK_IFELSE([AC_LANG_CALL([], [dswap_])],[LD_LAPACK="$THESELIBS"],[])
],[])
if test ! -z "$LD_LAPACK"; then
break;
fi
done
if test ! -z "$LD_LAPACK"; then
break;
fi
for extra_dynamic in "-lm" "-lpthread" "-lm -lpthread"; do
THESELIBS="$LD_LAPACK_STATIC_HEAD $flags $LD_LAPACK_STATIC_TAIL $extra_dynamic"
LIBS="-shared $THESELIBS -Wl,--no-undefined"
AC_LINK_IFELSE([AC_LANG_CALL([], [dgesv_])],[
AC_LINK_IFELSE([AC_LANG_CALL([], [dswap_])],[LD_LAPACK="$THESELIBS"],[])
],[])
if test ! -z "$LD_LAPACK"; then
break;
fi
done
if test ! -z "$LD_LAPACK"; then
break;
fi
done
if test -z "$LD_LAPACK"; then
if test "$1" = "RequireFound"; then
AC_MSG_ERROR([dgesv or dswap not found])
else
AC_MSG_RESULT([not found])
fi
else
AC_MSG_RESULT([$LD_LAPACK])
fi
elif test ! -z "$LD_LAPACK"; then
LIBS="$LD_LAPACK"
AC_LINK_IFELSE([AC_LANG_CALL([], [dgesv_])],[],[AC_MSG_RESULT([dgesv (LAPACK) linking failed using $LD_LAPACK]); LD_LAPACK=""])
AC_LINK_IFELSE([AC_LANG_CALL([], [dswap_])],[AC_MSG_RESULT([$LD_LAPACK])],[AC_MSG_RESULT([dswap (BLAS) linking failed using $LD_LAPACK]); LD_LAPACK=""])
fi
LIBS="$OLDLIBS"
AC_LANG_POP([C])
fi
])

0 comments on commit 4865156

Please sign in to comment.