[R] aligned memory allocation in C
Christophe Dutang
dutangc at gmail.com
Wed Aug 13 08:44:25 CEST 2008
Yes, it seems a good idea but your two questions are also good
questions!
Le 13 août 08 à 04:52, Jeffrey Horner a écrit :
> Christophe Dutang1 wrote:
>> Hi,
>> I'm currently R porting SF Mersenne Twister algorithm of Matsumoto
>> and Saito. To get the full power of their code, I want to use their
>> fonction fill_array32 which need aligned memory. That is to say I
>> need to use the C function memalign on windows, posix_memalign on
>> linux and classic malloc on Mac OS. In 'writing R extenstion', they
>> recommand to use R_alloc function to allocate memory in C.
>> Does R_alloc return a pointer to aligned memory?
>> if not how can I do this?
>> probably no, because R crashes when I succesively R_alloc and
>> fill_array32 (cf below) on my macbook with R 2.7.1.
>
> You can still do this. Just take the address returned from R_alloc
> and test for alignment. If it's not, then just use an aligned
> address beyond the one returned.
>
> (But then the question is, which direction beyond the one returned?
> How does one test for that?)
>
> Jeff
>
>> Thanks in advance
>> Kind regards
>> Christophe
>> PS : http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/howto-compile.html
>> provides an example of memalign.
>> PPS : mac os report
>> Thread 0 Crashed:
>> 0 libSystem.B.dylib 0x9341bb9e __kill + 10
>> 1 libSystem.B.dylib 0x93492ec2 raise + 26
>> 2 libSystem.B.dylib 0x934a247f abort + 73
>> 3 randtoolbox.so 0x15e65f1d 0x15e5d000 + 36637
>> 4 randtoolbox.so 0x15e614ef fill_array32 + 4038
>> 5 randtoolbox.so 0x15e6513d SFmersennetwister
>> + 335
>> 6 randtoolbox.so 0x15e652c6
>> doSFMersenneTwister + 255
>> 7 libR.dylib 0x00367a52 do_dotcall + 1394
>> 8 libR.dylib 0x0038b5a2 Rf_eval + 1754
>> 9 libR.dylib 0x0038f9a2 do_set + 592
>> 10 libR.dylib 0x0038b366 Rf_eval + 1182
>> 11 libR.dylib 0x0038b366 Rf_eval + 1182
>> 12 libR.dylib 0x0038c140 do_begin + 58
>> 13 libR.dylib 0x0038b366 Rf_eval + 1182
>> 14 libR.dylib 0x0038b366 Rf_eval + 1182
>> 15 libR.dylib 0x0038c140 do_begin + 58
>> 16 libR.dylib 0x0038b366 Rf_eval + 1182
>> 17 libR.dylib 0x0038d9a6 Rf_applyClosure +
>> 663
>> 18 libR.dylib 0x0038b25d Rf_eval + 917
>> 19 org.R-project.R 0x000189c3
>> run_REngineRmainloop + 569 (Rinit.m:442)
>> 20 org.R-project.R 0x0001142a -[REngine runREPL]
>> + 260 (REngine.m:181)
>> 21 org.R-project.R 0x00002e91 main + 795 (main.m:
>> 126)
>> 22 org.R-project.R 0x00002b5a _start + 216
>> 23 org.R-project.R 0x00002a81 start + 41
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
> --
> http://biostat.mc.vanderbilt.edu/JeffreyHorner
More information about the R-help
mailing list