Changeset 708 for trunk/ADOLC/doc/adolcmanual.tex
 Timestamp:
 Jul 12, 2016 4:18:44 AM (3 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/ADOLC/doc/adolcmanual.tex
r689 r708 3285 3285 %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3286 3286 % 3287 \section{T apeless forward differentiation in ADOLC}3287 \section{Traceless forward differentiation in ADOLC} 3288 3288 \label{tapeless} 3289 3289 % 3290 3290 Up to version 1.9.0, the development of the ADOLC software package 3291 3291 was based on the decision to store all data necessary for derivative 3292 computation on t apes, where large applications require the tapes to be3292 computation on traces (tapes), where large applications require the traces to be 3293 3293 written out to corresponding files. In almost all cases this means 3294 3294 a considerable drawback in terms of run time due to the excessive 3295 memory accesses. Using these t apes enables ADOLC to offer multiple3295 memory accesses. Using these traces enables ADOLC to offer multiple 3296 3296 functions. However, it is not necessary for all tasks of derivative 3297 3297 computation to do that. 3298 3298 3299 Starting with version 1.10.0, ADOLC now features a t apeless forward3299 Starting with version 1.10.0, ADOLC now features a traceless forward 3300 3300 mode for computing first order derivatives in scalar mode, i.e., 3301 3301 $\dot{y} = F'(x)\dot{x}$, and in vector mode, i.e., $\dot{Y} = F'(x)\dot{X}$. 3302 This t apeless variant coexists with the more universal3303 t ape based mode in the package. The following subsections describe3304 the source code modifications required to use the t apeless forward mode of3302 This traceless variant coexists with the more universal 3303 trace based mode in the package. The following subsections describe 3304 the source code modifications required to use the traceless forward mode of 3305 3305 ADOLC. 3306 3306 % … … 3315 3315 y_3 = \arctan(x_2/x_1), 3316 3316 \end{eqnarray*} 3317 as an example. The corresponding source code is shown in \autoref{fig:t apeless}.3317 as an example. The corresponding source code is shown in \autoref{fig:traceless}. 3318 3318 \begin{figure}[htb] 3319 3319 \framebox[\textwidth]{\parbox{\textwidth}{ … … 3343 3343 %\end{center} 3344 3344 }} 3345 \caption{Example for t apeless forward mode}3346 \label{fig:t apeless}3345 \caption{Example for traceless forward mode} 3346 \label{fig:traceless} 3347 3347 \end{figure} 3348 3348 % 3349 3349 Changes to the source code that are necessary for applying the 3350 t apeless forwardADOLC are described in the following two3350 traceless forward mode of ADOLC are described in the following two 3351 3351 subsections, where the vector mode version is described 3352 3352 as extension of the scalar mode. … … 3354 3354 \subsubsection*{The scalar mode} 3355 3355 % 3356 To use the t apeless forward mode, one has to include only3356 To use the traceless forward mode, one has to include only 3357 3357 the header file \verb#adtl.h# since it does not include the 3358 t ape based functions defined in other header files.3359 3360 As in the t ape based forward version of ADOLC all derivative3358 trace based functions defined in other header files. 3359 3360 As in the trace based forward version of ADOLC all derivative 3361 3361 calculations are introduced by calls to overloaded 3362 operators. Therefore, similar to the t apebased version all3362 operators. Therefore, similar to the tracebased version all 3363 3363 independent, intermediate and dependent variables must be declared 3364 with type {\sf adouble}. The whole t apeless functionality provided by3364 with type {\sf adouble}. The whole traceless functionality provided by 3365 3365 \verb#adtl.h# was written as complete inline intended code 3366 3366 due to run time aspects, where the real portion of inlined code can 3367 3367 be influenced by switches for many compilers. Likely, the whole 3368 3368 derivative code is inlined by default. Our experiments 3369 with the t apeless mode have produced complete inlined code by using3369 with the traceless mode have produced complete inlined code by using 3370 3370 standard switches (optimization) for GNU and Intel C++ 3371 3371 compiler. 3372 3372 3373 3373 To avoid name conflicts 3374 resulting from the inlining the t apeless version has its own namespace3374 resulting from the inlining the traceless version has its own namespace 3375 3375 \verb#adtl#. As a result four possibilities of using the {\sf adouble} 3376 type are available for the t apeless version:3376 type are available for the traceless version: 3377 3377 \begin{itemize} 3378 3378 \item Defining a new type … … 3407 3407 \begin{center} 3408 3408 \begin{tabular}{l} 3409 {\sf \#using namespace adtl;}\\3409 {\sf using namespace adtl;}\\ 3410 3410 ...\\ 3411 3411 {\sf adouble tmp;} … … 3418 3418 function evaluation. This can be done by assigning the variables a {\sf 3419 3419 double} value. The {\sf ad}value is set to zero in this case. 3420 Additionally, the t apeless forward mode variant of ADOLC3420 Additionally, the traceless forward mode variant of ADOLC 3421 3421 offers a function named {\sf setValue} for setting the value without 3422 3422 changing the {\sf ad}value. To set the {\sf ad}values of the independent 3423 variables ADOLC offers two possibilities: 3423 variables ADOLC offers two possibilities: 3424 3424 \begin{itemize} 3425 3425 \item Using the constructor 3426 3426 \begin{center} 3427 3427 \begin{tabular}{l} 3428 {\sf adouble x1(2,1), x2(4,0), y;} 3428 {\sf double seedOne = 1., seedZero = 0.;}\\ 3429 {\sf adouble x1(2,\&seedOne), x2(4,\&seedZero), y;} 3429 3430 \end{tabular} 3430 3431 \end{center} … … 3436 3437 \begin{center} 3437 3438 \begin{tabular}{l} 3439 {\sf double seedOne = 1., seedZero = 0.;}\\ 3438 3440 {\sf adouble x1=2, x2=4, y;}\\ 3439 3441 ...\\ 3440 {\sf x1.setADValue( 1);}\\3441 {\sf x2.setADValue( 0);}3442 {\sf x1.setADValue(\&seedOne);}\\ 3443 {\sf x2.setADValue(\&seedZero);} 3442 3444 \end{tabular} 3443 3445 \end{center} 3444 The same example as above but now using {\sf setADValue}method for initializing the derivative values. 3446 The same example as above but now using {\sf setADValue}method for initializing the derivative values. It is important to note that in both cases the derivative values have to be set by passing an address of a variable or a pointer of the {\sf double} type (instead of passing the value directly). The reason for doing this will become clear in the next subsection. 3445 3447 \end{itemize} 3446 3448 % 3447 3449 The derivatives can be obtained at any time during the evaluation 3448 process by calling the {\sf getADValue}method 3450 process by calling the {\sf getADValue}method which returns a pointer (instead of a value), and therefore, it can be assigned to another pointer or it can be dereferenced immediately in order to read the value: 3449 3451 \begin{center} 3450 3452 \begin{tabular}{l} 3451 3453 {\sf adouble y;}\\ 3452 3454 ...\\ 3453 {\sf cout $<<$ y.getADValue();}3455 {\sf cout $<<$ *(y.getADValue());} 3454 3456 \end{tabular} 3455 3457 \end{center} … … 3475 3477 \> {\sf \rule{1cm}{0pt}...}\\ 3476 3478 \\ 3477 \> {\sf \rule{0.5cm}{0pt}x[0].setADValue(1);\hspace*{3cm}// derivative of f with respect to $x_1$}\\ 3479 \> {\sf \rule{0.5cm}{0pt}double seed = 1.;}\\ 3480 \> {\sf \rule{0.5cm}{0pt}x[0].setADValue(\&seed);\hspace*{3cm}// derivative of f with respect to $x_1$}\\ 3478 3481 \> {\sf \rule{0.5cm}{0pt}y[0] = sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]);}\\ 3479 3482 \> {\sf \rule{0.5cm}{0pt}y[1] = atan(sqrt(x[0]*x[0]+x[1]*x[1])/x[2]);}\\ … … 3481 3484 \\ 3482 3485 \> {\sf \rule{0.5cm}{0pt}cout $<<$ "y1=" $<<$ y[0].getValue() $<<$ " , y2=" $<<$ y[1].getValue ... ;}\\ 3483 \> {\sf \rule{0.5cm}{0pt}cout $<<$ "dy2/dx1 = " $<<$ y[1].getADValue() $<<$ endl;}\\3486 \> {\sf \rule{0.5cm}{0pt}cout $<<$ "dy2/dx1 = " $<<$ *(y[1].getADValue()) $<<$ endl;}\\ 3484 3487 \> {\sf \rule{0.5cm}{0pt}return 0;}\\ 3485 3488 \> {\sf \}} … … 3487 3490 %\end{center} 3488 3491 }} 3489 \caption{Example for t apeless scalar forward mode}3492 \caption{Example for traceless scalar forward mode} 3490 3493 \label{fig:modcode} 3491 3494 \end{figure} … … 3506 3509 error. \verb#adtl::setNumDir(N)# must therefore be called before 3507 3510 declaring any \verb#adtl::adouble# objects. 3508 3509 Compared to the scalar case setting and getting the derivative 3510 values, i.e. the directions, is more involved. Instead of 3511 working with single {\sf double} values, pointer to fields of {\sf 3512 double}s are used as illustrated by the following example: 3511 3512 Setting and getting the derivative values is done in the same manner as in the scalar case, by passing and retrieving the pointers, as illustrated in the following example: 3513 3513 \begin{center} 3514 3514 \begin{tabular}{l} … … 3524 3524 \end{tabular} 3525 3525 \end{center} 3526 Additionally, the tapeless vector forward mode of ADOLC offers two 3527 new methods for setting/getting the derivative values. Similar 3528 to the scalar case, {\sf double} values are used but due to the vector 3529 mode the position of the desired vector element must be supplied in 3530 the argument list: 3526 Now using the pointers in the methods {\sf setADValue} and {\sf getADValue} makes more sense since the vector mode requires the field of $p$ elements per {\sf adouble} which holds the derivative values. 3527 Additionally, the traceless vector forward mode of ADOLC offers two 3528 new methods for setting/getting the derivative values. Setting a derivative value of the desired vector element is possible by passing a {\sf double} value and its position in the vector ({\sf integer}). Getting a derivative value of the desired vector element requires as argument only its position in the vector. One can note that the pointers are not used in these cases, as illustrated in the following example: 3531 3529 \begin{center} 3532 3530 \begin{tabular}{l} … … 3578 3576 \end{tabbing} 3579 3577 }} 3580 \caption{Example for t apeless vector forward mode}3578 \caption{Example for traceless vector forward mode} 3581 3579 \label{fig:modcode2} 3582 3580 \end{figure} … … 3590 3588 \begin{center} 3591 3589 \begin{tabular}{l} 3592 {\sf g++ I/home/username/adolc\_base/include c t apeless\_scalar.cpp}3590 {\sf g++ I/home/username/adolc\_base/include c traceless\_scalar.cpp} 3593 3591 \end{tabular} 3594 3592 \end{center} … … 3604 3602 \begin{center} 3605 3603 \begin{tabular}{l} 3606 {\sf g++ o tapeless\_scalar tapeless\_scalar.o ladolc L/home/username/adolc\_base/lib} 3604 {\sf g++ o traceless\_scalar traceless\_scalar.o}\\ 3605 {\sf Wl,{}rpath Wl,/home/username/adolc\_base/lib L/home/username/adolc\_base/lib ladolc} 3607 3606 \end{tabular} 3608 3607 \end{center} 3609 The mentioned source codes {\sf t apeless\_scalar.c} and {\sf tapeless\_vector.c}3610 illustrating the use of the for t apeless scalar and vector mode can be found in3608 The mentioned source codes {\sf traceless\_scalar.c} and {\sf traceless\_vector.c} 3609 illustrating the use of the for traceless scalar and vector mode can be found in 3611 3610 the directory {\sf examples}. 3612 3611 % 3613 \subsection{Concluding Remarks for the T apeless Forward Mode Variant}3614 % 3615 As many other AD methods the t apeless forward mode provided by the3612 \subsection{Concluding Remarks for the Traceless Forward Mode Variant} 3613 % 3614 As many other AD methods the traceless forward mode provided by the 3616 3615 ADOLC package has its own strengths and drawbacks. Please read the 3617 3616 following section carefully to become familiar with the things that … … 3622 3621 \item Code speed\\ 3623 3622 Increasing computation speed was one of the main aspects in writing 3624 the t apeless code. In many cases higher performance can be3623 the traceless code. In many cases higher performance can be 3625 3624 expected this way. However this is not guarenteed for repeated 3626 3625 evaluations. 3627 3626 \item Smaller overall memory requirements\\ 3628 T apeless ADOLC does not write tapes anymore, as the name3627 Traceless ADOLC does not write traces anymore, as the name 3629 3628 implies. Loop ''unrolling'' can be avoided this 3630 3629 way. Considered main memory plus disk space as overall memory 3631 requirements the t apeless version can be3630 requirements the traceless version can be 3632 3631 executed in a more efficient way. 3633 3632 \end{itemize} … … 3637 3636 The ability to compute derivatives to a given function is 3638 3637 bounded by the main memory plus swap size when using 3639 t apeless ADOLC. Computation from swap should be avoided anyway3638 traceless ADOLC. Computation from swap should be avoided anyway 3640 3639 as far as possible since it slows down the computing time 3641 3640 drastically. Therefore, if the program execution is … … 3650 3649 where the storage size of all non {\sf adouble} based variables is described by $M_p$. 3651 3650 \item Compile time\\ 3652 As discussed in the previous sections, the t apeless forward mode of3651 As discussed in the previous sections, the traceless forward mode of 3653 3652 the ADOLC package is implemented as inline intended version. Using 3654 3653 this approach results in a higher source code size, since every … … 3656 3655 operation itself as well as for the corresponding derivative 3657 3656 code after the inlining process. Therefore, the compilation time 3658 needed for the t apeless version may be higher than that of the tape based code.3657 needed for the traceless version may be higher than that of the trace based code. 3659 3658 \item Code Size\\ 3660 3659 A second drawback and result of the code inlining is the 3661 3660 increase of code sizes for the binaries. The increase 3662 factor compared to the corresponding t ape based program is3661 factor compared to the corresponding trace based program is 3663 3662 difficult to quantify as it is task dependent. Practical results 3664 3663 have shown that values between 1.0 and 2.0 can be … … 3712 3711 \end{eqnarray*} 3713 3712 as an example. We now calculate the Jacobian at $M=1024$ different points. 3714 The source code for one point is shown in \autoref{fig:t apeless}. This example3713 The source code for one point is shown in \autoref{fig:traceless}. This example 3715 3714 has no real application but can still be used to show the combination of the traceless version 3716 3715 of ADOLC and Cuda.
Note: See TracChangeset
for help on using the changeset viewer.