simple_deps.c 3.4 KB

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