Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfTaskScheduler.h
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20/*
21 Based on Magnum example
22
23 Original authors — credit is appreciated but not required:
24
25 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 —
26 Vladimír Vondruš <mosra@centrum.cz>
27 2019 — Nghia Truong <nghiatruong.vn@gmail.com>
28
29 This library is free software; you can redistribute it and/or
30 modify it under the terms of the GNU Lesser General Public
31 License as published by the Free Software Foundation; either
32 version 2.1 of the License, or (at your option) any later version.
33
34 This library is distributed in the hope that it will be useful,
35 but WITHOUT ANY WARRANTY; without even the implied warranty of
36 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 Lesser General Public License for more details.
38 */
39
40#ifndef _SOURCE_TFTASKSCHEDULER_H_
41#define _SOURCE_TFTASKSCHEDULER_H_
42
43#ifdef USE_TBB
44#include <tbb/tbb.h>
45#endif
46
47#include "tfThreadPool.h"
48
49
50namespace TissueForge {
51
52
53 template<class IndexType, class Function> void parallel_for(IndexType endIdx, Function&& func) {
54 #ifdef USE_TBB
55 tbb::parallel_for(tbb::blocked_range<IndexType>(IndexType(0), endIdx),
56 [&](const tbb::blocked_range<IndexType>& r) {
57 for(IndexType i = r.begin(), iEnd = r.end(); i < iEnd; ++i) {
58 func(i);
59 }
60 });
61 #else
62 ThreadPool::getUniqueInstance().parallel_for(endIdx, std::forward<Function>(func));
63 #endif
64 }
65
66};
67
68#endif // _SOURCE_TFTASKSCHEDULER_H_
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26