[Rd] Optimized blas?

Saikat DebRoy saikat@stat.wisc.edu
02 Mar 2000 07:52:01 -0600


>>>>> "gb" == gb  <gb@stat.umu.se> writes:

  >> I can't help noticing that you are configuring for a RISC
  >> optimized BLAS library on an Intel x86 processor.  I have no idea
  >> if this is serious, but it seems a bit odd.

  gb> Talking about that, is there an x86 optimized (for Linux and/or
  gb> NT) BLAS around somewhere?

You can try atlas (http://www.netlib.org/atlas/). You will have to
download the source and build it on your machine if you want it to
work optimally. The problem with that is that it does not build the
shared libraries by default and the whole build process is rather
complicated. Also, you will have to patch the R-1.0.0 configure.in file
(I am attaching the patch below) and then run autoconf to generate the
configure file.

Even after you do all these, the performance benefit is not great. R
currently uses only level 1 blas and the most significant atlas
optimizations are for level 3 (and level 2 to some extant). I do not
think that it is worth the effort.

Note that this patch for autoconf is a hack borrowed from a hack on
the octave configure.in and I have tested this only on a debian x86
system.

Saikat

========================================================================
--- configure.in	Thu Mar  2 07:27:13 2000
+++ configure.in	Thu Mar  2 07:34:18 2000
@@ -126,6 +126,11 @@
     fi],
   use_blas_risc=true)
 
+AC_ARG_WITH(fastblas,
+  [  --with-fastblas         use an optimized BLAS library (if available)],
+  [ use_fastblas=${withval} ],
+  use_fastblas=true)
+
 AC_ARG_WITH(dxml,
   [  --with-dxml             use DXML library (if available)],
   [ if test "${withval}" = no; then
@@ -352,7 +357,42 @@
 if ${use_dxml}; then
   AC_CHECK_LIB(dxml, main, FLIBS="-ldxml ${FLIBS}" BLAS="")
 fi
-if test -n "${BLAS}" && ${use_blas}; then
+
+# ----------------------------------------------------------------------
+# Checks for BLAS and LAPACK libraries:
+
+# name of Fortran dgemm function to check for (depends upon F77 compiler
+# name-mangling scheme):
+if test "$r_cv_prog_f77_append_underscore" = "yes"; then
+  dgemm_func=dgemm_
+else
+  dgemm_func=dgemm
+fi
+
+# remember current FLIBS, so we can check if any libs were found below.
+blas_save_FLIBS="${FLIBS}"
+if test ${use_fastblas} = no; then
+  blas_save_FLIBS="different from $LIBS so tests fail below"
+elif test ${use_fastblas} != "yes"; then
+  # user specified a BLAS library to try on the command line
+  AC_CHECK_LIB($use_fastblas, $dgemm_func, 
+    [ BLAS="" FLIBS="-l$use_fastblas $FLIBS"], , ${FLIBS})
+fi
+
+if test "${blas_save_FLIBS}" = "${FLIBS}"; then
+  # Checks for ATLAS BLAS library:
+  AC_CHECK_LIB(atlas, ATL_xerbla,
+      [ FLIBS="-latlas ${FLIBS}"], , $FLIBS)
+  if test "${blas_save_FLIBS}" != "${FLIBS}"; then
+    # check for other atlas libs:
+    AC_CHECK_LIB(cblas, cblas_dgemm,
+      [ FLIBS="-lcblas ${FLIBS}"
+	AC_CHECK_LIB(f77blas, $dgemm_func, 
+	  [ BLAS="" FLIBS="-lf77blas ${FLIBS}"],
+	  [ FLIBS="{blas_save_FLIBS}"], $FLIBS)],
+	[ FLIBS="{blas_save_FLIBS}"], $FLIBS)
+  fi
+elif test -n "${BLAS}" && ${use_blas}; then
   AC_CHECK_LIB(blas, main,
     [ FLIBS="-lblas ${FLIBS}" BLAS=""
       if ${use_blas_risc}; then

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._