barrier-1.c 964 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Trivial test of barrier. */
  2. #include <omp.h>
  3. #include <sys/time.h>
  4. #include <unistd.h>
  5. #include <assert.h>
  6. #include "libgomp_g.h"
  7. struct timeval stamps[3][3];
  8. static void function(void *dummy)
  9. {
  10. int iam = omp_get_thread_num ();
  11. gettimeofday (&stamps[iam][0], NULL);
  12. if (iam == 0)
  13. usleep (10);
  14. GOMP_barrier ();
  15. if (iam == 0)
  16. {
  17. gettimeofday (&stamps[0][1], NULL);
  18. usleep (10);
  19. }
  20. GOMP_barrier ();
  21. gettimeofday (&stamps[iam][2], NULL);
  22. }
  23. int main()
  24. {
  25. omp_set_dynamic (0);
  26. GOMP_parallel_start (function, NULL, 3);
  27. function (NULL);
  28. GOMP_parallel_end ();
  29. assert (!timercmp (&stamps[0][0], &stamps[0][1], >));
  30. assert (!timercmp (&stamps[1][0], &stamps[0][1], >));
  31. assert (!timercmp (&stamps[2][0], &stamps[0][1], >));
  32. assert (!timercmp (&stamps[0][1], &stamps[0][2], >));
  33. assert (!timercmp (&stamps[0][1], &stamps[1][2], >));
  34. assert (!timercmp (&stamps[0][1], &stamps[2][2], >));
  35. return 0;
  36. }