LCOV - code coverage report
Current view: top level - core - ActionWithVector.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 10 12 83.3 %
Date: 2026-11-05 10:19:04 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-2023 The plumed team
       3             :    (see the PEOPLE file at the root of the distribution for a list of names)
       4             : 
       5             :    See http://www.plumed.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       8             : 
       9             :    plumed is free software: you can redistribute it and/or modify
      10             :    it under the terms of the GNU Lesser General Public License as published by
      11             :    the Free Software Foundation, either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    plumed is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU Lesser General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : #ifndef __PLUMED_core_ActionWithVector_h
      23             : #define __PLUMED_core_ActionWithVector_h
      24             : 
      25             : #include "ActionWithValue.h"
      26             : #include "ActionAtomistic.h"
      27             : #include "ActionWithArguments.h"
      28             : #include <limits>
      29             : #include <vector>
      30             : 
      31             : namespace PLMD {
      32             : 
      33             : struct ArgumentsBookkeeping {
      34             :   std::size_t nargs{0};
      35             :   std::vector<std::size_t> ranks;
      36             :   std::vector<std::size_t> shapestarts;
      37             :   std::vector<std::size_t> shapedata;
      38             :   std::vector<std::size_t> ncols;
      39             :   std::vector<std::size_t> bookstarts;
      40             :   std::vector<std::size_t> booksizes;
      41             :   std::vector<std::size_t> bookeeping;
      42             :   std::vector<std::size_t> argstarts;
      43             : };
      44             : 
      45             : class ActionWithVector:
      46             :   public ActionAtomistic,
      47             :   public ActionWithValue,
      48             :   public ActionWithArguments {
      49             :   friend class Value;
      50             : private:
      51             :   static constexpr int NoMasksUsed =-1;
      52             : /// Check if there is a mask value
      53             :   int nmask=NoMasksUsed;
      54             : /// The list of active tasks
      55             :   std::vector<unsigned> active_tasks;
      56             : protected:
      57             : /// Turn off the flag that says this action has a masked input
      58             :   void ignoreMaskArguments();
      59             : /// Accumulate the forces from the Values
      60             :   bool checkForForces();
      61             : /// Copy all the data to the bookeeping array
      62             :   void copyArgumentBookeeping( ArgumentsBookkeeping& argumentsMap ) const ;
      63             : /// Implementation of transferStashToValues for both precisions
      64             :   template <typename T>
      65             :   void stashToValuesImpl( const std::vector<unsigned>& partialTaskList, const std::vector<T>& stash );
      66             : /// Implementation of transferForcesToStash for both precisions
      67             :   template <typename T>
      68             :   void forcesToStashImpl( const std::vector<unsigned>& partialTaskList, std::vector<T>& stash ) const ;
      69             : public:
      70             :   static void registerKeywords( Keywords& keys );
      71             :   explicit ActionWithVector(const ActionOptions&);
      72        3953 :   virtual ~ActionWithVector() {}
      73             :   void lockRequests() override;
      74             :   void unlockRequests() override;
      75             :   virtual void prepare() override;
      76             : /// Check if a mask has been set
      77             :   int getNumberOfMasks() const ;
      78             :   void calculateNumericalDerivatives(ActionWithValue* av) override;
      79             : /// Get the list of tasks that are active
      80             :   virtual std::vector<unsigned>& getListOfActiveTasks();
      81             :   const std::vector<unsigned>& getConstListOfActiveTasks() const ;
      82             : /// Find out how many tasks we need to perform in this loop
      83             :   virtual void getNumberOfTasks( unsigned& ntasks );
      84             : /// Determine if a particular task is active based on the values of the input argument
      85             :   virtual int checkTaskIsActive( const unsigned& itask ) const ;
      86             : /// This is so we can parallelize with GPU
      87             :   virtual void getInputData( std::vector<double>& inputdata, ArgumentsBookkeeping& argumentsMap ) const ;
      88             :   virtual void getInputData( std::vector<float>& inputdata, ArgumentsBookkeeping& argumentsMap ) const ;
      89             : /// Get the atomic input data
      90             :   virtual void getAtomicInputData( std::vector<double>& inputdata ) const ;
      91             :   virtual void getAtomicInputData( std::vector<float>& inputdata ) const ;
      92             : /// Get the argument input data
      93             :   virtual void getArgumentInputData( std::vector<double>& inputdata ) const ;
      94             :   virtual void getArgumentInputData( std::vector<float>& inputdata ) const ;
      95             : /// Get the size of the value in the stash
      96             :   virtual unsigned getSizeOfValueInStash( const Value* myval );
      97             : /// This is so we an transfer data gathered in the parallel task manager to the underlying values
      98             :   virtual void transferStashToValues( const std::vector<unsigned>& partialTaskList, const std::vector<double>& stash );
      99             : /// This is so we an transfer data gathered in the parallel task manager to the underlying values
     100             :   virtual void transferStashToValues( const std::vector<unsigned>& partialTaskList, const std::vector<float>& stash );
     101             : /// This is so we can transfer forces from the values to the parallel task manager
     102             :   virtual void transferForcesToStash( const std::vector<unsigned>& partialTaskList, std::vector<double>& stash ) const ;
     103             : /// This is so we can transfer forces from the values to the parallel task manager
     104             :   virtual void transferForcesToStash( const std::vector<unsigned>& partialTaskList, std::vector<float>& stash ) const ;
     105             : /// Get the number of forces to use
     106             :   unsigned getNumberOfForceDerivatives() const ;
     107             : /// Apply the forces on this data
     108             :   void apply() override;
     109             : /// Apply the forces on non-zero rank objects
     110           0 :   virtual void applyNonZeroRankForces( std::vector<double>& outforces ) {
     111           0 :     plumed_error();
     112             :   }
     113             : };
     114             : 
     115             : inline
     116             : int ActionWithVector::getNumberOfMasks() const {
     117     1088725 :   return nmask;
     118             : }
     119             : 
     120             : inline
     121         395 : void ActionWithVector::ignoreMaskArguments() {
     122         395 :   plumed_assert( nmask<=0 );
     123         395 :   nmask=NoMasksUsed;
     124         395 : }
     125             : 
     126             : inline
     127             : const std::vector<unsigned>& ActionWithVector::getConstListOfActiveTasks() const {
     128             :   return active_tasks;
     129             : }
     130             : 
     131             : inline
     132      233969 : unsigned ActionWithVector::getSizeOfValueInStash( const Value* myval ) {
     133      233969 :   if( myval->hasDerivatives() ) {
     134       10109 :     return myval->getNumberOfStoredValues()*(1+getNumberOfDerivatives());
     135             :   }
     136      223860 :   return myval->getNumberOfStoredValues();
     137             : }
     138             : 
     139             : }
     140             : 
     141             : #endif

Generated by: LCOV version 1.16