106c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 206c3fb27SDimitry Andric // 306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 606c3fb27SDimitry Andric // 706c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 806c3fb27SDimitry Andric 906c3fb27SDimitry Andric #include <__algorithm/min.h> 1006c3fb27SDimitry Andric #include <__config> 11*0fca6ea1SDimitry Andric #include <__pstl/backends/libdispatch.h> 1206c3fb27SDimitry Andric #include <dispatch/dispatch.h> 1306c3fb27SDimitry Andric 1406c3fb27SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 15*0fca6ea1SDimitry Andric namespace __pstl::__libdispatch { 1606c3fb27SDimitry Andric 1706c3fb27SDimitry Andric void __dispatch_apply(size_t chunk_count, void* context, void (*func)(void* context, size_t chunk)) noexcept { 1806c3fb27SDimitry Andric ::dispatch_apply_f(chunk_count, DISPATCH_APPLY_AUTO, context, func); 1906c3fb27SDimitry Andric } 2006c3fb27SDimitry Andric 215f757f3fSDimitry Andric __chunk_partitions __partition_chunks(ptrdiff_t element_count) noexcept { 2206c3fb27SDimitry Andric __chunk_partitions partitions; 235f757f3fSDimitry Andric partitions.__chunk_count_ = std::max<ptrdiff_t>(1, element_count / 256); 2406c3fb27SDimitry Andric partitions.__chunk_size_ = element_count / partitions.__chunk_count_; 255f757f3fSDimitry Andric partitions.__first_chunk_size_ = element_count - (partitions.__chunk_count_ - 1) * partitions.__chunk_size_; 265f757f3fSDimitry Andric if (partitions.__chunk_count_ == 0 && element_count > 0) 275f757f3fSDimitry Andric partitions.__chunk_count_ = 1; 2806c3fb27SDimitry Andric return partitions; 2906c3fb27SDimitry Andric } 3006c3fb27SDimitry Andric 31*0fca6ea1SDimitry Andric } // namespace __pstl::__libdispatch 3206c3fb27SDimitry Andric _LIBCPP_END_NAMESPACE_STD 33