distributed_csr_test.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright (C) 2006 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Douglas Gregor
  6. // Andrew Lumsdaine
  7. // A test of the distributed compressed sparse row graph type
  8. #include <boost/graph/use_mpi.hpp>
  9. #include <boost/config.hpp>
  10. #include <boost/throw_exception.hpp>
  11. #include <boost/serialization/vector.hpp>
  12. #include <boost/graph/distributed/compressed_sparse_row_graph.hpp>
  13. #include <boost/graph/distributed/mpi_process_group.hpp>
  14. #include <boost/graph/distributed/concepts.hpp>
  15. #include <boost/graph/erdos_renyi_generator.hpp>
  16. #include <boost/random/linear_congruential.hpp>
  17. #include <boost/graph/breadth_first_search.hpp>
  18. #include <boost/graph/graphviz.hpp>
  19. #include <boost/property_map/vector_property_map.hpp>
  20. #include <boost/test/minimal.hpp>
  21. #ifdef BOOST_NO_EXCEPTIONS
  22. void
  23. boost::throw_exception(std::exception const& ex)
  24. {
  25. std::cout << ex.what() << std::endl;
  26. abort();
  27. }
  28. #endif
  29. using namespace boost;
  30. using boost::graph::distributed::mpi_process_group;
  31. void concept_checks()
  32. {
  33. typedef compressed_sparse_row_graph<directedS, no_property, no_property, no_property,
  34. distributedS<mpi_process_group> >
  35. Digraph;
  36. typedef graph_traits<Digraph>::vertex_descriptor vertex_descriptor;
  37. typedef graph_traits<Digraph>::edge_descriptor edge_descriptor;
  38. function_requires< GraphConcept<Digraph> >();
  39. function_requires< IncidenceGraphConcept<Digraph> >();
  40. function_requires< AdjacencyGraphConcept<Digraph> >();
  41. function_requires< DistributedVertexListGraphConcept<Digraph> >();
  42. function_requires< DistributedEdgeListGraphConcept<Digraph> >();
  43. function_requires<
  44. ReadablePropertyGraphConcept<Digraph, vertex_descriptor, vertex_global_t>
  45. >();
  46. function_requires<
  47. ReadablePropertyGraphConcept<Digraph, vertex_descriptor, vertex_owner_t>
  48. >();
  49. function_requires<
  50. ReadablePropertyGraphConcept<Digraph, vertex_descriptor, vertex_local_t>
  51. >();
  52. function_requires<
  53. ReadablePropertyGraphConcept<Digraph, vertex_descriptor, vertex_index_t>
  54. >();
  55. function_requires<
  56. ReadablePropertyGraphConcept<Digraph, edge_descriptor, edge_global_t>
  57. >();
  58. // DPG TBD: edge_owner, edge_local property maps
  59. function_requires<
  60. ReadablePropertyGraphConcept<Digraph, edge_descriptor, edge_index_t>
  61. >();
  62. // Check default construction
  63. Digraph g;
  64. }
  65. int test_main(int argc, char* argv[])
  66. {
  67. mpi::environment env(argc, argv);
  68. concept_checks();
  69. typedef compressed_sparse_row_graph<directedS, no_property, no_property, no_property,
  70. distributedS<mpi_process_group> >
  71. Digraph;
  72. // Build an Erdos-Renyi graph to test with
  73. typedef sorted_erdos_renyi_iterator<minstd_rand, Digraph> ERIter;
  74. int n = 40;
  75. double prob = 0.1;
  76. minstd_rand gen;
  77. Digraph g(ERIter(gen, n, prob), ERIter(), n);
  78. breadth_first_search(g, vertex(0, g), visitor(bfs_visitor<>()));
  79. std::ofstream out("dcsr.dot");
  80. write_graphviz(out, g);
  81. return 0;
  82. }