digitalmars.D.learn - How to specify number of worker threads for Taskpool
- Sparsh Mittal (14/14) Feb 17 2013 I am seeing
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (19/33) Feb 17 2013 Please also consider:
- Sparsh Mittal (1/1) Feb 17 2013 Thanks a lot for your reply. It was very helpful.
I am seeing I am running the example of parallel foreach given in that section. Sorry if it is too obvious, but my question is when using foreach(i, ref elem; taskPool.parallel(logs)) { elem = log(i + 1.0); } where taskPool is not explicitly defined, how do I specify number of worker threads? I don't know when is constructor of TaskPool called and hence when /////// trusted this(size_t nWorkers); /////// Allows for custom number of worker threads. function which allows for setting number of threads, is called. I will be thankful for your help.
Feb 17 2013
On 02/17/2013 08:23 AM, Sparsh Mittal wrote:I am seeingPlease also consider: http://ddili.org/ders/d.en/parallelism.htmlI am running the example of parallel foreach given in that section. Sorry if it is too obvious, but my question is when using foreach(i, ref elem; taskPool.parallel(logs)) { elem = log(i + 1.0); } where taskPool is not explicitly defined,That is a pre-defined object of the std.parallelism module.how do I specify number o worker threads?You cannot change taskPool. It is started with one less than the total cores of the system.I don't know when is constructor of TaskPool called and hence when /////// trusted this(size_t nWorkers); /////// Allows for custom number of worker threads. function which allows for setting number of threads, is called. I will be thankful for your help.You must construct a separate TaskPool object and use that one for your special needs. The following example from the link above uses just 2 cores: import std.stdio; import std.parallelism; void main() { auto workers = new TaskPool(2); foreach (i; workers.parallel([1, 2, 3, 4])) { writefln("Working on %s", i); } workers.finish(); } Ali
Feb 17 2013
Thanks a lot for your reply. It was very helpful.
Feb 17 2013