0

This is related to How to disable OMP in a translation unit at the source file?. The patch I am working on has the following due to benchmarking results. It appears we need the ability to turn off OMP on the translation unit:

static const bool CRYPTOPP_RW_USE_OMP = true;
...

ModularArithmetic modp(m_p), modq(m_q);

#pragma omp parallel sections if(CRYPTOPP_RW_USE_OMP)
{
    #pragma omp section
        m_pre_2_9p = modp.Exponentiate(2, (9 * m_p - 11)/8);
    #pragma omp section
        m_pre_2_3q = modq.Exponentiate(2, (3 * m_q - 5)/8);
    #pragma omp section
        m_pre_q_p = modp.Exponentiate(m_q, m_p - 2);
}

The patch also applies to a cross platform library (Linux, Unix, Solaris, BSDs, OS X and Windows), and it supports a lot of older compilers. I need to ensure that I don't break a compile.

Question: how portable is the #pragma omp parallel sections if(CRYPTOPP_RW_USE_OMP)? Will using it break compiles that used to work with just #pragma omp parallel sections?

I tried looking at past OpenMP specifications, like 2.0, but I can't see where its allowed in the grammar (see Appendix C). The closest I could find is the parallel-directive production (line 22), which leads to parallel-clause (line 24) and then unique-parallel-clause.

And looking at documentation for platforms I can't test on, its not clear to me if its available. For example, Microsoft's documentation for Visual Studio 2005 appears to only allow it on a loop.

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885

1 Answers1

3

In the very document you link, page 8, section 2.2 parallel Construct. if is among the available clauses (the first one). It is part of the standard, so portable across all conforming compilers.

In your MSDN link:

if applies to the following directives:

parallel

for (OpenMP)

sections (OpenMP)

  • Oh, I see. For Microsoft, I went by the description of *"Specifies whether a loop should be executed in parallel or in serial."* I'm on a laptop with limited screen real estate, so I did not scroll down the page. So I'm clear, this will be available in all conforming OMP compilers, regardless of the OMP version. Is that correct? – jww Jun 26 '15 at 23:48
  • The document is for OMPv. 2.0, for older versions you must look into the specifications, I do not remember all historic versions by hearth. – Vladimir F Героям слава Jun 26 '15 at 23:50
  • @jww Also, your MSDN link is obsolete. It is even written there that you should follow https://msdn.microsoft.com/en-US/library/5187hzke%28v=vs.140%29.aspx The word *loop* is corrected there. – Vladimir F Героям слава Jun 26 '15 at 23:53
  • Well, its an old link. I landed on the Visual Studio 2013 page of the docs. Then I went back as far as I could using the *Other Versions*. Crypto++ still has VC 5.0 project files, so I can't break the compile going back even earlier than VS 2005. – jww Jun 27 '15 at 00:08
  • 1
    The `if` clause is part of the original OpenMP 1.0 specification for C/C++. It **must** be supported by any existing OpenMP-enabled compiler. The same applies to the combined `parallel sections` directive. – Hristo Iliev Jun 27 '15 at 19:05