/[escript]/trunk/dudley/src/Assemble_CopyNodalData.cpp
ViewVC logotype

Contents of /trunk/dudley/src/Assemble_CopyNodalData.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4346 - (show annotations)
Tue Apr 2 04:46:45 2013 UTC (6 years, 4 months ago) by jfenwick
File size: 13183 byte(s)
Bringing the changes from doubleplusgood branch.
Can't merge directly because svn doesn't transfer changes to renamed files (mutter grumble).
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16 /************************************************************************************/
17
18 /* assemblage routines: copies data between different types nodal representation */
19
20 /************************************************************************************/
21
22 #include "Util.h"
23 #include "Assemble.h"
24 #ifdef _OPENMP
25 #include <omp.h>
26 #endif
27
28 void Dudley_Assemble_CopyNodalData(Dudley_NodeFile * nodes, escriptDataC * out, escriptDataC * in)
29 {
30 dim_t n, k, l, mpiSize;
31 dim_t numComps = getDataPointSize(out);
32 Paso_Coupler *coupler = NULL;
33 type_t in_data_type = getFunctionSpaceType(in);
34 type_t out_data_type = getFunctionSpaceType(out);
35 index_t upperBound;
36 double *recv_buffer;
37 size_t numComps_size = 0;
38 Dudley_resetError();
39 if (nodes == NULL)
40 return;
41 mpiSize = nodes->MPIInfo->size;
42
43 /* check out and in */
44 if (numComps != getDataPointSize(in))
45 {
46 Dudley_setError(TYPE_ERROR,
47 "Dudley_Assemble_CopyNodalData: number of components of input and output Data do not match.");
48 }
49 else if (!isExpanded(out))
50 {
51 Dudley_setError(TYPE_ERROR, "Dudley_Assemble_CopyNodalData: expanded Data object is expected for output data.");
52 }
53
54 /* more sophisticated test needed for overlapping node/DOF counts */
55 if (in_data_type == DUDLEY_NODES)
56 {
57 if (!numSamplesEqual(in, 1, Dudley_NodeFile_getNumNodes(nodes)))
58 {
59 Dudley_setError(TYPE_ERROR,
60 "Dudley_Assemble_CopyNodalData: illegal number of samples of input Data object");
61 }
62 }
63 else if (in_data_type == DUDLEY_REDUCED_NODES)
64 {
65 if (!numSamplesEqual(in, 1, Dudley_NodeFile_getNumReducedNodes(nodes)))
66 {
67 Dudley_setError(TYPE_ERROR,
68 "Dudley_Assemble_CopyNodalData: illegal number of samples of input Data object");
69 }
70 }
71 else if (in_data_type == DUDLEY_DEGREES_OF_FREEDOM)
72 {
73 if (!numSamplesEqual(in, 1, Dudley_NodeFile_getNumDegreesOfFreedom(nodes)))
74 {
75 Dudley_setError(TYPE_ERROR,
76 "Dudley_Assemble_CopyNodalData: illegal number of samples of input Data object");
77 }
78 if ((((out_data_type == DUDLEY_NODES) || (out_data_type == DUDLEY_DEGREES_OF_FREEDOM)) && !isExpanded(in)
79 && (mpiSize > 1)))
80 {
81
82 Dudley_setError(TYPE_ERROR,
83 "Dudley_Assemble_CopyNodalData: DUDLEY_DEGREES_OF_FREEDOM to DUDLEY_NODES or DUDLEY_DEGREES_OF_FREEDOM requires expanded input data on more than one processor.");
84 }
85 }
86 else if (in_data_type == DUDLEY_REDUCED_DEGREES_OF_FREEDOM)
87 {
88 if (!numSamplesEqual(in, 1, Dudley_NodeFile_getNumReducedDegreesOfFreedom(nodes)))
89 {
90 Dudley_setError(TYPE_ERROR,
91 "Dudley_Assemble_CopyNodalData: illegal number of samples of input Data object");
92 }
93 if ((out_data_type == DUDLEY_DEGREES_OF_FREEDOM) && !isExpanded(in) && (mpiSize > 1))
94 {
95
96 Dudley_setError(TYPE_ERROR,
97 "Dudley_Assemble_CopyNodalData: DUDLEY_REDUCED_DEGREES_OF_FREEDOM to DUDLEY_DEGREES_OF_FREEDOM requires expanded input data on more than one processor.");
98 }
99 }
100 else
101 {
102 Dudley_setError(TYPE_ERROR, "Dudley_Assemble_CopyNodalData: illegal function space type for target object");
103 }
104
105 if (out_data_type == DUDLEY_NODES)
106 {
107 if (!numSamplesEqual(out, 1, Dudley_NodeFile_getNumNodes(nodes)))
108 {
109 Dudley_setError(TYPE_ERROR,
110 "Dudley_Assemble_CopyNodalData: illegal number of samples of output Data object");
111 }
112 }
113 else if (out_data_type == DUDLEY_REDUCED_NODES)
114 {
115 if (!numSamplesEqual(out, 1, Dudley_NodeFile_getNumReducedNodes(nodes)))
116 {
117 Dudley_setError(TYPE_ERROR,
118 "Dudley_Assemble_CopyNodalData: illegal number of samples of output Data object");
119 }
120 }
121 else if (out_data_type == DUDLEY_DEGREES_OF_FREEDOM)
122 {
123 if (!numSamplesEqual(out, 1, Dudley_NodeFile_getNumDegreesOfFreedom(nodes)))
124 {
125 Dudley_setError(TYPE_ERROR,
126 "Dudley_Assemble_CopyNodalData: illegal number of samples of output Data object");
127 }
128 }
129 else if (out_data_type == DUDLEY_REDUCED_DEGREES_OF_FREEDOM)
130 {
131 if (!numSamplesEqual(out, 1, Dudley_NodeFile_getNumReducedDegreesOfFreedom(nodes)))
132 {
133 Dudley_setError(TYPE_ERROR,
134 "Dudley_Assemble_CopyNodalData: illegal number of samples of output Data object");
135 }
136 }
137 else
138 {
139 Dudley_setError(TYPE_ERROR, "Dudley_Assemble_CopyNodalData: illegal function space type for source object");
140 }
141
142 /* now we can start */
143
144 if (Dudley_noError())
145 {
146 /*********************** DUDLEY_NODES **************************************************/
147 numComps_size = (size_t) numComps *sizeof(double);
148 if (in_data_type == DUDLEY_NODES)
149 {
150 requireWrite(out);
151 if (out_data_type == DUDLEY_NODES)
152 {
153 #pragma omp parallel private(n)
154 {
155
156 #pragma omp parallel for private(n) schedule(static)
157 for (n = 0; n < nodes->nodesMapping->numNodes; n++)
158 {
159 memcpy(getSampleDataRWFast(out, n), getSampleDataROFast(in, n), numComps_size);
160 }
161 }
162 }
163 else if (out_data_type == DUDLEY_REDUCED_NODES)
164 {
165 #pragma omp parallel private(n)
166 {
167 #pragma omp for schedule(static)
168 for (n = 0; n < nodes->reducedNodesMapping->numTargets; n++)
169 {
170 memcpy(getSampleDataRWFast(out, n),
171 getSampleDataROFast(in, nodes->reducedNodesMapping->map[n]), numComps_size);
172 }
173 }
174 }
175 else if (out_data_type == DUDLEY_DEGREES_OF_FREEDOM)
176 {
177 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
178 #pragma omp parallel private(n)
179 {
180 #pragma omp for schedule(static)
181 for (n = 0; n < nComps; n++)
182 {
183 memcpy(getSampleDataRWFast(out, n),
184 getSampleDataROFast(in, nodes->degreesOfFreedomMapping->map[n]), numComps_size);
185 }
186 }
187 }
188 else if (out_data_type == DUDLEY_REDUCED_DEGREES_OF_FREEDOM)
189 {
190 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
191 #pragma omp parallel private(n)
192 {
193 #pragma omp for schedule(static)
194 for (n = 0; n < nComps; n++)
195 {
196 memcpy(getSampleDataRWFast(out, n),
197 getSampleDataROFast(in, nodes->reducedDegreesOfFreedomMapping->map[n]), numComps_size);
198 }
199 }
200 }
201 /*********************** DUDLEY_REDUCED_NODES **************************************************/
202 }
203 else if (in_data_type == DUDLEY_REDUCED_NODES)
204 {
205 requireWrite(out);
206 if (out_data_type == DUDLEY_NODES)
207 {
208 Dudley_setError(TYPE_ERROR, "Dudley_Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
209
210 }
211 else if (out_data_type == DUDLEY_REDUCED_NODES)
212 {
213 #pragma omp parallel private(n)
214 {
215 #pragma omp for schedule(static)
216 for (n = 0; n < nodes->reducedNodesMapping->numNodes; n++)
217 {
218 memcpy(getSampleDataRWFast(out, n), getSampleDataROFast(in, n), numComps_size);
219 }
220 }
221 }
222 else if (out_data_type == DUDLEY_DEGREES_OF_FREEDOM)
223 {
224 Dudley_setError(TYPE_ERROR,
225 "Dudley_Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
226 }
227 else if (out_data_type == DUDLEY_REDUCED_DEGREES_OF_FREEDOM)
228 {
229 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
230 #pragma omp parallel private(n,k)
231 {
232 #pragma omp for schedule(static)
233 for (n = 0; n < nComps; n++)
234 {
235 k = nodes->reducedDegreesOfFreedomMapping->map[n];
236 memcpy(getSampleDataRWFast(out, n),
237 getSampleDataROFast(in, nodes->reducedNodesMapping->target[k]), numComps_size);
238 }
239 }
240 }
241
242 /*********************** DUDLEY_DEGREES_OF_FREEDOM **************************************************/
243 }
244 else if (in_data_type == DUDLEY_DEGREES_OF_FREEDOM)
245 {
246 requireWrite(out);
247 if (out_data_type == DUDLEY_NODES)
248 {
249 coupler = Paso_Coupler_alloc(nodes->degreesOfFreedomConnector, numComps);
250 if (Esys_noError())
251 {
252 /* It is not immediately clear whether coupler can be trusted with constant data so I'll assume RW */
253 /* Also, it holds pointers so it might not be safe to use on lazy data anyway? */
254 requireWrite(in);
255 Paso_Coupler_startCollect(coupler, getDataRW(in));
256 recv_buffer = Paso_Coupler_finishCollect(coupler);
257 upperBound = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
258 #pragma omp parallel private(n,k)
259 {
260 #pragma omp for schedule(static)
261 for (n = 0; n < nodes->numNodes; n++)
262 {
263 k = nodes->degreesOfFreedomMapping->target[n];
264 if (k < upperBound)
265 {
266 memcpy(getSampleDataRWFast(out, n), getSampleDataROFast(in, k), numComps_size);
267 }
268 else
269 {
270 memcpy(getSampleDataRWFast(out, n),
271 &recv_buffer[(k - upperBound) * numComps], numComps_size);
272 }
273 }
274 }
275 }
276 Paso_Coupler_free(coupler);
277 }
278 else if (out_data_type == DUDLEY_REDUCED_NODES)
279 {
280 coupler = Paso_Coupler_alloc(nodes->degreesOfFreedomConnector, numComps);
281 if (Esys_noError())
282 {
283 requireWrite(in); /* See comment above about coupler and const */
284 Paso_Coupler_startCollect(coupler, getDataRW(in));
285 recv_buffer = Paso_Coupler_finishCollect(coupler);
286 upperBound = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
287 requireWrite(out);
288
289 #pragma omp parallel private(n,k,l)
290 {
291 #pragma omp for schedule(static)
292 for (n = 0; n < nodes->reducedNodesMapping->numTargets; n++)
293 {
294 l = nodes->reducedNodesMapping->map[n];
295 k = nodes->degreesOfFreedomMapping->target[l];
296 if (k < upperBound)
297 {
298 memcpy(getSampleDataRWFast(out, n), getSampleDataROFast(in, k), numComps_size);
299 }
300 else
301 {
302 memcpy(getSampleDataRWFast(out, n),
303 &recv_buffer[(k - upperBound) * numComps], numComps_size);
304 }
305 }
306 }
307 }
308 Paso_Coupler_free(coupler);
309 }
310 else if (out_data_type == DUDLEY_DEGREES_OF_FREEDOM)
311 {
312 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
313 requireWrite(out);
314 #pragma omp parallel private(n)
315 {
316 #pragma omp for schedule(static)
317 for (n = 0; n < nComps; n++)
318 {
319 memcpy(getSampleDataRWFast(out, n), getSampleDataROFast(in, n), numComps_size);
320 }
321 }
322 }
323 else if (out_data_type == DUDLEY_REDUCED_DEGREES_OF_FREEDOM)
324 {
325 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
326 requireWrite(out);
327 #pragma omp parallel private(n,k)
328 {
329 #pragma omp for schedule(static)
330 for (n = 0; n < nComps; n++)
331 {
332 k = nodes->reducedDegreesOfFreedomMapping->map[n];
333 memcpy(getSampleDataRWFast(out, n),
334 getSampleDataROFast(in, nodes->degreesOfFreedomMapping->target[k]), numComps_size);
335 }
336 }
337 }
338
339 /*********************** DUDLEY_REDUCED_DEGREES_OF_FREEDOM **************************************************/
340 }
341 else if (in_data_type == DUDLEY_REDUCED_DEGREES_OF_FREEDOM)
342 {
343
344 if (out_data_type == DUDLEY_NODES)
345 {
346 Dudley_setError(TYPE_ERROR,
347 "Dudley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
348 }
349 else if (out_data_type == DUDLEY_REDUCED_NODES)
350 {
351 coupler = Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector, numComps);
352 if (Esys_noError())
353 {
354 upperBound = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
355 requireWrite(in); /* See comment about coupler and const */
356 Paso_Coupler_startCollect(coupler, getDataRW(in));
357 recv_buffer = Paso_Coupler_finishCollect(coupler);
358 requireWrite(out);
359 #pragma omp parallel private(n,k,l)
360 {
361 #pragma omp for schedule(static)
362 for (n = 0; n < nodes->reducedNodesMapping->numTargets; n++)
363 {
364 l = nodes->reducedNodesMapping->map[n];
365 k = nodes->reducedDegreesOfFreedomMapping->target[l];
366 if (k < upperBound)
367 {
368 memcpy(getSampleDataRWFast(out, n), getSampleDataROFast(in, k), numComps_size);
369 }
370 else
371 {
372 memcpy(getSampleDataRWFast(out, n),
373 &recv_buffer[(k - upperBound) * numComps], numComps_size);
374 }
375 }
376 }
377 }
378 Paso_Coupler_free(coupler);
379 }
380 else if (out_data_type == DUDLEY_REDUCED_DEGREES_OF_FREEDOM)
381 {
382 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
383 requireWrite(out);
384 #pragma omp parallel private(n)
385 {
386 #pragma omp for schedule(static)
387 for (n = 0; n < nComps; n++)
388 {
389 memcpy(getSampleDataRWFast(out, n), getSampleDataROFast(in, n), numComps_size);
390 }
391 }
392 }
393 else if (out_data_type == DUDLEY_DEGREES_OF_FREEDOM)
394 {
395 Dudley_setError(TYPE_ERROR,
396 "Dudley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
397 }
398 }
399 }
400 return;
401 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/finley/src/Assemble_CopyNodalData.cpp:2682-2741 /branches/pasowrap/dudley/src/Assemble_CopyNodalData.cpp:3661-3674 /branches/py3_attempt2/dudley/src/Assemble_CopyNodalData.cpp:3871-3891 /branches/restext/finley/src/Assemble_CopyNodalData.cpp:2610-2624 /branches/ripleygmg_from_3668/dudley/src/Assemble_CopyNodalData.cpp:3669-3791 /branches/stage3.0/finley/src/Assemble_CopyNodalData.cpp:2569-2590 /branches/symbolic_from_3470/dudley/src/Assemble_CopyNodalData.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/dudley/src/Assemble_CopyNodalData.cpp:3517-3974 /release/3.0/finley/src/Assemble_CopyNodalData.cpp:2591-2601 /trunk/dudley/src/Assemble_CopyNodalData.cpp:4257-4344 /trunk/ripley/test/python/dudley/src/Assemble_CopyNodalData.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26