Select Git revision
fmpi_task.c
fmpi_task.c 2.80 KiB
// SPDX-License-Identifier: 0BSD
/*!
* @file
* @license{
* BSD Zero Clause License
*
* Copyright (c) 2022 by Raphael Bach
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
* }
*/
/*==============================================================================
INCLUDE
==============================================================================*/
// Own header
#include "fmpi_task.h"
// C Standard Library
#include <assert.h>
#include <stdint.h> // int64_t
// Internal
#include "fmpi_domain.h"
#include "fmpi_stencil.h"
#include "internal/fmpi_ctx.h"
#include "internal/fmpi_futhark.h"
#include "internal/fmpi_futhark_entry.h"
#include "internal/fmpi_mpi.h"
#include "internal/generic/fmpi_type.h"
/*==============================================================================
PUBLIC FUNCTION DEFINITION
==============================================================================*/
/*------------------------------------------------------------------------------
fmpi_task_run()
------------------------------------------------------------------------------*/
struct fmpi_task fmpi_task_register(
struct fmpi_ctx * ctx, const fmpi_task_func func,
const struct fmpi_stencil stencil, const struct fmpi_task_args * args
){
assert(ctx != NULL);
assert(ctx->task_cnt < FMPI_TASK_MAX);
assert(args != NULL);
struct fmpi_task task = {
.func = func,
.args = *args,
.stencil = stencil
};
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]);
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,
task.domains[i].parts[rank].dim_len[0],
task.domains[i].parts[rank].dim_len[1],
task.domains[i].parts[rank].dim_len[2]
);
task.args.in[i].start = start;
}
ctx->tasks[ctx->task_cnt++] = task;
futhark_context_sync(ctx->fut->ctx);
return task;
}
void fmpi_task_run(
const struct fmpi_ctx * const ctx, const struct fmpi_task * const task
){
assert(ctx != NULL);
assert(task != NULL);
task->func(ctx, &task->args);
}