aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/vect.cc
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/src/vect.cc
parent3304ca09afa0a0c134365d3992709935b493ef1b (diff)
CarpetLib: Create MPI datatypes for vect<,> classes
Diffstat (limited to 'Carpet/CarpetLib/src/vect.cc')
-rw-r--r--Carpet/CarpetLib/src/vect.cc35
1 files changed, 35 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.