LCOV - code coverage report
Current view: top level - tests - openmp.cpp (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 15 15 100.0 %
Date: 2016-03-29 17:09:06 Functions: 5 5 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2008-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             : // Simple test case for bug:
      19             : // http://sourceforge.net/tracker/index.php?func=detail&aid=1964341&group_id=170962&atid=856209
      20             : 
      21             : // Compile with:
      22             : //  g++-4.2 test.cpp -g -fopenmp -lgomp -lpthread -o test
      23             : 
      24             : #define NTHREADS 4
      25             : #define LOOPSIZE 100000
      26             : 
      27             : #include "test.h"
      28             : #include <pthread.h>
      29             : 
      30             : #ifdef LUNCHBOX_USE_OPENMP
      31             : #  include <omp.h>
      32             : #endif
      33             : 
      34           4 : void* runChild( void* )
      35             : {
      36             :     unsigned char data[ LOOPSIZE ];
      37             : 
      38             : #ifdef LUNCHBOX_USE_OPENMP
      39          67 : #  pragma omp parallel for
      40             : #endif
      41             :     for( int i = 0; i < LOOPSIZE; ++i )
      42             :     {
      43      137980 :         data[i] = static_cast< unsigned char >( i % 256 );
      44             :     }
      45      400004 :     for( int i = 0; i < LOOPSIZE; ++i )
      46             :     {
      47      400000 :         TEST( data[i] == static_cast< unsigned char >( i % 256 ));
      48             :     }
      49             : 
      50           4 :     return 0;
      51             : }
      52             : 
      53           1 : int main( int, char** )
      54             : {
      55             : //    omp_set_nested( 1 );
      56             : 
      57             :     pthread_attr_t attributes;
      58           1 :     pthread_attr_init( &attributes );
      59           1 :     pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM );
      60             : 
      61             :     pthread_t threadIDs[NTHREADS];
      62             : 
      63           5 :     for( int i = 0; i < NTHREADS; ++i )
      64           4 :         pthread_create( &threadIDs[i], &attributes, runChild, 0 );
      65             : 
      66           5 :     for( int i = 0; i < NTHREADS; ++i )
      67           4 :         pthread_join( threadIDs[i], 0 );
      68           1 :     return EXIT_SUCCESS;
      69           3 : }

Generated by: LCOV version 1.11