Commit a2756452 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

added extents to parallel piece files by communication

parent d11aca8f
...@@ -23,7 +23,7 @@ public: ...@@ -23,7 +23,7 @@ public:
, wholeExtent_(filledArray<6,int>(0)) , wholeExtent_(filledArray<6,int>(0))
, origin_(0.0) , origin_(0.0)
, spacing_(0.0) , spacing_(0.0)
, level_(gridView.template begin<0,Interior_Partition>()->level()) , level_(gridView.template begin<0,All_Partition>()->level())
{} {}
std::array<int, 6> const& wholeExtentImpl () const std::array<int, 6> const& wholeExtentImpl () const
...@@ -44,6 +44,7 @@ public: ...@@ -44,6 +44,7 @@ public:
void updateImpl () void updateImpl ()
{ {
Super::updateImpl(); Super::updateImpl();
localPieceCalled_ = false;
for (int i = 0; i < dim; ++i) { for (int i = 0; i < dim; ++i) {
wholeExtent_[2*i] = 0; wholeExtent_[2*i] = 0;
...@@ -52,6 +53,20 @@ public: ...@@ -52,6 +53,20 @@ public:
auto it = gridView_.grid().begin(level_); auto it = gridView_.grid().begin(level_);
initGeometry(it->coords); initGeometry(it->coords);
#if HAVE_MPI
int rank = -1;
int num_ranks = -1;
MPI_Comm_rank(gridView_.comm(), &rank);
MPI_Comm_size(gridView_.comm(), &num_ranks);
if (rank == 0) {
extents_.resize(num_ranks);
requests_.resize(num_ranks);
for (int i = 1; i < num_ranks; ++i)
MPI_Irecv(extents_[i].data(), extents_[i].size(), MPI_INT, i, /*tag=*/6, gridView_.comm(), &requests_[i]);
}
#endif
} }
template <class Coords> template <class Coords>
...@@ -92,25 +107,38 @@ public: ...@@ -92,25 +107,38 @@ public:
extent[2*i] = gc.min(i); extent[2*i] = gc.min(i);
extent[2*i+1] = gc.max(i)+1; extent[2*i+1] = gc.max(i)+1;
} }
#if HAVE_MPI
if (!localPieceCalled_) {
int rank = -1;
MPI_Comm_rank(gridView_.comm(), &rank);
if (rank != 0) {
MPI_Isend(extent.data(), extent.size(), MPI_INT, 0, /*tag=*/6, gridView_.comm(), &sendRequest_);
} else {
extents_[0] = extent;
}
localPieceCalled_ = true;
}
#endif
writer(extent); writer(extent);
} }
template <class Writer> template <class Writer>
void writePiecesImpl (Writer const& writer) const void writePiecesImpl (Writer const& writer) const
{ {
auto extent = filledArray<6,int>(0); assert(localPieceCalled_);
// for (auto const& part : gridView_.gridLevel().template partition<InteriorEntity>()) #if HAVE_MPI
// {
// for (int i = 0; i < dim; ++i) {
// extent[2*i] = part.begin()[i];
// extent[2*i+1] = part.end()[i]-1;
// }
int num_ranks = -1; int num_ranks = -1;
MPI_Comm_size(MPI_COMM_WORLD, &num_ranks); MPI_Comm_size(gridView_.comm(), &num_ranks);
std::vector<MPI_Status> status(num_ranks-1);
MPI_Waitall(num_ranks-1, requests_.data()+1, status.data());
for (int p = 0; p < num_ranks; ++p) { for (int p = 0; p < num_ranks; ++p) {
writer(p, extent, false); writer(p, extents_[p], true);
} }
#endif
} }
template <class T> template <class T>
...@@ -142,6 +170,11 @@ private: ...@@ -142,6 +170,11 @@ private:
FieldVector<ctype,3> origin_; FieldVector<ctype,3> origin_;
std::vector<std::size_t> indexMap_; std::vector<std::size_t> indexMap_;
int level_; int level_;
mutable std::vector<std::array<int,6>> extents_;
mutable std::vector<MPI_Request> requests_;
mutable MPI_Request sendRequest_;
mutable bool localPieceCalled_ = false;
}; };
namespace Impl namespace Impl
......
...@@ -51,12 +51,14 @@ void VtkWriterInterface<GV,DC> ...@@ -51,12 +51,14 @@ void VtkWriterInterface<GV,DC>
if (num_ranks > 1) { if (num_ranks > 1) {
filename = p.string() + "_p" + std::to_string(rank) + "." + fileExtension(); filename = p.string() + "_p" + std::to_string(rank) + "." + fileExtension();
writeSerialFile(filename);
if (rank == 0) { if (rank == 0) {
writeParallelFile(p.string(), num_ranks); writeParallelFile(p.string(), num_ranks);
} }
} else {
writeSerialFile(filename);
} }
#endif #endif
writeSerialFile(filename);
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <dune/grid/utility/structuredgridfactory.hh> #include <dune/grid/utility/structuredgridfactory.hh>
#include <dune/vtk/vtkreader.hh> #include <dune/vtk/vtkreader.hh>
#include <dune/vtk/vtkunstructuredgridwriter.hh> #include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
using namespace Dune; using namespace Dune;
using namespace Dune::experimental; using namespace Dune::experimental;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <dune/grid/utility/structuredgridfactory.hh> #include <dune/grid/utility/structuredgridfactory.hh>
#include <dune/vtk/vtkreader.hh> #include <dune/vtk/vtkreader.hh>
#include <dune/vtk/vtkunstructuredgridwriter.hh> #include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
using namespace Dune; using namespace Dune;
using namespace Dune::experimental; using namespace Dune::experimental;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment