prologue.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2013 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 <starpu.h>
  18. #include <sys/time.h>
  19. #include <omp.h>
  20. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  21. starpu_data_handle_t handle;
  22. void cpu_codelet(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  23. {
  24. int *val = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  25. *val += 1;
  26. printf("task executing \n");
  27. }
  28. struct starpu_codelet cl =
  29. {
  30. .modes = { STARPU_RW },
  31. .cpu_funcs = {cpu_codelet, NULL},
  32. .nbuffers = 1,
  33. .name = "callback"
  34. };
  35. void callback_func(void *callback_arg)
  36. {
  37. int ret;
  38. struct starpu_task *task = starpu_task_create();
  39. task->cl = &cl;
  40. task->handles[0] = handle;
  41. ret = starpu_task_submit(task);
  42. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  43. }
  44. void prologue_callback_func(void *callback_arg)
  45. {
  46. double *x = (double*)callback_arg;
  47. printf("x = %lf\n", *x);
  48. }
  49. void pop_prologue_callback_func(void *args)
  50. {
  51. unsigned val = (unsigned) args;
  52. printf("pop_prologue_callback val %d \n", val);
  53. }
  54. int main(int argc, char **argv)
  55. {
  56. int v=40;
  57. int ret;
  58. ret = starpu_init(NULL);
  59. if (ret == -ENODEV)
  60. return 77;
  61. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  62. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&v, sizeof(int));
  63. struct starpu_task *task = starpu_task_create();
  64. task->cl = &cl;
  65. task->prologue_callback_func = callback_func;
  66. task->prologue_callback_arg = NULL;
  67. task->prologue_callback_pop_func = pop_prologue_callback_func;
  68. task->prologue_callback_pop_arg = (void*) 5;
  69. task->handles[0] = handle;
  70. ret = starpu_task_submit(task);
  71. if (ret == -ENODEV) goto enodev;
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  73. double *x = (double*)malloc(sizeof(double));
  74. *x = -999.0;
  75. int ret2 = starpu_task_insert(&cl,
  76. STARPU_RW, handle,
  77. STARPU_PROLOGUE_CALLBACK, prologue_callback_func,
  78. STARPU_PROLOGUE_CALLBACK_ARG, x,
  79. STARPU_PROLOGUE_CALLBACK_POP, pop_prologue_callback_func,
  80. STARPU_PROLOGUE_CALLBACK_POP_ARG, 5,
  81. 0);
  82. starpu_task_wait_for_all();
  83. starpu_data_unregister(handle);
  84. FPRINTF(stderr, "v -> %d\n", v);
  85. free(x);
  86. starpu_shutdown();
  87. return 0;
  88. enodev:
  89. starpu_shutdown();
  90. return 77;
  91. }