Skip to content
Snippets Groups Projects
Commit a054c167 authored by Felix Weiglhofer's avatar Felix Weiglhofer
Browse files

algo: Add CBM_PARALLEL_FOR macro.

parent 6f36b307
No related branches found
No related tags found
1 merge request!1350algo: Add CBM_PARALLEL_FOR macro.
Pipeline #24357 passed
......@@ -147,6 +147,7 @@ SpacesInParentheses: false
SpacesInSquareBrackets: false
WhitespaceSensitiveMacros: ['CBM_ENUM_DICT']
StatementMacros: ['CBM_PARALLEL_FOR']
Standard: c++11
......
......@@ -10,6 +10,21 @@
#include <omp.h>
#endif
#define CBM_PRAGMA(...) _Pragma(#__VA_ARGS__)
// OpenMP parallel for
// If OpenMP is not available, this macro expands to nothing
//
// Hiding the pragma in a macro isn't technically necessary, as the compiler will ignore it if OpenMP is not available.
// But it slightly increases readability as it's indented to the same level as the code it applies to.
//
// Accepts the same arguments as the OpenMP parallel for pragma.
#ifdef HAVE_OMP
#define CBM_PARALLEL_FOR(...) CBM_PRAGMA(omp parallel for __VA_ARGS__)
#else
#define CBM_PARALLEL_FOR(...)
#endif
namespace cbm::algo::openmp
{
......
......@@ -10,6 +10,7 @@
#include <xpu/host.h>
#include "compat/Algorithm.h"
#include "compat/OpenMP.h"
#include "log.hpp"
using namespace std;
......@@ -178,7 +179,7 @@ namespace cbm::algo
xpu::push_timer("Unpack");
xpu::t_add_bytes(sizeBytes);
#pragma omp parallel for schedule(dynamic)
CBM_PARALLEL_FOR(schedule(dynamic))
for (size_t i = 0; i < numMs; i++) {
auto result = algos.at(msEqIds[i])(msContent[i], msDesc[i], ts.start_time());
msDigis[i] = std::move(result.first);
......@@ -196,7 +197,7 @@ namespace cbm::algo
xpu::push_timer("Merge");
xpu::t_add_bytes(nDigisTotal * sizeof(Digi));
#pragma omp parallel for schedule(dynamic)
CBM_PARALLEL_FOR(schedule(dynamic))
for (unsigned int i = 0; i < numMs; i++) {
unsigned int offset = 0;
for (unsigned int x = 0; x < i; x++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment