File: test_parallel_foreach.cpp

package info (click to toggle)
rkcommon 1.14.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,304 kB
  • sloc: cpp: 33,504; sh: 31; makefile: 13
file content (28 lines) | stat: -rw-r--r-- 619 bytes parent folder | download | duplicates (2)
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
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "../catch.hpp"

#include "rkcommon/tasking/parallel_foreach.h"

#include <algorithm>
#include <vector>

using rkcommon::tasking::parallel_foreach;

TEST_CASE("parallel_foreach", "[parallel_foreach]")
{
  const size_t N_ELEMENTS = size_t(1e8);

  const int bad_value  = 0;
  const int good_value = 1;

  std::vector<int> v(N_ELEMENTS);
  std::fill(v.begin(), v.end(), bad_value);

  parallel_foreach(v, [&](int &value) { value = good_value; });

  auto found = std::find(v.begin(), v.end(), bad_value);

  REQUIRE(found == v.end());
}