From ff8968e5951b1ab93ab4cfcf0a270084f3aaec9e Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Mon, 8 Apr 2024 12:33:08 -0700 Subject: [PATCH] format clang-format --- src/phasicFlow/Kokkos/KokkosTypes.hpp | 162 ++--- src/phasicFlow/Kokkos/KokkosUtilities.hpp | 214 +++--- src/phasicFlow/Kokkos/Range.hpp | 188 +++-- src/phasicFlow/Kokkos/ViewAlgorithms.hpp | 681 ++++++++---------- src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp | 52 +- src/phasicFlow/Kokkos/baseAlgorithms_.hpp | 244 +++---- src/phasicFlow/Timer/Timer.cpp | 85 +-- src/phasicFlow/Timer/Timer.hpp | 100 ++- .../boundaryField/createBoundaryFields.hpp | 26 +- src/phasicFlow/globals/error.cpp | 132 ++-- src/phasicFlow/globals/error.hpp | 98 ++- src/phasicFlow/globals/vocabs.hpp | 60 +- src/phasicFlow/repository/Time/Time.cpp | 109 ++- src/phasicFlow/repository/Time/Time.hpp | 101 ++- .../repository/Time/baseTimeControl.cpp | 87 +++ .../repository/Time/baseTimeControl.hpp | 21 +- .../systemControl/systemControl.cpp | 333 ++++----- src/phasicFlow/typeSelection/typeInfo.hpp | 363 ++++++---- .../typeSelection/virtualConstructor.hpp | 106 ++- src/phasicFlow/types/basicTypes/Logical.cpp | 137 ++-- src/phasicFlow/types/basicTypes/Logical.hpp | 155 ++-- .../types/basicTypes/bTypesFunctions.cpp | 521 ++++++++------ .../types/basicTypes/bTypesFunctions.hpp | 276 ++++--- .../types/basicTypes/builtinTypes.hpp | 56 +- src/phasicFlow/types/basicTypes/math.hpp | 210 +++--- .../types/basicTypes/numericConstants.hpp | 81 +-- src/phasicFlow/types/quadruple/quadruple.hpp | 289 ++++---- .../types/quadruple/quadrupleFwd.hpp | 170 ++--- src/phasicFlow/types/quadruple/quadrupleI.hpp | 404 ++++------- .../types/quadruple/quadrupleMath.hpp | 61 +- src/phasicFlow/types/triple/triple.hpp | 395 +++++----- src/phasicFlow/types/triple/tripleFwd.hpp | 218 ++---- src/phasicFlow/types/triple/tripleI.hpp | 510 +++++-------- src/phasicFlow/types/triple/tripleMath.hpp | 64 +- src/phasicFlow/types/types.cpp | 29 +- src/phasicFlow/types/types.hpp | 120 ++- 36 files changed, 3353 insertions(+), 3505 deletions(-) diff --git a/src/phasicFlow/Kokkos/KokkosTypes.hpp b/src/phasicFlow/Kokkos/KokkosTypes.hpp index 6597b5b7..c902abef 100644 --- a/src/phasicFlow/Kokkos/KokkosTypes.hpp +++ b/src/phasicFlow/Kokkos/KokkosTypes.hpp @@ -2,17 +2,17 @@ O C enter of O O E ngineering and O O M ultiscale modeling of - OOOOOOO F luid flow + OOOOOOO F luid flow ------------------------------------------------------------------------------ Copyright (C): www.cemf.ir email: hamid.r.norouzi AT gmail.com ------------------------------------------------------------------------------- +------------------------------------------------------------------------------ Licence: - This file is part of phasicFlow code. It is a free software for simulating + This file is part of phasicFlow code. It is a free software for simulating granular and multiphase flows. You can redistribute it and/or modify it under - the terms of GNU General Public License v3 or any other later versions. - - phasicFlow is distributed to help others in their research in the field of + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -22,155 +22,141 @@ Licence: /** * \file KokkosType.hpp - * - * \brief name aliases and typedesf for Kokkos entities that are + * + * \brief name aliases and typedesf for Kokkos entities that are * frequently used in PhasicFlow. - * + * */ - #include #include #include #include "builtinTypes.hpp" - namespace pFlow { +/// Host memory space +using HostSpace = Kokkos::HostSpace; -/// Host memory space -using HostSpace = Kokkos::HostSpace; - -/// Serial execution space -using Serial = Kokkos::Serial; +/// Serial execution space +using Serial = Kokkos::Serial; #ifdef _OPENMP -/// OpenMp execution space -using OpenMP = Kokkos::OpenMP; +/// OpenMp execution space +using OpenMP = Kokkos::OpenMP; #endif #ifdef __CUDACC__ -/// Cuda execution space -using Cuda = Kokkos::Cuda; +/// Cuda execution space +using Cuda = Kokkos::Cuda; #endif -/// Default Host execution space, on top of all host execution spaces -using DefaultHostExecutionSpace = Kokkos::DefaultHostExecutionSpace; +/// Default Host execution space, on top of all host execution spaces +using DefaultHostExecutionSpace = Kokkos::DefaultHostExecutionSpace; -/// Default execution space, it can be device exe. space, if a device space is -/// activated. -using DefaultExecutionSpace = Kokkos::DefaultExecutionSpace; +/// Default execution space, it can be device exe. space, if a device space is +/// activated. +using DefaultExecutionSpace = Kokkos::DefaultExecutionSpace; +using deviceRPolicyStatic = Kokkos::RangePolicy< + Kokkos::DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType>; -using deviceRPolicyStatic = - Kokkos::RangePolicy< - Kokkos::DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType >; +using hostRPolicyStatic = Kokkos::RangePolicy< + Kokkos::DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType>; +using deviceRPolicyDynamic = Kokkos::RangePolicy< + Kokkos::DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType>; -using hostRPolicyStatic = - Kokkos::RangePolicy< - Kokkos::DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType >; - -using deviceRPolicyDynamic = - Kokkos::RangePolicy< - Kokkos::DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType >; - - -using hostRPolicyDynamic = - Kokkos::RangePolicy< - Kokkos::DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType >; - +using hostRPolicyDynamic = Kokkos::RangePolicy< + Kokkos::DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType>; /// Pair of two variables template -using Pair = Kokkos::pair; +using Pair = Kokkos::pair; /// View for a scalar template - using ViewTypeScalar = Kokkos::View; +using ViewTypeScalar = Kokkos::View; -/// 1D veiw as a vector +/// 1D veiw as a vector template - using ViewType1D = Kokkos::View; +using ViewType1D = Kokkos::View; /// 2D view as an array template - using ViewType2D = Kokkos::View; +using ViewType2D = Kokkos::View; /// 3D view as an array template - using ViewType3D = Kokkos::View; +using ViewType3D = Kokkos::View; -/// 1D dual view as a vector +/// 1D dual view as a vector template - using DualViewType1D = Kokkos::DualView; +using DualViewType1D = Kokkos::DualView; /// unordered map template - using unorderedMap = Kokkos::UnorderedMap; +using unorderedMap = Kokkos::UnorderedMap; -/// unordered set +/// unordered set template - using unorderedSet = Kokkos::UnorderedMap; +using unorderedSet = Kokkos::UnorderedMap; -/// Scalar on device +/// Scalar on device template - using deviceViewTypeScalar = Kokkos::View; +using deviceViewTypeScalar = Kokkos::View; /// 1D array (vector) with default device (memory space and execution space) template - using deviceViewType1D = Kokkos::View; - -/// 2D view on device as an array on device -template - using deviceViewType2D = Kokkos::View; - -/// 3D view on device as an array on device -template - using deviceViewType3D = Kokkos::View; +using deviceViewType1D = Kokkos::View; +/// 2D view on device as an array on device +template +using deviceViewType2D = Kokkos::View; +/// 3D view on device as an array on device +template +using deviceViewType3D = Kokkos::View; template - using hostViewTypeScalar = Kokkos::View; +using hostViewTypeScalar = Kokkos::View; /// 1D array (vector with host memeory space) template - using hostViewType1D = Kokkos::View; +using hostViewType1D = Kokkos::View; -/// 2D array on host -template - using hostViewType2D = Kokkos::View; +/// 2D array on host +template +using hostViewType2D = Kokkos::View; /// 3D array on host -template - using hostViewType3D = Kokkos::View; +template +using hostViewType3D = Kokkos::View; /// 1D vector on device with atomic capabilities template -using deviceAtomicViewType1D = - Kokkos::View< - T*, - Kokkos::MemoryTraits::value?0:Kokkos::Atomic>>; +using deviceAtomicViewType1D = Kokkos::View< + T*, + Kokkos::MemoryTraits< + std::is_same_v ? 0 : Kokkos::Atomic>>; /// 3D array on device with atomic capabilities template -using deviceAtomicViewType3D = - Kokkos::View< - T***, - Kokkos::MemoryTraits::value?0:Kokkos::Atomic>>; - +using deviceAtomicViewType3D = Kokkos::View< + T***, + Kokkos::MemoryTraits< + std::is_same_v ? 0 : Kokkos::Atomic>>; } // pFlow -#endif //__KokkosTypes_hpp__ +#endif //__KokkosTypes_hpp__ diff --git a/src/phasicFlow/Kokkos/KokkosUtilities.hpp b/src/phasicFlow/Kokkos/KokkosUtilities.hpp index 6d1c7f46..7669ba1f 100644 --- a/src/phasicFlow/Kokkos/KokkosUtilities.hpp +++ b/src/phasicFlow/Kokkos/KokkosUtilities.hpp @@ -2,17 +2,17 @@ O C enter of O O E ngineering and O O M ultiscale modeling of - OOOOOOO F luid flow + OOOOOOO F luid flow ------------------------------------------------------------------------------ Copyright (C): www.cemf.ir email: hamid.r.norouzi AT gmail.com ------------------------------------------------------------------------------- +------------------------------------------------------------------------------ Licence: - This file is part of phasicFlow code. It is a free software for simulating + This file is part of phasicFlow code. It is a free software for simulating granular and multiphase flows. You can redistribute it and/or modify it under - the terms of GNU General Public License v3 or any other later versions. - - phasicFlow is distributed to help others in their research in the field of + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -21,209 +21,205 @@ Licence: #ifndef __KokkosUtilities_hpp__ #define __KokkosUtilities_hpp__ - #include "KokkosTypes.hpp" -#include "pFlowMacros.hpp" -#include "types.hpp" -#include "span.hpp" #include "dataIO.hpp" #include "iOstream.hpp" +#include "pFlowMacros.hpp" +#include "span.hpp" +#include "types.hpp" namespace pFlow { template -INLINE_FUNCTION_H -bool constexpr isHostAccessible() +INLINE_FUNCTION_H bool constexpr isHostAccessible() { - return Kokkos::SpaceAccessibility::accessible; + return Kokkos::SpaceAccessibility::accessible; } template -INLINE_FUNCTION_H -bool constexpr isDeviceAccessible() +INLINE_FUNCTION_H bool constexpr isDeviceAccessible() { - return Kokkos::SpaceAccessibility::accessible; + return Kokkos::SpaceAccessibility< + ExecutionSpace, + DefaultExecutionSpace::memory_space>::accessible; } /// Is MemoerySpace accessible from ExecutionSpace template -INLINE_FUNCTION_H -bool constexpr areAccessible() +INLINE_FUNCTION_H bool constexpr areAccessible() { - return Kokkos::SpaceAccessibility::accessible; + return Kokkos::SpaceAccessibility::accessible; } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocInit( ViewType1D& view, uint32 len) -{ - Kokkos::realloc(Kokkos::WithoutInitializing, view, len); -} - -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocNoInit(ViewType1D& view, uint32 len) +template +INLINE_FUNCTION_H void +reallocInit(ViewType1D& view, uint32 len) { Kokkos::realloc(Kokkos::WithoutInitializing, view, len); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocFill( ViewType1D& view, uint32 len, Type val) +template +INLINE_FUNCTION_H void +reallocNoInit(ViewType1D& view, uint32 len) +{ + Kokkos::realloc(Kokkos::WithoutInitializing, view, len); +} + +template +INLINE_FUNCTION_H void +reallocFill(ViewType1D& view, uint32 len, Type val) { reallocNoInit(view, len); Kokkos::deep_copy(view, val); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocInit( ViewType2D& view, uint32 len1, uint32 len2) +template +INLINE_FUNCTION_H void +reallocInit(ViewType2D& view, uint32 len1, uint32 len2) { Kokkos::realloc(view, len1, len2); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocNoInit(ViewType2D& view, uint32 len1, uint32 len2) -{ - Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2); +template +INLINE_FUNCTION_H void +reallocNoInit(ViewType2D& view, uint32 len1, uint32 len2) +{ + Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocFill( ViewType2D& view, uint32 len1, uint32 len2, Type val) +template +INLINE_FUNCTION_H void +reallocFill( + ViewType2D& view, + uint32 len1, + uint32 len2, + Type val +) { reallocNoInit(view, len1, len2); Kokkos::deep_copy(view, val); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocInit( ViewType3D& view, uint32 len1, uint32 len2, uint32 len3) +template +INLINE_FUNCTION_H void +reallocInit( + ViewType3D& view, + uint32 len1, + uint32 len2, + uint32 len3 +) { Kokkos::realloc(view, len1, len2, len3); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocNoInit(ViewType3D& view, uint32 len1, uint32 len2, uint32 len3) +template +INLINE_FUNCTION_H void +reallocNoInit( + ViewType3D& view, + uint32 len1, + uint32 len2, + uint32 len3 +) { - - Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2, len3); + Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2, len3); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocFill( ViewType3D& view, uint32 len1, uint32 len2, uint32 len3, Type val) +template +INLINE_FUNCTION_H void +reallocFill( + ViewType3D& view, + uint32 len1, + uint32 len2, + uint32 len3, + Type val +) { reallocNoInit(view, len1, len2, len3); Kokkos::deep_copy(view, val); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void resizeInit(ViewType1D& view, uint32 newLen) +template +INLINE_FUNCTION_H void +resizeInit(ViewType1D& view, uint32 newLen) { Kokkos::resize(view, newLen); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void resizeNoInit(ViewType1D& view, uint32 newLen) +template +INLINE_FUNCTION_H void +resizeNoInit(ViewType1D& view, uint32 newLen) { Kokkos::resize(Kokkos::WithoutInitializing, view, newLen); } template -INLINE_FUNCTION_H -void swapViews(ViewType& v1, ViewType &v2) +INLINE_FUNCTION_H void +swapViews(ViewType& v1, ViewType& v2) { static_assert( - std::is_move_assignable::value && std::is_move_constructible::value, - "swapViews arguments must be move assignable and move constructible"); + std::is_move_assignable_v && + std::is_move_constructible_v, + "swapViews arguments must be move assignable and move constructible" + ); ViewType tmp = std::move(v1); - v1 = std::move(v2); - v2 = std::move(tmp); + v1 = std::move(v2); + v2 = std::move(tmp); } - template -INLINE_FUNCTION_H -iOstream& operator <<(iOstream& os, const Pair& p) +INLINE_FUNCTION_H iOstream& +operator<<(iOstream& os, const Pair& p) { - os<<'('< -INLINE_FUNCTION_H -span makeSpan(ViewType1D & v) +INLINE_FUNCTION_H span + makeSpan(ViewType1D& v) { return span(v.data(), v.size()); } template -INLINE_FUNCTION_H -span makeSpan(ViewType1D & v, uint32 size) +INLINE_FUNCTION_H span + makeSpan(ViewType1D& v, uint32 size) { return span(v.data(), size); } template -INLINE_FUNCTION_H -span makeSpan(const ViewType1D & v) +INLINE_FUNCTION_H span + makeSpan(const ViewType1D& v) { return span(const_cast(v.data()), v.size()); } template -INLINE_FUNCTION_H -span makeSpan(const ViewType1D & v, uint32 size) +INLINE_FUNCTION_H span + makeSpan(const ViewType1D& v, uint32 size) { return span(const_cast(v.data()), size); } - template -INLINE_FUNCTION_H -iOstream& operator <<(iOstream& os, const ViewType1D & v) +INLINE_FUNCTION_H iOstream& +operator<<(iOstream& os, const ViewType1D& v) { - using ExSpace = typename ViewType1D::execution_space; - static_assert(isHostAccessible(), "View memory is not accessible from Host"); + static_assert( + isHostAccessible(), "View memory is not accessible from Host" + ); span spn(v.data(), v.size()); - os< -#include "pFlowMacros.hpp" -#include "typeInfo.hpp" #include "builtinTypes.hpp" #include "iOstream.hpp" - +#include "pFlowMacros.hpp" +#include "typeInfo.hpp" namespace pFlow { - /** * Range for elements in an vector [start,end) - * + * */ template -struct Range -: -public Kokkos::pair +struct Range : public Kokkos::pair { - using Pair = Kokkos::pair; + using Pair = Kokkos::pair; TypeInfoTemplateNV11("Range", T) - //// - Constructors + //// - Constructors - /// Default - INLINE_FUNCTION_HD - Range(){} + /// Default + INLINE_FUNCTION_HD Range() + { + } - /// From end, set start to 0 - INLINE_FUNCTION_HD - Range(const T& e) - : - Range(0,e) - {} - - /// From componeents - INLINE_FUNCTION_HD - Range(const T& s, const T& e) - : - Range::Pair(s,e) - {} + /// From end, set start to 0 + INLINE_FUNCTION_HD + Range(const T& e) + : Range(0, e) + { + } - /// From pair - INLINE_FUNCTION_HD - Range(const Range::Pair &src ) - : - Range::Pair(src) - {} + /// From componeents + INLINE_FUNCTION_HD + Range(const T& s, const T& e) + : Range::Pair(s, e) + { + } - /// Copy - INLINE_FUNCTION_HD - Range(const Range&) = default; + /// From pair + INLINE_FUNCTION_HD + Range(const Range::Pair& src) + : Range::Pair(src) + { + } - /// Move - INLINE_FUNCTION_HD - Range(Range&&) = default; + /// Copy + INLINE_FUNCTION_HD + Range(const Range&) = default; - /// Copy assignment - INLINE_FUNCTION_HD - Range& operator=(const Range&) = default; + /// Move + INLINE_FUNCTION_HD + Range(Range&&) = default; - /// Move assignment - INLINE_FUNCTION_HD - Range& operator=(Range&&) = default; + /// Copy assignment + INLINE_FUNCTION_HD + Range& operator=(const Range&) = default; - /// Destructor - INLINE_FUNCTION_HD - ~Range()=default; + /// Move assignment + INLINE_FUNCTION_HD + Range& operator=(Range&&) = default; + + /// Destructor + INLINE_FUNCTION_HD + ~Range() = default; //// - Methods - /// Start - INLINE_FUNCTION_HD - T& start() - { - return this->first; - } + /// Start + INLINE_FUNCTION_HD + T& start() + { + return this->first; + } - /// End - INLINE_FUNCTION_HD - T& end() - { - return this->second; - } + /// End + INLINE_FUNCTION_HD + T& end() + { + return this->second; + } - INLINE_FUNCTION_HD - const T& start()const - { - return this->first; - } + INLINE_FUNCTION_HD + const T& start() const + { + return this->first; + } - INLINE_FUNCTION_HD - const T& end()const - { - return this->second; - } + INLINE_FUNCTION_HD + const T& end() const + { + return this->second; + } - INLINE_FUNCTION_HD - T numElements() - { - return end()-start(); - } - - INLINE_FUNCTION_HD - auto getPair()const - { - return Pair(this->first, this->second); - } + INLINE_FUNCTION_HD + T numElements() + { + return end() - start(); + } + INLINE_FUNCTION_HD + auto getPair() const + { + return Pair(this->first, this->second); + } }; template -INLINE_FUNCTION_H -iOstream& operator <<(iOstream& os, const Range& rng) +INLINE_FUNCTION_H iOstream& +operator<<(iOstream& os, const Range& rng) { - os<<"["<; +using range32 = Range; -using range64 = Range; +using range64 = Range; -using rangeU32 = Range; - -using rangeU64 = Range; +using rangeU32 = Range; +using rangeU64 = Range; } // pFlow -#endif //__KokkosTypes_hpp__ +#endif //__KokkosTypes_hpp__ diff --git a/src/phasicFlow/Kokkos/ViewAlgorithms.hpp b/src/phasicFlow/Kokkos/ViewAlgorithms.hpp index d765e014..025534c9 100644 --- a/src/phasicFlow/Kokkos/ViewAlgorithms.hpp +++ b/src/phasicFlow/Kokkos/ViewAlgorithms.hpp @@ -2,17 +2,17 @@ O C enter of O O E ngineering and O O M ultiscale modeling of - OOOOOOO F luid flow + OOOOOOO F luid flow ------------------------------------------------------------------------------ Copyright (C): www.cemf.ir email: hamid.r.norouzi AT gmail.com ------------------------------------------------------------------------------- +------------------------------------------------------------------------------ Licence: - This file is part of phasicFlow code. It is a free software for simulating + This file is part of phasicFlow code. It is a free software for simulating granular and multiphase flows. You can redistribute it and/or modify it under - the terms of GNU General Public License v3 or any other later versions. - - phasicFlow is distributed to help others in their research in the field of + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -21,57 +21,48 @@ Licence: #ifndef __ViewAlgorithms_hpp__ #define __ViewAlgorithms_hpp__ - -#include "numericConstants.hpp" -#include "Range.hpp" #include "KokkosUtilities.hpp" +#include "Range.hpp" +#include "numericConstants.hpp" +#include "cudaAlgorithms.hpp" #include "kokkosAlgorithms.hpp" #include "stdAlgorithms.hpp" -#include "cudaAlgorithms.hpp" - namespace pFlow -{ -template -INLINE_FUNCTION_H -uint32 count( - const ViewType1D& view, - uint32 start, - uint32 end, - const T& val) { - - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; - - return pFlow::algorithms::KOKKOS::count - ( - view.data()+start, - numElems, - val - ); -} - template -INLINE_FUNCTION_H -void fill -( - ViewType1D& view, - rangeU32 span, - T val +INLINE_FUNCTION_H uint32 +count( + const ViewType1D& view, + uint32 start, + uint32 end, + const T& val ) +{ + using ExecutionSpace = + typename ViewType1D::execution_space; + + uint32 numElems = end - start; + + return pFlow::algorithms::KOKKOS::count( + view.data() + start, numElems, val + ); +} + +template +INLINE_FUNCTION_H void +fill(ViewType1D& view, rangeU32 span, T val) { using exe_space = typename ViewType1D::execution_space; - auto subV = Kokkos::subview(view, span.getPair() ); - if constexpr ( std::is_trivially_copyable_v) + auto subV = Kokkos::subview(view, span.getPair()); + if constexpr (std::is_trivially_copyable_v) { Kokkos::deep_copy(subV, val); } - else if constexpr( isHostAccessible()) + else if constexpr (isHostAccessible()) { - for(auto i=span.start(); i -void fill -( - ViewType1D& view, - uint32 start, - uint32 end, - T val -) +void +fill(ViewType1D& view, uint32 start, uint32 end, T val) { - fill(view, rangeU32(start, end),val); + fill(view, rangeU32(start, end), val); } template -void fill -( - ViewType3D& view, - rangeU32 range1, - rangeU32 range2, - rangeU32 range3, - const T& val +void +fill( + ViewType3D& view, + rangeU32 range1, + rangeU32 range2, + rangeU32 range3, + const T& val ) { static_assert(std::is_trivially_copyable_v, "Not valid type for fill"); @@ -111,222 +96,201 @@ void fill } template -void fill -( - ViewType3D& view, - const T& val -) +void +fill(ViewType3D& view, const T& val) { static_assert(std::is_trivially_copyable_v, "Not valid type for fill"); Kokkos::deep_copy(view, val); } -template< - typename Type, - typename... properties> -void fillSequence( - ViewType1D& view, - uint32 start, - uint32 end, - const Type startVal - ) -{ - static_assert(std::is_trivially_copyable_v, "Not valid type for fill"); - using ExecutionSpace = typename ViewType1D::execution_space; - uint32 numElems = end-start; - - pFlow::algorithms::KOKKOS::fillSequence( - view.data()+start, - numElems, - startVal); - - return ; -} - - -template< - typename Type, - typename... properties, - typename indexType, - typename... indexProperties> -bool fillSelected -( - ViewType1D view, - ViewType1D indices, - uint32 numElems, - Type val +template +void +fillSequence( + ViewType1D& view, + uint32 start, + uint32 end, + const Type startVal ) { - - static_assert(std::is_trivially_copyable_v, "Not valid type for fillSelected"); static_assert( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In fillSelected, arguments view and indices must have similar spaces"); + std::is_trivially_copyable_v, "Not valid type for fill" + ); + using ExecutionSpace = + typename ViewType1D::execution_space; + uint32 numElems = end - start; + + pFlow::algorithms::KOKKOS::fillSequence( + view.data() + start, numElems, startVal + ); + + return; +} + +template< + typename Type, + typename... properties, + typename indexType, + typename... indexProperties> +bool +fillSelected( + ViewType1D view, + ViewType1D indices, + uint32 numElems, + Type val +) +{ + static_assert( + std::is_trivially_copyable_v, "Not valid type for fillSelected" + ); + static_assert( + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In fillSelected, arguments view and indices must have similar spaces" + ); using ExSpace = typename ViewType1D::execution_space; - using policy = Kokkos::RangePolicy >; + using policy = Kokkos::RangePolicy>; Kokkos::parallel_for( - "ViewAlgorithms::fillSelected", - policy(0,numElems), - LAMBDA_HD(uint32 i){ - //view[indices[i]]= val; - }); + "ViewAlgorithms::fillSelected", + policy(0, numElems), + LAMBDA_HD(uint32 i){ + // view[indices[i]]= val; + } + ); Kokkos::fence(); return true; } template< - typename Type, - typename... properties, - typename indexType, - typename... indexProperties> -bool fillSelected( - ViewType1D view, - const ViewType1D indices, - const ViewType1D vals, - const uint32 numElems ) + typename Type, + typename... properties, + typename indexType, + typename... indexProperties> +bool +fillSelected( + ViewType1D view, + const ViewType1D indices, + const ViewType1D vals, + const uint32 numElems +) { - static_assert(std::is_trivially_copyable_v, "Not valid type for fillSelected"); static_assert( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In fillSelected arguments view and indices must have similar spaces"); + std::is_trivially_copyable_v, "Not valid type for fillSelected" + ); + static_assert( + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In fillSelected arguments view and indices must have similar spaces" + ); + + using ExecutionSpace = + typename ViewType1D::execution_space; - using ExecutionSpace = typename ViewType1D::execution_space; - pFlow::algorithms::KOKKOS::fillSelected( - view.data(), - indices.data(), - vals.data(), - numElems - ); + view.data(), indices.data(), vals.data(), numElems + ); return true; } - template -INLINE_FUNCTION_H -T min( - const ViewType1D& view, - uint32 start, - uint32 end) +INLINE_FUNCTION_H T +min(const ViewType1D& view, uint32 start, uint32 end) { + using ExecutionSpace = + typename ViewType1D::execution_space; - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; - - return - pFlow::algorithms::KOKKOS::min( - view.data()+start, - numElems); + uint32 numElems = end - start; + + return pFlow::algorithms::KOKKOS::min( + view.data() + start, numElems + ); } template -INLINE_FUNCTION_H -T max( - const ViewType1D& view, - uint32 start, - uint32 end) +INLINE_FUNCTION_H T +max(const ViewType1D& view, uint32 start, uint32 end) { + using ExecutionSpace = + typename ViewType1D::execution_space; - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; + uint32 numElems = end - start; - return - pFlow::algorithms::KOKKOS::max( - view.data()+start, - numElems); -} - -template < - typename dType, - typename... dProperties, - typename sType, - typename... sProperties> -INLINE_FUNCTION_H -void copy( - const ViewType1D& dst, - const ViewType1D& src - ) -{ - Kokkos::deep_copy(dst,src); + return pFlow::algorithms::KOKKOS::max( + view.data() + start, numElems + ); } -template < - typename dType, - typename... dProperties, - typename sType, - typename... sProperties> -INLINE_FUNCTION_H -void copy( - const ViewType1D& dst, - uint32 dStart, - const ViewType1D& src, - uint32 sStart, - uint32 sEnd - ) +template< + typename dType, + typename... dProperties, + typename sType, + typename... sProperties> +INLINE_FUNCTION_H void +copy( + const ViewType1D& dst, + const ViewType1D& src +) { - - range32 sSpan(sStart,sEnd); - range32 dSpan(dStart,dStart+(sEnd-sStart)); - - auto srcSub = Kokkos::subview(src, sSpan); - auto dstSub = Kokkos::subview(dst, dSpan); - - Kokkos::deep_copy(dstSub,srcSub); + Kokkos::deep_copy(dst, src); } -template < - typename Type, - typename... sProperties> -INLINE_FUNCTION_H -void getNth( - Type& dst, - const ViewType1D& src, - const uint32 n - ) +template< + typename dType, + typename... dProperties, + typename sType, + typename... sProperties> +INLINE_FUNCTION_H void +copy( + const ViewType1D& dst, + uint32 dStart, + const ViewType1D& src, + uint32 sStart, + uint32 sEnd +) { - - auto subV = Kokkos::subview(src, Kokkos::make_pair(n,n+1)); - hostViewType1D dstView("getNth",1); - //hostViewTypeScalar - Kokkos::deep_copy(dstView,subV); + range32 sSpan(sStart, sEnd); + range32 dSpan(dStart, dStart + (sEnd - sStart)); + + auto srcSub = Kokkos::subview(src, sSpan); + auto dstSub = Kokkos::subview(dst, dSpan); + + Kokkos::deep_copy(dstSub, srcSub); +} + +template +INLINE_FUNCTION_H void +getNth(Type& dst, const ViewType1D& src, const uint32 n) +{ + auto subV = Kokkos::subview(src, Kokkos::make_pair(n, n + 1)); + hostViewType1D dstView("getNth", 1); + // hostViewTypeScalar + Kokkos::deep_copy(dstView, subV); dst = *dstView.data(); } - template -INLINE_FUNCTION_H -void sort( - ViewType1D& view, - uint32 start, - uint32 end) +INLINE_FUNCTION_H void +sort(ViewType1D& view, uint32 start, uint32 end) { - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; + using ExecutionSpace = + typename ViewType1D::execution_space; - if constexpr( isHostAccessible()) - { - pFlow::algorithms::STD::sort( - view.data()+start, - numElems); + uint32 numElems = end - start; + + if constexpr (isHostAccessible()) + { + pFlow::algorithms::STD::sort(view.data() + start, numElems); return; } #ifdef __CUDACC__ - - pFlow::algorithms::CUDA::sort( - view.data()+start, - numElems); + + pFlow::algorithms::CUDA::sort(view.data() + start, numElems); #else static_assert("sort on device is not defined!"); @@ -336,33 +300,32 @@ void sort( } template -INLINE_FUNCTION_H -void sort( - ViewType1D& view, - uint32 start, - uint32 end, - CompareFunc compare) +INLINE_FUNCTION_H void +sort( + ViewType1D& view, + uint32 start, + uint32 end, + CompareFunc compare +) { + using ExecutionSpace = + typename ViewType1D::execution_space; - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; + uint32 numElems = end - start; - if constexpr( isHostAccessible()) + if constexpr (isHostAccessible()) { - pFlow::algorithms::STD::sort( - view.data()+start, - numElems, - compare); - return; + pFlow::algorithms::STD::sort( + view.data() + start, numElems, compare + ); + return; } #ifdef __CUDACC__ - + pFlow::algorithms::CUDA::sort( - view.data()+start, - numElems, - compare); + view.data() + start, numElems, compare + ); #else static_assert("sort on device is not defined!"); @@ -372,163 +335,157 @@ void sort( } template< - typename Type, - typename... properties, - typename permType, - typename... permProperties> -void permuteSort( - const ViewType1D& view, - uint32 start, - uint32 end, - ViewType1D& permuteView, - uint32 permStart ) + typename Type, + typename... properties, + typename permType, + typename... permProperties> +void +permuteSort( + const ViewType1D& view, + uint32 start, + uint32 end, + ViewType1D& permuteView, + uint32 permStart +) { static_assert( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In permuteSort, view and permuteView should have the same space"); + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In permuteSort, view and permuteView should have the same space" + ); - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; - - pFlow::algorithms::STD::permuteSort( - view.data()+start, - permuteView.data()+permStart, - numElems); + using ExecutionSpace = + typename ViewType1D::execution_space; + + uint32 numElems = end - start; + + pFlow::algorithms::STD::permuteSort( + view.data() + start, permuteView.data() + permStart, numElems + ); return; - #ifdef __CUDACC__ - + pFlow::algorithms::CUDA::permuteSort( - view.data()+start, - permuteView.data()+permStart, - numElems); + view.data() + start, permuteView.data() + permStart, numElems + ); #else static_assert("sort on device is not defined!"); #endif - } template -INLINE_FUNCTION_HD -int32 binarySearch_(const T* array, int32 length, const T& val) +INLINE_FUNCTION_HD int32 +binarySearch_(const T* array, int32 length, const T& val) { - if(length <= 0) return -1; - - int low = 0; - int high = length - 1; + if (length <= 0) + return -1; - while (low <= high) - { - int mid = low + (high - low)/2; - - if ( array[mid] > val) - { - high = mid - 1; - } - else if ( array[mid] < val) - { - low = mid + 1; - } - else - { - return mid; - } - } + int low = 0; + int high = length - 1; - return -1; // val not found in array[0, length) + while (low <= high) + { + int mid = low + (high - low) / 2; + + if (array[mid] > val) + { + high = mid - 1; + } + else if (array[mid] < val) + { + low = mid + 1; + } + else + { + return mid; + } + } + + return -1; // val not found in array[0, length) } -/// On DEVICE and HOST calls -template< - typename Type, - typename... properties> -INLINE_FUNCTION_HD -uint32 binarySearch( - const ViewType1D& view, - uint32 start, - uint32 end, - const Type& val) +/// On DEVICE and HOST calls +template +INLINE_FUNCTION_HD uint32 +binarySearch( + const ViewType1D& view, + uint32 start, + uint32 end, + const Type& val +) { - - if(end<=start)return -1; + if (end <= start) + return -1; - if(auto res = - binarySearch_(view.data()+start,end-start,val); res!=-1) { - return res+start; + if (auto res = binarySearch_(view.data() + start, end - start, val); + res != -1) + { + return res + start; } - else{ + else + { return res; } } -template< - typename Type, - typename... properties, - typename... dProperties> -void exclusiveScan( - const ViewType1D& view, - uint32 start, - uint32 end, - ViewType1D& dView, - uint32 dStart ) +template +void +exclusiveScan( + const ViewType1D& view, + uint32 start, + uint32 end, + ViewType1D& dView, + uint32 dStart +) { - - static_assert - ( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In exclusiveScan, view and dView should have the same space" + static_assert( + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In exclusiveScan, view and dView should have the same space" ); - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; - - pFlow::algorithms::KOKKOS::exclusiveScan( - view.data()+start, - dView.data()+dStart, - numElems); + using ExecutionSpace = + typename ViewType1D::execution_space; + + uint32 numElems = end - start; + + pFlow::algorithms::KOKKOS::exclusiveScan( + view.data() + start, dView.data() + dStart, numElems + ); } - -template< - typename Type, - typename... properties, - typename... dProperties> -void inclusiveScan( - const ViewType1D& view, - uint32 start, - uint32 end, - ViewType1D& dView, - uint32 dStart) +template +void +inclusiveScan( + const ViewType1D& view, + uint32 start, + uint32 end, + ViewType1D& dView, + uint32 dStart +) { - using ExecutionSpace = typename ViewType1D::execution_space; - - static_assert - ( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In exclusiveScan, view and dView should have the same space" + using ExecutionSpace = + typename ViewType1D::execution_space; + + static_assert( + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In exclusiveScan, view and dView should have the same space" ); + uint32 numElems = end - start; - uint32 numElems = end-start; - - pFlow::algorithms::KOKKOS::inclusiveScan( - view.data()+start, - dView.data()+dStart, - numElems); + pFlow::algorithms::KOKKOS::inclusiveScan( + view.data() + start, dView.data() + dStart, numElems + ); } } // pFlow - -#endif // Viewalgorithms +#endif // __ViewAlgorithms_hpp__ diff --git a/src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp b/src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp index c4fa96ad..779c0b03 100644 --- a/src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp +++ b/src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp @@ -2,50 +2,50 @@ O C enter of O O E ngineering and O O M ultiscale modeling of - OOOOOOO F luid flow + OOOOOOO F luid flow ------------------------------------------------------------------------------ Copyright (C): www.cemf.ir email: hamid.r.norouzi AT gmail.com ------------------------------------------------------------------------------- +------------------------------------------------------------------------------ Licence: - This file is part of phasicFlow code. It is a free software for simulating + This file is part of phasicFlow code. It is a free software for simulating granular and multiphase flows. You can redistribute it and/or modify it under - the terms of GNU General Public License v3 or any other later versions. - - phasicFlow is distributed to help others in their research in the field of + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ template -void insertSetElementH -( - ViewType1D& view, - hostViewType1D