Select Git revision
UserCreateResumeCommand.ts
Forked from
Dojo Project (HES-SO) / Projects / UI / DojoCLI
Source project has a limited visibility.
fmpi_core.c 5.46 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_core.h"
// C Standard Library
#include <assert.h>
#include <stdio.h> // fprintf()
#include <stdlib.h> // NULL, abort()
// Internal
#include "fmpi_task.h"
#include "internal/fmpi_ctx.h"
#include "internal/fmpi_error.h"
#include "internal/fmpi_futhark.h"
#include "internal/fmpi_mpi.h"
/*==============================================================================
PUBLIC FUNCTION DEFINITION
==============================================================================*/
/*------------------------------------------------------------------------------
fmpi_init()
------------------------------------------------------------------------------*/
struct fmpi_ctx * fmpi_init(int * const argc, char ** argv[])
{
struct fmpi_ctx * ctx = fmpi_ctx_create(argc, argv);
if(ctx == NULL) {
fprintf(stderr, "fmpi_ctx_create() failed!\n");
}
return ctx;
}
/*------------------------------------------------------------------------------
fmpi_exit()
------------------------------------------------------------------------------*/
int fmpi_exit(struct fmpi_ctx ** const ctx)
{
assert(ctx != NULL);
assert(*ctx != NULL);
const int err = fmpi_ctx_destroy(ctx);
if(err != FMPI_SUCCESS) {
fprintf(stderr, "fmpi_ctx_destroy() failed!\n");
}
return err;
}
/*------------------------------------------------------------------------------
fmpi_abort()
------------------------------------------------------------------------------*/
_Noreturn void fmpi_abort(const struct fmpi_ctx * const ctx)
{
assert(ctx != NULL);
fmpi_mpi_abort(ctx->mpi);
abort();
}
/*------------------------------------------------------------------------------
fmpi_is_root()
------------------------------------------------------------------------------*/
_Bool fmpi_is_root(const struct fmpi_ctx * const ctx)
{
assert(ctx != NULL);
return fmpi_mpi_is_root(ctx->mpi);
}
/*------------------------------------------------------------------------------
fmpi_world_rank()
------------------------------------------------------------------------------*/
int fmpi_world_rank(const struct fmpi_ctx * const ctx)
{
assert(ctx != NULL);
const int rank = fmpi_mpi_world_rank(ctx->mpi);
if(rank < FMPI_SUCCESS) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_mpi_world_rank() failed!");
}
return rank;
}
/*------------------------------------------------------------------------------
fmpi_world_barrier()
------------------------------------------------------------------------------*/
int fmpi_world_barrier(const struct fmpi_ctx * const ctx)
{
assert(ctx != NULL);
const int err = fmpi_mpi_world_barrier(ctx->mpi);
if(err != FMPI_SUCCESS) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_mpi_world_barrier() failed!");
}
return err;
}
/*------------------------------------------------------------------------------
fmpi_run_task()
------------------------------------------------------------------------------*/
int fmpi_run_task(
const struct fmpi_ctx * const ctx, struct fmpi_task * const task
){
assert(ctx != NULL);
assert(task != NULL);
if(task->type == FMPI_TASK_TYPE_SYNC) {
const int err = fmpi_task_run_sync(ctx, task);
if(err != FMPI_SUCCESS) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_task_run_sync() failed!");
}
return err;
}
if(task->type == FMPI_TASK_TYPE_ASYNC) {
const int err = fmpi_task_run_async(ctx, task);
if(err != FMPI_SUCCESS) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_task_run_async() failed!");
}
return err;
}
return FMPI_ERROR;
}
/*------------------------------------------------------------------------------
fmpi_sync()
------------------------------------------------------------------------------*/
int fmpi_sync(const struct fmpi_ctx * const ctx)
{
assert(ctx != NULL);
const int err = fmpi_futhark_sync(ctx->fut);
if(err != FMPI_SUCCESS) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_futhark_sync() failed!");
}
return err;
}
/*------------------------------------------------------------------------------
fmpi_world_size()
------------------------------------------------------------------------------*/
int fmpi_world_size(const struct fmpi_ctx * const ctx)
{
assert(ctx != NULL);
const int size = fmpi_mpi_world_size(ctx->mpi);
if(size < FMPI_SUCCESS) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_mpi_world_size() failed!");
}
return size;
}