user_interaction_implicit.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011,2013,2014,2016 Université de Bordeaux
  4. * Copyright (C) 2013 Inria
  5. * Copyright (C) 2010-2013,2015,2017 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <errno.h>
  21. #include <starpu.h>
  22. #include <stdlib.h>
  23. #include "../helper.h"
  24. /*
  25. * Test modifying the data in the callback of starpu_data_acquire_cb
  26. */
  27. #ifdef STARPU_QUICK_CHECK
  28. # define NBUFFERS 4
  29. # define NITER 16
  30. #else
  31. # define NBUFFERS 16
  32. # define NITER 128
  33. #endif
  34. struct data
  35. {
  36. unsigned index;
  37. unsigned val;
  38. starpu_data_handle_t handle;
  39. };
  40. struct data buffers[NBUFFERS];
  41. static
  42. void callback_sync_data(void *arg)
  43. {
  44. struct data *data = (struct data *) arg;
  45. data->val++;
  46. starpu_data_release(data->handle);
  47. }
  48. int main(int argc, char **argv)
  49. {
  50. int ret;
  51. ret = starpu_initialize(NULL, &argc, &argv);
  52. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  54. unsigned b;
  55. for (b = 0; b < NBUFFERS; b++)
  56. {
  57. buffers[b].index = b;
  58. starpu_variable_data_register(&buffers[b].handle, STARPU_MAIN_RAM, (uintptr_t)&buffers[b].val, sizeof(unsigned));
  59. }
  60. unsigned iter;
  61. for (iter = 0; iter < NITER; iter++)
  62. {
  63. for (b = 0; b < NBUFFERS; b++)
  64. {
  65. ret = starpu_data_acquire_cb(buffers[b].handle, STARPU_RW,
  66. callback_sync_data, &buffers[b]);
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire_cb");
  68. }
  69. }
  70. ret = starpu_task_wait_for_all();
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  72. /* do some cleanup */
  73. ret = EXIT_SUCCESS;
  74. for (b = 0; b < NBUFFERS; b++)
  75. {
  76. starpu_data_unregister(buffers[b].handle);
  77. /* check result */
  78. if (buffers[b].val != NITER)
  79. {
  80. FPRINTF(stderr, "buffer[%u] = %u should be %d\n", b, buffers[b].val, NITER);
  81. ret = EXIT_FAILURE;
  82. }
  83. }
  84. starpu_shutdown();
  85. return ret;
  86. }