MPQC  3.0.0-alpha
sc::sma2::Array< N > Class Template Reference

Implements a block sparse tensor. More...

#include <chemistry/qc/lmp2/sma.h>

Public Types

typedef IndicesLess< N > Compare
 
typedef AVLMMap< BlockInfo< N >, double *, Compareblockmap_t
 
typedef AVLMMap< BlockInfo< N >, double *, IndexListLess< N > > cached_blockmap_t
 

Public Member Functions

 Array (const Array< N > &a)
 
void assign_tol (const Array< N > &a, double tol)
 Assigns this to 'a', but throws out blocks smaller than tol. More...
 
void assign_all (const Array< N > &a)
 Assigns this to 'a', and keeps all blocks.
 
Array< N > & operator= (const Array< N > &a)
 Assigns this to 'a', but throws out small blocks.
 
 Array (const std::string &name="", double tol=DBL_EPSILON)
 This does not initialize any indices. More...
 
void init (const std::string &name="", double tol=DBL_EPSILON)
 
 Array (const Range &index, const std::string &name="", double tol=DBL_EPSILON)
 Initialize all N indices to index.
 
void init (const Range &index, const std::string &name="", double tol=DBL_EPSILON)
 
 Array (const Range &i0, const Range &i1, const std::string &name="", double tol=DBL_EPSILON)
 Initialize range 0 to i0, and the rest to i1.
 
void init (const Range &i0, const Range &i1, const std::string &name="", double tol=DBL_EPSILON)
 
 Array (const Range &i0, const Range &i1, const Range &i2, const std::string &name="", double tol=DBL_EPSILON)
 Initialize range 0 to i0, 1 to i1, and the rest to i2.
 
void init (const Range &i0, const Range &i1, const Range &i2, const std::string &name="", double tol=DBL_EPSILON)
 
 Array (const Range &i0, const Range &i1, const Range &i2, const Range &i3, const std::string &name="", double tol=DBL_EPSILON)
 Initialize range 0, 1 and 2 to i0, i1, and i2, and the rest to i3.
 
void init (const Range &i0, const Range &i1, const Range &i2, const Range &i3, const std::string &name="", double tol=DBL_EPSILON)
 
 Array (const Range &i0, const Range &i1, const Range &i2, const Range &i3, const Range &i4, const std::string &name="", double tol=DBL_EPSILON)
 Initialize range 0, 1, 2, 3, and 4 to i0, i1, i2, i3, and i4, and the rest to i4.
 
void init (const Range &i0, const Range &i1, const Range &i2, const Range &i3, const Range &i4, const std::string &name="", double tol=DBL_EPSILON)
 
 Array (const Range &i0, const Range &i1, const Range &i2, const Range &i3, const Range &i4, const Range &i5, const std::string &name="", double tol=DBL_EPSILON)
 Initialize range 0, 1, 2, 3, 4, and 5 to i0, i1, i2, i3, i4, and i5, and the rest to i5.
 
void init (const Range &i0, const Range &i1, const Range &i2, const Range &i3, const Range &i4, const Range &i5, const std::string &name="", double tol=DBL_EPSILON)
 
 Array (const Range *ranges, double tol=DBL_EPSILON)
 Initialize each range to the ranges in the given range array.
 
double tolerance () const
 
void set_tolerance (double t)
 
void clear ()
 Make this array store nothing.
 
const blockmap_tblockmap () const
 Return the block map.
 
void set_index (int i, const Range &idx)
 Sets the i'th Range to index.
 
void set_indices (const Range *r)
 Initialize each range to the ranges in the given range array.
 
const Rangeindex (int i) const
 Gets the i'th Range.
 
const Rangeindices () const
 Gets the Range array.
 
int block_size (const BlockInfo< N > &bi) const
 Return size of the given block.
 
blockmap_t::value_type & add_unallocated_block (const BlockInfo< N > &b)
 Adds block b. More...
 
blockmap_t::value_type & add_allocated_block (const BlockInfo< N > &b)
 Adds block b. More...
 
blockmap_t::value_type & add_zeroed_block (const BlockInfo< N > &b)
 Adds block b. More...
 
void remove_block (const BlockInfo< N > &b)
 Removes a block. More...
 
void relocate_block (const BlockInfo< N > &b_old, const BlockInfo< N > &b_new)
 
blockmap_t::iterator add_new_unallocated_block (const typename blockmap_t::iterator &hint, const BlockInfo< N > &b)
 Adds block b. More...
 
blockmap_t::iterator add_new_unallocated_block (const BlockInfo< N > &b)
 Adds block b. More...
 
void add_all_unallocated_blocks ()
 Adds all possible blocks to give a dense array. More...
 
blockmap_t::iterator initial_hint ()
 Returns an initial hint. More...
 
