YAC 3.20.0
Yet Another Coupler
Loading...
Searching...
No Matches
interpolation_utils.h File Reference

Utility macros and functions for interpolation operators. This file contains utility macros for target field computation in interpolation operators, as well as internal functions for the direct interpolation operator. More...

#include <math.h>
#include <yaxt.h>
#include "utils_common.h"
#include "ppm/ppm_xfuncs.h"
#include "interpolation/interpolation_internal.h"
#include "interpolation/interp_grid_internal.h"
#include "instrument_internal.h"
Include dependency graph for interpolation_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  yac_interpolation_buffer
 

Macros

#define NO_SCALING(RESULT)   (RESULT)
 No scaling: $f(x) = x$.
 
#define MULT(RESULT)   ((RESULT) * scale_factor)
 Multiplicative scaling: $f(x) = a * x$.
 
#define ADD(RESULT)   ((RESULT) + scale_summand)
 Additive scaling: $f(x) = x + b$.
 
#define MULT_ADD(RESULT)   ((RESULT) * scale_factor + scale_summand)
 Combined multiplicative and additive scaling: $f(x) = a * x + b$.
 
#define FRAC_MASK_TOL   (1e-12)
 
#define COMPUTE_FIELD_STENCIL_FRAC_WGT(TGT_POS, WEIGHT, SCALE)
 
#define COMPUTE_FIELD_STENCIL_FRAC_NOWGT(TGT_POS, SCALE)
 
#define COMPUTE_FIELD_STENCIL_NOFRAC_(TGT_POS, WEIGHT, SCALE)
 
#define COMPUTE_FIELD_DIRECT_FRAC(SCALE)
 
#define COMPUTE_FIELD_DIRECT_NOFRAC(SCALE)
 
#define COMPUTE_FIELD_STENCIL_FRAC(SCALE)
 
#define COMPUTE_FIELD_STENCIL_NOFRAC(SCALE)
 
#define COMPUTE_FIELD(COMPUTE_FIELD_FRAC, COMPUTE_FIELD_NOFRAC)
 
#define CHECK_WITH_FRAC_MASK()
 Assert that a local with_frac_mask flag is consistent with the frac_mask_fallback_value that was passed to the constructor.
 
#define YAC_INTERP_GRID_ASSERT_F(INTERP_GRID, EXP, FMT, ...)
 
#define YAC_INTERP_GRID_ASSERT(INTERP_GRID, EXP, MSG)    YAC_INTERP_GRID_ASSERT_F(INTERP_GRID, EXP, MSG "%s", "")
 
#define YAC_INTERP_GRID_FIELD_ASSERT_F(INTERP_GRID, EXP, FMT, ...)
 
#define YAC_INTERP_GRID_FIELD_ASSERT(INTERP_GRID, EXP, MSG)    YAC_INTERP_GRID_FIELD_ASSERT_F(INTERP_GRID, EXP, MSG "%s", "")
 
#define CHECK_INTERP_GRID_HAS_SRC_FIELDS(INTERP_GRID)
 
#define CHECK_INTERP_GRID_SRC_FIELD_IDX_VALID(INTERP_GRID, SRC_FIELD_IDX)
 
#define CHECK_INTERP_GRID_SRC_FIELD_LOCATION_CORNER_CELL_EDGE(INTERP_GRID, LOCATION)
 
#define CHECK_INTERP_GRID_NUM_SRC_FIELDS_SINGLE(INTERP_GRID)
 
#define CHECK_INTERP_GRID_SRC_FIELD_IS_CELL(INTERP_GRID, SRC_FIELD_IDX)
 
#define CHECK_INTERP_GRID_TGT_FIELD_IS_CELL(INTERP_GRID)
 

Enumerations

enum  yac_interpolation_buffer_type { SEND_BUFFER , RECV_BUFFER }
 

Functions

