Skip to content
Snippets Groups Projects
Verified Commit 6367ea49 authored by raphael.bach's avatar raphael.bach
Browse files

Add `fmpi_partition_block_2d()`

parent cec71102
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> // size_t, NULL, malloc(), free() #include <stdlib.h> // size_t, NULL, malloc(), free()
#include <string.h> // memcpy() #include <string.h> // memcpy()
#include <stdio.h>
// Internal // Internal
#include "fmpi_data.h" #include "fmpi_data.h"
#include "fmpi_stencil.h" #include "fmpi_stencil.h"
...@@ -46,6 +45,12 @@ ...@@ -46,6 +45,12 @@
static struct fmpi_data fmpi_partition_block_1d( static struct fmpi_data fmpi_partition_block_1d(
const struct fmpi_ctx * ctx, const struct fmpi_data * data const struct fmpi_ctx * ctx, const struct fmpi_data * data
); );
/*------------------------------------------------------------------------------
fmpi_partition_block_2d()
------------------------------------------------------------------------------*/
static struct fmpi_data fmpi_partition_block_2d(
const struct fmpi_ctx * ctx, const struct fmpi_data * data
);
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
fmpi_halo_1d() fmpi_halo_1d()
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
...@@ -152,7 +157,38 @@ static struct fmpi_data fmpi_partition_block_1d( ...@@ -152,7 +157,38 @@ static struct fmpi_data fmpi_partition_block_1d(
}; };
} }
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
fmpi_create_halo() fmpi_partition_block_2d()
------------------------------------------------------------------------------*/
static struct fmpi_data fmpi_partition_block_2d(
const struct fmpi_ctx * const ctx, const struct fmpi_data * const data
) {
assert(ctx != NULL);
assert(data != NULL);
size_t dim_len[1] = {0};
if(fmpi_mpi_dims_create(ctx->mpi, dim_len, 1) != FMPI_SUCCESS) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI",
"fmpi_mpi_dims_create() failed!"
);
}
const size_t rank = (size_t)ctx->mpi->rank;
const size_t cnt_per_proc = data->cnt/dim_len[0];
const size_t rem = data->cnt % dim_len[0];
const size_t cnt = (rank < rem) ? (cnt_per_proc + 1) : cnt_per_proc;
const size_t size = cnt * data->type.size;
const size_t offset = (rank * size) + (rank < rem ? 0 : (rem * data->type.size));
return (struct fmpi_data){
.type = data->type,
.cnt = cnt,
.size = size,
.dim_len = {data->dim_len[0], data->dim_len[1]/dim_len[0], 1},
.dim_cnt = 2,
.raw = (char *)data->raw + offset,
.gpu = NULL
};
}
/*------------------------------------------------------------------------------
fmpi_halo_1d()
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
static struct fmpi_data fmpi_halo_1d( static struct fmpi_data fmpi_halo_1d(
const struct fmpi_ctx * const ctx, const struct fmpi_data data, const struct fmpi_ctx * const ctx, const struct fmpi_data data,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment