prio.c 2.9 KB

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