feat(linear-static-3d-euler-beam): step 17 - parallel-for-tbb
This commit is contained in:
@@ -3,6 +3,7 @@ add_library(
|
||||
STATIC
|
||||
analysis/analysis_model.cpp
|
||||
analysis/analysis_state.cpp
|
||||
assembly/parallel_for.cpp
|
||||
build_info.cpp
|
||||
core/diagnostic.cpp
|
||||
core/status.cpp
|
||||
@@ -25,6 +26,7 @@ target_link_libraries(
|
||||
fesa_solver
|
||||
PRIVATE
|
||||
Fesa::MKL
|
||||
Fesa::TBB
|
||||
)
|
||||
|
||||
# Product warnings are strict without imposing FESA policy on external targets.
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "fesa/assembly/parallel_for.hpp"
|
||||
|
||||
#include <oneapi/tbb/parallel_for.h>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
void SerialParallelFor::execute(
|
||||
std::size_t count,
|
||||
const std::function<void(std::size_t)>& body) const {
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
body(index);
|
||||
}
|
||||
}
|
||||
|
||||
void TbbParallelFor::execute(
|
||||
std::size_t count,
|
||||
const std::function<void(std::size_t)>& body) const {
|
||||
if (count == 0U) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use oneTBB's caller-scoped scheduler policy. This adapter does not set
|
||||
// process-wide concurrency or override the later MKL/TBB oversubscription
|
||||
// policy. A body exception cancels sibling tasks and is rethrown; work
|
||||
// already running during cancellation may still finish its indexed slot.
|
||||
oneapi::tbb::parallel_for(
|
||||
std::size_t{0}, count, [&body](std::size_t index) { body(index); });
|
||||
}
|
||||
|
||||
} // namespace fesa
|
||||
Reference in New Issue
Block a user