OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
sparse_vector.hpp File Reference

Sparse vector for halo exchange and indexed data views. More...

#include <algorithm>
#include <cstddef>
#include <vector>
#include <openpfc/core/backend_tags.hpp>
#include <openpfc/core/databuffer.hpp>
Include dependency graph for sparse_vector.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  pfc::core::SparseVector< BackendTag, T >
 Sparse vector for indexed data views. More...
 

Typedefs

using pfc::core::HostTag = backend::CpuTag
 

Functions

template<typename BackendTag , typename T >
bool pfc::core::on_host (const SparseVector< BackendTag, T > &vec)
 Check if SparseVector is on host.
 

Detailed Description

Sparse vector for halo exchange and indexed data views.

SparseVector represents a sparse view into selected entries of a dense array. It contains:

  • Sorted indices (exchanged once during setup)
  • Values at those indices (exchanged every step)

Key optimization: Indices are sorted for optimal contiguous memory access.

Used for:

  • Halo exchange in distributed memory
  • Arbitrary subregion extraction
  • Mask-based data selection
// Create sparse vector with indices
std::vector<size_t> indices = {2, 4, 6};
// Gather values from source array
std::vector<double> source = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
gather(sparse, source.data(), source.size());
// Scatter values to destination
std::vector<double> dest(7, 0.0);
scatter(sparse, dest.data(), dest.size());
Sparse vector for indexed data views.
Definition sparse_vector.hpp:66
void gather(SparseVector< BackendTag, T > &sparse_vector, const T *source, size_t source_size)
Gather: Collect values from dense array into SparseVector.
Definition sparse_vector_ops.hpp:64
void scatter(const SparseVector< BackendTag, T > &sparse_vector, T *dest, size_t dest_size)
Scatter: Write values from SparseVector into dense array.
Definition sparse_vector_ops.hpp:123
See also
core/databuffer.hpp for underlying memory management
core/exchange.hpp for MPI communication
Author
OpenPFC Development Team
Date
2025