component_eager.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Inria
  4. * Copyright (C) 2017 CNRS
  5. * Copyright (C) 2014-2017 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu_sched_component.h>
  19. #include <starpu_scheduler.h>
  20. static int eager_push_task(struct starpu_sched_component * component, struct starpu_task * task)
  21. {
  22. int ret;
  23. STARPU_ASSERT(component && task && starpu_sched_component_is_eager(component));
  24. STARPU_ASSERT(starpu_sched_component_can_execute_task(component,task));
  25. int workerid;
  26. for(workerid = starpu_bitmap_first(component->workers_in_ctx);
  27. workerid != -1;
  28. workerid = starpu_bitmap_next(component->workers_in_ctx, workerid))
  29. {
  30. int nimpl;
  31. for(nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  32. {
  33. if(starpu_worker_can_execute_task(workerid,task,nimpl)
  34. || starpu_combined_worker_can_execute_task(workerid, task, nimpl))
  35. {
  36. unsigned i;
  37. for (i = 0; i < component->nchildren; i++)
  38. {
  39. int idworker;
  40. for(idworker = starpu_bitmap_first(component->children[i]->workers);
  41. idworker != -1;
  42. idworker = starpu_bitmap_next(component->children[i]->workers, idworker))
  43. {
  44. if (idworker == workerid)
  45. {
  46. if(starpu_sched_component_is_worker(component->children[i]))
  47. {
  48. if (component->children[i]->can_pull(component->children[i]))
  49. return 1;
  50. }
  51. else
  52. {
  53. ret = starpu_sched_component_push_task(component,component->children[i],task);
  54. if (!ret)
  55. return 0;
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. return 1;
  64. }
  65. int starpu_sched_component_is_eager(struct starpu_sched_component * component)
  66. {
  67. return component->push_task == eager_push_task;
  68. }
  69. struct starpu_sched_component * starpu_sched_component_eager_create(struct starpu_sched_tree *tree, void *arg)
  70. {
  71. (void)arg;
  72. struct starpu_sched_component * component = starpu_sched_component_create(tree, "eager");
  73. component->push_task = eager_push_task;
  74. return component;
  75. }