openMP减少和线程数控制
openMP reduction and thread number control
我将 OpenMP 用作:
#pragma omp parallel for reduction(+:average_stroke_width)
for(int i = 0; i < GB_name.size(); ++i) {...}
我知道我可以使用 :
#pragma omp parallel for num_threads(thread)
for(int index = 0; index < GB_name.size(); ++index){...}
reduction时如何控制线程数?
How can I control the thread number when I use reduction?
两个子句可以一起使用:
#pragma omp parallel for reduction(+:average_stroke_width) num_threads(thread)
for(int i = 0; i < GB_name.size(); ++i) {...}
请注意,reduction
涉及所有线程,因此您不能使用 8 个线程的并行循环,然后仅使用 4 个线程执行归约。 Reduction结合了所有线程中的本地值,因此所有线程都需要参与。
我将 OpenMP 用作:
#pragma omp parallel for reduction(+:average_stroke_width)
for(int i = 0; i < GB_name.size(); ++i) {...}
我知道我可以使用 :
#pragma omp parallel for num_threads(thread)
for(int index = 0; index < GB_name.size(); ++index){...}
reduction时如何控制线程数?
How can I control the thread number when I use reduction?
两个子句可以一起使用:
#pragma omp parallel for reduction(+:average_stroke_width) num_threads(thread)
for(int i = 0; i < GB_name.size(); ++i) {...}
请注意,reduction
涉及所有线程,因此您不能使用 8 个线程的并行循环,然后仅使用 4 个线程执行归约。 Reduction结合了所有线程中的本地值,因此所有线程都需要参与。