[phobos] std.parallelism: Request for review/comment
David Simcha
dsimcha at gmail.com
Tue Aug 31 20:33:51 PDT 2010
On 8/31/2010 3:07 PM, Sean Kelly wrote:
> A few general comments:
>
> I'm wondering whether the use of a TaskPool should always be explicit. Perhaps a default pool should be considered to exist, and calling parallel() instead of pool.parallel() will use that? It's rare for apps to have multiple distinct pools anyway, so this may be an easy way to help obscure a tiny bit more of the implementation.
Ok, I've done the following:
1. There is now a default pool that is initialized lazily with the
default number of threads. The function that retrieves it is called
taskPool().
2. Just to save typing and make the API a little more elegant, I added
a free function parallel() as a synonym for taskPool.parallel().
3. I don't want to make map() and reduce() free functions that forward
to taskPool.map() and taskPool.reduce() because these would collide with
std.algorithm which I expect would also be imported in most modules
using std.parallelism. This would force use of qualified names and not
actually be any less verbose than just typing taskPool.map(). I could
make parallelMap() and parallelReduce() functions, but these are not any
less verbose.
4. For tasks, I added a little syntactic sugar:
// Submit to default pool.
auto myTask = task!myFun(args).submit();
// Submit to explicitly instantiated pool.
auto pool = new TaskPool();
auto myTask = task!myFun(args).submitTo(pool);
Unfortunately, core.cpuid is still kind of buggy, so on a lot of newer
Intel machines the default pool will have the wrong number of threads
until this gets fixed. If anyone can think of a decent API, I can make
the number of threads in the default pool configurable.
More information about the phobos
mailing list