taskloop.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <pthread.h>
  2. #include <starpu.h>
  3. #include <stdio.h>
  4. #include "../helper.h"
  5. /*
  6. * Check the OpenMP orphaned task support.
  7. */
  8. #if !defined(STARPU_OPENMP)
  9. int main(void)
  10. {
  11. return STARPU_TEST_SKIPPED;
  12. }
  13. #else
  14. __attribute__((constructor))
  15. static void omp_constructor(void)
  16. {
  17. int ret = starpu_omp_init();
  18. STARPU_CHECK_RETURN_VALUE(ret, "starpu_omp_init");
  19. }
  20. __attribute__((destructor))
  21. static void omp_destructor(void)
  22. {
  23. starpu_omp_shutdown();
  24. }
  25. void taskloop_callback(unsigned long long begin_i, unsigned long long end_i) {
  26. int worker_id;
  27. pthread_t tid;
  28. tid = pthread_self();
  29. worker_id = starpu_worker_get_id();
  30. printf ("begin = %llu , end = %llu, %p\n", begin_i, end_i, (void *)starpu_task_get_current());
  31. }
  32. void taskloop_callback_wrapper(void *buffers[], void *_args)
  33. {
  34. (void) buffers;
  35. struct starpu_omp_task_region_attr * args = _args;
  36. taskloop_callback(args->begin_i, args->end_i);
  37. }
  38. int
  39. main (void)
  40. {
  41. struct starpu_omp_task_region_attr attr;
  42. memset(&attr, 0, sizeof(attr));
  43. #ifdef STARPU_SIMGRID
  44. attr.cl.model = &starpu_perfmodel_nop;
  45. #endif
  46. attr.cl.flags = STARPU_CODELET_SIMGRID_EXECUTE;
  47. attr.cl.cpu_funcs[0] = taskloop_callback_wrapper;
  48. attr.cl_arg = &attr;
  49. attr.cl.where = STARPU_CPU;
  50. attr.if_clause = 1;
  51. attr.final_clause = 0;
  52. attr.untied_clause = 1;
  53. attr.mergeable_clause = 0;
  54. attr.nogroup_clause = 0;
  55. attr.is_loop = 0;
  56. attr.collapse = 0;
  57. attr.num_tasks = 5;
  58. attr.nb_iterations = 400;
  59. attr.grainsize = 130;
  60. starpu_omp_taskloop_inline_begin(&attr);
  61. starpu_omp_taskloop_inline_end(&attr);
  62. return 0;
  63. }
  64. #endif