tree_random.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_node.h>
  18. #include <starpu_scheduler.h>
  19. /* Random scheduler with a fifo queue for its scheduling window */
  20. static void initialize_random_fifo_center_policy(unsigned sched_ctx_id)
  21. {
  22. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  23. struct starpu_sched_tree *t = starpu_sched_tree_create(sched_ctx_id);
  24. t->root = starpu_sched_node_fifo_create(NULL);
  25. struct starpu_sched_node * random_node = starpu_sched_node_random_create(NULL);
  26. t->root->add_child(t->root, random_node);
  27. starpu_sched_node_add_father(random_node, t->root);
  28. unsigned i;
  29. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  30. {
  31. struct starpu_sched_node * worker_node = starpu_sched_node_worker_get(i);
  32. STARPU_ASSERT(worker_node);
  33. random_node->add_child(random_node, worker_node);
  34. starpu_sched_node_add_father(worker_node, random_node);
  35. }
  36. starpu_sched_tree_update_workers(t);
  37. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  38. }
  39. static void deinitialize_random_fifo_center_policy(unsigned sched_ctx_id)
  40. {
  41. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  42. starpu_sched_tree_destroy(tree);
  43. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  44. }
  45. struct starpu_sched_policy _starpu_sched_tree_random_policy =
  46. {
  47. .init_sched = initialize_random_fifo_center_policy,
  48. .deinit_sched = deinitialize_random_fifo_center_policy,
  49. .add_workers = starpu_sched_tree_add_workers,
  50. .remove_workers = starpu_sched_tree_remove_workers,
  51. .push_task = starpu_sched_tree_push_task,
  52. .pop_task = starpu_sched_tree_pop_task,
  53. .pre_exec_hook = NULL,
  54. .post_exec_hook = NULL,
  55. .pop_every_task = NULL,
  56. .policy_name = "tree-random",
  57. .policy_description = "random tree policy"
  58. };
  59. /* Random scheduler with a priority queue for its scheduling window */
  60. static void initialize_random_prio_center_policy(unsigned sched_ctx_id)
  61. {
  62. starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
  63. struct starpu_sched_tree *t = starpu_sched_tree_create(sched_ctx_id);
  64. t->root = starpu_sched_node_prio_create(NULL);
  65. struct starpu_sched_node * random_node = starpu_sched_node_random_create(NULL);
  66. t->root->add_child(t->root, random_node);
  67. starpu_sched_node_add_father(random_node, t->root);
  68. unsigned i;
  69. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  70. {
  71. struct starpu_sched_node * worker_node = starpu_sched_node_worker_get(i);
  72. STARPU_ASSERT(worker_node);
  73. random_node->add_child(random_node, worker_node);
  74. starpu_sched_node_add_father(worker_node, random_node);
  75. }
  76. starpu_sched_tree_update_workers(t);
  77. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  78. }
  79. static void deinitialize_random_prio_center_policy(unsigned sched_ctx_id)
  80. {
  81. struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  82. starpu_sched_tree_destroy(tree);
  83. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  84. }
  85. struct starpu_sched_policy _starpu_sched_tree_random_prio_policy =
  86. {
  87. .init_sched = initialize_random_prio_center_policy,
  88. .deinit_sched = deinitialize_random_prio_center_policy,
  89. .add_workers = starpu_sched_tree_add_workers,
  90. .remove_workers = starpu_sched_tree_remove_workers,
  91. .push_task = starpu_sched_tree_push_task,
  92. .pop_task = starpu_sched_tree_pop_task,
  93. .pre_exec_hook = NULL,
  94. .post_exec_hook = NULL,
  95. .pop_every_task = NULL,
  96. .policy_name = "tree-random-prio",
  97. .policy_description = "random-prio tree policy"
  98. };