RavEngine
Loading...
Searching...
No Matches
parallel_for.h
1
/*
2
Copyright 2018 Google Inc. All Rights Reserved.
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS-IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PARALLEL_FOR_H_
18
#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PARALLEL_FOR_H_
19
20
#include <algorithm>
21
#include <functional>
22
#include <thread>
23
24
namespace
vraudio {
25
26
// Gets the number of hardware threads; always returns more than zero.
27
//
28
// @return Number of hardware threads.
29
inline
unsigned
int
GetNumberOfHardwareThreads() {
30
// According to the standard, hardware_concurrency() may return zero if "this
31
// value is not computable or well defined". In that case, we want to have a
32
// thread count of one (instead of zero).
33
return
std::max(1U, std::thread::hardware_concurrency());
34
}
35
36
// Repeatedly executes |function| multiple times, specified by |num_iterations|.
37
// Different executions of |function| may occur on one of the |num_threads|
38
// threads.
39
//
40
// |function| has a function signature of void(const size_t i), with |i| taking
41
// values in the range [0, |num_iterations|).
42
//
43
// @param num_threads Number of threads to execute |function|.
44
// @param num_iterations Number of iterations for this for loop.
45
// @param function Function to be run. The function should take a single
46
// parameter that is of type const size_t, representing the iteration
47
// index, and no return value.
48
void
ParallelFor(
unsigned
int
num_threads,
size_t
num_iterations,
49
const
std::function<
void
(
const
size_t
)>& function);
50
51
}
// namespace vraudio
52
53
#endif
// RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_PARALLEL_FOR_H_
RavEngine
deps
resonance-audio
resonance_audio
geometrical_acoustics
parallel_for.h
Generated by
1.9.8