simple_deps.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 <unistd.h>
  17. #include <starpu.h>
  18. #include <starpu_profiling.h>
  19. #include "../helper.h"
  20. /*
  21. * Task1 must be executed before task0, even if task0 is submitted first.
  22. * Applies to : all schedulers.
  23. */
  24. static void
  25. dummy(void *buffers[], void *args)
  26. {
  27. (void) buffers;
  28. (void) args;
  29. usleep(1000000);
  30. }
  31. static int
  32. run(struct starpu_sched_policy *policy)
  33. {
  34. int ret;
  35. struct starpu_conf conf;
  36. starpu_conf_init(&conf);
  37. conf.sched_policy = policy;
  38. ret = starpu_init(&conf);
  39. if (ret != 0)
  40. exit(STARPU_TEST_SKIPPED);
  41. starpu_profiling_status_set(1);
  42. struct starpu_codelet cl =
  43. {
  44. .cpu_funcs = {dummy, NULL},
  45. .nbuffers = 0
  46. };
  47. struct starpu_task *task0 = starpu_task_create();
  48. task0->cl = &cl;
  49. task0->destroy = 0;
  50. struct starpu_task *task1 = starpu_task_create();
  51. task1->cl = &cl;
  52. task1->destroy = 0;
  53. starpu_task_declare_deps_array(task0, 1, &task1);
  54. ret = starpu_task_submit(task0);
  55. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  56. ret = starpu_task_submit(task1);
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  58. starpu_task_wait_for_all();
  59. double t1, t2;
  60. t1 = starpu_timing_timespec_to_us(&task1->profiling_info->end_time);
  61. t2 = starpu_timing_timespec_to_us(&task0->profiling_info->start_time);
  62. starpu_task_destroy(task0);
  63. starpu_task_destroy(task1);
  64. starpu_shutdown();
  65. return t1 < t2 ? 0:1;
  66. }
  67. extern struct starpu_sched_policy _starpu_sched_ws_policy;
  68. extern struct starpu_sched_policy _starpu_sched_prio_policy;
  69. extern struct starpu_sched_policy _starpu_sched_random_policy;
  70. extern struct starpu_sched_policy _starpu_sched_dm_policy;
  71. extern struct starpu_sched_policy _starpu_sched_dmda_policy;
  72. extern struct starpu_sched_policy _starpu_sched_dmda_ready_policy;
  73. extern struct starpu_sched_policy _starpu_sched_dmda_sorted_policy;
  74. extern struct starpu_sched_policy _starpu_sched_eager_policy;
  75. extern struct starpu_sched_policy _starpu_sched_parallel_heft_policy;
  76. extern struct starpu_sched_policy _starpu_sched_pgreedy_policy;
  77. extern struct starpu_sched_policy _starpu_sched_heft_policy;
  78. static struct starpu_sched_policy *policies[] =
  79. {
  80. &_starpu_sched_ws_policy,
  81. &_starpu_sched_prio_policy,
  82. &_starpu_sched_dm_policy,
  83. &_starpu_sched_dmda_policy,
  84. &_starpu_sched_heft_policy,
  85. &_starpu_sched_dmda_ready_policy,
  86. &_starpu_sched_dmda_sorted_policy,
  87. &_starpu_sched_random_policy,
  88. &_starpu_sched_eager_policy,
  89. &_starpu_sched_parallel_heft_policy,
  90. &_starpu_sched_pgreedy_policy
  91. };
  92. int
  93. main(void)
  94. {
  95. int i;
  96. int n_policies = sizeof(policies)/sizeof(policies[0]);
  97. for (i = 0; i < n_policies; ++i)
  98. {
  99. struct starpu_sched_policy *policy = policies[i];
  100. FPRINTF(stdout, "Running with policy %s.\n",
  101. policy->policy_name);
  102. int ret;
  103. ret = run(policy);
  104. if (ret == 1)
  105. return EXIT_FAILURE;
  106. }
  107. return EXIT_SUCCESS;
  108. }