I'm trying to gather different struct into an pointer of struct which is inside a struct.
A container container a cartesian 2d, the cartesian2d contains a pointer of grid.
I tried to first gather with the type MPI_Byte, but the gather hanged indefinitely.
Now I created a data_type, but I receive a segfault on the process 0.
Here is the three structs involved and some relevant code, I won't post all my program since it's pretty long, but I know the create_grid function cause no problem:
typedef struct grid {
int *data;
int width;
int height;
int padding;
int pw;
int ph;
}
typedef struct cartesian {
grid_t **grids;
int width;
int height;
}
typedef struct container {
cart_t* cartesian;
grid_t* global_grid;
grid_t* curr_grid;
grid_t* next_grid;
int numprocs;
int rank;
MPI_Comm communication;
// Other irrelevant stuff
} container_t
// Inside the gather function
grid* local_grid = create_grid_withpadding(container->next_grid, 0);
MPI_Datatype struct_type;
MPI_Datatype final_type;
MPI_Aint lb, extent;
MPI_Datatype array_of_types [6] = { MPI_INT, MPI_INT,MPI_INT,MPI_INT,MPI_INT,MPI_INT};
int array_of_blocklengths[6] = { local_grid->height*local_grid->width, 1, 1, 1, 1, 1};
MPI_Aint array_of_displacements[6] = { offsetof( grid, data ), offsetof( grid, width), offsetof( grid, height),
offsetof( grid, padding), offsetof( grid, pw), offsetof( grid,ph) };
MPI_Type_create_struct( 6, array_of_blocklengths, array_of_displacements,
array_of_types, &struct_type );
MPI_Type_get_extent( struct_type, &lb, &extent );
MPI_Type_create_resized( struct_type, lb, extent, &final_type );
MPI_Type_commit( &final_type );
if (container->rank == 0) {
MPI_Gather(&local_grid[0], 1, final_type,
&container->cartesian->grids[0][0],1, final_type, 0,
container->communication);
}
What should I change in my code?