testsuite/libgomp.c/sections-1.c

Go to the documentation of this file.
00001 /* Test that all sections are touched.  */
00002 
00003 /* { dg-require-effective-target sync_int_long } */
00004 
00005 #include <omp.h>
00006 #include <string.h>
00007 #include <assert.h>
00008 #include "libgomp_g.h"
00009 
00010 
00011 #define N 100
00012 static int data[N];
00013 static int NTHR;
00014 
00015 static void clean_data (void)
00016 {
00017   memset (data, -1, sizeof (data));
00018 }
00019 
00020 static void test_data (void)
00021 {
00022   int i;
00023 
00024   for (i = 0; i < N; ++i)
00025     assert (data[i] != -1);
00026 }
00027 
00028 static void set_data (unsigned i, int val)
00029 {
00030   int old;
00031   assert (i >= 1 && i <= N);
00032   old = __sync_lock_test_and_set (data+i-1, val);
00033   assert (old == -1);
00034 }
00035   
00036 
00037 static void f_1 (void *dummy)
00038 {
00039   int iam = omp_get_thread_num ();
00040   unsigned long s;
00041 
00042   for (s = GOMP_sections_start (N); s ; s = GOMP_sections_next ())
00043     set_data (s, iam);
00044   GOMP_sections_end ();
00045 }
00046 
00047 static void test_1 (void)
00048 {
00049   clean_data ();
00050   GOMP_parallel_start (f_1, NULL, NTHR);
00051   f_1 (NULL);
00052   GOMP_parallel_end ();
00053   test_data ();
00054 }
00055 
00056 static void f_2 (void *dummy)
00057 {
00058   int iam = omp_get_thread_num ();
00059   unsigned s;
00060 
00061   while ((s = GOMP_sections_next ()))
00062     set_data (s, iam);
00063   GOMP_sections_end_nowait ();
00064 }
00065 
00066 static void test_2 (void)
00067 {
00068   clean_data ();
00069   GOMP_parallel_sections_start (f_2, NULL, NTHR, N);
00070   f_2 (NULL);
00071   GOMP_parallel_end ();
00072   test_data ();
00073 }
00074 
00075 int main()
00076 {
00077   omp_set_dynamic (0);
00078 
00079   NTHR = 4;
00080 
00081   test_1 ();
00082   test_2 ();
00083 
00084   return 0;
00085 }

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