C OpenMP - Enforce default chunk size
In C to parallelize a loop with schedule(static)
would mean that the chunk size is quickly computed as ceil
(loops/threads)
.
For my project I have to iterrate through 9 different chunk sizes, one of which is "default". This is how I did it:
I wrote a perl loop that compiles my program with -DCHUNKSIZE=$c
and in the omp
code I specify schedule(static, CHUNKSIZE)
.
Question: what can I do for default? Chunk size of 0 doesn't work :(
Thanks!
P.S.
I was hoping to avoid having #ifdef ..开发者_运维技巧. #else ... #endif
since I have very many loops that are parallelized
I agree with ejd. As to how to handle it, why not:
#ifdef CHUNKSIZE
#pragma omp parallel for schedule(mode, CHUNKSIZE)
#else
#pragma omp parallel for schedule(mode)
#endif
for ( ; ; ) /* ... */
and then not pass -DCHUNKSIZE
for the default.
You have to leave the chunksize off completely and just specify "schedule(kind)".
#ifdef CHUNKSIZE
#define OPM_FOR(mode) _Pragma("omp parallel for schedule(" #mode ", "CHUNKSIZE")")
#else
#define OMP_FOR(mode) _Pragma("omp parallel for schedule(" #mode ")")
#endif
OMP_FOR(static)
for ( ; ; ) { /* */ }
Basically, Æsahættr's solution with the additional use of the _Pragma() operator (which is in C99, I believe).
精彩评论