Skip to content
Snippets Groups Projects
Verified Commit 207e89d3 authored by baptiste.coudray's avatar baptiste.coudray
Browse files

Fixed overflow

parent bf6fe4a1
No related branches found
No related tags found
No related merge requests found
...@@ -8,14 +8,14 @@ extern void chunk_info_init(chunk_info_t *ci, int type, const int dimensions[2], ...@@ -8,14 +8,14 @@ extern void chunk_info_init(chunk_info_t *ci, int type, const int dimensions[2],
ci->dimensions[1] = dimensions[1]; ci->dimensions[1] = dimensions[1];
ci->count = (size_t) ci->dimensions[0] * (size_t) ci->dimensions[1]; ci->count = (size_t) ci->dimensions[0] * (size_t) ci->dimensions[1];
if (allocate_data) { if (allocate_data) {
chunk_info_allocate_data(ci, (size_t)type); chunk_info_allocate_data(ci, type);
} }
ci->y = y; ci->y = y;
ci->x = x; ci->x = x;
} }
extern void chunk_info_allocate_data(chunk_info_t *ci, size_t type) { extern void chunk_info_allocate_data(chunk_info_t *ci, int type) {
ci->data = calloc(ci->count, type); ci->data = calloc(ci->count, (size_t) type);
assert(ci->data != NULL); assert(ci->data != NULL);
} }
......
...@@ -13,7 +13,7 @@ typedef struct chunk_info { ...@@ -13,7 +13,7 @@ typedef struct chunk_info {
extern void chunk_info_init(chunk_info_t *ci, int type, const int dimensions[2], int y, int x, bool allocate_data); extern void chunk_info_init(chunk_info_t *ci, int type, const int dimensions[2], int y, int x, bool allocate_data);
extern void chunk_info_allocate_data(chunk_info_t *ci, size_t type); extern void chunk_info_allocate_data(chunk_info_t *ci, int type);
extern void chunk_info_print(chunk_info_t *ci); extern void chunk_info_print(chunk_info_t *ci);
......
...@@ -42,6 +42,7 @@ struct dispatch_context { ...@@ -42,6 +42,7 @@ struct dispatch_context {
MPI_Datatype datatype; MPI_Datatype datatype;
int network_dimensions[2]; int network_dimensions[2];
int data_dimensions[2]; int data_dimensions[2];
size_t count;
int n_dimensions; int n_dimensions;
chunk_info_t *chunk_info; chunk_info_t *chunk_info;
int type; int type;
...@@ -140,22 +141,22 @@ static void divide_data(struct dispatch_context *dc) { ...@@ -140,22 +141,22 @@ static void divide_data(struct dispatch_context *dc) {
} }
extern struct dispatch_context *dispatch_context_new(const int *dimensions, MPI_Datatype datatype, int n_dimensions) { extern struct dispatch_context *dispatch_context_new(const int *dimensions, MPI_Datatype datatype, int n_dimensions) {
struct dispatch_context *dispatch_context = calloc(1, sizeof(struct dispatch_context)); struct dispatch_context *dc = calloc(1, sizeof(struct dispatch_context));
assert(dispatch_context != NULL); assert(dc != NULL);
get_world_size(dispatch_context); get_world_size(dc);
get_my_rank(dispatch_context); get_my_rank(dc);
dispatch_context->n_dimensions = n_dimensions; dc->n_dimensions = n_dimensions;
dispatch_context->datatype = datatype; dc->datatype = datatype;
MPI_Type_size(dispatch_context->datatype, &dispatch_context->type); MPI_Type_size(dc->datatype, &dc->type);
switch (n_dimensions) { switch (n_dimensions) {
case 1: case 1:
dispatch_context->data_dimensions[0] = 1; dc->data_dimensions[0] = 1;
dispatch_context->data_dimensions[1] = dimensions[0]; dc->data_dimensions[1] = dimensions[0];
break; break;
case 2: case 2:
dispatch_context->data_dimensions[0] = dimensions[0]; dc->data_dimensions[0] = dimensions[0];
dispatch_context->data_dimensions[1] = dimensions[1]; dc->data_dimensions[1] = dimensions[1];
break; break;
case 3: case 3:
return NULL; return NULL;
...@@ -165,10 +166,11 @@ extern struct dispatch_context *dispatch_context_new(const int *dimensions, MPI_ ...@@ -165,10 +166,11 @@ extern struct dispatch_context *dispatch_context_new(const int *dimensions, MPI_
break; break;
} }
find_network_dimensions(dispatch_context); find_network_dimensions(dc);
create_network_communicators(dispatch_context); create_network_communicators(dc);
divide_data(dispatch_context); divide_data(dc);
return dispatch_context; dc->count = (size_t) dc->data_dimensions[0] * (size_t) dc->data_dimensions[1];
return dc;
} }
extern void dispatch_context_print(struct dispatch_context *dc) { extern void dispatch_context_print(struct dispatch_context *dc) {
...@@ -347,8 +349,7 @@ static envelope_t get_outer_envelope_1d(struct dispatch_context *dc, int thickne ...@@ -347,8 +349,7 @@ static envelope_t get_outer_envelope_1d(struct dispatch_context *dc, int thickne
chunk_info_init(&outer_envelope.east, dc->type, dimensions, 0, start_x, true); chunk_info_init(&outer_envelope.east, dc->type, dimensions, 0, start_x, true);
MPI_Irecv(outer_envelope.east.data, (int) outer_envelope.east.count, dc->datatype, MPI_Irecv(outer_envelope.east.data, (int) outer_envelope.east.count, dc->datatype,
dest_source_x, dest_source_x, WEST_COLUMN_TAG, dc->communicators[1], &requests[i_request]);
WEST_COLUMN_TAG, dc->communicators[1], &requests[i_request]);
} }
MPI_Waitall(4, requests, MPI_STATUSES_IGNORE); MPI_Waitall(4, requests, MPI_STATUSES_IGNORE);
...@@ -393,8 +394,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne ...@@ -393,8 +394,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int send_count = min(thickness, dc->chunk_info->dimensions[1]) * dc->chunk_info->dimensions[0]; int send_count = min(thickness, dc->chunk_info->dimensions[1]) * dc->chunk_info->dimensions[0];
MPI_Isend(inner_envelope->east.data, (int) send_count, dc->datatype, dest_source_x, MPI_Isend(inner_envelope->east.data, (int) send_count, dc->datatype, dest_source_x, EAST_COLUMN_TAG,
EAST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]); dc->communicators[1], &requests[i_request++]);
/* Neighbour send west column, which correspond to east envelope */ /* Neighbour send west column, which correspond to east envelope */
int dimensions[2] = { int dimensions[2] = {
...@@ -404,8 +405,7 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne ...@@ -404,8 +405,7 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y; int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x + dc->chunks_info[dest_source].dimensions[1] - dimensions[1]; int start_x = dc->chunks_info[dest_source].x + dc->chunks_info[dest_source].dimensions[1] - dimensions[1];
chunk_info_init(&outer_envelope.east, dc->type, dimensions, start_y, start_x, true); chunk_info_init(&outer_envelope.east, dc->type, dimensions, start_y, start_x, true);
MPI_Irecv(outer_envelope.east.data, (int) outer_envelope.east.count, dc->datatype, MPI_Irecv(outer_envelope.east.data, (int) outer_envelope.east.count, dc->datatype, dest_source_x,
dest_source_x,
WEST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]); WEST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]);
} }
...@@ -427,8 +427,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne ...@@ -427,8 +427,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y; int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x; int start_x = dc->chunks_info[dest_source].x;
chunk_info_init(&outer_envelope.south, dc->type, dimensions, start_y, start_x, true); chunk_info_init(&outer_envelope.south, dc->type, dimensions, start_y, start_x, true);
MPI_Irecv(outer_envelope.south.data, (int) outer_envelope.south.count, dc->datatype, MPI_Irecv(outer_envelope.south.data, (int) outer_envelope.south.count, dc->datatype, dest_source_y,
dest_source_y, NORTH_ROW_TAG, dc->communicators[2], &requests[i_request++]); NORTH_ROW_TAG, dc->communicators[2], &requests[i_request++]);
} }
// West // West
...@@ -448,8 +448,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne ...@@ -448,8 +448,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y; int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x; int start_x = dc->chunks_info[dest_source].x;
chunk_info_init(&outer_envelope.west, dc->type, dimensions, start_y, start_x, true); chunk_info_init(&outer_envelope.west, dc->type, dimensions, start_y, start_x, true);
MPI_Irecv(outer_envelope.west.data, (int) outer_envelope.west.count, dc->datatype, MPI_Irecv(outer_envelope.west.data, (int) outer_envelope.west.count, dc->datatype, dest_source_x,
dest_source_x, EAST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]); EAST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]);
} }
// North-East // North-East
...@@ -459,16 +459,16 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne ...@@ -459,16 +459,16 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dest_source = INDEX_2D_TO_1D(dest_source_y, dest_source_x, dc->network_dimensions[1]); int dest_source = INDEX_2D_TO_1D(dest_source_y, dest_source_x, dc->network_dimensions[1]);
int send_count = thickness * thickness; int send_count = thickness * thickness;
MPI_Isend(inner_envelope->north_east.data, send_count, dc->datatype, dest_source, MPI_Isend(inner_envelope->north_east.data, send_count, dc->datatype, dest_source, NORTH_EAST_CELLS_TAG,
NORTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]); MPI_COMM_WORLD, &requests[i_request++]);
/* Neighbour send south-west cell, which correspond to north-east cell */ /* Neighbour send south-west cell, which correspond to north-east cell */
int dimensions[2] = {thickness, thickness}; int dimensions[2] = {thickness, thickness};
int start_y = dc->chunks_info[dest_source].y + dc->chunks_info[dest_source].dimensions[0] + dimensions[0]; int start_y = dc->chunks_info[dest_source].y + dc->chunks_info[dest_source].dimensions[0] + dimensions[0];
int start_x = dc->chunks_info[dest_source].x; int start_x = dc->chunks_info[dest_source].x;
chunk_info_init(&outer_envelope.north_east, dc->type, dimensions, start_y, start_x, true); chunk_info_init(&outer_envelope.north_east, dc->type, dimensions, start_y, start_x, true);
MPI_Irecv(outer_envelope.north_east.data, (int) outer_envelope.north_east.count, dc->datatype, MPI_Irecv(outer_envelope.north_east.data, (int) outer_envelope.north_east.count, dc->datatype, dest_source,
dest_source, SOUTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]); SOUTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
} }
// South-East // South-East
...@@ -478,16 +478,16 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne ...@@ -478,16 +478,16 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dest_source = INDEX_2D_TO_1D(dest_source_y, dest_source_x, dc->network_dimensions[1]); int dest_source = INDEX_2D_TO_1D(dest_source_y, dest_source_x, dc->network_dimensions[1]);
int send_count = thickness * thickness; int send_count = thickness * thickness;
MPI_Isend(inner_envelope->south_east.data, send_count, dc->datatype, dest_source, MPI_Isend(inner_envelope->south_east.data, send_count, dc->datatype, dest_source, SOUTH_EAST_CELLS_TAG,
SOUTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]); MPI_COMM_WORLD, &requests[i_request++]);
/* Neighbour send north-west cell, which correspond to south-east cell */ /* Neighbour send north-west cell, which correspond to south-east cell */
int dimensions[2] = {thickness, thickness}; int dimensions[2] = {thickness, thickness};
int start_y = dc->chunks_info[dest_source].y; int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x; int start_x = dc->chunks_info[dest_source].x;
chunk_info_init(&outer_envelope.south_east, dc->type, dimensions, start_y, start_x, true); chunk_info_init(&outer_envelope.south_east, dc->type, dimensions, start_y, start_x, true);
MPI_Irecv(outer_envelope.south_east.data, (int) outer_envelope.south_east.count, dc->datatype, MPI_Irecv(outer_envelope.south_east.data, (int) outer_envelope.south_east.count, dc->datatype, dest_source,
dest_source, NORTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]); NORTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
} }
// South-West // South-West
...@@ -497,16 +497,16 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne ...@@ -497,16 +497,16 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dest_source = INDEX_2D_TO_1D(dest_source_y, dest_source_x, dc->network_dimensions[1]); int dest_source = INDEX_2D_TO_1D(dest_source_y, dest_source_x, dc->network_dimensions[1]);
int send_count = thickness * thickness; int send_count = thickness * thickness;
MPI_Isend(inner_envelope->south_west.data, send_count, dc->datatype, dest_source, MPI_Isend(inner_envelope->south_west.data, send_count, dc->datatype, dest_source, SOUTH_WEST_CELLS_TAG,
SOUTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]); MPI_COMM_WORLD, &requests[i_request++]);
/* Neighbour send north-east cell, which correspond to south-west cell */ /* Neighbour send north-east cell, which correspond to south-west cell */
int dimensions[2] = {thickness, thickness}; int dimensions[2] = {thickness, thickness};
int start_y = dc->chunks_info[dest_source].y; int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x + dc->chunks_info[dest_source].dimensions[1] - thickness; int start_x = dc->chunks_info[dest_source].x + dc->chunks_info[dest_source].dimensions[1] - thickness;
chunk_info_init(&outer_envelope.south_west, dc->type, dimensions, start_y, start_x, true); chunk_info_init(&outer_envelope.south_west, dc->type, dimensions, start_y, start_x, true);
MPI_Irecv(outer_envelope.south_west.data, (int) outer_envelope.south_west.count, dc->datatype, MPI_Irecv(outer_envelope.south_west.data, (int) outer_envelope.south_west.count, dc->datatype, dest_source,
dest_source, NORTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]); NORTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
} }
// North-West // North-West
...@@ -516,16 +516,16 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne ...@@ -516,16 +516,16 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dest_source = INDEX_2D_TO_1D(dest_source_y, dest_source_x, dc->network_dimensions[1]); int dest_source = INDEX_2D_TO_1D(dest_source_y, dest_source_x, dc->network_dimensions[1]);
int send_count = thickness * thickness; int send_count = thickness * thickness;
MPI_Isend(inner_envelope->north_west.data, send_count, dc->datatype, dest_source, MPI_Isend(inner_envelope->north_west.data, send_count, dc->datatype, dest_source, NORTH_WEST_CELLS_TAG,
NORTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]); MPI_COMM_WORLD, &requests[i_request++]);
/* Neighbour send south-east cell, which correspond to north-west cell */ /* Neighbour send south-east cell, which correspond to north-west cell */
int dimensions[2] = {thickness, thickness}; int dimensions[2] = {thickness, thickness};
int start_y = dc->chunks_info[dest_source].y + dc->chunks_info[dest_source].dimensions[0] - thickness; int start_y = dc->chunks_info[dest_source].y + dc->chunks_info[dest_source].dimensions[0] - thickness;
int start_x = dc->chunks_info[dest_source].x + dc->chunks_info[dest_source].dimensions[1] - thickness; int start_x = dc->chunks_info[dest_source].x + dc->chunks_info[dest_source].dimensions[1] - thickness;
chunk_info_init(&outer_envelope.north_west, dc->type, dimensions, start_y, start_x, true); chunk_info_init(&outer_envelope.north_west, dc->type, dimensions, start_y, start_x, true);
MPI_Irecv(outer_envelope.north_west.data, (int) outer_envelope.north_west.count, dc->datatype, MPI_Irecv(outer_envelope.north_west.data, (int) outer_envelope.north_west.count, dc->datatype, dest_source,
dest_source, SOUTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]); SOUTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
} }
MPI_Waitall(i_request, requests, MPI_STATUSES_IGNORE); MPI_Waitall(i_request, requests, MPI_STATUSES_IGNORE);
...@@ -591,11 +591,11 @@ static void chunk_data_to_data(struct dispatch_context *dc, void *chunk_data, vo ...@@ -591,11 +591,11 @@ static void chunk_data_to_data(struct dispatch_context *dc, void *chunk_data, vo
extern void *get_data(struct dispatch_context *dc) { extern void *get_data(struct dispatch_context *dc) {
void *data = NULL; void *data = NULL;
if (dc->my_rank == ROOT_RANK) { if (dc->my_rank == ROOT_RANK) {
data = calloc((size_t) dc->data_dimensions[0] * (size_t) dc->data_dimensions[1], (size_t) dc->type); data = calloc(dc->count, (size_t) dc->type);
chunk_data_to_data(dc, dc->chunk_info->data, data, dc->my_rank); chunk_data_to_data(dc, dc->chunk_info->data, data, dc->my_rank);
for (int i = 0; i < dc->world_size; ++i) { for (int i = 0; i < dc->world_size; ++i) {
if (i != dc->my_rank) { if (i != dc->my_rank) {
chunk_info_allocate_data(&dc->chunks_info[i], (size_t) dc->type); chunk_info_allocate_data(&dc->chunks_info[i], dc->type);
MPI_Recv(dc->chunks_info[i].data, (int) dc->chunks_info[i].count, dc->datatype, i, CHUNK_DATA_TAG, MPI_Recv(dc->chunks_info[i].data, (int) dc->chunks_info[i].count, dc->datatype, i, CHUNK_DATA_TAG,
MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_COMM_WORLD, MPI_STATUS_IGNORE);
chunk_data_to_data(dc, dc->chunks_info[i].data, data, i); chunk_data_to_data(dc, dc->chunks_info[i].data, data, i);
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
void init_chunk_board(chunk_info_t *ci) { void init_chunk_board(chunk_info_t *ci) {
for (int i = 0; i < ci->dimensions[0]; ++i) { for (int i = 0; i < ci->dimensions[0]; ++i) {
for (int j = 0; j < ci->dimensions[1]; ++j) { for (int j = 0; j < ci->dimensions[1]; ++j) {
((int8_t *) ci->data)[INDEX_2D_TO_1D(i, j, ci->dimensions[1])] = rand() % 2; size_t k = INDEX_2D_TO_1D((size_t) i, (size_t) j, (size_t) ci->dimensions[1]);
((int8_t *) ci->data)[k] = rand() % 2;
} }
} }
} }
......
...@@ -102,7 +102,6 @@ int main(int argc, char *argv[]) { ...@@ -102,7 +102,6 @@ int main(int argc, char *argv[]) {
int board_dimensions[2] = {board_n, board_m}; int board_dimensions[2] = {board_n, board_m};
struct dispatch_context *disp_context = dispatch_context_new(board_dimensions, MPI_INT8_T, 2); struct dispatch_context *disp_context = dispatch_context_new(board_dimensions, MPI_INT8_T, 2);
dispatch_context_print(disp_context);
chunk_info_t ci = get_chunk_info(disp_context); chunk_info_t ci = get_chunk_info(disp_context);
init_chunk_board(&ci); init_chunk_board(&ci);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment