dummy_sched.c 3.8 KB

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