我正在尝试使用MPI_Send和MPI_Recv发送包含从0级到rank1的变量数的结构。我得到分段错误。有什么帮助吗?这是我的代码:
typedef struct {
double x;
double y;
double z;
int e[8];
int ID;
int n_n[7];
int corner_ID;
int val;
int loc;
int proc;
int local;
int global;
int req; } MNODE;
MPI_Datatype send_node;
MPI_Datatype type1[13] = {MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT};
int blocklen1[13] = {1,1,1,8,1,7,1,1,1,1,1,1,1};
MPI_Aint disp1[13] = {0,sizeof(double),2*sizeof(double),3*sizeof(double)+8*sizeof(double),3*sizeof(double)+9*sizeof(double),3*sizeof(double)+16*sizeof(double),3*sizeof(double)+17*sizeof(double),3*sizeof(double)+18*sizeof(double),3*sizeof(double)+19*sizeof(double),3*sizeof(double)+20*sizeof(double),3*sizeof(double)+21*sizeof(double),3*sizeof(double)+22*sizeof(double),3*sizeof(double)+23*sizeof(double)};
MPI_Type_create_struct(13,blocklen1,disp1,type1,&send_node);
MPI_Type_commit(&send_node);
int NUMNP, i;
NUMNP = 20;
MNODE *node;
node = (MNODE*)malloc(NUMNP*sizeof(MNODE));
if (myrank == 0)
{
MPI_Send(node, NUMNP, send_node, 1, 1, MPI_COMM_WORLD);
}
if (myrank == 1)
{
MNODE *d_node;
d_node = (MNODE*)malloc(NUMNP*sizeof(MNODE));
MPI_Recv(d_node, NUMNP, send_node, 0, myrank, MPI_COMM_WORLD, &status);
}