user_interaction_implicit.c 2.2 KB

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