Ticket #34231: test.cpp

File test.cpp, 1.0 KB (added by devernay (Frédéric Devernay), 12 years ago)

test file from GCC bug 36242, exhibiting the OpenMP bug

Line 
1
2/* Copyright (c) 2008, Stefan Eilemann <eile@equalizergraphics.com>
3   All rights reserved. */
4
5// Simple test case for bug:
6// http://sourceforge.net/tracker/index.php?func=detail&aid=1964341&group_id=170962&atid=856209
7
8// Compile with:
9//  g++-4.2 test.cpp -g -fopenmp -lgomp -lpthread -o test
10
11#define NTHREADS 4
12#define LOOPSIZE 100000
13
14#include <pthread.h>
15//#include <omp.h>
16
17void* runChild( void* arg )
18{
19    unsigned char data[ LOOPSIZE ];
20
21#  pragma omp parallel for
22    for( int i = 0; i < LOOPSIZE; ++i )
23    {
24        data[i] = static_cast< unsigned char >( i % 256 );
25    }
26
27    return 0;
28}
29
30int main( int argc, char **argv )
31{
32//    omp_set_nested( 1 );
33
34    pthread_attr_t attributes;
35    pthread_attr_init( &attributes );
36    pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM );
37
38        pthread_t threadIDs[NTHREADS];
39
40    for( int i = 0; i < NTHREADS; ++i )
41        pthread_create( &threadIDs[i], &attributes, runChild, 0 );
42
43    for( int i = 0; i < NTHREADS; ++i )
44        pthread_join( threadIDs[i], 0 );
45}