Chi-Tech
chi_math::ParallelSTLVector Class Reference

#include <ParallelSTLVector.h>

Inheritance diagram for chi_math::ParallelSTLVector:
chi_math::ParallelVector chi_math::GhostedParallelSTLVector

Public Member Functions

 ParallelSTLVector (uint64_t local_size, uint64_t global_size, MPI_Comm communicator)
 
 ParallelSTLVector (const ParallelSTLVector &other)
 
 ParallelSTLVector (ParallelSTLVector &&other) noexcept
 
std::unique_ptr< ParallelVectorMakeCopy () const override
 
std::unique_ptr< ParallelVectorMakeClone () const override
 
double * Data () override
 
const double * Data () const override
 
const std::vector< double > & LocalSTLData () const
 
std::vector< double > & LocalSTLData ()
 
double operator[] (int64_t local_id) const override
 
double & operator[] (int64_t local_id) override
 
std::vector< double > MakeLocalVector () override
 Return a vector containing the locally owned data. More...
 
void Set (double value) override
 
void Set (const std::vector< double > &local_vector) override
 
void BlockSet (const std::vector< double > &y, int64_t local_offset, int64_t num_values) override
 
void CopyLocalValues (const ParallelVector &y) override
 
void CopyLocalValues (Vec y) override
 
void BlockCopyLocalValues (const ParallelVector &y, int64_t y_offset, int64_t local_offset, int64_t num_values) override
 
void BlockCopyLocalValues (Vec y, int64_t y_offset, int64_t local_offset, int64_t num_values) override
 
void SetValue (int64_t global_id, double value, VecOpType op_type) override
 
void SetValues (const std::vector< int64_t > &global_ids, const std::vector< double > &values, VecOpType op_type) override
 
void operator+= (const ParallelVector &y) override
 
void PlusAY (const ParallelVector &y, double a) override
 
void AXPlusY (double a, const ParallelVector &y) override
 
void Scale (double a) override
 
void Shift (double a) override
 
double ComputeNorm (chi_math::NormType norm_type) const override
 
void Assemble () override
 
std::string PrintStr () const override
 Print the local vectors to stings. More...
 
- Public Member Functions inherited from chi_math::ParallelVector
 ParallelVector (uint64_t local_size, uint64_t global_size, MPI_Comm communicator)
 
 ParallelVector (const ParallelVector &other)
 
 ParallelVector (ParallelVector &&other) noexcept
 
virtual std::unique_ptr< ParallelVectorMakeCopy () const =0
 
virtual std::unique_ptr< ParallelVectorMakeClone () const =0
 
virtual double * Data ()=0
 
virtual const double * Data () const =0
 
uint64_t LocalSize () const
 Return the size of the locally owned portion of the parallel vector. More...
 
uint64_t GlobalSize () const
 Return the global size of the parallel vector. More...
 
virtual double operator[] (int64_t local_id) const =0
 
virtual double & operator[] (int64_t local_id)=0
 
virtual std::vector< double > MakeLocalVector ()=0
 Return a vector containing the locally owned data. More...
 
virtual void Set (double value)=0
 
virtual void Set (const std::vector< double > &local_vector)=0
 
virtual void BlockSet (const std::vector< double > &y, int64_t local_offset, int64_t num_values)=0
 
virtual void CopyLocalValues (const ParallelVector &y)=0
 
virtual void CopyLocalValues (Vec y)=0
 
virtual void BlockCopyLocalValues (const ParallelVector &y, int64_t y_offset, int64_t local_offset, int64_t num_values)=0
 
virtual void BlockCopyLocalValues (Vec y, int64_t y_offset, int64_t local_offset, int64_t num_values)=0
 
virtual void SetValue (int64_t global_id, double value, VecOpType op_type)=0
 
virtual void SetValues (const std::vector< int64_t > &global_ids, const std::vector< double > &values, VecOpType op_type)=0
 
virtual void operator+= (const ParallelVector &y)=0
 
virtual void PlusAY (const ParallelVector &y, double a)=0
 
