在MPI和C中,如何将结构信息的结构发送到从属进程并接收它们?

时间:2015-08-24 08:59:43

标签: c struct mpi

如代码所示,我在c中有两个结构。在一些输入读取和initialize_pop(parent_pop)之后,parent_pop包含4个个体生成。然后我必须将每个人发送到每个进程(4个进程)以评估并生成每个进程的新个体(完全仍然是4个人),然后接收这4个新人在掌握过程中组成了一个叫做child_pop的新人口。这是我的psudo程序。感谢任何帮助。提前谢谢。

typedef struct{
double *xreal;
int **gene;
double crowd_dist;
}
individual;

typedef struct
{
individual *ind;
}
population;



Here is the main program:
int main (int argc, char **argv)
{
population *parent_pop;
int i, my_id, num_procs;
MPI_Init(&argc, &argv);
// Find out process ID and process number //
MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
input_read();/*read input*/
initialize_pop (parent_pop);/*generate 4 individuals to form the parent_pop*/
MPI_Datatype MPI_individual;
int count = 3;
int blocklens[] = { 1, 1, 1 };
MPI_Aint disps[3];
MPI_Datatype old_types[] = { MPI_int, MPI_double, MPI_double };
disps[0] = offsetof(individual, *xreal);
disps[1] = offsetof(individual, **gene);
disps[2] = offsetof(individual, crowd_dist);
MPI_Type_struct(count, blocklens, disps, old_types, &MPI_individual);
MPI_Type_commit(&MPI_individual);

*********Part need help****************************
send each individual to each process;
*********Part need help****************************

evaluate(parent_pop);/*evaluate each individual in each process*/
genearte_new_pop(child_pop);/*generate 4 new individuals to form the child_pop*/

*********Part need help****************************
receive each individual information from the slave processes to get the child_pop in the master process
*********Part need help****************************

}

0 个答案:

没有答案