#include <IntegerReprosum.hpp>
Classes | |
| struct | Metadata |
Public Member Functions | |
| IntegerReprosum (int comm=0) | |
| Serial constructor; the comm parameter is unused. More... | |
| ~IntegerReprosum ()=default | |
| double | sum (const std::vector< double > &vals) const |
| double | sum_masked (const std::vector< double > &vals, const std::vector< int > &mask) const |
| void | sum_masked_batch (const std::vector< std::vector< double > > &fields, const std::vector< int > &mask, std::vector< double > &gsums) const |
Private Member Functions | |
| Metadata | compute_metadata (const std::vector< double > &vals, const std::vector< int > *mask) const |
| Reduce per-field local exponent extrema and the local count of non-zero summands across the comm and derive arr_max_shift, max_levels, extra_levels. More... | |
| void | encode_local (const std::vector< double > &vals, const std::vector< int > *mask, const Metadata &md, std::vector< int64_t > &iv) const |
Encode local summands into the integer-vector representation. iv is sized max_levels + extra_levels, indexed so that iv[idx] corresponds to algorithmic level idx - (extra_levels - 1). More... | |
| void | reduce_global (std::vector< int64_t > &iv) const |
| MPI_Allreduce(MPI_SUM, MPI_INT64_T) on the integer vector. More... | |
| double | decode_global (const std::vector< int64_t > &iv, const Metadata &md) const |
| Reconstruct double from the global integer vector. Faithful port of the decode section of shr_reprosum_int (preprocess for non- overlap and same-sign, truncate at FP-representable boundary, sum the resulting r8 components smallest-to-largest). More... | |
Static Private Attributes | |
| static constexpr int | kI8Digits = 63 |
| mantissa bits in int64 (sign excluded) More... | |
| static constexpr int | kR8Digits = 53 |
| mantissa bits in double More... | |
| static constexpr int | kRadix = 2 |
Reproducible global summation using the integer-vector algorithm (Worley). One instance per MPI communicator; the sum() / sum_masked() entry points can be called repeatedly on different value vectors.
Definition at line 48 of file IntegerReprosum.hpp.
|
explicit |
Serial constructor; the comm parameter is unused.
Definition at line 35 of file IntegerReprosum.cpp.
|
default |
|
private |
Reduce per-field local exponent extrema and the local count of non-zero summands across the comm and derive arr_max_shift, max_levels, extra_levels.
Definition at line 97 of file IntegerReprosum.cpp.
References moab::IntegerReprosum::Metadata::arr_max_shift, moab::IntegerReprosum::Metadata::extra_levels, moab::IntegerReprosum::Metadata::gmax_exp, moab::IntegerReprosum::Metadata::gmin_exp, moab::IntegerReprosum::Metadata::max_levels, and moab::IntegerReprosum::Metadata::max_nsummands.
|
private |
Reconstruct double from the global integer vector. Faithful port of the decode section of shr_reprosum_int (preprocess for non- overlap and same-sign, truncate at FP-representable boundary, sum the resulting r8 components smallest-to-largest).
Definition at line 331 of file IntegerReprosum.cpp.
References moab::IntegerReprosum::Metadata::arr_max_shift, moab::IntegerReprosum::Metadata::extra_levels, moab::IntegerReprosum::Metadata::gmax_exp, moab::anonymous_namespace{IntegerReprosum.cpp}::i2pow(), moab::IntegerReprosum::Metadata::max_levels, moab::IntegerReprosum::Metadata::max_nsummands, moab::anonymous_namespace{IntegerReprosum.cpp}::scale2(), and moab::anonymous_namespace{IntegerReprosum.cpp}::set_exp().
|
private |
Encode local summands into the integer-vector representation. iv is sized max_levels + extra_levels, indexed so that iv[idx] corresponds to algorithmic level idx - (extra_levels - 1).
Definition at line 221 of file IntegerReprosum.cpp.
References moab::IntegerReprosum::Metadata::arr_max_shift, moab::IntegerReprosum::Metadata::extra_levels, moab::IntegerReprosum::Metadata::gmax_exp, moab::anonymous_namespace{IntegerReprosum.cpp}::i2pow(), moab::IntegerReprosum::Metadata::max_levels, moab::IntegerReprosum::Metadata::max_nsummands, and moab::anonymous_namespace{IntegerReprosum.cpp}::scale2().
|
private |
MPI_Allreduce(MPI_SUM, MPI_INT64_T) on the integer vector.
Definition at line 310 of file IntegerReprosum.cpp.
| double moab::IntegerReprosum::sum | ( | const std::vector< double > & | vals | ) | const |
Compute the global sum of every entry in vals across all ranks on the constructor's MPI communicator. Bit-identical regardless of how vals is partitioned across ranks or iterated locally.
Definition at line 560 of file IntegerReprosum.cpp.
| double moab::IntegerReprosum::sum_masked | ( | const std::vector< double > & | vals, |
| const std::vector< int > & | mask | ||
| ) | const |
Compute the global sum of vals[i] only where mask[i] >= 0. Useful for excluding halo / not-owned entries when summing per-rank partial vectors. mask must be the same length as vals.
Definition at line 565 of file IntegerReprosum.cpp.
References moab::IntegerReprosum::Metadata::max_nsummands.
| void moab::IntegerReprosum::sum_masked_batch | ( | const std::vector< std::vector< double > > & | fields, |
| const std::vector< int > & | mask, | ||
| std::vector< double > & | gsums | ||
| ) | const |
Convenience batch entry: compute one global sum per input vector, sharing the metadata (gmax/gmin exponent) reduction across all fields in the batch. Equivalent to calling sum_masked() N times but with one fewer MPI_Allreduce per field for the metadata. All input vectors must have the same length and use the same mask.
Definition at line 579 of file IntegerReprosum.cpp.
References moab::IntegerReprosum::Metadata::arr_max_shift, moab::IntegerReprosum::Metadata::extra_levels, moab::IntegerReprosum::Metadata::gmax_exp, moab::IntegerReprosum::Metadata::gmin_exp, moab::IntegerReprosum::Metadata::max_levels, and moab::IntegerReprosum::Metadata::max_nsummands.
Referenced by moab::TempestOnlineMap::ApplyWeightsWithDualMap().
|
staticconstexprprivate |
mantissa bits in int64 (sign excluded)
Definition at line 130 of file IntegerReprosum.hpp.
|
staticconstexprprivate |
mantissa bits in double
Definition at line 131 of file IntegerReprosum.hpp.
|
staticconstexprprivate |
Definition at line 132 of file IntegerReprosum.hpp.