/[escript]/branches/arrexp_2137_win_merge/finley/src/Assemble_CopyNodalData.c
ViewVC logotype

Contents of /branches/arrexp_2137_win_merge/finley/src/Assemble_CopyNodalData.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2226 - (show annotations)
Thu Jan 22 05:11:02 2009 UTC (10 years, 4 months ago) by jfenwick
File MIME type: text/plain
File size: 15628 byte(s)
It continues
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 #pragma omp parallel private(n)
105 {
106 void* buff=allocSampleBuffer(in);
107 #pragma omp parallel for private(n) schedule(static)
108 for (n=0;n<nodes->nodesMapping->numNodes;n++) {
109 memcpy(getSampleDataRWFast(out,n), getSampleDataROFast(in,n,buff), numComps_size);
110 }
111 freeSampleBuffer(buff);
112 }
113
114 } else if (out_data_type == FINLEY_REDUCED_NODES) {
115 #pragma omp parallel private(n)
116 {
117 void* buff=allocSampleBuffer(in);
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 freeSampleBuffer(buff);
125 }
126 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
127 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
128 #pragma omp parallel private(n)
129 {
130 void* buff=allocSampleBuffer(in);
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 freeSampleBuffer(buff);
138 }
139
140 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
141 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
142 #pragma omp parallel private(n)
143 {
144 void* buff=allocSampleBuffer(in);
145 #pragma omp parallel for private(n) schedule(static)
146 for (n=0;n<nComps;n++) {
147 memcpy(getSampleDataRWFast(out,n),
148 getSampleDataROFast(in,nodes->reducedDegreesOfFreedomMapping->map[n],buff),
149 numComps_size);
150 }
151 freeSampleBuffer(buff);
152 }
153 }
154 /*********************** FINLEY_REDUCED_NODES **************************************************/
155 } else if (in_data_type == FINLEY_REDUCED_NODES) {
156 requireWrite(out);
157 if (out_data_type == FINLEY_NODES) {
158 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
159
160 } else if (out_data_type == FINLEY_REDUCED_NODES) {
161 #pragma omp parallel private(n)
162 {
163 void* buff=allocSampleBuffer(in);
164 #pragma omp for schedule(static)
165 for (n=0;n<nodes->reducedNodesMapping->numNodes;n++) {
166 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n,buff),numComps_size);
167 }
168 freeSampleBuffer(buff);
169 }
170
171 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
172 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
173 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
174 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
175 #pragma omp parallel private(n,k)
176 {
177 void* buff=allocSampleBuffer(in);
178 #pragma omp for schedule(static)
179 for (n=0;n<nComps;n++) {
180 k=nodes->reducedDegreesOfFreedomMapping->map[n];
181 memcpy(getSampleDataRWFast(out,n),
182 getSampleDataROFast(in,nodes->reducedNodesMapping->target[k],buff),
183 numComps_size);
184 }
185 freeSampleBuffer(buff);
186 }
187 }
188
189 /*********************** FINLEY_DEGREES_OF_FREEDOM **************************************************/
190 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
191 requireWrite(out);
192 if (out_data_type == FINLEY_NODES) {
193 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
194 if (Paso_noError()) {
195 /* It is not immediately clear whether coupler can be trusted with constant data so I'll assume RW */
196 /* Also, it holds pointers so it might not be safe to use on lazy data anyway?*/
197 requireWrite(in);
198 Paso_Coupler_startCollect(coupler,getSampleDataRWFast(in,0));
199 recv_buffer=Paso_Coupler_finishCollect(coupler);
200 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
201 #pragma omp parallel private(n,k)
202 {
203 void* buff=allocSampleBuffer(in);
204 #pragma omp for schedule(static)
205 for (n=0;n<nodes->numNodes;n++) {
206 k=nodes->degreesOfFreedomMapping->target[n];
207 if (k < upperBound) {
208 memcpy(getSampleDataRWFast(out,n),
209 getSampleDataROFast(in,k,buff),
210 numComps_size);
211 } else {
212 memcpy(getSampleDataRWFast(out,n),
213 &recv_buffer[(k-upperBound)*numComps],
214 numComps_size);
215 }
216 }
217 freeSampleBuffer(buff);
218 }
219 }
220 Paso_Coupler_free(coupler);
221 } else if (out_data_type == FINLEY_REDUCED_NODES) {
222 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
223 if (Paso_noError()) {
224 requireWrite(in); /* See comment above about coupler and const */
225 Paso_Coupler_startCollect(coupler,getSampleDataRWFast(in,0));
226 recv_buffer=Paso_Coupler_finishCollect(coupler);
227 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
228 requireWrite(out);
229 #pragma omp parallel private(n,k,l)
230 {
231 void* buff=allocSampleBuffer(in);
232 #pragma omp for schedule(static)
233 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
234 l=nodes->reducedNodesMapping->map[n];
235 k=nodes->degreesOfFreedomMapping->target[l];
236 if (k < upperBound) {
237 memcpy(getSampleDataRWFast(out,n),
238 getSampleDataROFast(in,k,buff),
239 numComps_size);
240 } else {
241 memcpy(getSampleDataRWFast(out,n),
242 &recv_buffer[(k-upperBound)*numComps],
243 numComps_size);
244 }
245 }
246 freeSampleBuffer(buff);
247 }
248 }
249 Paso_Coupler_free(coupler);
250 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
251 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
252 requireWrite(out);
253 #pragma omp parallel private(n)
254 {
255 void* buff=allocSampleBuffer(in);
256 #pragma omp for schedule(static)
257 for (n=0;n<nComps;n++) {
258 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n,buff),numComps_size);
259 }
260 freeSampleBuffer(buff);
261 }
262
263 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
264 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
265 requireWrite(out);
266 #pragma omp parallel private(n,k)
267 {
268 void* buff=allocSampleBuffer(in);
269 #pragma omp for schedule(static)
270 for (n=0;n<nComps;n++) {
271 k=nodes->reducedDegreesOfFreedomMapping->map[n];
272 memcpy(getSampleDataRWFast(out,n),
273 getSampleDataROFast(in,nodes->degreesOfFreedomMapping->target[k],buff),
274 numComps_size);
275 }
276 freeSampleBuffer(buff);
277 }
278 }
279
280 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
281
282 if (out_data_type == FINLEY_NODES) {
283 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
284 } else if (out_data_type == FINLEY_REDUCED_NODES) {
285 coupler=Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector,numComps);
286 if (Paso_noError()) {
287 upperBound=Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
288 requireWrite(in); /* See comment about coupler and const */
289 Paso_Coupler_startCollect(coupler,getSampleDataRWFast(in,0));
290 recv_buffer=Paso_Coupler_finishCollect(coupler);
291 requireWrite(out);
292 #pragma omp parallel private(n,k,l)
293 {
294 void* buff=allocSampleBuffer(in);
295 #pragma omp for schedule(static)
296 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
297 l=nodes->reducedNodesMapping->map[n];
298 k=nodes->reducedDegreesOfFreedomMapping->target[l];
299 if (k < upperBound) {
300 memcpy(getSampleDataRWFast(out,n),
301 getSampleDataROFast(in,k,buff),
302 numComps_size);
303 } else {
304 memcpy(getSampleDataRWFast(out,n),
305 &recv_buffer[(k-upperBound)*numComps],
306 numComps_size);
307 }
308 }
309 freeSampleBuffer(buff);
310 }
311 }
312 Paso_Coupler_free(coupler);
313 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
314 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
315 requireWrite(out);
316 #pragma omp parallel private(n)
317 {
318 void* buff=allocSampleBuffer(in);
319 #pragma omp for schedule(static)
320 for (n=0;n<nComps;n++) {
321 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n,buff),numComps_size);
322 }
323 }
324 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
325 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
326 }
327 }
328 }
329 return;
330 }
331

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26