execute_all_tasks.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <math.h>
  17. #include <unistd.h>
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * All tasks submitted by StarPU should be executed once.
  22. * Applies to: all schedulers.
  23. */
  24. #define NTASKS 8
  25. #define TASK_DURATION 1e6 /* In microseconds */
  26. extern struct starpu_sched_policy _starpu_sched_ws_policy;
  27. extern struct starpu_sched_policy _starpu_sched_prio_policy;
  28. extern struct starpu_sched_policy _starpu_sched_random_policy;
  29. extern struct starpu_sched_policy _starpu_sched_dm_policy;
  30. extern struct starpu_sched_policy _starpu_sched_dmda_policy;
  31. extern struct starpu_sched_policy _starpu_sched_dmda_ready_policy;
  32. extern struct starpu_sched_policy _starpu_sched_dmda_sorted_policy;
  33. extern struct starpu_sched_policy _starpu_sched_eager_policy;
  34. extern struct starpu_sched_policy _starpu_sched_parallel_heft_policy;
  35. extern struct starpu_sched_policy _starpu_sched_pgreedy_policy;
  36. extern struct starpu_sched_policy _starpu_sched_heft_policy;
  37. static struct starpu_sched_policy *policies[] =
  38. {
  39. &_starpu_sched_ws_policy,
  40. &_starpu_sched_prio_policy,
  41. &_starpu_sched_dm_policy,
  42. &_starpu_sched_dmda_policy,
  43. &_starpu_sched_heft_policy,
  44. &_starpu_sched_dmda_ready_policy,
  45. &_starpu_sched_dmda_sorted_policy,
  46. &_starpu_sched_random_policy,
  47. &_starpu_sched_eager_policy,
  48. &_starpu_sched_parallel_heft_policy,
  49. &_starpu_sched_pgreedy_policy
  50. };
  51. static void
  52. dummy(void *buffers[], void *args)
  53. {
  54. (void) buffers;
  55. (void) args;
  56. usleep(TASK_DURATION);
  57. }
  58. static int
  59. run(struct starpu_sched_policy *p)
  60. {
  61. int ret;
  62. struct starpu_conf conf;
  63. (void) starpu_conf_init(&conf);
  64. conf.sched_policy = p;
  65. ret = starpu_init(&conf);
  66. if (ret == -ENODEV)
  67. exit(STARPU_TEST_SKIPPED);
  68. starpu_profiling_status_set(1);
  69. struct starpu_task *tasks[NTASKS] = { NULL };
  70. struct starpu_codelet cl =
  71. {
  72. .cpu_funcs = {dummy, NULL},
  73. .cuda_funcs = {dummy, NULL},
  74. .opencl_funcs = {dummy, NULL},
  75. .nbuffers = 0
  76. };
  77. int i;
  78. for (i = 0; i < NTASKS; i++)
  79. {
  80. struct starpu_task *task = starpu_task_create();
  81. tasks[i] = task;
  82. task->cl = &cl;
  83. task->synchronous = 1;
  84. task->destroy = 0;
  85. ret = starpu_task_submit(task);
  86. if (ret != 0)
  87. return 1;
  88. }
  89. starpu_task_wait_for_all();
  90. for (i = 0; i < NTASKS; i++)
  91. {
  92. struct starpu_task_profiling_info *pi;
  93. double task_len;
  94. pi = tasks[i]->profiling_info;
  95. task_len = starpu_timing_timespec_delay_us(&pi->start_time, &pi->end_time);
  96. if (task_len < TASK_DURATION/2)
  97. {
  98. char name[48];
  99. starpu_worker_get_name(pi->workerid, name, 48);
  100. FPRINTF(stderr, "Task %d, executed by %s, lasted %fµs\n",
  101. i, name, task_len);
  102. return 1;
  103. }
  104. starpu_task_destroy(tasks[i]);
  105. }
  106. starpu_shutdown();
  107. return 0;
  108. }
  109. int
  110. main(void)
  111. {
  112. int i;
  113. int n_policies = sizeof(policies)/sizeof(policies[0]);
  114. for (i = 0; i < n_policies; ++i)
  115. {
  116. struct starpu_sched_policy *policy = policies[i];
  117. FPRINTF(stdout, "Running with policy %s.\n",
  118. policy->policy_name);
  119. int ret;
  120. ret = run(policy);
  121. if (ret == 1)
  122. return EXIT_FAILURE;
  123. }
  124. return EXIT_SUCCESS;
  125. }