aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2011-06-14 14:44:42 -0400
committerBarry Wardell <barry.wardell@gmail.com>2011-12-14 18:26:30 +0000
commit9df252f135bfcde504b329108353fecb6193142e (patch)
treea975a81e190be0ae1bb2846be3111901c142de75 /Carpet/CarpetLib
parent3304ca09afa0a0c134365d3992709935b493ef1b (diff)
CarpetLib: Create MPI datatypes for vect<,> classes
Diffstat (limited to 'Carpet/CarpetLib')
-rw-r--r--Carpet/CarpetLib/src/vect.cc35
-rw-r--r--Carpet/CarpetLib/src/vect.hh17
2 files changed, 52 insertions, 0 deletions
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 <cassert>
#include <iostream>
+#include <typeinfo>
#include "defs.hh"
#include "bboxset.hh"
@@ -44,6 +45,40 @@ void vect<T,D>::output (ostream& os) const {
+// MPI
+template<typename T,int D>
+MPI_Datatype vect<T,D>::mpi_datatype () const
+{
+ static bool initialised = false;
+ static MPI_Datatype newtype;
+ if (not initialised) {
+ vect<T,D> 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<type>(), /* 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 <iostream>
#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<T,D>& a) {
+// MPI
+
+template<typename T,int D>
+inline MPI_Datatype mpi_datatype (vect<T,D> const & a) {
+ return a.mpi_datatype();
+}
+namespace dist {
+ template<> inline MPI_Datatype mpi_datatype<ivect> ()
+ { ivect dummy; return mpi_datatype(dummy); }
+}
+
+
+
#if 0
// Specialise explicit constructors