/[escript]/trunk/finley/src/Assemble_CopyNodalData.c
ViewVC logotype

Contents of /trunk/finley/src/Assemble_CopyNodalData.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2271 - (show annotations)
Mon Feb 16 05:08:29 2009 UTC (10 years, 9 months ago) by jfenwick
File MIME type: text/plain
File size: 15709 byte(s)
Merging version 2269 to trunk

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* assemblage routines: copies data between different types nodal representation */
18
19 /**************************************************************/
20
21 #include "Util.h"
22 #include "Assemble.h"
23 #ifdef _OPENMP
24 #include <omp.h>
25 #endif
26
27 void Finley_Assemble_CopyNodalData(Finley_NodeFile* nodes,escriptDataC* out,escriptDataC* in) {
28 dim_t n,k,l, mpiSize;
29 dim_t numComps=getDataPointSize(out);
30 Paso_Coupler *coupler=NULL;
31 type_t in_data_type=getFunctionSpaceType(in);
32 type_t out_data_type=getFunctionSpaceType(out);
33 index_t upperBound;
34 double* recv_buffer;
35 size_t numComps_size=0;
36 Finley_resetError();
37 if (nodes==NULL) return;
38 mpiSize=nodes->MPIInfo->size;
39
40 /* check out and in */
41 if (numComps!=getDataPointSize(in)) {
42 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: number of components of input and output Data do not match.");
43 } else if (!isExpanded(out)) {
44 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: expanded Data object is expected for output data.");
45 }
46
47 /* more sophisticated test needed for overlapping node/DOF counts */
48 if (in_data_type == FINLEY_NODES) {
49 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumNodes(nodes))) {
50 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
51 }
52 } else if (in_data_type == FINLEY_REDUCED_NODES) {
53 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumReducedNodes(nodes))) {
54 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
55 }
56 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
57 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
58 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
59 }
60 if ( (((out_data_type == FINLEY_NODES) || (out_data_type == FINLEY_DEGREES_OF_FREEDOM)) && !isExpanded(in) && (mpiSize>1))) {
61
62 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: FINLEY_DEGREES_OF_FREEDOM to FINLEY_NODES or FINLEY_DEGREES_OF_FREEDOM requires expanded input data on more than one processor.");
63 }
64 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
65 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
66 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
67 }
68 if ( (out_data_type == FINLEY_DEGREES_OF_FREEDOM) && !isExpanded(in) && (mpiSize>1)) {
69
70 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: FINLEY_REDUCED_DEGREES_OF_FREEDOM to FINLEY_DEGREES_OF_FREEDOM requires expanded input data on more than one processor.");
71 }
72 } else {
73 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for target object");
74 }
75
76 if (out_data_type == FINLEY_NODES) {
77 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumNodes(nodes))) {
78 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
79 }
80 } else if (out_data_type == FINLEY_REDUCED_NODES) {
81 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedNodes(nodes))) {
82 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
83 }
84 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
85 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
86 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
87 }
88 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
89 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
90 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
91 }
92 } else {
93 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for source object");
94 }
95
96 /* now we can start */
97
98 if (Finley_noError()) {
99 /*********************** FINLEY_NODES **************************************************/
100 numComps_size=(size_t)numComps*sizeof(double);
101 if (in_data_type == FINLEY_NODES) {
102 requireWrite(out);
103 if (out_data_type == FINLEY_NODES) {
104 void* buff=allocSampleBuffer(in);
105 #pragma omp parallel private(n)
106 {
107
108 #pragma omp parallel for private(n) schedule(static)
109 for (n=0;n<nodes->nodesMapping->numNodes;n++) {
110 memcpy(getSampleDataRWFast(out,n), getSampleDataROFast(in,n,buff), numComps_size);
111 }
112 }
113 freeSampleBuffer(buff);
114 } else if (out_data_type == FINLEY_REDUCED_NODES) {
115 void* buff=allocSampleBuffer(in);
116 #pragma omp parallel private(n)
117 {
118 #pragma omp for schedule(static)
119 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
120 memcpy(getSampleDataRWFast(out,n),
121 getSampleDataROFast(in,nodes->reducedNodesMapping->map[n],buff),
122 numComps_size);
123 }
124 }
125 freeSampleBuffer(buff);
126 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
127 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
128 void* buff=allocSampleBuffer(in);
129 #pragma omp parallel private(n)
130 {
131 #pragma omp for schedule(static)
132 for (n=0;n<nComps;n++) {
133 memcpy(getSampleDataRWFast(out,n),
134 getSampleDataROFast(in,nodes->degreesOfFreedomMapping->map[n],buff),
135 numComps_size);
136 }
137 }
138 freeSampleBuffer(buff);
139 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
140 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
141 void* buff=allocSampleBuffer(in);
142 #pragma omp parallel private(n)
143 {
144 #pragma omp for schedule(static)
145 for (n=0;n<nComps;n++) {
146 memcpy(getSampleDataRWFast(out,n),
147 getSampleDataROFast(in,nodes->reducedDegreesOfFreedomMapping->map[n],buff),
148 numComps_size);
149 }
150 }
151 freeSampleBuffer(buff);
152 }
153 /*********************** FINLEY_REDUCED_NODES **************************************************/
154 } else if (in_data_type == FINLEY_REDUCED_NODES) {
155 requireWrite(out);
156 if (out_data_type == FINLEY_NODES) {
157 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
158
159 } else if (out_data_type == FINLEY_REDUCED_NODES) {
160 void* buff=allocSampleBuffer(in);
161 #pragma omp parallel private(n)
162 {
163 #pragma omp for schedule(static)
164 for (n=0;n<nodes->reducedNodesMapping->numNodes;n++) {
165 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n,buff),numComps_size);
166 }
167 }
168 freeSampleBuffer(buff);
169 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
170 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
171 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
172 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
173 void* buff=allocSampleBuffer(in);
174 #pragma omp parallel private(n,k)
175 {
176 #pragma omp for schedule(static)
177 for (n=0;n<nComps;n++) {
178 k=nodes->reducedDegreesOfFreedomMapping->map[n];
179 memcpy(getSampleDataRWFast(out,n),
180 getSampleDataROFast(in,nodes->reducedNodesMapping->target[k],buff),
181 numComps_size);
182 }
183 }
184 freeSampleBuffer(buff);
185 }
186
187 /*********************** FINLEY_DEGREES_OF_FREEDOM **************************************************/
188 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
189 requireWrite(out);
190 if (out_data_type == FINLEY_NODES) {
191 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
192 if (Paso_noError()) {
193 void* buff=allocSampleBuffer(in);
194 /* It is not immediately clear whether coupler can be trusted with constant data so I'll assume RW */
195 /* Also, it holds pointers so it might not be safe to use on lazy data anyway?*/
196 requireWrite(in);
197 Paso_Coupler_startCollect(coupler,getSampleDataRWFast(in,0));
198 recv_buffer=Paso_Coupler_finishCollect(coupler);
199 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
200 #pragma omp parallel private(n,k)
201 {
202 #pragma omp for schedule(static)
203 for (n=0;n<nodes->numNodes;n++) {
204 k=nodes->degreesOfFreedomMapping->target[n];
205 if (k < upperBound) {
206 memcpy(getSampleDataRWFast(out,n),
207 getSampleDataROFast(in,k,buff),
208 numComps_size);
209 } else {
210 memcpy(getSampleDataRWFast(out,n),
211 &recv_buffer[(k-upperBound)*numComps],
212 numComps_size);
213 }
214 }
215 }
216 freeSampleBuffer(buff);
217 }
218 Paso_Coupler_free(coupler);
219 } else if (out_data_type == FINLEY_REDUCED_NODES) {
220 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
221 if (Paso_noError()) {
222 void* buff=allocSampleBuffer(in);
223 requireWrite(in); /* See comment above about coupler and const */
224 Paso_Coupler_startCollect(coupler,getSampleDataRWFast(in,0));
225 recv_buffer=Paso_Coupler_finishCollect(coupler);
226 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
227 requireWrite(out);
228
229 #pragma omp parallel private(n,k,l)
230 {
231 #pragma omp for schedule(static)
232 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
233 l=nodes->reducedNodesMapping->map[n];
234 k=nodes->degreesOfFreedomMapping->target[l];
235 if (k < upperBound) {
236 memcpy(getSampleDataRWFast(out,n),
237 getSampleDataROFast(in,k,buff),
238 numComps_size);
239 } else {
240 memcpy(getSampleDataRWFast(out,n),
241 &recv_buffer[(k-upperBound)*numComps],
242 numComps_size);
243 }
244 }
245 }
246 freeSampleBuffer(buff);
247 }
248 Paso_Coupler_free(coupler);
249 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
250 void* buff=allocSampleBuffer(in);
251 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
252 requireWrite(out);
253 #pragma omp parallel private(n)
254 {
255 #pragma omp for schedule(static)
256 for (n=0;n<nComps;n++) {
257 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n,buff),numComps_size);
258 }
259 }
260 freeSampleBuffer(buff);
261 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
262 void* buff=allocSampleBuffer(in);
263 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
264 requireWrite(out);
265 #pragma omp parallel private(n,k)
266 {
267 #pragma omp for schedule(static)
268 for (n=0;n<nComps;n++) {
269 k=nodes->reducedDegreesOfFreedomMapping->map[n];
270 memcpy(getSampleDataRWFast(out,n),
271 getSampleDataROFast(in,nodes->degreesOfFreedomMapping->target[k],buff),
272 numComps_size);
273 }
274 }
275 freeSampleBuffer(buff);
276 }
277
278 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
279
280 if (out_data_type == FINLEY_NODES) {
281 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
282 } else if (out_data_type == FINLEY_REDUCED_NODES) {
283 coupler=Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector,numComps);
284 if (Paso_noError()) {
285 void* buff=allocSampleBuffer(in);
286 upperBound=Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
287 requireWrite(in); /* See comment about coupler and const */
288 Paso_Coupler_startCollect(coupler,getSampleDataRWFast(in,0));
289 recv_buffer=Paso_Coupler_finishCollect(coupler);
290 requireWrite(out);
291 #pragma omp parallel private(n,k,l)
292 {
293 #pragma omp for schedule(static)
294 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
295 l=nodes->reducedNodesMapping->map[n];
296 k=nodes->reducedDegreesOfFreedomMapping->target[l];
297 if (k < upperBound) {
298 memcpy(getSampleDataRWFast(out,n),
299 getSampleDataROFast(in,k,buff),
300 numComps_size);
301 } else {
302 memcpy(getSampleDataRWFast(out,n),
303 &recv_buffer[(k-upperBound)*numComps],
304 numComps_size);
305 }
306 }
307 }
308 freeSampleBuffer(buff);
309 }
310 Paso_Coupler_free(coupler);
311 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
312 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
313 void* buff=allocSampleBuffer(in);
314 requireWrite(out);
315 #pragma omp parallel private(n)
316 {
317 #pragma omp for schedule(static)
318 for (n=0;n<nComps;n++) {
319 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n,buff),numComps_size);
320 }
321 }
322 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
323 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
324 }
325 }
326 }
327 return;
328 }
329

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26