user_interaction_implicit.c 2.3 KB

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