1 c c++ struct cluster-computing mpi
我正在为MPI创建新的派生数据类型以从Counter结构发送数据,你知道在MPI中创建新类型是痛苦和棘手的,因为如果我在正确的轨道上我需要一些帮助并且谢谢你?
typedef struct Counter{
int range1,range2,range3,range4;
double preset1 ,preset2 ,preset3 ,preset4;
} countType;
MPI_Datatype createRecType()
{
// Set-up the arguments for the type constructor
MPI_Datatype new_type;
int count = 2;
int blocklens[] = { 4, 4 };
MPI_Aint indices[4];
indices[0] = 0;
MPI_Type_extent( MPI_DOUBLE, &indices[1] );
indices[1] *= 4; // There are 2 doubles
MPI_Datatype old_types[] = { MPI_INT ,MPI_DOUBLE};
// Call the data type constructor
MPI_Type_struct(count, blocklens, indices, old_types, &new_type);
MPI_Type_commit(&new_type);
return new_type;
}
Run Code Online (Sandbox Code Playgroud)
如果我猜对了,请参阅https://computing.llnl.gov/tutorials/mpi/#Derived_Data_Types和"示例:Struct Derived Data Type"部分.它介绍了如何描述定义为"粒子":
typedef struct {
float x, y, z;
float velocity;
int n, type;
} Particle;
Run Code Online (Sandbox Code Playgroud)
这样MPI就可以处理它们的数组.整个相关片段是:
/* Setup description of the 4 MPI_FLOAT fields x, y, z, velocity */
offsets[0] = 0;
oldtypes[0] = MPI_FLOAT;
blockcounts[0] = 4;
/* Setup description of the 2 MPI_INT fields n, type */
/* Need to first figure offset by getting size of MPI_FLOAT */
MPI_Type_extent(MPI_FLOAT, &extent);
offsets[1] = 4 * extent;
oldtypes[1] = MPI_INT;
blockcounts[1] = 2;
/* Now define structured type and commit it */
MPI_Type_struct(2, blockcounts, offsets, oldtypes, &particletype);
MPI_Type_commit(&particletype);
Run Code Online (Sandbox Code Playgroud)
您的代码似乎遵循所有这些.除非你有一些拼写错误,否则你的代码似乎没问题.但我不能保证它,除非我尝试编译并运行它;)
有一点可以肯定,你indices
太大了.[2]就足够了.但是把它放大不会有任何坏处.该count
说2,所以MPI将无法读取该数组这些额外的元素.