JavaScript is not enabled in your browser
Objexx Engineering

Multidimensional C++ Arrays    |    Objexx Labs

Performance
Posted 2016/03/29

Since C++ doesn't provide multidimensional arrays in its standard library technical applications typically use one of the more well-known array libraries such as Eigen, Armadillo, uBLAS, or Boost.MultiArray. These each have somewhat different goals, capabilities, and performance. At Objexx we have a focus on array performance and we do a lot of conversions from Fortran to C++. You can criticize Fortran for its many limitations but its arrays have capabilities that are very nice for scientific and engineering applications.

From this perspective we have certain features that we would like to see these major array libraries adopt:

  • Flexible index ranges (like Fortran). Sometimes natural indexing for an algorithm doesn't start at zero. With C++11 arrays can provide a nice syntax for this, such as we use in the ObjexxFCL arrays:
      Array2D_int A( {-n,n}, 3 );
    
    This can be supported with no lookup performance penalty so it nice to give projects the option of natural indexing.
  • Live slice (section) proxies. These can exploit the same C++11 syntax shown above for index ranges for elegant usage:
      A( {-i,i,2}, 2 )
    
    Slices can be non-contiguous so their use must be balanced against performance considerations but a proper "Fortranic" implementation can eliminate other kinds of overhead.
  • Linear indexing to eliminate the index offset overhead in lookups for 2+D arrays in loops. See Array Lookups for more on linear indexing.
  • Row and column major array layout support. Row major is more natural in the C/C++ world but column major is more familiar for projects migrating from Fortran. We provide both variants in the ObjexxFCL and we built a nifty Clang-based tool for converting a code base between them.