C/C++ and Fortran

 View Only

Questions on C/C++ volatile from SC08 Tutorial S08: A Hands-on Introduction to OpenMP

By Archive User posted Mon November 17, 2008 01:35 PM


Originally posted by: Michael_Wong

On Sunday, I attended the OpenMP Tutorial hosted by some of my colleagues from the OpenMP committee, Tim Mattson and Larry Meadows. It was an excellent tutorial, full of features and pointing out the behavioral differences between OpenMP 2.5 and 3.0. Tim has been doing this tutorial for almost 20 years and Larry, as the OpenMP CEO has been involved in this for the same amount of time.

I must point out that IBM xl C/C++ 10.1 compiler for AIX and Linux both have support for OpenMP 3.0, in addiiton to the compilers mentioned during the tutorial. In fact, this compiler was one of the first to have support for OpenMP 3.0 in the industry since the ratification of the specification in May, 2008.


You can get a trial version from the link above.

There were a few C++ specific questions. During the discussion on OpenMP memory model, one questions involves how volatile in C/C++ is used in multithreaded program.

The C++ 0x Standard will clarify that the volatile keyword continues to have nothing to do with multithreading. It merely indicates that something from the environment may change the value. The role of an atomic variable will be used to indicate that another thread may change the value of this variable. It is possible to say that a variable is an atomic volatile to indicate that something from the environment AND another thread may change the value. The C standard, when it supports concurrency in C1x will likely adapt the same meaning.

So in short, C++ Volatile !=Jave volatile and C++ Volatile!= C++ atomic. During C++0x concurrency deliberations, we discussed at length and felt that there is too much history and presumed meanings involved with volatile. In fact, it may even have different meanings varying from compilers to platforms. So it was felt wiser to leave it alone, allowing implementers to retain whatever meaning they are used to, and adapt a new way of naming truly atomic types.

I hope this helps to answer one of the question regarding the role of volatile.

There was another question about how OpenMP 3.0 changed the role of what constructor (default, copy, assignment) is called by each of the private/threadprivate/first/lastprivate variable. Tim was right that we worked very hard to clarify this aspect, but the rules while somewhat intuitive is still fairly tedious to enumerate, given the many ways that C++ does initialization. I will clarify that in a subsequent post.