LCOV - code coverage report
Current view: top level - core - ActionWithMatrix.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 5 5 100.0 %
Date: 2025-12-04 11:19:34 Functions: 0 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_ActionWithMatrix_h
      23             : #define __PLUMED_core_ActionWithMatrix_h
      24             : 
      25             : #include "ActionWithVector.h"
      26             : #include <cstddef>
      27             : 
      28             : namespace PLMD {
      29             : 
      30             : //this class serves as a workaround for moving data with openacc without specifying --memory=managed
      31         200 : class RequiredMatrixElements {
      32             :   std::vector<std::size_t> bookeeping{};
      33             :   std::size_t* bookeeping_data=nullptr;
      34             : public:
      35             :   std::size_t ncols=0;
      36             :   void update() {
      37        2006 :     bookeeping_data = bookeeping.data();
      38             :   }
      39             :   void toACCDevice() const {
      40             :     //this assumes that update() has already been called
      41             : #pragma acc enter data copyin(this[0:1], bookeeping_data[0:bookeeping.size()])
      42             :   }
      43             :   void removeFromACCDevice() const {
      44             : #pragma acc exit data delete(bookeeping_data[0:bookeeping.size()],this[0:1])
      45             :   }
      46             :   std::size_t& operator[]( std::size_t i ) {
      47    35013887 :     return bookeeping_data[i];
      48             :   }
      49             :   std::size_t operator[]( std::size_t i ) const {
      50    25239047 :     return bookeeping_data[i];
      51             :   }
      52             :   std::size_t size() const {
      53             :     return bookeeping.size();
      54             :   }
      55             :   void resize(std::size_t newSize) {
      56        1003 :     bookeeping.resize(newSize);
      57             :     update();
      58             :   }
      59             : };
      60             : 
      61             : class MatrixElementOutput {
      62             : public:
      63             :   View<double> values;
      64             :   View2D<double> derivs;
      65             :   MatrixElementOutput( std::size_t nv, std::size_t nd, double* v, double* d ) :
      66             :     values( v, nv ),
      67             :     derivs( d, nv, nd ) {
      68             :   }
      69             : };
      70             : 
      71             : class ActionWithMatrix : public ActionWithVector {
      72             : protected:
      73             : /// Some actions have a flag that sets this to true.  The elements on the diagonal of the resulting matrix are then set to zero
      74             :   bool diagzero;
      75             : /// Update all the arrays for doing bookeeping
      76             :   void updateBookeepingArrays( RequiredMatrixElements& mat );
      77             : public:
      78             :   static void registerKeywords( Keywords& keys );
      79             :   explicit ActionWithMatrix(const ActionOptions&);
      80             : /// Get the elements of the matrices into the output values
      81             :   void transferStashToValues( const std::vector<unsigned>& partialTaskList, const std::vector<double>& stash ) override ;
      82             : /// Get the forces from the output values and transfer them to the stash
      83             :   void transferForcesToStash( const std::vector<unsigned>& partialTaskList, std::vector<double>& stash ) const override ;
      84             : };
      85             : 
      86             : }
      87             : #endif

Generated by: LCOV version 1.16