123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef BOOST_GRAPH_PARALLEL_INPLACE_ALL_TO_ALL_HPP
- #define BOOST_GRAPH_PARALLEL_INPLACE_ALL_TO_ALL_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 <vector>
- #include <iterator>
- namespace boost { namespace parallel {
- template<typename ProcessGroup, typename T>
- void
- inplace_all_to_all(ProcessGroup pg,
- const std::vector<std::vector<T> >& outgoing,
- std::vector<std::vector<T> >& incoming)
- {
- typedef typename std::vector<T>::size_type size_type;
- typedef typename ProcessGroup::process_size_type process_size_type;
- typedef typename ProcessGroup::process_id_type process_id_type;
- process_size_type p = num_processes(pg);
-
- synchronize(pg);
-
- for (process_id_type dest = 0; dest < p; ++dest) {
- if (dest != process_id(pg)) {
- send(pg, dest, 0, outgoing[dest].size());
- if (!outgoing[dest].empty())
- send(pg, dest, 1, &outgoing[dest].front(), outgoing[dest].size());
- }
- }
-
- synchronize(pg);
-
- for (process_id_type source = 0; source < p; ++source) {
- if (source != process_id(pg)) {
- size_type size;
- receive(pg, source, 0, size);
- incoming[source].resize(size);
- if (size > 0)
- receive(pg, source, 1, &incoming[source].front(), size);
- } else if (&incoming != &outgoing) {
- incoming[source] = outgoing[source];
- }
- }
- }
- template<typename ProcessGroup, typename T>
- void
- inplace_all_to_all(ProcessGroup pg, std::vector<std::vector<T> >& data)
- {
- inplace_all_to_all(pg, data, data);
- }
- } }
- #endif
|