aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/data.hh
blob: ba44556ffec032141b19fdd2dc3d108c83b3041f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/data.hh,v 1.23 2004/06/08 22:57:22 schnetter Exp $

#ifndef DATA_HH
#define DATA_HH

#include <cassert>
#include <iostream>
#include <string>
#include <vector>

#include "cctk.h"

#include "defs.hh"
#include "dist.hh"
#include "bbox.hh"
#include "gdata.hh"
#include "vect.hh"

using namespace std;



// A distributed multi-dimensional array
template<class T,int D>
class data: public gdata<D>
{
  
  // Types
  typedef vect<int,D> ivect;
  typedef bbox<int,D> ibbox;

  // Fields
  T* _storage;			// the data (if located on this processor)
  size_t _allocated_bytes;      // number of allocated bytes
  
  // For vector groups with contiguous storage
  int vectorlength;             // number of vector elements
  int vectorindex;              // index of this vector element
  data* vectorleader;           // if index!=0: first vector element
  vector<bool> vectorclients;   // if index==0: registered elements
  
  void register_client (int index);
  void unregister_client (int index);
  bool has_clients ();
  
public:
  
  // Constructors
  data (const int varindex = -1,
        const operator_type transport_operator = op_error,
        const int vectorlength = 1, const int vectorindex = 0,
        data* const vectorleader = NULL);
  data (const int varindex, const operator_type transport_operator,
        const int vectorlength, const int vectorindex,
        data* const vectorleader,
        const ibbox& extent, const int proc);

  // Destructors
  virtual ~data ();

  // Pseudo constructors
  virtual data* make_typed (const int varindex,
                            const operator_type transport_operator) const;

  // Storage management
private:
  void getmem (const size_t nelems);
  void freemem ();
public:
  virtual void allocate (const ibbox& extent, const int proc,
			 void* const mem=0);
  virtual void free ();
  virtual void transfer_from (gdata<D>* gsrc);

private:
  T* vectordata (const int vectorindex) const;
public:

  // Processor management
  virtual void change_processor (comm_state<D>& state,
                                 const int newproc, void* const mem=0);
private:
  virtual void change_processor_recv (const int newproc, void* const mem=0);
  virtual void change_processor_send (const int newproc, void* const mem=0);
  virtual void change_processor_wait (const int newproc, void* const mem=0);
public:

  // Accessors
  virtual const void* storage () const
  {
    assert (this->_has_storage);
    return _storage;
  }

  virtual void* storage () {
    assert (this->_has_storage);
    return _storage;
  }
  
  // Data accessors
  const T& operator[] (const ivect& index) const
  {
    assert (_storage);
    return _storage[offset(index)];
  }
  
  T& operator[] (const ivect& index)
  {
    assert (_storage);
    return _storage[offset(index)];
  }
  
  // Data manipulators
  void copy_from_innerloop (const gdata<D>* gsrc,
			    const ibbox& box);
  void interpolate_from_innerloop (const vector<const gdata<D>*> gsrcs,
				   const vector<CCTK_REAL> times,
				   const ibbox& box, const CCTK_REAL time,
				   const int order_space,
				   const int order_time);
  
public:

  // Output
  ostream& output (ostream& os) const;
};



#endif // DATA_HH