LCOV - code coverage report
Current view: top level - tools - OpenMP.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 15 19 78.9 %
Date: 2026-03-30 13:16:06 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-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             : 
      23             : #include "OpenMP.h"
      24             : #include "Tools.h"
      25             : #include <cstdlib>
      26             : #if defined(_OPENMP)
      27             : #include <omp.h>
      28             : #endif
      29             : 
      30             : namespace PLMD {
      31             : 
      32             : 
      33             : struct OpenMPVars {
      34             :   unsigned cacheline_size=512;
      35             :   bool cache_set=false;
      36             :   unsigned num_threads=1;
      37             :   bool nt_env_set=false;
      38             : };
      39             : 
      40     1918166 : static OpenMPVars & getOpenMPVars() {
      41             :   static OpenMPVars vars;
      42     1918166 :   return vars;
      43             : }
      44             : 
      45           0 : void OpenMP::setNumThreads(const unsigned nt) {
      46           0 :   getOpenMPVars().num_threads=nt;
      47           0 : }
      48             : 
      49       59955 : unsigned OpenMP::getCachelineSize() {
      50       59955 :   if(!getOpenMPVars().cache_set) {
      51         827 :     if(std::getenv("PLUMED_CACHELINE_SIZE")) {
      52           0 :       Tools::convert(std::getenv("PLUMED_CACHELINE_SIZE"),getOpenMPVars().cacheline_size);
      53             :     }
      54         827 :     getOpenMPVars().cache_set = true;
      55             :   }
      56       59955 :   return getOpenMPVars().cacheline_size;
      57             : }
      58             : 
      59     1858211 : unsigned OpenMP::getNumThreads() {
      60     1858211 :   if(!getOpenMPVars().nt_env_set) {
      61         828 :     if(std::getenv("PLUMED_NUM_THREADS")) {
      62         828 :       Tools::convert(std::getenv("PLUMED_NUM_THREADS"),getOpenMPVars().num_threads);
      63             :     }
      64         828 :     getOpenMPVars().nt_env_set = true;
      65             :   }
      66     1858211 :   return getOpenMPVars().num_threads;
      67             : }
      68             : 
      69     6263808 : unsigned OpenMP::getThreadNum() {
      70             : #if defined(_OPENMP)
      71     6263808 :   return omp_get_thread_num();
      72             : #else
      73             :   return 0;
      74             : #endif
      75             : }
      76             : 
      77             : 
      78             : 
      79             : }
      80             : 
      81             : 
      82             : 

Generated by: LCOV version 1.16