Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:20

0001 // Copyright 2005 The Trustees of Indiana University.
0002 
0003 // Use, modification and distribution is subject to the Boost Software
0004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 //  Authors: Douglas Gregor
0008 //           Andrew Lumsdaine
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 // Implements the inplace all-to-all communication algorithm.
0019 //
0020 #include <vector>
0021 #include <iterator>
0022 
0023 namespace boost { namespace parallel { 
0024 
0025 template<typename ProcessGroup, typename T>
0026 // where {LinearProcessGroup<ProcessGroup>, MessagingProcessGroup<ProcessGroup>}
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   // Make sure there are no straggling messages
0040   synchronize(pg);
0041 
0042   // Send along the count (always) and the data (if count > 0)
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   // Make sure all of the data gets transferred
0052   synchronize(pg);
0053 
0054   // Receive the sizes and data
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 // where {LinearProcessGroup<ProcessGroup>, MessagingProcessGroup<ProcessGroup>}
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 } } // end namespace boost::parallel
0077 
0078 #endif // BOOST_GRAPH_PARALLEL_INPLACE_ALL_TO_ALL_HPP