lib-1.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <stdlib.h>
  2. #include <omp.h>
  3. int
  4. main (void)
  5. {
  6. double d, e;
  7. int l;
  8. omp_lock_t lck;
  9. omp_nest_lock_t nlck;
  10. d = omp_get_wtime ();
  11. omp_init_lock (&lck);
  12. omp_set_lock (&lck);
  13. if (omp_test_lock (&lck))
  14. abort ();
  15. omp_unset_lock (&lck);
  16. if (! omp_test_lock (&lck))
  17. abort ();
  18. if (omp_test_lock (&lck))
  19. abort ();
  20. omp_unset_lock (&lck);
  21. omp_destroy_lock (&lck);
  22. omp_init_nest_lock (&nlck);
  23. if (omp_test_nest_lock (&nlck) != 1)
  24. abort ();
  25. omp_set_nest_lock (&nlck);
  26. if (omp_test_nest_lock (&nlck) != 3)
  27. abort ();
  28. omp_unset_nest_lock (&nlck);
  29. omp_unset_nest_lock (&nlck);
  30. if (omp_test_nest_lock (&nlck) != 2)
  31. abort ();
  32. omp_unset_nest_lock (&nlck);
  33. omp_unset_nest_lock (&nlck);
  34. omp_destroy_nest_lock (&nlck);
  35. omp_set_dynamic (1);
  36. if (! omp_get_dynamic ())
  37. abort ();
  38. omp_set_dynamic (0);
  39. if (omp_get_dynamic ())
  40. abort ();
  41. omp_set_nested (1);
  42. if (! omp_get_nested ())
  43. abort ();
  44. omp_set_nested (0);
  45. if (omp_get_nested ())
  46. abort ();
  47. omp_set_num_threads (5);
  48. if (omp_get_num_threads () != 1)
  49. abort ();
  50. if (omp_get_max_threads () != 5)
  51. abort ();
  52. if (omp_get_thread_num () != 0)
  53. abort ();
  54. omp_set_num_threads (3);
  55. if (omp_get_num_threads () != 1)
  56. abort ();
  57. if (omp_get_max_threads () != 3)
  58. abort ();
  59. if (omp_get_thread_num () != 0)
  60. abort ();
  61. l = 0;
  62. #pragma omp parallel reduction (|:l)
  63. {
  64. l = omp_get_num_threads () != 3;
  65. l |= omp_get_thread_num () < 0;
  66. l |= omp_get_thread_num () >= 3;
  67. #pragma omp master
  68. l |= omp_get_thread_num () != 0;
  69. }
  70. if (l)
  71. abort ();
  72. if (omp_get_num_procs () <= 0)
  73. abort ();
  74. if (omp_in_parallel ())
  75. abort ();
  76. #pragma omp parallel reduction (|:l)
  77. l = ! omp_in_parallel ();
  78. #pragma omp parallel reduction (|:l) if (1)
  79. l = ! omp_in_parallel ();
  80. if (l)
  81. abort ();
  82. e = omp_get_wtime ();
  83. if (d > e)
  84. abort ();
  85. d = omp_get_wtick ();
  86. /* Negative precision is definitely wrong,
  87. bigger than 1s clock resolution is also strange. */
  88. if (d <= 0 || d > 1)
  89. abort ();
  90. return 0;
  91. }