OpenMP:线程是否有办法终止所有其他并行线程?

发布于 2024-09-26 18:46:14 字数 154 浏览 0 评论 0原文

我正在尝试使用 openMP 进行大数据处理,并且相对较新。我的输入数据集很大,因此我将其分为多个子集,每个线程都处理数据子集。子集中的每个数据项都由线程执行。如果其中一个线程在对任何数据项进行操作期间失败,我想终止其他线程并返回失败。使用共享变量是一种选择,但是有更好的方法来做同样的事情吗?

I am experimenting with openMP for large data processing and relatively new to it. My input data set is huge and so I divided it into multiple subsets and each thread working on the subset of data. Each data item in the subset is acted up on by the thread. If one of the threads fails during its operation on any dataitem, i would like to terminate other threads and return a failure. Using shared variable is an option, but is there a better way to do the same ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长梦不多时 2024-10-03 18:46:14

如果您的某个线程因输入而阻塞,您希望发生什么情况?您想让程序突然停止吗?或者您想停止并行执行并整理程序的串行部分?

OpenMP 并不是真正为这两种操作而设计的,因此您将与它作斗争,而不是像大多数初学者那样与它作斗争。正如您所建议的,您当然可以使用共享变量并编写自己的逻辑来停止程序或在其中一个线程失败时跳转到并行区域的末尾。但 OpenMP 没有针对这些操作的内在机制。

您可能想要研究 OpenMP 3.0 的新任务功能。使用这些,您当然可以实现一个系统,其中任务被分派到返回成功或失败的线程,并且具有处理失败的其他任务。

最后,有人可能会争辩说,错误的输入不应导致程序崩溃,但那是另一个话题了。

What do you want to happen if one of your threads chokes on its input ? Do you want to bring the program to a sudden halt ? Or do you want to stop the parallel execution and have a serial part of the program tidy up ?

OpenMP is not really designed for either kind of operation, so you're going to be struggling against it, rather than struggling with it as most beginners do. You certainly could, as you suggest, use shared variables and write your own logic to stop the program or jump to the end of the parallel region if one of the threads fails. But there are no OpenMP intrinsic mechanisms for these operations.

You might want to investigate the new task capabilities of OpenMP 3.0. Using these you can certainly implement a system whereby tasks are dispatched to threads which return either success or failure, and have other tasks which deal with failures.

Finally, one might argue that bad input should not cause a program to crash, but that's another topic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文