Discussion Page for CASA C++ Modernization Requirements

Adding a new discussion thread

Create a new new thread by providing a title for the thread (will be shown in the table of contents above) in the first box and the comment itself in the second.

No such template def 'PROMPT:jhjtoctalk'



C++11's shared_ptr will allow us to reimplement casa::CountedPtr so that CASA's data structures can more easily be used in a multithreaded environment.

-- JimJacobs 2014-03-10 - 16:45

Is this different from std::tr1::shared_ptr that is currently being used throughout our codebase?

-- DaveMehringer - 2014-03-17

I don't think there are any significant differences. However, it is important to note that there are two different STL libraries libc++ (new) and libstdc++ (old). I think we would want the newer version, but I don't think there are significant differences for the few STL classes we use (Jim might know otherwise, though).

-- DarrellSchiebel - 2014-03-17

I'm not sure how widely supported the std::tr1 stuff was. We will have to think through mixing CountedPtr (which would be implemented using std::shared_ptr) with std::shared_ptr to make sure we don't end up having two independent counted pointers managing the same storage.

-- JimJacobs - 2014-03-18

We discussed replacing CounterPtr with std::shared_ptrÂ… and I thought we decided to just do away with CountedPtr...

-- DarrellSchiebel - 2014-03-18

No. The solution is to reimplement CountedPtr with shared_ptr. That keeps backwards compatibility and prevents us from having to redo a big chunk of CasaCore.

-- JimJacobs - 2014-03-26

lambda function

I've found lambda functions provide a nice way to "lighten the code". Instead of having to create a class, and then create an object, and then pass the object into a function, lambda functions allow an in-place creation of a function with flexible "capture lists", e.g. when specifying a callback:
         int count = 0;
         auto cb = std::function<curlfunc_t>(
              [&](void *ptr, size_t size, size_t nmemb) -> size_t {
                   char buf[35];
                   printf("(%zu/%zu): %s\n",size,nmemb,buf);
                   return size*nmemb;
         curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cb);
Here the local variable of captured by reference ('[&]') and this allows me to create a callback in-place which can increment a local count variable to keep track of the number of blocks that curl fetches.

-- DarrellSchiebel 2014-03-17 - 17:14

auto type

I think for complicated templated types, the auto type (see lambda example) can really help keep the code readable. When a particular variable's type is important, the type can be included. Otherwise, auto works great.

   -- DarrellSchiebel 2014-03-17 - 17:25


For my purposes, I've found clang++ to have the best support for C++11. This is the compiler that apple supplies with Xcode, and a version for RHEL6 is available in the CASA repository:
-bash-4.1$ rpm -qa | grep clang
We should collect a summary set of links for C++11 support:

   -- DarrellSchiebel 2014-03-17 - 17:30

in gcc, almost full feature is supported after gcc 4.8. I think 4.8.2 is better than 4.8.1. Furthermore, RH7 will be based on gcc 4.8 series (see https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/7-Beta/html-single/7.0_Release_Notes/index.html#chap-compiler-and-tools).

-- TakeshiNakazato - 2014-03-27

move semantics

Many of the hoops we jump through to make our code efficient, e.g. clever copy operators (to avoid copies of temporaries), passing by reference or via a pointer, etc, can be resolved with C++11 via move semantics:
     Vector( Vector &&that ) : elem{that.elem}, sz{that.sz} {
          that.elem = nullptr;
          that.sz = 0;
Here, when the compiler knows (or is told) that move semantics can be used a copy of a variable (e.g. a temporary) is not made, but rather the state of the variable is moved to the copy.

   -- DarrellSchiebel 2014-03-17 - 17:36

c++11 references

It would be useful to collect a list of reference materialÂ… not limited to books, but also including web pages which contain useful idioms (especially useful with variadic templates):
  • books
    • Stroustrup's book The C++ Programming Language: Edition 4 is very good, and very complete. It is organized to be both a tutorial and reference manual. It has many examples and includes complete source code for the examples. Some of the historical notes are also interesting.
  • web notes
    • Templates are much improved with C++11. In fact, they make it possible to use the extern "C" signature of a external library function and automatically make a C++ wrapper at compile time which matches the library function. This page gives a nice overview of how to unpackage the traits of a function.

   -- DarrellSchiebel 2014-03-17 - 17:41

OMP and other non-C++ Functionality

What is the desirability of various OMP, etc., versions? These require compiler support and so might bear on the selection of compilers.

   -- JimJacobs 2014-03-18 - 16:29

Concerning other features: gcc 4.9 came out with OpenMP 4.0 and Cilk Plus support.

OpenAcc does not seem to have made it into the 4.9 release...but was supposed to.

Clang does not yet have support for OpenMP and i keep hearing its close since end of 2012.

OpenMP and Cilk are nice and allows readable/maintenable code for multi-threading

-- KumarGolap - 2014-03-17

Personally, I really like the Rx approach to lockless multi-threading. Hiding all of the locking in a data abstraction is very powerful. In this idiom, streams of asynchronous events can be combined, truncated, or filtered with all of the synchronization being handled by schedulers. However, I believe Rx is concerned with higher-level multi-threading than OpenMP, which I believe is more about parallel loops etc. I don't know much about Clik Plus...

-- DarrellSchiebel - 2014-03-18

Which versions of OpenMP, etc., do we need to consider selecting a compiler? Is 4.0 bring really desirable, must-have functionality from a CASA perspective?

-- JimJacobs - 2014-03-20

I think xdispatch/GCD would be one of the candidates for multi-threading. This is poweful when it is combined with lambda function.

-- TakeshiNakazato - 2014-03-27

Scope of modernization

I would like to clarify what is the scope of modernization project. Does it aim A) to rewrite whole code with full c++11 features? or B) to minimize changes in existing code and to implement upcoming features using c++11? I believe we will aim B) at the moment and finally we are headed for A). This may be indicated in Requirements 6. but let me clarify.

   -- TakeshiNakazato 2014-03-27 - 20:55


I like std::unique_ptr. This is a replacement for auto_ptr.

   -- TakeshiNakazato 2014-03-27 - 21:03

Users viewpoint

I would like to point out that we should take into account users benefit. It may be mentioned somewhere but it is not written clearly in the wiki page. We should clarify what is an outcome of the modernization (using C++11) not only from developer's but also from user's viewpoint. This is because that transition to C++11 (or modern compiler) might affect release schedule so that we sometimes forces users to accept certain delay of development. Please remember that supporting RH6 and OSX 10.8 for example. Changing compiler is more difficult than we think. Scheduling should not be too optimistic. Modernization work might affect release scope or release schedule unless there are several peoples 100% specific for modernization.

   -- TakeshiNakazato 2014-03-27 - 21:34

Compiler Requirement: RX extensions

The DBus VO client uses the RX extensions. It is separate (build, library, everything) from CASA, but I would like to be able to use the RX extensions within CASA so I would like one compiler requirement be that we choose a compiler which can build the RX extensions (https://rxcpp.codeplex.com). This is a compact, flexible, and entirely header-file based library.

   -- DarrellSchiebel 2014-04-07 - 10:19


-- JimJacobs - 2014-03-07
Topic revision: r14 - 2014-04-07, DarrellSchiebel
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding NRAO Public Wiki? Send feedback