【发布时间】:2018-05-30 07:37:45
【问题描述】:
我知道here 网站上有一个关于此的问题,但这是在 c 中实现的。我需要它的 c++ 版本。
问题如下: 我创建了一个具有以下形式的结构
struct word
{
char value[WORD_MAX_LENGTH];
int freq;
};
我需要发送这些结构的数组。如何序列化这个结构并使用 MPI_Send 将其中的 500 个发送到另一个进程。
这是我到目前为止的地方:
MPI_Datatype word_type, oldtypes[2];
int blockcounts[2];
MPI_Aint offsets[2], extent;
//Determine the offset and block length of the first element of the struct which is a char array.
offsets[0] = 0;
oldtypes[0] = MPI_CHAR;
blockcounts[0] = WORD_MAX_LENGTH;
//Determine the offset of int ferq of the struct.
MPI_Type_extent(MPI_CHAR, &extent);
offsets[1] = 16 * extent;
blockcounts[1] = 1;
// Finally create the type.
MPI_Type_create_struct(2, blockcounts, offsets, oldtypes, &word_type);
MPI_Type_commit(&word_type);
当我这样做时,它编译时没有错误,但是当我尝试运行它时。 它抱怨
Fatal error in PMPI_Type_create_struct: Invalid datatype, error stack:
PMPI_Type_create_struct(173): MPI_Type_create_struct(count=2,
array_of_blocklengths=0x7fffbd059f70,
array_of_displacements=0x7fffbd059f80, array_of_types=0x7fffbd059f60,
newtype=0x7fffbd059f14) failed
PMPI_Type_create_struct(142): Invalid datatype
任何帮助将不胜感激。 注意:我不能使用 boost 库。
【问题讨论】: