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-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <algorithm> |
10 | |
11 | // REQUIRES: libcpp-pstl-backend-libdispatch |
12 | |
13 | // __chunk_partitions __partition_chunks(ptrdiff_t); |
14 | |
15 | #include <__pstl/backends/libdispatch.h> |
16 | #include <cassert> |
17 | #include <cstddef> |
18 | |
19 | int main(int, char**) { |
20 | { |
21 | auto chunks = std::__pstl::__libdispatch::__partition_chunks(0); |
22 | assert(chunks.__chunk_count_ == 1); |
23 | assert(chunks.__first_chunk_size_ == 0); |
24 | assert(chunks.__chunk_size_ == 0); |
25 | } |
26 | |
27 | { |
28 | auto chunks = std::__pstl::__libdispatch::__partition_chunks(1); |
29 | assert(chunks.__chunk_count_ == 1); |
30 | assert(chunks.__first_chunk_size_ == 1); |
31 | assert(chunks.__chunk_size_ == 1); |
32 | } |
33 | |
34 | for (std::ptrdiff_t i = 2; i != 2ll << 20; ++i) { |
35 | auto chunks = std::__pstl::__libdispatch::__partition_chunks(i); |
36 | assert(chunks.__chunk_count_ >= 1); |
37 | assert(chunks.__chunk_count_ <= i); |
38 | assert((chunks.__chunk_count_ - 1) * chunks.__chunk_size_ + chunks.__first_chunk_size_ == i); |
39 | } |
40 | return 0; |
41 | } |
42 | |