~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to dolfin/graph/BoostGraphInterface.cpp

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include <boost/foreach.hpp>
27
27
#include <boost/graph/adjacency_list.hpp>
 
28
#include <boost/graph/compressed_sparse_row_graph.hpp>
28
29
 
29
30
#include <dolfin/common/Array.h>
30
31
#include "dolfin/common/Timer.h"
35
36
using namespace dolfin;
36
37
 
37
38
//-----------------------------------------------------------------------------
38
 
dolfin::uint BoostGraphInterface::compute_local_vertex_coloring(const Graph& graph,
39
 
                                                        std::vector<uint>& colors)
 
39
std::size_t BoostGraphInterface::compute_local_vertex_coloring(const Graph& graph,
 
40
                                                 std::vector<std::size_t>& colors)
40
41
{
41
 
  // Number of vertices in graph
42
 
  const uint num_vertices = graph.size();
43
 
  dolfin_assert(num_vertices == colors.size());
44
 
 
45
 
  // Copy Graph data structure into a BoostGraph
46
 
  BoostBidirectionalGraph g(num_vertices);
47
 
  for (uint i = 0; i < graph.size(); ++i)
48
 
  {
49
 
    BOOST_FOREACH(boost::unordered_set<uint>::value_type edge, graph[i])
50
 
    {
51
 
      const uint e = edge;
52
 
      boost::add_edge(i, e, g);
53
 
    }
54
 
  }
 
42
  // Number of vertices
 
43
  const std::size_t n = graph.size();
 
44
  dolfin_assert(n == colors.size());
 
45
 
 
46
  // Typedef for Boost compressed sparse row graph
 
47
  typedef boost::compressed_sparse_row_graph<boost::directedS> BoostGraph;
 
48
 
 
49
  // Count number of edges
 
50
  Graph::const_iterator vertex;
 
51
  std::size_t num_edges = 0;
 
52
  for (vertex = graph.begin(); vertex != graph.end(); ++vertex)
 
53
    num_edges += vertex->size();
 
54
 
 
55
  // Build list of graph edges
 
56
  std::vector<std::pair<std::size_t, std::size_t> > edges;
 
57
  edges.reserve(num_edges);
 
58
  graph_set_type::const_iterator edge;
 
59
  for (vertex = graph.begin(); vertex != graph.end(); ++vertex)
 
60
    for (edge = vertex->begin(); edge != vertex->end(); ++edge)
 
61
      edges.push_back(std::make_pair(vertex - graph.begin(), *edge));
 
62
 
 
63
  // Build Boost graph
 
64
  BoostGraph g(boost::edges_are_unsorted_multi_pass,
 
65
               edges.begin(), edges.end(), n);
55
66
 
56
67
  // Perform coloring
57
68
  return compute_local_vertex_coloring(g, colors);