execute_all_tasks.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Thibaut Lambert
  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 <starpu.h>
  18. #include <starpu_scheduler.h>
  19. #include <core/jobs.h>
  20. #include "../helper.h"
  21. /*
  22. * All tasks submitted by StarPU should be executed once.
  23. * Applies to: all schedulers.
  24. */
  25. #define NTASKS 8
  26. void dummy(void *buffers[], void *args)
  27. {
  28. (void) buffers;
  29. (void) args;
  30. }
  31. static int
  32. run(struct starpu_sched_policy *p)
  33. {
  34. int ret;
  35. struct starpu_conf conf;
  36. (void) starpu_conf_init(&conf);
  37. conf.sched_policy = p;
  38. ret = starpu_init(&conf);
  39. if (ret == -ENODEV)
  40. exit(STARPU_TEST_SKIPPED);
  41. struct starpu_task *tasks[NTASKS] = { NULL };
  42. struct starpu_codelet cl =
  43. {
  44. .cpu_funcs = {dummy},
  45. .cpu_funcs_name = {"dummy"},
  46. .cuda_funcs = {dummy},
  47. .opencl_funcs = {dummy},
  48. .nbuffers = 0
  49. };
  50. int i;
  51. for (i = 0; i < NTASKS; i++)
  52. {
  53. struct starpu_task *task = starpu_task_create();
  54. tasks[i] = task;
  55. task->cl = &cl;
  56. task->synchronous = 1;
  57. task->destroy = 0;
  58. ret = starpu_task_submit(task);
  59. if (ret != 0)
  60. {
  61. FPRINTF(stderr,"task submission returned %d\n", ret);
  62. return 1;
  63. }
  64. }
  65. starpu_task_wait_for_all();
  66. ret = 0;
  67. for (i = 0; i < NTASKS; i++)
  68. {
  69. struct _starpu_job *j = tasks[i]->starpu_private;
  70. if (j == NULL || j->terminated == 0)
  71. {
  72. FPRINTF(stderr, "Error with policy %s.\n", p->policy_name);
  73. ret = 1;
  74. break;
  75. }
  76. }
  77. for (i = 0; i < NTASKS; i++)
  78. {
  79. starpu_task_destroy(tasks[i]);
  80. }
  81. starpu_shutdown();
  82. return ret;
  83. }
  84. int main(void)
  85. {
  86. struct starpu_sched_policy **policies;
  87. struct starpu_sched_policy **policy;
  88. char *sched = getenv("STARPU_SCHED");
  89. policies = starpu_sched_get_predefined_policies();
  90. for(policy=policies ; *policy!=NULL ; policy++)
  91. {
  92. if (sched && strcmp(sched, (*policy)->policy_name))
  93. /* Testing another specific scheduler, no need to run this */
  94. continue;
  95. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  96. int ret;
  97. ret = run(*policy);
  98. if (ret == 1)
  99. return EXIT_FAILURE;
  100. }
  101. return EXIT_SUCCESS;
  102. }