OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Vnode.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  ***************************************************************************/
7 
8 #ifndef VNODE_H
9 #define VNODE_H
10 
11 // include files
12 #include "Utility/RefCounted.h"
13 #include "Index/NDIndex.h"
14 
15 #include <iostream>
16 
17 // forward declarations
18 template <unsigned Dim> class Vnode;
19 template <unsigned Dim>
20 std::ostream& operator<<(std::ostream&, const Vnode<Dim>&);
21 
22 
23 //----------------------------------------------------------------------
24 //
25 // Vnodes really have very little information.
26 // It knows its domain and what processor it resides on.
27 //
28 // Also, it has a global integer index for the vnode (useful with more recent
29 // FieldLayouts which store a logical "array" of vnodes; user specifies numbers
30 // of vnodes along each direction). Classes or user codes that use Vnode are
31 // responsible for setting and managing the values of this index; if unset, it
32 // has the value -1.
33 //
34 //----------------------------------------------------------------------
35 
36 template<unsigned Dim>
37 class Vnode : public RefCounted
38 {
39 
40 private:
42  int Node;
43  int vnode_m; // Global vnode ID number (between 0 and nvnodes - 1)
44 
45 public:
46  // Null ctor does nothing.
47  Vnode() {}
48 
49  // Normal ctor:
50  Vnode(const NDIndex<Dim>& domain, int node, int vnode=-1) :
51  Domain(domain), Node(node), vnode_m(vnode) {}
52 
53  // Copy ctor:
54  Vnode(const Vnode<Dim>& vn) :
55  Domain(vn.Domain), Node(vn.Node), vnode_m(vn.vnode_m) {}
56 
57  // operator= to copy one vnode into another
59  Domain = vn.Domain;
60  Node = vn.Node;
61  vnode_m = vn.vnode_m;
62  return *this;
63  }
64 
65  int getNode() const { return Node; }
66  int getVnode() const { return vnode_m; }
67  const NDIndex<Dim>& getDomain() const { return Domain; }
68 
69  // put data into a message to send to another node
70  Message& putMessage(Message& m) const {
71  Domain.putMessage(m);
72  m.put(Node);
73  m.put(vnode_m);
74  return m;
75  }
76 
77  // get data out from a message
79  Domain.getMessage(m);
80  m.get(Node);
81  m.get(vnode_m);
82  return m;
83  }
84 
85 };
86 
88 
89 template <unsigned Dim>
90 inline std::ostream&
91 operator<<(std::ostream& out, const Vnode<Dim>& v) {
92  out << "Node = " << v.getNode() << " ; vnode_m = " << v.getVnode()
93  << " ; Domain = " << v.getDomain();
94  return out;
95 }
96 
97 #endif // VNODE_H
std::ostream & operator<<(std::ostream &, const Vnode< Dim > &)
Definition: Vnode.h:91
Definition: Vnode.h:38
NDIndex< Dim > Domain
Definition: Vnode.h:41
int getVnode() const
Definition: Vnode.h:66
Vnode()
Definition: Vnode.h:47
Vnode(const Vnode< Dim > &vn)
Definition: Vnode.h:54
int Node
Definition: Vnode.h:42
Message & getMessage(Message &m)
Definition: Vnode.h:78
const NDIndex< Dim > & getDomain() const
Definition: Vnode.h:67
Vnode(const NDIndex< Dim > &domain, int node, int vnode=-1)
Definition: Vnode.h:50
Message & putMessage(Message &m) const
Definition: Vnode.h:70
Vnode< Dim > & operator=(const Vnode< Dim > &vn)
Definition: Vnode.h:58
int vnode_m
Definition: Vnode.h:43
int getNode() const
Definition: Vnode.h:65
Message & put(const T &val)
Definition: Message.h:406
Message & get(const T &cval)
Definition: Message.h:476