user_interaction_implicit.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013 CNRS
  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 "../helper.h"
  23. /*
  24. * Test modifying the data in the callback of starpu_data_acquire_cb
  25. */
  26. #ifdef STARPU_QUICK_CHECK
  27. # define NBUFFERS 4
  28. # define NITER 16
  29. #else
  30. # define NBUFFERS 16
  31. # define NITER 128
  32. #endif
  33. struct data
  34. {
  35. unsigned index;
  36. unsigned val;
  37. starpu_data_handle_t handle;
  38. };
  39. struct data buffers[NBUFFERS];
  40. static
  41. void callback_sync_data(void *arg)
  42. {
  43. struct data *data = (struct data *) arg;
  44. data->val++;
  45. starpu_data_release(data->handle);
  46. }
  47. int main(int argc, char **argv)
  48. {
  49. int ret;
  50. ret = starpu_initialize(NULL, &argc, &argv);
  51. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  53. unsigned b;
  54. for (b = 0; b < NBUFFERS; b++)
  55. {
  56. buffers[b].index = b;
  57. starpu_variable_data_register(&buffers[b].handle, STARPU_MAIN_RAM, (uintptr_t)&buffers[b].val, sizeof(unsigned));
  58. }
  59. unsigned iter;
  60. for (iter = 0; iter < NITER; iter++)
  61. {
  62. for (b = 0; b < NBUFFERS; b++)
  63. {
  64. ret = starpu_data_acquire_cb(buffers[b].handle, STARPU_RW,
  65. callback_sync_data, &buffers[b]);
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire_cb");
  67. }
  68. }
  69. ret = starpu_task_wait_for_all();
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  71. /* do some cleanup */
  72. ret = EXIT_SUCCESS;
  73. for (b = 0; b < NBUFFERS; b++)
  74. {
  75. starpu_data_unregister(buffers[b].handle);
  76. /* check result */
  77. if (buffers[b].val != NITER)
  78. {
  79. FPRINTF(stderr, "buffer[%u] = %u should be %d\n", b, buffers[b].val, NITER);
  80. ret = EXIT_FAILURE;
  81. }
  82. }
  83. starpu_shutdown();
  84. return ret;
  85. }