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

Add `fmpi_domain` module

parent 43693443
Branches
No related tags found
No related merge requests found
// 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.
* }
*/
/*==============================================================================
GUARD
==============================================================================*/
#ifndef FMPI_DOMAIN_H_20220520194220
#define FMPI_DOMAIN_H_20220520194220
/*==============================================================================
INCLUDE
==============================================================================*/
// C Standard Library
#include <stddef.h> // size_t
// Internal
#include "fmpi_data.h"
/*==============================================================================
TYPE
==============================================================================*/
// Forward declaration from `fmpi_ctx.h`
struct fmpi_ctx;
/*------------------------------------------------------------------------------
fmpi_domain
------------------------------------------------------------------------------*/
/**
* TODO
*
* @example{
* TODO
* }
*/
typedef struct fmpi_domain {
struct fmpi_data data; //!< Data composing the domain.
struct fmpi_data * parts; //!< Partitions of the domain after decomposition.
size_t part_cnt; //!< Number of partitions.
} fmpi_domain;
/*==============================================================================
PUBLIC FUNCTION
==============================================================================*/
/*------------------------------------------------------------------------------
fmpi_new_domain
------------------------------------------------------------------------------*/
struct fmpi_domain fmpi_new_domain(const struct fmpi_ctx * ctx, struct fmpi_data data);
/*==============================================================================
GUARD
==============================================================================*/
#endif // FMPI_DOMAIN_H_20220520194220
// 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_domain.h"
// C Standard Library
#include <assert.h>
#include <stdlib.h>
// Internal
#include "fmpi_data.h"
#include "internal/fmpi_ctx.h"
#include "internal/fmpi_mpi.h"
/*==============================================================================
PUBLIC FUNCTION
==============================================================================*/
//! @todo Handle creation of domain with data in 2D and 3D
/*------------------------------------------------------------------------------
fmpi_new_domain()
------------------------------------------------------------------------------*/
struct fmpi_domain fmpi_new_domain(
const struct fmpi_ctx * const ctx, const struct fmpi_data data)
{
assert(ctx != NULL);
const size_t proc_cnt = (size_t)ctx->mpi->size;
struct fmpi_domain domain = {
.data = data,
.part_cnt = proc_cnt
};
domain.parts = malloc(proc_cnt * sizeof(*domain.parts));
if(domain.parts == NULL) {
FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "malloc(domain.parts) failed!");
}
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,
.cnt = cnt,
.size = size,
.dim_len = {cnt, 1, 1},
.dim_cnt = 1,
.start = (char *)data.start + offset
};
offset += size;
}
return domain;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment