StdMpi.cc 5.54 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
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
  int intSizeOf(std::map<const DegreeOfFreedom*, DegreeOfFreedom> &data)
  {
    return data.size() * 2;
  }

  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();
  }

59
60
61
62
63
64
65
66
67
68
  void makeBuf(int &data, int *buf)
  {
    buf[0] = data;
  }

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

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
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
  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]));
  }

  void makeBuf(std::vector<MeshStructure> &data, unsigned long int *buf)
  {    
    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, 
		   unsigned long int *buf, int bufSize)
  {
    int pos = 0;

    while (pos < bufSize) {       
      int codeSize = buf[pos++];
      int nElements = buf[pos++];
      std::vector<unsigned long int> code;
      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]);
    }
  }

}