I have an R package which uses lots of Fortran subroutines for nested loops of recursive linear algebra computations (depending heavily on BLAS and LAPACK routines). As an interface to Fortran, I use .Fortran
function. I just read Jonathan Callahan's blog post about using .Call
instead of .C
in case of subroutines written in C/C++, and it got me thinking that would it be better to use .Call
interface also when using Fortran subroutines, by writing a simple wrapper in C which then calls the Fortran subroutines?
As said, my Fortran codes are quite simple in a sense that I just play with multidimensional arrays of type double or integer. But I have learned that I must write quite a lot of checks in R side to ensure that everything doesn't crash because of I accidentally forgot to change the storage mode of some matrix to integer or the dimensions of some matrix were changed etc.
Subroutines are written as F90/95.
.C
and.Fortran
are much larger than.Call
at least because the extra copying of the arguments. There might be some performance differences with the type checking in C compared to R etc also, don't know about that. – Sloop