LCOV - code coverage report
Current view: top level - lunchbox - omp.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 13 14 92.9 %
Date: 2014-08-05 Functions: 4 4 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2007-2012, Stefan Eilemann <eile@equalizergraphics.com> 
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *  
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  * 
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include "omp.h"
      19             : #include "debug.h"
      20             : 
      21             : #include <cstdlib>
      22             : 
      23             : namespace lunchbox
      24             : {
      25             : namespace
      26             : {
      27             : static unsigned _setupNThreads();
      28          29 : unsigned _nThreads = _setupNThreads();
      29             : 
      30          29 : static unsigned _setupNThreads()
      31             : {
      32             : #ifdef LUNCHBOX_USE_OPENMP
      33          29 :     const char* nThreadsEnv = getenv( "OMP_NUM_THREADS" );
      34          29 :     unsigned    nThreads    = 0;
      35             : 
      36          29 :     if( nThreadsEnv )
      37           0 :         nThreads = atoi( nThreadsEnv );
      38             : 
      39          29 :     if( nThreads < 1 )
      40          29 :         nThreads = omp_get_num_procs();
      41             : 
      42          29 :     LBASSERT( nThreads > 0 );
      43          29 :     omp_set_num_threads( nThreads );
      44          29 :     return nThreads;
      45             : #else
      46             :     return 1;
      47             : #endif
      48             : }
      49             : }
      50             : 
      51          85 : unsigned OMP::getNThreads()
      52             : {
      53          85 :     return _nThreads;
      54             : }
      55             : 
      56          87 : }

Generated by: LCOV version 1.10