prio.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Simon Archipoff
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <unistd.h>
  18. #include <starpu.h>
  19. #include <starpu_scheduler.h>
  20. #include "../helper.h"
  21. /*
  22. * Task1 must be executed before task0, even if task0 is submitted first.
  23. * Applies to : all schedulers.
  24. */
  25. #ifdef STARPU_QUICK_CHECK
  26. #define NTASKS 10
  27. #elif !defined(STARPU_LONG_CHECK)
  28. #define NTASKS 100
  29. #else
  30. #define NTASKS 1000
  31. #endif
  32. void
  33. A(void *buffers[], void *args)
  34. {
  35. (void) buffers;
  36. (void) args;
  37. FPRINTF(stdout,"A");
  38. usleep(1000);
  39. }
  40. void
  41. B(void *buffers[], void *args)
  42. {
  43. (void) buffers;
  44. (void) args;
  45. FPRINTF(stdout,"B");
  46. usleep(1000);
  47. }
  48. static int
  49. run(struct starpu_sched_policy *policy)
  50. {
  51. int ret;
  52. struct starpu_conf conf;
  53. int i;
  54. starpu_conf_init(&conf);
  55. conf.sched_policy = policy;
  56. ret = starpu_init(&conf);
  57. if (ret != 0)
  58. exit(STARPU_TEST_SKIPPED);
  59. starpu_profiling_status_set(1);
  60. struct starpu_codelet clA =
  61. {
  62. .cpu_funcs = {A},
  63. .cpu_funcs_name = {"A"},
  64. .opencl_funcs = {A},
  65. .cuda_funcs = {A},
  66. .nbuffers = 0
  67. };
  68. struct starpu_codelet clB =
  69. {
  70. .cpu_funcs = {B},
  71. .cpu_funcs_name = {"B"},
  72. .opencl_funcs = {B},
  73. .cuda_funcs = {B},
  74. .nbuffers = 0
  75. };
  76. starpu_srand48(0);
  77. for (i = 0; i < NTASKS; i++)
  78. {
  79. struct starpu_task *task = starpu_task_create();
  80. if (((int)(starpu_drand48()*2))%2)
  81. {
  82. task->cl = &clA;
  83. task->priority=STARPU_MIN_PRIO;
  84. }
  85. else
  86. {
  87. task->cl = &clB;
  88. task->priority=STARPU_MAX_PRIO;
  89. }
  90. task->detach=1;
  91. ret = starpu_task_submit(task);
  92. if (ret == -ENODEV) goto enodev;
  93. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  94. }
  95. starpu_task_wait_for_all();
  96. FPRINTF(stdout,"\n");
  97. starpu_shutdown();
  98. return 0;
  99. enodev:
  100. starpu_shutdown();
  101. return -ENODEV;
  102. }
  103. int main(void)
  104. {
  105. struct starpu_sched_policy **policies;
  106. struct starpu_sched_policy **policy;
  107. char *sched = getenv("STARPU_SCHED");
  108. policies = starpu_sched_get_predefined_policies();
  109. for(policy=policies ; *policy!=NULL ; policy++)
  110. {
  111. int ret;
  112. if (sched && strcmp(sched, (*policy)->policy_name))
  113. /* Testing another specific scheduler, no need to run this */
  114. continue;
  115. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  116. ret = run(*policy);
  117. if (ret == -ENODEV)
  118. return STARPU_TEST_SKIPPED;
  119. if (ret == 1)
  120. return EXIT_FAILURE;
  121. }
  122. return EXIT_SUCCESS;
  123. }