aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetInterp
diff options
context:
space:
mode:
authorThomas Radke <tradke@aei.mpg.de>2005-08-27 11:14:00 +0000
committerThomas Radke <tradke@aei.mpg.de>2005-08-27 11:14:00 +0000
commit400f2fe2175c796dc53cac09b5c18a2ddf2bf67a (patch)
treefd79e178cb4935847f26b17119241d63ee6fa91b /Carpet/CarpetInterp
parent2f7584d3a2f6efdd535866750bcfff5db1f4258c (diff)
CarpetInterp: copy interpolation results directly into output arrays, without requiring an intermediate copy operation
darcs-hash:20050827111420-776a0-1e41fee0c43d1e7f7eda3c26450fff250035ea7c.gz
Diffstat (limited to 'Carpet/CarpetInterp')
-rw-r--r--Carpet/CarpetInterp/src/interp.cc31
1 files changed, 14 insertions, 17 deletions
diff --git a/Carpet/CarpetInterp/src/interp.cc b/Carpet/CarpetInterp/src/interp.cc
index bdc17ffaa..7b8646dee 100644
--- a/Carpet/CarpetInterp/src/interp.cc
+++ b/Carpet/CarpetInterp/src/interp.cc
@@ -554,24 +554,21 @@ namespace CarpetInterp {
//////////////////////////////////////////////////////////////////////
// Finally, sort the received outputs back into the caller's arrays
//////////////////////////////////////////////////////////////////////
- {
- // sorting is done with the help of the indices vector
- //
- // It would be nice if this could be done in a single step
- // without copying data into an intermediate buffer.
- vector<CCTK_REAL> tmp(N_interp_points);
- for (int d = 0; d < N_output_arrays; d++) {
- for (int c = 0, i = 0, offset = 0; c < allhomecnts.size(); c++) {
- for (int n = 0; n < allhomecnts[c]; n++, i++) {
- tmp.at(i) = outputs_buffer.at(allhomecnts[c]*d + offset + n);
- }
- offset += N_output_arrays * allhomecnts[c];
- }
- for (int c = 0, i = 0; c < allhomecnts.size(); c++) {
- for (int n = 0; n < allhomecnts[c]; n++, i++) {
- static_cast<CCTK_REAL *>(output_arrays[d])[i] = tmp.at(indices[i]);
- }
+
+ // sorting is done with the help of the inverse indices vector
+ vector<int> reverse_indices(indices.size());
+ for (int i = 0; i < indices.size(); i++) {
+ reverse_indices.at(indices[i]) = i;
+ }
+
+ for (int d = 0; d < N_output_arrays; d++) {
+ for (int c = 0, i = 0, offset = 0; c < allhomecnts.size(); c++) {
+ assert (allhomecnts[c]*(d+1) + offset <= outputs_buffer.size());
+ for (int n = 0; n < allhomecnts[c]; n++, i++) {
+ static_cast<CCTK_REAL *>(output_arrays[d])[reverse_indices[i]] =
+ outputs_buffer[allhomecnts[c]*d + offset + n];
}
+ offset += N_output_arrays * allhomecnts[c];
}
}