Parallelization of a large array
safety0ff via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 10 14:15:16 PDT 2015
On Tuesday, 10 March 2015 at 20:41:14 UTC, Dennis Ritchie wrote:
> Hi.
> How to parallelize a large array to check for the presence of
> an element matching the value with the data?
Here's a simple method (warning: has pitfalls):
import std.stdio;
import std.parallelism;
void main()
{
int[] a = new int[1000000];
foreach (i, ref elem; a)
elem = cast(int)i;
bool found;
foreach (elem; a.parallel)
if (elem == 895639)
found = true;
if (found)
writeln("Yes");
else
writeln("No");
}
More information about the Digitalmars-d-learn
mailing list