ALPSCore reference
mpi_map.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
12 #ifndef ALPS_UTILITIES_MPI_MAP_HPP_INCLUDED_b6555a13ab3b46c2a2b4a434a3484099
13 #define ALPS_UTILITIES_MPI_MAP_HPP_INCLUDED_b6555a13ab3b46c2a2b4a434a3484099
14 
15 #include <alps/utilities/mpi.hpp>
16 #include <map>
17 
18 namespace alps {
19  namespace mpi {
20 
22 
23  // FIXME: what is exception safety status?
24  // FIXME!: make a test
25  template <typename K, typename V>
26  inline void broadcast(const communicator& comm, std::map<K,V>& a_map, int root)
27  {
28  typedef std::map<K,V> map_type;
29  typedef typename map_type::value_type value_type;
30 
31  std::size_t root_sz=a_map.size();
32  broadcast(comm, root_sz, root);
33 
34  if (comm.rank()==root) {
35  for(value_type& pair: a_map) {
36  broadcast(comm, const_cast<K&>(pair.first), root);
37  broadcast(comm, pair.second, root);
38  }
39  } else {
40  map_type new_map;
41  while (root_sz--) {
42  std::pair<K,V> pair; // FIXME! this requires default ctor
43  broadcast(comm, pair.first, root);
44  broadcast(comm, pair.second, root);
45  new_map.insert(pair);
46  }
47  using std::swap;
48  swap(a_map, new_map);
49  }
50  }
51 
52  } // mpi::
53 } // alps::
54 
55 #endif /* ALPS_UTILITIES_MPI_MAP_HPP_INCLUDED_b6555a13ab3b46c2a2b4a434a3484099 */
void swap(params &p1, params &p2)
Header for object-oriented interface to MPI (similar to boost::mpi)
Encapsulation of an MPI communicator and some communicator-related operations.
Definition: mpi.hpp:111
int rank() const
Returns process rank in this communicator.
Definition: mpi.hpp:156
void broadcast(const communicator &comm, T *vals, std::size_t count, int root)
Broadcasts array vals of a primitive type T, length count on communicator comm with root root ...
Definition: mpi.hpp:270