Thread Building Block 与 MPI,哪一个更适合您的需要?

发布于 2024-08-20 06:48:06 字数 304 浏览 3 评论 0原文

现在我有一个 C++ 串行求解器用于解决优化问题,我应该使用不同的参数并行化我的求解器,看看它是否可以帮助提高求解器的性能。现在我不确定我应该使用TBB还是MPI。从我读过的TBB书籍来看,我感觉TBB更适合循环或细粒度代码。由于我对TBB没有太多经验,我觉得很难将我的代码分成小部分以实现并行化。另外,从文献中,我发现很多作者使用MPI来并行多个求解器并使其协作。我想也许 MPI 更适合我的需要。因为我对 TBB 或 MPI 都不太了解。谁能告诉我我的感觉是否正确? MPI 会更适合我吗?如果是的话,开始学习MPI有什么材料好呢?我没有MPI经验,我使用Windows系统和c++。多谢。

Now I have a serial solver in C++ for solving optimization problems and I am supposed to parallelize my solver with different parameters to see whether it can help improve the performance of the solver. Now I am not sure whther I should use TBB or MPI. From a TBB book I read, I feel TBB is more suitable for looping or fine-grained code. Since I do not have much experience with TBB, I feel it is difficult to divide my code to small parts in order to realize the parallelization. In addition, from the literature, I find many authors used MPI to parallel several solvers and make it cooperate. I guess maybe MPI fits my need more. Since I do not have much knowledge on either TBB or MPI. Anyone can tell me whether my feeling is right? Will MPI fit me better? If so, what material is good for start learning MPI. I have no experience with MPI and I use Windows system and c++. Thanks a lot.

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

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

发布评论

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

评论(1

不寐倦长更 2024-08-27 06:48:06

您需要记住的基本事情是在共享内存和分布式内存之间进行选择。
共享内存是指有多个进程(通常是一个进程内有多个线程)可以访问公共内存。这可以是相当细粒度的,并且通常更简单地将单线程程序调整为具有多个线程。您需要以这样的方式设计程序:线程大部分时间在内存的不同部分中工作(利用数据并行性),并且共享部分使用锁来防止并发访问。
分布式内存意味着您有可能在一台或多台分布式计算机中执行的不同进程,但这些进程有一个共同的目标并通过消息传递(数据通信)共享数据。没有公共内存空间,一个进程需要的来自另一进程的所有数据都需要通信。
这是一种更通用的方法,但由于通信要求,它需要粗粒度。
TBB 是一个支持基于线程的共享内存并行性的库,而 MPI 是一个支持分布式内存并行性的库(它具有简单的通信原语以及用于不同节点执行中的多个进程的脚本)。

最重要的是您要确定求解器中的并行性,然后选择最佳解决方案。您是否具有数据并行性(不同的线程/进程可以在不同的数据块中并行工作,而不需要通信或共享该数据的部分内容)?任务并行性(不同的线程/进程可能对数据执行不同的转换,或者以管道或图形方式执行数据处理中的不同步骤)?

The basic thing you need to have in mind is to choose between shared-memory and distributed-memory.
Shared-memory is when you have more than one process (normally more than one thread within a process) that can access a common memory. This can be quite fine-grained and it is normally simpler to adapt a single-threaded program to have several threads. You will need to design the program in a way that the threads work most of the time in separate parts of the memory (exploit data parallelism) and that the shared part is protected against concurrent accesses using locks.
Distributed-memory means that you have different processes that might be executed in one or several distributed computers but these process have together a common goal and share data through message-passing (data communication). There is no common memory space and all the data one process need from another process will require communication.
It is a more general approach but, because of communication requirements, it requires coarse grains.
TBB is a library support for thread-based shared-memory parallelism while MPI is a library for distributed-memory parallelism (it has simple primitives for communication and also scripts for several processes in different nodes execution).

The most important thing is for you to identify the parallelisms within your solver and then choose the best solution. Do you have data parallelism (different thread/processes could be working in parallel in different chunks of data without the need of communication or sharing parts of this data)? Task parallelism (different threads/processes could be performing a different transformation to your data or a different step in the data processing in a pipeline or graph fashion)?

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