static void compute_tgt_field_stencil (double const *restrict **src_fields, double const *restrict **src_frac_masks, double const *restrict *remote_src_fields, double const *restrict *remote_src_frac_masks, double *restrict *tgt_field, size_t const *restrict tgt_pos, size_t tgt_count, size_t const *restrict prefix_num_src_per_tgt, double const *restrict weights, size_t const *restrict src_field_idx, size_t const *restrict src_idx, size_t num_src_fields, size_t collection_size, double frac_mask_fallback_value, double scale_factor, double scale_summand)
 Compute target field values using stencil-based summation of source data (sparse-matrix-vector multiply), optionally applying fractional masking and scaling.
 
static void compute_tgt_field_direct (double const *restrict **src_fields, double const *restrict **src_frac_masks, double *restrict *tgt_field, size_t *restrict tgt_buffer_sizes, size_t num_src_fields, size_t collection_size, double frac_mask_fallback_value, double scale_factor, double scale_summand)
 Copy source field values to target buffers, optionally applying fractional masking and scaling.
 
struct yac_interpolation_buffer yac_interpolation_buffer_init (Xt_redist *redists, size_t num_fields, size_t collection_size, enum yac_interpolation_buffer_type type)
 
struct yac_interpolation_buffer yac_interpolation_buffer_init_2 (Xt_redist *redists, size_t *min_buffer_sizes, size_t num_fields, size_t collection_size, enum yac_interpolation_buffer_type type)
 
struct yac_interpolation_buffer yac_interpolation_buffer_copy (struct yac_interpolation_buffer buffer, size_t num_fields, size_t collection_size)
 
void yac_interpolation_buffer_free (struct yac_interpolation_buffer *buffer)
 

Detailed Description

Utility macros and functions for interpolation operators. This file contains utility macros for target field computation in interpolation operators, as well as internal functions for the direct interpolation operator.

See also
Target field computation macros

Definition in file interpolation_utils.h.

Macro Definition Documentation

◆ CHECK_INTERP_GRID_HAS_SRC_FIELDS

#define CHECK_INTERP_GRID_HAS_SRC_FIELDS ( INTERP_GRID)
Value:
INTERP_GRID, yac_interp_grid_get_num_src_fields(INTERP_GRID) != 0, \
"Number of source fields is 0.")
size_t yac_interp_grid_get_num_src_fields(struct yac_interp_grid *interp_grid)
#define YAC_INTERP_GRID_ASSERT(INTERP_GRID, EXP, MSG)

Definition at line 741 of file interpolation_utils.h.

◆ CHECK_INTERP_GRID_NUM_SRC_FIELDS_SINGLE

#define CHECK_INTERP_GRID_NUM_SRC_FIELDS_SINGLE ( INTERP_GRID)
Value:
YAC_INTERP_GRID_FIELD_ASSERT_F( \
INTERP_GRID, \
"Invalid number of source fields. Got %zu, expected 1.", \
#define CHECK_INTERP_GRID_HAS_SRC_FIELDS(INTERP_GRID)

Definition at line 762 of file interpolation_utils.h.

◆ CHECK_INTERP_GRID_SRC_FIELD_IDX_VALID

#define CHECK_INTERP_GRID_SRC_FIELD_IDX_VALID ( INTERP_GRID,
SRC_FIELD_IDX )
Value:
YAC_INTERP_GRID_ASSERT_F( \
INTERP_GRID, (SRC_FIELD_IDX) < yac_interp_grid_get_num_src_fields(INTERP_GRID), \
"invalid src_field_idx. Got %zu, expected < %zu", \
(size_t)(SRC_FIELD_IDX), yac_interp_grid_get_num_src_fields(INTERP_GRID))

Definition at line 746 of file interpolation_utils.h.

◆ CHECK_INTERP_GRID_SRC_FIELD_IS_CELL

