reducer_impl.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* reducer_impl.h -*-C++-*-
  2. *
  3. *************************************************************************
  4. *
  5. * @copyright
  6. * Copyright (C) 2009-2013, Intel Corporation
  7. * All rights reserved.
  8. *
  9. * @copyright
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. * * Neither the name of Intel Corporation nor the names of its
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * @copyright
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  30. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  32. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  33. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  35. * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. **************************************************************************/
  38. /**
  39. * @file reducer_impl.h
  40. *
  41. * @brief Functions to implement reducers in the runtime.
  42. */
  43. #ifndef INCLUDED_REDUCER_IMPL_DOT_H
  44. #define INCLUDED_REDUCER_IMPL_DOT_H
  45. #include <cilk/common.h>
  46. #include <internal/abi.h>
  47. #include "rts-common.h"
  48. __CILKRTS_BEGIN_EXTERN_C
  49. /**
  50. * Construct an empty reducer map from the memory pool associated with the
  51. * given worker. This reducer map must be destroyed before the worker's
  52. * associated global context is destroyed.
  53. *
  54. * @param w __cilkrts_worker the cilkred_map is being created for.
  55. *
  56. * @return Pointer to the initialized cilkred_map.
  57. */
  58. COMMON_SYSDEP
  59. cilkred_map *__cilkrts_make_reducer_map(__cilkrts_worker *w);
  60. /**
  61. * Destroy a reducer map. The map must have been allocated from the worker's
  62. * global context and should have been allocated from the same worker.
  63. *
  64. * @param w __cilkrts_worker the cilkred_map was created for.
  65. * @param h The cilkred_map to be deallocated.
  66. */
  67. COMMON_SYSDEP
  68. void __cilkrts_destroy_reducer_map(__cilkrts_worker *w,
  69. cilkred_map *h);
  70. /**
  71. * Set the specified reducer map as the leftmost map if is_leftmost is true,
  72. * otherwise, set it to not be the leftmost map.
  73. *
  74. * @param h The cilkred_map to be modified.
  75. * @param is_leftmost true if the reducer map is leftmost.
  76. */
  77. COMMON_SYSDEP
  78. void __cilkrts_set_leftmost_reducer_map(cilkred_map *h,
  79. int is_leftmost);
  80. /**
  81. * Merge reducer map RIGHT_MAP into LEFT_MAP and return the result of the
  82. * merge. Both maps must be allocated from the global context associated
  83. * with the specified worker. The returned reducer map must be destroyed
  84. * before the worker's associated global context is destroyed.
  85. *
  86. * If two cilkred_maps are specified, one will be destroyed and the other
  87. * one will be returned as the merged cilkred_map.
  88. *
  89. * When reducers can contain nested parallelism, execution can return
  90. * on a different worker than when it started (but still using the
  91. * same stack).
  92. *
  93. * Upon return, *w_ptr stores the pointer to the worker that execution
  94. * returns on.
  95. *
  96. * @param w_ptr Pointer to the currently executing worker.
  97. * @param left_map The left cilkred_map.
  98. * @param right_map The right cilkred_map.
  99. *
  100. * @return pointer to merged cilkred_map.
  101. */
  102. extern
  103. cilkred_map *merge_reducer_maps(__cilkrts_worker **w_ptr,
  104. cilkred_map *left_map,
  105. cilkred_map *right_map);
  106. /**
  107. * Similar to merge_reducer_maps(), except that after merging
  108. * RIGHT_MAP into LEFT_MAP, it repeatedly merges (*w_ptr)->reducer_map
  109. * into LEFT_MAP. This procedure ensures that any new reducers
  110. * created by the reductions themselves also get merged into LEFT_MAP.
  111. */
  112. extern
  113. cilkred_map *repeated_merge_reducer_maps(__cilkrts_worker **w_ptr,
  114. cilkred_map *left_map,
  115. cilkred_map *right_map);
  116. __CILKRTS_END_EXTERN_C
  117. #endif // ! defined(INCLUDED_REDUCER_IMPL_DOT_H)