【发布时间】:2021-02-05 14:04:24
【问题描述】:
我有结构(复矩阵的单个元素):
typedef struct s_complex_number {
int real;
int img;
} ComplexNumber;
这就是我将复杂矩阵描述为自定义 MPI 数据类型的方式
#define SIZE_COL 10
MPI_Datatype matrix;
MPI_Datatype types[2] = {MPI_INT, MPI_INT};
MPI_Datatype row;
MPI_Datatype complexNumber;
MPI_Aint disp[2];
ComplexNumber ***recvData;
ComplexNumber ***sendData;
ComplexNumber example;
int blockLength[] = {1, 1};
disp[0] = (uintptr_t)&example.real - (uintptr_t)&example;
disp[1] = (uintptr_t)&example.img - (uintptr_t)&example;
/***********************Initialize custom types************************/
MPI_Type_create_struct(2, blockLength, disp, types, &complexNumber);
MPI_Type_commit(&complexNumber);
MPI_Type_vector(1, SIZE_COL, 1, complexNumber, &row);
MPI_Type_commit(&row);
MPI_Type_vector(1, SIZE_COL, 1, row, &matrix);
MPI_Type_commit(&matrix);
/**********************************************************************/
每次我尝试发送数据时,都会出现分段错误。
如何正确描述 MPI 中的 ComplexNumber** 类型?
【问题讨论】:
-
您可以使用预定义的
MPI_2INT数据类型。 MPI 需要连续内存中的数据(例如,没有锯齿状数组),您可以确保这一点。
标签: c types segmentation-fault mpi