execute_all_tasks.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 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.h>
  17. #include <core/jobs.h>
  18. #include "../helper.h"
  19. /*
  20. * All tasks submitted by StarPU should be executed once.
  21. * Applies to: all schedulers.
  22. */
  23. #define NTASKS 8
  24. extern struct starpu_sched_policy _starpu_sched_ws_policy;
  25. extern struct starpu_sched_policy _starpu_sched_prio_policy;
  26. extern struct starpu_sched_policy _starpu_sched_random_policy;
  27. extern struct starpu_sched_policy _starpu_sched_dm_policy;
  28. extern struct starpu_sched_policy _starpu_sched_dmda_policy;
  29. extern struct starpu_sched_policy _starpu_sched_dmda_ready_policy;
  30. extern struct starpu_sched_policy _starpu_sched_dmda_sorted_policy;
  31. extern struct starpu_sched_policy _starpu_sched_eager_policy;
  32. extern struct starpu_sched_policy _starpu_sched_parallel_heft_policy;
  33. extern struct starpu_sched_policy _starpu_sched_pgreedy_policy;
  34. static struct starpu_sched_policy *policies[] =
  35. {
  36. &_starpu_sched_ws_policy,
  37. &_starpu_sched_prio_policy,
  38. &_starpu_sched_dm_policy,
  39. &_starpu_sched_dmda_policy,
  40. &_starpu_sched_dmda_ready_policy,
  41. &_starpu_sched_dmda_sorted_policy,
  42. &_starpu_sched_random_policy,
  43. &_starpu_sched_eager_policy,
  44. &_starpu_sched_parallel_heft_policy,
  45. &_starpu_sched_pgreedy_policy
  46. };
  47. static void
  48. dummy(void *buffers[], void *args)
  49. {
  50. (void) buffers;
  51. (void) args;
  52. }
  53. static int
  54. run(struct starpu_sched_policy *p)
  55. {
  56. int ret;
  57. struct starpu_conf conf;
  58. (void) starpu_conf_init(&conf);
  59. conf.sched_policy = p;
  60. ret = starpu_init(&conf);
  61. if (ret == -ENODEV)
  62. exit(STARPU_TEST_SKIPPED);
  63. struct starpu_task *tasks[NTASKS] = { NULL };
  64. struct starpu_codelet cl =
  65. {
  66. .cpu_funcs = {dummy, NULL},
  67. .cuda_funcs = {dummy, NULL},
  68. .opencl_funcs = {dummy, NULL},
  69. .nbuffers = 0
  70. };
  71. int i;
  72. for (i = 0; i < NTASKS; i++)
  73. {
  74. struct starpu_task *task = starpu_task_create();
  75. tasks[i] = task;
  76. task->cl = &cl;
  77. task->synchronous = 1;
  78. task->destroy = 0;
  79. ret = starpu_task_submit(task);
  80. if (ret != 0)
  81. return 1;
  82. }
  83. starpu_task_wait_for_all();
  84. ret = 0;
  85. for (i = 0; i < NTASKS; i++)
  86. {
  87. struct _starpu_job *j = tasks[i]->starpu_private;
  88. if (j == NULL || j->terminated == 0)
  89. {
  90. ret = 1;
  91. break;
  92. }
  93. }
  94. for (i = 0; i < NTASKS; i++)
  95. {
  96. starpu_task_destroy(tasks[i]);
  97. }
  98. starpu_shutdown();
  99. return ret;
  100. }
  101. int
  102. main(void)
  103. {
  104. int i;
  105. int n_policies = sizeof(policies)/sizeof(policies[0]);
  106. for (i = 0; i < n_policies; ++i)
  107. {
  108. struct starpu_sched_policy *policy = policies[i];
  109. FPRINTF(stdout, "Running with policy %s.\n",
  110. policy->policy_name);
  111. int ret;
  112. ret = run(policy);
  113. if (ret == 1)
  114. return EXIT_FAILURE;
  115. }
  116. return EXIT_SUCCESS;
  117. }