From 911209c554f88810cf31eaea9c21f64c5d8f210c Mon Sep 17 00:00:00 2001 From: Alain Miniussi Date: Fri, 10 Oct 2014 16:38:44 +0200 Subject: [PATCH] checkpointing before transfert --- include/boost/mpi/cartesian_communicator.hpp | 7 ++++- src/cartesian_communicator.cpp | 22 ++++++++++++-- src/communicator.cpp | 1 + test/cartesian_topology_test.cpp | 30 ++++++++++++++------ 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/include/boost/mpi/cartesian_communicator.hpp b/include/boost/mpi/cartesian_communicator.hpp index 0535073..2b9d623 100644 --- a/include/boost/mpi/cartesian_communicator.hpp +++ b/include/boost/mpi/cartesian_communicator.hpp @@ -244,10 +244,15 @@ public: */ std::vector coords(int rk) const; /** - * Retrieve the topology. + * Retrieve the topology and coordinates of this process in the grid. * */ void topology( cartesian_topology& dims, std::vector& coords ) const; + /** + * Retrieve the topology of the grid. + * + */ + cartesian_topology topology() const; }; /** diff --git a/src/cartesian_communicator.cpp b/src/cartesian_communicator.cpp index afb6541..147b41a 100644 --- a/src/cartesian_communicator.cpp +++ b/src/cartesian_communicator.cpp @@ -41,7 +41,7 @@ operator<<(std::ostream& out, cartesian_topology const& topo) { cartesian_communicator::cartesian_communicator(const communicator& comm, const cartesian_topology& topology, bool reorder ) - : communicator() + : communicator(MPI_COMM_NULL, comm_attach) { std::vector dims(topology.size()); std::vector periodic(topology.size()); @@ -66,7 +66,7 @@ cartesian_communicator::cartesian_communicator(const communicator& comm, cartesian_communicator::cartesian_communicator(const cartesian_communicator& comm, const std::vector& keep ) - : communicator() + : communicator(MPI_COMM_NULL, comm_attach) { int const max_dims = comm.ndims(); int const nbkept = keep.size(); @@ -142,6 +142,13 @@ cartesian_communicator::topology( cartesian_topology& topo, topo.swap(res); } +cartesian_topology +cartesian_communicator::topology() const { + cartesian_topology topo(ndims()); + std::vector coords; + topology(topo, coords); + return topo; +} void cartesian_topology::split(std::vector& dims, std::vector& periodics) const { int ndims = size(); @@ -156,8 +163,17 @@ cartesian_topology::split(std::vector& dims, std::vector& periodics) std::vector& cartesian_dimensions(int sz, std::vector& dims) { + int min = 1; + int const dimsz = dims.size(); + for(int i = 0; i < dimsz; ++i) { + if (dims[i] > 0) { + min *= dims[i]; + } + } + int leftover = sz % min; + BOOST_MPI_CHECK_RESULT(MPI_Dims_create, - (sz, dims.size(), dims.data())); + (sz-leftover, dims.size(), dims.data())); return dims; } diff --git a/src/communicator.cpp b/src/communicator.cpp index e703949..a172edd 100644 --- a/src/communicator.cpp +++ b/src/communicator.cpp @@ -206,6 +206,7 @@ optional communicator::as_cartesian_communicator() const void communicator::abort(int errcode) const { BOOST_MPI_CHECK_RESULT(MPI_Abort, (MPI_Comm(*this), errcode)); + std::abort(); } /************************************************************* diff --git a/test/cartesian_topology_test.cpp b/test/cartesian_topology_test.cpp index 61cfea8..893c9a1 100644 --- a/test/cartesian_topology_test.cpp +++ b/test/cartesian_topology_test.cpp @@ -74,8 +74,10 @@ void test_shifted_coords( mpi::cartesian_communicator const& cc, int pos, mpi:: } } -void test_shifted_coords( mpi::cartesian_communicator const& cc, std::vector const& coords, mpi::cartesian_topology const& topo ) +void test_shifted_coords( mpi::cartesian_communicator const& cc) { + std::vector coords; mpi::cartesian_topology topo(cc.ndims()); + cc.topology(topo, coords); if (cc.rank() == 0) { std::cout << "Testing shifts with topology " << topo << '\n'; } @@ -106,17 +108,14 @@ void test_topology_consistency( mpi::cartesian_communicator const& cc) test_coordinates_consistency( cc, coords ); } -void test_cartesian_topology( mpi::communicator const& world, mpi::cartesian_topology const& topo) +void test_cartesian_topology( mpi::cartesian_communicator const& cc) { - mpi::cartesian_communicator cc(world, topo, true); BOOST_CHECK(cc.has_cartesian_topology()); - BOOST_CHECK(cc.ndims() == int(topo.size())); for( int r = 0; r < cc.size(); ++r) { cc.barrier(); if (r == cc.rank()) { std::vector coords = cc.coords(r); std::cout << "Process of cartesian rank " << cc.rank() - << " and global rank " << world.rank() << " has coordinates ("; std::copy(coords.begin(), coords.end(), std::ostream_iterator(std::cout,",")); std::cout << ")\n"; @@ -129,7 +128,24 @@ void test_cartesian_topology( mpi::communicator const& world, mpi::cartesian_top } mpi::cartesian_communicator cce(cc, even); test_topology_consistency(cce); - test_shifted_coords( cce, cce.coords(cce.rank()), topo ); + test_shifted_coords(cce); +} + +void test_cartesian_topology( mpi::communicator const& world, mpi::cartesian_topology const& topo) +{ + mpi::cartesian_communicator cc(world, topo, true); + if (cc) { + BOOST_CHECK(cc.has_cartesian_topology()); + BOOST_CHECK(cc.ndims() == int(topo.size())); + if (cc.rank() == 0) { + std::cout << "Asked topology " << topo << ", got " << cc.topology() << '\n'; + } + test_cartesian_topology(cc); + } else { + std::ostringstream out; + out << world.rank() << " was left outside the cartesian grid\n"; + std::cout << out.str(); + } } int test_main(int argc, char* argv[]) @@ -138,8 +154,6 @@ int test_main(int argc, char* argv[]) mpi::communicator world; int const ndim = world.size() >= 24 ? 3 : 2; - //std::cout << "Say something:" << std::flush; - //std::cin.get(); mpi::cartesian_topology topo(ndim); typedef mpi::cartesian_dimension cd; if (topo.size() == 3) {