Tuesday, February 25, 2014

OpenMP, macros, and #define

Sometimes you need to include directives in macros. The classic example would be putting OpenMP directives into macros. The "obvious" way of doing this is:

#define BARRIER \
#pragma omp barrier

void foo()
{
  BARRIER
}

Which produces the following error:

"test.c", line 6: invalid source character: '#'
"test.c", line 6: undefined symbol: pragma
"test.c", line 6: syntax error before or at: omp

Fortunately C99 introduced the _Pragma mechanism to solve this problem. So the functioning code looks like:

#define BARRIER \
_Pragma("omp barrier")

void foo()
{
  BARRIER
}

1 comment:

  1. The articles printed on our site are have information and leisure purposes. The information proven on this site is correct at the time of the writing. We at GamingZion cannot be held responsible for any loss nor can claim any share from winnings that outcome from gambling activities at the organizations promoted on this website. Jackpot City Canada Casino has been proud since its inception to supply world-class leisure in a secure and secure gaming surroundings. ✅ Reliability — few casinos can boast more 메리트카지노 than twenty years of expertise. It speaks of the boundless reliability and belief of consumers.

    ReplyDelete