std.parallelism taskPool.map example throws exception
Jay Norwood via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Aug 7 18:06:40 PDT 2015
Unfortunately, this is not a very good example for
std.parallelism, since the measured times are better using the
std.algorithm.map calls. I know from past experience that
std.parallelism routines can work well when the work is spread
out correctly, so this example could be improved.
This is parallel
D:\visd\map\map\Release>map
sum=1.17335e+07
time msecs:1242
Non-parallel
D:\visd\map\map\Release>map
sum=1.17335e+07
time msecs:970
I think this example
import std.parallelism;
import std.algorithm;
import std.stdio;
import std.conv;
import std.math;
import std.range;
import std.file;
import std.datetime;
void main()
{
auto fn = "numberList.txt";
auto f = File(fn,"w");
scope(exit) std.file.remove(fn);
foreach (i ; iota(10.0,2_000_000.0)){
f.writefln("%g",i+0.5);
}
f.close();
std.datetime.StopWatch sw;
sw.start();
auto lineRange = File(fn).byLineCopy();
auto chomped = std.algorithm.map!"a.chomp"(lineRange);
auto nums = std.algorithm.map!(to!double)(chomped);
auto logs = std.algorithm.map!log10(nums);
double sum = 0;
foreach(elem; logs)
{
sum += elem;
}
long tm = sw.peek().msecs;
writeln("sum=",sum);
writeln("time msecs:", tm);
}
More information about the Digitalmars-d-learn
mailing list