COMBINATORIAL_BLAS  1.6
indexHolder.h
Go to the documentation of this file.
1 
11 #ifndef __INDEX_HOLDER_H_
12 #define __INDEX_HOLDER_H_
13 
14 #include <iostream>
15 
19 template <typename T>
20 class IndexHolder {
21  public:
22  unsigned long index;
23  T value;
24 
28  value = T();
29  index = 0;
30  };
31  IndexHolder(T v, unsigned long i) { value = v; index = i;};
33  value = rhs.value;
34  index = rhs.index;
35  };
36 
38 
40 
41 
42 
46  static bool lessThan (const IndexHolder<T>& a, const IndexHolder<T>& b) {
47  return a < b;
48  }
49 
53  if ( this != &other ) {
54  value = other.value;
55  index = other.index;
56  }
57 
58  return *this;
59  }
60 
61  friend std::ostream& operator<<(std::ostream& os, const IndexHolder& dt) {
62  os << "idx-hldr: " << dt.value << ":" << dt.index << std::endl;
63  return os;
64  }
65 
66 
67  bool operator < ( IndexHolder<T> const &other) const {
68  if ( value == other.value )
69  return (index < other.index );
70  else
71  return ( value < other.value );
72  }
73 
74  bool operator > ( IndexHolder<T> const &other) const {
75  if ( value == other.value )
76  return (index > other.index );
77  else
78  return ( value > other.value );
79  }
80 
81  bool operator <= ( IndexHolder<T> const &other) const {
82  if ( value == other.value )
83  return (index <= other.index );
84  else
85  return ( value <= other.value );
86  }
87 
88  bool operator >= ( IndexHolder<T> const &other) const {
89  if ( value == other.value )
90  return (index >= other.index );
91  else
92  return ( value >= other.value );
93  }
94 
95  bool operator == ( IndexHolder<T> const &other) const {
96  return ( ( value == other.value ) && (index == other.index) );
97  }
98 
99  bool operator != ( IndexHolder<T> const &other) const {
100  return ( ( value != other.value) || (index != other.index) );
101  }
103 
104 };
105 
106 
107 namespace par {
108 
109  //Forward Declaration
110  template <typename T>
111  class Mpi_datatype;
112 
113  template <typename T>
115  public:
116  static MPI_Datatype value()
117  {
118  static bool first = true;
119  static MPI_Datatype datatype;
120 
121  if (first) {
122  /*
123  IndexHolder<T> test;
124 
125  first = false;
126  int block[2];
127  MPI_Aint disp[2];
128  MPI_Datatype type[2];
129 
130  block[0] = 1;
131  block[0] = 1;
132  type[0] = MPI_LONG;
133  type[1] = Mpi_datatype<T>::value();
134  disp[0] = 0;
135  disp[1] = sizeof(long); // sizeof(unsigned long);
136 */
137  MPI_Type_contiguous(sizeof(IndexHolder<T>), MPI_BYTE, &datatype);
138  // MPI_Type_create_struct(2, block, disp, type, &datatype);
139  MPI_Type_commit(&datatype);
140  }
141 
142  return datatype;
143  }
144  };
145 
146 }//end namespace par
147 
148 
149 #endif
150 
bool operator>(IndexHolder< T > const &other) const
Definition: indexHolder.h:74
An abstract class used for communicating messages using user-defined datatypes. The user must impleme...
Definition: dtypes.h:29
IndexHolder(const IndexHolder< T > &rhs)
Definition: indexHolder.h:32
static bool lessThan(const IndexHolder< T > &a, const IndexHolder< T > &b)
Definition: indexHolder.h:46
bool operator!=(IndexHolder< T > const &other) const
Definition: indexHolder.h:99
IndexHolder(T v, unsigned long i)
Definition: indexHolder.h:31
bool operator==(IndexHolder< T > const &other) const
Definition: indexHolder.h:95
IndexHolder< T > & operator=(const IndexHolder< T > &other)
Definition: indexHolder.h:52
friend std::ostream & operator<<(std::ostream &os, const IndexHolder &dt)
Definition: indexHolder.h:61
Collection of Generic Parallel Functions: Sorting, Partitioning, Searching,...
Definition: dtypes.h:18
A small helper class used while sorting a pair of value and its index in an array/vector.
Definition: indexHolder.h:20
unsigned long index
Definition: indexHolder.h:22
bool operator>=(IndexHolder< T > const &other) const
Definition: indexHolder.h:88