LCOV - code coverage report
Current view: top level - tools - OpenMP.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 14 17 82.4 %
Date: 2024-10-11 08:09:47 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     1954083 : static OpenMPVars & getOpenMPVars() {
      41             :   static OpenMPVars vars;
      42     1954083 :   return vars;
      43             : }
      44             : 
      45           0 : void OpenMP::setNumThreads(const unsigned nt) {
      46           0 :   getOpenMPVars().num_threads=nt;
      47           0 : }
      48             : 
      49       88038 : unsigned OpenMP::getCachelineSize() {
      50       88038 :   if(!getOpenMPVars().cache_set) {
      51         786 :     if(std::getenv("PLUMED_CACHELINE_SIZE")) Tools::convert(std::getenv("PLUMED_CACHELINE_SIZE"),getOpenMPVars().cacheline_size);
      52         786 :     getOpenMPVars().cache_set = true;
      53             :   }
      54       88038 :   return getOpenMPVars().cacheline_size;
      55             : }
      56             : 
      57     1866045 : unsigned OpenMP::getNumThreads() {
      58     1866045 :   if(!getOpenMPVars().nt_env_set) {
      59         786 :     if(std::getenv("PLUMED_NUM_THREADS")) Tools::convert(std::getenv("PLUMED_NUM_THREADS"),getOpenMPVars().num_threads);
      60         786 :     getOpenMPVars().nt_env_set = true;
      61             :   }
      62     1866045 :   return getOpenMPVars().num_threads;
      63             : }
      64             : 
      65     6263516 : unsigned OpenMP::getThreadNum() {
      66             : #if defined(_OPENMP)
      67     6263516 :   return omp_get_thread_num();
      68             : #else
      69             :   return 0;
      70             : #endif
      71             : }
      72             : 
      73             : 
      74             : 
      75             : }
      76             : 
      77             : 
      78             : 

Generated by: LCOV version 1.15