handlers.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Copyright (C) 2007 Douglas Gregor
  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. // This file contains code for the distributed adjacency list's
  6. // message handlers. It should not be included directly by users.
  7. #ifndef BOOST_GRAPH_DISTRIBUTED_ADJLIST_HANDLERS_HPP
  8. #define BOOST_GRAPH_DISTRIBUTED_ADJLIST_HANDLERS_HPP
  9. #ifndef BOOST_GRAPH_USE_MPI
  10. #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
  11. #endif
  12. #include <boost/graph/parallel/simple_trigger.hpp>
  13. #include <boost/graph/parallel/detail/untracked_pair.hpp>
  14. namespace boost {
  15. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  16. void
  17. PBGL_DISTRIB_ADJLIST_TYPE::
  18. setup_triggers()
  19. {
  20. using boost::graph::parallel::simple_trigger;
  21. simple_trigger(process_group_, msg_add_vertex_with_property, this,
  22. &adjacency_list::handle_add_vertex_with_property);
  23. simple_trigger(process_group_, msg_add_vertex_with_property_and_reply, this,
  24. &adjacency_list::handle_add_vertex_with_property_and_reply);
  25. simple_trigger(process_group_, msg_add_edge, this,
  26. &adjacency_list::handle_add_edge);
  27. simple_trigger(process_group_, msg_add_edge_with_reply, this,
  28. &adjacency_list::handle_add_edge_with_reply);
  29. simple_trigger(process_group_, msg_add_edge_with_property, this,
  30. &adjacency_list::handle_add_edge_with_property);
  31. simple_trigger(process_group_, msg_add_edge_with_property_and_reply, this,
  32. &adjacency_list::handle_add_edge_with_property_and_reply);
  33. simple_trigger(process_group_, msg_nonlocal_edge, this,
  34. &adjacency_list::handle_nonlocal_edge);
  35. simple_trigger(process_group_, msg_remove_edge, this,
  36. &adjacency_list::handle_remove_edge);
  37. }
  38. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  39. void
  40. PBGL_DISTRIB_ADJLIST_TYPE::
  41. handle_add_vertex_with_property(int source, int tag,
  42. const vertex_property_type& data,
  43. trigger_receive_context)
  44. {
  45. vertex_descriptor v(this->processor(),
  46. add_vertex(this->build_vertex_property(data),
  47. this->base()));
  48. if (on_add_vertex)
  49. on_add_vertex(v, *this);
  50. }
  51. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  52. typename PBGL_DISTRIB_ADJLIST_TYPE::local_vertex_descriptor
  53. PBGL_DISTRIB_ADJLIST_TYPE::
  54. handle_add_vertex_with_property_and_reply(int source, int tag,
  55. const vertex_property_type& data,
  56. trigger_receive_context)
  57. {
  58. // Try to find a vertex with this name
  59. local_vertex_descriptor local_v
  60. = add_vertex(this->build_vertex_property(data), this->base());
  61. vertex_descriptor v(processor(), local_v);
  62. if (on_add_vertex)
  63. on_add_vertex(v, *this);
  64. return local_v;
  65. }
  66. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  67. void
  68. PBGL_DISTRIB_ADJLIST_TYPE::
  69. handle_add_edge(int source, int tag, const msg_add_edge_data& data,
  70. trigger_receive_context)
  71. {
  72. add_edge(vertex_descriptor(processor(), data.source),
  73. data.target, *this);
  74. }
  75. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  76. boost::parallel::detail::untracked_pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool>
  77. PBGL_DISTRIB_ADJLIST_TYPE::
  78. handle_add_edge_with_reply(int source, int tag, const msg_add_edge_data& data,
  79. trigger_receive_context)
  80. {
  81. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool> p =
  82. add_edge(vertex_descriptor(processor(), data.source),data.target, *this);
  83. return p;
  84. }
  85. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  86. void
  87. PBGL_DISTRIB_ADJLIST_TYPE::
  88. handle_add_edge_with_property(int source, int tag,
  89. const msg_add_edge_with_property_data& data,
  90. trigger_receive_context)
  91. {
  92. add_edge(vertex_descriptor(processor(), data.source),
  93. data.target, data.get_property(), *this);
  94. }
  95. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  96. boost::parallel::detail::untracked_pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool>
  97. PBGL_DISTRIB_ADJLIST_TYPE::
  98. handle_add_edge_with_property_and_reply
  99. (int source, int tag,
  100. const msg_add_edge_with_property_data& data,
  101. trigger_receive_context)
  102. {
  103. std::pair<typename PBGL_DISTRIB_ADJLIST_TYPE::edge_descriptor, bool> p =
  104. add_edge(vertex_descriptor(processor(), data.source),
  105. data.target, data.get_property(), *this);
  106. return p;
  107. }
  108. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  109. void
  110. PBGL_DISTRIB_ADJLIST_TYPE::
  111. handle_nonlocal_edge(int source, int tag,
  112. const msg_nonlocal_edge_data& data,
  113. trigger_receive_context)
  114. {
  115. add_remote_edge(data, source, directed_selector());
  116. }
  117. template<PBGL_DISTRIB_ADJLIST_TEMPLATE_PARMS>
  118. void
  119. PBGL_DISTRIB_ADJLIST_TYPE::
  120. handle_remove_edge(int source, int tag,
  121. const msg_remove_edge_data& data,
  122. trigger_receive_context)
  123. {
  124. remove_local_edge(data, source, directed_selector());
  125. }
  126. }
  127. #endif // BOOST_GRAPH_DISTRIBUTED_ADJLIST_HANDLERS_HPP