21#ifndef _libint2_src_bin_libint_rr_h_
22#define _libint2_src_bin_libint_rr_h_
26#include <default_params.h>
28#include <global_macros.h>
29#include <polyconstr.h>
30#include <singl_stack.h>
32#include <util_types.h>
44class ImplicitDimensions;
47class AlgebraicOperator;
55 static std::shared_ptr<RRStackBase<RR> > rrstack_;
62 typedef typename parent_type::data_type data_type;
63 typedef typename parent_type::value_type value_type;
69 static std::shared_ptr<RRStackBase<RR> >&
Instance() {
81 for (citer_type it = rrs->begin(); it != rrs->end(); it++) {
82 find((*it).second.second);
91std::shared_ptr<RRStackBase<RR> > RRStackBase<RR>::rrstack_;
97 :
public std::enable_shared_from_this<RecurrenceRelation> {
111 virtual std::shared_ptr<DGVertex>
rr_child(
unsigned int i)
const = 0;
113 virtual std::shared_ptr<DGVertex>
rr_target()
const = 0;
119 const std::shared_ptr<ExprType>&
rr_expr()
const {
return expr_; }
144 return BraketDirection::None;
156 const std::string&
label()
const;
164 virtual void generate_code(
const std::shared_ptr<CodeContext>& context,
165 const std::shared_ptr<ImplicitDimensions>& dims,
166 const std::string& funcname, std::ostream& decl,
172 const std::shared_ptr<CodeContext>& context,
173 const std::shared_ptr<ImplicitDimensions>& dims,
174 const std::string& funcname, std::ostream& decl, std::ostream& def);
178 const std::shared_ptr<CodeContext>& context,
179 const std::shared_ptr<ImplicitDimensions>& dims)
const;
182 unsigned int nflops()
const {
return nflops_; }
190 unsigned int nflops_;
191 mutable std::string label_;
192 std::shared_ptr<ExprType> expr_;
194 void add_expr(
const std::shared_ptr<ExprType>& a,
int minus = 1);
202 std::shared_ptr<RRStackBase<RecurrenceRelation> > rrstack =
204 std::shared_ptr<RR> this_ptr = std::const_pointer_cast<RR, const RR>(
205 std::static_pointer_cast<const RR, const RecurrenceRelation>(
206 std::enable_shared_from_this<
208 rrstack->find(this_ptr);
209#if DEBUG || DEBUG_CONSTRUCTION
210 std::cout <<
"register_with_rrstack: registered " << this_ptr->label()
220 std::shared_ptr<DirectedGraph> generate_graph_(
221 const std::shared_ptr<DirectedGraph>& dg);
224 void assign_symbols_(std::shared_ptr<CodeSymbols>& S);
227 virtual std::shared_ptr<ImplicitDimensions> adapt_dims_(
228 const std::shared_ptr<ImplicitDimensions>& dims)
const;
231 virtual bool has_generic(
232 const std::shared_ptr<CompilationParameters>& cparams)
const;
234 virtual std::string generic_header()
const;
237 virtual std::string generic_instance(
238 const std::shared_ptr<CodeContext>& context,
239 const std::shared_ptr<CodeSymbols>& args)
const;
244std::shared_ptr<RecurrenceRelation::ExprType> operator+(
245 const std::shared_ptr<DGVertex>& A,
const std::shared_ptr<DGVertex>& B);
246std::shared_ptr<RecurrenceRelation::ExprType> operator-(
247 const std::shared_ptr<DGVertex>& A,
const std::shared_ptr<DGVertex>& B);
248std::shared_ptr<RecurrenceRelation::ExprType> operator*(
249 const std::shared_ptr<DGVertex>& A,
const std::shared_ptr<DGVertex>& B);
250std::shared_ptr<RecurrenceRelation::ExprType> operator/(
251 const std::shared_ptr<DGVertex>& A,
const std::shared_ptr<DGVertex>& B);
252const std::shared_ptr<RecurrenceRelation::ExprType>& operator+=(
253 std::shared_ptr<RecurrenceRelation::ExprType>& A,
254 const std::shared_ptr<DGVertex>& B);
255const std::shared_ptr<RecurrenceRelation::ExprType>& operator-=(
256 std::shared_ptr<RecurrenceRelation::ExprType>& A,
257 const std::shared_ptr<DGVertex>& B);
258const std::shared_ptr<RecurrenceRelation::ExprType>& operator*=(
259 std::shared_ptr<RecurrenceRelation::ExprType>& A,
260 const std::shared_ptr<DGVertex>& B);
261const std::shared_ptr<RecurrenceRelation::ExprType>& operator/=(
262 std::shared_ptr<RecurrenceRelation::ExprType>& A,
263 const std::shared_ptr<DGVertex>& B);
276std::shared_ptr<RecurrenceRelation::ExprType>
operator*(
278 const std::shared_ptr<DGVertex>& B);
280std::shared_ptr<RecurrenceRelation::ExprType>
operator*(
282 const std::shared_ptr<DGVertex>& B);
AlgebraicOperator is an algebraic operator that acts on objects of type T.
Definition algebra.h:47
RRStack implements a stack of RecurrenceRelation's which can only hold one instance of a given RR.
Definition rr.h:53
void remove(const data_type &rr)
removes rr from the stack
Definition rr.h:87
static std::shared_ptr< RRStackBase< RR > > & Instance()
Obtain the unique Instance of RRStack.
Definition rr.h:69
void add(const std::shared_ptr< RRStackBase< RR > > &rrs)
adds content of rrs to this stack
Definition rr.h:80
RecurrenceRelation describes all recurrence relations.
Definition rr.h:97
virtual std::shared_ptr< DGVertex > rr_target() const =0
Returns the target.
void inst_id(const SingletonStack< RecurrenceRelation, std::string >::InstanceID &i)
RecurrenceRelation is managed by SingletonStack but doesn't need to keep track of instance ID.
Definition rr.h:186
virtual std::string description() const
description() returns a verbose description of this RR
Definition rr.cc:300
virtual bool invariant_type() const
Returns true is the type of target and all children are exactly the same.
Definition rr.cc:332
size_t size_of_children() const
Definition rr.cc:377
AlgebraicOperator< DGVertex > ExprType
Numerical expression of a recurrence relation is always expressed as an AlgebraicOperator<DGVertex>
Definition rr.h:117
virtual unsigned int num_children() const =0
num_children() returns the actual number of children.
const std::shared_ptr< ExprType > & rr_expr() const
Returns the expression.
Definition rr.h:119
virtual std::shared_ptr< DGVertex > rr_child(unsigned int i) const =0
Returns i-th child.
virtual BraketDirection braket_direction() const
Definition rr.h:143
bool register_with_rrstack()
Registers with the stack.
Definition rr.h:199
virtual std::string spfunction_call(const std::shared_ptr< CodeContext > &context, const std::shared_ptr< ImplicitDimensions > &dims) const
Generate a callback for this recurrence relation.
Definition rr.cc:339
const std::string & label() const
label() returns a unique, short, descriptive label of this RR (e.g.
Definition rr.cc:295
virtual int partindex_direction() const
Definition rr.h:137
virtual bool is_simple() const =0
Returns true is this recurrence relation is simple enough to optimize away.
virtual std::string generate_label() const =0
Generates the label.
void add_expr(const std::shared_ptr< ExprType > &a, int minus=1)
Adds a (or -a, if minus = -1) to expr_.
Definition rr.cc:305
virtual void generate_code(const std::shared_ptr< CodeContext > &context, const std::shared_ptr< ImplicitDimensions > &dims, const std::string &funcname, std::ostream &decl, std::ostream &def)
Generate declaration and definition for the recurrence relation.
Definition rr.cc:51
virtual void generate_generic_code(const std::shared_ptr< CodeContext > &context, const std::shared_ptr< ImplicitDimensions > &dims, const std::string &funcname, std::ostream &decl, std::ostream &def)
Generate declaration and definition for the recurrence relation using generic code (typically,...
Definition rr.cc:200
unsigned int nflops() const
Return the number of FLOPs per this recurrence relation.
Definition rr.h:182
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T.
Definition singl_stack.h:45
const value_type & find(const std::shared_ptr< RR > &obj)
Returns the pointer to the unique instance of object obj.
Definition singl_stack.h:81
void remove(const std::shared_ptr< RR > &obj)
Searches for obj on the stack and, if found, removes the unique instance.
Definition singl_stack.h:135
KeyTypes::InstanceID InstanceID
Specifies type for the instance index variables.
Definition singl_stack.h:50
map_type::iterator iter_type
use iter_type objects to iterate over the stack
Definition singl_stack.h:54
map_type::const_iterator citer_type
const version of iter_type
Definition singl_stack.h:56
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
std::shared_ptr< CTimeEntity< typename ProductType< T, U >::result > > operator*(const std::shared_ptr< CTimeEntity< T > > &A, const std::shared_ptr< CTimeEntity< U > > &B)
Creates product A*B.
Definition entity.h:302
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition bfset.h:906