StdMpi.cc 7.29 KB
Newer Older
1
2
3
4
#include "StdMpi.h"

namespace AMDiS {

5
6
7
8
9
  int intSizeOf(int &data)
  {
    return 1;
  }

10
11
12
13
14
  int intSizeOf(std::map<const DegreeOfFreedom*, DegreeOfFreedom> &data)
  {
    return data.size() * 2;
  }

15
16
17
18
19
  int intSizeOf(std::map<WorldVector<double>, int> &data)
  {
    return data.size() * (Global::getGeo(WORLD) + 1);
  }

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
  int intSizeOf(std::vector<MeshStructure> &data)
  {
    int s = 0;
    for (unsigned int i = 0; i < data.size(); i++)
      s += data[i].getCode().size() + 2;

    return s;
  }

  int intSizeOf(std::vector<WorldVector<double> > &data)
  {
    return data.size() * Global::getGeo(WORLD);
  }

  int intSizeOf(std::vector<int> &data)
  {
    return data.size();
  }

  int intSizeOf(std::vector<double> &data)
  {
    return data.size();
  }
  
  int intSizeOf(std::vector<std::pair<int, int> > &data)
  {
    return data.size() * 2;
  }

  int intSizeOf(std::vector<AtomicBoundary> &data)
  {
    return data.size() * 3;
  }

  int intSizeOf(std::vector<BoundaryObject> &data)
  {
    return data.size() * 5;
  }

  int intSizeOf(std::vector<const DegreeOfFreedom*> &data)
  {
    return data.size();
  }

64
65
66
67
68
69
70
71
72
73
  int intSizeOf(std::vector<std::vector<double> > &data)
  {
    int size = 1;

    for (unsigned int i = 0; i < data.size(); i++)
      size += data[i].size() + 1;
    
    return size;
  }

74
75
76
77
78
79
80
81
82
83
  void makeBuf(int &data, int *buf)
  {
    buf[0] = data;
  }

  void makeFromBuf(int &data, int *buf, int bufSize)
  {
    data = buf[0];
  }

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
  void makeBuf(std::map<const DegreeOfFreedom*, DegreeOfFreedom> &data, int* buf)
  {
    int i = 0;
    for (std::map<const DegreeOfFreedom*, DegreeOfFreedom>::iterator it = data.begin();
	 it != data.end(); ++it) {
      buf[i++] = *(it->first);
      buf[i++] = it->second;
    }
  }
  
  void makeFromBuf(std::vector<std::pair<DegreeOfFreedom, DegreeOfFreedom> > &data, 
		   int *buf, int bufSize)
  {    
    if (bufSize == 0)
      return;

    TEST_EXIT(bufSize % 2 == 0)("This should not happen!\n");

    data.clear();
    data.reserve(bufSize / 2);

    for (int i = 0; i < (bufSize / 2); i++)
      data.push_back(std::make_pair(buf[i * 2], buf[i * 2 + 1]));
  }

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
  void makeBuf(std::map<WorldVector<double>, int> &data, double* buf)
  {
    int i = 0;
    for (std::map<WorldVector<double>, int>::iterator it = data.begin();
	 it != data.end(); ++it) {
      for (int j = 0; j < Global::getGeo(WORLD); j++)
	buf[i++] = it->first[j];
      buf[i++] = static_cast<double>(it->second);      
    }
  }

  void makeFromBuf(std::map<WorldVector<double>, int> &data, double* buf, int bufSize)
  {
    if (bufSize == 0)
      return;

    int oneEntrySize = Global::getGeo(WORLD) + 1;
    int nEntry = bufSize / oneEntrySize;

    TEST_EXIT(bufSize % oneEntrySize == 0)("This should not happen!\n");

    data.clear();
    int i = 0;
    WorldVector<double> coords;

    for (int j = 0; j < nEntry; j++) {
      for (int k = 0; k < Global::getGeo(WORLD); k++)
	coords[k] = buf[i++];
      data[coords] = static_cast<int>(buf[i++]);
    }
  }

141
  void makeBuf(std::vector<MeshStructure> &data, uint64_t *buf)
142
143
144
145
146
147
148
149
150
151
152
153
  {    
    int pos = 0;
    for (unsigned int i = 0; i < data.size(); i++) {
      buf[pos++] = data[i].getCode().size();
      buf[pos++] = data[i].getNumElements();

      for (unsigned int j = 0; j < data[i].getCode().size(); j++)
	buf[pos++] = data[i].getCode()[j];
    }
  }

  void makeFromBuf(std::vector<MeshStructure> &data, 
154
		   uint64_t *buf, int bufSize)
155
156
157
158
159
160
  {
    int pos = 0;

    while (pos < bufSize) {       
      int codeSize = buf[pos++];
      int nElements = buf[pos++];
161
      std::vector<uint64_t> code;
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
      code.resize(codeSize);
      for (int i = 0; i < codeSize; i++)
	code[i] = buf[pos++];

      MeshStructure meshCode;
      meshCode.init(code, nElements);

      data.push_back(meshCode);
    }	
  }