int n_block () const
 Returns the number of blocks.
 
size_t n_element () const
 Returns the number of elements contained in blocks.
 
size_t n_element_allocated () const
 Returns the number of elements contained in blocks.
 
std::string name () const
 
double max_n_block ()
 
double max_n_element ()
 
void assign (double val)
 Assigns the given value to all elements in the array.
 
void zero ()
 Zeros the array.
 
void compute_bounds ()
 Computes the bound for each block.
 
void allocate_blocks ()
 Allocate storage for all blocks if storage has not already been allocated.
 
void deallocate_blocks ()
 Deallocate storage for all blocks.
 
ContractPart< N > operator() ()
 
ContractPart< N > operator() (const Index &i1)
 
ContractPart< N > operator() (const Index &i1, const Index &i2)
 
ContractPart< N > operator() (const std::string &i1, const std::string &i2)
 
ContractPart< N > operator() (const Index &i1, const Index &i2, const Index &i3)
 
ContractPart< N > operator() (const std::string &i1, const std::string &i2, const std::string &i3)
 
ContractPart< N > operator() (const Index &i1, const Index &i2, const Index &i3, const Index &i4)
 
ContractPart< N > operator() (const std::string &i1, const std::string &i2, const std::string &i3, const std::string &i4)
 
ContractPart< N > operator() (const Index &i1, const Index &i2, const Index &i3, const Index &i4, const Index &i5)
 
ContractPart< N > operator() (const std::string &i1, const std::string &i2, const std::string &i3, const std::string &i4, const std::string &i5)
 
ContractPart< N > operator() (const Index &i1, const Index &i2, const Index &i3, const Index &i4, const Index &i5, const Index &i6)
 
ContractPart< N > operator() (const std::string &i1, const std::string &i2, const std::string &i3, const std::string &i4, const std::string &i5, const std::string &i6)
 
void operator*= (double f)
 Multiplication by a scalar.
 
void init_blocks (const Array< N > &a, double tol)
 Initialize the stored blocks to be the same as those in a.
 
void init_blocks (const Array< N > &a)
 Initialize the stored blocks to be the same as those in a.
 
double block_max_abs (typename blockmap_t::const_iterator &b) const
 Find maximum absolute value of elements in a block.
 
double max_abs_element ()
 Find maximum absolute value of elements.
 
void print_local (std::ostream &o=sc::ExEnv::outn()) const
 Print the array.
 
void print (const sc::Ref< sc::MessageGrp > &grp=0, bool distributed=false, std::ostream &o=sc::ExEnv::outn()) const
 
int & debug ()
 Set/get the debug level.
 
const int & debug () const
 
void read (sc::StateIn &si)
 
void write (sc::StateOut &so) const
 
void parallel_accumulate (const sc::Ref< sc::MessageGrp > &grp)
 Performs a reduce-broadcast on the data. More...
 
void parallel_union (const sc::Ref< sc::MessageGrp > &grp)
 Makes the block distribution the same on all processes. More...
 
void replicated_from_distributed (const sc::Ref< sc::MessageGrp > &, const Array< N > &)
 Convert a distributed array to a replicated array. More...
 
void distributed_from_distributed (const sc::Ref< sc::MessageGrp > &, const BlockDistrib< N > &, Array< N > &, bool clear_source_array=false, bool ignore_block_distrib_throws=false)
 Redistribute an array. More...
 
double value ()
 If this is a scalar (N==0) return the value of the scalar.
 
void clear_blockmap_cache ()
 Get rid of cached blockmaps.
 
void set_use_blockmap_cache (bool ubmc)
 Used to indicate whether or not a blockmap cache is to be used. More...
 
bool use_blockmap_cache () const
 Return true if blockmap caches are in use.
 
bool blockmap_cache_entry_exists (const IndexList &il)
 Return true if the needed blockmap cache entry exists.
 
cached_blockmap_tblockmap_cache_entry (const IndexList &il)
 Return a cached blockmap.
 

Static Public Member Functions

static int nindex ()
 Return the number of indices.
 

Friends

template<int N1>
void remap (typename Array< N1 >::cached_blockmap_t &target, const Array< N1 > &source, const IndexList &fixed, const BlockInfo< N1 > &fixedvals)
 
template<int N1>
void remap (Array< N1 > &target, const Array< N1 > &source, const IndexList &il)
 

Detailed Description

template<int N>
class sc::sma2::Array< N >

Implements a block sparse tensor.

Array maps the BlockInfo to the block's data using the given Compare type to sort the blocks.

Constructor & Destructor Documentation

◆ Array()

template<int N>
sc::sma2::Array< N >::Array ( const std::string &  name = "",
double  tol = DBL_EPSILON 
)
inline

