YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
interpolation_utils.h File Reference
#include <math.h>
#include "utils_common.h"
#include "ppm/ppm_xfuncs.h"
#include "interpolation/interpolation_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 FRAC_MASK_TOL   (1e-12)
 
#define COMPUTE_TGT_FIELD_WGT_FRAC_(TGT_POS, WEIGHT, SCALE)
 
#define COMPUTE_TGT_FIELD_WGT_NOFRAC_(TGT_POS, WEIGHT, SCALE)
 
#define COMPUTE_TGT_FIELD_WGT(COMPUTE, SCALE)
 
#define COMPUTE_TGT_FIELD_WGT_FRAC(SCALE)    COMPUTE_TGT_FIELD_WGT(COMPUTE_TGT_FIELD_WGT_FRAC_, SCALE)
 
#define COMPUTE_TGT_FIELD_WGT_NOFRAC(SCALE)    COMPUTE_TGT_FIELD_WGT(COMPUTE_TGT_FIELD_WGT_NOFRAC_, SCALE)
 
#define NO_SCALING(RESULT)   (RESULT)
 
#define MULT(RESULT)   ((RESULT) * scale_factor)
 
#define ADD(RESULT)   ((RESULT) + scale_summand)
 
#define MULT_ADD(RESULT)   ((RESULT) * scale_factor + scale_summand)
 
#define COMPUTE_FIELD(COMPUTE_FIELD_FRAC, COMPUTE_FIELD_NOFRAC)
 
#define COMPUTE_TGT_FIELD_FRAC(SCALE)
 
#define COMPUTE_TGT_FIELD_NOFRAC(SCALE)
 
#define CHECK_WITH_FRAC_MASK(ROUTINE)
 

Enumerations

enum  yac_interpolation_buffer_type { SEND_BUFFER , RECV_BUFFER }
 

Functions

static void compute_tgt_field_wgt (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 optionally using weighted sums of source data and optionally applying fractional masking.
 
static void compute_tgt_field (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)
 
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)
 

Macro Definition Documentation

◆ ADD

#define ADD ( RESULT)    ((RESULT) + scale_summand)

◆ CHECK_WITH_FRAC_MASK

#define CHECK_WITH_FRAC_MASK ( ROUTINE)
Value:
with_frac_mask == \
YAC_FRAC_MASK_VALUE_IS_VALID(frac_mask_fallback_value), \
"ERROR(%s) " \
"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)", (ROUTINE), \
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:19

Definition at line 310 of file interpolation_utils.h.

◆ COMPUTE_FIELD

#define COMPUTE_FIELD ( COMPUTE_FIELD_FRAC,
COMPUTE_FIELD_NOFRAC )
Value:
{ \
if (YAC_FRAC_MASK_VALUE_IS_VALID(frac_mask_fallback_value)) { \
if (scale_factor == 1.0) { \
if (scale_summand == 0.0) COMPUTE_FIELD_FRAC(NO_SCALING) \
else COMPUTE_FIELD_FRAC(ADD) \
} else { \
if (scale_summand == 0.0) COMPUTE_FIELD_FRAC(MULT) \
else COMPUTE_FIELD_FRAC(MULT_ADD) \
} \
} else { \
if (scale_factor == 1.0) { \
if (scale_summand == 0.0) COMPUTE_FIELD_NOFRAC(NO_SCALING) \
else COMPUTE_FIELD_NOFRAC(ADD) \
} else { \
if (scale_summand == 0.0) COMPUTE_FIELD_NOFRAC(MULT) \
else COMPUTE_FIELD_NOFRAC(MULT_ADD) \
} \
} \
}
#define ADD(RESULT)
#define NO_SCALING(RESULT)
#define MULT(RESULT)
#define MULT_ADD(RESULT)

◆ COMPUTE_TGT_FIELD_FRAC

#define COMPUTE_TGT_FIELD_FRAC ( SCALE)
Value:
{ \
for (size_t i = 0; i < collection_size; ++i) { \
for (size_t j = 0; j < num_src_fields; ++j) { \
memcpy(tgt_field[i * num_src_fields + j], \
src_fields[i][j], tgt_buffer_sizes[j]); \
size_t const tgt_count = \
tgt_buffer_sizes[j] / sizeof(***src_fields); \
{ \
YAC_OMP_FOR \
for (size_t k = 0; k < tgt_count; ++k) { \
if (fabs(src_frac_masks[i][j][k]) > FRAC_MASK_TOL) \
tgt_field[i * num_src_fields + j][k] = \
SCALE( \
tgt_field[i * num_src_fields + j][k] / \
src_frac_masks[i][j][k]); \
else \
tgt_field[i * num_src_fields + j][k] = \
frac_mask_fallback_value; \
} \
} \
} \
} \
}
#define FRAC_MASK_TOL
int collection_size
#define YAC_OMP_PARALLEL

◆ COMPUTE_TGT_FIELD_NOFRAC