virtual void AXPlusY (double a, const ParallelVector &y)=0
 
virtual void Scale (double a)=0
 
virtual void Shift (double a)=0
 
virtual double ComputeNorm (chi_math::NormType norm_type) const =0
 
virtual void Assemble ()=0
 
virtual std::string PrintStr () const =0
 Print the local vectors to stings. More...
 
virtual void CommunicateGhostEntries ()
 
virtual ~ParallelVector ()=default
 

Protected Types

using Operation = std::pair< int64_t, double >
 

Protected Attributes

const std::vector< uint64_t > extents_
 
std::vector< double > values_
 
std::vector< Operationset_cache_
 
std::vector< Operationadd_cache_
 
- Protected Attributes inherited from chi_math::ParallelVector
const uint64_t local_size_
 
const uint64_t global_size_
 
const int location_id_
 
const int process_count_
 
const MPI_Comm comm_
 

Private Member Functions

int FindOwnerPID (uint64_t global_id) const
 

Static Private Member Functions

static std::vector< uint64_t > DefineExtents (uint64_t local_size, int comm_size, MPI_Comm communicator)
 

Detailed Description

An implementation of a parallel vector.

Definition at line 19 of file ParallelSTLVector.h.

Member Typedef Documentation

◆ Operation

using chi_math::ParallelSTLVector::Operation = std::pair<int64_t, double>
protected

Definition at line 174 of file ParallelSTLVector.h.

Constructor & Destructor Documentation

◆ ParallelSTLVector() [1/3]

chi_math::ParallelSTLVector::ParallelSTLVector ( uint64_t  local_size,
uint64_t  global_size,
MPI_Comm  communicator 
)

Initialize a parallel vector with the given local and global sizes with the given communicator whose entries are set to zero.

Definition at line 23 of file ParallelSTLVector.cc.

◆ ParallelSTLVector() [2/3]

chi_math::ParallelSTLVector::ParallelSTLVector ( const ParallelSTLVector other)

Copy constructor.

Definition at line 32 of file ParallelSTLVector.cc.

◆ ParallelSTLVector() [3/3]

chi_math::ParallelSTLVector::ParallelSTLVector ( ParallelSTLVector &&  other)
noexcept

Move constructor.

Definition at line 37 of file ParallelSTLVector.cc.

Member Function Documentation

◆ Assemble()

void chi_math::ParallelSTLVector::Assemble ( )
overridevirtual

Communicate all operations stored within the operation cache to the corresponding processes that own the respective global indices, and apply the operations.

This routine clears the respective operation cache once completed.

Implements chi_math::ParallelVector.

Definition at line 375 of file ParallelSTLVector.cc.

◆ AXPlusY()

void chi_math::ParallelSTLVector::AXPlusY ( double  a,
const ParallelVector y 
)
overridevirtual

Performs x = a*x + y with the current vector being x.

Implements chi_math::ParallelVector.

Definition at line 290 of file ParallelSTLVector.cc.

◆ BlockCopyLocalValues() [1/2]

void chi_math::ParallelSTLVector::BlockCopyLocalValues ( const ParallelVector y,
int64_t  y_offset,
int64_t  local_offset,
int64_t  num_values 
)
overridevirtual

Copies a contiguous block of local data (num_values entries) from the source vector (starting at y_offset) to the current vector starting at local_offset.

Implements chi_math::ParallelVector.

Definition at line 157 of file ParallelSTLVector.cc.

◆ BlockCopyLocalValues() [2/2]

void chi_math::ParallelSTLVector::BlockCopyLocalValues ( Vec  y,
int64_t  y_offset,
int64_t  local_offset,
int64_t  num_values 
)
overridevirtual

Copies a contiguous block of local data (num_values entries) from the source vector (starting at y_offset) to the current vector starting at local_offset. PETSc flavor.

Implements chi_math::ParallelVector.

Definition at line 188 of file ParallelSTLVector.cc.

◆ BlockSet()

