From: Daniel Berger Date: 2007-03-12T13:55:05+09:00 Subject: Re: Trying to make Array#collect massively parallel with OpenMP On Mar 11, 4:37 pm, "Jan Svitok" wrote: > On 3/11/07, Daniel Berger wrote: > > > > > Hi all, > > > Windows XP Home > > VC++ 8 (free edition) > > > Just for kicks I tried creating a parallel Array#collect method, which > > I called Array#acollect (asynch. collect). I added the following C > > code to array.c, rebuilt and reinstalled, but it doesn't seem to be > > any faster. Could this be an issue with my compiler? Or a Windows > > thing? > > > static VALUE rb_ary_acollect(VALUE ary){ > > long i; > > VALUE collect; > > > if (!rb_block_given_p()) > > return rb_ary_new4(RARRAY(ary)->len, RARRAY(ary)->ptr); > > > collect = rb_ary_new2(RARRAY(ary)->len); > > > #pragma omp parallel for > > for (i = 0; i < RARRAY(ary)->len; i++) > > rb_ary_push(collect, rb_yield(RARRAY(ary)->ptr[i])); > > > return collect; > > } > > > rb_define_method(rb_cArray, "acollect", rb_ary_acollect, 0); > > > # bench_collect.rb > > require "benchmark" > > > MAX = 4000 > > > array = [] > > MAX.times{ |n| > > array[n] = 2 * n > > } > > > # No significant difference (?) > > Benchmark.bm(30) do |x| > > x.report("Array#collect"){ > > MAX.times{ array.collect{ |e| e += 4 } } > > } > > x.report("Array#acollect"){ > > MAX.times{ array.acollect{ |e| e += 4 } } > > } > > end > > > Ideas? > > > Thanks, > > > Dan > > Hi, > > I'm no expert in either ruby internals or openmp. I've just a few > ideas for you (though most of them will be obvious probably): > > 1.http://msdn2.microsoft.com/en-us/library/fw509c3b(VS.80).aspxsays > you need to add /openmp compiler switch (try using _OPENMP define to > see if the compiler recognizes omp pragmas). #include "omp.h" might > help as well. Ah, thanks. I tried that and I got: LINK : fatal error LNK1104: cannot open file 'VCOMP.lib' It doesn't look like I have omp.h. This may be a header that's not included in the free version of VC++. I'll have to ask around. Thanks, Dan