Re: [Rd] [R] aligned memory allocation in C

From: Christophe Dutang <dutangc_at_gmail.com>
Date: Wed, 13 Aug 2008 22:46:03 +0200

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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 13 Aug 2008 - 21:04:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 14 Aug 2008 - 17:36:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive