testsuite/libgomp.c/ordered-2.c

Go to the documentation of this file.
00001 /* Trivial test of ordered.  */
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 next;
00013 static int CHUNK, NTHR;
00014 
00015 static void clean_data (void)
00016 {
00017   next = 0;
00018 }
00019 
00020 static void set_data (long i)
00021 {
00022   int n = __sync_fetch_and_add (&next, 1);
00023   assert (n == i);
00024 }
00025 
00026 
00027 #define TMPL_1(sched)                           \
00028 static void f_##sched##_1 (void *dummy)                 \
00029 {                                   \
00030   long s0, e0, i;                           \
00031   if (GOMP_loop_ordered_##sched##_start (0, N, 1, CHUNK, &s0, &e0)) \
00032     do                                  \
00033       {                                 \
00034     for (i = s0; i < e0; ++i)                   \
00035       {                             \
00036         GOMP_ordered_start ();                  \
00037         set_data (i);                       \
00038         GOMP_ordered_end ();                    \
00039       }                             \
00040       }                                 \
00041     while (GOMP_loop_ordered_##sched##_next (&s0, &e0));        \
00042   GOMP_loop_end ();                         \
00043 }                                   \
00044 static void t_##sched##_1 (void)                    \
00045 {                                   \
00046   clean_data ();                            \
00047   GOMP_parallel_start (f_##sched##_1, NULL, NTHR);          \
00048   f_##sched##_1 (NULL);                         \
00049   GOMP_parallel_end ();                         \
00050 }
00051 
00052 TMPL_1(static)
00053 TMPL_1(dynamic)
00054 TMPL_1(guided)
00055 
00056 static void test (void)
00057 {
00058   t_static_1 ();
00059   t_dynamic_1 ();
00060   t_guided_1 ();
00061 }
00062 
00063 int main()
00064 {
00065   omp_set_dynamic (0);
00066 
00067   NTHR = 4;
00068 
00069   CHUNK = 1;
00070   test ();
00071 
00072   CHUNK = 5;
00073   test ();
00074 
00075   CHUNK = 7;
00076   test ();
00077 
00078   CHUNK = 0;
00079   t_static_1 ();
00080 
00081   return 0;
00082 }

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