Skip to main content

sum

Function sum 

Source
pub fn sum(backend: ComputeBackend, x: &Field<f64>) -> f64
Expand description

Sum of all elements, sum_i x[i].

Units: the field’s own units. An empty field sums to 0.0.

§Determinism

Reproducible run to run and independent of thread count, but not bit-identical to the serial Field::sum — the summation order differs. See the module-level “Reduction determinism” section for the measured deviation.

use outram_foam_basic_lib::compute::ComputeBackend;
use outram_foam_basic_lib::fields::field::Field;
use outram_foam_basic_lib::fields::parallel;

assert_eq!(parallel::sum(ComputeBackend::Serial, &Field::new(vec![1.0, 2.0, 3.0])), 6.0);
assert_eq!(parallel::sum(ComputeBackend::CpuMulti, &Field::<f64>::new(vec![])), 0.0);