an example of parallel calculation of metrics

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 1 11:08:30 PDT 2015


On 10/01/2015 08:56 AM, Jay Norwood wrote:

 > Thanks.  My particular use case, working with metric expressions, is
 > easier to understand if I use the names.

Makes sense. Please open a bug at least for investigation why tuples 
with named members don't work with amap.

 > I converted the use of Tuple
 > to struct to see if I could get an easier error msg. Turns out the use
 > of struct also results in much cleaner writeln text.
 >
 > Still has the compile error, though.

We have to live with the fact that amap and friends produce a Tuple 
result if there are multiple functions. A struct won't work.

However, if you prove to yourself that the result tuple and your struct 
have the same memory layout, you can cast the tuple slice to struct 
slice after calling amap:

alias TO_for_amap_result = Tuple!(TR, TR, TR, TR);
struct TO { TR L1_MISS; TR L1_HIT; TR DATA_ACC; TR ALL_ACC;}

// ...

     auto results_for_amap = new TO_for_amap_result[samples.length];

// ...

 
taskPool.amap!(Metrics)(std.algorithm.map!getTerm(samples),results_for_amap);

     auto results = cast(TO[])results_for_amap;

// Use 'results' from this point on...

Ali



More information about the Digitalmars-d-learn mailing list