mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Addressing code review comments.
This commit is contained in:
parent
68020589c3
commit
58d8119f2a
@ -78,9 +78,10 @@ public:
|
||||
|
||||
std::vector<vtkm::Id> FindBlocks(const vtkm::Vec3f& p) const { return this->FindBlocks(p, -1); }
|
||||
|
||||
std::vector<vtkm::Id> FindBlocks(const vtkm::Vec3f& p, const std::vector<vtkm::Id>& oldIDs) const
|
||||
std::vector<vtkm::Id> FindBlocks(const vtkm::Vec3f& p,
|
||||
const std::vector<vtkm::Id>& ignoreBlocks) const
|
||||
{
|
||||
vtkm::Id ignoreID = (oldIDs.empty() ? -1 : oldIDs[0]);
|
||||
vtkm::Id ignoreID = (ignoreBlocks.empty() ? -1 : ignoreBlocks[0]);
|
||||
return FindBlocks(p, ignoreID);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace filter
|
||||
{
|
||||
|
||||
MemStream::MemStream(std::size_t sz0)
|
||||
: Data(NULL)
|
||||
: Data(nullptr)
|
||||
, Len(0)
|
||||
, MaxLen(0)
|
||||
, Pos(0)
|
||||
@ -25,7 +25,7 @@ MemStream::MemStream(std::size_t sz0)
|
||||
}
|
||||
|
||||
MemStream::MemStream(std::size_t sz, const unsigned char* buff)
|
||||
: Data(NULL)
|
||||
: Data(nullptr)
|
||||
, Len(sz)
|
||||
, MaxLen(sz)
|
||||
, Pos(0)
|
||||
@ -43,6 +43,19 @@ MemStream::MemStream(const MemStream& s)
|
||||
std::memcpy(this->Data, s.GetData(), this->Len);
|
||||
}
|
||||
|
||||
MemStream::MemStream(MemStream&& s)
|
||||
{
|
||||
this->Pos = 0;
|
||||
this->Len = s.GetLen();
|
||||
this->MaxLen = this->Len;
|
||||
this->Data = s.Data;
|
||||
|
||||
s.Pos = 0;
|
||||
s.Len = 0;
|
||||
s.MaxLen = 0;
|
||||
s.Data = nullptr;
|
||||
}
|
||||
|
||||
MemStream::~MemStream()
|
||||
{
|
||||
this->ClearMemStream();
|
||||
@ -53,7 +66,7 @@ void MemStream::ClearMemStream()
|
||||
if (this->Data)
|
||||
{
|
||||
delete[] this->Data;
|
||||
this->Data = NULL;
|
||||
this->Data = nullptr;
|
||||
}
|
||||
this->Pos = 0;
|
||||
this->Len = 0;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#define vtk_m_filter_MemStream_h
|
||||
|
||||
#include <vtkm/filter/vtkm_filter_export.h>
|
||||
#include <vtkmstd/is_trivially_copyable.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
@ -29,6 +30,7 @@ public:
|
||||
MemStream(std::size_t sz0 = 32);
|
||||
MemStream(std::size_t sz, const unsigned char* buff);
|
||||
MemStream(const MemStream& s);
|
||||
MemStream(MemStream&& s);
|
||||
~MemStream();
|
||||
|
||||
void Rewind() { this->Pos = 0; }
|
||||
@ -96,10 +98,9 @@ inline void MemStream::SetPos(std::size_t p)
|
||||
template <typename T>
|
||||
struct Serialization
|
||||
{
|
||||
#if (defined(__clang__) && !defined(__ppc64__)) || (defined(__GNUC__) && __GNUC__ >= 5)
|
||||
static_assert(std::is_trivially_copyable<T>::value,
|
||||
static_assert(vtkmstd::is_trivially_copyable<T>::value,
|
||||
"Default serialization works only for trivially copyable types");
|
||||
#endif
|
||||
|
||||
static void write(MemStream& memstream, const T& data)
|
||||
{
|
||||
memstream.WriteBinary((const unsigned char*)&data, sizeof(T));
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
#include <vtkm/cont/ErrorFilterExecution.h>
|
||||
#include <vtkm/filter/particleadvection/Messenger.h>
|
||||
|
||||
#ifdef VTKM_ENABLE_MPI
|
||||
@ -42,21 +43,19 @@ void Messenger::RegisterTag(int tag, int num_recvs, int size)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "Invalid message tag: " << tag << std::endl;
|
||||
throw msg.str();
|
||||
throw vtkm::cont::ErrorFilterExecution(msg.str());
|
||||
}
|
||||
this->MessageTagInfo[tag] = std::pair<int, int>(num_recvs, size);
|
||||
}
|
||||
|
||||
int Messenger::CalcMessageBufferSize(int msgSz)
|
||||
{
|
||||
MemStream buff;
|
||||
int rank = 0;
|
||||
|
||||
std::vector<int> m(static_cast<std::size_t>(msgSz));
|
||||
vtkm::filter::write(buff, rank);
|
||||
vtkm::filter::write(buff, m);
|
||||
|
||||
return static_cast<int>(buff.GetLen());
|
||||
return static_cast<int>(sizeof(int)) // rank
|
||||
// std::vector<int> msg;
|
||||
// msg.size()
|
||||
+ static_cast<int>(sizeof(std::size_t))
|
||||
// msgSz ints.
|
||||
+ msgSz * static_cast<int>(sizeof(int));
|
||||
}
|
||||
|
||||
void Messenger::InitializeBuffers()
|
||||
@ -175,7 +174,7 @@ void Messenger::PrepareForSend(int tag, MemStream* buff, std::vector<unsigned ch
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "Message tag not found: " << tag << std::endl;
|
||||
throw msg.str();
|
||||
throw vtkm::cont::ErrorFilterExecution(msg.str());
|
||||
}
|
||||
|
||||
int bytesLeft = buff->GetLen();
|
||||
@ -307,7 +306,7 @@ bool Messenger::RecvData(std::set<int>& tags,
|
||||
{
|
||||
delete[] status;
|
||||
delete[] indices;
|
||||
throw "receive buffer not found";
|
||||
throw vtkm::cont::ErrorFilterExecution("receive buffer not found");
|
||||
}
|
||||
|
||||
incomingBuffers[i] = it->second;
|
||||
|
@ -13,8 +13,10 @@
|
||||
|
||||
#include <vtkm/cont/Algorithm.h>
|
||||
#include <vtkm/cont/ArrayCopy.h>
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/ArrayHandleTransform.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/ErrorFilterExecution.h>
|
||||
#include <vtkm/cont/ParticleArrayCopy.h>
|
||||
#include <vtkm/filter/particleadvection/DataSetIntegrator.h>
|
||||
#include <vtkm/filter/particleadvection/ParticleMessenger.h>
|
||||
@ -166,7 +168,7 @@ public:
|
||||
|
||||
N += (myTerm + numTermMessages);
|
||||
if (N > totalNumSeeds)
|
||||
throw "Particle count error";
|
||||
throw vtkm::cont::ErrorFilterExecution("Particle count error");
|
||||
}
|
||||
|
||||
std::cout << "Done: " << this->Rank << " Terminated= " << this->Terminated.size() << std::endl;
|
||||
@ -326,7 +328,7 @@ public:
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> cellIndex;
|
||||
vtkm::Id connectivityLen =
|
||||
vtkm::cont::Algorithm::ScanExclusive(numPointsPerCellArray, cellIndex);
|
||||
vtkm::cont::ArrayHandleCounting<vtkm::Id> connCount(0, 1, connectivityLen);
|
||||
vtkm::cont::ArrayHandleIndex connCount(connectivityLen);
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
|
||||
vtkm::cont::ArrayCopy(connCount, connectivity);
|
||||
|
||||
|
@ -13,16 +13,9 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <vtkm/cont/Logging.h>
|
||||
#include <vtkm/filter/particleadvection/Logger.h>
|
||||
|
||||
#if 0
|
||||
#define DBG(msg) vtkm::filter::Logger::GetInstance("out")->GetStream() << msg
|
||||
#define WDBG(msg) vtkm::filter::Logger::GetInstance("wout")->GetStream() << msg
|
||||
#else
|
||||
#define DBG(msg)
|
||||
#define WDBG(msg)
|
||||
#endif
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
@ -47,21 +40,21 @@ ParticleMessenger::ParticleMessenger(vtkmdiy::mpi::communicator& comm,
|
||||
#endif
|
||||
}
|
||||
|
||||
int ParticleMessenger::CalcParticleBufferSize(int nParticles, int numBlockIds)
|
||||
int ParticleMessenger::CalcParticleBufferSize(int nParticles, int nBlockIds)
|
||||
{
|
||||
MemStream buff;
|
||||
int r = 0;
|
||||
|
||||
//Make a vector of particles where each particle has 'numBlockIds' in the blockId array.
|
||||
std::vector<vtkm::Massless> v(static_cast<std::size_t>(nParticles));
|
||||
std::vector<vtkm::Id> blockIDs(static_cast<std::size_t>(numBlockIds), 0);
|
||||
|
||||
vtkm::filter::write(buff, r);
|
||||
vtkm::filter::write(buff, v);
|
||||
for (int i = 0; i < nParticles; i++)
|
||||
vtkm::filter::write(buff, blockIDs);
|
||||
|
||||
return static_cast<int>(buff.GetLen());
|
||||
return
|
||||
// rank
|
||||
static_cast<int>(sizeof(int))
|
||||
//std::vector<vtkm::Massless> p;
|
||||
//p.size()
|
||||
+ static_cast<int>(sizeof(std::size_t))
|
||||
//nParticles of vtkm::Massless
|
||||
+ nParticles * static_cast<int>(sizeof(vtkm::Massless))
|
||||
// std::vector<vtkm::Id> blockIDs for each particle.
|
||||
// blockIDs.size() for each particle
|
||||
+ nParticles * static_cast<int>(sizeof(std::size_t))
|
||||
// nBlockIDs of vtkm::Id for each particle.
|
||||
+ nParticles * nBlockIds * static_cast<int>(sizeof(vtkm::Id));
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
@ -111,7 +104,6 @@ void ParticleMessenger::Exchange(const std::vector<vtkm::Massless>& outData,
|
||||
std::vector<MsgCommType> msgData;
|
||||
if (RecvAny(&msgData, &particleData, false))
|
||||
{
|
||||
DBG("-----Recv: M: " << msgData.size() << " P: " << particleData.size() << std::endl);
|
||||
for (auto& it : particleData)
|
||||
for (const auto& v : it.second)
|
||||
{
|
||||
@ -124,10 +116,7 @@ void ParticleMessenger::Exchange(const std::vector<vtkm::Massless>& outData,
|
||||
for (auto& m : msgData)
|
||||
{
|
||||
if (m.second[0] == MSG_TERMINATE)
|
||||
{
|
||||
numTerminateMessages += static_cast<vtkm::Id>(m.second[1]);
|
||||
DBG("-----TERMinate: Recv: " << m.second[1] << std::endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +124,6 @@ void ParticleMessenger::Exchange(const std::vector<vtkm::Massless>& outData,
|
||||
if (numLocalTerm > 0)
|
||||
{
|
||||
std::vector<int> msg = { MSG_TERMINATE, static_cast<int>(numLocalTerm) };
|
||||
DBG("-----SendAllMsg: msg=" << msg << std::endl);
|
||||
SendAllMsg(msg);
|
||||
}
|
||||
|
||||
@ -245,7 +233,7 @@ void ParticleMessenger::SendParticles(int dst, const Container<P, Allocator>& c)
|
||||
{
|
||||
if (dst == this->Rank)
|
||||
{
|
||||
std::cerr << "Error. Sending IC to yourself" << std::endl;
|
||||
VTKM_LOG_S(vtkm::cont::LogLevel::Error, "Error. Sending a particle to yourself.");
|
||||
return;
|
||||
}
|
||||
if (c.empty())
|
||||
|
Loading…
Reference in New Issue
Block a user