aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/data.hh
blob: 6b7a774e1ae9fe6b323bec88562d9b2aeb3e73ad (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#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 "mem.hh"
#include "vect.hh"

using namespace std;

template<typename T>
class data;

template<typename T>
ostream & operator << ( ostream & os, const data<T> & d );

// A distributed multi-dimensional array
template<typename T>
class data: public gdata
{
  
  // Fields
  mem<T> * _memory;             // the data (if located on this processor)
  
  // 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
   
private:
  // Forbid copying and passing by value
  data (data const &);
  data & operator= (data const &);
  
public:
  
  // Constructors
  data (const int varindex = -1,
        const centering cent = error_centered,
        const operator_type transport_operator = op_error,
        const int vectorlength = 1, const int vectorindex = 0,
        data* const vectorleader = NULL,
        const int tag = -1);
  data (const int varindex,
        const centering cent, 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 centering cent,
                            const operator_type transport_operator,
                            const int tag) const;

  // Storage management
  virtual void allocate (const ibbox& extent, const int proc,
			 void* const memptr = NULL, size_t const memsize = 0);
  virtual void free ();
  virtual size_t allocsize (const ibbox& extent, const int proc) const;
  
public:
  
  // Data accessors
  const T& operator[] (const ivect& index) const
  {
    assert (_has_storage);
    assert (_memory);
    return _memory->storage(vectorindex)[offset(index)];
  }
  
  T& operator[] (const ivect& index)
  {
    assert (_has_storage);
    assert (_memory);
    return _memory->storage(vectorindex)[offset(index)];
  }

  // Datatype accessors
private:
  // maps the C datatype of a data class object to a 0-based index
  virtual unsigned int c_datatype () const
  {
    T dummy;
    return dist::c_datatype (dummy);
  }
  // size of the C datatype
  virtual size_t c_datatype_size () const
  {
    return sizeof (T);
  }

  // Data manipulators
  
private:
  
  void
  copy_from_innerloop (gdata const * gsrc,
                       ibbox const & box);
  
  void
  transfer_from_innerloop (vector <gdata const *> const & gsrcs,
                           vector <CCTK_REAL> const & times,
                           ibbox const & box,
                           CCTK_REAL time,
                           int order_space,
                           int order_time);
  
  void
  transfer_time (vector <gdata const *> const & gsrcs,
                 vector <CCTK_REAL> const & times,
                 ibbox const & box,
                 CCTK_REAL time,
                 int order_space,
                 int order_time);
  
  void
  transfer_p_r (data const * const src,
                ibbox const & box,
                int order_space);
  
  void
  transfer_p_vc_cc (data const * const src,
                    ibbox const & box,
                    int order_space);
  
  void
  transfer_prolongate (data const * const src,
                       ibbox const & box,
                       int order_space);
  
  void
  transfer_restrict (data const * const src,
                     ibbox const & box,
                     int order_space);
  
  void
  time_interpolate (vector <data *> const & srcs,
                    ibbox const & box,
                    vector <CCTK_REAL> const & times,
                    CCTK_REAL time,
                    int order_time);
  
public:
  
  // Memory usage
  size_t memory () const;
  
  // Output
  ostream & output (ostream& os) const;
  
  friend ostream & operator<< <T> (ostream & os, data<T> const & d);
};
  
// Memory usage
template<typename T>
inline size_t memoryof (data<T> const & d)
{
  return d.memory();
}

#endif // DATA_HH