simple_deps.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. if (ret == -ENODEV) goto enodev;
  56. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  57. ret = starpu_task_submit(task1);
  58. if (ret == -ENODEV) goto enodev;
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  60. starpu_task_wait_for_all();
  61. double t1, t2;
  62. t1 = starpu_timing_timespec_to_us(&task1->profiling_info->end_time);
  63. t2 = starpu_timing_timespec_to_us(&task0->profiling_info->start_time);
  64. starpu_task_destroy(task0);
  65. starpu_task_destroy(task1);
  66. starpu_shutdown();
  67. return t1 < t2 ? 0:1;
  68. enodev:
  69. starpu_shutdown();
  70. return -ENODEV;
  71. }
  72. extern struct starpu_sched_policy _starpu_sched_ws_policy;
  73. extern struct starpu_sched_policy _starpu_sched_prio_policy;
  74. extern struct starpu_sched_policy _starpu_sched_random_policy;
  75. extern struct starpu_sched_policy _starpu_sched_dm_policy;
  76. extern struct starpu_sched_policy _starpu_sched_dmda_policy;
  77. extern struct starpu_sched_policy _starpu_sched_dmda_ready_policy;
  78. extern struct starpu_sched_policy _starpu_sched_dmda_sorted_policy;
  79. extern struct starpu_sched_policy _starpu_sched_eager_policy;
  80. extern struct starpu_sched_policy _starpu_sched_parallel_heft_policy;
  81. extern struct starpu_sched_policy _starpu_sched_pgreedy_policy;
  82. extern struct starpu_sched_policy _starpu_sched_heft_policy;
  83. static struct starpu_sched_policy *policies[] =
  84. {
  85. &_starpu_sched_ws_policy,
  86. &_starpu_sched_prio_policy,
  87. &_starpu_sched_dm_policy,
  88. &_starpu_sched_dmda_policy,
  89. &_starpu_sched_heft_policy,
  90. &_starpu_sched_dmda_ready_policy,
  91. &_starpu_sched_dmda_sorted_policy,
  92. &_starpu_sched_random_policy,
  93. &_starpu_sched_eager_policy,
  94. &_starpu_sched_parallel_heft_policy,
  95. &_starpu_sched_pgreedy_policy
  96. };
  97. int
  98. main(void)
  99. {
  100. int i;
  101. int n_policies = sizeof(policies)/sizeof(policies[0]);
  102. for (i = 0; i < n_policies; ++i)
  103. {
  104. struct starpu_sched_policy *policy = policies[i];
  105. FPRINTF(stdout, "Running with policy %s.\n",
  106. policy->policy_name);
  107. int ret;
  108. ret = run(policy);
  109. if (ret == -ENODEV)
  110. return STARPU_TEST_SKIPPED;
  111. if (ret == 1)
  112. return EXIT_FAILURE;
  113. }
  114. return EXIT_SUCCESS;
  115. }