2015-10-13 41 views
2

我有我想填寫讀文件(並行,使用set_view等等)C結構的陣列添加填充到MPI結構

typedef struct 
{ 
    char type; 
    double value; 
    double velocity; 
} Cell; 

我的問題是,某些文件(TYPE1 )只會有typevalue(與案件速度成爲留給O,以及其他一些文件(2型)都在我typevaluevelocity

因此,在我的文件中讀取n塊時,我(讀取nx 9位(case1)或nx 17位((case2)我必須在良好的對抗中加入緩衝區。

我開始用mpi_cell_aligned

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_Type_contiguous我還內置了mpi_cell_packed類型與代表9/17連續比特(UI二進制文件格式)。

我的問題是寫入我的緩衝區,我試圖建立一個矢量類型,其中包含幾個mpi_cell_aligned。在情況2中,很容易,因爲每種類型都緊挨着另一種類型,但在情況1中,我必須考慮我的類型之間的填充,這與我們的1倍長度相對應。

不幸的是,MPI_Type_Vector的步幅必須以結構數量來衡量,而不是以字節爲單位。與此同時,我不能用MPI_BYTE來描述我的矢量,因爲我的單元格結構不完整(char和第一個double之間的對齊填充)。

如何構建相應的MPI數據類型,以便在case 1中正確表示Cell數組?

回答

3

您必須修改爲MPI類型的程度的情況下,1

一種類型的程度是用來知道在哪裏找到的SEND/RECV /寫以下元素的尺寸/讀取操作。

主要功能是MPI_Type_create_resized。在你的情況下,MPI類型的情況下,1程度必須是一樣的MPI類型的情況下的程度2.

所以你必須做這樣的事情:

/* 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); 
+0

我使用sizeof(細胞)作爲一個程度,我做了這份工作。謝謝 – Amxx