如何在MPICH中传递结构体类型?
我想通过MPI_Gather()和MPI_Bcast()进行通讯,传递的数据是类型为如下结构体的currentbest:
struct individual{
int chrom[LENGTH];
int realchrom[LENGTH];
double value;
};
struct individual currentbest;
请问如何定义数据类型MPI_Datatype?
问题点数:30、回复次数:1Top
1 楼lightnut()回复于 2006-05-01 03:05:18 得分 30
int blockLens[3] = {LENGTH, LENGTH, 1};
MPI_Datatype type[3] = {MPI_INT, MPI_INT, MPI_DOUBLE};
MPI_Aint disp[3];
MPI_Address( ¤tbest, &disp[0] );
MPI_Address( ¤tbest.realchrom[0], &disp[1] );
MPI_Address( ¤tbest.value, &disp[2]);
disp[2] = disp[2] - disp[0];
disp[1] = disp[1] - disp[0];
disp[0] = 0;
MPI_Datatype individualType;
MPI_Type_struct(1, blockLens, disp, type, &individualType);
MPI_Type_commit(&individualType);
.....//using the individualType
MPI_Type_free(&individualType);
Top




