user_interaction_implicit.c 2.1 KB

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