From f9b854047b03dbc8c6b8e7bf6fbf1916324dedf0 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Tue, 18 Sep 2018 11:44:00 +0200 Subject: [PATCH] Encapsulate Kokkos::parallel_for and Kokkos::parallel_reduce --- src/algebra/TinyMatrix.hpp | 1 - src/main.cpp | 5 ---- src/mesh/Connectivity.cpp | 4 ++-- src/mesh/Connectivity.hpp | 3 ++- src/mesh/ConnectivityMatrix.hpp | 2 +- src/mesh/ItemToItemMatrix.hpp | 2 +- src/mesh/MeshData.hpp | 28 +++++++++++----------- src/mesh/MeshNodeBoundary.hpp | 6 ++--- src/scheme/AcousticSolver.hpp | 26 ++++++++++---------- src/scheme/BlockPerfectGas.hpp | 6 ++--- src/scheme/BoundaryCondition.hpp | 2 +- src/scheme/FiniteVolumesEulerUnknowns.hpp | 14 +++++------ src/utils/Array.hpp | 2 +- src/utils/ArrayUtils.hpp | 6 ++--- src/utils/PastisUtils.hpp | 29 +++++++++++++++++++++++ 15 files changed, 80 insertions(+), 56 deletions(-) create mode 100644 src/utils/PastisUtils.hpp diff --git a/src/algebra/TinyMatrix.hpp b/src/algebra/TinyMatrix.hpp index 8ef511660..888acb068 100644 --- a/src/algebra/TinyMatrix.hpp +++ b/src/algebra/TinyMatrix.hpp @@ -3,7 +3,6 @@ #include <PastisMacros.hpp> #include <PastisAssert.hpp> -#include <Kokkos_Core.hpp> #include <Types.hpp> #include <TinyVector.hpp> diff --git a/src/main.cpp b/src/main.cpp index ba6f6c504..064a38227 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,11 +6,6 @@ #include <SignalManager.hpp> #include <ConsoleManager.hpp> -// #include <RawKokkosAcousticSolver.hpp> -// #include <MeshLessAcousticSolver.hpp> -// #include <AcousticSolverClass.hpp> -// #include <AcousticSolverTest.hpp> - #include <Connectivity.hpp> #include <Mesh.hpp> diff --git a/src/mesh/Connectivity.cpp b/src/mesh/Connectivity.cpp index 9d95f2896..90024775d 100644 --- a/src/mesh/Connectivity.cpp +++ b/src/mesh/Connectivity.cpp @@ -228,14 +228,14 @@ Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector, { CellValue<CellType> cell_type(*this); - Kokkos::parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j){ cell_type[j] = cell_type_vector[j]; }); m_cell_type = cell_type; } { CellValue<double> inv_cell_nb_nodes(*this); - Kokkos::parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j){ const auto& cell_nodes = cell_to_node_matrix.rowConst(j); inv_cell_nb_nodes[j] = 1./cell_nodes.length; }); diff --git a/src/mesh/Connectivity.hpp b/src/mesh/Connectivity.hpp index 4c83d4adc..c4cd00ab7 100644 --- a/src/mesh/Connectivity.hpp +++ b/src/mesh/Connectivity.hpp @@ -3,9 +3,10 @@ #include <PastisMacros.hpp> #include <PastisAssert.hpp> +#include <PastisUtils.hpp> + #include <TinyVector.hpp> -#include <Kokkos_Core.hpp> #include <ItemValue.hpp> #include <IConnectivity.hpp> diff --git a/src/mesh/ConnectivityMatrix.hpp b/src/mesh/ConnectivityMatrix.hpp index b8fa1e009..512c2cfdf 100644 --- a/src/mesh/ConnectivityMatrix.hpp +++ b/src/mesh/ConnectivityMatrix.hpp @@ -1,7 +1,7 @@ #ifndef CONNECTIVITY_MATRIX_HPP #define CONNECTIVITY_MATRIX_HPP -#include <Kokkos_Core.hpp> +#include <PastisUtils.hpp> #include <Kokkos_StaticCrsGraph.hpp> class ConnectivityMatrix diff --git a/src/mesh/ItemToItemMatrix.hpp b/src/mesh/ItemToItemMatrix.hpp index 70240b8ef..38f8234c7 100644 --- a/src/mesh/ItemToItemMatrix.hpp +++ b/src/mesh/ItemToItemMatrix.hpp @@ -4,7 +4,7 @@ #include <ItemType.hpp> #include <ItemId.hpp> -#include <Kokkos_Core.hpp> +#include <PastisUtils.hpp> #include <ConnectivityMatrix.hpp> template <ItemType SourceItemType, diff --git a/src/mesh/MeshData.hpp b/src/mesh/MeshData.hpp index 0f016f0e9..6bd7e8925 100644 --- a/src/mesh/MeshData.hpp +++ b/src/mesh/MeshData.hpp @@ -1,7 +1,7 @@ #ifndef MESH_DATA_HPP #define MESH_DATA_HPP -#include <Kokkos_Core.hpp> +#include <PastisUtils.hpp> #include <TinyVector.hpp> #include <ItemValue.hpp> @@ -40,7 +40,7 @@ class MeshData = m_mesh.connectivity().cellToNodeMatrix(); CellValue<Rd> xj(m_mesh.connectivity()); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ const auto& cell_nodes = cell_to_node_matrix[j]; xj[j] = 0.5*(xr[cell_nodes[0]]+xr[cell_nodes[1]]); }); @@ -54,7 +54,7 @@ class MeshData const auto& cell_to_node_matrix = m_mesh.connectivity().cellToNodeMatrix(); CellValue<Rd> xj(m_mesh.connectivity()); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ Rd X = zero; const auto& cell_nodes = cell_to_node_matrix[j]; for (size_t R=0; R<cell_nodes.size(); ++R) { @@ -74,7 +74,7 @@ class MeshData = m_mesh.connectivity().cellToNodeMatrix(); CellValue<double> Vj(m_mesh.connectivity()); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ double sum_cjr_xr = 0; const auto& cell_nodes = cell_to_node_matrix[j]; @@ -98,7 +98,7 @@ class MeshData { NodeValuePerCell<Rd> Cjr(m_mesh.connectivity()); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ const auto& cell_nodes = cell_to_node_matrix[j]; for (size_t R=0; R<cell_nodes.size(); ++R) { int Rp1 = (R+1)%cell_nodes.size(); @@ -112,7 +112,7 @@ class MeshData { NodeValuePerCell<double> ljr(m_mesh.connectivity()); - Kokkos::parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ + parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ ljr[jr] = l2Norm(m_Cjr[jr]); }); m_ljr = ljr; @@ -120,7 +120,7 @@ class MeshData { NodeValuePerCell<Rd> njr(m_mesh.connectivity()); - Kokkos::parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ + parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ njr[jr] = (1./m_ljr[jr])*m_Cjr[jr]; }); m_njr = njr; @@ -132,7 +132,7 @@ class MeshData const auto& face_to_node_matrix = m_mesh.connectivity().faceToNodeMatrix(); - Kokkos::parallel_for(m_mesh.numberOfFaces(), PASTIS_LAMBDA(const FaceId& l) { + parallel_for(m_mesh.numberOfFaces(), PASTIS_LAMBDA(const FaceId& l) { const auto& face_nodes = face_to_node_matrix[l]; const size_t nb_nodes = face_nodes.size(); std::vector<Rd> dxr(nb_nodes); @@ -164,11 +164,11 @@ class MeshData { NodeValuePerCell<Rd> Cjr(m_mesh.connectivity()); - Kokkos::parallel_for(Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ + parallel_for(Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ Cjr[jr] = zero; }); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { const auto& cell_nodes = cell_to_node_matrix[j]; const auto& cell_faces = cell_to_face_matrix[j]; @@ -209,7 +209,7 @@ class MeshData { NodeValuePerCell<double> ljr(m_mesh.connectivity()); - Kokkos::parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ + parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ ljr[jr] = l2Norm(m_Cjr[jr]); }); m_ljr = ljr; @@ -217,7 +217,7 @@ class MeshData { NodeValuePerCell<Rd> njr(m_mesh.connectivity()); - Kokkos::parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ + parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ njr[jr] = (1./m_ljr[jr])*m_Cjr[jr]; }); m_njr = njr; @@ -271,7 +271,7 @@ class MeshData // in 1d Cjr are computed once for all { NodeValuePerCell<Rd> Cjr(m_mesh.connectivity()); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { Cjr(j,0)=-1; Cjr(j,1)= 1; }); @@ -281,7 +281,7 @@ class MeshData m_njr = m_Cjr; { NodeValuePerCell<double> ljr(m_mesh.connectivity()); - Kokkos::parallel_for(ljr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ + parallel_for(ljr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ ljr[jr] = 1; }); m_ljr = ljr; diff --git a/src/mesh/MeshNodeBoundary.hpp b/src/mesh/MeshNodeBoundary.hpp index a8026cc86..9f945e07b 100644 --- a/src/mesh/MeshNodeBoundary.hpp +++ b/src/mesh/MeshNodeBoundary.hpp @@ -37,7 +37,7 @@ class MeshNodeBoundary = mesh.connectivity().faceToCellMatrix(); const Array<const FaceId>& face_list = ref_face_list.faceList(); - Kokkos::parallel_for(face_list.size(), PASTIS_LAMBDA(const int& l){ + parallel_for(face_list.size(), PASTIS_LAMBDA(const int& l){ const auto& face_cells = face_to_cell_matrix[face_list[l]]; if (face_cells.size()>1) { std::cerr << "internal faces cannot be used to define mesh boundaries\n"; @@ -64,7 +64,7 @@ class MeshNodeBoundary node_ids.resize(std::distance(node_ids.begin(), last)); Array<NodeId> node_list(node_ids.size()); - Kokkos::parallel_for(node_ids.size(), PASTIS_LAMBDA(const int& r){ + parallel_for(node_ids.size(), PASTIS_LAMBDA(const int& r){ node_list[r] = node_ids[r]; }); m_node_list = node_list; @@ -158,7 +158,7 @@ _checkBoundaryIsFlat(const TinyVector<2,double>& normal, const NodeValue<const R2>& xr = mesh.xr(); - Kokkos::parallel_for(m_node_list.size(), PASTIS_LAMBDA(const size_t& r) { + parallel_for(m_node_list.size(), PASTIS_LAMBDA(const size_t& r) { const R2& x = xr[m_node_list[r]]; if ((x-origin,normal)>1E-13*length) { std::cerr << "this FlatBoundary is not flat!\n"; diff --git a/src/scheme/AcousticSolver.hpp b/src/scheme/AcousticSolver.hpp index 389e916e0..3afc43496 100644 --- a/src/scheme/AcousticSolver.hpp +++ b/src/scheme/AcousticSolver.hpp @@ -39,7 +39,7 @@ class AcousticSolver computeRhoCj(const CellValue<const double>& rhoj, const CellValue<const double>& cj) { - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { m_rhocj[j] = rhoj[j]*cj[j]; }); return m_rhocj; @@ -51,7 +51,7 @@ class AcousticSolver const NodeValuePerCell<const double>& ljr, const NodeValuePerCell<const Rd>& njr) { - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { const size_t& nb_nodes =m_Ajr.numberOfSubValues(j); const double& rho_c = rhocj[j]; for (size_t r=0; r<nb_nodes; ++r) { @@ -68,7 +68,7 @@ class AcousticSolver const auto& node_local_numbers_in_their_cells = m_connectivity.nodeLocalNumbersInTheirCells(); - Kokkos::parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { + parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { Rdd sum = zero; const auto& node_to_cell = node_to_cell_matrix[r]; const auto& node_local_number_in_its_cells @@ -96,7 +96,7 @@ class AcousticSolver const auto& node_local_numbers_in_their_cells = m_connectivity.nodeLocalNumbersInTheirCells(); - Kokkos::parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { + parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { Rd& br = m_br[r]; br = zero; const auto& node_to_cell = node_to_cell_matrix[r]; @@ -144,7 +144,7 @@ class AcousticSolver const Array<const NodeId>& node_list = symmetry_bc.nodeList(); - Kokkos::parallel_for(symmetry_bc.numberOfNodes(), PASTIS_LAMBDA(const int& r_number) { + parallel_for(symmetry_bc.numberOfNodes(), PASTIS_LAMBDA(const int& r_number) { const NodeId r = node_list[r_number]; m_Ar[r] = P*m_Ar[r]*P + nxn; @@ -162,7 +162,7 @@ class AcousticSolver { inverse(Ar, m_inv_Ar); const NodeValue<const Rdd> invAr = m_inv_Ar; - Kokkos::parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { + parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { m_ur[r]=invAr[r]*br[r]; }); @@ -179,7 +179,7 @@ class AcousticSolver const auto& cell_to_node_matrix = m_mesh.connectivity().cellToNodeMatrix(); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { const auto& cell_nodes = cell_to_node_matrix[j]; for (size_t r=0; r<cell_nodes.size(); ++r) { @@ -191,7 +191,7 @@ class AcousticSolver void inverse(const NodeValue<const Rdd>& A, NodeValue<Rdd>& inv_A) const { - Kokkos::parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { + parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { inv_A[r] = ::inverse(A[r]); }); } @@ -258,7 +258,7 @@ class AcousticSolver const auto& cell_to_node_matrix = m_mesh.connectivity().cellToNodeMatrix(); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ const auto& cell_nodes = cell_to_node_matrix[j]; double S = 0; @@ -297,7 +297,7 @@ class AcousticSolver = m_mesh.connectivity().cellToNodeMatrix(); const CellValue<const double> inv_mj = unknowns.invMj(); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { const auto& cell_nodes = cell_to_node_matrix[j]; Rd momentum_fluxes = zero; @@ -311,18 +311,18 @@ class AcousticSolver Ej[j] -= (dt*inv_mj[j]) * energy_fluxes; }); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { ej[j] = Ej[j] - 0.5 * (uj[j],uj[j]); }); NodeValue<Rd> mutable_xr = m_mesh.mutableXr(); - Kokkos::parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r){ + parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r){ mutable_xr[r] += dt*ur[r]; }); m_mesh_data.updateAllData(); const CellValue<const double> mj = unknowns.mj(); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ rhoj[j] = mj[j]/Vj[j]; }); } diff --git a/src/scheme/BlockPerfectGas.hpp b/src/scheme/BlockPerfectGas.hpp index 13dbfd816..f3ea76520 100644 --- a/src/scheme/BlockPerfectGas.hpp +++ b/src/scheme/BlockPerfectGas.hpp @@ -34,7 +34,7 @@ public: const CellValue<const double>& e = m_ej; const CellValue<const double>& gamma = m_gammaj; - Kokkos::parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ + parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ const double gamma_minus_one = gamma[j]-1; m_pj[j] = gamma_minus_one*rho[j]*e[j]; m_cj[j] = std::sqrt(gamma[j]*gamma_minus_one*e[j]); @@ -48,12 +48,12 @@ public: const CellValue<const double>& p = m_pj; const CellValue<const double>& gamma = m_gammaj; - Kokkos::parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ + parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ m_ej[j] = p[j]/(rho[j]*(gamma[j]-1)); }); const CellValue<const double>& e = m_ej; - Kokkos::parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ + parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ m_cj[j] = std::sqrt(gamma[j]*(gamma[j]-1)*e[j]); }); } diff --git a/src/scheme/BoundaryCondition.hpp b/src/scheme/BoundaryCondition.hpp index ed73e14bc..0380f97c0 100644 --- a/src/scheme/BoundaryCondition.hpp +++ b/src/scheme/BoundaryCondition.hpp @@ -69,7 +69,7 @@ public: m_number_of_faces(faces.size()) { Array<unsigned int> face_list(faces.size()); - Kokkos::parallel_for(m_number_of_faces, PASTIS_LAMBDA(const int& f){ + parallel_for(m_number_of_faces, PASTIS_LAMBDA(const int& f){ face_list[f]=faces[f]; }); m_face_list = face_list; diff --git a/src/scheme/FiniteVolumesEulerUnknowns.hpp b/src/scheme/FiniteVolumesEulerUnknowns.hpp index fc1178b77..109e93d5a 100644 --- a/src/scheme/FiniteVolumesEulerUnknowns.hpp +++ b/src/scheme/FiniteVolumesEulerUnknowns.hpp @@ -124,7 +124,7 @@ public: { const CellValue<const Rd>& xj = m_mesh_data.xj(); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ if (xj[j][0]<0.5) { m_rhoj[j]=1; } else { @@ -132,7 +132,7 @@ public: } }); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ if (xj[j][0]<0.5) { m_pj[j]=1; } else { @@ -140,27 +140,27 @@ public: } }); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ m_uj[j] = zero; }); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ m_gammaj[j] = 1.4; }); BlockPerfectGas block_eos(m_rhoj, m_ej, m_pj, m_gammaj, m_cj); block_eos.updateEandCFromRhoP(); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ m_Ej[j] = m_ej[j]+0.5*(m_uj[j],m_uj[j]); }); const CellValue<const double>& Vj = m_mesh_data.Vj(); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ m_mj[j] = m_rhoj[j] * Vj[j]; }); - Kokkos::parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ m_inv_mj[j] = 1./m_mj[j]; }); } diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp index bfcb6231d..e7273ecee 100644 --- a/src/utils/Array.hpp +++ b/src/utils/Array.hpp @@ -2,7 +2,7 @@ #define ARRAY_HPP #include <PastisMacros.hpp> -#include <Kokkos_Core.hpp> +#include <PastisUtils.hpp> #include <PastisAssert.hpp> diff --git a/src/utils/ArrayUtils.hpp b/src/utils/ArrayUtils.hpp index 26f4b6233..b64452d99 100644 --- a/src/utils/ArrayUtils.hpp +++ b/src/utils/ArrayUtils.hpp @@ -2,7 +2,7 @@ #define ARRAY_UTILS_HPP #include <PastisMacros.hpp> -#include <Kokkos_Core.hpp> +#include <PastisUtils.hpp> template <typename ArrayType> class ReduceMin @@ -17,7 +17,7 @@ class ReduceMin operator data_type() { data_type reduced_value; - Kokkos::parallel_reduce(m_array.size(), *this, reduced_value); + parallel_reduce(m_array.size(), *this, reduced_value); return reduced_value; } @@ -69,7 +69,7 @@ class ReduceMax operator data_type() { data_type reduced_value; - Kokkos::parallel_reduce(m_array.size(), *this, reduced_value); + parallel_reduce(m_array.size(), *this, reduced_value); return reduced_value; } diff --git a/src/utils/PastisUtils.hpp b/src/utils/PastisUtils.hpp new file mode 100644 index 000000000..adf12176f --- /dev/null +++ b/src/utils/PastisUtils.hpp @@ -0,0 +1,29 @@ +#ifndef PASTIS_UTILS_HPP +#define PASTIS_UTILS_HPP + +#include <Kokkos_Core.hpp> +#include <PastisMacros.hpp> + +#include <functional> +#include <string> + +template <typename FunctionType> +PASTIS_FORCEINLINE +void parallel_for(const size_t& size, + const FunctionType& lambda, + const std::string& label = "") +{ + Kokkos::parallel_for(size, lambda, label); +} + +template <typename ArrayType, typename ReturnType> +PASTIS_FORCEINLINE +void parallel_reduce(const size_t& size, + const ArrayType& array, + ReturnType& value, + const std::string& label = "") +{ + Kokkos::parallel_reduce(label, size, array, value); +} + +#endif // PASTIS_UTILS_HPP -- GitLab