user_interaction_implicit.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 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 <stdio.h>
  18. #include <unistd.h>
  19. #include <errno.h>
  20. #include <starpu.h>
  21. #include <stdlib.h>
  22. #include <pthread.h>
  23. #include "../helper.h"
  24. #define NBUFFERS 16
  25. #define NITER 128
  26. struct data
  27. {
  28. unsigned index;
  29. unsigned val;
  30. starpu_data_handle_t handle;
  31. };
  32. struct data buffers[NBUFFERS];
  33. void callback_sync_data(void *arg)
  34. {
  35. struct data *data = (struct data *) arg;
  36. data->val++;
  37. starpu_data_release(data->handle);
  38. }
  39. int main(int argc, char **argv)
  40. {
  41. int ret;
  42. ret = starpu_init(NULL);
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  44. unsigned b;
  45. for (b = 0; b < NBUFFERS; b++)
  46. {
  47. buffers[b].index = b;
  48. starpu_variable_data_register(&buffers[b].handle, 0, (uintptr_t)&buffers[b].val, sizeof(unsigned));
  49. }
  50. unsigned iter;
  51. for (iter = 0; iter < NITER; iter++)
  52. for (b = 0; b < NBUFFERS; b++)
  53. {
  54. ret = starpu_data_acquire_cb(buffers[b].handle, STARPU_RW,
  55. callback_sync_data, &buffers[b]);
  56. STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire_cb");
  57. }
  58. ret = starpu_task_wait_for_all();
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  60. /* do some cleanup */
  61. for (b = 0; b < NBUFFERS; b++)
  62. {
  63. starpu_data_unregister(buffers[b].handle);
  64. /* check result */
  65. if (buffers[b].val != NITER)
  66. {
  67. fprintf(stderr, "buffer[%u] = %u should be %d\n", b, buffers[b].val, NITER);
  68. STARPU_ABORT();
  69. }
  70. }
  71. starpu_shutdown();
  72. return EXIT_SUCCESS;
  73. }