Skip to main content

scale

Function scale 

Source
pub fn scale(alpha: f64, x: &mut [f64], backend: ComputeBackend)
Expand description

Scale x := alpha * x, in place, on the chosen backend.

The third element-wise vector update a Krylov solver needs, alongside axpy and the products. GMRES normalises every Arnoldi basis vector with it (v := v / ||v||), twice per inner iteration, so on a large mesh it is on the hot path; BiCGStab uses it to rescale search directions.

§Arguments

  • alpha — dimensionless scalar multiplier.
  • x — dimensionless vector in cell order, updated in place.
  • backend — requested execution backend; see vecop_backend_for for what will actually run.

§Determinism

Bitwise identical between backends and at any thread count, and bitwise identical to crate::krylov::vecops::scal: every element is an independent single multiplication, so — exactly as for axpy — there is no reduction to reassociate and no summation order to depend on. This is the strongest of the three determinism grades in this module and it holds unconditionally, for any finite or non-finite alpha and any input.

§Example

use outram_foam_basic_lib::compute::ComputeBackend;
use outram_foam_basic_lib::ldu_matrix::parallel::scale;

let mut x = [1.0, -2.0, 3.0];
scale(-2.0, &mut x, ComputeBackend::CpuMulti);
assert_eq!(x, [-2.0, 4.0, -6.0]);