aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/region.hh
blob: e5f36011cc64c387969efb070f827e86a4ba2090 (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
#ifndef REGION_HH
#define REGION_HH

#include <iostream>
#include <vector>

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



// Region description
struct region_t {
  ibbox        extent;           // extent
  b2vect       outer_boundaries; // outer boundaries
  int          map;              // map to which this region belongs
  int          processor;        // processor number
  ipfulltree * processors;       // processor decomposition
  
  region_t ();
  region_t (region_t const & a);
  region_t & operator= (region_t const & a);
  ~region_t ();
  
  bool invariant () const CCTK_MEMBER_ATTRIBUTE_PURE;
  
  // For regridding
  CCTK_REAL load () const CCTK_MEMBER_ATTRIBUTE_PURE;
  region_t split (CCTK_REAL ratio_new_over_old);
  
  // Check whether a region is defined consistently
  bool check_region(bool is_superregion) const;
private:
  bool check_children(ipfulltree const& tree, int parent_map, int level,
                      ibset& child_extents) const;
public:
  
  // Output processor decomposition? (Off by default.)
  static bool full_output;
};



bool operator== (region_t const & a, region_t const & b)
  CCTK_ATTRIBUTE_PURE;
inline
bool operator!= (region_t const & a, region_t const & b)
{
  return not (a == b);
}



void
combine_regions (vector<region_t> const & oldregs,
                 vector<region_t> & newregs);



size_t memoryof (region_t const & reg) CCTK_ATTRIBUTE_PURE;

istream & operator>> (istream & is, region_t       & reg);
ostream & operator<< (ostream & os, region_t const & reg);
void fulloutput (ostream & os, region_t const & reg);



// A pseudoregion is almost a region; it is a bbox that belongs to a
// certain component.  Pseudoregions are a compact way to store
// information about what components needs to send data to what other
// components during synchronisation or regridding.
struct pseudoregion_t {
  ibbox extent;
  int component;
  pseudoregion_t ()
  {
  }
  pseudoregion_t (pseudoregion_t const & p)
    : extent (p.extent), component (p.component)
  {
  }
  pseudoregion_t (ibbox const & extent_, int const component_)
    : extent (extent_), component (component_)
  {
  }
};

MPI_Datatype mpi_datatype (pseudoregion_t const &)
  CCTK_ATTRIBUTE_PURE;
namespace dist {
  template<> inline MPI_Datatype mpi_datatype<pseudoregion_t> ()
  { pseudoregion_t dummy; return mpi_datatype(dummy); }
}

bool operator== (pseudoregion_t const & a, pseudoregion_t const & b)
  CCTK_ATTRIBUTE_PURE;
inline
bool operator!= (pseudoregion_t const & a, pseudoregion_t const & b)
{
  return not (a == b);
}

inline size_t memoryof (pseudoregion_t const & p)
{
  return
    memoryof (p.extent) +
    memoryof (p.component);
}

istream & operator>> (istream & is, pseudoregion_t       & p);
ostream & operator<< (ostream & os, pseudoregion_t const & p);



struct sendrecv_pseudoregion_t {
  pseudoregion_t send, recv;
  sendrecv_pseudoregion_t ()
  {
  }
  sendrecv_pseudoregion_t (sendrecv_pseudoregion_t const & srp)
    : send (srp.send), recv (srp.recv)
  {
  }
  sendrecv_pseudoregion_t (ibbox const & send_extent, int const send_component,
                           ibbox const & recv_extent, int const recv_component)
    : send (pseudoregion_t (send_extent, send_component)),
      recv (pseudoregion_t (recv_extent, recv_component))
  {
  }
};

MPI_Datatype mpi_datatype (sendrecv_pseudoregion_t const &)
  CCTK_ATTRIBUTE_PURE;
namespace dist {
  template<> inline MPI_Datatype mpi_datatype<sendrecv_pseudoregion_t> ()
  { sendrecv_pseudoregion_t dummy; return mpi_datatype(dummy); }
}

inline size_t memoryof (sendrecv_pseudoregion_t const & srp)
{
  return memoryof (srp.send) + memoryof (srp.recv);
}

istream & operator>> (istream & os, sendrecv_pseudoregion_t       & srp);
ostream & operator<< (ostream & os, sendrecv_pseudoregion_t const & srp);



#endif // #ifndef REGION_HH