timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::basic_tree< Tp > Struct Template Reference

Basic hierarchical tree implementation. Expects population from tim::graph. More...

#include "timemory/storage/basic_tree.hpp"

+ Collaboration diagram for tim::basic_tree< Tp >:

Public Types

using this_type = basic_tree< Tp >
 
using value_type = Tp
 
using child_type = this_type
 
using child_pointer = std::shared_ptr< child_type >
 
using children_type = std::vector< child_pointer >
 
using children_base = std::vector< child_type >
 

Public Member Functions

template<typename GraphT , typename ItrT >
this_typeoperator() (const GraphT &g, ItrT root)
 construction from tim::graph<Tp> More...
 
this_typeoperator+= (const this_type &rhs)
 
this_typeoperator-= (const this_type &rhs)
 
template<typename Archive >
void save (Archive &ar, const unsigned int) const
 
template<typename Archive >
void load (Archive &ar, const unsigned int)
 
auto & get_value ()
 return the current tree node More...
 
auto & get_children ()
 return the array of child nodes More...
 
const auto & get_value () const
 
const auto & get_children () const
 
template<typename GraphT , typename ItrT >
basic_tree< Tp > & operator() (const GraphT &g, ItrT root)
 

Friends

bool operator== (const this_type &lhs, const this_type &rhs)
 
bool operator!= (const this_type &lhs, const this_type &rhs)
 

Detailed Description

template<typename Tp>
struct tim::basic_tree< Tp >

Basic hierarchical tree implementation. Expects population from tim::graph.

Template Parameters
TpComponent type

Definition at line 43 of file basic_tree.hpp.

Member Typedef Documentation

◆ child_pointer

template<typename Tp >
using tim::basic_tree< Tp >::child_pointer = std::shared_ptr<child_type>

Definition at line 48 of file basic_tree.hpp.

◆ child_type

template<typename Tp >
using tim::basic_tree< Tp >::child_type = this_type

Definition at line 47 of file basic_tree.hpp.

◆ children_base

template<typename Tp >
using tim::basic_tree< Tp >::children_base = std::vector<child_type>

Definition at line 50 of file basic_tree.hpp.

◆ children_type

template<typename Tp >
using tim::basic_tree< Tp >::children_type = std::vector<child_pointer>

Definition at line 49 of file basic_tree.hpp.

◆ this_type

template<typename Tp >
using tim::basic_tree< Tp >::this_type = basic_tree<Tp>

Definition at line 45 of file basic_tree.hpp.

◆ value_type

template<typename Tp >
using tim::basic_tree< Tp >::value_type = Tp

Definition at line 46 of file basic_tree.hpp.

Member Function Documentation

◆ get_children() [1/2]

template<typename Tp >
auto & tim::basic_tree< Tp >::get_children ( )
inline

return the array of child nodes

Definition at line 70 of file basic_tree.hpp.

70{ return m_children; }

Referenced by tim::operation::finalize::merge< Type, true >::operator()().

◆ get_children() [2/2]

template<typename Tp >
const auto & tim::basic_tree< Tp >::get_children ( ) const
inline

Definition at line 73 of file basic_tree.hpp.

73{ return m_children; }

◆ get_value() [1/2]

template<typename Tp >
auto & tim::basic_tree< Tp >::get_value ( )
inline

return the current tree node

Definition at line 68 of file basic_tree.hpp.

68{ return m_value; }

◆ get_value() [2/2]

template<typename Tp >
const auto & tim::basic_tree< Tp >::get_value ( ) const
inline

Definition at line 72 of file basic_tree.hpp.

72{ return m_value; }

◆ load()

template<typename Tp >
template<typename Archive >
void tim::basic_tree< Tp >::load ( Archive &  ar,
const unsigned int   
)

Definition at line 238 of file basic_tree.hpp.

239{
240 // this is for backward compatiblity
241 children_base _children{};
242 ar(cereal::make_nvp("node", m_value), cereal::make_nvp("children", _children));
243 for(auto&& itr : _children)
244 m_children.emplace_back(std::make_shared<child_type>(std::move(itr)));
245}
std::vector< child_type > children_base
Definition: basic_tree.hpp:50

◆ operator()() [1/2]

template<typename Tp >
template<typename GraphT , typename ItrT >
this_type & tim::basic_tree< Tp >::operator() ( const GraphT &  g,
ItrT  root 
)

construction from tim::graph<Tp>

◆ operator()() [2/2]

template<typename Tp >
template<typename GraphT , typename ItrT >
basic_tree< Tp > & tim::basic_tree< Tp >::operator() ( const GraphT &  g,
ItrT  root 
)

Definition at line 95 of file basic_tree.hpp.

