OpenMP中的并行合并排序 [英] Parallel Merge-Sort in OpenMP

查看:399
本文介绍了OpenMP中的并行合并排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我在多核上运行它.发生的是,在树的叶子处,有两个线程并行运行.他们完成工作后,将启动其他2个线程,依此类推.即使我们为所有叶节点提供了免费内核.

I run it on a multicore. What happens is that at the leafs of the tree, 2 threads run in parallel. After they finished their work 2 other threads start and so on. Even if we have free cores for all the leaf nodes.

我认为原因是此OpenMP代码未在并行区域内创建并行区域.我说得对吗?

I think the reason is this OpenMP code does not create parallel regions inside parallel regions. Am I correct?

推荐答案

我认为原因是OpenMP无法在并行区域内创建并行区域"

"I think the reason is that OpenMP cannot create parallel regions inside parallel regions"

您可以具有平行区域的平行区域.

You can have parallel region of parallel region.

OpenMP并行区域可以彼此嵌套.如果嵌套 禁用并行性,然后由线程创建新团队 在并行区域内遇到并行构造包括 仅遇到线程.如果启用了嵌套并行操作, 那么新团队可能包含多个线程((

OpenMP parallel regions can be nested inside each other. If nested parallelism is disabled, then the new team created by a thread encountering a parallel construct inside a parallel region consists only of the encountering thread. If nested parallelism is enabled, then the new team may consist of more than one thread (source).

为了正确运行代码,您需要调用omp_set_nested(1)omp_set_num_threads(2).

In order to run your code correctly, you need to call omp_set_nested(1) and omp_set_num_threads(2).

可以通过设置 OMP_NESTED环境变量或调用omp_set_nested()函数

Nested parallelism can be enabled or disabled by setting the OMP_NESTED environment variable or calling omp_set_nested() function

这篇关于OpenMP中的并行合并排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