Explore chapters and articles related to this topic
Portable Software Technology
Published in David R. Martinez, Robert A. Bond, Vai M. Michael, High Performance Embedded Computing Handbook, 2018
where A, B, C, and D are all distributed vectors or matrices. Such expressions are enabled by the operator overloading feature of C++ (Stroustrup 1997). A naive implementation of operator overloading in C++ will result in the creation of complete copies of the data for each substep of the expression, such as the intermediate multiply C*D, which can result in a significant performance penalty. This penalty can be avoided by the use of expression templates, which enable the construction of a chained expression in such a way as to eliminate the temporary variables (see Figure 17-2). In many instances, it is possible to achieve better performance with expression templates than using standard C-based libraries because the C++ expression-template code can achieve superior cache performance for long expressions (Haney et al. 1999).
Efficient computation of derivatives for solving optimization problems in R and Python using SWIG-generated interfaces to ADOL-C†
Published in Optimization Methods and Software, 2018
K. Kulshreshtha, S.H.K. Narayanan, J. Bessac, K. MacIntyre
Another difficulty is imposed by the structure of the R language. It does not allow for operator overloading in the same sense as C++ does. The C++ compiler generates additional code and lookup tables so that the correct operator or function can be chosen at runtime, based on context in any expression, that is, dynamic dispatch. In R, the programmer is responsible for checking the arguments to any overloaded function or operator and dispatching the correct version. As a safeguard against inadvertent overloading of common mathematical operators, the SWIG-generated interface contains named functions for such operators; for example, ‘Plus‘ is generated in R for the C++ operator +. To utilize operator overloading correctly, we needed to modify the generated R source code to save the existing definition of ‘+‘ as shown in the first line of Figure 2(b) and dispatch it if the arguments are not the data types we expect for the ADOL-C library.
Automatic differentiation of a finite-volume-based transient heat conduction code for sensitivity analysis
Published in Numerical Heat Transfer, Part B: Fundamentals, 2018
Operator overloading refers to the customization of the standard operators defined by a programming language for operands of user-defined types. This feature can be utilized to perform automatic differentiation through a suitably defined type. Consider the class FwdDiff, partially shown in Figure 1, which is similar in concept to that of Jemcov [2] and the implementation in WEdiff. As shown under the “Constructors” comment block, the FwdDiff class can be constructed from a standard double, another instance of a FwdDiff, and can be extended to any other constructors that are needed. All of the standard arithmetic operators must also be overloaded (only the operators *= and + = are shown in Figure 1). Further, access methods must be provided, where the function val() returns the value of the FwdDiff object, while the function dx() returns its derivative with respect to the designated quantity. Each of these values is held as private member data within the class.