Parallelization of a large array
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 10 17:38:39 PDT 2015
On Tuesday, 10 March 2015 at 22:37:29 UTC, Ali Çehreli wrote:
> On 03/10/2015 03:16 PM, Meta wrote:
>
> > Just add a condition variable.
> >
> > import std.stdio;
> > import std.algorithm;
> > import std.parallelism;
> >
> > void main() {
> >
> > int b = 2;
> >
> > auto a = [1, 2, 2, 3];
> >
> > if (find(a, b).length != 0)
> > writeln("Yes_");
> >
> > auto found = false;
> >
> > foreach (elem; a.parallel)
> > if (!found && elem == b)
> > {
> > writeln("Yes");
> > found = true;
>
> I thought about the same solution but then realized that it's a
> race condition, which needs to be taken care of. It's true that
> the value always changes from false to true but still...
>
> > }
> > }
>
> Ali
Yes, it's a non-deterministic solution, but I don't think it
matters all that much as we don't care which element fulfills the
criterion, just that such an element exists.
That's my reasoning, anyway. I know next to nothing about
parallel processing.
More information about the Digitalmars-d-learn
mailing list