Skip to content
Snippets Groups Projects
Commit 5aa04a09 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Fixed Memory Leak

Node and OperatorNode get virtual destructors
parent 90149bcb
Branches
No related tags found
No related merge requests found
Showing
with 152 additions and 162 deletions
#include <feature_creation/feature_space/FeatureSpace.hpp>
BOOST_CLASS_EXPORT(FeatureNode)
BOOST_CLASS_EXPORT(AddNode)
BOOST_CLASS_EXPORT(SubNode)
BOOST_CLASS_EXPORT(AbsDiffNode)
BOOST_CLASS_EXPORT(MultNode)
BOOST_CLASS_EXPORT(DivNode)
BOOST_CLASS_EXPORT(SqNode)
BOOST_CLASS_EXPORT(SqrtNode)
BOOST_CLASS_EXPORT(CbNode)
BOOST_CLASS_EXPORT(CbrtNode)
BOOST_CLASS_EXPORT(SixPowNode)
BOOST_CLASS_EXPORT(ExpNode)
BOOST_CLASS_EXPORT(NegExpNode)
BOOST_CLASS_EXPORT(LogNode)
BOOST_CLASS_EXPORT(AbsNode)
BOOST_CLASS_EXPORT(InvNode)
BOOST_CLASS_EXPORT(SinNode)
BOOST_CLASS_EXPORT(CosNode)
BOOST_CLASS_EXPORT_GUID(FeatureNode, "FeatureNode")
BOOST_CLASS_EXPORT_GUID(AddNode, "AddNode")
BOOST_CLASS_EXPORT_GUID(SubNode, "SubNode")
BOOST_CLASS_EXPORT_GUID(AbsDiffNode, "AbsDiffNode")
BOOST_CLASS_EXPORT_GUID(MultNode, "MultNode")
BOOST_CLASS_EXPORT_GUID(DivNode, "DivNode")
BOOST_CLASS_EXPORT_GUID(SqNode, "SqNode")
BOOST_CLASS_EXPORT_GUID(SqrtNode, "SqrtNode")
BOOST_CLASS_EXPORT_GUID(CbNode, "CbNode")
BOOST_CLASS_EXPORT_GUID(CbrtNode, "CbrtNode")
BOOST_CLASS_EXPORT_GUID(SixPowNode, "SixPowNode")
BOOST_CLASS_EXPORT_GUID(ExpNode, "ExpNode")
BOOST_CLASS_EXPORT_GUID(NegExpNode, "NegExpNode")
BOOST_CLASS_EXPORT_GUID(LogNode, "LogNode")
BOOST_CLASS_EXPORT_GUID(AbsNode, "AbsNode")
BOOST_CLASS_EXPORT_GUID(InvNode, "InvNode")
BOOST_CLASS_EXPORT_GUID(SinNode, "SinNode")
BOOST_CLASS_EXPORT_GUID(CosNode, "CosNode")
FeatureSpace::FeatureSpace(
std::shared_ptr<MPI_Interface> mpi_comm,
......@@ -140,6 +140,7 @@ void FeatureSpace::generate_feature_space()
++feat_ind;
}
}
if(nn <= _n_rung_store)
{
// bool use_temp = (nn != _max_phi) || (_max_phi > _n_rung_store);
......@@ -153,9 +154,11 @@ void FeatureSpace::generate_feature_space()
{
std::vector<size_t> next_phi_sizes;
mpi::all_gather(*_mpi_comm, next_phi.size(), next_phi_sizes);
size_t n_feat = std::accumulate(next_phi_sizes.begin(), next_phi_sizes.end(), _phi.size());
size_t n_feat_rank = n_feat / _mpi_comm->size();
size_t n_feat_below_rank = _mpi_comm->rank() * n_feat_rank;
if(_mpi_comm->rank() < n_feat % _mpi_comm->size())
{
++n_feat_rank;
......@@ -165,6 +168,7 @@ void FeatureSpace::generate_feature_space()
{
n_feat_below_rank += n_feat % _mpi_comm->size();
}
if(n_feat_below_rank + n_feat_rank <= _phi.size())
{
_phi.erase(_phi.begin(), _phi.begin() + n_feat_below_rank);
......@@ -178,12 +182,14 @@ void FeatureSpace::generate_feature_space()
{
_phi = {};
}
while((_phi.size() < n_feat_rank) && (next_phi.size() > 0))
{
next_phi.back()->reindex(_phi.size() + n_feat_below_rank);
_phi.push_back(next_phi.back());
next_phi.pop_back();
}
// This can be calculated without an all_gather, using it to not introduce too many things at one time
std::vector<size_t> next_phi_needed;
std::vector<size_t> next_phi_excess;
......@@ -229,7 +235,7 @@ void FeatureSpace::generate_feature_space()
}
else
{
size_t total_recv = std::accumulate(next_phi_excess.begin(), next_phi_excess.begin() + _mpi_comm->rank(), 0);
size_t total_recv = std::accumulate(next_phi_needed.begin(), next_phi_needed.begin() + _mpi_comm->rank(), 0);
size_t prev_recv_sent = 0;
size_t recv_size = 0;
int ind = 0;
......
......
......@@ -11,8 +11,7 @@ FeatureNode::FeatureNode(int feat_ind, std::string expr, std::vector<double> val
std::copy_n(value.data(), value.size(), value_ptr());
}
FeatureNode::FeatureNode(const FeatureNode &o) :
Node(o)
FeatureNode::~FeatureNode()
{}
void FeatureNode::update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, int pl_mn, int& expected_abs_tot)
......
......
......@@ -17,6 +17,19 @@ class FeatureNode: public Node
{
friend class boost::serialization::access;
/**
* @brief Serialization function to send over MPI
*
* @param ar Archive representation of node
*/
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<Node>(*this);
ar & _expr;
ar & _unit;
}
protected:
std::string _expr; //!< Expression of the feature
Unit _unit; //!< Unit for the feature
......@@ -37,12 +50,7 @@ public:
*/
FeatureNode(int feat_ind, std::string expr, std::vector<double> value, Unit unit);
/**
* @brief Copy constructor
*
* @param o Node to be copied
*/
FeatureNode(const FeatureNode &o);
~FeatureNode();
/**
* @brief Get the expression for the overall descriptor (From head node down)
......@@ -103,19 +111,6 @@ public:
* @param add_sub_leaves [description]
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
/**
* @brief Serialization function to send over MPI
*
* @param ar Archive representation of node
*/
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<Node>(*this);
ar & _expr;
ar & _unit;
}
};
#endif
......@@ -8,9 +8,7 @@ Node::Node(int feat_ind, int n_samp) :
_feat_ind(feat_ind)
{}
Node::Node(const Node &o) :
_n_samp(o._n_samp),
_feat_ind(o._feat_ind)
Node::~Node()
{}
BOOST_SERIALIZATION_ASSUME_ABSTRACT(Node)
......
......
......@@ -21,6 +21,20 @@
*/
class Node
{
friend class boost::serialization::access;
/**
* @brief Serialization function to send over MPI
*
* @param ar Archive representation of node
*/
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & _n_samp;
ar & _feat_ind;
}
protected:
int _n_samp; //!< Number of samples in the feature
int _feat_ind; //!< Index of the feature
......@@ -40,12 +54,7 @@ public:
*/
Node(int feat_ind, int n_samp);
/**
* @brief Copy constructor
*
* @param o Node to be copied
*/
Node(const Node &o);
virtual ~Node();
/**
* @brief Reindex the feature
......@@ -122,18 +131,6 @@ public:
* @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves
*/
virtual void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot) = 0;
/**
* @brief Serialization function to send over MPI
*
* @param ar Archive representation of node
*/
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & _n_samp;
ar & _feat_ind;
}
};
typedef std::shared_ptr<Node> node_ptr;
......
......
......@@ -6,16 +6,10 @@ OperatorNode::OperatorNode()
OperatorNode::OperatorNode(std::vector<node_ptr> feats, int rung, int feat_ind) :
Node(feat_ind, feats[0]->n_samp()),
_feats(feats)
{
_feats.reserve(_feats.size());
}
{}
OperatorNode::OperatorNode(const OperatorNode &o) :
Node(o),
_feats(o._feats)
{
_feats.reserve(_feats.size());
}
OperatorNode::~OperatorNode()
{}
double* OperatorNode::value_ptr(int offset)
{
......
......
......@@ -9,6 +9,7 @@
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/vector.hpp>
/**
......@@ -19,6 +20,13 @@
class OperatorNode: public Node
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<Node>(*this);
ar & _feats;
}
protected:
std::vector<node_ptr> _feats;
......@@ -38,11 +46,8 @@ public:
* @param feat_ind index of the feature
*/
OperatorNode(std::vector<node_ptr> feats, int rung, int feat_ind);
/**
* @brief Base Constructor
* @details This is only used for serialization
*/
OperatorNode(const OperatorNode &o);
virtual ~OperatorNode();
virtual std::string expr() = 0;
......@@ -50,13 +55,6 @@ public:
virtual void set_value(int offset = -1) = 0;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<Node>(*this);
ar & _feats;
}
/**
* @brief Get the pointer to the feature's data
* @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data
......
......
......@@ -5,6 +5,13 @@
class AbsDiffNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
AbsDiffNode();
......@@ -51,12 +58,6 @@ public:
* @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,7 +5,13 @@
class AbsNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
AbsNode();
......@@ -51,12 +57,6 @@ public:
* @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,7 +5,13 @@
class AddNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
AddNode();
......@@ -52,12 +58,6 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,7 +5,13 @@
class CosNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
CosNode();
......@@ -52,12 +58,6 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,7 +5,13 @@
class CbNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
CbNode();
......@@ -51,13 +57,6 @@ public:
* @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,7 +5,13 @@
class CbrtNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
CbrtNode();
......@@ -52,12 +58,6 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,7 +5,13 @@
class DivNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
DivNode();
......@@ -52,12 +58,6 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,7 +5,13 @@
class ExpNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
ExpNode();
......@@ -52,12 +58,6 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,6 +5,13 @@
class InvNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
InvNode();
......@@ -52,11 +59,5 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,7 +5,13 @@
class LogNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
LogNode();
......@@ -51,13 +57,6 @@ public:
* @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,6 +5,13 @@
class MultNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
MultNode();
......@@ -52,12 +59,6 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,6 +5,13 @@
class NegExpNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
NegExpNode();
......@@ -52,12 +59,6 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
......@@ -5,6 +5,13 @@
class SinNode: public OperatorNode
{
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
SinNode();
......@@ -52,12 +59,6 @@ public:
*/
void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, double fact, double& expected_abs_tot);
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
// ar.template register_type<OperatorNode>();
ar & boost::serialization::base_object<OperatorNode>(*this);
}
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment