[Openmp-dev] Understanding threadprivate support for C++

Simone Atzeni via Openmp-dev openmp-dev at lists.llvm.org
Thu Sep 13 22:20:20 PDT 2018


Hi all,

I am having some trouble understanding all the possible scenarios of the threadprivate construct with C++ object.
I have the following example(full example attached):

myclass x;
#pragma omp threadprivate (x)

....

#pragma omp parallel
    {
        int myid = omp_get_thread_num();
        x.add(myid);
    }

#pragma omp parallel
    {
        printf("%d\n", x.get());
    }

In this example I understand that "x" will be threadprivate to each thread and its default constructor will be called when entering the first parallel region. In this case I am initializing an int (within the object) to 0 with the default constructor, then the method "add(myid)" will add the value of the thread id to this int.In the second parallel region each thread will basically print the value of it's own thread id.
Another situation is when I put the "copyin(x)" clause in the first parallel construct. In that case the copy assignment operator will be called and the threadprivate version of x will be initialized to whatever value has the global instance of x.
If what I said is correct, what I don't understand are the cases when the copy constructor and the "constructor accepting argument" would be called, what are possible examples? Also, what are examples with a vector (meaning the case that would call __kmpc_threadprivate_register_vec)?

Thank you.
Simone


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20180914/b35cd32c/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: threadprivate_defaultc.cpp
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20180914/b35cd32c/attachment.ksh>


More information about the Openmp-dev mailing list