Select Git revision
fmpi_mpi.c 12.49 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 "internal/fmpi_mpi.h"
// C Standard Library
#include <assert.h>
#include <limits.h> // INT_MAX
#include <stdbool.h>
#include <stdio.h> // printf()
#include <stdlib.h> // NULL, free(), malloc()
// External
#include <mpi.h>
// Internal
#include "internal/fmpi_common.h"
#include "internal/fmpi_error.h"
#include "internal/fmpi_type.h"
/*==============================================================================
DEFINE
==============================================================================*/
#define FMPI_MPI_ROOT 0
/*==============================================================================
MACRO
==============================================================================*/
#define FMPI_RAISE_MPI_ERROR(ctx, ...) \
do { \
if((ctx)->err_handler.func != NULL) { \
FMPI_RAISE_ERROR((ctx)->err_handler, "MPI", __VA_ARGS__); \
} \
} while(0)
/*==============================================================================
PUBLIC FUNCTION DEFINITION
==============================================================================*/
/*------------------------------------------------------------------------------
fmpi_mpi_init()
------------------------------------------------------------------------------*/
struct fmpi_mpi_ctx * fmpi_mpi_init(
int * const argc, char ** argv[],
const struct fmpi_error_handler err_handler
){
struct fmpi_mpi_ctx * ctx = malloc(sizeof(*ctx));
if(ctx == NULL) {
FMPI_RAISE_ERROR(err_handler, "FMPI", "malloc(fmpi_mpi_ctx) failed!");
return NULL;
}
ctx->err_handler = err_handler;
ctx->root = FMPI_MPI_ROOT;
int err = MPI_Init(argc, argv);
if(fmpi_mpi_check_error(ctx, err, "MPI_Init") != FMPI_SUCCESS) {