File: parallel_any_of.cpp

package info (click to toggle)
embree 4.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 99,492 kB
  • sloc: cpp: 224,036; xml: 40,944; ansic: 2,731; python: 812; sh: 639; makefile: 228; csh: 42
file content (36 lines) | stat: -rw-r--r-- 1,085 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "../../../external/catch.hpp"
#include "../common/tasking/taskscheduler.h"
#include "../common/algorithms/parallel_any_of.h"

#include <vector>
#include <numeric>
#include <thread>

using namespace embree;

namespace parallel_any_of_unit_tests {

TEST_CASE ("Test parallel_any_of", "[parallel_any_of]")
{
  const size_t num_threads = std::thread::hardware_concurrency();
  TaskScheduler::create(num_threads, true, false);

  std::vector<int> data(1024);
  std::iota(data.begin(), data.end(), 0);

  std::shuffle(data.begin(), data.end(), std::mt19937{7777});

  auto unaryPredicateTrue  = [&](size_t i) -> bool { return data[i] == 512; };
  auto unaryPredicateFalse = [&](size_t i) -> bool { return data[i] == 1048; };

  bool resultUnaryPredicateTrue  = parallel_any_of(size_t(0), data.size(), unaryPredicateTrue);
  bool resultUnaryPredicateFalse = parallel_any_of(size_t(0), data.size(), unaryPredicateFalse);

  REQUIRE(resultUnaryPredicateTrue);
  REQUIRE(!resultUnaryPredicateFalse);
}

}