This does not initialize any indices.

The set_index member must be called for all indices before the array is used.

Member Function Documentation

◆ add_all_unallocated_blocks()

template<int N>
void sc::sma2::Array< N >::add_all_unallocated_blocks ( )
inline

Adds all possible blocks to give a dense array.

The data is not allocated. This cannot be called after storage for the data has been allocated with allocate blocks.

◆ add_allocated_block()

template<int N>
blockmap_t::value_type& sc::sma2::Array< N >::add_allocated_block ( const BlockInfo< N > &  b)
inline

Adds block b.

The data is allocated. This should not be used with add_unallocated_blocks or allocate_blocks. The memory allocated is not initialized.

◆ add_new_unallocated_block() [1/2]

template<int N>
blockmap_t::iterator sc::sma2::Array< N >::add_new_unallocated_block ( const BlockInfo< N > &  b)
inline

Adds block b.

The data is not allocated. This cannot be called after storage for the data has been allocated with allocate blocks. This assumes that the new block does not already exist int the multimap.

◆ add_new_unallocated_block() [2/2]

template<int N>
blockmap_t::iterator sc::sma2::Array< N >::add_new_unallocated_block ( const typename blockmap_t::iterator &  hint,
const BlockInfo< N > &  b 
)
inline

Adds block b.

The data is not allocated. This cannot be called after storage for the data has been allocated with allocate blocks. This assumes that the new block does not already exist int the multimap. The hint gives a suggested insertion point.

Referenced by sc::sma2::Array< 6 >::add_all_unallocated_blocks().

◆ add_unallocated_block()

template<int N>
blockmap_t::value_type& sc::sma2::Array< N >::add_unallocated_block ( const BlockInfo< N > &  b)
inline

Adds block b.

The data is not allocated. This cannot be called after storage for the data has been allocated with allocate blocks.

Referenced by sc::sma2::Array< 6 >::init_blocks(), and sc::sma2::ContractPart< Nl >::operator|=().

◆ add_zeroed_block()

template<int N>
blockmap_t::value_type& sc::sma2::Array< N >::add_zeroed_block ( const BlockInfo< N > &  b)
inline

Adds block b.

The data is allocated. This should not be used with add_unallocated_blocks or allocate_blocks. The data allocated is initialized to zero.

◆ assign_tol()

template<int N>
void sc::sma2::Array< N >::assign_tol ( const Array< N > &  a,
double  tol 
)
inline

Assigns this to 'a', but throws out blocks smaller than tol.

The tolerance of this will be set to the tolerance of 'a', no matter what tol is.

Referenced by sc::sma2::Array< 6 >::assign_all(), and sc::sma2::Array< 6 >::operator=().

◆ distributed_from_distributed()

template<int N>
void sc::sma2::Array< N >::distributed_from_distributed ( const sc::Ref< sc::MessageGrp > &  msg,
const BlockDistrib< N > &  distrib,
Array< N > &  d,
bool  clear_source_array = false,
bool  ignore_block_distrib_throws = false 
)

Redistribute an array.

The result is stored in this.

◆ initial_hint()

template<int N>
blockmap_t::iterator sc::sma2::Array< N >::initial_hint ( )
inline

Returns an initial hint.

Basically, it is just used to initialize a blockmap::iterator to a valid value.

◆ parallel_accumulate()

template<int N>
void sc::sma2::Array< N >::parallel_accumulate ( const sc::Ref< sc::MessageGrp > &  grp)

Performs a reduce-broadcast on the data.

The array must have the same block structure on all processes.

◆ parallel_union()

template<int N>
void sc::sma2::Array< N >::parallel_union ( const sc::Ref< sc::MessageGrp > &  grp)

Makes the block distribution the same on all processes.

If any processes hold a block, then all will after this call. This does not send any data, only block structure is sent.

◆ remove_block()

template<int N>
void sc::sma2::Array< N >::remove_block ( const BlockInfo< N > &  b)
inline

Removes a block.

If the data has been allocated, it is deallocated. Does nothing if the block does not exist.

◆ replicated_from_distributed()

template<int N>
void sc::sma2::Array< N >::replicated_from_distributed ( const sc::Ref< sc::MessageGrp > &  msg,
const Array< N > &  d 
)

Convert a distributed array to a replicated array.

The result is stored in this.

◆ set_use_blockmap_cache()

template<int N>
void sc::sma2::Array< N >::set_use_blockmap_cache ( bool  ubmc)
inline

Used to indicate whether or not a blockmap cache is to be used.

Blockmap caches store alternative blockmaps that are used in the contract routine. If a required blockmap is not available, then it is computed. It is also added to the blockmap cache if this is true.


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

Generated at Sun Jan 26 2020 23:24:15 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.