execute_on_all.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <common/config.h>
  18. #include <core/jobs.h>
  19. struct wrapper_func_args {
  20. void (*func)(void *);
  21. void *arg;
  22. };
  23. static void wrapper_func(void *buffers[] __attribute__ ((unused)), void *_args)
  24. {
  25. struct wrapper_func_args *args = _args;
  26. args->func(args->arg);
  27. }
  28. static struct starpu_perfmodel_t wrapper_model = {
  29. .type = STARPU_HISTORY_BASED,
  30. .symbol = "_wrapper_model"
  31. };
  32. /* execute func(arg) on each worker that matches the "where" flag */
  33. void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where)
  34. {
  35. int ret;
  36. unsigned worker;
  37. unsigned nworkers = starpu_worker_get_count();
  38. struct starpu_task *tasks[STARPU_NMAXWORKERS];
  39. /* create a wrapper codelet */
  40. struct starpu_codelet_t wrapper_cl = {
  41. .where = where,
  42. .cuda_func = wrapper_func,
  43. .cpu_func = wrapper_func,
  44. .opencl_func = wrapper_func,
  45. /* XXX we do not handle Cell .. */
  46. .nbuffers = 0,
  47. .model = &wrapper_model
  48. };
  49. struct wrapper_func_args args = {
  50. .func = func,
  51. .arg = arg
  52. };
  53. for (worker = 0; worker < nworkers; worker++)
  54. {
  55. tasks[worker] = starpu_task_create();
  56. tasks[worker]->cl = &wrapper_cl;
  57. tasks[worker]->cl_arg = &args;
  58. tasks[worker]->execute_on_a_specific_worker = 1;
  59. tasks[worker]->workerid = worker;
  60. tasks[worker]->detach = 0;
  61. tasks[worker]->destroy = 0;
  62. #ifdef STARPU_USE_FXT
  63. _starpu_exclude_task_from_dag(tasks[worker]);
  64. #endif
  65. ret = starpu_task_submit(tasks[worker]);
  66. if (ret == -ENODEV)
  67. {
  68. /* if the worker is not able to execute this tasks, we
  69. * don't insist as this means the worker is not
  70. * designated by the "where" bitmap */
  71. starpu_task_destroy(tasks[worker]);
  72. tasks[worker] = NULL;
  73. }
  74. }
  75. for (worker = 0; worker < nworkers; worker++)
  76. {
  77. if (tasks[worker])
  78. {
  79. ret = starpu_task_wait(tasks[worker]);
  80. STARPU_ASSERT(!ret);
  81. starpu_task_destroy(tasks[worker]);
  82. }
  83. }
  84. }