在openMPI中向进程发送数据(以字节为单位)的最佳方式
best way to send data(given in Bytes) to a process in openMPI?
我正在这样做,假设我需要向根进程发送临时字节数:
var char*;
var=new char[temp];
MPI_Isend(&temp,1,MPI_INT,0,tag,MPI_COMM_WORLD,&request[0]);
MPI_Isend(var,temp,MPI_BYTE,0,tag,MPI_COMM_WORLD,&request[1]);
在根进程上,我正在编写以下代码,
MPI_Recv(&temp,1,MPI_INT,i,tag,MPI_COMM_WORLD,&status[0]);
var=new char[temp];
MPI_Recv(var,temp,MPI_BYTE,0,tag,MPI_COMM_WORLD,&status[1]);
我能够在根进程接收temp(要传输的数据字节数),并在下一部分看到截断消息的错误?
您不需要将元素的数量作为单独的消息发送。MPI提供了一种机制,允许程序窥探消息队列,并在接收消息之前获得消息大小
发件人:
char *var = new char[temp];
MPI_Send(var, temp, MPI_BYTE, 0, tag, MPI_COMM_WORLD);
接收器:
MPI_Status status;
int temp;
// Probe for matching message without receiving it
MPI_Probe(i, tag, MPI_COMM_WORLD, &status);
// Get the number of data elements in the message
MPI_Get_count(&status, MPI_BYTE, &temp);
char *var = new char[temp];
MPI_Recv(var, temp, MPI_BYTE, i, tag, MPI_COMM_WORLD, &status);
这是一种与不同大小的阵列进行通信的最佳方式。
您从错误的位置接收:
MPI_Recv(var,temp,MPI_BYTE,0,tag,MPI_COMM_WORLD,&status[1]);
^
您应该(大概)从i
进程接收。
相关文章:
- 从原始字节解码协议缓冲区(以 C++为单位)
- 如何在 c++ 中确定一条指令(以字节为单位)在哪里结束,另一条指令从哪里开始?
- 获取嵌套 stl 容器的大小(以字节为单位)
- 常量"C"占用的空间(以字节为单位)
- C++ 中 STL 中迭代器的大小(以字节为单位)是多少
- 如何以C++为单位计算向量中的字节数?
- 有人知道可以使用 c++ 以字节为单位编码 asm 字符串的任何东西吗?
- 如何以字节为单位计算mpz_class的长度?
- 获取C++模板参数包的总大小(以字节为单位)
- 快速简单的方法,以C++为单位一次读取一个字节的 stdin
- 以C++(Arduino)为单位比较指针到字节
- C++/C:Char[]的前缀长度(以字节为单位)(二进制/十六进制)
- 以 C++ 为单位设置(短整型)的上下字节
- visual 在指向缓冲区(字符串 " ")的空指针上使用 sizeof() C++ 以获得以字节为单位的大小?
- 如何获得以字节为单位的UTF-16LE字符串的大小
- 为什么 C/C++ "Hello World" 以千字节为单位?
- 在 C++ 中以字节块为单位读取和写入文件
- 以 C++ 为单位递增 16 字节字符数组
- C++字符串长度(以字节为单位)
- 解码像 FAST 这样的数据协议的快速方法是什么,其中数据以字节为单位编码,并将位作为存在标志