void chi_math::ParallelSTLVector::BlockSet ( const std::vector< double > &  y,
int64_t  local_offset,
int64_t  num_values 
)
overridevirtual

Copies a contiguous block of data from the source STL vector to the current vector starting at local_offset. The input STL vector must have exactly num_values entries.

Implements chi_math::ParallelVector.

Definition at line 111 of file ParallelSTLVector.cc.

◆ ComputeNorm()

double chi_math::ParallelSTLVector::ComputeNorm ( chi_math::NormType  norm_type) const
overridevirtual

Returns the specified norm of the vector.

Implements chi_math::ParallelVector.

Definition at line 318 of file ParallelSTLVector.cc.

◆ CopyLocalValues() [1/2]

void chi_math::ParallelSTLVector::CopyLocalValues ( const ParallelVector y)
overridevirtual

Sets the local values of one vector equal to another. The sizes must be compatible.

Implements chi_math::ParallelVector.

Definition at line 129 of file ParallelSTLVector.cc.

◆ CopyLocalValues() [2/2]

void chi_math::ParallelSTLVector::CopyLocalValues ( Vec  y)
overridevirtual

Sets the local values of the vector equal to that of the PETSc vector. The sizes must be compatible.

Implements chi_math::ParallelVector.

Definition at line 143 of file ParallelSTLVector.cc.

◆ Data() [1/2]

const double * chi_math::ParallelSTLVector::Data ( ) const
overridevirtual

Returns a direct const pointer to the memory array used internally by the vector to store its owned elements

Implements chi_math::ParallelVector.

Definition at line 59 of file ParallelSTLVector.cc.

◆ Data() [2/2]

double * chi_math::ParallelSTLVector::Data ( )
overridevirtual

Returns a direct pointer to the memory array used internally by the vector to store its owned elements.

Implements chi_math::ParallelVector.

Definition at line 58 of file ParallelSTLVector.cc.

◆ DefineExtents()

std::vector< uint64_t > chi_math::ParallelSTLVector::DefineExtents ( uint64_t  local_size,
int  comm_size,
MPI_Comm  communicator 
)
staticprivate

Definition at line 492 of file ParallelSTLVector.cc.

◆ FindOwnerPID()

int chi_math::ParallelSTLVector::FindOwnerPID ( uint64_t  global_id) const
private

Definition at line 518 of file ParallelSTLVector.cc.

◆ LocalSTLData() [1/2]

std::vector< double > & chi_math::ParallelSTLVector::LocalSTLData ( )

Returns a reference to the local data of the vector.

Definition at line 66 of file ParallelSTLVector.cc.

◆ LocalSTLData() [2/2]

const std::vector< double > & chi_math::ParallelSTLVector::LocalSTLData ( ) const

Returns a constant reference to the local data of the vector.

Definition at line 61 of file ParallelSTLVector.cc.

◆ MakeClone()

std::unique_ptr< ParallelVector > chi_math::ParallelSTLVector::MakeClone ( ) const
overridevirtual

Creates a copy of the vector datastructures but NOT the values. The values are defaulted to zero. This routine requires no communication.

Implements chi_math::ParallelVector.

Definition at line 49 of file ParallelSTLVector.cc.

◆ MakeCopy()

std::unique_ptr< ParallelVector > chi_math::ParallelSTLVector::MakeCopy ( ) const
overridevirtual

Creates a copy of the vector datastructures AND values. This routine requires no communication.

Implements chi_math::ParallelVector.

Definition at line 44 of file ParallelSTLVector.cc.

◆ MakeLocalVector()

std::vector< double > chi_math::ParallelSTLVector::MakeLocalVector ( )
overridevirtual

Return a vector containing the locally owned data.

Implements chi_math::ParallelVector.

Definition at line 68 of file ParallelSTLVector.cc.

◆ operator+=()

void chi_math::ParallelSTLVector::operator+= ( const ParallelVector y)
overridevirtual

In place adding of vectors. The sizes must be compatible.

Implements chi_math::ParallelVector.

Definition at line 253 of file ParallelSTLVector.cc.

