/[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 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 14905 byte(s)
Don't panic.
Updating copyright stamps

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 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
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), numComps_size);
110 }
111 }
112 } else if (out_data_type == FINLEY_REDUCED_NODES) {
113 #pragma omp parallel private(n)
114 {
115 #pragma omp for schedule(static)
116 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
117 memcpy(getSampleDataRWFast(out,n),
118 getSampleDataROFast(in,nodes->reducedNodesMapping->map[n]),
119 numComps_size);
120 }
121 }
122 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
123 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
124 #pragma omp parallel private(n)
125 {
126 #pragma omp for schedule(static)
127 for (n=0;n<nComps;n++) {
128 memcpy(getSampleDataRWFast(out,n),
129 getSampleDataROFast(in,nodes->degreesOfFreedomMapping->map[n]),
130 numComps_size);
131 }
132 }
133 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
134 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
135 #pragma omp parallel private(n)
136 {
137 #pragma omp for schedule(static)
138 for (n=0;n<nComps;n++) {
139 memcpy(getSampleDataRWFast(out,n),
140 getSampleDataROFast(in,nodes->reducedDegreesOfFreedomMapping->map[n]),
141 numComps_size);
142 }
143 }
144 }
145 /*********************** FINLEY_REDUCED_NODES **************************************************/
146 } else if (in_data_type == FINLEY_REDUCED_NODES) {
147 requireWrite(out);
148 if (out_data_type == FINLEY_NODES) {
149 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
150
151 } else if (out_data_type == FINLEY_REDUCED_NODES) {
152 #pragma omp parallel private(n)
153 {
154 #pragma omp for schedule(static)
155 for (n=0;n<nodes->reducedNodesMapping->numNodes;n++) {
156 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n),numComps_size);
157 }
158 }
159 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
160 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
161 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
162 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
163 #pragma omp parallel private(n,k)
164 {
165 #pragma omp for schedule(static)
166 for (n=0;n<nComps;n++) {
167 k=nodes->reducedDegreesOfFreedomMapping->map[n];
168 memcpy(getSampleDataRWFast(out,n),
169 getSampleDataROFast(in,nodes->reducedNodesMapping->target[k]),
170 numComps_size);
171 }
172 }
173 }
174
175 /*********************** FINLEY_DEGREES_OF_FREEDOM **************************************************/
176 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
177 requireWrite(out);
178 if (out_data_type == FINLEY_NODES) {
179 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
180 if (Paso_noError()) {
181 /* It is not immediately clear whether coupler can be trusted with constant data so I'll assume RW */
182 /* Also, it holds pointers so it might not be safe to use on lazy data anyway?*/
183 requireWrite(in);
184 Paso_Coupler_startCollect(coupler,getDataRW(in));
185 recv_buffer=Paso_Coupler_finishCollect(coupler);
186 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
187 #pragma omp parallel private(n,k)
188 {
189 #pragma omp for schedule(static)
190 for (n=0;n<nodes->numNodes;n++) {
191 k=nodes->degreesOfFreedomMapping->target[n];
192 if (k < upperBound) {
193 memcpy(getSampleDataRWFast(out,n),
194 getSampleDataROFast(in,k),
195 numComps_size);
196 } else {
197 memcpy(getSampleDataRWFast(out,n),
198 &recv_buffer[(k-upperBound)*numComps],
199 numComps_size);
200 }
201 }
202 }
203 }
204 Paso_Coupler_free(coupler);
205 } else if (out_data_type == FINLEY_REDUCED_NODES) {
206 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
207 if (Paso_noError()) {
208 requireWrite(in); /* See comment above about coupler and const */
209 Paso_Coupler_startCollect(coupler,getDataRW(in));
210 recv_buffer=Paso_Coupler_finishCollect(coupler);
211 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
212 requireWrite(out);
213
214 #pragma omp parallel private(n,k,l)
215 {
216 #pragma omp for schedule(static)
217 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
218 l=nodes->reducedNodesMapping->map[n];
219 k=nodes->degreesOfFreedomMapping->target[l];
220 if (k < upperBound) {
221 memcpy(getSampleDataRWFast(out,n),
222 getSampleDataROFast(in,k),
223 numComps_size);
224 } else {
225 memcpy(getSampleDataRWFast(out,n),
226 &recv_buffer[(k-upperBound)*numComps],
227 numComps_size);
228 }
229 }
230 }
231 }
232 Paso_Coupler_free(coupler);
233 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
234 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
235 requireWrite(out);
236 #pragma omp parallel private(n)
237 {
238 #pragma omp for schedule(static)
239 for (n=0;n<nComps;n++) {
240 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n),numComps_size);
241 }
242 }
243 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
244 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
245 requireWrite(out);
246 #pragma omp parallel private(n,k)
247 {
248 #pragma omp for schedule(static)
249 for (n=0;n<nComps;n++) {
250 k=nodes->reducedDegreesOfFreedomMapping->map[n];
251 memcpy(getSampleDataRWFast(out,n),
252 getSampleDataROFast(in,nodes->degreesOfFreedomMapping->target[k]),
253 numComps_size);
254 }
255 }
256 }
257
258 /*********************** FINLEY_REDUCED_DEGREES_OF_FREEDOM **************************************************/
259 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
260
261 if (out_data_type == FINLEY_NODES) {
262 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
263 } else if (out_data_type == FINLEY_REDUCED_NODES) {
264 coupler=Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector,numComps);
265 if (Paso_noError()) {
266 upperBound=Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
267 requireWrite(in); /* See comment about coupler and const */
268 Paso_Coupler_startCollect(coupler,getDataRW(in));
269 recv_buffer=Paso_Coupler_finishCollect(coupler);
270 requireWrite(out);
271 #pragma omp parallel private(n,k,l)
272 {
273 #pragma omp for schedule(static)
274 for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
275 l=nodes->reducedNodesMapping->map[n];
276 k=nodes->reducedDegreesOfFreedomMapping->target[l];
277 if (k < upperBound) {
278 memcpy(getSampleDataRWFast(out,n),
279 getSampleDataROFast(in,k),
280 numComps_size);
281 } else {
282 memcpy(getSampleDataRWFast(out,n),
283 &recv_buffer[(k-upperBound)*numComps],
284 numComps_size);
285 }
286 }
287 }
288 }
289 Paso_Coupler_free(coupler);
290 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
291 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
292 requireWrite(out);
293 #pragma omp parallel private(n)
294 {
295 #pragma omp for schedule(static)
296 for (n=0;n<nComps;n++) {
297 memcpy(getSampleDataRWFast(out,n),getSampleDataROFast(in,n),numComps_size);
298 }
299 }
300 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
301 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
302 }
303 }
304 }
305 return;
306 }
307

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26