dummy_sched.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <pthread.h>
  17. #include <starpu.h>
  18. #define NTASKS 32000
  19. struct starpu_task_list sched_list;
  20. static pthread_cond_t sched_cond;
  21. static pthread_mutex_t sched_mutex;
  22. static void init_dummy_sched(struct starpu_machine_topology_s *topology,
  23. struct starpu_sched_policy_s *policy)
  24. {
  25. /* Create a linked-list of tasks and a condition variable to protect it */
  26. starpu_task_list_init(&sched_list);
  27. pthread_mutex_init(&sched_mutex, NULL);
  28. pthread_cond_init(&sched_cond, NULL);
  29. unsigned workerid;
  30. for (workerid = 0; workerid < topology->nworkers; workerid++)
  31. starpu_worker_set_sched_condition(workerid, &sched_cond, &sched_mutex);
  32. fprintf(stderr, "Initialising Dummy scheduler\n");
  33. }
  34. static void deinit_dummy_sched(struct starpu_machine_topology_s *topology,
  35. struct starpu_sched_policy_s *policy)
  36. {
  37. STARPU_ASSERT(starpu_task_list_empty(&sched_list));
  38. pthread_cond_destroy(&sched_cond);
  39. pthread_mutex_destroy(&sched_mutex);
  40. fprintf(stderr, "Destroying Dummy scheduler\n");
  41. }
  42. static int push_task_dummy(struct starpu_task *task)
  43. {
  44. pthread_mutex_lock(&sched_mutex);
  45. starpu_task_list_push_front(&sched_list, task);
  46. pthread_cond_signal(&sched_cond);
  47. pthread_mutex_unlock(&sched_mutex);
  48. }
  49. /* The mutex associated to the calling worker is already taken by StarPU */
  50. static struct starpu_task *pop_task_dummy(void)
  51. {
  52. /* NB: In this simplistic strategy, we assume that all workers are able
  53. * to execute all tasks, otherwise, it would have been necessary to go
  54. * through the entire list until we find a task that is executable from
  55. * the calling worker. So we just take the head of the list and give it
  56. * to the worker. */
  57. return starpu_task_list_pop_back(&sched_list);
  58. }
  59. static struct starpu_sched_policy_s dummy_sched_policy = {
  60. .init_sched = init_dummy_sched,
  61. .deinit_sched = deinit_dummy_sched,
  62. .push_task = push_task_dummy,
  63. .push_prio_task = NULL,
  64. .pop_task = pop_task_dummy,
  65. .post_exec_hook = NULL,
  66. .pop_every_task = NULL,
  67. .policy_name = "dummy",
  68. .policy_description = "dummy scheduling strategy"
  69. };
  70. static struct starpu_conf conf = {
  71. .sched_policy_name = NULL,
  72. .sched_policy = &dummy_sched_policy,
  73. .ncpus = -1,
  74. .ncuda = -1,
  75. .nopencl = -1,
  76. .nspus = -1,
  77. .use_explicit_workers_bindid = 0,
  78. .use_explicit_workers_cuda_gpuid = 0,
  79. .use_explicit_workers_opencl_gpuid = 0,
  80. .calibrate = 0
  81. };
  82. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  83. {
  84. }
  85. static starpu_codelet dummy_codelet =
  86. {
  87. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  88. .cpu_func = dummy_func,
  89. .cuda_func = dummy_func,
  90. .opencl_func = dummy_func,
  91. .model = NULL,
  92. .nbuffers = 0
  93. };
  94. int main(int argc, char **argv)
  95. {
  96. starpu_init(&conf);
  97. unsigned i;
  98. for (i = 0; i < NTASKS; i++)
  99. {
  100. struct starpu_task *task = starpu_task_create();
  101. task->cl = &dummy_codelet;
  102. task->cl_arg = NULL;
  103. starpu_task_submit(task);
  104. }
  105. starpu_task_wait_for_all();
  106. starpu_shutdown();
  107. return 0;
  108. }