write_back.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <datawizard/datawizard.h>
  17. void _starpu_write_through_data(starpu_data_handle handle, uint32_t requesting_node,
  18. uint32_t write_through_mask)
  19. {
  20. if ((write_through_mask & ~(1<<requesting_node)) == 0) {
  21. /* nothing will be done ... */
  22. return;
  23. }
  24. while (_starpu_spin_trylock(&handle->header_lock))
  25. _starpu_datawizard_progress(requesting_node, 1);
  26. /* first commit all changes onto the nodes specified by the mask */
  27. uint32_t node;
  28. for (node = 0; node < STARPU_MAXNODES; node++)
  29. {
  30. if (write_through_mask & (1<<node)) {
  31. /* we need to commit the buffer on that node */
  32. if (node != requesting_node)
  33. {
  34. uint32_t handling_node =
  35. _starpu_select_node_to_handle_request(requesting_node, node);
  36. starpu_data_request_t r;
  37. /* check that there is not already a similar
  38. * request that we should reuse */
  39. r = _starpu_search_existing_data_request(handle->per_node[node], STARPU_R);
  40. if (!r) {
  41. /* there was no existing request so we create one now */
  42. r = _starpu_create_data_request(handle, handle->per_node[requesting_node],
  43. handle->per_node[node], handling_node, STARPU_R, 1);
  44. _starpu_post_data_request(r, handling_node);
  45. }
  46. else {
  47. /* if there is already a similar request, it is
  48. * useless to post another one */
  49. _starpu_spin_unlock(&r->lock);
  50. }
  51. }
  52. }
  53. }
  54. _starpu_spin_unlock(&handle->header_lock);
  55. }
  56. void starpu_data_set_wt_mask(starpu_data_handle handle, uint32_t wt_mask)
  57. {
  58. handle->wt_mask = wt_mask;
  59. /* in case the data has some children, set their wt_mask as well */
  60. if (handle->nchildren > 0)
  61. {
  62. unsigned child;
  63. for (child = 0; child < handle->nchildren; child++)
  64. starpu_data_set_wt_mask(&handle->children[child], wt_mask);
  65. }
  66. }