繁体   English   中英

MPI派生数据类型

[英]MPI derived data type

我有一个需要使用OpenMPI的任务,在这里我需要创建一种新的数据类型来发送消息,因此我对此进行了搜索并发现了一些东西。

遵循本教程之后,我这样做了:

typedef struct {

    int a;
    int b;

}SpecialData;

SpecialData p,q,vector[size];
MPI_Datatype tipSpecial , oldType[2];
int noBlocks[2];
MPI_Aint offsets[2],extent;

MPI_Init(&argc, &argv);

MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

// setup the 7 double fields
offsets[0] = 0 ;
oldType[0] = MPI_DOUBLE;
noBlocks[0] = 7;

//setup the 4 int fields of the struct
MPI_Type_extent(MPI_DOUBLE, &extent);
offsets[1] = 8 * extent;
oldType[1] = MPI_INT;
noBlocks[1] = 4;
MPI_Type_struct(2, noBlocks, offsets, oldType, &tipSpecial);
MPI_Type_commit(&tipSpecial);
///... Some code here where I do things based on the rank.
p.a = 9;
p.b = 9;


MPI_Send(p, 1, tipSpecial, 0, tag, MPI_COMM_WORLD);
MPI_Recv(q,1, tipSpecial, 0, tag, MPI_COMM_WORLD, &status);

我在发送和接收时特别在第一个参数时出错。

Error:
Main.c: In function ‘main’:
Main.c:125:3: error: incompatible type for argument 1 of ‘MPI_Send’
   MPI_Send(p, 1, tipSpecial, 0, tag, MPI_COMM_WORLD);

知道为什么会这样吗?

MPI_SendMPI_RecvMPI_Send指向数据缓冲区的指针作为其第一个参数。 与数组不同,要获取标量变量的地址,必须使用引用运算符&

 MPI_Send(&p, 1, tipSpecial, 0, tag, MPI_COMM_WORLD);
 //       ^
 MPI_Recv(&q, 1, tipSpecial, 0, tag, MPI_COMM_WORLD, &status);
 //       ^

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM