Several posts explain that it is best to assign names to OpenMP critical
sections so that their synchronizations do not conflict.
For example, see "critical" an entire function or openMP, atomic vs critical?.
Is it possible to define a macro to create an OpenMP critical section such that it forms a unique name each time the macro is instanced? (Possibly this could use __FILE__
and __LINE__
? However, __FILE__
is a string?)
Something like:
#if defined(_MSC_VER)
#define PRAGMA(...) __pragma(__VA_ARGS__)
#else
#define PRAGMA(...) _Pragma(#__VA_ARGS__) // C++11
#endif
#define BEGIN_LOCK PRAGMA(omp critical (some_incantation_for_a_unique_name))
BEGIN_LOCK { some_code(); }
And, why doesn't OpenMP make this the default behavior? Is there some drawback to this?