tree_prio.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_node.h>
  17. #include <starpu_scheduler.h>
  18. static void initialize_prio_center_policy(unsigned sched_ctx_id)
  19. {
  20. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  21. struct starpu_sched_tree *t = starpu_sched_tree_create(sched_ctx_id);
  22. t->root = starpu_sched_node_prio_create(NULL);
  23. struct starpu_sched_node * eager_node = starpu_sched_node_eager_create(NULL);
  24. t->root->add_child(t->root, eager_node);
  25. starpu_sched_node_set_father(eager_node, t->root, sched_ctx_id);
  26. unsigned i;
  27. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  28. {
  29. struct starpu_sched_node * worker_node = starpu_sched_node_worker_get(i);
  30. STARPU_ASSERT(worker_node);
  31. eager_node->add_child(eager_node, worker_node);
  32. starpu_sched_node_set_father(worker_node, eager_node, sched_ctx_id);
  33. }
  34. starpu_sched_tree_update_workers(t);
  35. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  36. }
  37. static void deinitialize_prio_center_policy(unsigned sched_ctx_id)
  38. {
  39. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  40. starpu_sched_tree_destroy(tree);
  41. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  42. }
  43. struct starpu_sched_policy _starpu_sched_tree_prio_policy =
  44. {
  45. .init_sched = initialize_prio_center_policy,
  46. .deinit_sched = deinitialize_prio_center_policy,
  47. .add_workers = starpu_sched_tree_add_workers,
  48. .remove_workers = starpu_sched_tree_remove_workers,
  49. .push_task = starpu_sched_tree_push_task,
  50. .pop_task = starpu_sched_tree_pop_task,
  51. .pre_exec_hook = starpu_sched_node_worker_pre_exec_hook,
  52. .post_exec_hook = starpu_sched_node_worker_post_exec_hook,
  53. .pop_every_task = NULL,
  54. .policy_name = "tree-prio",
  55. .policy_description = "prio tree policy"
  56. };