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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4346 - (hide annotations)
Tue Apr 2 04:46:45 2013 UTC (6 years, 5 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 jgs 82
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 4154 * Copyright (c) 2003-2013 by University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
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 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     * Development since 2012 by School of Earth Sciences
13     *
14     *****************************************************************************/
15 ksteube 1312
16 jfenwick 3981 /************************************************************************************/
17 jgs 82
18 ksteube 1312 /* assemblage routines: copies data between different types nodal representation */
19 jgs 82
20 jfenwick 3981 /************************************************************************************/
21 jgs 82
22     #include "Util.h"
23     #include "Assemble.h"
24     #ifdef _OPENMP
25     #include <omp.h>
26     #endif
27    
28 jfenwick 3224 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 ksteube 1312 index_t upperBound;
36 jfenwick 3224 double *recv_buffer;
37     size_t numComps_size = 0;
38 jfenwick 3086 Dudley_resetError();
39 jfenwick 3224 if (nodes == NULL)
40     return;
41     mpiSize = nodes->MPIInfo->size;
42 jgs 82
43     /* check out and in */
44 jfenwick 3224 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 jgs 82 }
49 jfenwick 3224 else if (!isExpanded(out))
50     {
51     Dudley_setError(TYPE_ERROR, "Dudley_Assemble_CopyNodalData: expanded Data object is expected for output data.");
52     }
53 jgs 82
54 bcumming 751 /* more sophisticated test needed for overlapping node/DOF counts */
55 jfenwick 3224 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 ksteube 1312
82 jfenwick 3224 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 ksteube 1312
96 jfenwick 3224 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 jgs 82 }
100 jfenwick 3224 else
101     {
102     Dudley_setError(TYPE_ERROR, "Dudley_Assemble_CopyNodalData: illegal function space type for target object");
103 jgs 82 }
104    
105 jfenwick 3224 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 jgs 82 /* now we can start */
143 ksteube 1312
144 jfenwick 3224 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 jfenwick 2271 }
162 jfenwick 3224 }
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 jfenwick 2271 }
174 jfenwick 3224 }
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 jfenwick 2271 }
187 jfenwick 3224 }
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 ksteube 1312
210 jfenwick 3224 }
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 jfenwick 2271 }
221 jfenwick 3224 }
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 jfenwick 2271 }
240 jfenwick 3224 }
241 ksteube 1312
242 jfenwick 3224 /*********************** DUDLEY_DEGREES_OF_FREEDOM **************************************************/
243     }
244     else if (in_data_type == DUDLEY_DEGREES_OF_FREEDOM)
245     {
246 jfenwick 2271 requireWrite(out);
247 jfenwick 3224 if (out_data_type == DUDLEY_NODES)
248     {
249     coupler = Paso_Coupler_alloc(nodes->degreesOfFreedomConnector, numComps);
250 jfenwick 3227 if (Esys_noError())
251 jfenwick 3224 {
252 jfenwick 2271 /* It is not immediately clear whether coupler can be trusted with constant data so I'll assume RW */
253 jfenwick 3224 /* Also, it holds pointers so it might not be safe to use on lazy data anyway? */
254 jfenwick 2271 requireWrite(in);
255 jfenwick 3224 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 jfenwick 2271 {
260 jfenwick 3224 #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 jfenwick 2271 }
275 jfenwick 3224 }
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 jfenwick 3227 if (Esys_noError())
282 jfenwick 3224 {
283 jfenwick 2271 requireWrite(in); /* See comment above about coupler and const */
284 jfenwick 3224 Paso_Coupler_startCollect(coupler, getDataRW(in));
285     recv_buffer = Paso_Coupler_finishCollect(coupler);
286     upperBound = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
287 jfenwick 2271 requireWrite(out);
288    
289 jfenwick 3224 #pragma omp parallel private(n,k,l)
290 jfenwick 2271 {
291 jfenwick 3224 #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 jfenwick 2271 }
307 jfenwick 3224 }
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 ksteube 1312
339 jfenwick 3224 /*********************** DUDLEY_REDUCED_DEGREES_OF_FREEDOM **************************************************/
340     }
341     else if (in_data_type == DUDLEY_REDUCED_DEGREES_OF_FREEDOM)
342     {
343 ksteube 1312
344 jfenwick 3224 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 jfenwick 3227 if (Esys_noError())
353 jfenwick 3224 {
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 jfenwick 2271 requireWrite(out);
359 jfenwick 3224 #pragma omp parallel private(n,k,l)
360 jfenwick 2271 {
361 jfenwick 3224 #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 jfenwick 2271 }
377 jfenwick 3224 }
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 jgs 82 }

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