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

Add `fmpi_partition_block_1d()` in `fmpi_domain` module

parent b1dbd3af
No related branches found
No related tags found
No related merge requests found
......@@ -29,9 +29,22 @@
// Internal
#include "fmpi_data.h"
#include "internal/fmpi_ctx.h"
#include "internal/fmpi_error.h"
#include "internal/fmpi_mpi.h"
/*==============================================================================
PUBLIC FUNCTION
PRIVATE FUNCTION DECLARATION
==============================================================================*/
/*------------------------------------------------------------------------------
fmpi_partition_block_1d()
------------------------------------------------------------------------------*/
/**
* TODO
*/
static struct fmpi_data * fmpi_partition_block_1d(
const struct fmpi_ctx * ctx, const struct fmpi_data * data
);
/*==============================================================================
PUBLIC FUNCTION DEFINITION
==============================================================================*/
//! @todo Handle creation of domain with data in 2D and 3D
/*------------------------------------------------------------------------------
......@@ -44,29 +57,49 @@ struct fmpi_domain fmpi_new_domain(
const size_t proc_cnt = (size_t)ctx->mpi->size;
struct fmpi_domain domain = {
.data = data,
.parts = NULL,
.part_cnt = proc_cnt
};
domain.parts = malloc(proc_cnt * sizeof(*domain.parts));
domain.parts = fmpi_partition_block_1d(ctx, &data);
if(domain.parts == NULL) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "malloc(domain.parts) failed!");
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_partition_block_1d() failed!");
}
return domain;
}
const size_t cnt_per_proc = data.cnt/proc_cnt;
size_t rem = data.cnt % proc_cnt;
/*==============================================================================
PRIVATE FUNCTION DEFINITION
==============================================================================*/
/*------------------------------------------------------------------------------
fmpi_partition_block_1d()
------------------------------------------------------------------------------*/
static struct fmpi_data * fmpi_partition_block_1d(
const struct fmpi_ctx * const ctx, const struct fmpi_data * const data
) {
assert(ctx != NULL);
assert(data != NULL);
const size_t proc_cnt = (size_t)ctx->mpi->size;
struct fmpi_data * parts = malloc(proc_cnt * sizeof(*parts));
if(parts == NULL) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "malloc(parts) failed!");
return NULL;
}
const size_t cnt_per_proc = data->cnt/proc_cnt;
size_t rem = data->cnt % proc_cnt;
size_t offset = 0;
for(size_t i = 0; i < proc_cnt; i++) {
const size_t cnt = rem != 0 ? cnt_per_proc + 1 : cnt_per_proc;
rem = rem != 0 ? rem - 1 : rem;
const size_t size = cnt * data.type_size;
domain.parts[i] = (struct fmpi_data){ \
.type = data.type,
.type_size = data.type_size,
const size_t size = cnt * data->type_size;
parts[i] = (struct fmpi_data){ \
.type = data->type,
.type_size = data->type_size,
.cnt = cnt,
.size = size,
.dim_len = {cnt, 1, 1},
.dim_cnt = 1,
.start = (char *)data.start + offset
.start = (char *)data->start + offset
};
offset += size;
}
return domain;
return parts;
}
......@@ -30,6 +30,7 @@
#include "fmpi_domain.h"
#include "fmpi_stencil.h"
#include "internal/fmpi_ctx.h"
#include "internal/fmpi_error.h"
#include "internal/fmpi_futhark.h"
#include "internal/fmpi_futhark_entry.h"
#include "internal/fmpi_mpi.h"
......@@ -55,6 +56,10 @@ struct fmpi_task fmpi_task_register(
const size_t rank = (size_t)ctx->mpi->rank;
for(size_t i = 0; i < task.args.cnt; i++) {
task.domains[i] = fmpi_new_domain(ctx, args->in[i]);
if(task.domains[i].parts == NULL) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_new_domain() failed!");
continue;
}
void * start = fmpi_futhark_new_data(
ctx->fut, task.domains[i].parts[rank].start, task.domains[i].data.type,
task.domains[i].data.dim_cnt,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment