From c95e416e4a994bf804e973a0cf638b7f0315b6eb Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Fri, 18 Oct 2019 12:23:44 +0200 Subject: [PATCH] [BUGFIX] illegal pointer access --- apps/benchmarks/GranularGas/GenerateModule.py | 2 +- python/mesa_pd.py | 2 +- src/mesa_pd/data/ParticleAccessor.h | 14 +++++++------- src/mesa_pd/data/ParticleStorage.h | 14 +++++++------- src/mesa_pd/kernel/AssocToBlock.h | 5 ++++- src/mesa_pd/mpi/SyncNextNeighborsBlockForest.cpp | 10 ++-------- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/apps/benchmarks/GranularGas/GenerateModule.py b/apps/benchmarks/GranularGas/GenerateModule.py index a6b7696b1..573be3b42 100755 --- a/apps/benchmarks/GranularGas/GenerateModule.py +++ b/apps/benchmarks/GranularGas/GenerateModule.py @@ -50,7 +50,7 @@ if __name__ == '__main__': ps.addProperty("nextParticle", "int", defValue="-1", syncMode="NEVER") ps.addInclude("blockforest/BlockForest.h") - ps.addProperty("currentBlock", "blockforest::Block*", defValue="nullptr", syncMode="NEVER") + ps.addProperty("currentBlock", "blockforest::BlockID", defValue="", syncMode="NEVER") kernels = [] kernels.append( kernel.DoubleCast(shapes) ) diff --git a/python/mesa_pd.py b/python/mesa_pd.py index 0ba17be6b..57a8f1382 100755 --- a/python/mesa_pd.py +++ b/python/mesa_pd.py @@ -49,7 +49,7 @@ if __name__ == '__main__': ps.addProperty("oldTorque", "walberla::mesa_pd::Vec3", defValue="real_t(0)", syncMode="MIGRATION") ps.addInclude("blockforest/BlockForest.h") - ps.addProperty("currentBlock", "blockforest::Block*", defValue="nullptr", syncMode="NEVER") + ps.addProperty("currentBlock", "blockforest::BlockID", defValue="", syncMode="NEVER") ps.addProperty("type", "uint_t", defValue="0", syncMode="COPY") diff --git a/src/mesa_pd/data/ParticleAccessor.h b/src/mesa_pd/data/ParticleAccessor.h index e1a9b17c7..f71f39af2 100644 --- a/src/mesa_pd/data/ParticleAccessor.h +++ b/src/mesa_pd/data/ParticleAccessor.h @@ -108,9 +108,9 @@ public: walberla::mesa_pd::Vec3& getOldTorqueRef(const size_t p_idx) {return ps_->getOldTorqueRef(p_idx);} void setOldTorque(const size_t p_idx, walberla::mesa_pd::Vec3 const & v) { ps_->setOldTorque(p_idx, v);} - blockforest::Block* const & getCurrentBlock(const size_t p_idx) const {return ps_->getCurrentBlock(p_idx);} - blockforest::Block*& getCurrentBlockRef(const size_t p_idx) {return ps_->getCurrentBlockRef(p_idx);} - void setCurrentBlock(const size_t p_idx, blockforest::Block* const & v) { ps_->setCurrentBlock(p_idx, v);} + blockforest::BlockID const & getCurrentBlock(const size_t p_idx) const {return ps_->getCurrentBlock(p_idx);} + blockforest::BlockID& getCurrentBlockRef(const size_t p_idx) {return ps_->getCurrentBlockRef(p_idx);} + void setCurrentBlock(const size_t p_idx, blockforest::BlockID const & v) { ps_->setCurrentBlock(p_idx, v);} uint_t const & getType(const size_t p_idx) const {return ps_->getType(p_idx);} uint_t& getTypeRef(const size_t p_idx) {return ps_->getTypeRef(p_idx);} @@ -253,9 +253,9 @@ public: void setOldTorque(const size_t /*p_idx*/, walberla::mesa_pd::Vec3 const & v) { oldTorque_ = v;} walberla::mesa_pd::Vec3& getOldTorqueRef(const size_t /*p_idx*/) {return oldTorque_;} - blockforest::Block* const & getCurrentBlock(const size_t /*p_idx*/) const {return currentBlock_;} - void setCurrentBlock(const size_t /*p_idx*/, blockforest::Block* const & v) { currentBlock_ = v;} - blockforest::Block*& getCurrentBlockRef(const size_t /*p_idx*/) {return currentBlock_;} + blockforest::BlockID const & getCurrentBlock(const size_t /*p_idx*/) const {return currentBlock_;} + void setCurrentBlock(const size_t /*p_idx*/, blockforest::BlockID const & v) { currentBlock_ = v;} + blockforest::BlockID& getCurrentBlockRef(const size_t /*p_idx*/) {return currentBlock_;} uint_t const & getType(const size_t /*p_idx*/) const {return type_;} void setType(const size_t /*p_idx*/, uint_t const & v) { type_ = v;} @@ -319,7 +319,7 @@ private: walberla::mesa_pd::Vec3 force_; walberla::mesa_pd::Vec3 oldForce_; walberla::mesa_pd::Vec3 oldTorque_; - blockforest::Block* currentBlock_; + blockforest::BlockID currentBlock_; uint_t type_; int nextParticle_; std::map<walberla::id_t, walberla::mesa_pd::data::ContactHistory> oldContactHistory_; diff --git a/src/mesa_pd/data/ParticleStorage.h b/src/mesa_pd/data/ParticleStorage.h index 0837b3432..7ff16c341 100644 --- a/src/mesa_pd/data/ParticleStorage.h +++ b/src/mesa_pd/data/ParticleStorage.h @@ -86,7 +86,7 @@ public: using force_type = walberla::mesa_pd::Vec3; using oldForce_type = walberla::mesa_pd::Vec3; using oldTorque_type = walberla::mesa_pd::Vec3; - using currentBlock_type = blockforest::Block*; + using currentBlock_type = blockforest::BlockID; using type_type = uint_t; using nextParticle_type = int; using oldContactHistory_type = std::map<walberla::id_t, walberla::mesa_pd::data::ContactHistory>; @@ -273,7 +273,7 @@ public: using force_type = walberla::mesa_pd::Vec3; using oldForce_type = walberla::mesa_pd::Vec3; using oldTorque_type = walberla::mesa_pd::Vec3; - using currentBlock_type = blockforest::Block*; + using currentBlock_type = blockforest::BlockID; using type_type = uint_t; using nextParticle_type = int; using oldContactHistory_type = std::map<walberla::id_t, walberla::mesa_pd::data::ContactHistory>; @@ -722,7 +722,7 @@ inline ParticleStorage::iterator ParticleStorage::create(const id_t& uid) force_.emplace_back(real_t(0)); oldForce_.emplace_back(real_t(0)); oldTorque_.emplace_back(real_t(0)); - currentBlock_.emplace_back(nullptr); + currentBlock_.emplace_back(); type_.emplace_back(0); nextParticle_.emplace_back(-1); oldContactHistory_.emplace_back(); @@ -1214,10 +1214,10 @@ public: class SelectParticleCurrentBlock { public: - using return_type = blockforest::Block*; - blockforest::Block*& operator()(data::Particle& p) const {return p.getCurrentBlockRef();} - blockforest::Block*& operator()(data::Particle&& p) const {return p.getCurrentBlockRef();} - blockforest::Block* const & operator()(const data::Particle& p) const {return p.getCurrentBlock();} + using return_type = blockforest::BlockID; + blockforest::BlockID& operator()(data::Particle& p) const {return p.getCurrentBlockRef();} + blockforest::BlockID& operator()(data::Particle&& p) const {return p.getCurrentBlockRef();} + blockforest::BlockID const & operator()(const data::Particle& p) const {return p.getCurrentBlock();} }; ///Predicate that selects a certain property from a Particle class SelectParticleType diff --git a/src/mesa_pd/kernel/AssocToBlock.h b/src/mesa_pd/kernel/AssocToBlock.h index 9936d57c6..f25008abc 100644 --- a/src/mesa_pd/kernel/AssocToBlock.h +++ b/src/mesa_pd/kernel/AssocToBlock.h @@ -54,7 +54,7 @@ template <typename Accessor> inline void AssocToBlock::operator()(const size_t idx, Accessor& ac) const { - blockforest::Block*& currentBlock = ac.getCurrentBlockRef(idx); + blockforest::Block* currentBlock = bf_->getBlock(ac.getCurrentBlock(idx)); if (currentBlock != nullptr) { @@ -71,6 +71,7 @@ inline void AssocToBlock::operator()(const size_t idx, { if (blk.second->getAABB().contains(ac.getPosition(idx))) { + ac.setCurrentBlock(idx, blk.second->getId()); currentBlock = blk.second.get(); return; } @@ -85,6 +86,8 @@ inline void AssocToBlock::operator()(const size_t idx, { WALBERLA_LOG_DEVEL(blk.second->getAABB()); } + using namespace walberla::mesa_pd::data::particle_flags; + WALBERLA_LOG_DEVEL_VAR(isSet(ac.getFlags(idx), GHOST)); } WALBERLA_CHECK_NOT_NULLPTR(currentBlock, ac.getPosition(idx)); } diff --git a/src/mesa_pd/mpi/SyncNextNeighborsBlockForest.cpp b/src/mesa_pd/mpi/SyncNextNeighborsBlockForest.cpp index 08bfc37ef..c24bf8b75 100644 --- a/src/mesa_pd/mpi/SyncNextNeighborsBlockForest.cpp +++ b/src/mesa_pd/mpi/SyncNextNeighborsBlockForest.cpp @@ -18,12 +18,6 @@ // //====================================================================================================================== -//====================================================================================================================== -// -// THIS FILE IS GENERATED - PLEASE CHANGE THE TEMPLATE !!! -// -//====================================================================================================================== - #include "SyncNextNeighborsBlockForest.h" #include <mesa_pd/domain/BlockForestDomain.h> @@ -122,8 +116,8 @@ void SyncNextNeighborsBlockForest::generateSynchronizationMessages(data::Particl continue; } - auto& currentBlock = pIt->getCurrentBlockRef(); - WALBERLA_CHECK_NOT_NULLPTR(currentBlock); + auto currentBlock = bf->getBlock(pIt->getCurrentBlock()); + WALBERLA_CHECK_NOT_NULLPTR(currentBlock, *pIt); if (isInsideAABB(pIt->getPosition(), pIt->getInteractionRadius() + dx, currentBlock->getAABB())) { //no sync needed -- GitLab