QMCPACK
test_ParallelExecutorSTD.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2019 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include <atomic>
13 #include <thread>
14 #include <functional>
15 
16 #include "catch.hpp"
17 
19 
20 namespace qmcplusplus
21 {
22 void TestTask(const int ip, std::atomic<int>& counter) { ++counter; }
23 
24 TEST_CASE("ParallelExecutor<STD> function case", "[concurrency]")
25 {
26  int num_threads = 8;
28  std::atomic<int> count(0);
29  test_block(num_threads, TestTask, std::ref(count));
30  REQUIRE(count == 8);
31 }
32 
33 TEST_CASE("ParallelExecutor<STD> lambda case", "[concurrency]")
34 {
35  int num_threads = 8;
37  std::atomic<int> count(0);
38  test_block(
39  num_threads, [](int id, std::atomic<int>& my_count) { ++my_count; }, std::ref(count));
40  REQUIRE(count == 8);
41 }
42 
43 TEST_CASE("ParallelExecutor<STD> nested case", "[concurrency]")
44 {
45  int num_threads = 8;
47  std::atomic<int> count(0);
48  test_block(
49  num_threads,
50  [num_threads](int task_id, std::atomic<int>& my_count) {
52  test_block2(num_threads, TestTask, std::ref(my_count));
53  },
54  std::ref(count));
55  REQUIRE(count == 64);
56 }
57 
58 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Abstraction for running concurrent tasks in parallel by an executor executor workers can be OpenMP th...
TEST_CASE("complex_helper", "[type_traits]")
void TestTask(const int ip, std::atomic< int > &counter)
REQUIRE(std::filesystem::exists(filename))