Parallelization of a large array
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 10 16:05:44 PDT 2015
On Tuesday, 10 March 2015 at 22:43:08 UTC, Ali Çehreli wrote:
> The following is the program that does NOT use taskPool.map. I
> am also changing the name of a variable because the local
> 'chunks' looked like std.range.chunks.
>
> import std.stdio;
> import std.algorithm;
> import std.parallelism;
> import std.range;
> import std.conv;
>
> void main()
> {
> const size_t elementCount = 895640;
> int[] a = iota(elementCount)
> .map!(i => i.to!int)
> .array;
>
> const chunkSize = a.length / taskPool.size;
> auto ch = a.chunks(chunkSize);
> bool[] results = new bool[ch.length];
>
> foreach (i, chunk; ch.parallel) {
> results[i] = chunk.canFind(895639);
> }
>
> writeln(results.canFind(true) ? "Yes" : "No");
> }
Thanks. This code will help me.
More information about the Digitalmars-d-learn
mailing list