brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 3dca702 Raw
33 lines · cpp
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include <__algorithm/min.h>10#include <__config>11#include <__pstl/backends/libdispatch.h>12#include <dispatch/dispatch.h>13 14_LIBCPP_BEGIN_NAMESPACE_STD15namespace __pstl::__libdispatch {16 17void __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);19}20 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;28  return partitions;29}30 31} // namespace __pstl::__libdispatch32_LIBCPP_END_NAMESPACE_STD33