Skip to content
Snippets Groups Projects
Commit 9c1db07f authored by Holger Obermaier's avatar Holger Obermaier
Browse files

Use std::swap to swap values

parent 1d8d9a57
No related branches found
No related tags found
1 merge request!3Draft: Porting from C to Cpp using Multidimensional Subscript Operator
#include "float3DTensorT.hpp"
#include <cstring>
#include <stddef.h>
#include <utility> // swap
// Choose default method to push and pop data to the buffer
// available methods: OPENMP, MEMCPY
......@@ -17,21 +18,9 @@ int buffer_push(
int i3_start, int i3_end,
int buffer_counter)
{
if (i1_end < i1_start) {
int swap = i1_start;
i1_start = i1_end;
i1_end = swap;
}
if (i2_end < i2_start) {
int swap = i2_start;
i2_start = i2_end;
i2_end = swap;
}
if (i3_end < i3_start) {
int swap = i3_start;
i3_start = i3_end;
i3_end = swap;
}
if (i1_end < i1_start) std::swap(i1_start, i1_end);
if (i2_end < i2_start) std::swap(i2_start, i2_end);
if (i3_end < i3_start) std::swap(i3_start, i3_end);
for (int i1 = i1_start; i1 <= i1_end; i1++) {
for (int i2 = i2_start; i2 <= i2_end; i2++) {
#pragma omp simd
......@@ -50,21 +39,9 @@ int buffer_pop(
int i3_start, int i3_end,
int buffer_counter)
{
if (i1_end < i1_start) {
int swap = i1_start;
i1_start = i1_end;
i1_end = swap;
}
if (i2_end < i2_start) {
int swap = i2_start;
i2_start = i2_end;
i2_end = swap;
}
if (i3_end < i3_start) {
int swap = i3_start;
i3_start = i3_end;
i3_end = swap;
}
if (i1_end < i1_start) std::swap(i1_start, i1_end);
if (i2_end < i2_start) std::swap(i2_start, i2_end);
if (i3_end < i3_start) std::swap(i3_start, i3_end);
for (int i1 = i1_start; i1 <= i1_end; i1++) {
for (int i2 = i2_start; i2 <= i2_end; i2++) {
#pragma omp simd
......@@ -85,21 +62,9 @@ int buffer_push(
int i3_start, int i3_end,
int buffer_counter)
{
if (i1_end < i1_start) {
int swap = i1_start;
i1_start = i1_end;
i1_end = swap;
}
if (i2_end < i2_start) {
int swap = i2_start;
i2_start = i2_end;
i2_end = swap;
}
if (i3_end < i3_start) {
int swap = i3_start;
i3_start = i3_end;
i3_end = swap;
}
if (i1_end < i1_start) std::swap(i1_start, i1_end);
if (i2_end < i2_start) std::swap(i2_start, i2_end);
if (i3_end < i3_start) std::swap(i3_start, i3_end);
const size_t vec_len = i3_end - i3_start + 1;
for (int i1 = i1_start; i1 <= i1_end; i1++) {
for (int i2 = i2_start; i2 <= i2_end; i2++) {
......@@ -117,21 +82,9 @@ int buffer_pop(
int i3_start, int i3_end,
int buffer_counter)
{
if (i1_end < i1_start) {
int swap = i1_start;
i1_start = i1_end;
i1_end = swap;
}
if (i2_end < i2_start) {
int swap = i2_start;
i2_start = i2_end;
i2_end = swap;
}
if (i3_end < i3_start) {
int swap = i3_start;
i3_start = i3_end;
i3_end = swap;
}
if (i1_end < i1_start) std::swap(i1_start, i1_end);
if (i2_end < i2_start) std::swap(i2_start, i2_end);
if (i3_end < i3_start) std::swap(i3_start, i3_end);
const size_t vec_len = i3_end - i3_start + 1;
for (int i1 = i1_start; i1 <= i1_end; i1++) {
for (int i2 = i2_start; i2 <= i2_end; i2++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment