cartesian_communicator.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright Alain Miniussi 2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Alain Miniussi
  6. #include <vector>
  7. #include <iostream>
  8. #include <boost/mpi/communicator.hpp>
  9. #include <boost/mpi/collectives.hpp>
  10. #include <boost/mpi/environment.hpp>
  11. #include <boost/mpi/cartesian_communicator.hpp>
  12. namespace mpi = boost::mpi;
  13. // Curly brace init make this useless, but
  14. // - Need to support obsolete like g++ 4.3.x. for some reason
  15. // - Can't conditionnaly compile with bjam (unless you find
  16. // the doc, and read it, which would only make sense if you
  17. // actually wan't to use bjam, which does not (make sense))
  18. typedef mpi::cartesian_dimension cd;
  19. int main(int argc, char* argv[])
  20. {
  21. mpi::environment env;
  22. mpi::communicator world;
  23. if (world.size() != 24) return -1;
  24. mpi::cartesian_dimension dims[] = {cd(2, true), cd(3,true), cd(4,true)};
  25. mpi::cartesian_communicator cart(world, mpi::cartesian_topology(dims));
  26. for (int r = 0; r < cart.size(); ++r) {
  27. cart.barrier();
  28. if (r == cart.rank()) {
  29. std::vector<int> c = cart.coordinates(r);
  30. std::cout << "rk :" << r << " coords: "
  31. << c[0] << ' ' << c[1] << ' ' << c[2] << '\n';
  32. }
  33. }
  34. return 0;
  35. }