MPI_Gather-向主机发送数据
MPI_Gather - Send data to the master
我想使用MPI_Gather将数据发送到列组0。但我做错了什么:
int size;
int rank;
int i;
int b;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
int* bb= new int[size];
//slave
if(rank!=0) {·
b=13;·
printf("slave %d n", b);
// sleep(5);
MPI_Gather(&b,1,MPI_INT,bb,1,MPI_INT,0,MPI_COMM_WORLD);
}
//master
if(rank==0)
{
b=12;
printf("master %d n", b);
for (i = 0; i < size; i++) {
printf("%dt", bb[i]);
}
}
MPI_Finalize();
return 0;
我期望bb=[12,13]。你知道怎么做吗?非常感谢。
MPI_Gather
。您应该将调用移出条件块:
//slave
if(rank!=0) {
b=13;
printf("slave %d n", b);
}
else {
b=12;
printf("master %d n", b);
}
// all
MPI_Gather(&b,1,MPI_INT,bb,1,MPI_INT,0,MPI_COMM_WORLD);
//master
if(rank==0)
{
for (i = 0; i < size; i++) {
printf("%dt", bb[i]);
}
}
相关文章:
- 防止主数据类型C++的隐式转换
- 用于访问容器<T>数据成员的正确 API
- 嵌套在类中时无法设置成员数据
- 使用流处理接收到的数据
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 来自复杂主机数据的阵列火力阵列
- 通过套接字一致地丢失数据(但在使用本地主机连接时不会)
- C++ 如何接收从互联网站点到本地主机的流数据包
- 将数据保存到空闲主机上的文件中
- 将二进制数据从Qt/C++DLL传递到Delphi主机应用程序中
- 通过Linux套接字接收多个主机的数据
- 如何将设备内存中分配的结构化数据从设备复制到主机
- 在将复杂数据从主机传输到设备的简单 CUDA 代码中出现问题
- MPI_Gather-向主机发送数据
- UDP发送()到本地主机在Winsock下丢弃数据包
- 保持主机数据完整,同时传输到CUDA GPU
- 从Oracle PL/SQL中获取数据到主机阵列
- Gstreamer:为什么我不能在本地主机上通过UDP发送数据?
- 从主机内部通过网络发送midi数据
- CUDA扩展std::vector来管理主机和设备数据