2

I have the following code:

const W = (f.IsUnit() ? U : modq.Multiply(m_pre_2_3q, U));

const Integer t = modp.Multiply(modp.Exponentiate(V, 3), eh);
const X = (f.IsUnit() ? t : modp.Multiply(m_pre_2_9p, t));

When converted to OpenMP, the const-ness is lost:

Integer W, X;
#pragma omp parallel sections
{
    #pragma omp section
    {
        W = (f.IsUnit() ? U : modq.Multiply(m_pre_2_3q, U));
    }

    #pragma omp section
    {
        const Integer t = modp.Multiply(modp.Exponentiate(V, 3), eh);
        X = (f.IsUnit() ? t : modp.Multiply(m_pre_2_9p, t));
    }
}

How do I recapture the const-ness on W and X when they appear in parallel sections?

jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    Does deferred construction break openMP? Do you have `std::experimental::optional` or `boost::optional`? – Yakk - Adam Nevraumont Jun 15 '15 at 01:48
  • @Yakk - I think OpenMP is probably OK. But the library uses C++03 (and not C++11 or Boost), so its not available. – jww Jun 15 '15 at 13:28
  • `optional` can be written yourself, deferred construction (esp if on a platform with weak alignment requirements) even easier. Try placement new in to a buffer, and const reference access? I'd be more concerned about create-and-assign than `const` – Yakk - Adam Nevraumont Jun 15 '15 at 13:53
  • Just a quick explanatory note (since OP has enough rep to see deleted answers) - I had posted an answer involving using const_cast, but I deleted it rapidly because I realised it got into undefined behaviour. Ignore it! – DavidW Jun 16 '15 at 09:22
  • @David - forgive my ignorance... How did it get into undefined behavior? – jww Jun 17 '15 at 00:41
  • 1
    @jww - this answer explains it reasonably well I think http://stackoverflow.com/a/357607/4657412. – DavidW Jun 17 '15 at 06:17
  • @Yakk - you might be able to answer this question: [Is there some ninja trick to make a variable constant after its declaration?](http://stackoverflow.com/q/3669315) – jww Jun 17 '15 at 06:29
  • @David - Thanks. I actually got into trouble like that some time ago. But it was a POD, and not a complex type. I had a test harness that had `const byte[]` of 1 character, and cast away const-ness. GCC put it in a register so that the modification to the array did not work and caused a crash. The modification were trivial: I tried flipping a bit with `arr[0] ^= 0x01;` (I was testing authenticated encryption routines). – jww Jun 17 '15 at 06:32

0 Answers0