diff --git a/cmake/globals.cmake b/cmake/globals.cmake index b2c084a3..34c075b4 100644 --- a/cmake/globals.cmake +++ b/cmake/globals.cmake @@ -4,9 +4,9 @@ list(APPEND validFiles *.C *.cpp *.cxx *.c *.cu *.H *.hpp *.hxx *.h *.cuh) macro(Kokkos_cmake_settings) -mark_as_advanced(FORCE var Kokkos_ENABLE_CUDA_LAMBDA) +#mark_as_advanced(FORCE var Kokkos_ENABLE_CUDA_LAMBDA) mark_as_advanced(FORCE var Kokkos_CXX_STANDARD) -mark_as_advanced(FORCE var Kokkos_ENABLE_CUDA_CONSTEXPR) +#mark_as_advanced(FORCE var Kokkos_ENABLE_CUDA_CONSTEXPR) mark_as_advanced(FORCE var Kokkos_ENABLE_OPENMP) mark_as_advanced(FORCE var Kokkos_ENABLE_SERIAL) mark_as_advanced(FORCE var Kokkos_ENABLE_CUDA) diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 5114f190..d9d701eb 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -21,7 +21,8 @@ streams/TStream/iTstream.cpp streams/TStream/oTstream.cpp streams/Fstream/iFstream.cpp streams/Fstream/oFstream.cpp -streams/Fstream/fileStream.cpp +streams/Fstream/fileStream.cpp +streams/dataIO/dataIO.cpp streams/streams.cpp fileSystem/fileSystem.cpp @@ -33,6 +34,12 @@ dictionary/entry/iEntry.cpp dictionary/entry/dataEntry.cpp dictionary/twoPartEntry/twoPartEntry.cpp +containers/Vector/Vectors.cpp + +repository/IOobject/objectFile.cpp +repository/IOobject/IOfileHeader.cpp +repository/IOobject/IOobject.cpp + ) set(link_libs) diff --git a/src/phasicFlow/Kokkos/KokkosUtilities.hpp b/src/phasicFlow/Kokkos/KokkosUtilities.hpp index 1b42bba7..451920ab 100644 --- a/src/phasicFlow/Kokkos/KokkosUtilities.hpp +++ b/src/phasicFlow/Kokkos/KokkosUtilities.hpp @@ -25,6 +25,7 @@ Licence: #include "KokkosTypes.hpp" #include "pFlowMacros.hpp" #include "types.hpp" +#include "span.hpp" #include "iOstream.hpp" namespace pFlow @@ -41,7 +42,7 @@ template INLINE_FUNCTION_H bool constexpr isDeviceAccessible() { - return Kokkos::SpaceAccessibility::accessible; + return Kokkos::SpaceAccessibility::accessible; } /// Is MemoerySpace accessible from ExecutionSpace @@ -56,7 +57,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocInit( ViewType1D& view, int32 len) +void reallocInit( ViewType1D& view, uint32 len) { Kokkos::realloc(Kokkos::WithoutInitializing, view, len); } @@ -65,7 +66,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocNoInit(ViewType1D& view, int32 len) +void reallocNoInit(ViewType1D& view, uint32 len) { Kokkos::realloc(Kokkos::WithoutInitializing, view, len); } @@ -74,7 +75,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocFill( ViewType1D& view, int32 len, Type val) +void reallocFill( ViewType1D& view, uint32 len, Type val) { reallocNoInit(view, len); Kokkos::deep_copy(view, val); @@ -84,7 +85,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocInit( ViewType2D& view, int32 len1, int32 len2) +void reallocInit( ViewType2D& view, uint32 len1, uint32 len2) { Kokkos::realloc(view, len1, len2); } @@ -93,7 +94,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocNoInit(ViewType2D& view, int32 len1, int32 len2) +void reallocNoInit(ViewType2D& view, uint32 len1, uint32 len2) { Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2); } @@ -102,7 +103,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocFill( ViewType2D& view, int32 len1, int32 len2, Type val) +void reallocFill( ViewType2D& view, uint32 len1, uint32 len2, Type val) { reallocNoInit(view, len1, len2); Kokkos::deep_copy(view, val); @@ -112,7 +113,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocInit( ViewType3D& view, int32 len1, int32 len2, int32 len3) +void reallocInit( ViewType3D& view, uint32 len1, uint32 len2, uint32 len3) { Kokkos::realloc(view, len1, len2, len3); } @@ -121,7 +122,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocNoInit(ViewType3D& view, int32 len1, int32 len2, int32 len3) +void reallocNoInit(ViewType3D& view, uint32 len1, uint32 len2, uint32 len3) { Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2, len3); @@ -131,7 +132,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void reallocFill( ViewType3D& view, int32 len1, int32 len2, int32 len3, Type val) +void reallocFill( ViewType3D& view, uint32 len1, uint32 len2, uint32 len3, Type val) { reallocNoInit(view, len1, len2, len3); Kokkos::deep_copy(view, val); @@ -141,7 +142,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void resizeInit(ViewType1D& view, int32 newLen) +void resizeInit(ViewType1D& view, uint32 newLen) { Kokkos::resize(view, newLen); } @@ -150,7 +151,7 @@ template < typename Type, typename... Properties> INLINE_FUNCTION_H -void resizeNoInit(ViewType1D& view, int32 newLen) +void resizeNoInit(ViewType1D& view, uint32 newLen) { Kokkos::resize(Kokkos::WithoutInitializing, view, newLen); } @@ -177,6 +178,22 @@ iOstream& operator <<(iOstream& os, const Pair& p) return os; } +template +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"); + + span spn(v.data(), v.size()); + os< return end()-start(); } + INLINE_FUNCTION_HD + auto getPair()const + { + return Pair(this->first, this->second); + } + }; template @@ -143,6 +149,10 @@ using range32 = Range; using range64 = Range; +using rangeU32 = Range; + +using rangeU64 = Range; + } // pFlow diff --git a/src/phasicFlow/Kokkos/ViewAlgorithms.hpp b/src/phasicFlow/Kokkos/ViewAlgorithms.hpp index 112569c6..7e8134a9 100644 --- a/src/phasicFlow/Kokkos/ViewAlgorithms.hpp +++ b/src/phasicFlow/Kokkos/ViewAlgorithms.hpp @@ -35,16 +35,16 @@ namespace pFlow { template INLINE_FUNCTION_H -int32 count( +uint32 count( const ViewType1D& view, - int32 start, - int32 end, + uint32 start, + uint32 end, const T& val) { using ExecutionSpace = typename ViewType1D::execution_space; - int32 numElems = end-start; + uint32 numElems = end-start; return pFlow::algorithms::KOKKOS::count ( @@ -59,11 +59,11 @@ INLINE_FUNCTION_H void fill ( ViewType1D& view, - range32 span, + rangeU32 span, T val ) { - auto subV = Kokkos::subview(view, span); + auto subV = Kokkos::subview(view, span.getPair() ); Kokkos::deep_copy(subV, val); } @@ -71,12 +71,12 @@ template void fill ( ViewType1D& view, - int32 start, - int32 end, + uint32 start, + uint32 end, T val ) { - fill(view, range32(start,end),val); + fill(view, rangeU32(start, end),val); } template< @@ -84,14 +84,14 @@ template< typename... properties> void fillSequence( ViewType1D& view, - int32 start, - int32 end, + uint32 start, + uint32 end, const Type startVal ) { using ExecutionSpace = typename ViewType1D::execution_space; - int32 numElems = end-start; + uint32 numElems = end-start; pFlow::algorithms::KOKKOS::fillSequence( view.data()+start, @@ -110,24 +110,27 @@ template< bool fillSelected ( ViewType1D view, - const ViewType1D indices, - const int32 numElems, - const Type val + ViewType1D indices, + uint32 numElems, + Type val ) { static_assert( areAccessible< typename ViewType1D::execution_space, typename ViewType1D::memory_space>(), - "In fillSelected arguments view and indices must have similar spaces"); + "In fillSelected, arguments view and indices must have similar spaces"); - using ExecutionSpace = typename ViewType1D::execution_space; - - pFlow::algorithms::KOKKOS::fillSelected( - view.data(), - indices.data(), - numElems, - val); + using ExSpace = typename ViewType1D::execution_space; + using policy = Kokkos::RangePolicy >; + + Kokkos::parallel_for( + "ViewAlgorithms::fillSelected", + policy(0,numElems), + LAMBDA_HD(uint32 i){ + //view[indices[i]]= val; + }); + Kokkos::fence(); return true; } @@ -141,7 +144,7 @@ bool fillSelected( ViewType1D view, const ViewType1D indices, const ViewType1D vals, - const int32 numElems ) + const uint32 numElems ) { static_assert( @@ -167,14 +170,15 @@ template INLINE_FUNCTION_H T min( const ViewType1D& view, - int32 start, - int32 end) + uint32 start, + uint32 end) { using ExecutionSpace = typename ViewType1D::execution_space; - int32 numElems = end-start; - + uint32 numElems = end-start; + + return pFlow::algorithms::KOKKOS::min( view.data()+start, numElems); @@ -184,13 +188,13 @@ template INLINE_FUNCTION_H T max( const ViewType1D& view, - int32 start, - int32 end) + uint32 start, + uint32 end) { using ExecutionSpace = typename ViewType1D::execution_space; - int32 numElems = end-start; + uint32 numElems = end-start; return pFlow::algorithms::KOKKOS::max( @@ -220,10 +224,10 @@ template < INLINE_FUNCTION_H void copy( const ViewType1D& dst, - int32 dStart, + uint32 dStart, const ViewType1D& src, - int32 sStart, - int32 sEnd + uint32 sStart, + uint32 sEnd ) { @@ -244,7 +248,7 @@ INLINE_FUNCTION_H void getNth( dType& dst, const ViewType1D& src, - const int32 n + const uint32 n ) { range32 span(n,n+1); @@ -259,12 +263,12 @@ template INLINE_FUNCTION_H void sort( ViewType1D& view, - int32 start, - int32 end) + uint32 start, + uint32 end) { using ExecutionSpace = typename ViewType1D::execution_space; - int32 numElems = end-start; + uint32 numElems = end-start; if constexpr( isHostAccessible()) { @@ -291,14 +295,14 @@ template INLINE_FUNCTION_H void sort( ViewType1D& view, - int32 start, - int32 end, + uint32 start, + uint32 end, CompareFunc compare) { using ExecutionSpace = typename ViewType1D::execution_space; - int32 numElems = end-start; + uint32 numElems = end-start; if constexpr( isHostAccessible()) { @@ -330,10 +334,10 @@ template< typename... permProperties> void permuteSort( const ViewType1D& view, - int32 start, - int32 end, + uint32 start, + uint32 end, ViewType1D& permuteView, - int32 permStart ) + uint32 permStart ) { static_assert( areAccessible< @@ -343,7 +347,7 @@ void permuteSort( using ExecutionSpace = typename ViewType1D::execution_space; - int32 numElems = end-start; + uint32 numElems = end-start; pFlow::algorithms::STD::permuteSort( view.data()+start, @@ -367,8 +371,9 @@ void permuteSort( template INLINE_FUNCTION_HD -int binarySearch_(const T* array, int length, const T& val) +int32 binarySearch_(const T* array, int32 length, const T& val) { + if(length <= 0) return -1; int low = 0; int high = length - 1; @@ -401,8 +406,8 @@ template< INLINE_FUNCTION_HD int32 binarySearch( const ViewType1D& view, - int32 start, - int32 end, + uint32 start, + uint32 end, const Type& val) { @@ -424,10 +429,10 @@ template< typename... dProperties> void exclusiveScan( const ViewType1D& view, - int32 start, - int32 end, + uint32 start, + uint32 end, ViewType1D& dView, - int32 dStart ) + uint32 dStart ) { static_assert @@ -441,7 +446,7 @@ void exclusiveScan( using ExecutionSpace = typename ViewType1D::execution_space; - int32 numElems = end-start; + uint32 numElems = end-start; pFlow::algorithms::KOKKOS::exclusiveScan( view.data()+start, @@ -457,10 +462,10 @@ template< typename... dProperties> void inclusiveScan( const ViewType1D& view, - int32 start, - int32 end, + uint32 start, + uint32 end, ViewType1D& dView, - int32 dStart) + uint32 dStart) { using ExecutionSpace = typename ViewType1D::execution_space; @@ -473,7 +478,7 @@ void inclusiveScan( ); - int32 numElems = end-start; + uint32 numElems = end-start; pFlow::algorithms::KOKKOS::inclusiveScan( view.data()+start, diff --git a/src/phasicFlow/Kokkos/phsicFlowKokkos.hpp b/src/phasicFlow/Kokkos/phasicFlowKokkos.hpp similarity index 97% rename from src/phasicFlow/Kokkos/phsicFlowKokkos.hpp rename to src/phasicFlow/Kokkos/phasicFlowKokkos.hpp index 22666e49..3372ba8a 100644 --- a/src/phasicFlow/Kokkos/phsicFlowKokkos.hpp +++ b/src/phasicFlow/Kokkos/phasicFlowKokkos.hpp @@ -21,7 +21,7 @@ Licence: #ifndef __phsicFlowKokkos_hpp__ #define __phsicFlowKokkos_hpp__ -#include "kokkosTypes.hpp" +#include "KokkosTypes.hpp" #include "KokkosUtilities.hpp" #include "ViewAlgorithms.hpp" #include "Range.hpp" diff --git a/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp b/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp index 8d12d1a6..ed150eed 100644 --- a/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp +++ b/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp @@ -64,16 +64,16 @@ protected: bool copy(const ListPtrType& src); // - return ith pointer - T* ptr(label i); + T* ptr(size_t i); // - return ith const poiter - const T* ptr(label i)const; + const T* ptr(size_t i)const; // - iterator position of ith element - auto pos(label i); + auto pos(size_t i); // - const iterator position of ith element - auto pos(label i) const; + auto pos(size_t i) const; public: @@ -141,15 +141,15 @@ public: //// - Methods // - set the ith element - T* set(label i, T* ptr); + T* set(size_t i, T* ptr); // - set the ith element and take the ownership from uniquePtr - uniquePtr set(label i, uniquePtr& ptr ); + uniquePtr set(size_t i, uniquePtr& ptr ); // - create the object in-place and set the pointer in ith position // if oject creation fails, uniquePtr deletes the memeory template - uniquePtr setSafe(label i, Args&&... args); + uniquePtr setSafe(size_t i, Args&&... args); // - put the pointer at the end void push_back(T* ptr); @@ -163,11 +163,11 @@ public: // - access to ith element // fatalexit if out of range or nullptr - T& operator[](label i); + T& operator[](size_t i); // - const access to ith element // fatalexit if out of range or nullptr - const T& operator[](label i) const; + const T& operator[](size_t i) const; // size of container size_t size()const; @@ -176,13 +176,13 @@ public: auto empty() const; // release the ownership of ith pointer - uniquePtr release(label i); + uniquePtr release(size_t i); // - clear the content of list and delete objects void clear(); // - clear the ith element - void clear(label i); + void clear(size_t i); // - clone the object diff --git a/src/phasicFlow/containers/List/ListPtr/ListPtrI.hpp b/src/phasicFlow/containers/List/ListPtr/ListPtrI.hpp index 2d476154..57f42c2b 100644 --- a/src/phasicFlow/containers/List/ListPtr/ListPtrI.hpp +++ b/src/phasicFlow/containers/List/ListPtr/ListPtrI.hpp @@ -39,7 +39,7 @@ inline bool pFlow::ListPtr::copy(const ListPtrType& src) } template -T* pFlow::ListPtr::ptr(label i) +T* pFlow::ListPtr::ptr(size_t i) { if(i >= size() ) return nullptr; @@ -53,7 +53,7 @@ T* pFlow::ListPtr::ptr(label i) template const T* pFlow::ListPtr::ptr ( - label i + size_t i ) const { @@ -68,7 +68,7 @@ const T* pFlow::ListPtr::ptr template auto pFlow::ListPtr::pos ( - label i + size_t i ) { if(i >= size() ) @@ -86,7 +86,7 @@ auto pFlow::ListPtr::pos template auto pFlow::ListPtr::pos ( - label i + size_t i )const { if(i >= size() ) @@ -146,7 +146,7 @@ pFlow::ListPtr& pFlow::ListPtr::operator= template T* pFlow::ListPtr::set ( - label i, T* ptr + size_t i, T* ptr ) { uniquePtr uptr(ptr); @@ -157,7 +157,7 @@ T* pFlow::ListPtr::set template pFlow::uniquePtr pFlow::ListPtr::set ( - label i, + size_t i, uniquePtr& ptr ) { @@ -182,7 +182,7 @@ template template pFlow::uniquePtr pFlow::ListPtr::setSafe ( - label i, + size_t i, Args&&... args ) { @@ -216,7 +216,7 @@ void pFlow::ListPtr::push_backSafe(Args&&... args) template T& pFlow::ListPtr::operator[] ( - label i + size_t i ) { T* p = ptr(i); @@ -234,7 +234,7 @@ T& pFlow::ListPtr::operator[] template const T& pFlow::ListPtr::operator[] ( - label i + size_t i ) const { const T* p = ptr(i); @@ -263,7 +263,7 @@ auto pFlow::ListPtr::empty() const template pFlow::uniquePtr pFlow::ListPtr::release ( - label i + size_t i ) { auto p = ptr(i); @@ -288,7 +288,7 @@ void pFlow::ListPtr::clear() template void pFlow::ListPtr::clear ( - label i + size_t i ) { T* p = ptr(i); diff --git a/src/phasicFlow/containers/Map/Map/Map.hpp b/src/phasicFlow/containers/Map/Map/Map.hpp index 16c0b9d3..ffeef6b0 100644 --- a/src/phasicFlow/containers/Map/Map/Map.hpp +++ b/src/phasicFlow/containers/Map/Map/Map.hpp @@ -138,7 +138,7 @@ template using wordMap = Map; template -using labelMap = Map; +using uint64Map = Map; template using uint32Map = Map; @@ -155,7 +155,7 @@ template inline iOstream& printKeys(iOstream& os, const wordMap & m); template -inline iOstream& printKeys(iOstream& os, const labelMap & m); +inline iOstream& printKeys(iOstream& os, const uint64Map & m); template inline iOstream& printKeys(iOstream& os, const uint32Map & m); diff --git a/src/phasicFlow/containers/Map/Map/MapI.hpp b/src/phasicFlow/containers/Map/Map/MapI.hpp index 7d52ea7e..7b28efcd 100644 --- a/src/phasicFlow/containers/Map/Map/MapI.hpp +++ b/src/phasicFlow/containers/Map/Map/MapI.hpp @@ -92,7 +92,7 @@ inline iOstream& printKeys(iOstream& os, const uint32Map & m) } template -inline iOstream& printKeys(iOstream& os, const labelMap & m) +inline iOstream& printKeys(iOstream& os, const uint64Map & m) { if (m.empty()) return os<<"labelMap is empty"< using wordHashMap = hashMap; template -using labelHashMap = hashMap; +using uint64HashMap = hashMap; template using uint32HashMap = hashMap; @@ -155,7 +155,7 @@ template inline iOstream& printKeys(iOstream& os, const wordHashMap & m); template -inline iOstream& printKeys(iOstream& os, const labelHashMap & m); +inline iOstream& printKeys(iOstream& os, const uint64HashMap & m); template inline iOstream& printKeys(iOstream& os, const uint32HashMap & m); diff --git a/src/phasicFlow/containers/Map/hashMap/hashMapI.hpp b/src/phasicFlow/containers/Map/hashMap/hashMapI.hpp index 74e85e6d..4c45687a 100644 --- a/src/phasicFlow/containers/Map/hashMap/hashMapI.hpp +++ b/src/phasicFlow/containers/Map/hashMap/hashMapI.hpp @@ -80,7 +80,7 @@ inline iOstream& printKeys(iOstream& os, const wordHashMap & m) template -inline iOstream& printKeys(iOstream& os, const labelHashMap & m) +inline iOstream& printKeys(iOstream& os, const uint64HashMap & m) { if (m.empty()) return os<<"labelHashMap is empty"< -pFlow::Vector::Vector(iIstream& is) -{ - readVector(is); -} - template bool pFlow::Vector::readVector ( @@ -33,7 +27,6 @@ bool pFlow::Vector::readVector ) { - if(is.isBinary() && !std::is_same_v) { this->resize(len); @@ -90,8 +83,6 @@ bool pFlow::Vector::readVector } } - - return true; } @@ -102,8 +93,12 @@ bool pFlow::Vector::writeVector iOstream& os ) const { + + span s( const_cast(this->data()), this->size()); + os<) + /*if( os.isBinary() && !std::is_same_v) { os.write(reinterpret_cast(this->data()), this->size()*sizeof(T)); } @@ -113,12 +108,12 @@ bool pFlow::Vector::writeVector auto len = size(); auto stride = getVectorStride(len); os << token::BEGIN_LIST; - label i = 0; + size_t i = 0; while( ioperator[](i++); - for(label j=0; joperator[](i++); } @@ -130,12 +125,12 @@ bool pFlow::Vector::writeVector os << token::END_LIST; os.check(FUNCTION_NAME); - } + }*/ return true; } -template +/*template bool pFlow::Vector::deleteElement_sorted ( const Vector