Skip to content

Commit

Permalink
refactor: remove SafePtr
Browse files Browse the repository at this point in the history
  • Loading branch information
e-kwsm committed Nov 24, 2023
1 parent 60bcd4a commit a858dfd
Show file tree
Hide file tree
Showing 81 changed files with 1,362 additions and 1,363 deletions.
2 changes: 1 addition & 1 deletion src/bin/libint/algebra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace libint2 {

template <>
void
AlgebraicOperator<DGVertex>::add_exit_arc(const SafePtr<DGArc>& a)
AlgebraicOperator<DGVertex>::add_exit_arc(const std::shared_ptr<DGArc>& a)
{
DGVertex::add_exit_arc(a);
#if CHECK_SAFETY
Expand Down
26 changes: 13 additions & 13 deletions src/bin/libint/algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ namespace libint2 {
typedef algebra::OperatorTypes::OperatorType OperatorType;

AlgebraicOperator(OperatorType OT,
const SafePtr<T>& left,
const SafePtr<T>& right) :
const std::shared_ptr<T>& left,
const std::shared_ptr<T>& right) :
DGVertex(ClassInfo<AlgebraicOperator>::Instance().id()), OT_(OT), left_(left), right_(right),
label_(algebra::OperatorSymbol[OT_])
{
}
virtual ~AlgebraicOperator() {}

/// Clone A but replace operands with left and right
AlgebraicOperator(const SafePtr<AlgebraicOperator>& A,
const SafePtr<T>& left,
const SafePtr<T>& right) :
AlgebraicOperator(const std::shared_ptr<AlgebraicOperator>& A,
const std::shared_ptr<T>& left,
const std::shared_ptr<T>& right) :
DGVertex(static_cast<DGVertex&>(*A)), OT_(A->OT_),
left_(left), right_(right), label_(A->label_)
{
Expand All @@ -90,16 +90,16 @@ namespace libint2 {
/// Returns the OperatorType
OperatorType type() const { return OT_; }
/// Returns the left argument
const SafePtr<T>& left() const { return left_; }
const std::shared_ptr<T>& left() const { return left_; }
/// Returns the right argument
const SafePtr<T>& right() const { return right_; }
const std::shared_ptr<T>& right() const { return right_; }

/// Overloads DGVertex::add_exit_arc(). The default definition is used unless T = DGVertex (see algebra.cc)
void add_exit_arc(const SafePtr<DGArc>& a) override;
void add_exit_arc(const std::shared_ptr<DGArc>& a) override;
/// Implements DGVertex::size()
unsigned int size() const override { return 1; }
/// Implements DGVertex::equiv()
bool equiv(const SafePtr<DGVertex>& a) const override
bool equiv(const std::shared_ptr<DGVertex>& a) const override
{
if (typeid_ == a->typeid_) {
#if ALGEBRAICOPERATOR_USE_KEY_TO_COMPARE
Expand All @@ -120,7 +120,7 @@ namespace libint2 {
}

/// laboriously compare 2 operators element by element
bool operator==(const SafePtr<AlgebraicOperator>& a) const {
bool operator==(const std::shared_ptr<AlgebraicOperator>& a) const {
#if ALGEBRAICOPERATOR_USE_SAFEPTR
// Find out why sometimes equivalent left_ and a->left_ have non-equivalent pointers
if (left_->equiv(a->left()) && left_ != a->left_) {
Expand Down Expand Up @@ -189,8 +189,8 @@ namespace libint2 {

private:
OperatorType OT_;
SafePtr<T> left_;
SafePtr<T> right_;
std::shared_ptr<T> left_;
std::shared_ptr<T> right_;

/// Implements DGVertex::this_precomputed()
bool this_precomputed() const override
Expand All @@ -204,7 +204,7 @@ namespace libint2 {
/*
template <>
void
AlgebraicOperator<DGVertex>::add_exit_arc(const SafePtr<DGArc>& a)
AlgebraicOperator<DGVertex>::add_exit_arc(const std::shared_ptr<DGArc>& a)
{
DGVertex::add_exit_arc(a);
if (left_->equiv(a->dest()))
Expand Down
4 changes: 2 additions & 2 deletions src/bin/libint/bfset.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
namespace libint2 {

/** Set of basis functions. Sets must be constructable using
SafePtr<BFSet> or SafePtr<ConstructablePolymorphically>.
std::shared_ptr<BFSet> or std::shared_ptr<ConstructablePolymorphically>.
*/
class BFSet : public ConstructablePolymorphically {

Expand All @@ -52,7 +52,7 @@ namespace libint2 {
};

/** Set of basis functions with incrementable/decrementable quantum numbers.
Sets must be constructable using SafePtr<BFSet> or SafePtr<ConstructablePolymorphically>.
Sets must be constructable using std::shared_ptr<BFSet> or std::shared_ptr<ConstructablePolymorphically>.
Call to dec() may invalidate the object. No further
modification of such object's state is possible.
Expand Down
248 changes: 124 additions & 124 deletions src/bin/libint/build_libint.cc

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/bin/libint/buildtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace libint2 {

void
generate_rr_code(std::ostream& os,
const SafePtr<CompilationParameters>& cparams,
const std::shared_ptr<CompilationParameters>& cparams,
std::deque<std::string>& decl_filenames,
std::deque<std::string>& def_filenames)
{
SafePtr<CodeContext> context(new CppCodeContext(cparams));
std::shared_ptr<CodeContext> context(new CppCodeContext(cparams));
ImplicitDimensions::set_default_dims(cparams);
std::string prefix(cparams->source_directory());

SafePtr<RRStack> rrstack = RRStack::Instance();
std::shared_ptr<RRStack> rrstack = RRStack::Instance();

#define GENERATE_ALL_RRS 0
#if GENERATE_ALL_RRS
Expand All @@ -51,7 +51,7 @@ namespace libint2 {
//
RRStack::citer_type it = rrstack->begin();
while (it != rrstack->end()) {
SafePtr<RecurrenceRelation> rr = (*it).second.second;
std::shared_ptr<RecurrenceRelation> rr = (*it).second.second;
#else
//
// generate code for all recurrence relation actually used
Expand All @@ -62,7 +62,7 @@ namespace libint2 {
const tciter tend = taskmgr.plast();
std::set<TaskExternSymbols::RRList::value_type> aggregate_rrlist;
for(tciter t=taskmgr.first(); t!=tend; ++t) {
const SafePtr<TaskExternSymbols> tsymbols = t->symbols();
const std::shared_ptr<TaskExternSymbols> tsymbols = t->symbols();
typedef TaskExternSymbols::SymbolList SymbolList;
auto rrlist = tsymbols->rrlist();
aggregate_rrlist.insert(rrlist.begin(), rrlist.end());
Expand Down
78 changes: 39 additions & 39 deletions src/bin/libint/buildtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@
namespace libint2 {

// defined in buildtest.cc
void generate_rr_code(std::ostream& os, const SafePtr<CompilationParameters>& cparams,
void generate_rr_code(std::ostream& os, const std::shared_ptr<CompilationParameters>& cparams,
std::deque<std::string>& decl_filenames,
std::deque<std::string>& def_filenames);

/// defined below generates code for dg; dg and memman are reset at the end
void
GenerateCode(const SafePtr<DirectedGraph>& dg,
const SafePtr<CodeContext>& context,
const SafePtr<CompilationParameters>& cparams,
const SafePtr<Strategy>& strat,
const SafePtr<Tactic>& tactic,
const SafePtr<MemoryManager>& memman,
GenerateCode(const std::shared_ptr<DirectedGraph>& dg,
const std::shared_ptr<CodeContext>& context,
const std::shared_ptr<CompilationParameters>& cparams,
const std::shared_ptr<Strategy>& strat,
const std::shared_ptr<Tactic>& tactic,
const std::shared_ptr<MemoryManager>& memman,
std::deque<std::string>& decl_filenames,
std::deque<std::string>& def_filenames,
const std::string& prefix,
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace libint2 {
to be produced (i.e. include header files + set-level recurrence relations code)
*/
template <class Integral, bool GenAllCode>
void BuildTest(const std::vector< SafePtr<Integral> >& targets, unsigned int size_to_unroll, unsigned int veclen,
void BuildTest(const std::vector< std::shared_ptr<Integral> >& targets, unsigned int size_to_unroll, unsigned int veclen,
bool vec_by_line, bool do_cse, const std::string& complabel = "buildtest",
std::ostream& os = std::cout);

Expand All @@ -91,23 +91,23 @@ namespace libint2 {
to be produced (i.e. include header files + set-level recurrence relations code)
*/
template <class Integral, bool GenAllCode>
void __BuildTest(const std::vector< SafePtr<Integral> >& targets, const SafePtr<CompilationParameters>& cparams,
void __BuildTest(const std::vector< std::shared_ptr<Integral> >& targets, const std::shared_ptr<CompilationParameters>& cparams,
unsigned int size_to_unroll, std::ostream& os = std::cout,
const SafePtr<Tactic>& tactic = SafePtr<Tactic>(new FirstChoiceTactic<DummyRandomizePolicy>),
const SafePtr<MemoryManager>& memman = SafePtr<MemoryManager>(new WorstFitMemoryManager),
const std::shared_ptr<Tactic>& tactic = std::shared_ptr<Tactic>(new FirstChoiceTactic<DummyRandomizePolicy>),
const std::shared_ptr<MemoryManager>& memman = std::shared_ptr<MemoryManager>(new WorstFitMemoryManager),
const std::string& complabel = "general_integral");

template <class Integral, bool GenAllCode>
void
__BuildTest(const std::vector< SafePtr<Integral> >& targets, const SafePtr<CompilationParameters>& cparams,
__BuildTest(const std::vector< std::shared_ptr<Integral> >& targets, const std::shared_ptr<CompilationParameters>& cparams,
unsigned int size_to_unroll, std::ostream& os,
const SafePtr<Tactic>& tactic, const SafePtr<MemoryManager>& memman,
const std::shared_ptr<Tactic>& tactic, const std::shared_ptr<MemoryManager>& memman,
const std::string& complabel)
{
const std::string prefix("");
const std::string label = cparams->api_prefix() + complabel;
SafePtr<Strategy> strat(new Strategy);
SafePtr<CodeContext> context(new CppCodeContext(cparams));
std::shared_ptr<Strategy> strat(new Strategy);
std::shared_ptr<CodeContext> context(new CppCodeContext(cparams));

LibraryTaskManager& taskmgr = LibraryTaskManager::Instance();
taskmgr.add(complabel);
Expand All @@ -118,7 +118,7 @@ namespace libint2 {
//
unsigned int max_am = 0;
for(unsigned int t=0; t<targets.size(); ++t) {
const SafePtr<Integral>& target = targets[t];
const std::shared_ptr<Integral>& target = targets[t];
const unsigned int np = target->bra().num_part();
// bra
for(unsigned int p=0; p<np; p++) {
Expand Down Expand Up @@ -148,7 +148,7 @@ namespace libint2 {

os << "Building " << complabel << std::endl;

SafePtr<DirectedGraph> dg_xxxx(new DirectedGraph);
std::shared_ptr<DirectedGraph> dg_xxxx(new DirectedGraph);
dg_xxxx->set_label(complabel);

// configure the graph
Expand All @@ -159,8 +159,8 @@ namespace libint2 {
dg_xxxx->registry()->unroll_threshold(size_to_unroll);

for(unsigned int t=0; t<targets.size(); ++t) {
const SafePtr<Integral>& target = targets[t];
SafePtr<DGVertex> target_ptr = dynamic_pointer_cast<DGVertex,Integral>(target);
const std::shared_ptr<Integral>& target = targets[t];
std::shared_ptr<DGVertex> target_ptr = dynamic_pointer_cast<DGVertex,Integral>(target);
assert(target_ptr != 0);
dg_xxxx->append_target(target_ptr);
}
Expand All @@ -177,9 +177,9 @@ namespace libint2 {

if (GenAllCode) {
// initialize code context to produce library API
SafePtr<CodeContext> icontext(new CppCodeContext(cparams));
std::shared_ptr<CodeContext> icontext(new CppCodeContext(cparams));
// initialize object to generate interface
SafePtr<Libint2Iface> iface(new Libint2Iface(cparams,icontext));
std::shared_ptr<Libint2Iface> iface(new Libint2Iface(cparams,icontext));

// generate interface
std::ostringstream oss;
Expand Down Expand Up @@ -215,12 +215,12 @@ namespace libint2 {
}

void
GenerateCode(const SafePtr<DirectedGraph>& dg,
const SafePtr<CodeContext>& context,
const SafePtr<CompilationParameters>& cparams,
const SafePtr<Strategy>& strat,
const SafePtr<Tactic>& tactic,
const SafePtr<MemoryManager>& memman,
GenerateCode(const std::shared_ptr<DirectedGraph>& dg,
const std::shared_ptr<CodeContext>& context,
const std::shared_ptr<CompilationParameters>& cparams,
const std::shared_ptr<Strategy>& strat,
const std::shared_ptr<Tactic>& tactic,
const std::shared_ptr<MemoryManager>& memman,
std::deque<std::string>& decl_filenames,
std::deque<std::string>& def_filenames,
const std::string& prefix,
Expand All @@ -245,7 +245,7 @@ namespace libint2 {
//std::cout << "missing some prerequisites!" << std::endl;
dg->foreach(pe);
}
std::deque< SafePtr<DGVertex> > prereq_list = pe.vertices;
std::deque< std::shared_ptr<DGVertex> > prereq_list = pe.vertices;

dg->traverse();
//dg->debug_print_traversal(cout);
Expand All @@ -262,7 +262,7 @@ namespace libint2 {
std::basic_ofstream<char> declfile(decl_filename.c_str());
std::basic_ofstream<char> deffile(def_filename.c_str());
// if have parent graph, it will pass its stack where this graph will put its results
SafePtr<CodeSymbols> args(new CodeSymbols);
std::shared_ptr<CodeSymbols> args(new CodeSymbols);
if (have_parent)
args->append_symbol("parent_stack");
dg->generate_code(context,memman,ImplicitDimensions::default_dims(),args,
Expand All @@ -286,9 +286,9 @@ namespace libint2 {
// last: missing prerequisites? create new graph computing prereqs and move them onto it
if (dg->missing_prerequisites()) {

SafePtr<DirectedGraph> dg_prereq(new DirectedGraph);
std::shared_ptr<DirectedGraph> dg_prereq(new DirectedGraph);
// configure identically
dg_prereq->registry() = SafePtr<GraphRegistry>(dg->registry()->clone());
dg_prereq->registry() = std::shared_ptr<GraphRegistry>(dg->registry()->clone());
// except:
// - allow uncontraction
// - no need to return targets via inteval->targets_ -- their locations are known by the parent graph (see allocate_mem)
Expand Down Expand Up @@ -324,7 +324,7 @@ namespace libint2 {
}

template <class Integral, bool GenAllCode>
void BuildTest(const std::vector< SafePtr<Integral> >& targets, unsigned int size_to_unroll, unsigned int veclen,
void BuildTest(const std::vector< std::shared_ptr<Integral> >& targets, unsigned int size_to_unroll, unsigned int veclen,
bool vec_by_line, bool do_cse, const std::string& complabel,
std::ostream& os)
{
Expand All @@ -336,7 +336,7 @@ namespace libint2 {
taskmgr.current(complabel);

// initialize cparams
SafePtr<CompilationParameters> cparams(new CompilationParameters);
std::shared_ptr<CompilationParameters> cparams(new CompilationParameters);
cparams->max_am(complabel,max_am);
cparams->num_bf(complabel,4u);
cparams->max_vector_length(veclen);
Expand Down Expand Up @@ -379,26 +379,26 @@ namespace libint2 {
// set default dims
ImplicitDimensions::set_default_dims(cparams);

SafePtr<StdRandomizePolicy> rpolicy(new StdRandomizePolicy(0.00));
std::shared_ptr<StdRandomizePolicy> rpolicy(new StdRandomizePolicy(0.00));
// use 4-center OS if the target is a 4-center integral
SafePtr<Tactic> tactic;
std::shared_ptr<Tactic> tactic;
{
typedef GenIntegralSet_11_11<typename Integral::BasisFunctionType,
typename Integral::OperatorType,
typename Integral::AuxIndexType> genint_11_11_t;
SafePtr< genint_11_11_t > cast_ptr = dynamic_pointer_cast<genint_11_11_t>(targets.front());
std::shared_ptr< genint_11_11_t > cast_ptr = dynamic_pointer_cast<genint_11_11_t>(targets.front());
if (cast_ptr) {
const unsigned int la = cast_ptr->bra(0, 0).norm();
const unsigned int lb = cast_ptr->ket(0, 0).norm();
const unsigned int lc = cast_ptr->bra(1, 0).norm();
const unsigned int ld = cast_ptr->ket(1, 0).norm();
tactic = SafePtr<Tactic>(new FourCenter_OS_Tactic(la, lb, lc, ld));
tactic = std::shared_ptr<Tactic>(new FourCenter_OS_Tactic(la, lb, lc, ld));
}
else {
tactic = SafePtr<Tactic>(new FirstChoiceTactic<StdRandomizePolicy>(rpolicy));
tactic = std::shared_ptr<Tactic>(new FirstChoiceTactic<StdRandomizePolicy>(rpolicy));
}
}
const SafePtr<MemoryManager> memman(new WorstFitMemoryManager);
const std::shared_ptr<MemoryManager> memman(new WorstFitMemoryManager);
__BuildTest<Integral,true>(targets,cparams,size_to_unroll,os,tactic,memman,complabel);
}

Expand Down
16 changes: 8 additions & 8 deletions src/bin/libint/codeblock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
using namespace std;
using namespace libint2;

ForLoop::ForLoop(const SafePtr<CodeContext>& context, std::string& varname,
const SafePtr<Entity>& less_than, const SafePtr<Entity>& start_at) :
ForLoop::ForLoop(const std::shared_ptr<CodeContext>& context, std::string& varname,
const std::shared_ptr<Entity>& less_than, const std::shared_ptr<Entity>& start_at) :
CodeBlock(context), varname_(varname), less_than_(less_than), start_at_(start_at)
{
init_();
Expand All @@ -38,11 +38,11 @@ ForLoop::~ForLoop()
void
ForLoop::init_()
{
SafePtr<CodeContext> ctext = context();
SafePtr< CTimeEntity<int> > lt_cptr = dynamic_pointer_cast<CTimeEntity<int>,Entity>(less_than_);
SafePtr< CTimeEntity<int> > sa_cptr = dynamic_pointer_cast<CTimeEntity<int>,Entity>(start_at_);
SafePtr< RTimeEntity<EntityTypes::Int> > lt_rptr = dynamic_pointer_cast<RTimeEntity<EntityTypes::Int>,Entity>(less_than_);
SafePtr< RTimeEntity<EntityTypes::Int> > sa_rptr = dynamic_pointer_cast<RTimeEntity<EntityTypes::Int>,Entity>(start_at_);
std::shared_ptr<CodeContext> ctext = context();
std::shared_ptr< CTimeEntity<int> > lt_cptr = dynamic_pointer_cast<CTimeEntity<int>,Entity>(less_than_);
std::shared_ptr< CTimeEntity<int> > sa_cptr = dynamic_pointer_cast<CTimeEntity<int>,Entity>(start_at_);
std::shared_ptr< RTimeEntity<EntityTypes::Int> > lt_rptr = dynamic_pointer_cast<RTimeEntity<EntityTypes::Int>,Entity>(less_than_);
std::shared_ptr< RTimeEntity<EntityTypes::Int> > sa_rptr = dynamic_pointer_cast<RTimeEntity<EntityTypes::Int>,Entity>(start_at_);

if (lt_cptr != 0) {
ostringstream oss;
Expand Down Expand Up @@ -75,7 +75,7 @@ ForLoop::init_()
std::string
ForLoop::open()
{
SafePtr<CodeContext> ctext = context();
std::shared_ptr<CodeContext> ctext = context();
ostringstream oss;

if (dummy_loop_) {
Expand Down
Loading

0 comments on commit a858dfd

Please sign in to comment.