【发布时间】:2011-08-23 14:45:14
【问题描述】:
我正在尝试使用 MPI_Datatype 发送以下结构,但 MPI_Send 在发送结构时崩溃。我想知道如何处理这种情况。这是我为定义新的 MPI 数据类型而编写的代码:
typedef struct
{
double x;
double y;
} vertex;
typedef struct
{
int num_vertices;
vertex vertex[2];
} vertex_list;
MPI_Datatype vertexType;
MPI_Type_contiguous(2,MPI_DOUBLE,&vertexType);
MPI_Type_commit(&vertexType);
MPI_Datatype vertexListType;
MPI_Datatype typev[3] = {MPI_INT, vertexType, MPI_UB};
int blocklenv[3] = {1, 2, 1};
MPI_Aint dispv[3];
/* compute displacements of structure components */
MPI_Address( vertexl, dispv);
MPI_Address( vertexl[0].vertex, dispv+1);
MPI_Address( vertexl+1, dispv+2);
base = dispv[0];
for (i=0; i <3; i++)
dispv[i] -= base;
/* build datatype describing structure */
MPI_Type_struct( 3, blocklenv, dispv, typev, &vertexListType);
MPI_Type_commit(&vertexListType);
https://docs.google.com/document/d/1OQFtx0ClkKQx7X91BlVgiizs5D9jShhtgsKafrgC7hk/edit?hl=en
【问题讨论】:
-
您可以编辑您的帖子而不是添加 cmets。帖子中的代码可以很好地格式化,问题会更好。
-
我已经为你复制了代码(只是等待同行评审)。将来,正如
pmg所说,您可以编辑自己的帖子,使用代码格式有助于获得更快的响应。 -
你也应该显示发送。
-
感谢您的回复@Captain @Head。如果嵌套结构中的数据不连续,例如当顶点是指针字段时,如何 MPI_Send : typedef struct { double x;双 y; } 顶点; typedef struct { int num_vertices;顶点*顶点; } 顶点列表;
标签: c distributed mpi distributed-computing