sg-ode
|
A generic interface for elementwise and aggregate operations on vectors. More...
#include <stddef.h>
#include "extern.h"
#include "inline_begin.h"
#include "restrict_begin.h"
#include "restrict_end.h"
#include "inline_end.h"
Go to the source code of this file.
Data Structures | |
struct | SgVectorDriverVt |
The minimal set of operations that a vector driver must support. More... | |
struct | SgVectorDriver |
A vector driver. More... | |
Typedefs | |
typedef void | SgVector |
A vector is an opaque data type containing a finite number of double s. More... | |
typedef void | SgVectorAccum |
An accumulator is an array of some kind. More... | |
typedef int | SgVectorAccumType |
The type of an accumulator. More... | |
typedef void | SgVectorOperation(void *f_ctx, SgVectorAccum *accum, const SgVectorAccum *val, size_t offset, double **data, size_t num_elems) |
An operation suitable for use in SgVectorDriverVt.operate . More... | |
typedef void | SgVectorDriverBase |
Represents an opaque vector driver. More... | |
Functions | |
SgVector * | sg_vector_try_new (struct SgVectorDriver drv) |
Creates a vector, returning NULL if it fails. More... | |
SgVector * | sg_vector_new (struct SgVectorDriver drv) |
Creates a vector. More... | |
void | sg_vector_del (struct SgVectorDriver drv, SgVector *vector) |
Destroys the vector. More... | |
size_t | sg_vector_len (struct SgVectorDriver drv) |
Gets the length of any vector created by this vector driver. More... | |
void | sg_vector_operate (struct SgVectorDriver drv, SgVectorAccum *accum, SgVectorAccumType accum_type, SgVectorOperation *f, void *f_ctx, size_t offset, SgVector **vectors, size_t num_vectors) |
Perform a generic operation on some vectors. More... | |
void | sg_vector_fill (struct SgVectorDriver drv, double value, SgVector *vector) |
Set every element of a vector to the same value. More... | |
void | sg_vector_copy (struct SgVectorDriver drv, const SgVector *src, SgVector *dest) |
Copy the contents of a vector. More... | |
void | sg_vector_neg_assign (struct SgVectorDriver drv, SgVector *z) |
void | sg_vector_neg (struct SgVectorDriver drv, const SgVector *x, SgVector *z) |
void | sg_vector_scale_assign (struct SgVectorDriver drv, double alpha, SgVector *z) |
In-place scalar multiplication of a vector. More... | |
void | sg_vector_scale (struct SgVectorDriver drv, double alpha, const SgVector *x, SgVector *z) |
Calculate scalar multiplication of a vector. More... | |
void | sg_vector_linear_assign (struct SgVectorDriver drv, double alpha, double beta, const SgVector *y, SgVector *z) |
Calculate z ← α z + β y . More... | |
void | sg_vector_linear (struct SgVectorDriver drv, double alpha, const SgVector *x, double beta, const SgVector *y, SgVector *z) |
Calculate the linear combination of two vectors. More... | |
double | sg_vector_sum (struct SgVectorDriver drv, const SgVector *vector) |
Sums the values of a vector. More... | |
Variables | |
SgVectorOperation | sg_vector_fill_operation |
SgVectorOperation | sg_vector_copy_operation |
SgVectorOperation | sg_vector_neg_assign_operation |
SgVectorOperation | sg_vector_neg_operation |
SgVectorOperation | sg_vector_scale_assign_operation |
SgVectorOperation | sg_vector_scale_operation |
SgVectorOperation | sg_vector_linear_assign_operation |
SgVectorOperation | sg_vector_linear_operation |
SgVectorOperation | sg_vector_sum_operation |
The underlying operation used by sg_vector_sum . More... | |
struct SgVectorDriverVt | SG_BASIC_VECTOR_DRIVER_VT |
A generic interface for elementwise and aggregate operations on vectors.
typedef void SgVector |
A vector is an opaque data type containing a finite number of double
s.
typedef void SgVectorAccum |
An accumulator is an array of some kind.
typedef int SgVectorAccumType |
The type of an accumulator.
unsigned char
, with length given by the absolute value of the type.double
, with length given by the absolute value of the type.Accum
pointer may not even be valid).It is important to specify the correct accumulator type, as the SgVectorDriver
implementation may use this information to transmit the accumulator across different processes.
typedef void SgVectorDriverBase |
Represents an opaque vector driver.
typedef void SgVectorOperation(void *f_ctx, SgVectorAccum *accum, const SgVectorAccum *val, size_t offset, double **data, size_t num_elems) |
An operation suitable for use in SgVectorDriverVt.operate
.
[in,out] | f_ctx | The same f_ctx pointer provided to operate . |
[in,out] | accum | The accumulated value so far. |
[in] | val | A value that needs to be merged into accum . |
[in] | offset | Offset of this slice relative to the beginning. |
[in,out] | data | Partial slices of the vectors. |
[in] | num_elems | Number of elements in each slice. |
The function must update accum
to the monoidal summation of:
accum
,val
, andnum_elems - 1
)The function may also perform an element-wise operation on the given subvectors. It can modify the subvectors, in which case the changes will be reflected on the original vectors.
For a given value of f_ctx
, function f
must be thread-safe. That is, it must not access global variables without synchronization.
void sg_vector_copy | ( | struct SgVectorDriver | drv, |
const SgVector * | src, | ||
SgVector * | dest | ||
) |
Copy the contents of a vector.
void sg_vector_del | ( | struct SgVectorDriver | drv, |
SgVector * | vector | ||
) |
Destroys the vector.
This is a no-op if the vector is null.
void sg_vector_fill | ( | struct SgVectorDriver | drv, |
double | value, | ||
SgVector * | vector | ||
) |
Set every element of a vector to the same value.
size_t sg_vector_len | ( | struct SgVectorDriver | drv | ) |
Gets the length of any vector created by this vector driver.
void sg_vector_linear | ( | struct SgVectorDriver | drv, |
double | alpha, | ||
const SgVector * | x, | ||
double | beta, | ||
const SgVector * | y, | ||
SgVector * | z | ||
) |
Calculate the linear combination of two vectors.
Either or both input vectors may completely overlap with the output vector. Partial overlaps are not allowed.
void sg_vector_linear_assign | ( | struct SgVectorDriver | drv, |
double | alpha, | ||
double | beta, | ||
const SgVector * | y, | ||
SgVector * | z | ||
) |
Calculate z ← α z + β y
.
The input vector y
may completely overlap with the output vector z
. Partial overlaps are not allowed.
SgVector* sg_vector_new | ( | struct SgVectorDriver | drv | ) |
Creates a vector.
void sg_vector_operate | ( | struct SgVectorDriver | drv, |
SgVectorAccum * | accum, | ||
SgVectorAccumType | accum_type, | ||
SgVectorOperation * | f, | ||
void * | f_ctx, | ||
size_t | offset, | ||
SgVector ** | vectors, | ||
size_t | num_vectors | ||
) |
Perform a generic operation on some vectors.
void sg_vector_scale | ( | struct SgVectorDriver | drv, |
double | alpha, | ||
const SgVector * | x, | ||
SgVector * | z | ||
) |
Calculate scalar multiplication of a vector.
The input vectors may completely overlap with the output vector. Partial overlaps are not allowed.
void sg_vector_scale_assign | ( | struct SgVectorDriver | drv, |
double | alpha, | ||
SgVector * | z | ||
) |
In-place scalar multiplication of a vector.
double sg_vector_sum | ( | struct SgVectorDriver | drv, |
const SgVector * | vector | ||
) |
Sums the values of a vector.
SgVector* sg_vector_try_new | ( | struct SgVectorDriver | drv | ) |
Creates a vector, returning NULL
if it fails.
SgVectorOperation sg_vector_sum_operation |
The underlying operation used by sg_vector_sum
.