开发者

Mixing Boost FOREACH macro and OpenMP parallelization

开发者 https://www.devze.com 2023-01-26 21:46 出处:网络
I currently have a code (in C) with an outer loop that is OpenMP-parallelized (it operates locally on a shared-memory list). I\'m rewriting it in C++, and for many things I found the BOOST_FOREACH mac

I currently have a code (in C) with an outer loop that is OpenMP-parallelized (it operates locally on a shared-memory list). I'm rewriting it in C++, and for many things I found the BOOST_FOREACH macro a very nice syntax as loop con开发者_如何学Pythonstruct for iterating over a list, array, etc.

My question is: is there a way I can both use that syntax and parallelize the loop OpenMP-style?


Copying from the terminal is worth 1 kilowords:

$ g++ a.cpp -I/opt/boost-1.45.0/include -O -fopenmp   
a.cpp: In function ‘int main()’:
a.cpp:12: error: for statement expected before ‘if’


Yes, it should just work. BOOST_FOREACH is just a helper macro for a for loop, so OpenMP should recognize and parallelize that loop.


Why not simply try it, and profile the result?

I would be impressed if OpenMP paralized boost_foreach, as foreach relies heavily on template tricks to deduct the container type. If I were in your position, I'd rewrite the foreach's to use regular for-loops.

0

精彩评论

暂无评论...
验证码 换一张
取 消