On 24.11.2015 19:49, Bishop120 wrote:
I figured this would be a simple parallel foreach function with an iota
range of sizeX and just making int X declared inside the function so
that I didnt have to worry about shared variable but I cant get around
the alive++ reduction and I dont understand enough about D's
reduction/parallel library.

Any ideas?  Thanks in advance for yalls patience and assistance!

I'm not sure what you're asking. Are you maybe looking for core.atomic.atomicOp?

Example:
----
import core.atomic: atomicOp;
import std.parallelism: parallel;
import std.range: iota;
import std.stdio: writeln;

void main()
{
    int x = 0;
    shared int y = 0;
    foreach(i; parallel(iota(100_000)))
    {
        ++x;
        y.atomicOp!"+="(1);
    }
    writeln(x); /* usually less than 100_000 */
    writeln(y); /* 100_000 */
}
----

Reply via email to