prio.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013, 2015-2016 Université Bordeaux
  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_scheduler.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. #ifdef STARPU_QUICK_CHECK
  25. #define NTASKS 10
  26. #elif !defined(STARPU_LONG_CHECK)
  27. #define NTASKS 100
  28. #else
  29. #define NTASKS 1000
  30. #endif
  31. void
  32. A(void *buffers[], void *args)
  33. {
  34. (void) buffers;
  35. (void) args;
  36. FPRINTF(stdout,"A");
  37. usleep(1000);
  38. }
  39. void
  40. B(void *buffers[], void *args)
  41. {
  42. (void) buffers;
  43. (void) args;
  44. FPRINTF(stdout,"B");
  45. usleep(1000);
  46. }
  47. static int
  48. run(struct starpu_sched_policy *policy)
  49. {
  50. int ret;
  51. struct starpu_conf conf;
  52. int i;
  53. starpu_conf_init(&conf);
  54. conf.sched_policy = policy;
  55. ret = starpu_init(&conf);
  56. if (ret != 0)
  57. exit(STARPU_TEST_SKIPPED);
  58. starpu_profiling_status_set(1);
  59. struct starpu_codelet clA =
  60. {
  61. .cpu_funcs = {A},
  62. .cpu_funcs_name = {"A"},
  63. .opencl_funcs = {A},
  64. .cuda_funcs = {A},
  65. .nbuffers = 0
  66. };
  67. struct starpu_codelet clB =
  68. {
  69. .cpu_funcs = {B},
  70. .cpu_funcs_name = {"B"},
  71. .opencl_funcs = {B},
  72. .cuda_funcs = {B},
  73. .nbuffers = 0
  74. };
  75. starpu_srand48(0);
  76. for (i = 0; i < NTASKS; i++)
  77. {
  78. struct starpu_task *task = starpu_task_create();
  79. if (((int)(starpu_drand48()*2))%2)
  80. {
  81. task->cl = &clA;
  82. task->priority=STARPU_MIN_PRIO;
  83. }
  84. else
  85. {
  86. task->cl = &clB;
  87. task->priority=STARPU_MAX_PRIO;
  88. }
  89. task->detach=1;
  90. ret = starpu_task_submit(task);
  91. if (ret == -ENODEV) goto enodev;
  92. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  93. }
  94. starpu_task_wait_for_all();
  95. FPRINTF(stdout,"\n");
  96. starpu_shutdown();
  97. return 0;
  98. enodev:
  99. starpu_shutdown();
  100. return -ENODEV;
  101. }
  102. int
  103. main(void)
  104. {
  105. struct starpu_sched_policy **policies;
  106. struct starpu_sched_policy **policy;
  107. #ifdef STARPU_HAVE_UNSETENV
  108. unsetenv("STARPU_SCHED");
  109. #endif
  110. policies = starpu_sched_get_predefined_policies();
  111. for(policy=policies ; *policy!=NULL ; policy++)
  112. {
  113. int ret;
  114. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  115. ret = run(*policy);
  116. if (ret == -ENODEV)
  117. return STARPU_TEST_SKIPPED;
  118. if (ret == 1)
  119. return EXIT_FAILURE;
  120. }
  121. return EXIT_SUCCESS;
  122. }