prio.c 2.6 KB

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