On Mar 12, 3:52 am, "Jan Svitok" <jan.svi... / gmail.com> wrote:
> On 3/12/07, Daniel Berger <djber... / gmail.com> wrote:
>
>
>
>
>
> > On Mar 11, 4:37 pm, "Jan Svitok" <jan.svi... / gmail.com> wrote:
> > > On 3/11/07, Daniel Berger <djber... / gmail.com> 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
>
> Seems OMP is included in standard and up.http://members.gamedev.net/Rivorus/surge/html/surge_act/setting_up_yo...

Drat.

> If you send me the patch/instructions I can compile that for you.

Edit array.c and add the rb_ary_acollect function in my OP anywhere
above the Init_array() declaration. Add "rb_define_method(rb_cArray,
"acollect", rb_ary_acollect, 0);" where all the other method
defintions are (near the bottom). Then recompile and install.

Thanks,

Dan