Controlling the number of parallel threads in the programming language D

I learn the D language because I'm interested in its parallelism support. Here is a parallel code snippet from my project:

import std.parallelism; foreach (node v; taskPool.parallel(std.range.iota(z))) { // call here handle(v); } 

How to control the number of threads that work in parallel? Is there an equivalent to the OpenMP omp_set_num_threads function?

+4
source share
1 answer

You can set defaultPoolThreads before using taskPool for the first time to set the number of threads, but this will not allow you to change it on the fly.

http://dlang.org/phobos/std_parallelism.html#.defaultPoolThreads

In addition, you can explicitly create new TaskPools instead of using the default. Depending on what you are trying to do, this may also be an option.

http://dlang.org/phobos/std_parallelism.html#.TaskPool.this

+6
source

Source: https://habr.com/ru/post/1493699/


All Articles