component_eager.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 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_sched_component.h>
  17. #include <starpu_scheduler.h>
  18. static int eager_push_task(struct starpu_sched_component * component, struct starpu_task * task)
  19. {
  20. int ret;
  21. STARPU_ASSERT(component && task && starpu_sched_component_is_eager(component));
  22. STARPU_ASSERT(starpu_sched_component_can_execute_task(component,task));
  23. int workerid;
  24. for(workerid = starpu_bitmap_first(component->workers_in_ctx);
  25. workerid != -1;
  26. workerid = starpu_bitmap_next(component->workers_in_ctx, workerid))
  27. {
  28. int nimpl;
  29. for(nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  30. {
  31. if(starpu_worker_can_execute_task(workerid,task,nimpl)
  32. || starpu_combined_worker_can_execute_task(workerid, task, nimpl))
  33. {
  34. int i;
  35. for (i = 0; i < component->nchildren; i++)
  36. {
  37. int idworker;
  38. for(idworker = starpu_bitmap_first(component->children[i]->workers);
  39. idworker != -1;
  40. idworker = starpu_bitmap_next(component->children[i]->workers, idworker))
  41. {
  42. if (idworker == workerid)
  43. {
  44. if(starpu_sched_component_is_worker(component->children[i]))
  45. {
  46. component->children[i]->can_pull(component->children[i]);
  47. return 1;
  48. }
  49. else
  50. {
  51. ret = starpu_sched_component_push_task(component,component->children[i],task);
  52. if (!ret)
  53. return 0;
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. return 1;
  62. }
  63. int starpu_sched_component_is_eager(struct starpu_sched_component * component)
  64. {
  65. return component->push_task == eager_push_task;
  66. }
  67. struct starpu_sched_component * starpu_sched_component_eager_create(struct starpu_sched_tree *tree, void * arg STARPU_ATTRIBUTE_UNUSED)
  68. {
  69. struct starpu_sched_component * component = starpu_sched_component_create(tree, "eager");
  70. component->push_task = eager_push_task;
  71. return component;
  72. }