Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Executor_OnEach.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 #ifndef GALOIS_RUNTIME_EXECUTOR_ONEACH_H
21 #define GALOIS_RUNTIME_EXECUTOR_ONEACH_H
22 
23 #include "galois/config.h"
24 #include "galois/gIO.h"
29 #include "galois/Threads.h"
30 #include "galois/Timer.h"
31 #include "galois/Traits.h"
32 
33 namespace galois {
34 namespace runtime {
35 
36 namespace internal {
37 
38 template <typename FunctionTy, typename ArgsTy>
39 inline void on_each_impl(FunctionTy&& fn, const ArgsTy& argsTuple) {
40 
41  static_assert(!has_trait<char*, ArgsTy>(), "old loopname");
42  static_assert(!has_trait<char const*, ArgsTy>(), "old loopname");
43 
44  static constexpr bool NEEDS_STATS = has_trait<loopname_tag, ArgsTy>();
45  static constexpr bool MORE_STATS =
46  NEEDS_STATS && has_trait<more_stats_tag, ArgsTy>();
47 
48  const char* const loopname = galois::internal::getLoopName(argsTuple);
49 
50  CondStatTimer<NEEDS_STATS> timer(loopname);
51 
52  PerThreadTimer<MORE_STATS> execTime(loopname, "Execute");
53 
54  const auto numT = getActiveThreads();
55 
56  OperatorReferenceType<decltype(std::forward<FunctionTy>(fn))> fn_ref = fn;
57 
58  auto runFun = [&] {
59  execTime.start();
60 
61  fn_ref(substrate::ThreadPool::getTID(), numT);
62 
63  execTime.stop();
64  };
65 
66  timer.start();
67  substrate::getThreadPool().run(numT, runFun);
68  timer.stop();
69 }
70 
71 } // namespace internal
72 
73 template <typename FunctionTy, typename TupleTy>
74 inline void on_each_gen(FunctionTy&& fn, const TupleTy& tpl) {
75  internal::on_each_impl(std::forward<FunctionTy>(fn), tpl);
76 }
77 
78 } // end namespace runtime
79 } // end namespace galois
80 
81 #endif
ThreadPool & getThreadPool(void)
return a reference to system thread pool
Definition: ThreadPool.cpp:259
void run(unsigned num, Args &&...args)
execute work on all threads a simple wrapper for run
Definition: ThreadPool.h:142
unsigned int getActiveThreads() noexcept
Returns the number of threads in use.
Definition: Threads.cpp:37
const char * loopname
Definition: Executor_ParaMeter.h:145
void on_each_gen(FunctionTy &&fn, const TupleTy &tpl)
Definition: Executor_OnEach.h:74
static unsigned getTID()
Definition: ThreadPool.h:204