00001 // PR c++/36308 00002 // { dg-do run } 00003 00004 #include <omp.h> 00005 #include <assert.h> 00006 00007 #define N 10 00008 00009 struct B 00010 { 00011 static int icount; 00012 static int ccount; 00013 static int dcount; 00014 static int xcount; 00015 00016 B (); 00017 B (const B &); 00018 virtual ~B (); 00019 B& operator= (const B &); 00020 void doit (); 00021 static void clear () { icount = ccount = dcount = xcount = 0; } 00022 }; 00023 00024 int B::icount; 00025 int B::ccount; 00026 int B::dcount; 00027 int B::xcount; 00028 00029 B::B () 00030 { 00031 #pragma omp atomic 00032 icount++; 00033 } 00034 00035 B::B (const B &) 00036 { 00037 #pragma omp atomic 00038 ccount++; 00039 } 00040 00041 B::~B () 00042 { 00043 #pragma omp atomic 00044 dcount++; 00045 } 00046 00047 void 00048 B::doit () 00049 { 00050 #pragma omp atomic 00051 xcount++; 00052 } 00053 00054 static int nthreads; 00055 00056 void 00057 test1 () 00058 { 00059 B b[N]; 00060 #pragma omp parallel private (b) 00061 { 00062 #pragma omp master 00063 nthreads = omp_get_num_threads (); 00064 b[0].doit (); 00065 } 00066 } 00067 00068 void 00069 test2 () 00070 { 00071 B b; 00072 #pragma omp parallel firstprivate (b) 00073 { 00074 #pragma omp single 00075 nthreads = omp_get_num_threads (); 00076 b.doit (); 00077 } 00078 } 00079 00080 int 00081 main () 00082 { 00083 omp_set_dynamic (0); 00084 omp_set_num_threads (4); 00085 00086 B::clear (); 00087 test1 (); 00088 assert (B::xcount == nthreads); 00089 assert (B::ccount == 0); 00090 assert (B::icount == (nthreads + 1) * N); 00091 assert (B::dcount == (nthreads + 1) * N); 00092 00093 B::clear (); 00094 test2 (); 00095 assert (B::xcount == nthreads); 00096 assert (B::ccount == nthreads); 00097 assert (B::icount == 1); 00098 assert (B::dcount == nthreads + 1); 00099 return 0; 00100 }