#define COMPUTE_TGT_FIELD_NOFRAC ( SCALE)
Value:
{ \
for (size_t i = 0; i < collection_size; ++i) { \
for (size_t j = 0; j < num_src_fields; ++j) { \
memcpy(tgt_field[i * num_src_fields + j], \
src_fields[i][j], tgt_buffer_sizes[j]); \
size_t const tgt_count = \
tgt_buffer_sizes[j] / sizeof(***src_fields); \
{ \
YAC_OMP_FOR \
for (size_t k = 0; k < tgt_count; ++k) \
tgt_field[i * num_src_fields + j][k] = \
SCALE(tgt_field[i * num_src_fields + j][k]); \
} \
} \
} \
}
#define SCALE(X)

◆ COMPUTE_TGT_FIELD_WGT

#define COMPUTE_TGT_FIELD_WGT ( COMPUTE,
SCALE )
Value:
{ \
if (weights != NULL) { \
if (tgt_pos != NULL) COMPUTE(tgt_pos[i], weights[k], SCALE) \
else COMPUTE(i, weights[k], SCALE) \
} else { \
if (tgt_pos != NULL) COMPUTE(tgt_pos[i], 1.0, SCALE) \
else COMPUTE(i, 1.0, SCALE) \
} \
}

◆ COMPUTE_TGT_FIELD_WGT_FRAC

#define COMPUTE_TGT_FIELD_WGT_FRAC ( SCALE)     COMPUTE_TGT_FIELD_WGT(COMPUTE_TGT_FIELD_WGT_FRAC_, SCALE)

◆ COMPUTE_TGT_FIELD_WGT_FRAC_

#define COMPUTE_TGT_FIELD_WGT_FRAC_ ( TGT_POS,
WEIGHT,
SCALE )

◆ COMPUTE_TGT_FIELD_WGT_NOFRAC

#define COMPUTE_TGT_FIELD_WGT_NOFRAC ( SCALE)     COMPUTE_TGT_FIELD_WGT(COMPUTE_TGT_FIELD_WGT_NOFRAC_, SCALE)

◆ COMPUTE_TGT_FIELD_WGT_NOFRAC_

#define COMPUTE_TGT_FIELD_WGT_NOFRAC_ ( TGT_POS,
WEIGHT,
SCALE )
Value:
{ \
for (size_t l = 0; l < collection_size; ++l) { \
double const * restrict * curr_local_field_data = \
src_fields?src_fields[l]:NULL; \
double const * restrict curr_remote_field_data = \
remote_src_fields[l * num_src_fields]; \
double * restrict curr_tgt_field = tgt_field[l]; \
{ \
YAC_OMP_FOR \
for (size_t i = 0; i < tgt_count; ++i) { \
double result = 0.0; \
size_t const k_bound = prefix_num_src_per_tgt[i+1]; \
for (size_t k = prefix_num_src_per_tgt[i]; k < k_bound; ++k) { \
double const * restrict src_field_data; \
if (src_field_idx[k] == SIZE_MAX) { \
src_field_data = curr_remote_field_data; \
} else { \
src_field_data = curr_local_field_data[src_field_idx[k]]; \
} \
result += src_field_data[src_idx[k]] * (WEIGHT); \
} \
curr_tgt_field[(TGT_POS)] = SCALE(result); \
} \
} \
} \
}

◆ FRAC_MASK_TOL

#define FRAC_MASK_TOL   (1e-12)

◆ MULT

#define MULT ( RESULT)    ((RESULT) * scale_factor)

◆ MULT_ADD

#define MULT_ADD ( RESULT)    ((RESULT) * scale_factor + scale_summand)

◆ NO_SCALING

#define NO_SCALING ( RESULT)    (RESULT)

Enumeration Type Documentation

◆ yac_interpolation_buffer_type

Enumerator
SEND_BUFFER 
RECV_BUFFER 

Definition at line 321 of file interpolation_utils.h.

Function Documentation

◆ compute_tgt_field()

static void compute_tgt_field ( 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

Definition at line 243 of file interpolation_utils.h.

Here is the caller graph for this function:

◆ compute_tgt_field_wgt()

static void compute_tgt_field_wgt ( 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 optionally using weighted sums of source data and optionally applying fractional masking.

This routine computes a target field based on the provided source data and weights. This is basically a sparse-matrix-vector multiplication.

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.

Each target point tgt_pos[i] is computed as a (weighted or unweighted) sum of source values (from local or remote processes).

Parameters
[in]src_fieldsLocal source field data.
dimensions: [collection_size][num_src_fields][local_points].
[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]).
[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.
[in]remote_src_frac_masksReceived fractional masks for remote source data
(same structure as remote_src_fields).
[out]tgt_fieldTarget field values to be computed, array of dimension [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_valueValue to used, if the sum of fractional mask values of all source contributions for a target is 0.0.
If it is YAC_FRAC_MASK_NO_VALUE, no fractional masking will be applied.
[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 100 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 114 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 125 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 86 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 98 of file interpolation_utils.c.

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