  void makeBuf(std::vector<WorldVector<double> > &data, double *buf)
  {
    int dimOfWorld = Global::getGeo(WORLD);
    int pos = 0;
    for (unsigned int i = 0; i < data.size(); i++)
      for (int j = 0; j < dimOfWorld; j++)
	buf[pos++] = data[i][j];
  }

  void makeFromBuf(std::vector<WorldVector<double> > &data, double *buf, int bufSize)
  {
    int dimOfWorld = Global::getGeo(WORLD);
    TEST_EXIT(bufSize % Global::getGeo(WORLD) == 0)("This should not happen!\n");

    int pos = 0;
    data.resize(bufSize / Global::getGeo(WORLD));
    for (unsigned int i = 0; i < data.size(); i++)
      for (int j = 0; j < dimOfWorld; j++)
	data[i][j] = buf[pos++];
  }

  void makeBuf(std::vector<int> &data, int *buf)
  {
    for (unsigned int i = 0; i < data.size(); i++)
      buf[i] = data[i];
  }

  void makeFromBuf(std::vector<int> &data, int *buf, int bufSize)
  {
    data.resize(bufSize);

    for (int i = 0; i < bufSize; i++)
      data[i] = buf[i];
  }

  void makeBuf(std::vector<double> &data, double *buf)
  {
    for (unsigned int i = 0; i < data.size(); i++)
      buf[i] = data[i];
  }

  void makeFromBuf(std::vector<double> &data, double *buf, int bufSize)
  {
    data.resize(bufSize);

    for (int i = 0; i < bufSize; i++)
      data[i] = buf[i];
  }

  void makeBuf(std::vector<std::pair<int, int> > &data, int *buf)
  {
    for (unsigned int i = 0; i < data.size(); i++) {
      buf[i * 2] = data[i].first;
      buf[i * 2 + 1] = data[i].second;
    }
  }

  void makeBuf(std::vector<AtomicBoundary> &data, int *buf)
  {
    for (unsigned int i = 0; i < data.size(); i++) {
      buf[i * 3] = data[i].rankObj.elIndex;
      buf[i * 3 + 1] = data[i].rankObj.subObj;
      buf[i * 3 + 2] = data[i].rankObj.ithObj;
    }
  }

  void makeFromBuf(std::vector<AtomicBoundary> &data, int *buf, int bufSize)
  {
    if (bufSize == 0)
      return;

    TEST_EXIT(bufSize % 3 == 0)("This should not happen!\n");    

    data.resize(bufSize / 3);
    for (int i = 0; i < bufSize / 3; i++) {
      data[i].rankObj.elIndex = buf[i * 3];
      data[i].rankObj.subObj = static_cast<GeoIndex>(buf[i * 3 + 1]);
      data[i].rankObj.ithObj = buf[i * 3 + 2];
    }
  }

  void makeBuf(std::vector<BoundaryObject> &data, int *buf)
  {
    for (unsigned int i = 0; i < data.size(); i++) {
      buf[i * 5] = data[i].elIndex;
      buf[i * 5 + 1] = data[i].elType;
      buf[i * 5 + 2] = data[i].subObj;
      buf[i * 5 + 3] = data[i].ithObj;
      buf[i * 5 + 4] = data[i].reverseMode;
    }
  }

  void makeFromBuf(std::vector<BoundaryObject> &data, int *buf, int bufSize)
  {
    if (bufSize == 0)
      return;

    TEST_EXIT(bufSize % 5 == 0)("This should not happen!\n");    

    data.resize(bufSize / 5);
    for (int i = 0; i < bufSize / 5; i++) {
      data[i].elIndex = buf[i * 5];
      data[i].elType = buf[i * 5 + 1];
      data[i].subObj = static_cast<GeoIndex>(buf[i * 5 + 2]);
      data[i].ithObj = buf[i * 5 + 3];
      data[i].reverseMode = static_cast<bool>(buf[i * 5 + 4]);
    }
  }

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
  void makeBuf(std::vector<std::vector<double> > &data, double *buf)
  {
    buf[0] = data.size();
    int counter = 1;

    for (unsigned int i = 0; i < data.size(); i++) {
      buf[counter++] = data[i].size();
      for (unsigned int j = 0; j < data[i].size(); j++)
	buf[counter++] = data[i][j];
    }
  }

  void makeFromBuf(std::vector<std::vector<double> > &data, double *buf, int bufSize)
  {
    data.resize(buf[0]);
    int counter = 1;

    for (unsigned int i = 0; i < data.size(); i++) {
      data[i].resize(buf[counter++]);
      
      for (unsigned int j = 0; j < data[i].size(); j++)
	data[i][j] = buf[counter++];
    }
  }

307
}