Loading...
Searching...
No Matches
compensated_product_sum.c File Reference
#include <math.h>
#include <omp.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  Compensated

Functions

static void add_term (struct Compensated *state, double value)
static void add_product (struct Compensated *state, double left, double right)
float compensated_product_sum (double *out, const double *left, const double *right, int n)

Function Documentation

◆ add_product()

void add_product ( struct Compensated * state,
double left,
double right )
static

Definition at line 23 of file compensated_product_sum.c.

24{
25 const double product = left * right;
26 add_term(state, product);
27 add_term(state, fma(left, right, -product));
28}
static void add_term(struct Compensated *state, double value)

◆ add_term()

void add_term ( struct Compensated * state,
double value )
static

Definition at line 14 of file compensated_product_sum.c.

15{
16 const double next = state->sum + value;
17 state->corr += fabs(state->sum) >= fabs(value)
18 ? (state->sum - next) + value
19 : (value - next) + state->sum;
20 state->sum = next;
21}

◆ compensated_product_sum()

float compensated_product_sum ( double * out,
const double * left,
const double * right,
int n )

Definition at line 30 of file compensated_product_sum.c.

32{
33 struct Compensated state = {0.0, 0.0};
34 const double start = omp_get_wtime();
35 int i = 0;
36#if unroll == 8
37 for (; i + 7 < n; i += 8) {
38 add_product(&state, left[i], right[i]);
39 add_product(&state, left[i + 1], right[i + 1]);
40 add_product(&state, left[i + 2], right[i + 2]);
41 add_product(&state, left[i + 3], right[i + 3]);
42 add_product(&state, left[i + 4], right[i + 4]);
43 add_product(&state, left[i + 5], right[i + 5]);
44 add_product(&state, left[i + 6], right[i + 6]);
45 add_product(&state, left[i + 7], right[i + 7]);
46 }
47#elif unroll == 4
48 for (; i + 3 < n; i += 4) {
49 add_product(&state, left[i], right[i]);
50 add_product(&state, left[i + 1], right[i + 1]);
51 add_product(&state, left[i + 2], right[i + 2]);
52 add_product(&state, left[i + 3], right[i + 3]);
53 }
54#elif unroll == 2
55 for (; i + 1 < n; i += 2) {
56 add_product(&state, left[i], right[i]);
57 add_product(&state, left[i + 1], right[i + 1]);
58 }
59#endif
60 for (; i < n; ++i)
61 add_product(&state, left[i], right[i]);
62 out[0] = state.sum + state.corr;
63 return (float)((omp_get_wtime() - start) * 1.0e3);
64}
static void add_product(struct Compensated *state, double left, double right)
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out