MPQC  3.0.0-alpha
Public Types | Public Member Functions | Static Public Member Functions | Friends
sc::sma2::Array< N > Class Template Reference

Implements a block sparse tensor. More...

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

List of all members.

Public Types

typedef IndicesLess< N > Compare
typedef std::multimap
< BlockInfo< N >, double
*, Compare
blockmap_t
typedef std::multimap
< BlockInfo< N >, double
*, IndexListLess< N > > 
cached_blockmap_t
typedef AVLMMap< BlockInfo< N >
, double *, Compare
blockmap_t
typedef AVLMMap< BlockInfo< N >
, double *, IndexListLess< N > > 
cached_blockmap_t
typedef __gnu_cxx::hash_map
< BlockInfo< N >, double
*, BlockInfoHash< N >
, BlockInfoEqual< N > > 
blockhash_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.
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.
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 bound () const
void set_bound (double b)
double tolerance () const
void set_tolerance (double t)
void clear ()
 Make this array store nothing.
const blockmap_t & blockmap () const
 Return the block map.
const blockhash_t & blockhash () const
 Return the block hash.
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.
blockmap_t::value_type & add_allocated_block (const BlockInfo< N > &b)
 Adds block b.
blockmap_t::value_type & add_zeroed_block (const BlockInfo< N > &b)
 Adds block b.
void remove_block (const BlockInfo< N > &b)
 Removes a block.
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.
blockmap_t::iterator add_new_unallocated_block (const BlockInfo< N > &b)
 Adds block b.
void add_all_unallocated_blocks ()
 Adds all possible blocks to give a dense array.
blockmap_t::iterator initial_hint ()
 Returns an initial hint.
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.
void parallel_union (const sc::Ref< sc::MessageGrp > &grp)
 Makes the block distribution the same on all processes.
void replicated_from_distributed (const sc::Ref< sc::MessageGrp > &, const Array< N > &)
 Convert a distributed array to a replicated array.
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.
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.
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_t & blockmap_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

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.

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

Initialize all N indices to index.

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

Initialize range 0 to i0, and the rest to i1.

template<int N>
sc::sma2::Array< N >::Array ( const Range i0,
const Range i1,
const Range i2,
const std::string &  name = "",
double  tol = DBL_EPSILON 
) [inline]

Initialize range 0 to i0, 1 to i1, and the rest to i2.

template<int N>
sc::sma2::Array< N >::Array ( const Range i0,
const Range i1,
const Range i2,
const Range i3,
const std::string &  name = "",
double  tol = DBL_EPSILON 
) [inline]

Initialize range 0, 1 and 2 to i0, i1, and i2, and the rest to i3.

template<int N>
sc::sma2::Array< N >::Array ( const Range i0,
const Range i1,
const Range i2,
const Range i3,
const Range i4,
const std::string &  name = "",
double  tol = DBL_EPSILON 
) [inline]

Initialize range 0, 1, 2, 3, and 4 to i0, i1, i2, i3, and i4, and the rest to i4.

template<int N>
sc::sma2::Array< N >::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 
) [inline]

Initialize range 0, 1, 2, 3, 4, and 5 to i0, i1, i2, i3, i4, and i5, and the rest to i5.

template<int N>
sc::sma2::Array< N >::Array ( const Range ranges,
double  tol = DBL_EPSILON 
) [inline]

Initialize each range to the ranges in the given range array.


Member Function Documentation

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.

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.

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().

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.

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< N >::operator|=().

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.

template<int N>
void sc::sma2::Array< N >::allocate_blocks ( ) [inline]

Allocate storage for all blocks if storage has not already been allocated.

Referenced by sc::sma2::Array< 6 >::assign(), sc::sma2::Array< 6 >::assign_tol(), and sc::sma2::Array< 6 >::compute_bounds().

template<int N>
void sc::sma2::Array< N >::assign ( double  val) [inline]

Assigns the given value to all elements in the array.

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

template<int N>
void sc::sma2::Array< N >::assign_all ( const Array< N > &  a) [inline]

Assigns this to 'a', and keeps all blocks.

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=().

template<int N>
double sc::sma2::Array< N >::block_max_abs ( typename blockmap_t::const_iterator &  b) const [inline]

Find maximum absolute value of elements in a block.

Referenced by sc::sma2::Array< 6 >::init_blocks(), and sc::sma2::Array< 6 >::max_abs_element().

template<int N>
int sc::sma2::Array< N >::block_size ( const BlockInfo< N > &  bi) const [inline]
template<int N>
void sc::sma2::Array< N >::clear ( ) [inline]
template<int N>
void sc::sma2::Array< N >::clear_blockmap_cache ( ) [inline]

Get rid of cached blockmaps.

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

template<int N>
void sc::sma2::Array< N >::compute_bounds ( ) [inline]

Computes the bound for each block.

Referenced by sc::sma2::Array< 6 >::operator*=().

template<int N>
void sc::sma2::Array< N >::deallocate_blocks ( ) [inline]

Deallocate storage for all blocks.

template<int N>
int& sc::sma2::Array< N >::debug ( ) [inline]

Set/get the debug level.

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 
)
template<int N>
const Range& sc::sma2::Array< N >::index ( int  i) const [inline]
template<int N>
const Range* sc::sma2::Array< N >::indices ( ) const [inline]
template<int N>
void sc::sma2::Array< N >::init_blocks ( const Array< N > &  a,
double  tol 
) [inline]

Initialize the stored blocks to be the same as those in a.

Referenced by sc::sma2::Array< 6 >::assign_tol(), and sc::sma2::Array< 6 >::init_blocks().

template<int N>
void sc::sma2::Array< N >::init_blocks ( const Array< N > &  a) [inline]

Initialize the stored blocks to be the same as those in a.

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.

template<int N>
int sc::sma2::Array< N >::n_block ( ) const [inline]

Returns the number of blocks.

template<int N>
size_t sc::sma2::Array< N >::n_element ( ) const [inline]

Returns the number of elements contained in blocks.

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

template<int N>
size_t sc::sma2::Array< N >::n_element_allocated ( ) const [inline]

Returns the number of elements contained in blocks.

Referenced by sc::sma2::Array< N >::distributed_from_distributed().

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.

References sc::Timer::enter(), and sc::Timer::exit().

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.

References sc::Timer::enter(), sc::Timer::exit(), sc::MessageGrp::me(), and sc::MessageGrp::n().

template<int N>
void sc::sma2::Array< N >::print_local ( std::ostream &  o = sc::ExEnv::outn()) const [inline]
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.

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.

References sc::sma2::Array< N >::block_size(), sc::Timer::enter(), sc::Timer::exit(), sc::MessageGrp::me(), and sc::MessageGrp::n().

template<int N>
void sc::sma2::Array< N >::set_index ( int  i,
const Range idx 
) [inline]

Sets the i'th Range to index.

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

template<int N>
void sc::sma2::Array< N >::set_indices ( const Range r) [inline]

Initialize each range to the ranges in the given range array.

Referenced by sc::sma2::Array< 6 >::Array(), and sc::sma2::Array< 6 >::init_blocks().

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.

template<int N>
void sc::sma2::Array< N >::zero ( ) [inline]

Zeros the array.


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

Generated at Sat Jul 7 2012 11:53:02 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.0.