File indexing completed on 2025-01-18 09:37:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_GRAPH_PARALLEL_INPLACE_ALL_TO_ALL_HPP
0011 #define BOOST_GRAPH_PARALLEL_INPLACE_ALL_TO_ALL_HPP
0012
0013 #ifndef BOOST_GRAPH_USE_MPI
0014 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
0015 #endif
0016
0017
0018
0019
0020 #include <vector>
0021 #include <iterator>
0022
0023 namespace boost { namespace parallel {
0024
0025 template<typename ProcessGroup, typename T>
0026
0027 void
0028 inplace_all_to_all(ProcessGroup pg,
0029 const std::vector<std::vector<T> >& outgoing,
0030 std::vector<std::vector<T> >& incoming)
0031 {
0032 typedef typename std::vector<T>::size_type size_type;
0033
0034 typedef typename ProcessGroup::process_size_type process_size_type;
0035 typedef typename ProcessGroup::process_id_type process_id_type;
0036
0037 process_size_type p = num_processes(pg);
0038
0039
0040 synchronize(pg);
0041
0042
0043 for (process_id_type dest = 0; dest < p; ++dest) {
0044 if (dest != process_id(pg)) {
0045 send(pg, dest, 0, outgoing[dest].size());
0046 if (!outgoing[dest].empty())
0047 send(pg, dest, 1, &outgoing[dest].front(), outgoing[dest].size());
0048 }
0049 }
0050
0051
0052 synchronize(pg);
0053
0054
0055 for (process_id_type source = 0; source < p; ++source) {
0056 if (source != process_id(pg)) {
0057 size_type size;
0058 receive(pg, source, 0, size);
0059 incoming[source].resize(size);
0060 if (size > 0)
0061 receive(pg, source, 1, &incoming[source].front(), size);
0062 } else if (&incoming != &outgoing) {
0063 incoming[source] = outgoing[source];
0064 }
0065 }
0066 }
0067
0068 template<typename ProcessGroup, typename T>
0069
0070 void
0071 inplace_all_to_all(ProcessGroup pg, std::vector<std::vector<T> >& data)
0072 {
0073 inplace_all_to_all(pg, data, data);
0074 }
0075
0076 } }
0077
0078 #endif