execute_schedule.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014 Université de 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 <stdio.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #include "../helper.h"
  22. #include <common/thread.h>
  23. #ifdef STARPU_QUICK_CHECK
  24. #define K 2
  25. #else
  26. #define K 16
  27. #endif
  28. #define N 64
  29. static unsigned current = 1;
  30. void codelet(STARPU_ATTRIBUTE_UNUSED void *descr[], void *_args)
  31. {
  32. uintptr_t me = (uintptr_t) _args;
  33. STARPU_ASSERT(current == me);
  34. current++;
  35. }
  36. static struct starpu_codelet cl =
  37. {
  38. .cpu_funcs = {codelet},
  39. .cuda_funcs = {codelet},
  40. .opencl_funcs = {codelet},
  41. .nbuffers = 0,
  42. };
  43. int main(int argc, char **argv)
  44. {
  45. int ret;
  46. struct starpu_task *dep_task[N];
  47. ret = starpu_initialize(NULL, &argc, &argv);
  48. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  49. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  50. unsigned n, i, k;
  51. for (k = 0; k < K; k++)
  52. {
  53. for (n = 0; n < N; n++)
  54. {
  55. struct starpu_task *task;
  56. dep_task[n] = starpu_task_create();
  57. dep_task[n]->cl = NULL;
  58. task = starpu_task_create();
  59. task->cl = &cl;
  60. task->execute_on_a_specific_worker = 1;
  61. task->workerid = 0;
  62. task->workerorder = k*N + n+1;
  63. task->cl_arg = (void*) (uintptr_t) (k*N + n+1);
  64. starpu_task_declare_deps_array(task, 1, &dep_task[n]);
  65. ret = starpu_task_submit(task);
  66. if (ret == -ENODEV) goto enodev;
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  68. }
  69. for (n = 0; n < N; n++)
  70. {
  71. i = (int)starpu_drand48()%(N-n);
  72. ret = starpu_task_submit(dep_task[i]);
  73. memmove(&dep_task[i], &dep_task[i+1], (N-i-1)*sizeof(dep_task[i]));
  74. if (ret == -ENODEV) goto enodev;
  75. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  76. }
  77. }
  78. starpu_task_wait_for_all();
  79. starpu_shutdown();
  80. return EXIT_SUCCESS;
  81. enodev:
  82. starpu_shutdown();
  83. fprintf(stderr, "WARNING: No one can execute this task\n");
  84. /* yes, we do not perform the computation but we did detect that no one
  85. * could perform the kernel, so this is not an error from StarPU */
  86. return STARPU_TEST_SKIPPED;
  87. }