user_interaction_implicit.c 1.8 KB

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