[R] Call a Fortran subroutine with R: R crashes

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Mon Aug 18 16:31:57 CEST 2008


Zornitsa Luleva wrote:
> Hello,
>
> I am trying to call a FORTRAN subroutine within R and something really
> strange happens:
>
> I have a dll-library, that I load with dyn.load('mpbvv.dll'). I have checked
> the [Ordinal/Name Pointer] Table for the function within the library that I
> want to call - it is there (objdump - p mpbvv.dll).
>
> Then, I have written an R-wrapper to call the FORTRAN subroutine, which
> works fine. SInce I have 200 "points", at which I have to evaluate the
> function, I have to call it 200 times. It works about 100 times just fine
> and then R crashes. The values for which the function is evaluated are
> almost the same, there no sudden big differences.
>
> The only thing that is probably not really ok is that is.loaded('mpbvv.dll')
> returns FALSE. But if I call getLoadedDLLs(), the library is loaded
>   
>> getLoadedDLLs()
>>     
>                                                              Filename
> base                                                             base
> methods       C:/Programme/R/R-2.7.1/library/methods/libs/methods.dll
> grDevices C:/Programme/R/R-2.7.1/library/grDevices/libs/grDevices.dll
> stats             C:/Programme/R/R-2.7.1/library/stats/libs/stats.dll
> mpbvv                                            E:/Zoe/DA/mpbvv.dll
>           Dynamic.Lookup
> base                  FALSE
> methods            FALSE
> grDevices           FALSE
> stats                 FALSE
> mpbvv               TRUE
> I am loading four more libraries:
>
> library('actuar')
> library('bbmle')
> library('polynom')
> library('NORMT3')
>
> Could this be a problem?
>
> I don't have any idea why R crashes. Do you?
>
>   
The most common case is that people's argument lists to .Fortran do not
match up with the expected types and dimensions of the subroutine. This
may (e.g.) cause you to write past the end of an array, leading to
memory corruption that will not be discovered until it trips up the
memory management some time later. Turning gctorture() on may provoke
the error to occur sooner and become easier to pinpoint.

> Thanks a lot for your advice in advance!
>   

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list