SheafSystem  0.0.0.0
equivalence.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Implementation for class EQUIVALENCE
19 
20 #include "SheafSystem/assert_contract.h"
21 
22 #ifndef EQUIVALENCE_H
23 #include "SheafSystem/equivalence.h"
24 #endif
25 
26 #ifdef PARALLEL_MPI
27 
28 #ifndef POSET_H
29 #include "SheafSystem/poset.h"
30 #endif
31 
32 sheaf::equivalence::
33 equivalence(int xremote_index, int xremote_proc, poset_storage* xremote_storage)
34 {
35 
36  // preconditions:
37 
38  require(xremote_index >= 0);
39  require(xremote_proc >= 0);
40  int size;
41  MPI_Comm_size(MPI_COMM_WORLD,&size);
42  require(xremote_proc < size);
43  require(xremote_storage != 0);
44 
45  // body:
46 
47  _remote_index = xremote_index;
48  _remote_proc = xremote_proc;
49  _remote_storage = xremote_storage;
50 
51  // postconditions:
52 
53  ensure(remote_index() == xremote_index);
54  ensure(remote_proc() == xremote_proc);
55  ensure(remote_storage() == xremote_storage);
56 
57  ensure(invariant());
58 }
59 
60 sheaf::equivalence::
61 ~equivalence()
62 {}
63 
64 bool
65 sheaf::equivalence::
66 invariant() const
67 {
68 
69  return true;
70 }
71 
72 hid_t
73 sheaf::equivalence::
74 hdf_type()
75 {
76 
77  // body:
78 
79  static bool first_call = true;
80  static hid_t result = -1;
81  herr_t rtncode = -1;
82 
83  if (first_call)
84  {
85 
86  first_call = false;
87 
89 
90  result = H5Tcreate(H5T_COMPOUND, sizeof(hdf_rep));
91  assertion(result >= 0);
92  rtncode = H5Tinsert(result,
93  "local_index",
94  HOFFSET(hdf_rep, local_index),
95  H5T_NATIVE_INT);
96  assertion(rtncode >= 0);
97  rtncode = H5Tinsert(result,
98  "remote_index",
99  HOFFSET(hdf_rep, remote_index),
100  H5T_NATIVE_INT);
101  assertion(rtncode >= 0);
102  rtncode = H5Tinsert(result,
103  "remote_proc",
104  HOFFSET(hdf_rep, remote_proc),
105  H5T_NATIVE_INT);
106  assertion(rtncode >= 0);
107  }
108 
109  // postconditions:
110 
111  ensure(result >= 0);
112 
115 
116  return result;
117 }
118 
119 MPI_Datatype
120 sheaf::equivalence::
121 mpi_type()
122 {
123 
124  // body:
125 
126  static bool first_call = true;
127  static MPI_Datatype result = MPI_DATATYPE_NULL;
128  int rtncode = MPI_SUCCESS;
129 
130  if (first_call)
131  {
132 
133  first_call = false;
134 
136 
137  int cts = 3;
138  MPI_Aint displs = 0;
139  MPI_Datatype types = MPI_INT;
140 
141  rtncode = MPI_Type_struct(1,&cts,&displs,&types,&result);
142  if (rtncode == MPI_SUCCESS)
143  rtncode = MPI_Type_commit(&result);
144  }
145 
146  // postconditions:
147 
148  ensure(rtncode == MPI_SUCCESS);
149  ensure(result != MPI_DATATYPE_NULL);
150 
153 
154  return result;
155 }
156 
157 void
158 sheaf::equivalence::
159 make_hdf_rep(hdf_rep* xhdf_rep, int xlocal_index)
160 {
161 
162  // preconditions:
163 
164  require(xhdf_rep != 0);
165  require(xlocal_index >= 0);
166 
167  // body:
168 
169  xhdf_rep->local_index = xlocal_index;
170  xhdf_rep->remote_index = _remote_index;
171  xhdf_rep->remote_proc = _remote_proc;
172 }
173 
174 void
175 sheaf::equivalence::
176 make_mpi_rep(mpi_rep* xmpi_rep)
177 {
178 
179  // preconditions:
180 
181  require(xmpi_rep != 0);
182 
183  // body:
184 
185  xmpi_rep->remote_index = _remote_index;
186  xmpi_rep->remote_proc = _remote_proc;
187  assertion(MPI_Address(_remote_storage, &xmpi_rep->remote_storage) == MPI_SUCCESS);
188 }
189 
190 /*
191 MPI_Comm
192 sheaf::equivalence::
193 communicator() {
194 
195  // return _communicator;
196 }
197 */
198 
199 int
200 sheaf::equivalence::
201 remote_index()
202 {
203 
204  return _remote_index;
205 }
206 
207 int
208 sheaf::equivalence::
209 remote_proc()
210 {
211 
212  return _remote_proc;
213 }
214 
215 sheaf::poset_storage *
216 sheaf::equivalence::
217 remote_storage()
218 {
219 
220  return _remote_storage;
221 }
222 
223 
224 sheaf::equivalence::
225 equivalence(hdf_rep* xrep)
226 {
227 
228  // preconditions:
229 
230  require(xrep != 0);
231 
232  // body:
233 
234  _remote_index = xrep->remote_index;
235  _remote_proc = xrep->remote_proc;
236  _remote_storage = 0;
237 
238  // postconditions:
239 
240 }
241 
242 void
243 sheaf::equivalence::
244 put_remote_storage(poset_storage* xstorage)
245 {
246 
247  // preconditions:
248 
249  require(xstorage != 0);
250 
251  // body:
252 
253  _remote_storage = xstorage;
254 
255 }
256 
257 #endif // PARALLEL_MPI