96{
97 using iterator_t = typename GraphT::sibling_iterator;
98 using entry_type = std::decay_t<decltype(std::declval<ItrT>()->data())>;
99
100 m_value = *root;
101 iterator_t _begin = g.begin(root);
102 iterator_t _end = g.end(root);
103 auto nchildren = std::distance(_begin, _end);
104 if(nchildren > 0)
105 {
106 m_children.reserve(nchildren);
107 for(auto itr = _begin; itr != _end; ++itr)
108 {
109 if(!itr->is_dummy() &&
110 !operation::get_is_invalid<entry_type, false>{}(itr->data()))
111 {
112 m_value.exclusive().data() -= itr->data();
113 m_value.exclusive().stats() -= itr->stats();
114 m_children.emplace_back(std::make_shared<child_type>());
115 m_children.back()->operator()(g, itr);
116 }
117 else
118 {
119 iterator_t _dbegin = g.begin(itr);
120 iterator_t _dend = g.end(itr);
121 for(auto ditr = _dbegin; ditr != _dend; ++ditr)
122 {
123 if(!ditr->is_dummy())
124 {
125 m_children.emplace_back(std::make_shared<child_type>());
126 m_children.back()->operator()(g, ditr);
127 }
128 }
129 }
130 }
131 }
132 return *this;
133}

◆ operator+=()

template<typename Tp >
basic_tree< Tp > & tim::basic_tree< Tp >::operator+= ( const this_type rhs)

Definition at line 137 of file basic_tree.hpp.

138{
139 if(*this == rhs)
140 {
141 m_value += rhs.m_value;
142 }
143 if(false)
144 {
145 for(auto& ritr : rhs.m_children)
146 m_children.insert(m_children.end(), ritr);
147 }
148 else
149 {
150 std::set<size_t> found{};
151 auto nitr = std::min<size_t>(m_children.size(), rhs.m_children.size());
152 // add identical entries
153 for(size_t i = 0; i < nitr; ++i)
154 {
155 if((*m_children.at(i)) == (*rhs.m_children.at(i)))
156 {
157 found.insert(i);
158 (*m_children.at(i)) += (*rhs.m_children.at(i));
159 }
160 }
161 // add to first matching entry
162 for(size_t i = 0; i < rhs.m_children.size(); ++i)
163 {
164 if(found.find(i) != found.end())
165 continue;
166 for(size_t j = 0; j < m_children.size(); ++j)
167 {
168 if((*m_children.at(j)) == (*rhs.m_children.at(i)))
169 {
170 found.insert(i);
171 (*m_children.at(j)) += (*rhs.m_children.at(i));
172 }
173 }
174 }
175 // append to end if not found anywhere
176 for(size_t i = 0; i < rhs.m_children.size(); ++i)
177 {
178 if(found.find(i) != found.end())
179 continue;
180 m_children.insert(m_children.end(), rhs.m_children.at(i));
181 }
182 }
183 return *this;
184}

◆ operator-=()

template<typename Tp >
basic_tree< Tp > & tim::basic_tree< Tp >::operator-= ( const this_type rhs)

Definition at line 188 of file basic_tree.hpp.

189{
190 if(*this == rhs)
191 {
192 m_value -= rhs.m_value;
193 }
194
195 std::set<size_t> found{};
196 auto nitr = std::min<size_t>(m_children.size(), rhs.m_children.size());
197 // add identical entries
198 for(size_t i = 0; i < nitr; ++i)
199 {
200 if((*m_children.at(i)) == (*rhs.m_children.at(i)))
201 {
202 found.insert(i);
203 m_children.at(i) -= rhs.m_children.at(i);
204 }
205 }
206 // add to first matching entry
207 for(size_t i = 0; i < rhs.m_children.size(); ++i)
208 {
209 if(found.find(i) != found.end())
210 continue;
211 for(size_t j = 0; j < m_children.size(); ++j)
212 {
213 if((*m_children.at(j)) == (*rhs.m_children.at(i)))
214 {
215 found.insert(i);
216 m_children.at(j) -= rhs.m_children.at(i);
217 }
218 }
219 }
220 return *this;
221}

◆ save()

template<typename Tp >
template<typename Archive >
void tim::basic_tree< Tp >::save ( Archive &  ar,
const unsigned int   
) const

Definition at line 226 of file basic_tree.hpp.

227{
228 // this is for backward compatiblity
229 children_base _children{};
230 for(const auto& itr : m_children)
231 _children.emplace_back(*itr);
232 ar(cereal::make_nvp("node", m_value), cereal::make_nvp("children", _children));
233}

Friends And Related Function Documentation

◆ operator!=

template<typename Tp >
bool operator!= ( const this_type lhs,
const this_type rhs 
)
friend

Definition at line 82 of file basic_tree.hpp.

83 {
84 return !(lhs == rhs);
85 }

◆ operator==

template<typename Tp >
bool operator== ( const this_type lhs,
const this_type rhs 
)
friend

Definition at line 75 of file basic_tree.hpp.

76 {
77 // auto _lhash = get_hash_id(get_hash_aliases(), lhs.m_value.hash());
78 // auto _rhash = get_hash_id(get_hash_aliases(), rhs.m_value.hash());
79 return (lhs.m_value.hash() == rhs.m_value.hash());
80 }

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