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

Returned envelope pointer instead of copy

parent 28f0e5ae
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,6 @@
#define min(a, b) (((a) <= (b)) ? (a) : (b))
#define max(a, b) (((a) >= (b)) ? (a) : (b))
#define INDEX_2D_TO_1D(y, x, nb_columns) ((x) + (y) * (nb_columns))
#define INDEX_3D_TO_1D(y, x, z, nb_columns, nb_depths) ((x) + (nb_columns) * ((y) + (nb_depths) * (z)))
#define ROW_COMMUNICATOR 1
......@@ -65,10 +64,9 @@
#define BOTTOM_NORTH_WEST_TAG 30
#define BOTTOM_SURFACE_TAG 31
const int FUTHARK_CHUNKS_ORDER[NB_CHUNKS] = {INDEX_CHUNK_EAST, INDEX_CHUNK_NORTH, INDEX_CHUNK_NORTH_EAST,
INDEX_CHUNK_NORTH_WEST, INDEX_CHUNK_SOUTH, INDEX_CHUNK_SOUTH_EAST,
INDEX_CHUNK_SOUTH_WEST, INDEX_CHUNK_SURFACE, INDEX_CHUNK_WEST};
static const int FUTHARK_CHUNKS_ORDER[NB_CHUNKS] = {INDEX_CHUNK_EAST, INDEX_CHUNK_NORTH, INDEX_CHUNK_NORTH_EAST,
INDEX_CHUNK_NORTH_WEST, INDEX_CHUNK_SOUTH, INDEX_CHUNK_SOUTH_EAST,
INDEX_CHUNK_SOUTH_WEST, INDEX_CHUNK_SURFACE, INDEX_CHUNK_WEST};
/* Taken from Futhark generated code */
struct futhark_opaque_envelope_1d_t {
......@@ -158,10 +156,12 @@ struct dispatch_context {
chunk_info_t *chunk_info;
int type;
chunk_info_t *chunks_info;
chunk_info_t active_domain;
};
extern void envelope_init_accessors(envelope_t *envelope) {
static envelope_t *envelope_new() {
envelope_t *envelope = calloc(1, sizeof(envelope_t));
assert(envelope != NULL);
envelope->back = &envelope->sides[INDEX_SIDE_BACK];
envelope->bottom = &envelope->sides[INDEX_SIDE_BOTTOM];
envelope->front = &envelope->sides[INDEX_SIDE_FRONT];
......@@ -180,6 +180,7 @@ extern void envelope_init_accessors(envelope_t *envelope) {
envelope->sides[i].surface = &envelope->sides[i].chunks[INDEX_CHUNK_SURFACE];
envelope->sides[i].west = &envelope->sides[i].chunks[INDEX_CHUNK_WEST];
}
return envelope;
}
static void get_world_size(struct dispatch_context *dc) {
......@@ -274,10 +275,6 @@ static void divide_data(struct dispatch_context *dc) {
int nb_depths_per_process = dc->data_dimensions[2] / dc->network_dimensions[2];
int remaining_depths = dc->data_dimensions[2] % dc->network_dimensions[2];
printf("nb_rows = %d, rem = %d\n", nb_rows_per_process, remaining_rows);
printf("nb_cols = %d, rem = %d\n", nb_columns_per_process, remaining_columns);
printf("nb_depths = %d, rem = %d\n", nb_depths_per_process, remaining_depths);
for (int i = 0, y = 0, x = 0, z = 0; i < dc->world_size; ++i) {
int nb_rows = nb_rows_per_process;
if (remaining_rows > 0) {
......@@ -355,7 +352,6 @@ extern struct dispatch_context *dispatch_context_new(const int *dimensions, MPI_
create_network_communicators(dc);
get_my_rank(dc);
divide_data(dc);
dc->active_domain = *dc->chunk_info;
return dc;
}
......@@ -366,7 +362,7 @@ extern void dispatch_context_print(struct dispatch_context *dc) {
dc->coordinates[0], dc->coordinates[1], dc->coordinates[2]);
}
static envelope_t get_inner_envelope_1d(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
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] * dc->type);
int thickness_x = min(thickness, dc->chunk_info->dimensions[1]);
......@@ -377,21 +373,20 @@ static envelope_t get_inner_envelope_1d(struct dispatch_context *dc, struct futh
futhark_entry_get_envelope_1d(fc, &fut_inner_envelope, fut_chunk_data, dimensions[1] * dc->type);
futhark_context_sync(fc);
envelope_t inner_envelope = (envelope_t) {0};
envelope_init_accessors(&inner_envelope);
envelope_t *inner_envelope = envelope_new();
// East
{
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - dimensions[1];
chunk_info_init(inner_envelope.front->east, dc->type, dimensions, 0, start_x, 0, true);
futhark_values_i8_1d(fc, fut_inner_envelope->v0, inner_envelope.front->east->data);
chunk_info_init(inner_envelope->front->east, dc->type, dimensions, 0, start_x, 0, true);
futhark_values_i8_1d(fc, fut_inner_envelope->v0, inner_envelope->front->east->data);
}
// West
{
int start_x = dc->chunk_info->x;
chunk_info_init(inner_envelope.front->west, dc->type, dimensions, 0, start_x, 0, true);
futhark_values_i8_1d(fc, fut_inner_envelope->v1, inner_envelope.front->west->data);
chunk_info_init(inner_envelope->front->west, dc->type, dimensions, 0, start_x, 0, true);
futhark_values_i8_1d(fc, fut_inner_envelope->v1, inner_envelope->front->west->data);
}
futhark_context_sync(fc);
......@@ -400,7 +395,7 @@ static envelope_t get_inner_envelope_1d(struct dispatch_context *dc, struct futh
return inner_envelope;
}
static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
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] * dc->type);
......@@ -413,16 +408,15 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
futhark_entry_get_envelope_2d(fc, &fut_inner_envelope, fut_chunk_data, thickness_y, thickness_x * dc->type);
futhark_context_sync(fc);
envelope_t inner_envelope = (envelope_t) {0};
envelope_init_accessors(&inner_envelope);
envelope_t *inner_envelope = envelope_new();
// East
{
int dimensions[3] = {dc->chunk_info->dimensions[0], thickness_x, 1};
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - dimensions[1];
chunk_info_init(inner_envelope.front->east, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v0, inner_envelope.front->east->data);
chunk_info_init(inner_envelope->front->east, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v0, inner_envelope->front->east->data);
}
// North
......@@ -430,8 +424,8 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
int dimensions[3] = {thickness_y, dc->chunk_info->dimensions[1], 1};
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
chunk_info_init(inner_envelope.front->north, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v1, inner_envelope.front->north->data);
chunk_info_init(inner_envelope->front->north, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v1, inner_envelope->front->north->data);
}
// North-East
......@@ -439,8 +433,8 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
int dimensions[3] = {thickness_y, thickness_x, 1};
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - dimensions[1];
chunk_info_init(inner_envelope.front->north_east, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v2, inner_envelope.front->north_east->data);
chunk_info_init(inner_envelope->front->north_east, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v2, inner_envelope->front->north_east->data);
}
// North-West
......@@ -448,8 +442,8 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
int dimensions[3] = {thickness_y, thickness_x, 1};
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
chunk_info_init(inner_envelope.front->north_west, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v3, inner_envelope.front->north_west->data);
chunk_info_init(inner_envelope->front->north_west, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v3, inner_envelope->front->north_west->data);
}
// South
......@@ -457,8 +451,8 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
int dimensions[3] = {thickness_y, dc->chunk_info->dimensions[1], 1};
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - dimensions[0];
int start_x = dc->chunk_info->x;
chunk_info_init(inner_envelope.front->south, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v4, inner_envelope.front->south->data);
chunk_info_init(inner_envelope->front->south, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v4, inner_envelope->front->south->data);
}
// South-East
......@@ -466,8 +460,8 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
int dimensions[3] = {thickness_y, thickness_x, 1};
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - dimensions[0];
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - dimensions[1];
chunk_info_init(inner_envelope.front->south_east, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v5, inner_envelope.front->south_east->data);
chunk_info_init(inner_envelope->front->south_east, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v5, inner_envelope->front->south_east->data);
}
// South-West
......@@ -475,8 +469,8 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
int dimensions[3] = {thickness_y, thickness_x, 1};
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - dimensions[0];
int start_x = dc->chunk_info->x;
chunk_info_init(inner_envelope.front->south_west, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v6, inner_envelope.front->south_west->data);
chunk_info_init(inner_envelope->front->south_west, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v6, inner_envelope->front->south_west->data);
}
// West
......@@ -484,8 +478,8 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
int dimensions[3] = {dc->chunk_info->dimensions[0], thickness_x, 1};
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
chunk_info_init(inner_envelope.front->west, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v7, inner_envelope.front->west->data);
chunk_info_init(inner_envelope->front->west, dc->type, dimensions, start_y, start_x, 0, true);
futhark_values_i8_2d(fc, fut_inner_envelope->v7, inner_envelope->front->west->data);
}
futhark_context_sync(fc);
......@@ -494,7 +488,7 @@ static envelope_t get_inner_envelope_2d(struct dispatch_context *dc, struct futh
return inner_envelope;
}
static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
static envelope_t *get_inner_envelope_3d(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
struct futhark_u8_3d *fut_chunk_data = futhark_new_u8_3d(fc, dc->chunk_info->data,
dc->chunk_info->dimensions[0],
dc->chunk_info->dimensions[1],
......@@ -511,8 +505,7 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
thickness_z * dc->type);
futhark_context_sync(fc);
envelope_t inner_envelope = {0};
envelope_init_accessors(&inner_envelope);
envelope_t *inner_envelope = envelope_new();
// Back
{
......@@ -522,8 +515,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - dimensions[1];
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - dimensions[2];
chunk_info_init(inner_envelope.back->east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v0, inner_envelope.back->east->data);
chunk_info_init(inner_envelope->back->east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v0, inner_envelope->back->east->data);
}
// Surface
......@@ -532,10 +525,9 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - thickness_z;
chunk_info_init(inner_envelope.back->surface, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(inner_envelope->back->surface, dc->type, dimensions, start_y, start_x, start_z, true);
const int64_t *dims = futhark_shape_i8_3d(fc, fut_inner_envelope->v7);
// if(dc->my_rank == 0) printf("[%lld][%lld][%lld]\n", dims[0], dims[1], dims[2]);
futhark_values_i8_3d(fc, fut_inner_envelope->v7, inner_envelope.back->surface->data);
futhark_values_i8_3d(fc, fut_inner_envelope->v7, inner_envelope->back->surface->data);
}
// West
......@@ -544,8 +536,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - thickness_z;
chunk_info_init(inner_envelope.back->west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v8, inner_envelope.back->west->data);
chunk_info_init(inner_envelope->back->west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v8, inner_envelope->back->west->data);
}
}
......@@ -557,8 +549,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - thickness_x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.bottom->east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v9, inner_envelope.bottom->east->data);
chunk_info_init(inner_envelope->bottom->east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v9, inner_envelope->bottom->east->data);
}
// North
......@@ -567,8 +559,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - thickness_z;
chunk_info_init(inner_envelope.bottom->north, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v10, inner_envelope.bottom->north->data);
chunk_info_init(inner_envelope->bottom->north, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v10, inner_envelope->bottom->north->data);
}
// North-East
......@@ -577,8 +569,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - thickness_x;
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - thickness_z;
chunk_info_init(inner_envelope.bottom->north_east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v11, inner_envelope.bottom->north_east->data);
chunk_info_init(inner_envelope->bottom->north_east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v11, inner_envelope->bottom->north_east->data);
}
// North-West
......@@ -587,8 +579,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - thickness_z;
chunk_info_init(inner_envelope.bottom->north_west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v12, inner_envelope.bottom->north_west->data);
chunk_info_init(inner_envelope->bottom->north_west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v12, inner_envelope->bottom->north_west->data);
}
// South
......@@ -597,8 +589,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.bottom->south, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v13, inner_envelope.bottom->south->data);
chunk_info_init(inner_envelope->bottom->south, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v13, inner_envelope->bottom->south->data);
}
// South-East
......@@ -607,8 +599,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - thickness_x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.bottom->south_east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v14, inner_envelope.bottom->south_east->data);
chunk_info_init(inner_envelope->bottom->south_east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v14, inner_envelope->bottom->south_east->data);
}
// South-West
......@@ -617,8 +609,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.bottom->south_west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v15, inner_envelope.bottom->south_west->data);
chunk_info_init(inner_envelope->bottom->south_west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v15, inner_envelope->bottom->south_west->data);
}
// Surface
......@@ -627,8 +619,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.bottom->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v16, inner_envelope.bottom->surface->data);
chunk_info_init(inner_envelope->bottom->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v16, inner_envelope->bottom->surface->data);
}
// West
......@@ -637,8 +629,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y + dc->chunk_info->dimensions[0] - thickness_y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.bottom->west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v17, inner_envelope.bottom->west->data);
chunk_info_init(inner_envelope->bottom->west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v17, inner_envelope->bottom->west->data);
}
}
......@@ -650,8 +642,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - thickness_x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.front->east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v18, inner_envelope.front->east->data);
chunk_info_init(inner_envelope->front->east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v18, inner_envelope->front->east->data);
}
// Surface
......@@ -660,8 +652,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.front->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v25, inner_envelope.front->surface->data);
chunk_info_init(inner_envelope->front->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v25, inner_envelope->front->surface->data);
}
// West
......@@ -670,8 +662,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.front->west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v26, inner_envelope.front->west->data);
chunk_info_init(inner_envelope->front->west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v26, inner_envelope->front->west->data);
}
}
......@@ -684,8 +676,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.left->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v34, inner_envelope.left->surface->data);
chunk_info_init(inner_envelope->left->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v34, inner_envelope->left->surface->data);
}
}
......@@ -697,8 +689,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - thickness_x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.right->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v43, inner_envelope.right->surface->data);
chunk_info_init(inner_envelope->right->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v43, inner_envelope->right->surface->data);
}
}
......@@ -710,8 +702,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - thickness_x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.top->east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v45, inner_envelope.top->east->data);
chunk_info_init(inner_envelope->top->east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v45, inner_envelope->top->east->data);
}
// North
......@@ -720,8 +712,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - thickness_z;
chunk_info_init(inner_envelope.top->north, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v46, inner_envelope.top->north->data);
chunk_info_init(inner_envelope->top->north, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v46, inner_envelope->top->north->data);
}
// North-East
......@@ -730,8 +722,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - thickness_x;
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - thickness_z;
chunk_info_init(inner_envelope.top->north_east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v47, inner_envelope.top->north_east->data);
chunk_info_init(inner_envelope->top->north_east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v47, inner_envelope->top->north_east->data);
}
// North-West
......@@ -740,8 +732,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z + dc->chunk_info->dimensions[2] - thickness_z;
chunk_info_init(inner_envelope.top->north_west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v48, inner_envelope.top->north_west->data);
chunk_info_init(inner_envelope->top->north_west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v48, inner_envelope->top->north_west->data);
}
// South
......@@ -750,8 +742,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.top->south, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v49, inner_envelope.top->south->data);
chunk_info_init(inner_envelope->top->south, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v49, inner_envelope->top->south->data);
}
// South-East
......@@ -760,8 +752,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x + dc->chunk_info->dimensions[1] - thickness_x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.top->south_east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v50, inner_envelope.top->south_east->data);
chunk_info_init(inner_envelope->top->south_east, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v50, inner_envelope->top->south_east->data);
}
// South-West
......@@ -770,8 +762,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.top->south_west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v51, inner_envelope.top->south_west->data);
chunk_info_init(inner_envelope->top->south_west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v51, inner_envelope->top->south_west->data);
}
// Surface
......@@ -780,8 +772,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.top->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v52, inner_envelope.top->surface->data);
chunk_info_init(inner_envelope->top->surface, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v52, inner_envelope->top->surface->data);
}
// West
......@@ -790,8 +782,8 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
int start_y = dc->chunk_info->y;
int start_x = dc->chunk_info->x;
int start_z = dc->chunk_info->z;
chunk_info_init(inner_envelope.top->west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v53, inner_envelope.top->west->data);
chunk_info_init(inner_envelope->top->west, dc->type, dimensions, start_y, start_x, start_z, true);
futhark_values_i8_3d(fc, fut_inner_envelope->v53, inner_envelope->top->west->data);
}
}
......@@ -802,33 +794,28 @@ static envelope_t get_inner_envelope_3d(struct dispatch_context *dc, struct futh
return inner_envelope;
}
extern envelope_t get_inner_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
envelope_t inner_envelope = {0};
extern envelope_t *get_inner_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
switch (dc->n_dimensions) {
case 1:
inner_envelope = get_inner_envelope_1d(dc, fc, thickness);
break;
return get_inner_envelope_1d(dc, fc, thickness);
case 2:
inner_envelope = get_inner_envelope_2d(dc, fc, thickness);
break;
return get_inner_envelope_2d(dc, fc, thickness);
case 3:
inner_envelope = get_inner_envelope_3d(dc, fc, thickness);
break;
return get_inner_envelope_3d(dc, fc, thickness);
default:
fprintf(stderr, "Invalid dimensions size.");
MPI_Abort(MPI_COMM_WORLD, 1);
break;
}
return inner_envelope;
return NULL;
}
static envelope_t get_outer_envelope_1d(struct dispatch_context *dc, int thickness, envelope_t *inner_envelope) {
static envelope_t *get_outer_envelope_1d(struct dispatch_context *dc, int thickness, envelope_t *inner_envelope) {
int coordinate_x = dc->coordinates[1];
MPI_Request requests[4];
int i_request = 0;
envelope_t outer_envelope = (envelope_t) {0};
envelope_init_accessors(&outer_envelope);
envelope_t *outer_envelope = envelope_new();
// East-part
{
......@@ -841,10 +828,10 @@ static envelope_t get_outer_envelope_1d(struct dispatch_context *dc, int thickne
int dimensions[3] = {1, min(thickness, dc->chunks_info[dest_source].dimensions[1]), 1};
int start_x = dc->chunks_info[dest_source].x;
chunk_info_init(outer_envelope.front->east, dc->type, dimensions, 0, start_x, 0, true);
chunk_info_init(outer_envelope->front->east, dc->type, dimensions, 0, start_x, 0, true);
int recv_count = (int) outer_envelope.front->east->count;
MPI_Irecv(outer_envelope.front->east->data, recv_count, dc->datatype, dest_source_x, FRONT_WEST_TAG,
int recv_count = (int) outer_envelope->front->east->count;
MPI_Irecv(outer_envelope->front->east->data, recv_count, dc->datatype, dest_source_x, FRONT_WEST_TAG,
dc->communicators[ROW_COMMUNICATOR], &requests[i_request++]);
}
......@@ -859,10 +846,10 @@ static envelope_t get_outer_envelope_1d(struct dispatch_context *dc, int thickne
int dimensions[3] = {1, min(thickness, dc->chunks_info[dest_source].dimensions[1]), 1};
int start_x = dc->chunks_info[dest_source].x + dc->chunks_info[dest_source].dimensions[1] - dimensions[1];
chunk_info_init(outer_envelope.front->west, dc->type, dimensions, 0, start_x, 0, true);
chunk_info_init(outer_envelope->front->west, dc->type, dimensions, 0, start_x, 0, true);
int recv_count = (int) outer_envelope.front->west->count;
MPI_Irecv(outer_envelope.front->west->data, recv_count, dc->datatype, dest_source_x, FRONT_EAST_TAG,
int recv_count = (int) outer_envelope->front->west->count;
MPI_Irecv(outer_envelope->front->west->data, recv_count, dc->datatype, dest_source_x, FRONT_EAST_TAG,
dc->communicators[ROW_COMMUNICATOR], &requests[i_request++]);
}
......@@ -870,14 +857,13 @@ static envelope_t get_outer_envelope_1d(struct dispatch_context *dc, int thickne
return outer_envelope;
}
static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickness, envelope_t *inner_envelope) {
static envelope_t *get_outer_envelope_2d(struct dispatch_context *dc, int thickness, envelope_t *inner_envelope) {
int coordinate_y = dc->coordinates[0];
int coordinate_x = dc->coordinates[1];
MPI_Request requests[16] = {0};
int i_request = 0;
envelope_t outer_envelope = (envelope_t) {0};
envelope_init_accessors(&outer_envelope);
envelope_t *outer_envelope = envelope_new();
// North
{
......@@ -895,10 +881,10 @@ 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.front->north, dc->type, dimensions, start_y, start_x, 0, true);
chunk_info_init(outer_envelope->front->north, dc->type, dimensions, start_y, start_x, 0, true);
int recv_count = (int) outer_envelope.front->north->count;
MPI_Irecv(outer_envelope.front->north->data, recv_count, dc->datatype, dest_source_y, FRONT_SOUTH_TAG,
int recv_count = (int) outer_envelope->front->north->count;
MPI_Irecv(outer_envelope->front->north->data, recv_count, dc->datatype, dest_source_y, FRONT_SOUTH_TAG,
dc->communicators[COLUMN_COMMUNICATOR], &requests[i_request++]);
}
......@@ -918,10 +904,10 @@ 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.front->east, dc->type, dimensions, start_y, start_x, 0, true);
chunk_info_init(outer_envelope->front->east, dc->type, dimensions, start_y, start_x, 0, true);
int recv_count = (int) outer_envelope.front->east->count;
MPI_Irecv(outer_envelope.front->east->data, recv_count, dc->datatype, dest_source_x, FRONT_WEST_TAG,
int recv_count = (int) outer_envelope->front->east->count;
MPI_Irecv(outer_envelope->front->east->data, recv_count, dc->datatype, dest_source_x, FRONT_WEST_TAG,
dc->communicators[ROW_COMMUNICATOR], &requests[i_request++]);
}
......@@ -941,10 +927,10 @@ 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.front->south, dc->type, dimensions, start_y, start_x, 0, true);
chunk_info_init(outer_envelope->front->south, dc->type, dimensions, start_y, start_x, 0, true);
int recv_count = (int) outer_envelope.front->south->count;
MPI_Irecv(outer_envelope.front->south->data, recv_count, dc->datatype, dest_source_y, FRONT_NORTH_TAG,
int recv_count = (int) outer_envelope->front->south->count;
MPI_Irecv(outer_envelope->front->south->data, recv_count, dc->datatype, dest_source_y, FRONT_NORTH_TAG,
dc->communicators[COLUMN_COMMUNICATOR], &requests[i_request++]);
}
......@@ -964,10 +950,10 @@ 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.front->west, dc->type, dimensions, start_y, start_x, 0, true);
chunk_info_init(outer_envelope->front->west, dc->type, dimensions, start_y, start_x, 0, true);
int recv_count = (int) outer_envelope.front->west->count;
MPI_Irecv(outer_envelope.front->west->data, recv_count, dc->datatype, dest_source_x, FRONT_EAST_TAG,
int recv_count = (int) outer_envelope->front->west->count;
MPI_Irecv(outer_envelope->front->west->data, recv_count, dc->datatype, dest_source_x, FRONT_EAST_TAG,
dc->communicators[ROW_COMMUNICATOR], &requests[i_request++]);
}
......@@ -985,10 +971,10 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dimensions[3] = {thickness, thickness, 1};
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.front->north_east, dc->type, dimensions, start_y, start_x, 0, true);
chunk_info_init(outer_envelope->front->north_east, dc->type, dimensions, start_y, start_x, 0, true);
int recv_count = (int) outer_envelope.front->north_east->count;
MPI_Irecv(outer_envelope.front->north_east->data, recv_count, dc->datatype, dest_source, FRONT_SOUTH_WEST_TAG,
int recv_count = (int) outer_envelope->front->north_east->count;
MPI_Irecv(outer_envelope->front->north_east->data, recv_count, dc->datatype, dest_source, FRONT_SOUTH_WEST_TAG,
MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1006,10 +992,10 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dimensions[3] = {thickness, thickness, 1};
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
chunk_info_init(outer_envelope.front->south_east, dc->type, dimensions, start_y, start_x, 0, true);
chunk_info_init(outer_envelope->front->south_east, dc->type, dimensions, start_y, start_x, 0, true);
int recv_count = (int) outer_envelope.front->south_east->count;
MPI_Irecv(outer_envelope.front->south_east->data, recv_count, dc->datatype, dest_source, FRONT_NORTH_WEST_TAG,
int recv_count = (int) outer_envelope->front->south_east->count;
MPI_Irecv(outer_envelope->front->south_east->data, recv_count, dc->datatype, dest_source, FRONT_NORTH_WEST_TAG,
MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1027,10 +1013,10 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dimensions[3] = {thickness, thickness, 1};
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.front->south_west, dc->type, dimensions, start_y, start_x, 0, true);
chunk_info_init(outer_envelope->front->south_west, dc->type, dimensions, start_y, start_x, 0, true);
int recv_count = (int) outer_envelope.front->south_west->count;
MPI_Irecv(outer_envelope.front->south_west->data, recv_count, dc->datatype, dest_source, FRONT_NORTH_EAST_TAG,
int recv_count = (int) outer_envelope->front->south_west->count;
MPI_Irecv(outer_envelope->front->south_west->data, recv_count, dc->datatype, dest_source, FRONT_NORTH_EAST_TAG,
MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1048,10 +1034,10 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
int dimensions[3] = {thickness, thickness, 1};
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 + dc->chunks_info[dest_source].dimensions[1] - dimensions[1];
chunk_info_init(outer_envelope.front->north_west, dc->type, dimensions, start_y, start_x, 0, true);
chunk_info_init(outer_envelope->front->north_west, dc->type, dimensions, start_y, start_x, 0, true);
int recv_count = (int) outer_envelope.front->north_west->count;
MPI_Irecv(outer_envelope.front->north_west->data, recv_count, dc->datatype, dest_source, FRONT_SOUTH_EAST_TAG,
int recv_count = (int) outer_envelope->front->north_west->count;
MPI_Irecv(outer_envelope->front->north_west->data, recv_count, dc->datatype, dest_source, FRONT_SOUTH_EAST_TAG,
MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1059,15 +1045,14 @@ static envelope_t get_outer_envelope_2d(struct dispatch_context *dc, int thickne
return outer_envelope;
}
static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickness, envelope_t *inner_envelope) {
static envelope_t *get_outer_envelope_3d(struct dispatch_context *dc, int thickness, envelope_t *inner_envelope) {
int coordinate_y = dc->coordinates[0];
int coordinate_x = dc->coordinates[1];
int coordinate_z = dc->coordinates[2];
MPI_Request requests[52] = {0};
int i_request = 0;
envelope_t outer_envelope = (envelope_t) {0};
envelope_init_accessors(&outer_envelope);
envelope_t *outer_envelope = envelope_new();
// Back
{
......@@ -1089,9 +1074,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.back->surface, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->back->surface, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.back->surface->data, (int) outer_envelope.back->surface->count, dc->datatype,
MPI_Irecv(outer_envelope->back->surface->data, (int) outer_envelope->back->surface->count, dc->datatype,
dest_source_z, FRONT_SURFACE_TAG, dc->communicators[DEPTH_COMMUNICATOR], &requests[i_request++]);
}
......@@ -1115,9 +1100,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.back->east, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->back->east, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.back->east->data, (int) outer_envelope.back->east->count, dc->datatype,
MPI_Irecv(outer_envelope->back->east->data, (int) outer_envelope->back->east->count, dc->datatype,
dest_source, FRONT_WEST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1141,9 +1126,9 @@ static envelope_t get_outer_envelope_3d(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];
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.back->west, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->back->west, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.back->west->data, (int) outer_envelope.back->west->count, dc->datatype,
MPI_Irecv(outer_envelope->back->west->data, (int) outer_envelope->back->west->count, dc->datatype,
dest_source, FRONT_EAST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
}
......@@ -1169,9 +1154,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.bottom->surface, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->surface, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->surface->data, (int) outer_envelope.bottom->surface->count, dc->datatype,
MPI_Irecv(outer_envelope->bottom->surface->data, (int) outer_envelope->bottom->surface->count, dc->datatype,
dest_source_y, TOP_SURFACE_TAG, dc->communicators[COLUMN_COMMUNICATOR], &requests[i_request++]);
}
......@@ -1195,9 +1180,9 @@ static envelope_t get_outer_envelope_3d(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];
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.bottom->north_west, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->north_west, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->north_west->data, (int) outer_envelope.bottom->north_west->count,
MPI_Irecv(outer_envelope->bottom->north_west->data, (int) outer_envelope->bottom->north_west->count,
dc->datatype, dest_source, TOP_SOUTH_EAST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1222,9 +1207,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.bottom->north_east, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->north_east, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->north_east->data, (int) outer_envelope.bottom->north_east->count,
MPI_Irecv(outer_envelope->bottom->north_east->data, (int) outer_envelope->bottom->north_east->count,
dc->datatype, dest_source, TOP_SOUTH_WEST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1249,9 +1234,9 @@ static envelope_t get_outer_envelope_3d(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];
int start_z = dc->chunks_info[dest_source].z + dc->chunks_info[dest_source].dimensions[2] - dimensions[2];
chunk_info_init(outer_envelope.bottom->south_west, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->south_west, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->south_west->data, (int) outer_envelope.bottom->south_west->count,
MPI_Irecv(outer_envelope->bottom->south_west->data, (int) outer_envelope->bottom->south_west->count,
dc->datatype, dest_source, TOP_NORTH_EAST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1276,9 +1261,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z + dc->chunks_info[dest_source].dimensions[2] - dimensions[2];
chunk_info_init(outer_envelope.bottom->south_east, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->south_east, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->south_east->data, (int) outer_envelope.bottom->south_east->count,
MPI_Irecv(outer_envelope->bottom->south_east->data, (int) outer_envelope->bottom->south_east->count,
dc->datatype, dest_source, TOP_NORTH_WEST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1302,9 +1287,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.bottom->east, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->east, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->east->data, (int) outer_envelope.bottom->east->count, dc->datatype,
MPI_Irecv(outer_envelope->bottom->east->data, (int) outer_envelope->bottom->east->count, dc->datatype,
dest_source, TOP_WEST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1328,9 +1313,9 @@ static envelope_t get_outer_envelope_3d(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];
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.bottom->west, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->west, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->west->data, (int) outer_envelope.bottom->west->count, dc->datatype,
MPI_Irecv(outer_envelope->bottom->west->data, (int) outer_envelope->bottom->west->count, dc->datatype,
dest_source, TOP_EAST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1354,9 +1339,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.bottom->north, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->north, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->north->data, (int) outer_envelope.bottom->north->count, dc->datatype,
MPI_Irecv(outer_envelope->bottom->north->data, (int) outer_envelope->bottom->north->count, dc->datatype,
dest_source, TOP_SOUTH_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1380,9 +1365,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z + dc->chunks_info[dest_source].dimensions[2] - dimensions[2];
chunk_info_init(outer_envelope.bottom->south, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->bottom->south, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.bottom->south->data, (int) outer_envelope.bottom->south->count, dc->datatype,
MPI_Irecv(outer_envelope->bottom->south->data, (int) outer_envelope->bottom->south->count, dc->datatype,
dest_source, TOP_NORTH_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
}
......@@ -1408,9 +1393,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z + dc->chunks_info[dest_source].dimensions[2] - dimensions[2];
chunk_info_init(outer_envelope.front->surface, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->front->surface, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.front->surface->data, (int) outer_envelope.front->surface->count, dc->datatype,
MPI_Irecv(outer_envelope->front->surface->data, (int) outer_envelope->front->surface->count, dc->datatype,
dest_source_z, BACK_SURFACE_TAG, dc->communicators[DEPTH_COMMUNICATOR], &requests[i_request++]);
}
......@@ -1434,9 +1419,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z + dc->chunks_info[dest_source].dimensions[2] - dimensions[2];
chunk_info_init(outer_envelope.front->east, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->front->east, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.front->east->data, (int) outer_envelope.front->east->count, dc->datatype,
MPI_Irecv(outer_envelope->front->east->data, (int) outer_envelope->front->east->count, dc->datatype,
dest_source, BACK_WEST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1460,9 +1445,9 @@ static envelope_t get_outer_envelope_3d(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];
int start_z = dc->chunks_info[dest_source].z + dc->chunks_info[dest_source].dimensions[2] - dimensions[2];
chunk_info_init(outer_envelope.front->west, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->front->west, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.front->west->data, (int) outer_envelope.front->west->count, dc->datatype,
MPI_Irecv(outer_envelope->front->west->data, (int) outer_envelope->front->west->count, dc->datatype,
dest_source, BACK_EAST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
}
......@@ -1486,9 +1471,9 @@ static envelope_t get_outer_envelope_3d(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];
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.left->surface, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->left->surface, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.left->surface->data, (int) outer_envelope.left->surface->count, dc->datatype,
MPI_Irecv(outer_envelope->left->surface->data, (int) outer_envelope->left->surface->count, dc->datatype,
dest_source_x, RIGHT_SURFACE_TAG, dc->communicators[ROW_COMMUNICATOR], &requests[i_request++]);
}
......@@ -1511,9 +1496,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.right->surface, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->right->surface, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.right->surface->data, (int) outer_envelope.right->surface->count, dc->datatype,
MPI_Irecv(outer_envelope->right->surface->data, (int) outer_envelope->right->surface->count, dc->datatype,
dest_source_x, LEFT_SURFACE_TAG, dc->communicators[ROW_COMMUNICATOR], &requests[i_request++]);
}
......@@ -1538,9 +1523,9 @@ static envelope_t get_outer_envelope_3d(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;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.top->surface, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->surface, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->surface->data, (int) outer_envelope.top->surface->count, dc->datatype,
MPI_Irecv(outer_envelope->top->surface->data, (int) outer_envelope->top->surface->count, dc->datatype,
dest_source_y, BOTTOM_SURFACE_TAG, dc->communicators[COLUMN_COMMUNICATOR],
&requests[i_request++]);
}
......@@ -1566,9 +1551,9 @@ static envelope_t get_outer_envelope_3d(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 + dc->chunks_info[dest_source].dimensions[1] - dimensions[1];
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.top->north_west, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->north_west, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->north_west->data, (int) outer_envelope.top->north_west->count, dc->datatype,
MPI_Irecv(outer_envelope->top->north_west->data, (int) outer_envelope->top->north_west->count, dc->datatype,
dest_source, BOTTOM_SOUTH_EAST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1593,9 +1578,9 @@ static envelope_t get_outer_envelope_3d(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;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.top->north_east, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->north_east, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->north_east->data, (int) outer_envelope.top->north_east->count, dc->datatype,
MPI_Irecv(outer_envelope->top->north_east->data, (int) outer_envelope->top->north_east->count, dc->datatype,
dest_source, BOTTOM_SOUTH_WEST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1620,9 +1605,9 @@ static envelope_t get_outer_envelope_3d(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];
int start_z = dc->chunks_info[dest_source].z + dc->chunks_info[dest_source].dimensions[2] - dimensions[2];
chunk_info_init(outer_envelope.top->south_west, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->south_west, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->south_west->data, (int) outer_envelope.top->south_west->count, dc->datatype,
MPI_Irecv(outer_envelope->top->south_west->data, (int) outer_envelope->top->south_west->count, dc->datatype,
dest_source, BOTTOM_NORTH_EAST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1647,9 +1632,9 @@ static envelope_t get_outer_envelope_3d(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];
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.top->south_east, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->south_east, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->south_east->data, (int) outer_envelope.top->south_east->count, dc->datatype,
MPI_Irecv(outer_envelope->top->south_east->data, (int) outer_envelope->top->south_east->count, dc->datatype,
dest_source, BOTTOM_NORTH_WEST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1673,9 +1658,10 @@ static envelope_t get_outer_envelope_3d(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;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.top->east, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->east, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->east->data, (int) outer_envelope.top->east->count, dc->datatype, dest_source,
MPI_Irecv(outer_envelope->top->east->data, (int) outer_envelope->top->east->count, dc->datatype,
dest_source,
BOTTOM_WEST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1699,9 +1685,10 @@ static envelope_t get_outer_envelope_3d(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 + dc->chunks_info[dest_source].dimensions[1] - dimensions[1];
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.top->west, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->west, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->west->data, (int) outer_envelope.top->west->count, dc->datatype, dest_source,
MPI_Irecv(outer_envelope->top->west->data, (int) outer_envelope->top->west->count, dc->datatype,
dest_source,
BOTTOM_EAST_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1725,9 +1712,9 @@ static envelope_t get_outer_envelope_3d(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;
int start_z = dc->chunks_info[dest_source].z;
chunk_info_init(outer_envelope.top->north, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->north, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->north->data, (int) outer_envelope.top->north->count, dc->datatype,
MPI_Irecv(outer_envelope->top->north->data, (int) outer_envelope->top->north->count, dc->datatype,
dest_source, BOTTOM_SOUTH_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
......@@ -1751,9 +1738,9 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
int start_y = dc->chunks_info[dest_source].y;
int start_x = dc->chunks_info[dest_source].x;
int start_z = dc->chunks_info[dest_source].z + dc->chunks_info[dest_source].dimensions[2] - dimensions[2];
chunk_info_init(outer_envelope.top->south, dc->type, dimensions, start_y, start_x, start_z, true);
chunk_info_init(outer_envelope->top->south, dc->type, dimensions, start_y, start_x, start_z, true);
MPI_Irecv(outer_envelope.top->south->data, (int) outer_envelope.top->south->count, dc->datatype,
MPI_Irecv(outer_envelope->top->south->data, (int) outer_envelope->top->south->count, dc->datatype,
dest_source, BOTTOM_NORTH_TAG, MPI_COMM_WORLD, &requests[i_request++]);
}
}
......@@ -1762,26 +1749,25 @@ static envelope_t get_outer_envelope_3d(struct dispatch_context *dc, int thickne
return outer_envelope;
}
extern envelope_t get_outer_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
envelope_t inner_envelope = get_inner_envelope(dc, fc, thickness);
envelope_init_accessors(&inner_envelope);
envelope_t outer_envelope = {0};
extern envelope_t *get_outer_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness) {
envelope_t *inner_envelope = get_inner_envelope(dc, fc, thickness);
envelope_t *outer_envelope = NULL;
switch (dc->n_dimensions) {
case 1:
outer_envelope = get_outer_envelope_1d(dc, thickness, &inner_envelope);
outer_envelope = get_outer_envelope_1d(dc, thickness, inner_envelope);
break;
case 2:
outer_envelope = get_outer_envelope_2d(dc, thickness, &inner_envelope);
outer_envelope = get_outer_envelope_2d(dc, thickness, inner_envelope);
break;
case 3:
outer_envelope = get_outer_envelope_3d(dc, thickness, &inner_envelope);
outer_envelope = get_outer_envelope_3d(dc, thickness, inner_envelope);
break;
default:
fprintf(stderr, "Invalid dimensions size.");
MPI_Abort(MPI_COMM_WORLD, 1);
break;
}
envelope_free(&inner_envelope);
envelope_free(inner_envelope);
return outer_envelope;
}
......@@ -1913,14 +1899,21 @@ extern void *futhark_outer_envelope_new(struct dispatch_context *dc, struct futh
static void chunk_data_to_data(struct dispatch_context *dc, void *chunk_data, void *data, int rank) {
int y = dc->chunks_info[rank].y;
int x = dc->chunks_info[rank].x;
int z = dc->chunks_info[rank].z;
uint8_t *data8 = (uint8_t *) data;
uint8_t *chunk_data8 = (uint8_t *) chunk_data;
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]) * 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);
for (int k = 0; k < dc->chunks_info[rank].dimensions[2]; ++k) {
uint8_t *src = chunk_data8 + (INDEX_3D_TO_1D(i, j, k, dc->chunks_info[rank].dimensions[1],
dc->chunks_info[rank].dimensions[2]) * dc->type);
uint8_t *dst = data8
+ (INDEX_3D_TO_1D(y + i, x + j, z + k,
dc->data_dimensions[1], dc->data_dimensions[2])
* dc->type);
memcpy(dst, src, (size_t) dc->type);
}
}
}
}
......@@ -1959,101 +1952,6 @@ extern void dispatch_context_free(struct dispatch_context *dc) {
MPI_Comm_free(&dc->communicators[0]);
}
static void set_active_domain_1d(struct dispatch_context *dc, struct futhark_context *fc, int dimensions[1], int x) {
chunk_info_init(&dc->active_domain, dc->type, dimensions, 0, x, 0, true);
int64_t dimensions64[1];
dimensions64[0] = dimensions[0] * dc->type;
struct futhark_u8_1d *fut_chunk_data = futhark_new_u8_1d(fc, dc->chunk_info->data, dimensions64[0] * dc->type);
struct futhark_i64_1d *fut_dimension = futhark_new_i64_1d(fc, dimensions64, 1);
struct futhark_u8_1d *subdomain;
futhark_context_sync(fc);
futhark_entry_get_subdomain_1d(fc, &subdomain, fut_chunk_data, x * dc->type, fut_dimension);
futhark_context_sync(fc);
futhark_values_u8_1d(fc, subdomain, dc->active_domain.data);
futhark_context_sync(fc);
futhark_free_u8_1d(fc, fut_chunk_data);
futhark_free_i64_1d(fc, fut_dimension);
futhark_free_u8_1d(fc, subdomain);
}
static void
set_active_domain_2d(struct dispatch_context *dc, struct futhark_context *fc, int dimensions[2], int y, int x) {
chunk_info_init(&dc->active_domain, dc->type, dimensions, y, x, 0, true);
int64_t dimensions64[2];
dimensions64[0] = dimensions[0];
dimensions64[1] = dimensions[1] * dc->type;
struct futhark_u8_2d *fut_chunk_data = futhark_new_u8_2d(fc, dc->chunk_info->data, dimensions64[0],
dimensions64[1]);
struct futhark_i64_1d *fut_dimensions = futhark_new_i64_1d(fc, dimensions64, 2);
struct futhark_u8_2d *subdomain;
futhark_context_sync(fc);
futhark_entry_get_subdomain_2d(fc, &subdomain, fut_chunk_data, y, x * dc->type, fut_dimensions);
futhark_context_sync(fc);
futhark_values_u8_2d(fc, subdomain, dc->active_domain.data);
futhark_context_sync(fc);
futhark_free_u8_2d(fc, fut_chunk_data);
futhark_free_i64_1d(fc, fut_dimensions);
futhark_free_u8_2d(fc, subdomain);
}
static void
set_active_domain_3d(struct dispatch_context *dc, struct futhark_context *fc, int dimensions[3], int y, int x, int z) {
chunk_info_init(&dc->active_domain, dc->type, dimensions, y, x, z, true);
int64_t dimensions64[3];
dimensions64[0] = dimensions[0];
dimensions64[1] = dimensions[1] * dc->type;
dimensions64[2] = dimensions[2];
struct futhark_u8_3d *fut_chunk_data = futhark_new_u8_3d(fc, dc->chunk_info->data, dimensions64[0],
dimensions64[1], dimensions64[2]);
struct futhark_i64_1d *fut_dimensions = futhark_new_i64_1d(fc, dimensions64, 3);
struct futhark_u8_3d *subdomain;
futhark_context_sync(fc);
futhark_entry_get_subdomain_3d(fc, &subdomain, fut_chunk_data, y, x * dc->type, z, fut_dimensions);
futhark_context_sync(fc);
futhark_values_u8_3d(fc, subdomain, dc->active_domain.data);
futhark_context_sync(fc);
futhark_free_u8_3d(fc, fut_chunk_data);
futhark_free_i64_1d(fc, fut_dimensions);
futhark_free_u8_3d(fc, subdomain);
}
extern void
set_active_domain(struct dispatch_context *dc, struct futhark_context *fc, int *dimensions, int y, int x, int z) {
switch (dc->n_dimensions) {
case 1:
set_active_domain_1d(dc, fc, dimensions, x);
break;
case 2:
set_active_domain_2d(dc, fc, dimensions, y, x);
break;
case 3:
set_active_domain_3d(dc, fc, dimensions, y, x, z);
break;
default:
break;
}
}
extern void restore_active_domain(struct dispatch_context *dc) {
chunk_info_free(&dc->active_domain);
dc->active_domain = *dc->chunk_info;
}
static void side_envelope_free(side_envelope_t *side_envelope) {
for (int i = 0; i < NB_CHUNKS; ++i) {
chunk_info_free(&side_envelope->chunks[i]);
......@@ -2064,4 +1962,5 @@ extern void envelope_free(envelope_t *envelope) {
for (int i = 0; i < NB_SIDES; ++i) {
side_envelope_free(&envelope->sides[i]);
}
free(envelope);
}
......@@ -2,6 +2,7 @@
#define _DISPATCH_H_
#include "../lattice_boltzmann/lbm.h"
//#include "../game_of_life/gol.h"
#include "chunk_info.h"
//#include "envelope.h"
......@@ -61,15 +62,13 @@ typedef struct envelope {
side_envelope_t *top;
} envelope_t;
extern void envelope_init_accessors(envelope_t *envelope);
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);
extern envelope_t get_inner_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness);
extern envelope_t *get_inner_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness);
extern envelope_t get_outer_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness);
extern envelope_t *get_outer_envelope(struct dispatch_context *dc, struct futhark_context *fc, int thickness);
extern void *
futhark_outer_envelope_new(struct dispatch_context *dc, struct futhark_context *fc, envelope_t *outer_envelope,
......@@ -81,9 +80,6 @@ extern void *get_data(struct dispatch_context *dc);
extern void dispatch_context_free(struct dispatch_context *dc);
extern void
set_active_domain(struct dispatch_context *dc, struct futhark_context *fc, int *dimensions, int y, int x, int z);
extern void envelope_free(envelope_t *envelope);
#endif //_DISPATCH_H_
This diff is collapsed.
......@@ -29,9 +29,9 @@ void init_chunk_board(chunk_info_t *ci) {
}
void compute_next_chunk_board(struct dispatch_context *dc, struct futhark_context *fc, chunk_info_t *ci) {
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
envelope_t *outer_envelope = get_outer_envelope(dc, fc, 1);
struct futhark_opaque_envelope_2d_i8 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, &outer_envelope,
struct futhark_opaque_envelope_2d_i8 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, outer_envelope,
futhark_restore_opaque_envelope_2d_i8,
FUTHARK_I8);
......@@ -48,7 +48,7 @@ void compute_next_chunk_board(struct dispatch_context *dc, struct futhark_contex
futhark_free_i8_2d(fc, fut_next_chunk_board);
futhark_free_i8_2d(fc, fut_chunk_board);
futhark_free_opaque_envelope_2d_i8(fc, fut_outer_envelope);
envelope_free(&outer_envelope);
envelope_free(outer_envelope);
}
int main(int argc, char *argv[]) {
......
......@@ -29,9 +29,9 @@ void init_chunk_board(chunk_info_t *ci) {
}
void compute_next_chunk_board(struct dispatch_context *dc, struct futhark_context *fc, chunk_info_t *ci) {
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
envelope_t *outer_envelope = get_outer_envelope(dc, fc, 1);
struct futhark_opaque_envelope_2d_i8 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, &outer_envelope,
struct futhark_opaque_envelope_2d_i8 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, outer_envelope,
futhark_restore_opaque_envelope_2d_i8,
FUTHARK_I8);
......@@ -48,7 +48,7 @@ void compute_next_chunk_board(struct dispatch_context *dc, struct futhark_contex
futhark_free_i8_2d(fc, fut_next_chunk_board);
futhark_free_i8_2d(fc, fut_chunk_board);
futhark_free_opaque_envelope_2d_i8(fc, fut_outer_envelope);
envelope_free(&outer_envelope);
envelope_free(outer_envelope);
}
int main(int argc, char *argv[]) {
......
### C template
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
.idea
lbm.h
lbm.c
......@@ -28,9 +28,9 @@ void init_chunk_lbm(chunk_info_t *ci) {
}
void compute_next_lbm(struct dispatch_context *dc, struct futhark_context *fc, chunk_info_t *ci) {
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
envelope_t *outer_envelope = get_outer_envelope(dc, fc, 1);
struct futhark_opaque_envelope_3d_i32 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, &outer_envelope,
struct futhark_opaque_envelope_3d_i32 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, outer_envelope,
futhark_restore_opaque_envelope_3d_i32,
FUTHARK_I32);
......@@ -48,7 +48,7 @@ void compute_next_lbm(struct dispatch_context *dc, struct futhark_context *fc, c
futhark_free_i32_3d(fc, fut_next_chunk_lbm);
futhark_free_i32_3d(fc, fut_chunk_lbm);
futhark_free_opaque_envelope_3d_i32(fc, fut_outer_envelope);
envelope_free(&outer_envelope);
envelope_free(outer_envelope);
}
int main(int argc, char *argv[]) {
......
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