user_interaction_implicit.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 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. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  45. unsigned b;
  46. for (b = 0; b < NBUFFERS; b++)
  47. {
  48. buffers[b].index = b;
  49. starpu_variable_data_register(&buffers[b].handle, 0, (uintptr_t)&buffers[b].val, sizeof(unsigned));
  50. }
  51. unsigned iter;
  52. for (iter = 0; iter < NITER; iter++)
  53. for (b = 0; b < NBUFFERS; b++)
  54. {
  55. ret = starpu_data_acquire_cb(buffers[b].handle, STARPU_RW,
  56. callback_sync_data, &buffers[b]);
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire_cb");
  58. }
  59. ret = starpu_task_wait_for_all();
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  61. /* do some cleanup */
  62. for (b = 0; b < NBUFFERS; b++)
  63. {
  64. starpu_data_unregister(buffers[b].handle);
  65. /* check result */
  66. if (buffers[b].val != NITER)
  67. {
  68. fprintf(stderr, "buffer[%u] = %u should be %d\n", b, buffers[b].val, NITER);
  69. STARPU_ABORT();
  70. }
  71. }
  72. starpu_shutdown();
  73. return EXIT_SUCCESS;
  74. }