#define CHECK_INTERP_GRID_SRC_FIELD_IS_CELL ( INTERP_GRID,
SRC_FIELD_IDX )
Value:
CHECK_INTERP_GRID_SRC_FIELD_IDX_VALID(INTERP_GRID, SRC_FIELD_IDX) \
YAC_INTERP_GRID_FIELD_ASSERT( \
INTERP_GRID, \
yac_interp_grid_get_src_field_location(INTERP_GRID, SRC_FIELD_IDX) == YAC_LOC_CELL, \
"Expected source fields defined as CELL")
enum yac_location yac_interp_grid_get_src_field_location(struct yac_interp_grid *interp_grid, size_t src_field_idx)
#define CHECK_INTERP_GRID_SRC_FIELD_IDX_VALID(INTERP_GRID, SRC_FIELD_IDX)
@ YAC_LOC_CELL
Definition location.h:14

Definition at line 770 of file interpolation_utils.h.

◆ CHECK_INTERP_GRID_SRC_FIELD_LOCATION_CORNER_CELL_EDGE

#define CHECK_INTERP_GRID_SRC_FIELD_LOCATION_CORNER_CELL_EDGE ( INTERP_GRID,
LOCATION )
Value:
YAC_INTERP_GRID_FIELD_ASSERT( \
INTERP_GRID, \
((LOCATION) == YAC_LOC_CORNER) || \
((LOCATION) == YAC_LOC_CELL) || \
((LOCATION) == YAC_LOC_EDGE), \
"Expected source fields defined as CORNER, CELL, or EDGE")
@ YAC_LOC_CORNER
Definition location.h:15
@ YAC_LOC_EDGE
Definition location.h:16

Definition at line 753 of file interpolation_utils.h.

◆ CHECK_INTERP_GRID_TGT_FIELD_IS_CELL

#define CHECK_INTERP_GRID_TGT_FIELD_IS_CELL ( INTERP_GRID)
Value:
INTERP_GRID, \
"Expected target fields defined as CELL")
enum yac_location yac_interp_grid_get_tgt_field_location(struct yac_interp_grid *interp_grid)
#define YAC_INTERP_GRID_FIELD_ASSERT(INTERP_GRID, EXP, MSG)

Definition at line 777 of file interpolation_utils.h.

◆ CHECK_WITH_FRAC_MASK

#define CHECK_WITH_FRAC_MASK ( )
Value:
with_frac_mask == \
YAC_FRAC_MASK_VALUE_IS_VALID(frac_mask_fallback_value), \
"with_frac_mask does not match value provided to constructor\n" \
"(frac_mask_fallback_value = %lf with_frac_mask = %d " \
"with_frac_mask(constructor) %d)", frac_mask_fallback_value, \
frac_mask_fallback_value != YAC_FRAC_MASK_NO_VALUE, with_frac_mask)
double const YAC_FRAC_MASK_NO_VALUE
#define YAC_FRAC_MASK_VALUE_IS_VALID(value)
Test whether a fractional mask value is valid.
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:39

Assert that a local with_frac_mask flag is consistent with the frac_mask_fallback_value that was passed to the constructor.

This macro is intended to be placed at the top of execute callbacks that carry a pre-checked with_frac_mask member. It guards against cases where a different fallback value is supplied at execution time than was used when the operator was constructed.

Definition at line 699 of file interpolation_utils.h.

◆ YAC_INTERP_GRID_ASSERT

#define YAC_INTERP_GRID_ASSERT ( INTERP_GRID,
EXP,
MSG )    YAC_INTERP_GRID_ASSERT_F(INTERP_GRID, EXP, MSG "%s", "")

Definition at line 719 of file interpolation_utils.h.

◆ YAC_INTERP_GRID_ASSERT_F

#define YAC_INTERP_GRID_ASSERT_F ( INTERP_GRID,
EXP,
FMT,
... )
Value:
(EXP), FMT "(source grid: %s; target grid: %s)", \
__VA_ARGS__, \
char const * yac_interp_grid_get_src_grid_name(struct yac_interp_grid *interp_grid)
Definition interp_grid.c:77
char const * yac_interp_grid_get_tgt_grid_name(struct yac_interp_grid *interp_grid)
Definition interp_grid.c:82

Definition at line 712 of file interpolation_utils.h.

◆ YAC_INTERP_GRID_FIELD_ASSERT

