parallel-1.c 777 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Trivial test of thread startup. */
  2. #include <omp.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include "libgomp_g.h"
  6. static int nthr;
  7. static int saw[4];
  8. static void function(void *dummy)
  9. {
  10. int iam = omp_get_thread_num ();
  11. if (iam == 0)
  12. nthr = omp_get_num_threads ();
  13. saw[iam] = 1;
  14. }
  15. int main()
  16. {
  17. omp_set_dynamic (0);
  18. GOMP_parallel_start (function, NULL, 2);
  19. function (NULL);
  20. GOMP_parallel_end ();
  21. assert (nthr == 2);
  22. assert (saw[0] != 0);
  23. assert (saw[1] != 0);
  24. assert (saw[2] == 0);
  25. memset (saw, 0, sizeof (saw));
  26. GOMP_parallel_start (function, NULL, 3);
  27. function (NULL);
  28. GOMP_parallel_end ();
  29. assert (nthr == 3);
  30. assert (saw[0] != 0);
  31. assert (saw[1] != 0);
  32. assert (saw[2] != 0);
  33. assert (saw[3] == 0);
  34. return 0;
  35. }