使用 OpenMP 处理程序中的 GUI 线程
我有一个 C++ 程序,它使用 OpenMP 并行执行一些冗长的计算。现在该程序还必须响应用户输入并更新一些图形。到目前为止,我一直从主/GUI 线程开始计算,仔细平衡工作负载,以便它既不会太短而掩盖 OpenMP 线程开销,也不会太长而导致 GUI 变得无响应。
显然我想通过同时运行所有内容来解决这个问题。据我所知,OpenMP 2.5 没有提供一个很好的机制来执行此操作。我认为它不是针对此类问题的。我也不想将整个核心专用于 GUI 线程,它只需要 <10% 的核心来完成其工作。
我认为也许将计算分离到一个单独的 pthread 中来启动并行结构将是解决这个问题的好方法。我对此进行了编码,但从 pthread 调用时 OpenMP 崩溃,类似于此错误: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36242。请注意,我并没有尝试一次从多个线程启动并行构造,OpenMP 在整个程序中仅在一个 pthread 中使用。
看来我既不能使用 OpenMP 来同时安排 GUI 工作,也不能使用 pthreads 来让并行结构同时运行。我正在考虑在一个单独的线程中处理我的 GUI 工作,但在我的情况下,这恰好相当丑陋,并且由于我使用的各种库,实际上可能无法工作。
这里的教科书解决方案是什么?我确信其他人已经在需要同时处理 GUI/网络等的程序中使用了 OpenMP,但我无法使用 Google 或 OpenMP 论坛找到任何信息。
谢谢!
I have a C++ program that performs some lengthy computation in parallel using OpenMP. Now that program also has to respond to user input and update some graphics. So far I've been starting my computations from the main / GUI thread, carefully balancing the workload so that it is neither to short to mask the OpenMP threading overhead nor to long so the GUI becomes unresponsive.
Clearly I'd like to fix that by running everything concurrently. As far as I can tell, OpenMP 2.5 doesn't provide a good mechanism for doing this. I assume it wasn't intended for this type of problem. I also wouldn't want to dedicate an entire core to the GUI thread, it just needs <10% of one for its work.
I thought maybe separating the computation into a separate pthread which launches the parallel constructs would be a good way of solving this. I coded this up but had OpenMP crash when invoked from the pthread, similar to this bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36242 . Note that I was not trying to launch parallel constructs from more than one thread at a time, OpenMP was only used in one pthread throughout the program.
It seems I can neither use OpenMP to schedule my GUI work concurrently nor use pthreads to have the parallel constructs run concurrently. I was thinking of just handling my GUI work in a separate thread, but that happens to be rather ugly in my case and might actually not work due to various libraries I use.
What's the textbook solution here? I'm sure others have used OpenMP in a program that needs to concurrently deal with a GUI / networking etc., but I haven't been able to find any information using Google or the OpenMP forum.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有教科书上的解决方案。 OpenMP 的教科书应用程序是非交互式程序,它们读取输入文件、执行大量计算并写入输出文件,所有这些都使用超级计算机中大小约为 #CPU 的相同线程池。它不是为交互式和计算代码的并发执行而设计的,我认为规范不能保证与任何线程库的互操作。
抛开理论不谈,您似乎在 OpenMP 的 GCC 实现中遇到了一个错误。请向 GCC 维护人员提交错误报告,暂时寻找不同的编译器或在单独的进程中运行 GUI 代码,通过某种 IPC 机制与 OpenMP 程序进行通信。 (例如,通过套接字的异步 I/O。)
There is no textbook solution. The textbook application for OpenMP is non-interactive programs that read input files, do heavy computation, and write output files, all using the same thread pool of size ~ #CPUs in your supercomputer. It was not designed for concurrent execution of interactive and computation code and I don't think interop with any threads library is guaranteed by the spec.
Leaving theory aside, you seem to have encountered a bug in the GCC implementation of OpenMP. Please file a bug report with the GCC maintainers and for the time being, either look for a different compiler or run your GUI code in a separate process, communicating with the OpenMP program over some IPC mechanism. (E.g., async I/O over sockets.)