问题描述
我有一个非常复杂的程序,必须与MPI并行运行.我为此使用MPICH3.
I have a quite complex program which I have to parallel with MPI. I use MPICH3 for this.
我知道制作新MPI_Datatype的方法为:
I know the way to make a new MPI_Datatype as:
typedef struct{
float x;
float y;
int centroid;
} point;
typedef struct{
int csize;//the current size
int tsize;//the total size
point * data;//the data carried
} ArrayList;
const int nfields=3;
MPI_Aint disps[nfields];
int blocklens[] = {1,1,1};
MPI_Datatype types[] = {MPI_FLOAT, MPI_FLOAT, MPI_INT};
disps[0] = offsetof( point, x );
disps[1] = offsetof( point, y );
disps[2] = offsetof( point, centroid );
MPI_Datatype istruct, pstruct;
MPI_Type_create_struct(nfields, blocklens, disps, types, &istruct );
MPI_Type_create_resized( istruct, 0, (char *)&(points[1]) - (char *)(&points[0]), &pstruct );
MPI_Type_commit(&pstruct);
但是我必须执行以下结构BigInteger的MPI_Datatype:
But I have to do a MPI_Datatype of the following struct BigInteger:
struct mylimb
{
int x;
};
typedef struct mylimb limb;
typedef enum eBoolean
{
FALSE = 0,
TRUE,
} boolean;
enum eSign
{
SIGN_POSITIVE = 0,
SIGN_NEGATIVE,
};
typedef struct BigInteger
{
limb limbs[1000];
int nbrLimbs;
enum eSign sign;
} BigInteger;
该结构在代码中广泛使用,因此我不能简单地将其更改为更简单的方法.那么有人可以告诉我如何从BigInteger中进行MPI_Datatype吗?我的主要问题是肢体是肢体,我该如何将其连接到我的MPI_Datatype
The struct is widely used in the code so I can not simply change it to a easier way. So can anybody tell my how I can do a MPI_Datatype from the BigInteger?My main problem is the limb which is a mylimb how can I concat this into my MPI_Datatype
提前谢谢!chrigi
Thanks in advance!chrigi
推荐答案
另一种重写BigInteger
的方法是
typedef struct BigInteger
{
int limbs[1000];
int nbrLimbs;
enum eSign sign;
} BigInteger;
,因此您可以将MPI_Type_create_struct()
与blocklens={1000,1,1}
一起使用
so you can use MPI_Type_create_struct()
with blocklens={1000,1,1}
我主要关心的是enum eSign
的大小.如果您不混合大小尾序,可以将其声明为MPI_BYTE
和sizeof(enum eSign)
my main concern is the size of enum eSign
. if you do not mix big and little endian, you can declare it as MPI_BYTE
and sizeof(enum eSign)
这篇关于MPI从包含具有structs和typedef的结构的结构中创建MPI_Datatype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!