1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include <__algorithm/min.h>
11 #include <__pstl/backends/libdispatch.h>
12 #include <dispatch/dispatch.h>
14 _LIBCPP_BEGIN_NAMESPACE_STD
15 namespace __pstl::__libdispatch
{
17 void __dispatch_apply(size_t chunk_count
, void* context
, void (*func
)(void* context
, size_t chunk
)) noexcept
{
18 ::dispatch_apply_f(chunk_count
, DISPATCH_APPLY_AUTO
, context
, func
);
21 __chunk_partitions
__partition_chunks(ptrdiff_t element_count
) noexcept
{
22 __chunk_partitions partitions
;
23 partitions
.__chunk_count_
= std::max
<ptrdiff_t>(1, element_count
/ 256);
24 partitions
.__chunk_size_
= element_count
/ partitions
.__chunk_count_
;
25 partitions
.__first_chunk_size_
= element_count
- (partitions
.__chunk_count_
- 1) * partitions
.__chunk_size_
;
26 if (partitions
.__chunk_count_
== 0 && element_count
> 0)
27 partitions
.__chunk_count_
= 1;
31 } // namespace __pstl::__libdispatch
32 _LIBCPP_END_NAMESPACE_STD