prio.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. .fpga_funcs = {A},
  67. .nbuffers = 0
  68. };
  69. struct starpu_codelet clB =
  70. {
  71. .cpu_funcs = {B},
  72. .cpu_funcs_name = {"B"},
  73. .opencl_funcs = {B},
  74. .cuda_funcs = {B},
  75. .fpga_funcs = {B},
  76. .nbuffers = 0
  77. };
  78. starpu_srand48(0);
  79. for (i = 0; i < NTASKS; i++)
  80. {
  81. struct starpu_task *task = starpu_task_create();
  82. if (((int)(starpu_drand48()*2))%2)
  83. {
  84. task->cl = &clA;
  85. task->priority=STARPU_MIN_PRIO;
  86. }
  87. else
  88. {
  89. task->cl = &clB;
  90. task->priority=STARPU_MAX_PRIO;
  91. }
  92. task->detach=1;
  93. ret = starpu_task_submit(task);
  94. if (ret == -ENODEV) goto enodev;
  95. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  96. }
  97. starpu_task_wait_for_all();
  98. FPRINTF(stdout,"\n");
  99. starpu_shutdown();
  100. return 0;
  101. enodev:
  102. starpu_shutdown();
  103. return -ENODEV;
  104. }
  105. int main(void)
  106. {
  107. struct starpu_sched_policy **policies;
  108. struct starpu_sched_policy **policy;
  109. char *sched = getenv("STARPU_SCHED");
  110. policies = starpu_sched_get_predefined_policies();
  111. for(policy=policies ; *policy!=NULL ; policy++)
  112. {
  113. int ret;
  114. if (sched && strcmp(sched, (*policy)->policy_name))
  115. /* Testing another specific scheduler, no need to run this */
  116. continue;
  117. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  118. ret = run(*policy);
  119. if (ret == -ENODEV)
  120. return STARPU_TEST_SKIPPED;
  121. if (ret == 1)
  122. return EXIT_FAILURE;
  123. }
  124. return EXIT_SUCCESS;
  125. }