Parallelization of a large array

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 10 15:43:08 PDT 2015


On 03/10/2015 03:34 PM, Ali Çehreli wrote:

 > It is possible by accessing the actual range by chunks:

Sorry, I posted a jumbled program that does not compile.

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");
}

Ali



More information about the Digitalmars-d-learn mailing list