Simpatico  v1.10
Pair.h
1 #ifndef UTIL_PAIR_H
2 #define UTIL_PAIR_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/containers/FArray.h>
12 #include <iostream>
13 
14 namespace Util
15 {
16 
22  template <typename Data>
23  class Pair : public FArray <Data, 2>
24  {
25 
26  #ifdef UTIL_MPI
27  public:
28 
32  static void commitMpiType();
33  #endif
34 
35  };
36 
43  template <typename Data>
44  std::istream& operator>>(std::istream& in, Pair<Data> &pair)
45  {
46  in >> pair[0] >> pair[1];
47  return in;
48  }
49 
56  template <typename Data>
57  std::ostream& operator<<(std::ostream& out, const Pair<Data> &pair)
58  {
59  out << " " << pair[0] << " " << pair[1];
60  return out;
61  }
62 
63  #ifdef UTIL_MPI
64 
65  /*
66  * Commit associated MPI Datatype.
67  */
68  template <typename Data>
70  {
71  if (!MpiTraits< Pair<Data> >::hasType) {
72  MpiStructBuilder builder;
73  Pair<Data> object;
74  builder.setBase(&object);
75  builder.addMember(&object[0], MpiTraits<Data>::type);
76  builder.addMember(&object[1], MpiTraits<Data>::type);
77  builder.commit(MpiTraits< Pair<Data> >::type);
78  MpiTraits< Pair<Data> >::hasType = true;
79  }
80  }
81 
82  #endif
83 }
84 #endif
void addMember(void *memberAddress, MPI::Datatype type, int count=1)
Add a new member variable to the type map.
void setBase(void *objectAddress)
Set address of an class instance.
void commit(MPI::Datatype &newType)
Build and commit a user-defined MPI Struct datatype.
An array of exactly 2 objects.
Definition: Pair.h:23
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition: Pair.h:44
Utility classes for scientific computation.
Definition: accumulators.mod:1
Default MpiTraits class.
Definition: MpiTraits.h:39
A fixed size (static) contiguous array template.
Definition: FArray.h:46
A MpiStructBuilder objects is used to create an MPI Struct datatype.
static void commitMpiType()
Commit associated MPI DataType.
Definition: Pair.h:69