混合开放MP/MPI代码中的多线程发送/接收时出错
Error in sending/receiving by multi-threads in hybrid openMP/MPI code
我在下面的代码中使用了OpenMP和MPI。我正在一台多核Windows机器上进行测试。
我得到了这两个错误:
[0] 致命错误 MPI_Send中的致命错误:其他 MPI 错误,错误堆栈: MPI_Send(buf=0x00007FF67497F33C, 计数=1, MPI_INT, dest=2, tag=1, MPI_COMM_WORLD( 失败 名片中缺少主机名或主机/端口描述无效
[1] 致命错误 MPI_Recv中的致命错误:其他 MPI 错误,错误堆栈: MPI_Recv(buf=0x00007FF67497F33C, 计数=1, MPI_INT, src=0, tag=1, MPI_COMM_WORLD, status=0x00007FF67497F348( 失败 共享内存队列名称没有空间
然后在另一次运行中,我收到此错误:
[0] 致命错误 MPI_Send中的致命错误:其他 MPI 错误,错误堆栈: MPI_Send(buf=0x000000172E31FCC4, 计数=1, MPI_INT, 目标=2, 标记=1, MPI_COMM_WORLD( 失败 在之前的尝试中无法与 2 通信
#include<iostream>
#include "mpi.h"
#include <omp.h>
using namespace std;
int numOfProc, id, array_size, portion;
int *arr = NULL;
MPI_Status status;
const static int tag = 1;
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numOfProc);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
cout << "Hello from Process # " << id << 'n';
int data;
omp_set_num_threads(2);
#pragma omp parallel for
for (int i = 1; i < 20; i++)
{
if (id == 0)//master
{
for (int p = 1; p < numOfProc; p++)
{
data = i*p;
MPI_Send(&data, 1, MPI_INT, p, tag, MPI_COMM_WORLD);
}
}
else // slaves
{
MPI_Recv(&data, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
cout << "Process " << id << " recieved " << data << " by thread " << omp_get_thread_num() << endl;
}
}
MPI_Finalize();
}
首先,您需要MPI_Init_thread()
MPI_THREAD_MULTIPLE
并确保库确实提供了此功能。
相关文章:
- 在C++中使用cURL和多线程
- 多线程双缓冲区
- 为什么我的多线程作业队列崩溃
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 试图创建一个多线程程序来查找0-100000000之间的总素数
- 为什么一个向量上的多线程操作很慢
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 全局变量 多读取器 一个写入器多线程安全?
- boost::文件系统::recursive_directory_iterator多线程安全
- 如何阻止TensorFlow的多线程
- 如何在多线程中正确使用unique_ptr进行多态性?
- 并发/多线程:是否可以以这种方式生成相同的输出?
- sigwait() 在多线程程序中不起作用
- 多线程程序中出现意外的内存泄漏
- 静态 constexpr 类成员变量对多线程读取是否安全?
- 多线程比没有线程C++慢
- 具有 C++11 多线程的特征库
- 通过安装信号处理程序关闭多线程应用程序
- 混合开放MP/MPI代码中的多线程发送/接收时出错
- 使用boost库编写多线程程序时出错