Skip to content
Snippets Groups Projects
Commit 7ae982f8 authored by Chichi Lalescu's avatar Chichi Lalescu
Browse files

use std::copy instead of element-wise copy

parent 3245d1ec
No related branches found
No related tags found
No related merge requests found
...@@ -148,37 +148,28 @@ int field_descriptor::transpose( ...@@ -148,37 +148,28 @@ int field_descriptor::transpose(
// for 3D transposition, the input data is messed up // for 3D transposition, the input data is messed up
fftwf_plan tplan; fftwf_plan tplan;
ptrdiff_t dim1; ptrdiff_t dim1;
switch (this->ndims) if (this->ndims == 3)
{ {
case 2: // transpose the two local dimensions 1 and 2
dim1 = this->sizes[1]; float *atmp;
break; atmp = fftwf_alloc_real(this->slice_size);
case 3: for (int k = 0; k < this->subsizes[0]; k++)
// transpose the two local dimensions 1 and 2 {
dim1 = this->sizes[1]*this->sizes[2]; // put transposed slice in atmp
float *atmp; for (int j = 0; j < this->sizes[1]; j++)
atmp = (float*)malloc(dim1*sizeof(float)); for (int i = 0; i < this->sizes[2]; i++)
for (int k = 0; k < this->subsizes[0]; k++) atmp[i*this->sizes[1] + j] =
{ input[(k*this->sizes[1] + j)*this->sizes[2] + i];
// put transposed slice in atmp // copy back transposed slice
for (int j = 0; j < this->sizes[1]; j++) std::copy(
for (int i = 0; i < this->sizes[2]; i++) atmp,
atmp[i*this->sizes[1] + j] = atmp + this->slice_size,
input[(k*this->sizes[1] + j)*this->sizes[2] + i]; input + k*this->slice_size);
// copy back transposed slice }
for (int j = 0; j < this->sizes[2]; j++) fftwf_free(atmp);
for (int i = 0; i < this->sizes[1]; i++)
input[(k*this->sizes[2] + j)*this->sizes[1] + i] =
atmp[j*this->sizes[1] + i];
}
free(atmp);
break;
default:
return EXIT_FAILURE;
break;
} }
tplan = fftwf_mpi_plan_transpose( tplan = fftwf_mpi_plan_transpose(
this->sizes[0], dim1, this->sizes[0], this->slice_size,
input, output, input, output,
this->comm, this->comm,
FFTW_ESTIMATE); FFTW_ESTIMATE);
......
{ {
"metadata": { "metadata": {
"name": "", "name": "",
"signature": "sha256:e257a2ed63efdfaaad53572bf411ce350bc2da0748cbff2374ba511f3a837cbc" "signature": "sha256:9cf3a6ad81b4021d61957c3d2805faad24a447da957672fc0268ff9b398c6dee"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
"language": "python", "language": "python",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"prompt_number": 51 "prompt_number": 54
}, },
{ {
"cell_type": "code", "cell_type": "code",
...@@ -215,11 +215,11 @@ ...@@ -215,11 +215,11 @@
"output_type": "stream", "output_type": "stream",
"stream": "stdout", "stream": "stdout",
"text": [ "text": [
"3.09944e-06\n" "2.86102e-06\n"
] ]
} }
], ],
"prompt_number": 52 "prompt_number": 55
}, },
{ {
"cell_type": "code", "cell_type": "code",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment