From 6482d08918de7233ba4c27584b2159a2fd58a406 Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Wed, 5 Feb 2025 13:44:05 +0100 Subject: [PATCH] Added some helper pacakages that will be needed for next step --- src/colvar/MultiColvarTemplate.h | 25 +++++++++++++++++++++++++ src/core/ParallelTaskManager.h | 14 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/colvar/MultiColvarTemplate.h b/src/colvar/MultiColvarTemplate.h index f24a6ccf43..f58bfaa0bb 100644 --- a/src/colvar/MultiColvarTemplate.h +++ b/src/colvar/MultiColvarTemplate.h @@ -62,6 +62,7 @@ class MultiColvarTemplate : public ActionWithVector { unsigned getNumberOfAtomsPerTask() const override ; void addValueWithDerivatives( const std::vector& shape=std::vector() ) override ; void addComponentWithDerivatives( const std::string& name, const std::vector& shape=std::vector() ) override ; + void getInputData( std::vector& inputdata ) const override ; void performTask( const unsigned&, MultiValue& ) const override ; void calculate() override; static void performTask( const unsigned& m, const std::vector& der_indices, const bool noderiv, const bool haspbc, const Pbc& pbc, MultiValue& myvals ); @@ -124,6 +125,13 @@ MultiColvarTemplate::MultiColvarTemplate(const ActionOptions&ao): // Setup the values mode = T::getModeAndSetupValues( this ); + // This sets up an array in the parallel task manager to hold all the indices + std::vector ind( ablocks.size()*ablocks[0].size() ); + for(unsigned i=0; i @@ -154,6 +162,23 @@ unsigned MultiColvarTemplate::getNumberOfAtomsPerTask() const { return ablocks.size(); } +template +void MultiColvarTemplate::getInputData( std::vector& inputdata ) const { + unsigned ntasks = ablocks[0].size(); std::size_t k=0; + if( inputdata.size()!=5*ablocks.size()*ntasks ) inputdata.resize( 5*ablocks.size()*ntasks ); + for(unsigned i=0; i void MultiColvarTemplate::performTask( const unsigned& task_index, MultiValue& myvals ) const { // Retrieve the positions diff --git a/src/core/ParallelTaskManager.h b/src/core/ParallelTaskManager.h index 4b35581ec0..b0e5bbe209 100644 --- a/src/core/ParallelTaskManager.h +++ b/src/core/ParallelTaskManager.h @@ -42,8 +42,14 @@ class ParallelTaskManager { std::vector buffer; /// A tempory vector of MultiValue so we can avoid doing lots of resizes std::vector myvals; +/// This holds indices for creating derivatives + std::vector indices; +/// This holds all the input data that is required to calculate all values for all tasks + std::vector inputdata; public: ParallelTaskManager(ActionWithVector* av); +/// Setup an array to hold all the indices that are used for derivatives + void setupIndexList( const std::vector& ind ); /// This runs all the tasks void runAllTasks( const unsigned& natoms=0 ); /// This runs each of the tasks @@ -60,6 +66,11 @@ ParallelTaskManager::ParallelTaskManager(ActionWithVector* av): if(am) ismatrix=true; } +template +void ParallelTaskManager::setupIndexList( const std::vector& ind ) { + indices.resize( ind.size() ); for(unsigned i=0; i void ParallelTaskManager::runAllTasks( const unsigned& natoms ) { unsigned stride=comm.Get_size(); @@ -86,6 +97,9 @@ void ParallelTaskManager::runAllTasks( const unsigned& natoms ) { // Clear buffer buffer.assign( buffer.size(), 0.0 ); + // Get all the input data so we can broadcast it to the GPU + action->getInputData( inputdata ); + #pragma omp parallel num_threads(nt) { std::vector omp_buffer;