user_interaction_implicit.c 1.7 KB

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