submit.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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 <sys/time.h>
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <starpu.h>
  21. #include "../helper.h"
  22. static int i = 0, j;
  23. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  24. {
  25. i++;
  26. FPRINTF(stdout, "called third task, i = %d\n", i);
  27. }
  28. static struct starpu_codelet dummy_codelet =
  29. {
  30. .cpu_funcs = {dummy_func, NULL},
  31. .cuda_funcs = {dummy_func, NULL},
  32. .opencl_funcs = {dummy_func, NULL},
  33. .model = NULL,
  34. .nbuffers = 0
  35. };
  36. static void callback(void *arg __attribute__ ((unused)))
  37. {
  38. struct starpu_task *task = starpu_task_create();
  39. task->cl = &dummy_codelet;
  40. task->detach = 1;
  41. if (starpu_task_submit(task) == ENODEV)
  42. exit(STARPU_TEST_SKIPPED);
  43. FPRINTF(stdout, "submitted third task, i = %d\n", i);
  44. }
  45. static struct starpu_codelet callback_submit_codelet =
  46. {
  47. .cpu_funcs = {dummy_func, NULL},
  48. .cuda_funcs = {dummy_func, NULL},
  49. .opencl_funcs = {dummy_func, NULL},
  50. .model = NULL,
  51. .nbuffers = 0
  52. };
  53. static void task_submit_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  54. {
  55. struct starpu_task *task = starpu_task_create();
  56. task->cl = &callback_submit_codelet;
  57. task->callback_func = callback;
  58. task->detach = 1;
  59. if (starpu_task_submit(task) == ENODEV)
  60. exit(STARPU_TEST_SKIPPED);
  61. i++;
  62. FPRINTF(stdout, "submitted second task, i = %d\n", i);
  63. }
  64. static struct starpu_codelet task_submit_codelet =
  65. {
  66. .cpu_funcs = {task_submit_func, NULL},
  67. .cuda_funcs = {task_submit_func, NULL},
  68. .opencl_funcs = {task_submit_func, NULL},
  69. .model = NULL,
  70. .nbuffers = 0
  71. };
  72. int main(int argc, char **argv)
  73. {
  74. int ret;
  75. ret = starpu_init(NULL);
  76. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  77. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  78. struct starpu_task *task = starpu_task_create();
  79. task->cl = &task_submit_codelet;
  80. task->detach = 1;
  81. ret = starpu_task_submit(task);
  82. if (ret == -ENODEV) goto enodev;
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  84. starpu_task_wait_for_all();
  85. j = i;
  86. starpu_shutdown();
  87. return j == 3 ? EXIT_SUCCESS : EXIT_FAILURE;
  88. enodev:
  89. fprintf(stderr, "WARNING: No one can execute this task\n");
  90. /* yes, we do not perform the computation but we did detect that no one
  91. * could perform the kernel, so this is not an error from StarPU */
  92. starpu_shutdown();
  93. return STARPU_TEST_SKIPPED;
  94. }