[Rd] How to connect R with a C code which includes Atlas

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jan 5 07:37:42 CET 2005

On Wed, 5 Jan 2005 xt_wang at cse.concordia.ca wrote:

> Hello, everybody,
> Happy New Year!
> I am a graduate student from Concordia University. I meet a problem when 
> I am working on my thesis. I hope I will get help from you.
> I have a mathematical model which was already implemented by using R 
> language. However, part of this model includes fixed point iteration 
> algorithm and calculation of large linear equations which n will get to 
> 5000. Because of limitation of memory, R is not enough to support this 
> kind of calculation. Now, I use C language with Matlab C library to 
> implement this part of model and solve this problem. But the problem is 
> that I can not connect my C program with R code since C program include 
> Matlab.h.
> The function I used from matlab is Cholesky algorithm which is applied 
> to calculate inv(C)*b where C is a symmetric positive definite matrix. 
> Since R is not easy to connect with C which include Maltab C library, 
> and I find Atlas is optimized linear algebra library and possible to be 
> used by R, do you think it is possible for me to replace matlab by using 
> Atlas function in my C code, and finally the C code can be connected 
> with R dynamically?  That means I can run a R program -> which include C 
> code-> which include Atlas automatically. If it is possible, could you 
> please tell me how can I realize the dynamic link?

Certainly.  Just put your C code into a package and include $(BLAS_LIBS) 
when you build the package: see `Writing R Extensions'.

Note that ATLAS is an optimized BLAS, the B standing for Basic.  For a 
Choleski decomposition you could use LAPACK as the R sources do and that 
will in turn use ATLAS if you built R against ATLAS.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-devel mailing list