[Issue 15134] std.parallelism taskPool.amap fails to compile with array of structs or Tuples with named members

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Oct 1 12:24:07 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15134

--- Comment #1 from Jay Norwood <jayn at prismnet.com> ---
This may be my problem.  I see this works with array of struct as inputs and a
Tuple as result with named members. So this is not a blocker.  I'll need to
check if there was some other problem with the original example which had named
Tuple members and array of Tuple as the input.

import std.algorithm, std.parallelism, std.range;
import std.typecons;
import std.meta;
import std.stdio;

// define some input measurement sample tuples and output metric tuples

struct TI {long L1I_MISS; long L1D_MISS; long cycles; }
alias TO = Tuple!(long, "raw", double, "per_cyc");

// various metric definitions
// using Tuples with defined names for each member, and use the names here in
the metrics.
TO met_l1_miss ( ref TI m){ TO rv;  rv.raw = m.L1I_MISS+m.L1D_MISS;  rv.per_cyc
= cast(double)rv.raw/m.cycles; return rv; }

// a convenience to use all the metrics above as a list
alias Metrics = AliasSeq!(met_l1_miss);

void main(string[] argv)
{
    auto samples = iota(100);
    auto meas = new TI[samples.length];
    auto results = new TO[samples.length];

    // Initialize some values for the measured samples
    foreach(i, ref m; meas){
        m.L1D_MISS= 100+i; m.L1I_MISS=100-i; m.cycles= 10+i;
    }

    ref TI getTerm(int i)
    {
        return meas[i];
    }

    // compute the metric results for the above measured sample values in
parallel
    taskPool.amap!(Metrics)(std.algorithm.map!getTerm(samples),results);

    TO rv1 = met_l1_miss( meas[1]);

    writeln("measurements:", meas[1]);
    writeln("rv1:", rv1);
    writeln("results:", results[1]);

}

--


More information about the Digitalmars-d-bugs mailing list