testsuite/libgomp.c/barrier-1.c

Go to the documentation of this file.
00001 /* Trivial test of barrier.  */
00002 
00003 #include <omp.h>
00004 #include <sys/time.h>
00005 #include <unistd.h>
00006 #include <assert.h>
00007 #include "libgomp_g.h"
00008 
00009 
00010 struct timeval stamps[3][3];
00011 
00012 static void function(void *dummy)
00013 {
00014   int iam = omp_get_thread_num ();
00015 
00016   gettimeofday (&stamps[iam][0], NULL);
00017   if (iam == 0)
00018     usleep (10);
00019 
00020   GOMP_barrier ();
00021 
00022   if (iam == 0)
00023     {
00024       gettimeofday (&stamps[0][1], NULL);
00025       usleep (10);
00026     }
00027 
00028   GOMP_barrier ();
00029   
00030   gettimeofday (&stamps[iam][2], NULL);
00031 }
00032 
00033 int main()
00034 {
00035   omp_set_dynamic (0);
00036 
00037   GOMP_parallel_start (function, NULL, 3);
00038   function (NULL);
00039   GOMP_parallel_end ();
00040 
00041   assert (!timercmp (&stamps[0][0], &stamps[0][1], >));
00042   assert (!timercmp (&stamps[1][0], &stamps[0][1], >));
00043   assert (!timercmp (&stamps[2][0], &stamps[0][1], >));
00044 
00045   assert (!timercmp (&stamps[0][1], &stamps[0][2], >));
00046   assert (!timercmp (&stamps[0][1], &stamps[1][2], >));
00047   assert (!timercmp (&stamps[0][1], &stamps[2][2], >));
00048 
00049   return 0;
00050 }

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