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

xt_wang at cse.concordia.ca xt_wang at cse.concordia.ca
Wed Jan 5 23:59:50 CET 2005

If it is possible to link a C code with Atlas into R. Is it possible to link a C
code with Matlab into R?

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.

More information about the R-devel mailing list