◆ operator[]() [1/2]

double chi_math::ParallelSTLVector::operator[] ( int64_t  local_id) const
overridevirtual

Read only accessor to the entry at the given local index of the local vector.

Note
This accessor allows access to all locally stored elements, including any data beyond local_size_ that may exist in derived classes.

Implements chi_math::ParallelVector.

Definition at line 74 of file ParallelSTLVector.cc.

◆ operator[]() [2/2]

double & chi_math::ParallelSTLVector::operator[] ( int64_t  local_id)
overridevirtual

Read/write accessor to the entry at the given local index of the local vector.

Note
This accessor allows access to all locally stored elements, including any data beyond local_size_ that may exist in derived classes.

Implements chi_math::ParallelVector.

Definition at line 84 of file ParallelSTLVector.cc.

◆ PlusAY()

void chi_math::ParallelSTLVector::PlusAY ( const ParallelVector y,
double  a 
)
overridevirtual

Adds a vector multiplied by scalar a, x = x + a*y. Optimized for a=1.0 and -1.0

Implements chi_math::ParallelVector.

Definition at line 268 of file ParallelSTLVector.cc.

◆ PrintStr()

std::string chi_math::ParallelSTLVector::PrintStr ( ) const
overridevirtual

Print the local vectors to stings.

Implements chi_math::ParallelVector.

Definition at line 528 of file ParallelSTLVector.cc.

◆ Scale()

void chi_math::ParallelSTLVector::Scale ( double  a)
overridevirtual

Adds a constant scalar value to all the entries of the vector

Implements chi_math::ParallelVector.

Definition at line 305 of file ParallelSTLVector.cc.

◆ Set() [1/2]

void chi_math::ParallelSTLVector::Set ( const std::vector< double > &  local_vector)
overridevirtual

Set the entries of the locally owned portion of the parallel vector to the given STL vector.

Implements chi_math::ParallelVector.

Definition at line 99 of file ParallelSTLVector.cc.

◆ Set() [2/2]

void chi_math::ParallelSTLVector::Set ( double  value)
overridevirtual

Set the entries of the locally owned portion of the parallel vector to the given value.

Implements chi_math::ParallelVector.

Definition at line 94 of file ParallelSTLVector.cc.

◆ SetValue()

void chi_math::ParallelSTLVector::SetValue ( int64_t  global_id,
double  value,
VecOpType  op_type 
)
overridevirtual

Define a set or add operation for the given global id-value pair

This routine adds the global id-value pair to the set operation cache, which upon execution of Assemble, communicates the operations to the appropriate process.

Implements chi_math::ParallelVector.

Definition at line 223 of file ParallelSTLVector.cc.

◆ SetValues()

void chi_math::ParallelSTLVector::SetValues ( const std::vector< int64_t > &  global_ids,
const std::vector< double > &  values,
VecOpType  op_type 
)
overridevirtual

Group multiple operations into a single call.

This routine goes through the given global id-value pairs and calls SetValue for each.

Implements chi_math::ParallelVector.

Definition at line 235 of file ParallelSTLVector.cc.

◆ Shift()

void chi_math::ParallelSTLVector::Shift ( double  a)
overridevirtual

Returns the specified norm of the vector.

Implements chi_math::ParallelVector.

Definition at line 311 of file ParallelSTLVector.cc.

Field Documentation

◆ add_cache_

std::vector<Operation> chi_math::ParallelSTLVector::add_cache_
protected

Definition at line 176 of file ParallelSTLVector.h.

◆ extents_

const std::vector<uint64_t> chi_math::ParallelSTLVector::extents_
protected

Definition at line 170 of file ParallelSTLVector.h.

◆ set_cache_

std::vector<Operation> chi_math::ParallelSTLVector::set_cache_
protected

Definition at line 175 of file ParallelSTLVector.h.

◆ values_

std::vector<double> chi_math::ParallelSTLVector::values_
protected

Definition at line 172 of file ParallelSTLVector.h.


The documentation for this class was generated from the following files: