Types 向MPI结构添加填充

Types 向MPI结构添加填充,types,io,mpi,memory-alignment,Types,Io,Mpi,Memory Alignment,我有一个C结构的数组,我想在读取文件时填充它(并行地,使用set_视图等等) 我的问题是,某些文件(类型1)将只有类型和值(在情况下,velocity必须保留为O,而在另一些文件(类型2)中,我有类型、值和速度 因此,当读取文件中的n块时,我要么读取nx9位(case1),要么读取nx17位(case2),我必须将其以良好的对齐方式放入缓冲区 我从一个mpi\u单元对齐的类型开始 MPI_Datatype mpi_cell_aligned; int count[] = { 1,

我有一个C结构的数组,我想在读取文件时填充它(并行地,使用set_视图等等)

我的问题是,某些文件(类型1)将只有
类型
(在情况下,velocity必须保留为O,而在另一些文件(类型2)中,我有
类型
速度

因此,当读取文件中的
n
块时,我要么读取nx9位(case1),要么读取nx17位(case2),我必须将其以良好的对齐方式放入缓冲区

我从一个
mpi\u单元对齐的
类型开始

MPI_Datatype mpi_cell_aligned;
int          count[] = { 1,                    1,                     1                        };
MPI_Aint     displ[] = { offsetof(Cell, type), offsetof(Cell, value), offsetof(Cell, velocity) };
MPI_Datatype types[] = { MPI_CHAR,             MPI_DOUBLE,            MPI_DOUBLE               };
switch(type)
{
    case 1: MPI_Type_create_struct(2, count, displ, types, &mpi_cell_aligned); break;
    case 2: MPI_Type_create_struct(3, count, displ, types, &mpi_cell_aligned); break;
}
MPI_Type_commit(&mpi_cell_aligned);
使用
MPI\u Type\u continuous
我还构建了一个
MPI\u cell\u packed
类型,表示9/17个连续位(ui是二进制文件中的格式)

我的问题是写入我的缓冲区,我试图构建一个向量类型,其中包含多个
mpi\u cell\u aligned
。在案例2中,每个类型都相邻,这很容易,但在案例1中,我必须考虑类型之间的填充,对应于1 double的长度

不幸的是,给定给
MPI_Type_Vector
的跨距必须以结构的数量来度量,而不是以字节来度量。同时,我不能仅仅用
MPI_BYTE
来描述我的向量,因为我的单元格结构没有满(字符和第一个双精度字符之间的对齐填充)


如何构建在案例1中正确表示单元数组的相应MPI数据类型?

您必须修改案例1中MPI类型的范围

类型的范围是用于知道在发送/接收/写入/读取操作中在何处查找以下元素的大小

主函数是MPI类型大小调整后的创建大小。在您的情况下,情况1中MPI类型的范围必须与情况2中MPI类型的范围相同

所以你必须这样做:

/* Temporary type */
MPI_Type_create_struct(2, count, displ, types, &mpi_cell_aligned_temp);
/* Compute new extent */
MPI_Type_size(mpi_cell_aligned_temp,&size_double);
extent = offsetof(Cell, velocity)+size_double;
/* Create new type with new extent */
MPI_Type_create_resized(mpi_cell_aligned_temp,0, extent,&mpi_cell_aligned_temp);
我使用sizeof(cell)作为扩展,我完成了这项工作。Thx
/* Temporary type */
MPI_Type_create_struct(2, count, displ, types, &mpi_cell_aligned_temp);
/* Compute new extent */
MPI_Type_size(mpi_cell_aligned_temp,&size_double);
extent = offsetof(Cell, velocity)+size_double;
/* Create new type with new extent */
MPI_Type_create_resized(mpi_cell_aligned_temp,0, extent,&mpi_cell_aligned_temp);