123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- #ifndef BOOST_GRAPH_DISTRIBUTED_QUEUE_HPP
- #define BOOST_GRAPH_DISTRIBUTED_QUEUE_HPP
- #ifndef BOOST_GRAPH_USE_MPI
- #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
- #endif
- #include <boost/graph/parallel/process_group.hpp>
- #include <boost/optional.hpp>
- #include <boost/shared_ptr.hpp>
- #include <vector>
- namespace boost { namespace graph { namespace distributed {
- struct always_push
- {
- template<typename T> bool operator()(const T&) const { return true; }
- };
- template<typename ProcessGroup, typename OwnerMap, typename Buffer,
- typename UnaryPredicate = always_push>
- class distributed_queue
- {
- typedef distributed_queue self_type;
- enum {
-
- msg_push,
-
- msg_multipush
- };
- public:
- typedef ProcessGroup process_group_type;
- typedef Buffer buffer_type;
- typedef typename buffer_type::value_type value_type;
- typedef typename buffer_type::size_type size_type;
-
- explicit
- distributed_queue(const ProcessGroup& process_group,
- const OwnerMap& owner,
- const Buffer& buffer,
- bool polling = false);
-
- explicit
- distributed_queue(const ProcessGroup& process_group = ProcessGroup(),
- const OwnerMap& owner = OwnerMap(),
- const Buffer& buffer = Buffer(),
- const UnaryPredicate& pred = UnaryPredicate(),
- bool polling = false);
-
- distributed_queue(const ProcessGroup& process_group, const OwnerMap& owner,
- const UnaryPredicate& pred, bool polling = false);
-
- virtual ~distributed_queue() {}
-
- void push(const value_type& x);
-
- void pop() { buffer.pop(); }
-
- value_type& top() { return buffer.top(); }
-
- const value_type& top() const { return buffer.top(); }
-
- bool empty() const;
-
- size_type size() const;
-
-
- virtual bool do_synchronize() const;
- private:
-
- void setup_triggers();
-
- void
- handle_push(int source, int tag, const value_type& value,
- trigger_receive_context);
- void
- handle_multipush(int source, int tag, const std::vector<value_type>& values,
- trigger_receive_context);
- mutable ProcessGroup process_group;
- OwnerMap owner;
- mutable Buffer buffer;
- UnaryPredicate pred;
- bool polling;
- typedef std::vector<value_type> outgoing_buffer_t;
- typedef std::vector<outgoing_buffer_t> outgoing_buffers_t;
- shared_ptr<outgoing_buffers_t> outgoing_buffers;
- };
- #define BOOST_DISTRIBUTED_QUEUE_PARMS \
- typename ProcessGroup, typename OwnerMap, typename Buffer, \
- typename UnaryPredicate
- #define BOOST_DISTRIBUTED_QUEUE_TYPE \
- distributed_queue<ProcessGroup, OwnerMap, Buffer, UnaryPredicate>
- template<BOOST_DISTRIBUTED_QUEUE_PARMS>
- inline void
- synchronize(const BOOST_DISTRIBUTED_QUEUE_TYPE& Q)
- { Q.do_synchronize(); }
- template<typename ProcessGroup, typename OwnerMap, typename Buffer>
- inline distributed_queue<ProcessGroup, OwnerMap, Buffer>
- make_distributed_queue(const ProcessGroup& process_group,
- const OwnerMap& owner,
- const Buffer& buffer,
- bool polling = false)
- {
- typedef distributed_queue<ProcessGroup, OwnerMap, Buffer> result_type;
- return result_type(process_group, owner, buffer, polling);
- }
- } } }
- #include <boost/graph/distributed/detail/queue.ipp>
- #undef BOOST_DISTRIBUTED_QUEUE_TYPE
- #undef BOOST_DISTRIBUTED_QUEUE_PARMS
- #endif
|