Skip to content

Commit

Permalink
Print the number of nodes and edges.
Browse files Browse the repository at this point in the history
* include/qdft/manager.hh,
* include/qdft/manager.hxx: Provide get_graph_size method.

* include/qdft/qdft.hh,
* include/qdft/qdft.hxx: Provide get_graphs_size method.

* src/test_lib.cc: Print total number of nodes and edges in addition to
  memory footprint.
  • Loading branch information
joudinet committed Jan 9, 2014
1 parent 57253ab commit 56d0944
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 26 deletions.
20 changes: 8 additions & 12 deletions include/qdft/manager.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2011, 2012 Johan Oudinet <[email protected]>
// Copyright (C) 2011, 2012, 2013, 2014 Johan Oudinet <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -44,6 +44,8 @@ namespace qdft {
typedef typename Traits::edge_descriptor edge_descriptor;
typedef typename Traits::in_edge_iterator in_edge_iterator;
typedef typename Traits::out_edge_iterator out_edge_iterator;
typedef typename Traits::vertices_size_type vertices_size_type;
typedef typename Traits::edges_size_type edges_size_type;
typedef boost::unordered_map<cname_type, vertex_descriptor> c2v_type;

/**
Expand Down Expand Up @@ -98,17 +100,6 @@ namespace qdft {
void
truncate (const cname_type& c, const quantity_type& n);

// /**
// * Remove q amount of data from c
// * q might be greater than the amount of data
// * if c does not exist just do nothing
// *
// * @param q amount of data to remove
// * @param c container's name
// */
// void
// remove (const quantity_type& q, const cname_type& c);

/**
* Set the transfered edge value to a specific quantity. This is
* usefull to revert a previous transfer.
Expand Down Expand Up @@ -153,6 +144,11 @@ namespace qdft {
*/
void show_graph (std::ostream& out = std::cout) const;

/**
* Get the number of nodes and edges in the graph
*/
std::pair<vertices_size_type, edges_size_type> get_graph_size () const;

private:
mutable Graph g_;
c2v_type c2v_; // Mapping from container's name to vertex descriptor
Expand Down
8 changes: 8 additions & 0 deletions include/qdft/manager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ namespace qdft {
write_graphviz_dp(out, g_, dp);
}

template <class Graph>
std::pair<typename data_manager<Graph>::vertices_size_type,
typename data_manager<Graph>::edges_size_type>
data_manager<Graph>::get_graph_size () const
{
return std::make_pair (num_vertices (g_), num_edges (g_));
}

// Remove vertex u from the internal graph
template <class Graph>
void data_manager<Graph>::remove_vertex_ (vertex_descriptor u)
Expand Down
22 changes: 9 additions & 13 deletions include/qdft/qdft.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2011, 2012 Johan Oudinet <[email protected]>
// Copyright (C) 2011, 2012, 2014 Johan Oudinet <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -43,6 +43,9 @@ namespace qdft {
public:
typedef boost::unordered_map<
dname_type, data_manager_ptr> data_managers_t;
typedef boost::graph_traits<Graph> Traits;
typedef typename Traits::vertices_size_type vertices_size_type;
typedef typename Traits::edges_size_type edges_size_type;

/**
* Create a new data of size q (and set mode m for further updates)
Expand Down Expand Up @@ -105,18 +108,6 @@ namespace qdft {
void
truncate (const dname_type& d, const cname_type& c, const quantity_type& n);

// /**
// * Remove q amount of data d from c
// * q might be greater than the amount of data
// * if c does not exist just do nothing
// *
// * @param d the data name
// * @param q amount of data to remove
// * @param c container's name
// */
// void
// remove (const dname_type& d, const quantity_type& q, const cname_type& c);

/**
* Set the transfered edge value to a specific quantity. This is
* usefull to revert a previous transfer.
Expand Down Expand Up @@ -175,6 +166,11 @@ namespace qdft {
*/
void save (const std::string& fname) const;

/**
* Get the total number of nodes and edges for all graphs
*/
std::pair<vertices_size_type, edges_size_type> get_graphs_size () const;

private:
data_managers_t dm_;
};
Expand Down
18 changes: 17 additions & 1 deletion include/qdft/qdft.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2011, 2012 Johan Oudinet <[email protected]>
// Copyright (C) 2011, 2012, 2014 Johan Oudinet <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -208,6 +208,22 @@ namespace qdft {
fs.close ();
}

template <class Graph>
std::pair<typename data_managers<Graph>::vertices_size_type,
typename data_managers<Graph>::edges_size_type>
data_managers<Graph>::get_graphs_size () const
{
vertices_size_type n = 0;
edges_size_type m = 0;
BOOST_FOREACH(typename data_managers_t::value_type i, dm_) {
std::pair<vertices_size_type, edges_size_type> p =
i.second->get_graph_size ();
n += p.first;
m += p.second;
}
return std::make_pair (n, m);
}

} // end namespace qdft

#endif // ! QDFT_QDFT_HXX
7 changes: 7 additions & 0 deletions src/test_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ unsigned long proc_mem_usage (int pid = getpid())
using namespace boost::posix_time;

typedef qdft::data_managers<> data_managers_t;
typedef data_managers_t::vertices_size_type vertices_size_type;
typedef data_managers_t::edges_size_type edges_size_type;

int overwrite=0;
std::ofstream ftime;
Expand Down Expand Up @@ -200,6 +202,11 @@ int main(int argc, char* argv[]) {
if (argc>9) ftime.close ();
dmanagers.show_graphs ();
if (argc>10) {
vertices_size_type n;
edges_size_type m;
boost::tie(n, m) = dmanagers.get_graphs_size ();
fmem << "GraphNodes: " << n << std::endl;
fmem << "GraphEdges: " << m << std::endl;
fmem << "Mem: " << proc_mem_usage () << " MiB" << std::endl;
fmem.close ();
}
Expand Down

0 comments on commit 56d0944

Please sign in to comment.