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