modular_ws.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 INRIA
  4. * Copyright (C) 2013 Simon Archipoff
  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 <starpu_sched_component.h>
  18. #include <starpu_scheduler.h>
  19. static void initialize_ws_center_policy(unsigned sched_ctx_id)
  20. {
  21. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  22. struct starpu_sched_tree *t = starpu_sched_tree_create(sched_ctx_id);
  23. t->root = starpu_sched_component_work_stealing_create(t, NULL);
  24. unsigned i;
  25. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  26. {
  27. struct starpu_sched_component * worker_component = starpu_sched_component_worker_get(sched_ctx_id, i);
  28. STARPU_ASSERT(worker_component);
  29. t->root->add_child(t->root, worker_component);
  30. worker_component->add_parent(worker_component, t->root);
  31. }
  32. starpu_sched_tree_update_workers(t);
  33. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  34. }
  35. static void deinitialize_ws_center_policy(unsigned sched_ctx_id)
  36. {
  37. struct starpu_sched_tree *t = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  38. starpu_sched_tree_destroy(t);
  39. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  40. }
  41. struct starpu_sched_policy _starpu_sched_modular_ws_policy =
  42. {
  43. .init_sched = initialize_ws_center_policy,
  44. .deinit_sched = deinitialize_ws_center_policy,
  45. .add_workers = starpu_sched_tree_add_workers,
  46. .remove_workers = starpu_sched_tree_remove_workers,
  47. .push_task = starpu_sched_tree_work_stealing_push_task,
  48. .pop_task = starpu_sched_tree_pop_task,
  49. .pre_exec_hook = NULL,
  50. .post_exec_hook = NULL,
  51. .pop_every_task = NULL,
  52. .policy_name = "modular-ws",
  53. .policy_description = "work stealing modular policy"
  54. };