[R] SUMMARY: Using R's LAPACK & Related files in Visual C++

Greg Tarpinian sasprog474 at yahoo.com
Fri Mar 26 21:46:41 CET 2004


The following were the replies to my question
about using R's LAPACK and other .h files in 
some of my C programs.  From what was
said, it appears that buying a ready-made
library (MKL = $200, for example)
or using CLapack according to the Shumway lecture
notes are the best approaches:

--------------------------------
>From Andy Liaw:

(1) If you just want linear algebra routines in your C
code, you should really look elsewhere.  You could,
for example, check out Intel's Math Kernel
Library.  (It used to be a free download.  Not sure if
that's still the case.)

(2) Googling `calling lapack from C', I also found:
http://physics.asu.edu/phy502-shumway/notes/lec11.html
--------------------------------
>From Timur Elzhov:

AFAIK, R uses native FORTRAN l(a,in)pack codes :)  Try
it, I guess you'll be able to call their functions,
this way:
  void dposl_(double*, int*, int*, double*); //for
`dposl' Fortran 
function

Note underscore `_' under function name! ;)
--------------------------------
>From Douglas Bates:

R's include files BLAS.h, Linpack.h, and Lapack.h all
contain

#include <R_ext/RS.h>

which defines portable macros F77_CALL that add the
underscore when necessary.  The reliable way to use
these routines in C is as

    F77_CALL(dposl)(A, &n, &n, x);

where A is a pointer to the matrix, stored in
Fortran-like column major order, and x is a pointer to
the right hand side.  Note that the integer n must be
passed by address because of Fortran calling
conventions.

The Lapack functions defined in Lapack.h can be called
from within C routines in R packages but you should
include a file Makevars that defines

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

Calling Lapack functions from standalone code is more
complicated.




More information about the R-help mailing list