execute_all_tasks.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Inria
  4. * Copyright (C) 2012,2013,2015,2017 CNRS
  5. * Copyright (C) 2013,2014,2016 Université de Bordeaux
  6. * Copyright (C) 2013 Thibaut Lambert
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include <starpu.h>
  20. #include <starpu_scheduler.h>
  21. #include <core/jobs.h>
  22. #include "../helper.h"
  23. /*
  24. * All tasks submitted by StarPU should be executed once.
  25. * Applies to: all schedulers.
  26. */
  27. #define NTASKS 8
  28. void dummy(void *buffers[], void *args)
  29. {
  30. (void) buffers;
  31. (void) args;
  32. }
  33. static int
  34. run(struct starpu_sched_policy *p)
  35. {
  36. int ret;
  37. struct starpu_conf conf;
  38. (void) starpu_conf_init(&conf);
  39. conf.sched_policy = p;
  40. ret = starpu_init(&conf);
  41. if (ret == -ENODEV)
  42. exit(STARPU_TEST_SKIPPED);
  43. struct starpu_task *tasks[NTASKS] = { NULL };
  44. struct starpu_codelet cl =
  45. {
  46. .cpu_funcs = {dummy},
  47. .cpu_funcs_name = {"dummy"},
  48. .cuda_funcs = {dummy},
  49. .opencl_funcs = {dummy},
  50. .nbuffers = 0
  51. };
  52. int i;
  53. for (i = 0; i < NTASKS; i++)
  54. {
  55. struct starpu_task *task = starpu_task_create();
  56. tasks[i] = task;
  57. task->cl = &cl;
  58. task->synchronous = 1;
  59. task->destroy = 0;
  60. ret = starpu_task_submit(task);
  61. if (ret != 0)
  62. {
  63. FPRINTF(stderr,"task submission returned %d\n", ret);
  64. return 1;
  65. }
  66. }
  67. starpu_task_wait_for_all();
  68. ret = 0;
  69. for (i = 0; i < NTASKS; i++)
  70. {
  71. struct _starpu_job *j = tasks[i]->starpu_private;
  72. if (j == NULL || j->terminated == 0)
  73. {
  74. FPRINTF(stderr, "Error with policy %s.\n", p->policy_name);
  75. ret = 1;
  76. break;
  77. }
  78. }
  79. for (i = 0; i < NTASKS; i++)
  80. {
  81. starpu_task_destroy(tasks[i]);
  82. }
  83. starpu_shutdown();
  84. return ret;
  85. }
  86. int main(void)
  87. {
  88. struct starpu_sched_policy **policies;
  89. struct starpu_sched_policy **policy;
  90. #ifdef STARPU_HAVE_UNSETENV
  91. unsetenv("STARPU_SCHED");
  92. #endif
  93. policies = starpu_sched_get_predefined_policies();
  94. for(policy=policies ; *policy!=NULL ; policy++)
  95. {
  96. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  97. int ret;
  98. ret = run(*policy);
  99. if (ret == 1)
  100. return EXIT_FAILURE;
  101. }
  102. return EXIT_SUCCESS;
  103. }