From 1dc9ca85e016ff41c5bf9f99d32b91f0f0a44d6f Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Sat, 1 Apr 2017 18:28:24 +1100 Subject: [PATCH] Moved the sorting entry structure to a separate file following @jwillis' work in the vectorisation branch. --- src/Makefile.am | 2 +- src/runner.c | 34 +------------------ src/sort_part.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 src/sort_part.h diff --git a/src/Makefile.am b/src/Makefile.am index 7c510004d9..14e435f663 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,7 +46,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \ hydro_properties.h riemann.h threadpool.h cooling.h cooling_struct.h sourceterms.h \ sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h \ dump.h logger.h active.h timeline.h xmf.h gravity_properties.h gravity_derivatives.h \ - vector_power.h hydro_space.h + vector_power.h hydro_space.h sort_part.h # Common source files AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \ diff --git a/src/runner.c b/src/runner.c index c4504c22be..5a26542bd1 100644 --- a/src/runner.c +++ b/src/runner.c @@ -55,6 +55,7 @@ #include "minmax.h" #include "runner_doiact_vec.h" #include "scheduler.h" +#include "sort_part.h" #include "sourceterms.h" #include "space.h" #include "stars.h" @@ -62,39 +63,6 @@ #include "timers.h" #include "timestep.h" -/** - * @brief Entry in a list of sorted indices. - */ -struct entry { - - /*! Distance on the axis */ - float d; - - /*! Particle index */ - int i; -}; - -/* Orientation of the cell pairs */ -const double runner_shift[13][3] = { - {5.773502691896258e-01, 5.773502691896258e-01, 5.773502691896258e-01}, - {7.071067811865475e-01, 7.071067811865475e-01, 0.0}, - {5.773502691896258e-01, 5.773502691896258e-01, -5.773502691896258e-01}, - {7.071067811865475e-01, 0.0, 7.071067811865475e-01}, - {1.0, 0.0, 0.0}, - {7.071067811865475e-01, 0.0, -7.071067811865475e-01}, - {5.773502691896258e-01, -5.773502691896258e-01, 5.773502691896258e-01}, - {7.071067811865475e-01, -7.071067811865475e-01, 0.0}, - {5.773502691896258e-01, -5.773502691896258e-01, -5.773502691896258e-01}, - {0.0, 7.071067811865475e-01, 7.071067811865475e-01}, - {0.0, 1.0, 0.0}, - {0.0, 7.071067811865475e-01, -7.071067811865475e-01}, - {0.0, 0.0, 1.0}, -}; - -/* Does the axis need flipping ? */ -const char runner_flip[27] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - /* Import the density loop functions. */ #define FUNCTION density #include "runner_doiact.h" diff --git a/src/sort_part.h b/src/sort_part.h new file mode 100644 index 0000000000..5f68070556 --- /dev/null +++ b/src/sort_part.h @@ -0,0 +1,90 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2017 James S. Wills (james.s.willis@durham.ac.uk) + * Matthieu Schaller (matthieu.schaller@durham.ac.uk) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ +#ifndef SWIFT_SORT_PART_H +#define SWIFT_SORT_PART_H + +/** + * @brief Entry in a list of sorted indices. + */ +struct entry { + + /*! Distance on the axis */ + float d; + + /*! Particle index */ + int i; +}; + +/* Orientation of the cell pairs */ +const double runner_shift[13][3] = { + {5.773502691896258e-01, 5.773502691896258e-01, 5.773502691896258e-01}, + {7.071067811865475e-01, 7.071067811865475e-01, 0.0}, + {5.773502691896258e-01, 5.773502691896258e-01, -5.773502691896258e-01}, + {7.071067811865475e-01, 0.0, 7.071067811865475e-01}, + {1.0, 0.0, 0.0}, + {7.071067811865475e-01, 0.0, -7.071067811865475e-01}, + {5.773502691896258e-01, -5.773502691896258e-01, 5.773502691896258e-01}, + {7.071067811865475e-01, -7.071067811865475e-01, 0.0}, + {5.773502691896258e-01, -5.773502691896258e-01, -5.773502691896258e-01}, + {0.0, 7.071067811865475e-01, 7.071067811865475e-01}, + {0.0, 1.0, 0.0}, + {0.0, 7.071067811865475e-01, -7.071067811865475e-01}, + {0.0, 0.0, 1.0}, +}; + +/* Does the axis need flipping ? */ +const char runner_flip[27] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +/** + * @brief Determines whether a pair of cells are corner to corner. + * + * @param sid sort ID + * + * @return 1 if corner to corner, 0 otherwise. + */ +__attribute__((always_inline)) INLINE static int sort_is_corner(int sid) { + return (sid == 0 || sid == 2 || sid == 6 || sid == 8); +} + +/** + * @brief Determines whether a pair of cells are edge to edge. + * + * @param sid sort ID + * + * @return 1 if edge to edge, 0 otherwise. + */ +__attribute__((always_inline)) INLINE static int sort_is_edge(int sid) { + return (sid == 1 || sid == 3 || sid == 5 || sid == 7 || sid == 9 || sid == 11); +} + +/** + * @brief Determines whether a pair of cells are face to face. + * + * @param sid sort ID + * + * @return 1 if face to face, 0 otherwise. + */ +__attribute__((always_inline)) INLINE static int sort_is_face(int sid) { + return (sid == 4 || sid == 10 || sid == 12); +} + + +#endif /* SWIFT_SORT_PART_H */ -- GitLab