#define YAC_INTERP_GRID_FIELD_ASSERT ( INTERP_GRID,
EXP,
MSG )    YAC_INTERP_GRID_FIELD_ASSERT_F(INTERP_GRID, EXP, MSG "%s", "")

Definition at line 733 of file interpolation_utils.h.

◆ YAC_INTERP_GRID_FIELD_ASSERT_F

#define YAC_INTERP_GRID_FIELD_ASSERT_F ( INTERP_GRID,
EXP,
FMT,
... )
Value:
(EXP), FMT \
"(source grid: %s; source field location: %s; " \
"target grid: %s; target field location: %s)", \
__VA_ARGS__, \
char const * yac_loc2str(enum yac_location location)
Definition location.c:33

Definition at line 722 of file interpolation_utils.h.

Enumeration Type Documentation

◆ yac_interpolation_buffer_type

Enumerator
SEND_BUFFER 
RECV_BUFFER 

Definition at line 787 of file interpolation_utils.h.

Function Documentation

◆ compute_tgt_field_direct()

static void compute_tgt_field_direct ( double const *restrict ** src_fields,
double const *restrict ** src_frac_masks,
double *restrict * tgt_field,
size_t *restrict tgt_buffer_sizes,
size_t num_src_fields,
size_t collection_size,
double frac_mask_fallback_value,
double scale_factor,
double scale_summand )
inlinestatic

Copy source field values to target buffers, optionally applying fractional masking and scaling.

This is the direct (1-to-1, no stencil) variant of compute_tgt_field_stencil. It is used for interpolation operators that perform a point-to-point copy (e.g. direct and raw-exchange operators). This routine will copy the source field values into a buffer whose contents will then be directly copied to the target field buffers, without any further processing on the target side. In case scaling and/or fractional masking is requested, the source field values will be pre-processed before being copied to the send buffer.

Parameters
[in]src_fieldsLocal source field data.
dimensions: [collection_size][num_src_fields][points].
When fractional masking is enabled, each value must already be pre-multiplied by the corresponding fractional mask value (i.e. Fs_i * f_i, not Fs_i).
[in]src_frac_masksLocal source fractional mask.
(same structure as src_fields; values are expected to be in the range of [0.0;1.0]; ignored when frac_mask_fallback_value is YAC_FRAC_MASK_NO_VALUE).
[out]tgt_fieldOutput buffers. dimensions: [collection_size * num_src_fields][points].
[in]tgt_buffer_sizesByte size of each target field buffer (length = num_src_fields).
[in]num_src_fieldsNumber of source fields.
[in]collection_sizeNumber of field collections.
[in]frac_mask_fallback_valueFallback value, which is applied to a target point if the sum of associated fractional mask values is below FRAC_MASK_TOL, i.e. effectively zero.
Pass YAC_FRAC_MASK_NO_VALUE to disable fractional masking.
[in]scale_factorMultiplicative scaling factor.
Not applied, if the frac_mask_fallback_value is assigned to a target.
[in]scale_summandAdditive scaling summand.
Not applied, if the frac_mask_fallback_value is assigned to a target.

Definition at line 657 of file interpolation_utils.h.

Here is the caller graph for this function:

◆ compute_tgt_field_stencil()

static void compute_tgt_field_stencil ( double const *restrict ** src_fields,
double const *restrict ** src_frac_masks,
double const *restrict * remote_src_fields,
double const *restrict * remote_src_frac_masks,
double *restrict * tgt_field,
size_t const *restrict tgt_pos,
size_t tgt_count,
size_t const *restrict prefix_num_src_per_tgt,
double const *restrict weights,
size_t const *restrict src_field_idx,
size_t const *restrict src_idx,
size_t num_src_fields,
size_t collection_size,
double frac_mask_fallback_value,
double scale_factor,
double scale_summand )
inlinestatic

Compute target field values using stencil-based summation of source data (sparse-matrix-vector multiply), optionally applying fractional masking and scaling.

This routine accumulates contributions from multiple source points per target point using a prefix-sum encoded stencil.

If no weights are provided, all source contributions are weighted equally (unweighted sum).

This routine can also optionally apply fractional masking and scaling.

The user has to provide the locally available source field. All source field data required from other processes has to be gathered by the user beforehand and provided in the dedicated buffers.

Parameters
[in]src_fieldsLocal source field data.
dimensions: [collection_size][num_src_fields][local_points].
When fractional masking is enabled, each value must already be pre-multiplied by the corresponding fractional mask value (i.e. Fs_i * f_i, not Fs_i).
[in]src_frac_masksLocal source fractional mask.
(same structure as src_fields; values are expected to be in the range of [0.0;1.0]; ignored when frac_mask_fallback_value is YAC_FRAC_MASK_NO_VALUE).
[in]remote_src_fieldsReceived source field contributions from other ranks
dimensions: [collection_size][required_remote_points].
Received source data of all fields of each collection is expected to be in a single contiguous buffer, therefore this argument is missing the "num_src_fields" dimension.
Same pre-multiplication requirement as src_fields applies.
[in]remote_src_frac_masksReceived fractional masks for remote source data
(same structure as remote_src_fields; values are expected to be in the range of [0.0;1.0]; ignored when frac_mask_fallback_value is YAC_FRAC_MASK_NO_VALUE).
[out]tgt_fieldOutput buffers. dimensions: [collection_size][tgt_points].
[in]tgt_posIndices of target points to be computed (length = tgt_count).
[in]tgt_countNumber of target points to be computed.
[in]prefix_num_src_per_tgtPrefix-sum array encoding the number of source contributions per target.
Length = tgt_count + 1
Where: prefix_num_src_per_tgt[i+1] - prefix_num_src_per_tgt[i] gives the number of sources for i'th target point.
[in]weightsInterpolation weights for each source contribution. If NULL, all contributions are weighted equally (unweighted sum).
[in]src_field_idxSource field index for each contribution.
SIZE_MAX indicates that the contribution originates from remote process gathered in remote_src_fields and remote_src_frac_masks
[in]src_idxSource index within the chosen source field.
In case of remote data (src_field_idx == SIZE_MAX), it is the index in the contiguous buffer containing received data for all source fields of a collection.
[in]num_src_fieldsNumber of source fields.
[in]collection_sizeNumber of field collections.
[in]frac_mask_fallback_valueFallback value, which is applied to a target point if the sum of associated fractional mask values is below FRAC_MASK_TOL, i.e. effectively zero.
Pass YAC_FRAC_MASK_NO_VALUE to disable fractional masking.
[in]scale_factorScaling factor applied to the final weighted sum.
Not applied, if the frac_mask_fallback_value is assigned to a target.
[in]scale_summandSummand added to the scaled result. Not applied, if the frac_mask_fallback_value is assigned to a target.

Definition at line 582 of file interpolation_utils.h.

Here is the caller graph for this function:

◆ yac_interpolation_buffer_copy()

struct yac_interpolation_buffer yac_interpolation_buffer_copy ( struct yac_interpolation_buffer buffer,
size_t num_fields,
size_t collection_size )

Definition at line 116 of file interpolation_utils.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_interpolation_buffer_free()

void yac_interpolation_buffer_free ( struct yac_interpolation_buffer * buffer)

Definition at line 127 of file interpolation_utils.c.

Here is the caller graph for this function:

◆ yac_interpolation_buffer_init()

struct yac_interpolation_buffer yac_interpolation_buffer_init ( Xt_redist * redists,
size_t num_fields,
size_t collection_size,
enum yac_interpolation_buffer_type type )

Definition at line 88 of file interpolation_utils.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_interpolation_buffer_init_2()

struct yac_interpolation_buffer yac_interpolation_buffer_init_2 ( Xt_redist * redists,
size_t * min_buffer_sizes,
size_t num_fields,
size_t collection_size,
enum yac_interpolation_buffer_type type )

Definition at line 100 of file interpolation_utils.c.

Here is the call graph for this function:
Here is the caller graph for this function: