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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (4 years, 11 months ago) by caltinay
File size: 12145 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17
18 /****************************************************************************
19
20 Assemblage routines: copies data between different types of nodal
21 representations
22
23 *****************************************************************************/
24
25 #include "Assemble.h"
26 #include "Util.h"
27
28 namespace finley {
29
30 void Assemble_CopyNodalData(const NodeFile* nodes, escript::Data& out,
31 const escript::Data& in)
32 {
33 resetError();
34 if (!nodes)
35 return;
36
37 const int mpiSize = nodes->MPIInfo->size;
38 const int numComps = out.getDataPointSize();
39 const int in_data_type=in.getFunctionSpace().getTypeCode();
40 const int out_data_type=out.getFunctionSpace().getTypeCode();
41
42 // check out and in
43 if (numComps != in.getDataPointSize()) {
44 setError(TYPE_ERROR,"Assemble_CopyNodalData: number of components of input and output Data do not match.");
45 } else if (!out.actsExpanded()) {
46 setError(TYPE_ERROR,"Assemble_CopyNodalData: expanded Data object is expected for output data.");
47 }
48
49 // more sophisticated test needed for overlapping node/DOF counts
50 if (in_data_type == FINLEY_NODES) {
51 if (!in.numSamplesEqual(1, nodes->getNumNodes())) {
52 setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of input Data object");
53 }
54 } else if (in_data_type == FINLEY_REDUCED_NODES) {
55 if (!in.numSamplesEqual(1, nodes->getNumReducedNodes())) {
56 setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of input Data object");
57 }
58 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
59 if (!in.numSamplesEqual(1, nodes->getNumDegreesOfFreedom())) {
60 setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of input Data object");
61 }
62 if (((out_data_type == FINLEY_NODES) || (out_data_type == FINLEY_DEGREES_OF_FREEDOM)) && !in.actsExpanded() && (mpiSize>1)) {
63 setError(TYPE_ERROR,"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 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
66 if (!in.numSamplesEqual(1, nodes->getNumReducedDegreesOfFreedom())) {
67 setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of input Data object");
68 }
69 if ((out_data_type == FINLEY_DEGREES_OF_FREEDOM) && !in.actsExpanded() && (mpiSize>1)) {
70 setError(TYPE_ERROR,"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 setError(TYPE_ERROR, "Assemble_CopyNodalData: illegal function space type for target object");
74 }
75
76 int numOut=0;
77 switch (out_data_type) {
78 case FINLEY_NODES:
79 numOut=nodes->getNumNodes();
80 break;
81
82 case FINLEY_REDUCED_NODES:
83 numOut=nodes->getNumReducedNodes();
84 break;
85
86 case FINLEY_DEGREES_OF_FREEDOM:
87 numOut=nodes->getNumDegreesOfFreedom();
88 break;
89
90 case FINLEY_REDUCED_DEGREES_OF_FREEDOM:
91 numOut=nodes->getNumReducedDegreesOfFreedom();
92 break;
93
94 default:
95 setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal function space type for source object");
96 }
97
98 if (!out.numSamplesEqual(1, numOut)) {
99 setError(TYPE_ERROR,"Assemble_CopyNodalData: illegal number of samples of output Data object");
100 }
101
102 if (!noError())
103 return;
104
105 const size_t numComps_size = numComps*sizeof(double);
106
107 /*********************** FINLEY_NODES ********************************/
108 if (in_data_type == FINLEY_NODES) {
109 out.requireWrite();
110 if (out_data_type == FINLEY_NODES) {
111 #pragma omp parallel for
112 for (int n=0; n<numOut; n++) {
113 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(n), numComps_size);
114 }
115 } else if (out_data_type == FINLEY_REDUCED_NODES) {
116 const std::vector<int>& map = nodes->borrowReducedNodesTarget();
117 const int mapSize = map.size();
118 #pragma omp parallel for
119 for (int n=0; n<mapSize; n++) {
120 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(map[n]),
121 numComps_size);
122 }
123 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
124 const std::vector<int>& map = nodes->borrowDegreesOfFreedomTarget();
125 #pragma omp parallel for
126 for (int n=0; n<numOut; n++) {
127 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(map[n]),
128 numComps_size);
129 }
130 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
131 const std::vector<int>& map = nodes->borrowReducedDegreesOfFreedomTarget();
132 #pragma omp parallel for
133 for (int n=0; n<numOut; n++) {
134 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(map[n]),
135 numComps_size);
136 }
137 }
138
139 /*********************** FINLEY_REDUCED_NODES ***************************/
140 } else if (in_data_type == FINLEY_REDUCED_NODES) {
141 if (out_data_type == FINLEY_NODES) {
142 setError(TYPE_ERROR,"Assemble_CopyNodalData: cannot copy from reduced nodes to nodes.");
143 } else if (out_data_type == FINLEY_REDUCED_NODES) {
144 out.requireWrite();
145 const int nNodes = nodes->getNumNodes();
146 #pragma omp parallel for
147 for (int n=0; n < nNodes; n++) {
148 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(n), numComps_size);
149 }
150 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
151 setError(TYPE_ERROR,"Assemble_CopyNodalData: cannot copy from reduced nodes to degrees of freedom.");
152 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
153 out.requireWrite();
154 const int* target = nodes->borrowTargetReducedNodes();
155 const std::vector<int>& map = nodes->borrowReducedDegreesOfFreedomTarget();
156 #pragma omp parallel for
157 for (int n=0; n<numOut; n++) {
158 memcpy(out.getSampleDataRW(n),
159 in.getSampleDataRO(target[map[n]]), numComps_size);
160 }
161 }
162
163 /******************** FINLEY_DEGREES_OF_FREEDOM *********************/
164 } else if (in_data_type == FINLEY_DEGREES_OF_FREEDOM) {
165 out.requireWrite();
166 if (out_data_type == FINLEY_NODES) {
167 paso::Coupler_ptr coupler(new paso::Coupler(nodes->degreesOfFreedomConnector, numComps));
168 if (Esys_noError()) {
169 // Coupler holds the pointer but it doesn't appear to get
170 // used so RO should work.
171 coupler->startCollect(in.getDataRO());
172 const double *recv_buffer=coupler->finishCollect();
173 const int upperBound=nodes->getNumDegreesOfFreedom();
174 const int* target = nodes->borrowTargetDegreesOfFreedom();
175 const int nNodes = nodes->numNodes;
176 #pragma omp parallel for
177 for (int n=0; n < nNodes; n++) {
178 const int k=target[n];
179 if (k < upperBound) {
180 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(k),
181 numComps_size);
182 } else {
183 memcpy(out.getSampleDataRW(n),
184 &recv_buffer[(k-upperBound)*numComps],
185 numComps_size);
186 }
187 }
188 }
189 } else if (out_data_type == FINLEY_REDUCED_NODES) {
190 paso::Coupler_ptr coupler(new paso::Coupler(nodes->degreesOfFreedomConnector, numComps));
191 if (Esys_noError()) {
192 coupler->startCollect(in.getDataRO());
193 const double *recv_buffer=coupler->finishCollect();
194 const int upperBound=nodes->getNumDegreesOfFreedom();
195 const std::vector<int>& map = nodes->borrowReducedNodesTarget();
196 const int* target = nodes->borrowTargetDegreesOfFreedom();
197 const int mapSize = map.size();
198
199 #pragma omp parallel for
200 for (int n=0; n < mapSize; n++) {
201 const int k=target[map[n]];
202 if (k < upperBound) {
203 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(k),
204 numComps_size);
205 } else {
206 memcpy(out.getSampleDataRW(n),
207 &recv_buffer[(k-upperBound)*numComps],
208 numComps_size);
209 }
210 }
211 }
212 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM) {
213 #pragma omp parallel for
214 for (int n=0; n<numOut; n++) {
215 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(n),
216 numComps_size);
217 }
218 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
219 const std::vector<int>& map = nodes->borrowReducedDegreesOfFreedomTarget();
220 const int* target = nodes->borrowTargetDegreesOfFreedom();
221 #pragma omp parallel for
222 for (int n=0; n<numOut; n++) {
223 memcpy(out.getSampleDataRW(n),
224 in.getSampleDataRO(target[map[n]]), numComps_size);
225 }
226 }
227
228 /**************** FINLEY_REDUCED_DEGREES_OF_FREEDOM *****************/
229 } else if (in_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
230 if (out_data_type == FINLEY_NODES) {
231 setError(TYPE_ERROR, "Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to nodes.");
232 } else if (out_data_type == FINLEY_REDUCED_NODES) {
233 paso::Coupler_ptr coupler(new paso::Coupler(nodes->reducedDegreesOfFreedomConnector,numComps));
234 if (Esys_noError()) {
235 coupler->startCollect(in.getDataRO());
236 out.requireWrite();
237 const int upperBound=nodes->getNumReducedDegreesOfFreedom();
238 const std::vector<int>& map=nodes->borrowReducedNodesTarget();
239 const int mapSize = map.size();
240 const int* target=nodes->borrowTargetReducedDegreesOfFreedom();
241 const double *recv_buffer=coupler->finishCollect();
242 #pragma omp parallel for
243 for (int n=0; n < mapSize; n++) {
244 const int k=target[map[n]];
245 if (k < upperBound) {
246 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(k),
247 numComps_size);
248 } else {
249 memcpy(out.getSampleDataRW(n),
250 &recv_buffer[(k-upperBound)*numComps],
251 numComps_size);
252 }
253 }
254 }
255 } else if (out_data_type == FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
256 out.requireWrite();
257 #pragma omp parallel for
258 for (int n=0; n<numOut; n++) {
259 memcpy(out.getSampleDataRW(n), in.getSampleDataRO(n), numComps_size);
260 }
261 } else if (out_data_type == FINLEY_DEGREES_OF_FREEDOM ) {
262 setError(TYPE_ERROR, "Assemble_CopyNodalData: cannot copy from reduced degrees of freedom to degrees of freedom.");
263 }
264 } // in_data_type
265 }
266
267 } // namespace finley
268

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/diaplayground/finley/src/Assemble_CopyNodalData.cpp:4940-5147 /branches/lapack2681/finley/src/Assemble_CopyNodalData.cpp:2682-2741 /branches/pasowrap/finley/src/Assemble_CopyNodalData.cpp:3661-3674 /branches/py3_attempt2/finley/src/Assemble_CopyNodalData.cpp:3871-3891 /branches/restext/finley/src/Assemble_CopyNodalData.cpp:2610-2624 /branches/ripleygmg_from_3668/finley/src/Assemble_CopyNodalData.cpp:3669-3791 /branches/stage3.0/finley/src/Assemble_CopyNodalData.cpp:2569-2590 /branches/symbolic_from_3470/finley/src/Assemble_CopyNodalData.cpp:3471-3974 /release/3.0/finley/src/Assemble_CopyNodalData.cpp:2591-2601 /trunk/finley/src/Assemble_CopyNodalData.cpp:4257-4344

  ViewVC Help
Powered by ViewVC 1.1.26