From 051145589c3e641dc79d15009881f262ef646243 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi Date: Wed, 13 Mar 2024 15:25:14 +0100 Subject: [PATCH] Same trick on wholemolecules speedup 3%, but code is a mess --- src/core/ActionAtomistic.h | 10 +++++ src/generic/WholeMolecules.cpp | 79 +++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/core/ActionAtomistic.h b/src/core/ActionAtomistic.h index 606af7b75b..a7ae4c729f 100644 --- a/src/core/ActionAtomistic.h +++ b/src/core/ActionAtomistic.h @@ -103,6 +103,7 @@ class ActionAtomistic : /// \warning Should be only used by actions that need to modify the shared position array. /// This array is insensitive to local changes such as makeWhole(), numerical derivatives, etc. void setGlobalPosition(const std::pair&, const Vector& pos); + std::array getValueData(std::size_t nn); /// Get total number of atoms, including virtual ones. /// Can be used to make a loop on modifyGlobalPosition or getGlobalPosition. unsigned getTotAtoms()const; @@ -277,6 +278,15 @@ void ActionAtomistic::setGlobalPosition(const std::pairdata[a.second]=pos[2]; } +inline +std::array ActionAtomistic::getValueData(std::size_t nn) { + std::array ptr; + ptr[0]=xpos[nn]->data.data(); + ptr[1]=ypos[nn]->data.data(); + ptr[2]=zpos[nn]->data.data(); + return ptr; +} + inline Vector ActionAtomistic::getForce( const std::pair& a ) const { Vector f; diff --git a/src/generic/WholeMolecules.cpp b/src/generic/WholeMolecules.cpp index b38fc31949..3256704f87 100644 --- a/src/generic/WholeMolecules.cpp +++ b/src/generic/WholeMolecules.cpp @@ -103,8 +103,8 @@ class WholeMolecules: public ActionPilot, public ActionAtomistic { - std::vector > > p_groups; - std::vector > > p_roots; + std::vector>>> p_groups; + std::vector>>> p_roots; std::vector refs; bool doemst, addref; public: @@ -221,17 +221,35 @@ WholeMolecules::WholeMolecules(const ActionOptions&ao): // Convert groups to p_groups p_groups.resize( groups.size() ); for(unsigned i=0; i>(nn,{})); + p_groups.back().back().second.push_back(kk); + first=false; + prev_nn=nn; + } } + // Convert roots to p_roots p_roots.resize( roots.size() ); for(unsigned i=0; i>(nn,{})); + p_roots.back().back().second.push_back(kk); + first=false; + prev_nn=nn; + } } - checkRead(); Tools::removeDuplicates(merge); requestAtoms(merge); @@ -241,25 +259,38 @@ WholeMolecules::WholeMolecules(const ActionOptions&ao): void WholeMolecules::calculate() { for(unsigned i=0; i