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

Changed type

parent 28d8c65b
No related branches found
No related tags found
No related merge requests found
......@@ -3,12 +3,12 @@
#include <assert.h>
#include "chunk_info.h"
extern void chunk_info_init(chunk_info_t *ci, size_t 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) {
ci->dimensions[0] = dimensions[0];
ci->dimensions[1] = dimensions[1];
ci->count = (size_t) ci->dimensions[0] * (size_t) ci->dimensions[1];
if (allocate_data) {
chunk_info_allocate_data(ci, type);
chunk_info_allocate_data(ci, (size_t)type);
}
ci->y = y;
ci->x = x;
......
......@@ -11,7 +11,7 @@ typedef struct chunk_info {
int x;
} chunk_info_t;
extern void chunk_info_init(chunk_info_t *ci, size_t 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);
......
......@@ -39,11 +39,12 @@ struct dispatch_context {
int my_cart_rank;
int coordinates[2];
MPI_Comm communicators[3]; /* cart_comm, row_comm, column_comm */
MPI_Datatype datatype;
int network_dimensions[2];
int data_dimensions[2];
int n_dimensions;
chunk_info_t *chunk_info;
size_t type;
int type;
chunk_info_t *chunks_info;
};
......@@ -138,13 +139,14 @@ static void divide_data(struct dispatch_context *dc) {
dc->chunk_info = &dc->chunks_info[dc->my_rank];
}
extern struct dispatch_context *dispatch_context_new(const int *dimensions, size_t type, 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));
assert(dispatch_context != NULL);
get_world_size(dispatch_context);
get_my_rank(dispatch_context);
dispatch_context->n_dimensions = n_dimensions;
dispatch_context->type = type;
dispatch_context->datatype = datatype;
MPI_Type_size(dispatch_context->datatype, &dispatch_context->type);
switch (n_dimensions) {
case 1:
......@@ -177,13 +179,13 @@ extern void dispatch_context_print(struct dispatch_context *dc) {
static envelope_t get_inner_envelope_1d(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
struct futhark_u8_1d *fut_chunk_data = futhark_new_u8_1d(fc, dc->chunk_info->data,
dc->chunk_info->dimensions[1] * (int64_t) dc->type);
dc->chunk_info->dimensions[1] * dc->type);
struct futhark_u8_1d *fut_west;
struct futhark_u8_1d *fut_east;
int thickness_x = min(thickness, dc->chunk_info->dimensions[1]);
int dimensions[2] = {1, thickness_x};
futhark_entry_get_envelope_1d(fc, &fut_west, &fut_east, fut_chunk_data, dimensions[1] * (int64_t) dc->type);
futhark_entry_get_envelope_1d(fc, &fut_west, &fut_east, fut_chunk_data, dimensions[1] * dc->type);
envelope_t inner_envelope = (envelope_t) {0};
// West
......@@ -208,7 +210,7 @@ static envelope_t get_inner_envelope_1d(struct dispatch_context *dc, struct futh
static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
struct futhark_u8_2d *fut_chunk_data = futhark_new_u8_2d(fc, dc->chunk_info->data,
dc->chunk_info->dimensions[0],
dc->chunk_info->dimensions[1] * (int64_t) dc->type);
dc->chunk_info->dimensions[1] * dc->type);
struct futhark_u8_2d *fut_north_west;
struct futhark_u8_2d *fut_north;
......@@ -224,7 +226,7 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
futhark_entry_get_envelope_2d(fc, &fut_north, &fut_north_east, &fut_east, &fut_south_east, &fut_south,
&fut_south_west, &fut_west, &fut_north_west, fut_chunk_data, thickness_y,
thickness_x * (int64_t) dc->type);
thickness_x * dc->type);
envelope_t inner_envelope = (envelope_t) {0};
......@@ -316,14 +318,14 @@ static envelope_t get_outer_envelope_1d(struct dispatch_context *dc, int thickne
int send_count = min(thickness, dc->chunk_info->dimensions[1]);
MPI_Isend(inner_envelope->west.data, send_count * (int) dc->type, MPI_UINT8_T, dest_source_x, WEST_COLUMN_TAG,
MPI_Isend(inner_envelope->west.data, send_count, dc->datatype, dest_source_x, WEST_COLUMN_TAG,
dc->communicators[1], &requests[i_request++]);
int dimensions[2] = {1, min(thickness, dc->chunks_info[dest_source].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.west, dc->type, dimensions, 0, start_x, true);
MPI_Irecv(outer_envelope.west.data, (int) outer_envelope.west.count * (int) dc->type, MPI_UINT8_T,
MPI_Irecv(outer_envelope.west.data, (int) outer_envelope.west.count, dc->datatype,
dest_source_x, EAST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]);
}
......@@ -335,16 +337,16 @@ static envelope_t get_outer_envelope_1d(struct dispatch_context *dc, int thickne
int send_count = min(thickness, dc->chunk_info->dimensions[1]);
void *inner_envelope_east = ((uint8_t *) inner_envelope->east.data)
+ (((size_t) (inner_envelope->east.dimensions[1] - send_count)) * dc->type);
+ ((inner_envelope->east.dimensions[1] - send_count) * dc->type);
MPI_Isend(inner_envelope_east, send_count * (int) dc->type, MPI_UINT8_T, dest_source_x, EAST_COLUMN_TAG,
MPI_Isend(inner_envelope_east, send_count, dc->datatype, dest_source_x, EAST_COLUMN_TAG,
dc->communicators[1], &requests[i_request++]);
int dimensions[2] = {1, min(thickness, dc->chunks_info[dest_source].dimensions[1])};
int start_x = dc->chunks_info[dest_source].x + dimensions[1];
chunk_info_init(&outer_envelope.east, dc->type, dimensions, 0, start_x, true);
MPI_Irecv(outer_envelope.east.data, (int) outer_envelope.east.count * (int) dc->type, MPI_UINT8_T,
MPI_Irecv(outer_envelope.east.data, (int) outer_envelope.east.count, dc->datatype,
dest_source_x,
WEST_COLUMN_TAG, dc->communicators[1], &requests[i_request]);
}
......@@ -368,7 +370,7 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int send_count = min(thickness, dc->chunk_info->dimensions[0]) * dc->chunk_info->dimensions[1];
MPI_Isend(inner_envelope->north.data, send_count * (int) dc->type, MPI_UINT8_T, dest_source_y, NORTH_ROW_TAG,
MPI_Isend(inner_envelope->north.data, send_count, dc->datatype, dest_source_y, NORTH_ROW_TAG,
dc->communicators[2], &requests[i_request++]);
/* Neighbour send south row, which correspond to north envelope */
......@@ -380,9 +382,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int start_x = dc->chunks_info[dest_source].x;
chunk_info_init(&outer_envelope.north, dc->type, dimensions, start_y, start_x, true);
MPI_Irecv(outer_envelope.north.data, (int) outer_envelope.north.count * (int) dc->type, MPI_UINT8_T,
dest_source_y,
SOUTH_ROW_TAG, dc->communicators[2], &requests[i_request++]);
MPI_Irecv(outer_envelope.north.data, (int) outer_envelope.north.count, dc->datatype,
dest_source_y, SOUTH_ROW_TAG, dc->communicators[2], &requests[i_request++]);
}
// East
......@@ -392,7 +393,7 @@ 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];
MPI_Isend(inner_envelope->east.data, (int) send_count * (int) dc->type, MPI_UINT8_T, dest_source_x,
MPI_Isend(inner_envelope->east.data, (int) send_count, dc->datatype, dest_source_x,
EAST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]);
/* Neighbour send west column, which correspond to east envelope */
......@@ -403,7 +404,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_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);
MPI_Irecv(outer_envelope.east.data, (int) outer_envelope.east.count * (int) dc->type, MPI_UINT8_T,
MPI_Irecv(outer_envelope.east.data, (int) outer_envelope.east.count, dc->datatype,
dest_source_x,
WEST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]);
}
......@@ -415,7 +416,7 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int send_count = min(thickness, dc->chunk_info->dimensions[0]) * dc->chunk_info->dimensions[1];
MPI_Isend(inner_envelope->south.data, send_count * (int) dc->type, MPI_UINT8_T, dest_source_y, SOUTH_ROW_TAG,
MPI_Isend(inner_envelope->south.data, send_count, dc->datatype, dest_source_y, SOUTH_ROW_TAG,
dc->communicators[2], &requests[i_request++]);
/* Neighbour send north row, which correspond to south envelope */
......@@ -426,9 +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_x = dc->chunks_info[dest_source].x;
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 * (int) dc->type, MPI_UINT8_T,
dest_source_y,
NORTH_ROW_TAG, dc->communicators[2], &requests[i_request++]);
MPI_Irecv(outer_envelope.south.data, (int) outer_envelope.south.count, dc->datatype,
dest_source_y, NORTH_ROW_TAG, dc->communicators[2], &requests[i_request++]);
}
// West
......@@ -437,7 +437,7 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dest_source = INDEX_2D_TO_1D(coordinate_y, dest_source_x, dc->network_dimensions[1]);
int send_count = min(thickness, dc->chunk_info->dimensions[1]) * dc->chunk_info->dimensions[0];
MPI_Isend(inner_envelope->west.data, send_count * (int) dc->type, MPI_UINT8_T, dest_source_x, WEST_COLUMN_TAG,
MPI_Isend(inner_envelope->west.data, send_count, dc->datatype, dest_source_x, WEST_COLUMN_TAG,
dc->communicators[1], &requests[i_request++]);
/* Neighbour send west column, which correspond to east envelope */
......@@ -448,9 +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_x = dc->chunks_info[dest_source].x;
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 * (int) dc->type, MPI_UINT8_T,
dest_source_x,
EAST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]);
MPI_Irecv(outer_envelope.west.data, (int) outer_envelope.west.count, dc->datatype,
dest_source_x, EAST_COLUMN_TAG, dc->communicators[1], &requests[i_request++]);
}
// North-East
......@@ -460,7 +459,7 @@ 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 send_count = thickness * thickness;
MPI_Isend(inner_envelope->north_east.data, send_count * (int) dc->type, MPI_UINT8_T, dest_source,
MPI_Isend(inner_envelope->north_east.data, send_count, dc->datatype, dest_source,
NORTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
/* Neighbour send south-west cell, which correspond to north-east cell */
......@@ -468,9 +467,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
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;
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 * (int) dc->type, MPI_UINT8_T,
dest_source,
SOUTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
MPI_Irecv(outer_envelope.north_east.data, (int) outer_envelope.north_east.count, dc->datatype,
dest_source, SOUTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
// South-East
......@@ -480,7 +478,7 @@ 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 send_count = thickness * thickness;
MPI_Isend(inner_envelope->south_east.data, send_count * (int) dc->type, MPI_UINT8_T, dest_source,
MPI_Isend(inner_envelope->south_east.data, send_count, dc->datatype, dest_source,
SOUTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
/* Neighbour send north-west cell, which correspond to south-east cell */
......@@ -488,9 +486,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_x = dc->chunks_info[dest_source].x;
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 * (int) dc->type, MPI_UINT8_T,
dest_source,
NORTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
MPI_Irecv(outer_envelope.south_east.data, (int) outer_envelope.south_east.count, dc->datatype,
dest_source, NORTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
// South-West
......@@ -500,7 +497,7 @@ 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 send_count = thickness * thickness;
MPI_Isend(inner_envelope->south_west.data, send_count * (int) dc->type, MPI_UINT8_T, dest_source,
MPI_Isend(inner_envelope->south_west.data, send_count, dc->datatype, dest_source,
SOUTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
/* Neighbour send north-east cell, which correspond to south-west cell */
......@@ -508,9 +505,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_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);
MPI_Irecv(outer_envelope.south_west.data, (int) outer_envelope.south_west.count * (int) dc->type, MPI_UINT8_T,
dest_source,
NORTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
MPI_Irecv(outer_envelope.south_west.data, (int) outer_envelope.south_west.count, dc->datatype,
dest_source, NORTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
// North-West
......@@ -520,7 +516,7 @@ 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 send_count = thickness * thickness;
MPI_Isend(inner_envelope->north_west.data, send_count * (int) dc->type, MPI_INT8_T, dest_source,
MPI_Isend(inner_envelope->north_west.data, send_count, dc->datatype, dest_source,
NORTH_WEST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
/* Neighbour send south-east cell, which correspond to north-west cell */
......@@ -528,9 +524,8 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
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;
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 * (int) dc->type, MPI_INT8_T,
dest_source,
SOUTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
MPI_Irecv(outer_envelope.north_west.data, (int) outer_envelope.north_west.count, dc->datatype,
dest_source, SOUTH_EAST_CELLS_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
MPI_Waitall(i_request, requests, MPI_STATUSES_IGNORE);
......@@ -586,8 +581,8 @@ static void chunk_data_to_data(struct dispatch_context *dc, void *chunk_data, vo
for (int i = 0; i < dc->chunks_info[rank].dimensions[0]; ++i) {
for (int j = 0; j < dc->chunks_info[rank].dimensions[1]; ++j) {
uint8_t *src = chunk_data8 + (INDEX_2D_TO_1D(i, j, dc->chunks_info[rank].dimensions[1]) * (int) dc->type);
uint8_t *dst = data8 + (INDEX_2D_TO_1D(y + i, x + j, dc->data_dimensions[1]) * (int) dc->type);
uint8_t *src = chunk_data8 + (INDEX_2D_TO_1D(i, j, dc->chunks_info[rank].dimensions[1]) * dc->type);
uint8_t *dst = data8 + (INDEX_2D_TO_1D(y + i, x + j, dc->data_dimensions[1]) * dc->type);
memcpy(dst, src, dc->type);
}
}
......@@ -600,17 +595,15 @@ extern void *get_data(struct dispatch_context *dc) {
chunk_data_to_data(dc, dc->chunk_info->data, data, dc->my_rank);
for (int i = 0; i < dc->world_size; ++i) {
if (i != dc->my_rank) {
chunk_info_allocate_data(&dc->chunks_info[i], dc->type);
MPI_Recv(dc->chunks_info[i].data, (int) dc->chunks_info[i].count * (int) dc->type, MPI_UINT8_T, i,
CHUNK_DATA_TAG,
chunk_info_allocate_data(&dc->chunks_info[i], (size_t) dc->type);
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);
chunk_data_to_data(dc, dc->chunks_info[i].data, data, i);
chunk_info_free(&dc->chunks_info[i]);
}
}
} else {
MPI_Send(dc->chunk_info->data, (int) dc->chunk_info->count * (int) dc->type, MPI_UINT8_T, ROOT_RANK,
CHUNK_DATA_TAG,
MPI_Send(dc->chunk_info->data, (int) dc->chunk_info->count, dc->datatype, ROOT_RANK, CHUNK_DATA_TAG,
MPI_COMM_WORLD);
}
return data;
......
......@@ -17,7 +17,7 @@ typedef struct envelope {
chunk_info_t south_west;
} envelope_t;
extern struct dispatch_context *dispatch_context_new(const int *dimensions, size_t type, int n_dimensions);
extern struct dispatch_context *dispatch_context_new(const int *dimensions, MPI_Datatype datatype, int n_dimensions);
extern void dispatch_context_print(struct dispatch_context *dc);
......
......@@ -101,7 +101,7 @@ int main(int argc, char *argv[]) {
int board_m = atoi(argv[3]);
int board_dimensions[2] = {board_n, board_m};
struct dispatch_context *disp_context = dispatch_context_new(board_dimensions, sizeof(int8_t), 2);
struct dispatch_context *disp_context = dispatch_context_new(board_dimensions, MPI_INT8_T, 2);
chunk_info_t ci = get_chunk_info(disp_context);
init_chunk_board(&ci);
......
......@@ -101,7 +101,7 @@ int main(int argc, char *argv[]) {
int board_m = atoi(argv[2]);
int board_dimensions[2] = {board_n, board_m};
struct dispatch_context *disp_context = dispatch_context_new(board_dimensions, sizeof(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);
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