bug fix binrayIO and sorting for cuda build
This commit is contained in:
parent
b6360643ee
commit
e729fe6363
|
@ -82,25 +82,16 @@ bool pFlow::Field<VectorField, T, PropType>::readNonUniform
|
|||
return false;
|
||||
}
|
||||
|
||||
this->clear();
|
||||
if(is.isBinary() && !std::is_same_v<T,word>)
|
||||
VectorType::readVector(is, flen);
|
||||
is.readEndStatement("readField");
|
||||
if( this->size() != flen )
|
||||
{
|
||||
this->resize(flen);
|
||||
is.read(reinterpret_cast<char*>(this->data()), this->size()*sizeof(T));
|
||||
is.readEndStatement("readField");
|
||||
ioErrorInFile( is.name(), is.lineNumber() ) <<
|
||||
" expected " << flen << " elements, but supplied "<<
|
||||
this->size() << " elements in file "<< is.name() <<endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
VectorType::read(is);
|
||||
is.readEndStatement("readField");
|
||||
if( this->size() != flen )
|
||||
{
|
||||
ioErrorInFile( is.name(), is.lineNumber() ) <<
|
||||
" expected " << flen << " elements, but supplied "<<
|
||||
this->size() << " elements in file "<< is.name() <<endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -178,17 +169,14 @@ bool pFlow::Field<VectorField, T, PropType>::readField
|
|||
template<template<class, class> class VectorField, class T, class PropType>
|
||||
bool pFlow::Field<VectorField, T, PropType>::writeField(iOstream& os)const
|
||||
{
|
||||
|
||||
os.writeWordKeyword(fieldKey_) << nonUniform__<<endl;
|
||||
os<< this->size()<<endl;
|
||||
if( os.isBinary() && !std::is_same_v<T,word>)
|
||||
{
|
||||
os.write(reinterpret_cast<const char*>(this->data()), this->size()*sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
VectorType::write(os);
|
||||
}
|
||||
|
||||
VectorType::write(os);
|
||||
|
||||
os.endEntry();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,59 +28,70 @@ pFlow::Vector<T, Allocator>::Vector(iIstream& is)
|
|||
template<typename T, typename Allocator>
|
||||
bool pFlow::Vector<T, Allocator>::readVector
|
||||
(
|
||||
iIstream& is
|
||||
iIstream& is,
|
||||
size_t len
|
||||
)
|
||||
{
|
||||
this->clear();
|
||||
|
||||
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
T val{};
|
||||
if( firstToken.isPunctuation() ) // start of vector
|
||||
if(is.isBinary() && !std::is_same_v<T,word>)
|
||||
{
|
||||
if(firstToken != token::BEGIN_LIST)
|
||||
this->resize(len);
|
||||
is.read(reinterpret_cast<char*>(this->data()), this->size()*sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->clear();
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
token firstToken(is);
|
||||
|
||||
T val{};
|
||||
if( firstToken.isPunctuation() ) // start of vector
|
||||
{
|
||||
if(firstToken != token::BEGIN_LIST)
|
||||
{
|
||||
warningInFunction
|
||||
<< "expected token "<< token::BEGIN_LIST
|
||||
<< " but found "<< firstToken ;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
token lastToken(is);
|
||||
|
||||
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
while
|
||||
( !(
|
||||
lastToken.isPunctuation()
|
||||
&& lastToken == token::END_LIST
|
||||
|
||||
)
|
||||
)
|
||||
{
|
||||
|
||||
is.putBack(lastToken);
|
||||
|
||||
is >> val;
|
||||
this->push_back(val);
|
||||
|
||||
is >> lastToken;
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
warningInFunction
|
||||
<< "expected token "<< token::BEGIN_LIST
|
||||
<< " but found "<< firstToken ;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
token lastToken(is);
|
||||
|
||||
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
|
||||
while
|
||||
( !(
|
||||
lastToken.isPunctuation()
|
||||
&& lastToken == token::END_LIST
|
||||
|
||||
)
|
||||
)
|
||||
{
|
||||
|
||||
is.putBack(lastToken);
|
||||
|
||||
is >> val;
|
||||
this->push_back(val);
|
||||
|
||||
is >> lastToken;
|
||||
is.fatalCheck(FUNCTION_NAME);
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
warningInFunction
|
||||
<< "expected token "<< token::BEGIN_LIST
|
||||
<< " but found "<< firstToken ;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -91,30 +102,35 @@ bool pFlow::Vector<T, Allocator>::writeVector
|
|||
iOstream& os
|
||||
) const
|
||||
{
|
||||
|
||||
|
||||
auto len = size();
|
||||
auto stride = getVectorStride(len);
|
||||
|
||||
// start of
|
||||
os << token::BEGIN_LIST;
|
||||
label i = 0;
|
||||
while( i<len )
|
||||
if( os.isBinary() && !std::is_same_v<T,word>)
|
||||
{
|
||||
os.write(reinterpret_cast<const char*>(this->data()), this->size()*sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
os << this->operator[](i++);
|
||||
for(label j=0; j<stride-1 && i<len; j++ )
|
||||
auto len = size();
|
||||
auto stride = getVectorStride(len);
|
||||
os << token::BEGIN_LIST;
|
||||
label i = 0;
|
||||
while( i<len )
|
||||
{
|
||||
os << token::SPACE << this->operator[](i++);
|
||||
|
||||
os << this->operator[](i++);
|
||||
for(label j=0; j<stride-1 && i<len; j++ )
|
||||
{
|
||||
os << token::SPACE << this->operator[](i++);
|
||||
}
|
||||
|
||||
if(i<len)
|
||||
os<< token::NL;
|
||||
}
|
||||
|
||||
os << token::END_LIST;
|
||||
|
||||
if(i<len)
|
||||
os<< token::NL;
|
||||
os.check(FUNCTION_NAME);
|
||||
}
|
||||
|
||||
os << token::END_LIST;
|
||||
|
||||
os.check(FUNCTION_NAME);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -291,6 +291,8 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const word& name()const
|
||||
{
|
||||
return name_;
|
||||
|
@ -372,9 +374,7 @@ public:
|
|||
// from iIstream and free size
|
||||
Vector(iIstream& is);
|
||||
|
||||
//bool readVector(iIstream & is, size_t len);
|
||||
|
||||
bool readVector(iIstream& is);
|
||||
bool readVector(iIstream& is, size_t len=0);
|
||||
|
||||
bool writeVector(iOstream& os) const;
|
||||
|
||||
|
|
|
@ -567,6 +567,7 @@ public:
|
|||
sortedView[i] = dVec[d_indices[i]];
|
||||
}
|
||||
);
|
||||
|
||||
Kokkos::fence();
|
||||
setSize(newSize);
|
||||
copy(deviceVector(), sortedView);
|
||||
|
@ -931,16 +932,24 @@ public:
|
|||
|
||||
//// - IO operations
|
||||
FUNCTION_H
|
||||
bool read(iIstream& is)
|
||||
bool readVector(
|
||||
iIstream& is,
|
||||
size_t len=0)
|
||||
{
|
||||
Vector<T> vecFromFile;
|
||||
if( !vecFromFile.read(is) ) return false;
|
||||
if( !vecFromFile.readVector(is,len) ) return false;
|
||||
|
||||
this->assign(vecFromFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FUNCTION_H
|
||||
bool read(iIstream& is)
|
||||
{
|
||||
return readVector(is);
|
||||
}
|
||||
|
||||
FUNCTION_H
|
||||
bool write(iOstream& os) const
|
||||
{
|
||||
|
|
|
@ -570,30 +570,25 @@ public:
|
|||
size_t newSize = indices.size();
|
||||
viewType sortedView("sortedView", newSize);
|
||||
|
||||
if constexpr (isHostAccessible_)
|
||||
{
|
||||
auto h_indices = indices.hostView();
|
||||
Kokkos::parallel_for(
|
||||
using policy = Kokkos::RangePolicy<
|
||||
execution_space,
|
||||
Kokkos::IndexType<int32> >;
|
||||
|
||||
auto d_indices = indices.deviceView();
|
||||
auto d_view = view_;
|
||||
Kokkos::parallel_for(
|
||||
"sortItems",
|
||||
newSize,
|
||||
LAMBDA_HD(int32 i){
|
||||
sortedView[i] = view_[h_indices[i]];
|
||||
sortedView(i) = d_view(d_indices(i));
|
||||
});
|
||||
}else
|
||||
{
|
||||
auto d_indices = indices.deviceView();
|
||||
Kokkos::parallel_for(
|
||||
"sortItems",
|
||||
newSize,
|
||||
LAMBDA_HD(int32 i){
|
||||
sortedView[i] = view_[d_indices[i]];
|
||||
});
|
||||
}
|
||||
|
||||
Kokkos::fence();
|
||||
|
||||
setSize(newSize);
|
||||
|
||||
copy(deviceVector(), sortedView);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
@ -835,16 +830,24 @@ public:
|
|||
//// - IO operations
|
||||
|
||||
FUNCTION_H
|
||||
bool read(iIstream& is)
|
||||
bool readVector(
|
||||
iIstream& is,
|
||||
size_t len=0)
|
||||
{
|
||||
Vector<T> vecFromFile;
|
||||
if( !vecFromFile.read(is) ) return false;
|
||||
if( !vecFromFile.readVector(is,len) ) return false;
|
||||
|
||||
this->assign(vecFromFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FUNCTION_H
|
||||
bool read(iIstream& is)
|
||||
{
|
||||
return readVector(is);
|
||||
}
|
||||
|
||||
FUNCTION_H
|
||||
bool write(iOstream& os)const
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ Licence:
|
|||
#include "mortonIndexing.hpp"
|
||||
#include "cells.hpp"
|
||||
|
||||
#include "streams.hpp"
|
||||
|
||||
bool pFlow::getSortedIndex(
|
||||
box boundingBox,
|
||||
|
@ -37,6 +38,8 @@ bool pFlow::getSortedIndex(
|
|||
|
||||
ViewType1D<uint64_t> mortonCode("mortonCode", activeRange.second);
|
||||
|
||||
output<<"before first kernel"<<endl;;
|
||||
|
||||
using rpMorton =
|
||||
Kokkos::RangePolicy<Kokkos::IndexType<int32>>;
|
||||
int32 numActive = 0;
|
||||
|
@ -52,13 +55,17 @@ bool pFlow::getSortedIndex(
|
|||
sumToUpdate++;
|
||||
}else
|
||||
{
|
||||
mortonCode[i] = xyzToMortonCode64(-1,-1,-1);
|
||||
mortonCode[i] = xyzToMortonCode64
|
||||
(
|
||||
static_cast<uint64_t>(-1),
|
||||
static_cast<uint64_t>(-1),
|
||||
static_cast<uint64_t>(-1)
|
||||
);
|
||||
}
|
||||
},
|
||||
numActive
|
||||
);
|
||||
|
||||
|
||||
permuteSort(
|
||||
mortonCode,
|
||||
activeRange.first,
|
||||
|
|
Loading…
Reference in New Issue