testsuite/libgomp.c/lib-1.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <omp.h>
00003 
00004 int
00005 main (void)
00006 {
00007   double d, e;
00008   int l;
00009   omp_lock_t lck;
00010   omp_nest_lock_t nlck;
00011 
00012   d = omp_get_wtime ();
00013 
00014   omp_init_lock (&lck);
00015   omp_set_lock (&lck);
00016   if (omp_test_lock (&lck))
00017     abort ();
00018   omp_unset_lock (&lck);
00019   if (! omp_test_lock (&lck))
00020     abort ();
00021   if (omp_test_lock (&lck))
00022     abort ();
00023   omp_unset_lock (&lck);
00024   omp_destroy_lock (&lck);
00025 
00026   omp_init_nest_lock (&nlck);
00027   if (omp_test_nest_lock (&nlck) != 1)
00028     abort ();
00029   omp_set_nest_lock (&nlck);
00030   if (omp_test_nest_lock (&nlck) != 3)
00031     abort ();
00032   omp_unset_nest_lock (&nlck);
00033   omp_unset_nest_lock (&nlck);
00034   if (omp_test_nest_lock (&nlck) != 2)
00035     abort ();
00036   omp_unset_nest_lock (&nlck);
00037   omp_unset_nest_lock (&nlck);
00038   omp_destroy_nest_lock (&nlck);
00039 
00040   omp_set_dynamic (1);
00041   if (! omp_get_dynamic ())
00042     abort ();
00043   omp_set_dynamic (0);
00044   if (omp_get_dynamic ())
00045     abort ();
00046 
00047   omp_set_nested (1);
00048   if (! omp_get_nested ())
00049     abort ();
00050   omp_set_nested (0);
00051   if (omp_get_nested ())
00052     abort ();
00053 
00054   omp_set_num_threads (5);
00055   if (omp_get_num_threads () != 1)
00056     abort ();
00057   if (omp_get_max_threads () != 5)
00058     abort ();
00059   if (omp_get_thread_num () != 0)
00060     abort ();
00061   omp_set_num_threads (3);
00062   if (omp_get_num_threads () != 1)
00063     abort ();
00064   if (omp_get_max_threads () != 3)
00065     abort ();
00066   if (omp_get_thread_num () != 0)
00067     abort ();
00068   l = 0;
00069 #pragma omp parallel reduction (|:l)
00070   {
00071     l = omp_get_num_threads () != 3;
00072     l |= omp_get_thread_num () < 0;
00073     l |= omp_get_thread_num () >= 3;
00074 #pragma omp master
00075     l |= omp_get_thread_num () != 0;
00076   }
00077   if (l)
00078     abort ();
00079 
00080   if (omp_get_num_procs () <= 0)
00081     abort ();
00082   if (omp_in_parallel ())
00083     abort ();
00084 #pragma omp parallel reduction (|:l)
00085   l = ! omp_in_parallel ();
00086 #pragma omp parallel reduction (|:l) if (1)
00087   l = ! omp_in_parallel ();
00088 
00089   e = omp_get_wtime ();
00090   if (d > e)
00091     abort ();
00092   d = omp_get_wtick ();
00093   /* Negative precision is definitely wrong,
00094      bigger than 1s clock resolution is also strange.  */
00095   if (d <= 0 || d > 1)
00096     abort ();
00097 
00098   return 0;
00099 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7