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

Douglas Bates bates at stat.wisc.edu
Fri Mar 26 18:35:59 CET 2004


Timur Elzhov <Timur.Elzhov at jinr.ru> writes:

> On Thu, Mar 25, 2004 at 08:40:30PM -0800, Greg Tarpinian wrote:
> 
> > I am a relative newcomer to both the R and C/C++ software worlds --
> > I'm taking a C Programming class currently.  I noticed the other day
> > that the
> > 
> > C:\Program Files\R1_8_1\src\include\R_ext
> > 
> > directory on my WinXP box has the header files
> > 
> > BLAS.h
> > Lapack.h
> > Linpack.h
> > RLapack.h
> > 
> > I am interested in (perhaps) using one or more of these header files
> > in a straight C program I'm working on in Visual C++ .NET.  (I need
> > matrix inversion, svd, generalized inverse, Cholesky decomposition,
> > and a few other matrix features for a class project and this is the
> > first time I've ever worked with header files.) My attempts to get the
> > freely available CLAPACK3-Windows.zip on
> > 
> > http://www.netlib.org/clapack/
> 
> 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! ;)

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