CERN Accelerating science

This website is no longer maintained. Its content may be obsolete. Please visit http://home.cern/ for current CERN information.

CERN Accelerating science

C++ and CERN

by Axel Naumann

In 1998, about fifteen years after its invention, C++ became a standard. Not in the sense of a few vendors agreeing on a minimal feature set, but in the sense of the standard for screws, paper and photographic film: a standard governed by the rules of the International Organization for Standardization ISO. It allows for using any compiler (that is "conforming") to compile your code, without having to change it to fit it to a given implementation. In 2011, a new version of this standard was published ("C++11"), and at about the same time, CERN became a member of the committee defining the C++ language standard.

 

But just because you use a screw you (luckily) don't need to discuss the standards applicable for screws. So why did CERN join the standardization process? The reasons can be nicely demonstrated with C++11.

We completely rely on C++: we estimate CERN has approximately 50 million lines of C++ code, to a large extent written by CERN users and employees. We store petabytes of physics data as C++ objects every year. For our physics we "bought in" through time, effort, money, experience, expertise, education. A small change in C++ can lock us into old compilers, because it could break parts of our code; although this is one of the topmost concerns of any language change: "will it break existing code?".

On the other hand we can use our expertise to shape the language. We can for instance say which features we would like to see, or which syntax a new feature should use. Is our expertise relevant? Bjarne Stroustrup said "yes"! We are one of the very few user representatives on the committee amongst a plenitude of compiler and library vendors (e.g. Microsoft, Apple, EDG, Boost, HP) and software companies (e.g. Google, Symantec). Many have experience with education of computer scientists, but not many have experience with keeping a 50MLOC "ship" on course, where coding novices are ideally as productive as coding wizards. With Fermilab likely not actively participating at the meetings anymore, CERN is the only remaining member from High Energy Physics; in fact, as far as I know, from all of natural science.

So where does C++11 come in? Isn't that the "next" standard, and will remain just that for the next 5 or so years? How relevant is "the future of C++" to us? Before C++11 was published, several experiments and PH projects already verified whether their code would compile with the preview of the new standard, which was already available in GCC, and soon after in "clang". So when the new standard was published, most compilers already supported a large part of it. There does not need to be a gap between a new standard and its first use. As a matter of fact, CMS is already compiling its offline code using C++11 (and its draft, "C++0x"), since August 2010! Switching the compiler to C++11-mode requires almost no changes in the source code.

What does C++11 bring? While the previous standard revision, 2003, was a mere "bugfix release", C++11 is almost a new language staying backward compatible with C++ 2003. It makes code much more readable (e.g. range-based loops); it gets rid of workarounds by promoting them to language properties (e.g. deleted constructors); it adds performance improvements through new language constructs (e.g. move semantics); it integrates essential, previously external parts (e.g. hash maps); it treats functions as first-class citizens (e.g. std::function, lambdas) and brings C++ to the multicore world (e.g. std::future). So there are many good reasons to have a look at it. Once you have used it for a while, going back to C++ 2003 will be terrible! To my knowledge, all experiments have verified that their current offline software works with compilers switched to C++11-mode, which would mean that C++11 can be turned on also for non-CMS physicists! Once all experiments have switched to C++11, we (ROOT, Geant4 etc) can finally start using it, too. Wouldn't that be nice!

Where does C++ go from here? What will come after C++11? As with any major release, people have found bugs, even in the C++ standard. There are for instance leftovers from the 2003 version that are now superseded, or inconsistencies that people only noticed once implementing the standard. All these corrections will end up in a new revision, likely 2014, the draft of which already exists.

The next committee meeting, April 15-20, will take place in Bristol. You are invited to come to the computing seminar on April 4 to discuss what CERN's opinion on the proposals should be, to hear how the meetings work, and to ask any question that these lines might have triggered. If you cannot make it then please just contact me at axel@cern.ch.