我有一个名为
Department
的结构体,以及名为 Departments
的结构体 Department 数组。我想将这个数组分散到特定数量的进程,以便每个进程都有一个名为 Current
的结构,其中包含 Departments
数组中的一个元素(结构)(部门)。
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
struct Department{
int position;
int Department_Destinations[100];
};
struct Department Current,Departments[100];
int main(int argc, char** argv){
int rank, nprocess;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &nprocess);
if(rank==0){
for(i=0;i<n;i++){
Departments[i].position=i+1;
for(j=0;j<c1;j++){
Departments[i].Department_Destinations[j]=0;
}
}
MPI_Scatter(Departments, sizeof(Current), MPI_BYTE, Current ,sizeof(Current), MPI_BYTE, 0,MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
假设进程数等于
Departments
元素(部门)的数量。
编译并运行此代码时,出现以下错误:“‘MPI_Scatter’的参数 4 的类型不兼容”
为什么会出现此错误以及如何在 MPI 中分散结构数组(部门)?
MPI_Scatter()
需要一个指向要分散的缓冲区的指针和一个指向将接收消息的缓冲区的指针。
如果
struct Department Current,Departments[100];
,你可以尝试一下吗:
MPI_Scatter(Departments, sizeof(Current), MPI_BYTE, &Current ,sizeof(Current), MPI_BYTE, 0,MPI_COMM_WORLD);