testsuite/libgomp.c/parallel-1.c

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

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