taskloop.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2018 Université de Bordeaux
  4. * Copyright (C) 2018 Inria
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <pthread.h>
  18. #include <starpu.h>
  19. #include <stdio.h>
  20. #include "../helper.h"
  21. /*
  22. * Check the OpenMP orphaned task support.
  23. */
  24. #if !defined(STARPU_OPENMP)
  25. int main(void)
  26. {
  27. return STARPU_TEST_SKIPPED;
  28. }
  29. #else
  30. __attribute__((constructor))
  31. static void omp_constructor(void)
  32. {
  33. int ret = starpu_omp_init();
  34. if (ret == -EINVAL) exit(STARPU_TEST_SKIPPED);
  35. STARPU_CHECK_RETURN_VALUE(ret, "starpu_omp_init");
  36. }
  37. __attribute__((destructor))
  38. static void omp_destructor(void)
  39. {
  40. starpu_omp_shutdown();
  41. }
  42. void taskloop_callback(unsigned long long begin_i, unsigned long long end_i)
  43. {
  44. int worker_id;
  45. pthread_t tid;
  46. tid = pthread_self();
  47. worker_id = starpu_worker_get_id();
  48. printf ("begin = %llu , end = %llu, %p\n", begin_i, end_i, (void *)starpu_task_get_current());
  49. }
  50. void taskloop_callback_wrapper(void *buffers[], void *_args)
  51. {
  52. (void) buffers;
  53. struct starpu_omp_task_region_attr * args = _args;
  54. taskloop_callback(args->begin_i, args->end_i);
  55. }
  56. int
  57. main (void)
  58. {
  59. struct starpu_omp_task_region_attr attr;
  60. memset(&attr, 0, sizeof(attr));
  61. #ifdef STARPU_SIMGRID
  62. attr.cl.model = &starpu_perfmodel_nop;
  63. #endif
  64. attr.cl.flags = STARPU_CODELET_SIMGRID_EXECUTE;
  65. attr.cl.cpu_funcs[0] = taskloop_callback_wrapper;
  66. attr.cl_arg = &attr;
  67. attr.cl.where = STARPU_CPU;
  68. attr.if_clause = 1;
  69. attr.final_clause = 0;
  70. attr.untied_clause = 1;
  71. attr.mergeable_clause = 0;
  72. attr.nogroup_clause = 0;
  73. attr.is_loop = 0;
  74. attr.collapse = 0;
  75. attr.num_tasks = 5;
  76. attr.nb_iterations = 400;
  77. attr.grainsize = 130;
  78. starpu_omp_taskloop_inline_begin(&attr);
  79. starpu_omp_taskloop_inline_end(&attr);
  80. return 0;
  81. }
  82. #endif