api_01.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014 INRIA
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include "../helper.h"
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #if !defined(STARPU_OPENMP)
  21. int main(int argc, char **argv)
  22. {
  23. return STARPU_TEST_SKIPPED;
  24. }
  25. #else
  26. __attribute__((constructor))
  27. static void omp_constructor(void)
  28. {
  29. int ret;
  30. /* we clear the whole OMP environment for this test, to check the
  31. * default behaviour of API functions */
  32. unsetenv("OMP_DYNAMIC");
  33. unsetenv("OMP_NESTED");
  34. unsetenv("OMP_SCHEDULE");
  35. unsetenv("OMP_STACKSIZE");
  36. unsetenv("OMP_WAIT_POLICY");
  37. unsetenv("OMP_THREAD_LIMIT");
  38. unsetenv("OMP_MAX_ACTIVE_LEVELS");
  39. unsetenv("OMP_CANCELLATION");
  40. unsetenv("OMP_DEFAULT_DEVICE");
  41. unsetenv("OMP_MAX_TASK_PRIORITY");
  42. unsetenv("OMP_PROC_BIND");
  43. unsetenv("OMP_NUM_THREADS");
  44. unsetenv("OMP_PLACES");
  45. unsetenv("OMP_DISPLAY_ENV");
  46. ret = starpu_omp_init();
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_omp_init");
  48. }
  49. __attribute__((destructor))
  50. static void omp_destructor(void)
  51. {
  52. starpu_omp_shutdown();
  53. }
  54. #define check_omp_func(f,_tv) \
  55. { \
  56. const int v = (f()); \
  57. const int tv = (_tv); \
  58. printf(#f ": %d (should be %d)\n", v, tv); \
  59. STARPU_ASSERT(v == tv); \
  60. }
  61. const char * get_sched_name(int sched_value)
  62. {
  63. const char *sched_name = NULL;
  64. switch (sched_value)
  65. {
  66. case starpu_omp_sched_undefined: sched_name = "<undefined>"; break;
  67. case starpu_omp_sched_static: sched_name = "static"; break;
  68. case starpu_omp_sched_dynamic: sched_name = "dynamic"; break;
  69. case starpu_omp_sched_guided: sched_name = "guided"; break;
  70. case starpu_omp_sched_auto: sched_name = "auto"; break;
  71. case starpu_omp_sched_runtime: sched_name = "runtime"; break;
  72. default: _STARPU_ERROR("invalid omp schedule value");
  73. }
  74. return sched_name;
  75. }
  76. int
  77. main (int argc, char *argv[])
  78. {
  79. const int nb_cpus = starpu_cpu_worker_get_count();
  80. check_omp_func(starpu_omp_get_num_threads, 1);
  81. check_omp_func(starpu_omp_get_thread_num, 0);
  82. /* since OMP_NUM_THREADS is cleared, starpu_omp_get_max_threads() should return nb_cpus */
  83. check_omp_func(starpu_omp_get_max_threads, nb_cpus);
  84. check_omp_func(starpu_omp_get_num_procs, nb_cpus);
  85. check_omp_func(starpu_omp_in_parallel, 0);
  86. check_omp_func(starpu_omp_get_dynamic, 0);
  87. check_omp_func(starpu_omp_get_nested, 0);
  88. check_omp_func(starpu_omp_get_cancellation, 0);
  89. {
  90. const enum starpu_omp_sched_value target_kind = starpu_omp_sched_static;
  91. const int target_modifier = 0;
  92. enum starpu_omp_sched_value kind;
  93. int modifier;
  94. const char *sched_name;
  95. const char *target_sched_name;
  96. starpu_omp_get_schedule(&kind, &modifier);
  97. sched_name = get_sched_name(kind);
  98. target_sched_name = get_sched_name(target_kind);
  99. printf("starpu_omp_get_schedule: %s,%d (should be %s,%d)\n", sched_name, modifier, target_sched_name, target_modifier);
  100. STARPU_ASSERT(kind == target_kind && modifier == target_modifier);
  101. }
  102. check_omp_func(starpu_omp_get_thread_limit, nb_cpus);
  103. check_omp_func(starpu_omp_get_max_active_levels, 1);
  104. check_omp_func(starpu_omp_get_level, 0);
  105. {
  106. const int tv = 0;
  107. const int v = starpu_omp_get_ancestor_thread_num(0);
  108. printf("starpu_omp_get_ancestor_thread_num(0): %d (should be %d)\n", v, tv);
  109. STARPU_ASSERT(v == tv);
  110. }
  111. {
  112. const int tv = 1;
  113. const int v = starpu_omp_get_team_size(0);
  114. printf("starpu_omp_get_team_size(0): %d (should be %d)\n", v, tv);
  115. STARPU_ASSERT(v == tv);
  116. }
  117. check_omp_func(starpu_omp_get_active_level, 0);
  118. check_omp_func(starpu_omp_in_final, 0);
  119. check_omp_func(starpu_omp_get_proc_bind, starpu_omp_proc_bind_undefined);
  120. check_omp_func(starpu_omp_get_default_device, 0);
  121. /* TODO: support more than one device */
  122. check_omp_func(starpu_omp_get_num_devices, 1);
  123. check_omp_func(starpu_omp_get_num_teams, 1);
  124. check_omp_func(starpu_omp_get_team_num, 0);
  125. check_omp_func(starpu_omp_is_initial_device, 1);
  126. check_omp_func(starpu_omp_get_max_task_priority, 0);
  127. return 0;
  128. }
  129. #endif