component_eager.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. STARPU_ASSERT(component && task && starpu_sched_component_is_eager(component));
  21. STARPU_ASSERT(starpu_sched_component_can_execute_task(component,task));
  22. int workerid;
  23. for(workerid = starpu_bitmap_first(component->workers_in_ctx);
  24. workerid != -1;
  25. workerid = starpu_bitmap_next(component->workers_in_ctx, workerid))
  26. {
  27. int nimpl;
  28. for(nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
  29. {
  30. if(starpu_worker_can_execute_task(workerid,task,nimpl)
  31. || starpu_combined_worker_can_execute_task(workerid, task, nimpl))
  32. {
  33. int i;
  34. for (i = 0; i < component->nchildren; i++)
  35. {
  36. int idworker;
  37. for(idworker = starpu_bitmap_first(component->children[i]->workers);
  38. idworker != -1;
  39. idworker = starpu_bitmap_next(component->children[i]->workers, idworker))
  40. {
  41. if (idworker == workerid)
  42. {
  43. if(starpu_sched_component_is_worker(component->children[i]))
  44. {
  45. component->children[i]->can_pull(component->children[i]);
  46. return 1;
  47. }
  48. else
  49. return component->children[i]->push_task(component->children[i],task);
  50. }
  51. }
  52. }
  53. }
  54. }
  55. }
  56. return 1;
  57. }
  58. int starpu_sched_component_is_eager(struct starpu_sched_component * component)
  59. {
  60. return component->push_task == eager_push_task;
  61. }
  62. struct starpu_sched_component * starpu_sched_component_eager_create(struct starpu_sched_tree *tree, void * arg STARPU_ATTRIBUTE_UNUSED)
  63. {
  64. struct starpu_sched_component * component = starpu_sched_component_create(tree);
  65. component->push_task = eager_push_task;
  66. component->name = "eager";
  67. return component;
  68. }