[Rd] [R] aligned memory allocation in C

Christophe Dutang dutangc at gmail.com
Wed Aug 13 22:46:03 CEST 2008


Hi,

You are completely right, the problem was not about what R_alloc  
returned but my use of the fill_array32. Now it works fine, but the  
block generation is longer due to a conversion to double after using  
fill_array32. I must underline the fact that I do not yet use sse2  
support.

Thanks again

Christophe


Le 13 août 08 à 14:30, Luke Tierney a écrit :

> On Wed, 13 Aug 2008, 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.
>
> R_alloc's alignment will be appropriate for holding any data type. It
> will be offset from a value returned by malloc by a multiple of 8
> bytes.
>
> My recollection, which may be wrong, is that on both Intel and PPC
> unaligned access to all basic data types is permitted but may be
> inefficient (in particular on Intel), so the reason for your crash is
> probably elsewhere.
>
> Best,
>
> luke
>
>>
>>
>> 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
>>
>>
>>
>> ______________________________________________
>> 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.
>
> -- 
> Luke Tierney
> Chair, Statistics and Actuarial Science
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa                  Phone:             319-335-3386
> Department of Statistics and        Fax:               319-335-3017
>   Actuarial Science
> 241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
> Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-devel mailing list