Download presentation
Presentation is loading. Please wait.
Published byDoreen Page Modified over 9 years ago
1
Andrea Valassi & Alejandro Álvarez IT-SDC White Area lecture 16 th April 2014 C++11 in practice Implications around Boost, ROOT, CORAL, COOL…
2
16 th April 2014A. Valassi and A. Álvarez – C++11 White Area Lecture2 Foreword C++11 is a new language in two complementary ways 1. It introduces radically new concepts and syntaxes (e.g. move semantics) 2. It provides a large number of new standard library classes The first part of this white area lecture was mainly about new concepts And was already very dense! The second part of this lecture will be mainly about the new standard library And release management when adding C++11 to existing software Jacek’s course focuses mainly on new concepts From the standard library, it covers (almost exclusively) smart pointers It does not cover the new C++11 standard library classes for concurrent programming (some of which will only be very briefly mentioned here)
3
16 th April 2014A. Valassi and A. Álvarez – C++11 White Area Lecture3 Outline Adding C++11 to large inter-dependent software projects Step 1: building the software with c++11 enabled Step 2: using c++11 extensions in the software The LCG Application Area “software stack” example C++11 and Boost What is Boost and why it has been so useful C++11 in CORAL and COOL Replace Boost by C++11 in CORAL and COOL Issues with Boost in the COOL API in the port to ROOT6 Eventually get rid of Boost also in the internal implementation List of C++11 classes we will be using to replace those from Boost
4
16 th April 2014A. Valassi and A. Álvarez – C++11 White Area Lecture4 Adding C++11 to existing software There are two logically separate steps involved It is easier to take them one after the other (but can also do both in one go) Step 1 – enable C++11 in the builds of ALL software packages involved Compile code with -std=c++11 This is a prerequisite for using c++11 extensions in the code Compiling ALL packages with this option (or without it) is the safest choice “The C++98 language is ABI-compatible with the C++11 language, but several places in the library break compatibility. This makes it dangerous to link C++98 objects with C++11 objects.” [http://gcc.gnu.org/wiki/Cxx11AbiCompatibility]http://gcc.gnu.org/wiki/Cxx11AbiCompatibility This is true even if none of your packages use any c++11 extensions! See the recent discussion about c++11-compatible Grid client builds Step 2 – start using C++11 extensions at leisure! Provided there are no other incompatibilities (see next slide on ROOT5)… And provided the compiler offers good C++11 support (gcc or clang – avoid icc...) NB: There is no coming back (unless you use #ifdef’s and/or branches)
5
16 th April 2014A. Valassi and A. Álvarez – C++11 White Area Lecture5 Example: adding C++11 to the LCG AA stack Step 1 – enable C++11 in the builds of ALL software packages involved Convention: disable c++11 until gcc46, enable c++11 as of gcc47 (and clang/icc) The same release, e.g. LCGCMT_66, can have builds without (gcc46) and with (gcc48) c++11 All external packages are consistently rebuilt using the same build option We waited for compilers with good enough c++11 support – and we use non-native compilers! Step 2 – start using C++11 extensions at leisure? Not yet: only in ROOT6-based stacks (ROOT5 does not support c++11) Many #ifdef’s in CORAL/COOL code (ROOT5/ROOT6, CORAL2/CORAL3, c++11 compiler option?) -std=c++11 means “#if defined __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L” CORAL ROOT COOL PyCool PyROOT “Externals” (Boost, SQLite…) LHC exp. sw (Gaudi, Athena…) LCGCMT release LCG Application Area sw: CORAL & COOL are used by ATLAS and LHCb through “LCGCMT” configurations (built centrally by PH-SFT)
6
16 th April 2014A. Valassi and A. Álvarez – C++11 White Area Lecture6 Before C++11, we have been using Boost! What is Boost? [http://www.boost.org]http://www.boost.org “Boost provides free peer-reviewed portable C++ source libraries.” The keyword here is portable – use the same code on Linux, Mac, Windows… “We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non- commercial use.” This is software we can use freely in our context without paying a license… “We aim to establish ‘existing practice’ and provide reference implementations so that Boost libraries are suitable for eventual standardization. Ten Boost libraries are included in the C++ Standards Committee's Library Technical Report (TR1) and in the new C++11 Standard. C++11 also includes several more Boost libraries in addition to those from TR1. More Boost libraries are proposed for TR2.” Essentially, Boost was born as a working prototype for C++11!... Boost was there well before C++11: for instance, boost::shared_ptr is used in COOL since 2004
7
16 th April 2014A. Valassi and A. Álvarez – C++11 White Area Lecture7 Boost C++11 in CORAL & COOL – why? Replacing Boost by C++11 in the COOL and CORAL API was proposed and is being implemented in the context of the port of PyCool to ROOT6 Technicality: the old version of clang JIT used in the current ROOT6 beta does not support inline ASM (assembler) – this will only be supported by the new “MCJIT” (end 2014?) PyCool is implemented in ROOT6 by feeding COOL public API headers to clang JIT, extracting the relevant “C++ reflection” information and exposing it in Python COOL public API headers include Boost headers with inline ASM… Moving the COOL API to C++11 was necessary to test PyCool with ROOT6 beta Moving the CORAL API too (used by the COOL API) to C++11 is also ongoing Well, but… replacing Boost by c++11 more generally is not a bad idea! More modern code – more maintainable and easier to write and read Removing dependency on a given Boost version may ease release management Will also try to replace Boost by C++11 throughout CORAL and COOL internals That said, my guess is that Boost will continue to do well and be very useful to many projects in the future… “Window of opportunity” – the move to ROOT6 will be a major transition Seize the moment and include this bunch of disruptive changes in the same release
8
16 th April 2014A. Valassi and A. Álvarez – C++11 White Area Lecture8 #include Boost C++11 in CORAL & COOL – how? Algorithms C++11 – lambdas, Polymorphic types Not yet in C++11! – Used in a single CORAL file Containers C++11 – initializer lists Functions C++11 – std::function, std::bind Date and time C++11 – std::chrono Smart pointers C++11 – std::shared_ptr, std::unique_ptr Also: deprecated std::auto_ptr std::unique_ptr (move semantics)! Filesystem Not yet in C++11! – Used in several CORAL files Random number generators C++11 – Concurrent programming C++11 – std::thread, std::mutex Tuples C++11 – std::tuple
9
916 th April 2014A. Valassi and A. Álvarez – C++11 White Area Lecture Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.