execute_all_tasks.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 <starpu_profiling.h>
  20. #include "../helper.h"
  21. /*
  22. * All tasks submitted by StarPU should be executed once.
  23. * Applies to: all schedulers.
  24. */
  25. #define NTASKS 2
  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 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. &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(1000000);
  57. }
  58. static int
  59. run(struct starpu_sched_policy *p)
  60. {
  61. int ret;
  62. ret = starpu_init(NULL);
  63. if (ret == -ENODEV)
  64. exit(STARPU_TEST_SKIPPED);
  65. starpu_profiling_status_set(1);
  66. struct starpu_task *tasks[NTASKS] = { NULL };
  67. struct starpu_codelet cl =
  68. {
  69. .cpu_funcs = {dummy, NULL},
  70. .cuda_funcs = {dummy, NULL},
  71. .opencl_funcs = {dummy, NULL},
  72. .nbuffers = 0
  73. };
  74. int i;
  75. for (i = 0; i < NTASKS; i++)
  76. {
  77. struct starpu_task *task = starpu_task_create();
  78. tasks[i] = task;
  79. task->cl = &cl;
  80. task->synchronous = 1;
  81. task->destroy = 0;
  82. ret = starpu_task_submit(task);
  83. if (ret != 0)
  84. return 1;
  85. }
  86. starpu_task_wait_for_all();
  87. for (i = 0; i < NTASKS; i++)
  88. {
  89. struct starpu_task_profiling_info *pi;
  90. double task_len;
  91. pi = tasks[i]->profiling_info;
  92. task_len = starpu_timing_timespec_delay_us(&pi->start_time, &pi->end_time);
  93. if (fabs(task_len - 1e6) > 10000) /* That's 10ms, should be good. */
  94. {
  95. FPRINTF(stderr, "Failed with task length: %fµ\n", task_len);
  96. return 1;
  97. }
  98. starpu_task_destroy(tasks[i]);
  99. }
  100. starpu_shutdown();
  101. return 0;
  102. }
  103. int
  104. main(void)
  105. {
  106. int i;
  107. int n_policies = sizeof(policies)/sizeof(policies[0]);
  108. for (i = 0; i < n_policies; ++i)
  109. {
  110. struct starpu_sched_policy *policy = policies[i];
  111. FPRINTF(stdout, "Running with policy %s.\n",
  112. policy->policy_name);
  113. int ret;
  114. ret = run(policy);
  115. if (ret == 1)
  116. return EXIT_FAILURE;
  117. }
  118. return EXIT_SUCCESS;
  119. }