From 9df252f135bfcde504b329108353fecb6193142e Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 14 Jun 2011 14:44:42 -0400 Subject: CarpetLib: Create MPI datatypes for vect<,> classes --- Carpet/CarpetLib/src/vect.cc | 35 +++++++++++++++++++++++++++++++++++ Carpet/CarpetLib/src/vect.hh | 17 +++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'Carpet/CarpetLib') diff --git a/Carpet/CarpetLib/src/vect.cc b/Carpet/CarpetLib/src/vect.cc index 15bf81a86..b8537a8eb 100644 --- a/Carpet/CarpetLib/src/vect.cc +++ b/Carpet/CarpetLib/src/vect.cc @@ -2,6 +2,7 @@ #include #include +#include #include "defs.hh" #include "bboxset.hh" @@ -44,6 +45,40 @@ void vect::output (ostream& os) const { +// MPI +template +MPI_Datatype vect::mpi_datatype () const +{ + static bool initialised = false; + static MPI_Datatype newtype; + if (not initialised) { + vect const& s = *this; +#define ENTRY(type, name) \ + { \ + sizeof s.name / sizeof(type), /* count elements */ \ + (char*)&s.name - (char*)&s, /* offsetof doesn't work (why?) */ \ + dist::mpi_datatype(), /* find MPI datatype */ \ + STRINGIFY(name), /* field name */ \ + STRINGIFY(type), /* type name */ \ + } + dist::mpi_struct_descr_t const descr[] = { + ENTRY(T, elt), + {1, sizeof s, MPI_UB, "MPI_UB", "MPI_UB"} + }; +#undef ENTRY + ostringstream buf; + buf << "vect<" << typeid(T).name() << "," << D << ">"; + newtype = + dist::create_mpi_datatype (sizeof descr / sizeof descr[0], descr, + buf.str().c_str(), sizeof s); + initialised = true; + } + return newtype; +} + + + + // Specialise some constructors for lower dimensions // These functions are declared, but must not be used. diff --git a/Carpet/CarpetLib/src/vect.hh b/Carpet/CarpetLib/src/vect.hh index 05f8c9ca7..b1379c64b 100644 --- a/Carpet/CarpetLib/src/vect.hh +++ b/Carpet/CarpetLib/src/vect.hh @@ -9,6 +9,7 @@ #include #include "defs.hh" +#include "dist.hh" #include "vect_helpers.hh" using namespace std; @@ -309,6 +310,9 @@ public: // Input/Output helpers void input (istream& is); void output (ostream& os) const; + + // MPI + MPI_Datatype mpi_datatype () const; }; @@ -659,6 +663,19 @@ inline ostream& operator<< (ostream& os, const vect& a) { +// MPI + +template +inline MPI_Datatype mpi_datatype (vect const & a) { + return a.mpi_datatype(); +} +namespace dist { + template<> inline MPI_Datatype mpi_datatype () + { ivect dummy; return mpi_datatype(dummy); } +} + + + #if 0 // Specialise explicit constructors -- cgit v1.2.3