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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1552 - (hide annotations)
Thu May 8 08:52:41 2008 UTC (11 years, 5 months ago) by gross
File MIME type: text/plain
File size: 13920 byte(s)
some changes to make the implementatiopn of a upwind MPI version easier
1 jgs 82
2 ksteube 1312 /* $Id$ */
3 jgs 82
4 ksteube 1312 /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 jgs 82 /**************************************************************/
17    
18 ksteube 1312 /* assemblage routines: copies data between different types nodal representation */
19 jgs 82
20     /**************************************************************/
21    
22     #include "Util.h"
23     #include "Assemble.h"
24     #ifdef _OPENMP
25     #include <omp.h>
26     #endif
27    
28     void Finley_Assemble_CopyNodalData(Finley_NodeFile* nodes,escriptDataC* out,escriptDataC* in) {
29 ksteube 1312 dim_t n,i,k,l, mpiSize;
30 jgs 123 dim_t numComps=getDataPointSize(out);
31 gross 1552 Paso_Coupler *coupler=NULL;
32 jgs 123 type_t in_data_type=getFunctionSpaceType(in);
33     type_t out_data_type=getFunctionSpaceType(out);
34 ksteube 1312 index_t upperBound;
35     double* recv_buffer;
36     size_t numComps_size=0;
37 jgs 150 Finley_resetError();
38 gross 1028 if (nodes==NULL) return;
39 ksteube 1312 mpiSize=nodes->MPIInfo->size;
40 jgs 82
41     /* check out and in */
42     if (numComps!=getDataPointSize(in)) {
43 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: number of components of input and output Data do not match.");
44 jgs 82 } else if (!isExpanded(out)) {
45 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: expanded Data object is expected for output data.");
46 jgs 82 }
47    
48 bcumming 751 /* more sophisticated test needed for overlapping node/DOF counts */
49 jgs 82 if (in_data_type == FINLEY_NODES) {
50 ksteube 1312 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumNodes(nodes))) {
51 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
52 jgs 82 }
53 gross 1062 } else if (in_data_type == FINLEY_REDUCED_NODES) {
54 ksteube 1312 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumReducedNodes(nodes))) {
55     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
56     }
57 jgs 82 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
58 ksteube 1312 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
59 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
60 jgs 82 }
61 ksteube 1312 if ( (((out_data_type == FINLEY_NODES) || (out_data_type == FINLEY_DEGREES_OF_FREEDOM)) && !isExpanded(in) && (mpiSize>1))) {
62    
63     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.");
64     }
65 jgs 82 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
66 ksteube 1312 if (! numSamplesEqual(in,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
67     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of input Data object");
68 jgs 82 }
69 ksteube 1312 if ( (out_data_type == FINLEY_DEGREES_OF_FREEDOM) && !isExpanded(in) && (mpiSize>1)) {
70    
71     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.");
72     }
73 jgs 82 } else {
74 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for target object");
75 jgs 82 }
76    
77     if (out_data_type == FINLEY_NODES) {
78 ksteube 1312 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumNodes(nodes))) {
79 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
80 jgs 82 }
81 gross 1062 } else if (out_data_type == FINLEY_REDUCED_NODES) {
82 ksteube 1312 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedNodes(nodes))) {
83     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
84     }
85 jgs 82 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
86 ksteube 1312 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumDegreesOfFreedom(nodes))) {
87 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
88 jgs 82 }
89     } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
90 ksteube 1312 if (! numSamplesEqual(out,1,Finley_NodeFile_getNumReducedDegreesOfFreedom(nodes))) {
91 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal number of samples of output Data object");
92 jgs 82 }
93     } else {
94 gross 1062 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: illegal function space type for source object");
95 jgs 82 }
96    
97     /* now we can start */
98 bcumming 751
99 jgs 150 if (Finley_noError()) {
100 ksteube 1312 /*********************** FINLEY_NODES **************************************************/
101     numComps_size=(size_t)numComps*sizeof(double);
102 jgs 82 if (in_data_type == FINLEY_NODES) {
103 ksteube 1312
104 jgs 82 if (out_data_type == FINLEY_NODES) {
105     #pragma omp parallel for private(n) schedule(static)
106 ksteube 1312 for (n=0;n<nodes->nodesMapping->numNodes;n++) {
107     memcpy(getSampleDataFast(out,n), getSampleDataFast(in,n), numComps_size);
108     }
109    
110     } else if (out_data_type == FINLEY_REDUCED_NODES) {
111     #pragma omp parallel for private(n,i) schedule(static)
112     for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
113     memcpy(getSampleDataFast(out,n),
114     getSampleDataFast(in,nodes->reducedNodesMapping->map[n]),
115     numComps_size);
116     }
117 jgs 82 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
118 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
119 jgs 82 #pragma omp parallel for private(n) schedule(static)
120 ksteube 1312 for (n=0;n<nComps;n++) {
121     memcpy(getSampleDataFast(out,n),
122     getSampleDataFast(in,nodes->degreesOfFreedomMapping->map[n]),
123     numComps_size);
124     }
125    
126 jgs 82 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
127 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
128 jgs 82 #pragma omp parallel for private(n,i) schedule(static)
129 ksteube 1312 for (n=0;n<nComps;n++) {
130     memcpy(getSampleDataFast(out,n),
131     getSampleDataFast(in,nodes->reducedDegreesOfFreedomMapping->map[n]),
132     numComps_size);
133 jgs 82 }
134     }
135 ksteube 1312 /*********************** FINLEY_REDUCED_NODES **************************************************/
136 gross 1062 } else if (in_data_type == FINLEY_REDUCED_NODES) {
137 ksteube 1312
138 gross 1062 if (out_data_type == FINLEY_NODES) {
139     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
140 ksteube 1312
141     } else if (out_data_type == FINLEY_REDUCED_NODES) {
142     #pragma omp parallel for private(n) schedule(static)
143     for (n=0;n<nodes->reducedNodesMapping->numNodes;n++) {
144     memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
145     }
146    
147 gross 1062 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
148     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
149     } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
150 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
151     #pragma omp parallel for private(n,k) schedule(static)
152     for (n=0;n<nComps;n++) {
153     k=nodes->reducedDegreesOfFreedomMapping->map[n];
154     memcpy(getSampleDataFast(out,n),
155     getSampleDataFast(in,nodes->reducedNodesMapping->target[k]),
156     numComps_size);
157     }
158 gross 1062 }
159 ksteube 1312
160     /*********************** FINLEY_DEGREES_OF_FREEDOM **************************************************/
161 jgs 82 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
162 ksteube 1312
163     if (out_data_type == FINLEY_NODES) {
164 gross 1552 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
165 ksteube 1312 if (Paso_noError()) {
166 gross 1552 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
167     recv_buffer=Paso_Coupler_finishCollect(coupler);
168 ksteube 1312 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
169     #pragma omp parallel for private(n,k) schedule(static)
170     for (n=0;n<nodes->numNodes;n++) {
171     k=nodes->degreesOfFreedomMapping->target[n];
172     if (k < upperBound) {
173     memcpy(getSampleDataFast(out,n),
174     getSampleDataFast(in,k),
175     numComps_size);
176     } else {
177     memcpy(getSampleDataFast(out,n),
178     &recv_buffer[(k-upperBound)*numComps],
179     numComps_size);
180     }
181     }
182     }
183 gross 1552 Paso_Coupler_free(coupler);
184 ksteube 1312 } else if (out_data_type == FINLEY_REDUCED_NODES) {
185 gross 1552 coupler=Paso_Coupler_alloc(nodes->degreesOfFreedomConnector,numComps);
186 ksteube 1312 if (Paso_noError()) {
187 gross 1552 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
188     recv_buffer=Paso_Coupler_finishCollect(coupler);
189 ksteube 1312 upperBound=Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
190     #pragma omp parallel for private(n,k,l) schedule(static)
191     for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
192     l=nodes->reducedNodesMapping->map[n];
193     k=nodes->degreesOfFreedomMapping->target[l];
194     if (k < upperBound) {
195     memcpy(getSampleDataFast(out,n),
196     getSampleDataFast(in,k),
197     numComps_size);
198     } else {
199     memcpy(getSampleDataFast(out,n),
200     &recv_buffer[(k-upperBound)*numComps],
201     numComps_size);
202     }
203     }
204     }
205 gross 1552 Paso_Coupler_free(coupler);
206 jgs 82 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
207 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->degreesOfFreedomDistribution);
208 jgs 82 #pragma omp parallel for private(n) schedule(static)
209 ksteube 1312 for (n=0;n<nComps;n++) {
210     memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
211     }
212    
213 jgs 82 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
214 ksteube 1312 int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
215     #pragma omp parallel for private(n,k) schedule(static)
216     for (n=0;n<nComps;n++) {
217     k=nodes->reducedDegreesOfFreedomMapping->map[n];
218     memcpy(getSampleDataFast(out,n),
219     getSampleDataFast(in,nodes->degreesOfFreedomMapping->target[k]),
220     numComps_size);
221 jgs 82 }
222     }
223 ksteube 1312
224 gross 1062 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
225 ksteube 1312
226     if (out_data_type == FINLEY_NODES) {
227     Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
228    
229     } else if (out_data_type == FINLEY_REDUCED_NODES) {
230 gross 1552 coupler=Paso_Coupler_alloc(nodes->reducedDegreesOfFreedomConnector,numComps);
231 ksteube 1312 if (Paso_noError()) {
232 gross 1552 Paso_Coupler_startCollect(coupler,getSampleDataFast(in,0));
233     recv_buffer=Paso_Coupler_finishCollect(coupler);
234 ksteube 1312 upperBound=Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
235     #pragma omp parallel for private(n,k,l) schedule(static)
236     for (n=0;n<nodes->reducedNodesMapping->numTargets;n++) {
237     l=nodes->reducedNodesMapping->map[n];
238     k=nodes->reducedDegreesOfFreedomMapping->target[l];
239     if (k < upperBound) {
240     memcpy(getSampleDataFast(out,n),
241     getSampleDataFast(in,k),
242     numComps_size);
243     } else {
244     memcpy(getSampleDataFast(out,n),
245     &recv_buffer[(k-upperBound)*numComps],
246     numComps_size);
247     }
248     }
249     }
250 gross 1552 Paso_Coupler_free(coupler);
251 ksteube 1312 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
252     int nComps = Paso_Distribution_getMyNumComponents(nodes->reducedDegreesOfFreedomDistribution);
253 jgs 82 #pragma omp parallel for private(n) schedule(static)
254 ksteube 1312 for (n=0;n<nComps;n++) {
255     memcpy(getSampleDataFast(out,n),getSampleDataFast(in,n),numComps_size);
256     }
257    
258 bcumming 782 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
259 ksteube 1312 Finley_setError(TYPE_ERROR,"Finley_Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
260 jgs 82 }
261 jgs 147 }
262 jgs 82 }
263     return;
264     }
265 bcumming 751

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26