diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..d3afccea0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: LLVM +IndentPPDirectives: BeforeHash \ No newline at end of file diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 000000000..fe050a28c --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,21 @@ +name: Run clang-format Linter + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.18.1 + with: + source: '.' + inplace: True + - uses: EndBug/add-and-commit@v9 + with: + author_name: Clang Robot + author_email: robot@example.com + message: 'Committing clang-format changes' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/ADOL-C/boost-test/adouble.cpp b/ADOL-C/boost-test/adouble.cpp index ea4d3777d..f11b19416 100644 --- a/ADOL-C/boost-test/adouble.cpp +++ b/ADOL-C/boost-test/adouble.cpp @@ -5,8 +5,8 @@ // Check that the specialization of std::numeric_limits for adouble exists // and does something reasonable. -BOOST_AUTO_TEST_CASE(std_numeric_limits_adouble) -{ +BOOST_AUTO_TEST_CASE(std_numeric_limits_adouble) { BOOST_TEST(bool(std::numeric_limits::is_specialized)); - BOOST_TEST(std::numeric_limits::max()==std::numeric_limits::max()); + BOOST_TEST(std::numeric_limits::max() == + std::numeric_limits::max()); } diff --git a/ADOL-C/boost-test/main.cpp b/ADOL-C/boost-test/main.cpp index bf7d5647e..e981cb1e7 100644 --- a/ADOL-C/boost-test/main.cpp +++ b/ADOL-C/boost-test/main.cpp @@ -1,16 +1,14 @@ -#define BOOST_TEST_MODULE boost-adolc-test +#define BOOST_TEST_MODULE boost - adolc - test #define BOOST_TEST_DYN_LINK #define BOOST_TEST_NO_MAIN #include namespace utf = boost::unit_test; -#include +#include // entry point: -int main(int argc, char* argv[], char* envp[]) -{ +int main(int argc, char *argv[], char *envp[]) { adtl::setNumDir(2); - return utf::unit_test_main( &init_unit_test, argc, argv ); + return utf::unit_test_main(&init_unit_test, argc, argv); } - diff --git a/ADOL-C/boost-test/traceCompositeTests.cpp b/ADOL-C/boost-test/traceCompositeTests.cpp index c1bcd547c..925123680 100644 --- a/ADOL-C/boost-test/traceCompositeTests.cpp +++ b/ADOL-C/boost-test/traceCompositeTests.cpp @@ -7,8 +7,7 @@ namespace tt = boost::test_tools; #include "const.h" -BOOST_AUTO_TEST_SUITE( trace_composite ) - +BOOST_AUTO_TEST_SUITE(trace_composite) /************************************/ /* Tests for trace vector mode with */ @@ -16,7 +15,6 @@ BOOST_AUTO_TEST_SUITE( trace_composite ) /* Author: Philipp Schuette */ /************************************/ - /* The tests for ADOL-C trace vector mode in this file involve more * complicated custom compositions of elementary functions with * higher numbers of independent and possibly dependent variables. @@ -35,8 +33,7 @@ BOOST_AUTO_TEST_SUITE( trace_composite ) * 1.0 * ) */ -BOOST_AUTO_TEST_CASE(CompositeTrig1_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig1_FOV_Forward) { double x1 = 0.289, x2 = 1.927, out; adouble ax1, ax2; @@ -44,14 +41,14 @@ BOOST_AUTO_TEST_CASE(CompositeTrig1_FOV_Forward) ax1 <<= x1; ax2 <<= x2; - ax1 = sin(ax1)*sin(ax1) + cos(ax1)*cos(ax1) + ax2; + ax1 = sin(ax1) * sin(ax1) + cos(ax1) * cos(ax1) + ax2; ax1 >>= out; trace_off(); double x1Derivative = 0.; double x2Derivative = 1.; - x1 = std::sin(x1)*std::sin(x1) + std::cos(x1)*std::cos(x1) + x2; + x1 = std::sin(x1) * std::sin(x1) + std::cos(x1) * std::cos(x1) + x2; double *x = myalloc1(2); double **xd = myalloc2(2, 2); @@ -83,8 +80,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig1_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeTrig1Operator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig1Operator_FOV_Reverse) { double x1 = 0.289, x2 = 1.927, out; adouble ax1, ax2; @@ -92,7 +88,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig1Operator_FOV_Reverse) ax1 <<= x1; ax2 <<= x2; - ax1 = sin(ax1)*sin(ax1) + cos(ax1)*cos(ax1) + ax2; + ax1 = sin(ax1) * sin(ax1) + cos(ax1) * cos(ax1) + ax2; ax1 >>= out; trace_off(); @@ -110,8 +106,8 @@ BOOST_AUTO_TEST_CASE(CompositeTrig1Operator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::sqrt(2.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::sqrt(2.)*x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::sqrt(2.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::sqrt(2.) * x2Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -124,8 +120,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig1Operator_FOV_Reverse) * 2*cos(x3)*sin(x3)*sin(x2) * ) */ -BOOST_AUTO_TEST_CASE(CompositeTrig2_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig2_FOV_Forward) { double x1 = 1.11, x2 = 2.22, x3 = 3.33, out; adouble ax1, ax2, ax3; @@ -134,17 +129,18 @@ BOOST_AUTO_TEST_CASE(CompositeTrig2_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ax1 = 2*sin(cos(ax1))*exp(ax2) - pow(cos(ax3), 2)*sin(ax2); + ax1 = 2 * sin(cos(ax1)) * exp(ax2) - pow(cos(ax3), 2) * sin(ax2); ax1 >>= out; trace_off(); - double x1Derivative = -2*std::cos(std::cos(x1))*std::exp(x2)*std::sin(x1); - double x2Derivative = 2*std::sin(std::cos(x1))*std::exp(x2) - - std::pow(std::cos(x3), 2)*std::cos(x2); - double x3Derivative = 2*std::cos(x3)*std::sin(x3)*std::sin(x2); - x1 = 2*std::sin(std::cos(x1))*std::exp(x2) - - std::pow(std::cos(x3), 2)*std::sin(x2); + double x1Derivative = + -2 * std::cos(std::cos(x1)) * std::exp(x2) * std::sin(x1); + double x2Derivative = 2 * std::sin(std::cos(x1)) * std::exp(x2) - + std::pow(std::cos(x3), 2) * std::cos(x2); + double x3Derivative = 2 * std::cos(x3) * std::sin(x3) * std::sin(x2); + x1 = 2 * std::sin(std::cos(x1)) * std::exp(x2) - + std::pow(std::cos(x3), 2) * std::sin(x2); double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -178,8 +174,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig2_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeTrig2Operator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig2Operator_FOV_Reverse) { double x1 = 1.11, x2 = 2.22, x3 = 3.33, out; adouble ax1, ax2, ax3; @@ -188,15 +183,16 @@ BOOST_AUTO_TEST_CASE(CompositeTrig2Operator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ax1 = 2*sin(cos(ax1))*exp(ax2) - pow(cos(ax3), 2)*sin(ax2); + ax1 = 2 * sin(cos(ax1)) * exp(ax2) - pow(cos(ax3), 2) * sin(ax2); ax1 >>= out; trace_off(); - double x1Derivative = -2*std::cos(std::cos(x1))*std::exp(x2)*std::sin(x1); - double x2Derivative = 2*std::sin(std::cos(x1))*std::exp(x2) - - std::pow(std::cos(x3), 2)*std::cos(x2); - double x3Derivative = 2*std::cos(x3)*std::sin(x3)*std::sin(x2); + double x1Derivative = + -2 * std::cos(std::cos(x1)) * std::exp(x2) * std::sin(x1); + double x2Derivative = 2 * std::sin(std::cos(x1)) * std::exp(x2) - + std::pow(std::cos(x3), 2) * std::cos(x2); + double x3Derivative = 2 * std::cos(x3) * std::sin(x3) * std::sin(x2); double **u = myalloc2(3, 1); double **z = myalloc2(3, 3); @@ -210,12 +206,12 @@ BOOST_AUTO_TEST_CASE(CompositeTrig2Operator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::exp(6.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::exp(6.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == std::exp(6.)*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == std::log(6.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == std::log(6.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == std::log(6.)*x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::exp(6.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::exp(6.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == std::exp(6.) * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == std::log(6.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == std::log(6.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == std::log(6.) * x3Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -229,8 +225,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig2Operator_FOV_Reverse) * pow(sin(x1), cos(x1) - x2) * ) */ -BOOST_AUTO_TEST_CASE(CompositeTrig3_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig3_FOV_Forward) { double x1 = 0.516, x2 = 9.89, x3 = 0.072, out; adouble ax1, ax2, ax3; @@ -239,18 +234,18 @@ BOOST_AUTO_TEST_CASE(CompositeTrig3_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ax1 = pow(sin(ax1), cos(ax1) - ax2)*ax3; + ax1 = pow(sin(ax1), cos(ax1) - ax2) * ax3; ax1 >>= out; trace_off(); - double x1Derivative = std::pow(std::sin(x1), std::cos(x1) - x2) * x3 - * (-std::sin(x1)*std::log(std::sin(x1)) - + (std::cos(x1) - x2)*std::cos(x1)/std::sin(x1)); - double x2Derivative = -std::log(std::sin(x1)) - * std::pow(std::sin(x1), std::cos(x1) - x2) * x3; + double x1Derivative = std::pow(std::sin(x1), std::cos(x1) - x2) * x3 * + (-std::sin(x1) * std::log(std::sin(x1)) + + (std::cos(x1) - x2) * std::cos(x1) / std::sin(x1)); + double x2Derivative = + -std::log(std::sin(x1)) * std::pow(std::sin(x1), std::cos(x1) - x2) * x3; double x3Derivative = std::pow(std::sin(x1), std::cos(x1) - x2); - x1 = std::pow(std::sin(x1), std::cos(x1) - x2)*x3; + x1 = std::pow(std::sin(x1), std::cos(x1) - x2) * x3; double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -284,8 +279,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig3_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeTrig3Operator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig3Operator_FOV_Reverse) { double x1 = 0.516, x2 = 9.89, x3 = 0.072, out; adouble ax1, ax2, ax3; @@ -294,16 +288,16 @@ BOOST_AUTO_TEST_CASE(CompositeTrig3Operator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ax1 = pow(sin(ax1), cos(ax1) - ax2)*ax3; + ax1 = pow(sin(ax1), cos(ax1) - ax2) * ax3; ax1 >>= out; trace_off(); - double x1Derivative = std::pow(std::sin(x1), std::cos(x1) - x2) * x3 - * (-std::sin(x1)*std::log(std::sin(x1)) - + (std::cos(x1) - x2)*std::cos(x1)/std::sin(x1)); - double x2Derivative = -std::log(std::sin(x1)) - * std::pow(std::sin(x1), std::cos(x1) - x2) * x3; + double x1Derivative = std::pow(std::sin(x1), std::cos(x1) - x2) * x3 * + (-std::sin(x1) * std::log(std::sin(x1)) + + (std::cos(x1) - x2) * std::cos(x1) / std::sin(x1)); + double x2Derivative = + -std::log(std::sin(x1)) * std::pow(std::sin(x1), std::cos(x1) - x2) * x3; double x3Derivative = std::pow(std::sin(x1), std::cos(x1) - x2); double **u = myalloc2(3, 1); @@ -318,12 +312,12 @@ BOOST_AUTO_TEST_CASE(CompositeTrig3Operator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::pow(10., 6.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::pow(10., 6.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == std::pow(10., 6.)*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == std::pow(6., 10.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == std::pow(6., 10.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == std::pow(6., 10.)*x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::pow(10., 6.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::pow(10., 6.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == std::pow(10., 6.) * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == std::pow(6., 10.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == std::pow(6., 10.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == std::pow(6., 10.) * x3Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -335,8 +329,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig3Operator_FOV_Reverse) * x1*exp(x2) * ) */ -BOOST_AUTO_TEST_CASE(CompositeTrig4_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig4_FOV_Forward) { double x1 = 1.56, x2 = 8.99, out; adouble ax1, ax2; @@ -344,14 +337,14 @@ BOOST_AUTO_TEST_CASE(CompositeTrig4_FOV_Forward) ax1 <<= x1; ax2 <<= x2; - ax1 = atan(tan(ax1))*exp(ax2); + ax1 = atan(tan(ax1)) * exp(ax2); ax1 >>= out; trace_off(); double x1Derivative = std::exp(x2); - double x2Derivative = x1*std::exp(x2); - x1 = x1*exp(x2); + double x2Derivative = x1 * std::exp(x2); + x1 = x1 * exp(x2); double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -383,8 +376,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig4_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeTrig4Operator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig4Operator_FOV_Reverse) { double x1 = 1.56, x2 = 8.99, out; adouble ax1, ax2; @@ -392,13 +384,13 @@ BOOST_AUTO_TEST_CASE(CompositeTrig4Operator_FOV_Reverse) ax1 <<= x1; ax2 <<= x2; - ax1 = atan(tan(ax1))*exp(ax2); + ax1 = atan(tan(ax1)) * exp(ax2); ax1 >>= out; trace_off(); double x1Derivative = std::exp(x2); - double x2Derivative = x1*std::exp(x2); + double x2Derivative = x1 * std::exp(x2); double **u = myalloc2(2, 1); double **z = myalloc2(2, 2); @@ -410,8 +402,8 @@ BOOST_AUTO_TEST_CASE(CompositeTrig4Operator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == -1.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == -1.*x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == -1. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == -1. * x2Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -426,8 +418,7 @@ BOOST_AUTO_TEST_CASE(CompositeTrig4Operator_FOV_Reverse) * 0.5 * sqrt(x4/x5) * ) */ -BOOST_AUTO_TEST_CASE(LongSum_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(LongSum_FOV_Forward) { double x1 = 0.11, x2 = -2.27, x3 = 81.7, x4 = 0.444, x5 = 4.444, out; adouble ax1, ax2, ax3, ax4, ax5; @@ -438,17 +429,17 @@ BOOST_AUTO_TEST_CASE(LongSum_FOV_Forward) ax4 <<= x4; ax5 <<= x5; - ax1 = ax1 + ax2 - ax3 + pow(ax1, 2) - 10 + sqrt(ax4*ax5); + ax1 = ax1 + ax2 - ax3 + pow(ax1, 2) - 10 + sqrt(ax4 * ax5); ax1 >>= out; trace_off(); - double x1Derivative = 1. + 2*x1; + double x1Derivative = 1. + 2 * x1; double x2Derivative = 1.; double x3Derivative = -1.; - double x4Derivative = 0.5 * std::sqrt(x5/x4); - double x5Derivative = 0.5 * std::sqrt(x4/x5); - x1 = x1 + x2 - x3 + std::pow(x1, 2) - 10 + std::sqrt(x4*x5); + double x4Derivative = 0.5 * std::sqrt(x5 / x4); + double x5Derivative = 0.5 * std::sqrt(x4 / x5); + x1 = x1 + x2 - x3 + std::pow(x1, 2) - 10 + std::sqrt(x4 * x5); double *x = myalloc1(5); double **xd = myalloc2(5, 5); @@ -486,8 +477,7 @@ BOOST_AUTO_TEST_CASE(LongSum_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(LongSumOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(LongSumOperator_FOV_Reverse) { double x1 = 0.11, x2 = -2.27, x3 = 81.7, x4 = 0.444, x5 = 4.444, out; adouble ax1, ax2, ax3, ax4, ax5; @@ -498,16 +488,16 @@ BOOST_AUTO_TEST_CASE(LongSumOperator_FOV_Reverse) ax4 <<= x4; ax5 <<= x5; - ax1 = ax1 + ax2 - ax3 + pow(ax1, 2) - 10 + sqrt(ax4*ax5); + ax1 = ax1 + ax2 - ax3 + pow(ax1, 2) - 10 + sqrt(ax4 * ax5); ax1 >>= out; trace_off(); - double x1Derivative = 1. + 2*x1; + double x1Derivative = 1. + 2 * x1; double x2Derivative = 1.; double x3Derivative = -1.; - double x4Derivative = 0.5 * std::sqrt(x5/x4); - double x5Derivative = 0.5 * std::sqrt(x4/x5); + double x4Derivative = 0.5 * std::sqrt(x5 / x4); + double x5Derivative = 0.5 * std::sqrt(x4 / x5); double **u = myalloc2(5, 1); double **z = myalloc2(5, 5); @@ -525,26 +515,26 @@ BOOST_AUTO_TEST_CASE(LongSumOperator_FOV_Reverse) BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][3] == x4Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][4] == x5Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 2.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == 2.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == 2.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][3] == 2.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][4] == 2.*x5Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == 3.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == 3.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == 3.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][3] == 3.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][4] == 3.*x5Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][0] == 4.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][1] == 4.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][2] == 4.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][3] == 4.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][4] == 4.*x5Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][0] == 5.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][1] == 5.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][2] == 5.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][3] == 5.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][4] == 5.*x5Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 2. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == 2. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == 2. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][3] == 2. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][4] == 2. * x5Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == 3. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == 3. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == 3. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][3] == 3. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][4] == 3. * x5Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][0] == 4. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][1] == 4. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][2] == 4. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][3] == 4. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][4] == 4. * x5Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][0] == 5. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][1] == 5. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][2] == 5. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][3] == 5. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][4] == 5. * x5Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -556,8 +546,7 @@ BOOST_AUTO_TEST_CASE(LongSumOperator_FOV_Reverse) * x1 * ) */ -BOOST_AUTO_TEST_CASE(InverseFunc_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(InverseFunc_FOV_Forward) { double x1 = 3.77, x2 = -21.12, out; adouble ax1, ax2; @@ -565,14 +554,14 @@ BOOST_AUTO_TEST_CASE(InverseFunc_FOV_Forward) ax1 <<= x1; ax2 <<= x2; - ax1 = sqrt(pow(ax1, 2))*ax2; + ax1 = sqrt(pow(ax1, 2)) * ax2; ax1 >>= out; trace_off(); double x1Derivative = x2; double x2Derivative = x1; - x1 = std::sqrt(std::pow(x1, 2))*x2; + x1 = std::sqrt(std::pow(x1, 2)) * x2; double *x = myalloc1(2); double **xd = myalloc2(2, 2); @@ -604,8 +593,7 @@ BOOST_AUTO_TEST_CASE(InverseFunc_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(InverseFuncOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(InverseFuncOperator_FOV_Reverse) { double x1 = 3.77, x2 = -21.12, out; adouble ax1, ax2; @@ -613,7 +601,7 @@ BOOST_AUTO_TEST_CASE(InverseFuncOperator_FOV_Reverse) ax1 <<= x1; ax2 <<= x2; - ax1 = sqrt(pow(ax1, 2))*ax2; + ax1 = sqrt(pow(ax1, 2)) * ax2; ax1 >>= out; trace_off(); @@ -631,8 +619,8 @@ BOOST_AUTO_TEST_CASE(InverseFuncOperator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::cos(2.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::cos(2.)*x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::cos(2.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::cos(2.) * x2Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -648,8 +636,7 @@ BOOST_AUTO_TEST_CASE(InverseFuncOperator_FOV_Reverse) * + exp(x1 + exp(x2 + x3))*pow(x1 + x2, x3)*log(x1 + x2) * ) */ -BOOST_AUTO_TEST_CASE(ExpPow_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(ExpPow_FOV_Forward) { double x1 = 0.642, x2 = 6.42, x3 = 0.528, out; adouble ax1, ax2, ax3; @@ -658,23 +645,23 @@ BOOST_AUTO_TEST_CASE(ExpPow_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ax1 = exp(ax1 + exp(ax2 + ax3))*pow(ax1 + ax2, ax3); + ax1 = exp(ax1 + exp(ax2 + ax3)) * pow(ax1 + ax2, ax3); ax1 >>= out; trace_off(); - double x1Derivative = std::exp(x1 + std::exp(x2 + x3))*std::pow(x1 + x2, x3) - + std::exp(x1 + std::exp(x2 + x3)) - * x3 * std::pow(x1 + x2, x3 - 1); - double x2Derivative = std::exp(x1 + std::exp(x2 + x3))*std::exp(x2 + x3) - * std::pow(x1 + x2, x3) - + std::exp(x1 + std::exp(x2 + x3)) - * x3 * std::pow(x1 + x2, x3 - 1); - double x3Derivative = std::exp(x1 + std::exp(x2 + x3))*std::exp(x2 + x3) - * std::pow(x1 + x2, x3) - + std::exp(x1 + std::exp(x2 + x3)) - * std::pow(x1 + x2, x3)*std::log(x1 + x2); - x1 = std::exp(x1 + std::exp(x2 + x3))*std::pow(x1 + x2, x3); + double x1Derivative = + std::exp(x1 + std::exp(x2 + x3)) * std::pow(x1 + x2, x3) + + std::exp(x1 + std::exp(x2 + x3)) * x3 * std::pow(x1 + x2, x3 - 1); + double x2Derivative = + std::exp(x1 + std::exp(x2 + x3)) * std::exp(x2 + x3) * + std::pow(x1 + x2, x3) + + std::exp(x1 + std::exp(x2 + x3)) * x3 * std::pow(x1 + x2, x3 - 1); + double x3Derivative = std::exp(x1 + std::exp(x2 + x3)) * std::exp(x2 + x3) * + std::pow(x1 + x2, x3) + + std::exp(x1 + std::exp(x2 + x3)) * + std::pow(x1 + x2, x3) * std::log(x1 + x2); + x1 = std::exp(x1 + std::exp(x2 + x3)) * std::pow(x1 + x2, x3); double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -708,8 +695,7 @@ BOOST_AUTO_TEST_CASE(ExpPow_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(ExpPowOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(ExpPowOperator_FOV_Reverse) { double x1 = 1., x2 = 2., x3 = 3., out; adouble ax1, ax2, ax3; @@ -718,22 +704,22 @@ BOOST_AUTO_TEST_CASE(ExpPowOperator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ax1 = exp(ax1 + exp(ax2 + ax3))*pow(ax1 + ax2, ax3); + ax1 = exp(ax1 + exp(ax2 + ax3)) * pow(ax1 + ax2, ax3); ax1 >>= out; trace_off(); - double x1Derivative = std::exp(x1 + std::exp(x2 + x3))*std::pow(x1 + x2, x3) - + std::exp(x1 + std::exp(x2 + x3)) - * x3 * std::pow(x1 + x2, x3 - 1); - double x2Derivative = std::exp(x1 + std::exp(x2 + x3))*std::exp(x2 + x3) - * std::pow(x1 + x2, x3) - + std::exp(x1 + std::exp(x2 + x3)) - * x3 * std::pow(x1 + x2, x3 - 1); - double x3Derivative = std::exp(x1 + std::exp(x2 + x3))*std::exp(x2 + x3) - * std::pow(x1 + x2, x3) - + std::exp(x1 + std::exp(x2 + x3)) - * std::pow(x1 + x2, x3)*std::log(x1 + x2); + double x1Derivative = + std::exp(x1 + std::exp(x2 + x3)) * std::pow(x1 + x2, x3) + + std::exp(x1 + std::exp(x2 + x3)) * x3 * std::pow(x1 + x2, x3 - 1); + double x2Derivative = + std::exp(x1 + std::exp(x2 + x3)) * std::exp(x2 + x3) * + std::pow(x1 + x2, x3) + + std::exp(x1 + std::exp(x2 + x3)) * x3 * std::pow(x1 + x2, x3 - 1); + double x3Derivative = std::exp(x1 + std::exp(x2 + x3)) * std::exp(x2 + x3) * + std::pow(x1 + x2, x3) + + std::exp(x1 + std::exp(x2 + x3)) * + std::pow(x1 + x2, x3) * std::log(x1 + x2); double **u = myalloc2(3, 1); double **z = myalloc2(3, 3); @@ -747,12 +733,12 @@ BOOST_AUTO_TEST_CASE(ExpPowOperator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == -1.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == -1.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == -1.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == -2.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == -2.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == -2.*x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == -1. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == -1. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == -1. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == -2. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == -2. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == -2. * x3Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -766,8 +752,7 @@ BOOST_AUTO_TEST_CASE(ExpPowOperator_FOV_Reverse) * pow(x1*x2 + 2*x3, 0.25) * ) */ -BOOST_AUTO_TEST_CASE(CompositeSqrt_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeSqrt_FOV_Forward) { double x1 = -2.14, x2 = -2.22, x3 = 50.05, x4 = 0.104, out; adouble ax1, ax2, ax3, ax4; @@ -777,16 +762,16 @@ BOOST_AUTO_TEST_CASE(CompositeSqrt_FOV_Forward) ax3 <<= x3; ax4 <<= x4; - ax1 = sqrt(sqrt(ax1*ax2 + 2*ax3))*ax4; + ax1 = sqrt(sqrt(ax1 * ax2 + 2 * ax3)) * ax4; ax1 >>= out; trace_off(); - double x1Derivative = 0.25*std::pow(x1*x2 + 2*x3, -0.75)*x2*x4; - double x2Derivative = 0.25*std::pow(x1*x2 + 2*x3, -0.75)*x1*x4; - double x3Derivative = 0.25*std::pow(x1*x2 + 2*x3, -0.75)*2.0*x4; - double x4Derivative = std::pow(x1*x2 + 2*x3, 0.25); - x1 = std::sqrt(std::sqrt(x1*x2 + 2*x3))*x4; + double x1Derivative = 0.25 * std::pow(x1 * x2 + 2 * x3, -0.75) * x2 * x4; + double x2Derivative = 0.25 * std::pow(x1 * x2 + 2 * x3, -0.75) * x1 * x4; + double x3Derivative = 0.25 * std::pow(x1 * x2 + 2 * x3, -0.75) * 2.0 * x4; + double x4Derivative = std::pow(x1 * x2 + 2 * x3, 0.25); + x1 = std::sqrt(std::sqrt(x1 * x2 + 2 * x3)) * x4; double *x = myalloc1(4); double **xd = myalloc2(4, 4); @@ -822,8 +807,7 @@ BOOST_AUTO_TEST_CASE(CompositeSqrt_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeSqrtOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeSqrtOperator_FOV_Reverse) { double x1 = -2.14, x2 = -2.22, x3 = 50.05, x4 = 0.104, out; adouble ax1, ax2, ax3, ax4; @@ -833,15 +817,15 @@ BOOST_AUTO_TEST_CASE(CompositeSqrtOperator_FOV_Reverse) ax3 <<= x3; ax4 <<= x4; - ax1 = sqrt(sqrt(ax1*ax2 + 2*ax3))*ax4; + ax1 = sqrt(sqrt(ax1 * ax2 + 2 * ax3)) * ax4; ax1 >>= out; trace_off(); - double x1Derivative = 0.25*std::pow(x1*x2 + 2*x3, -0.75)*x2*x4; - double x2Derivative = 0.25*std::pow(x1*x2 + 2*x3, -0.75)*x1*x4; - double x3Derivative = 0.25*std::pow(x1*x2 + 2*x3, -0.75)*2.0*x4; - double x4Derivative = std::pow(x1*x2 + 2*x3, 0.25); + double x1Derivative = 0.25 * std::pow(x1 * x2 + 2 * x3, -0.75) * x2 * x4; + double x2Derivative = 0.25 * std::pow(x1 * x2 + 2 * x3, -0.75) * x1 * x4; + double x3Derivative = 0.25 * std::pow(x1 * x2 + 2 * x3, -0.75) * 2.0 * x4; + double x4Derivative = std::pow(x1 * x2 + 2 * x3, 0.25); double **u = myalloc2(4, 1); double **z = myalloc2(4, 4); @@ -857,18 +841,18 @@ BOOST_AUTO_TEST_CASE(CompositeSqrtOperator_FOV_Reverse) BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][3] == x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == -1.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == -1.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == -1.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][3] == -1.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == 2.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == 2.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == 2.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][3] == 2.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][0] == -2.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][1] == -2.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][2] == -2.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][3] == -2.*x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == -1. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == -1. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == -1. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][3] == -1. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == 2. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == 2. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == 2. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][3] == 2. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][0] == -2. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][1] == -2. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][2] == -2. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][3] == -2. * x4Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -884,8 +868,7 @@ BOOST_AUTO_TEST_CASE(CompositeSqrtOperator_FOV_Reverse) * exp(cosh(x4)) * sinh(x4) * ) */ -BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Forward) { double x1 = 0.1, x2 = 5.099, x3 = 5.5, x4 = 4.73, out; adouble ax1, ax2, ax3, ax4; @@ -895,21 +878,25 @@ BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Forward) ax3 <<= x3; ax4 <<= x4; - ax1 = tanh(acos(pow(ax1, 2) + 0.5)*sin(ax2))*ax3 + exp(cosh(ax4)); + ax1 = tanh(acos(pow(ax1, 2) + 0.5) * sin(ax2)) * ax3 + exp(cosh(ax4)); ax1 >>= out; trace_off(); - double x1Derivative = -(1 - std::pow(std::tanh(std::acos(std::pow(x1, 2)+0.5) - * std::sin(x2)), 2)) * x3 * std::sin(x2) * 2. * x1 - / (std::sqrt(1. - std::pow(std::pow(x1, 2) + 0.5, 2))); - double x2Derivative = (1 - std::pow(std::tanh(std::acos(std::pow(x1, 2)+0.5) - * std::sin(x2)), 2)) * x3 * std::acos(std::pow(x1, 2) - + 0.5) * std::cos(x2); - double x3Derivative = std::tanh(std::acos(std::pow(x1, 2)+0.5)*std::sin(x2)); - double x4Derivative = std::exp(std::cosh(x4))*std::sinh(x4); - x1 = std::tanh(std::acos(std::pow(x1, 2) + 0.5)*std::sin(x2))*x3 - + std::exp(std::cosh(x4)); + double x1Derivative = + -(1 - std::pow(std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)), + 2)) * + x3 * std::sin(x2) * 2. * x1 / + (std::sqrt(1. - std::pow(std::pow(x1, 2) + 0.5, 2))); + double x2Derivative = + (1 - std::pow(std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)), + 2)) * + x3 * std::acos(std::pow(x1, 2) + 0.5) * std::cos(x2); + double x3Derivative = + std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)); + double x4Derivative = std::exp(std::cosh(x4)) * std::sinh(x4); + x1 = std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)) * x3 + + std::exp(std::cosh(x4)); double *x = myalloc1(4); double **xd = myalloc2(4, 4); @@ -945,8 +932,7 @@ BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Reverse) { double x1 = 0.1, x2 = 5.099, x3 = 5.5, x4 = 4.73, out; adouble ax1, ax2, ax3, ax4; @@ -956,19 +942,23 @@ BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Reverse) ax3 <<= x3; ax4 <<= x4; - ax1 = tanh(acos(pow(ax1, 2) + 0.5)*sin(ax2))*ax3 + exp(cosh(ax4)); + ax1 = tanh(acos(pow(ax1, 2) + 0.5) * sin(ax2)) * ax3 + exp(cosh(ax4)); ax1 >>= out; trace_off(); - double x1Derivative = -(1 - std::pow(std::tanh(std::acos(std::pow(x1, 2)+0.5) - * std::sin(x2)), 2)) * x3 * std::sin(x2) * 2. * x1 - / (std::sqrt(1. - std::pow(std::pow(x1, 2) + 0.5, 2))); - double x2Derivative = (1 - std::pow(std::tanh(std::acos(std::pow(x1, 2)+0.5) - * std::sin(x2)), 2)) * x3 * std::acos(std::pow(x1, 2) - + 0.5) * std::cos(x2); - double x3Derivative = std::tanh(std::acos(std::pow(x1, 2)+0.5)*std::sin(x2)); - double x4Derivative = std::exp(std::cosh(x4))*std::sinh(x4); + double x1Derivative = + -(1 - std::pow(std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)), + 2)) * + x3 * std::sin(x2) * 2. * x1 / + (std::sqrt(1. - std::pow(std::pow(x1, 2) + 0.5, 2))); + double x2Derivative = + (1 - std::pow(std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)), + 2)) * + x3 * std::acos(std::pow(x1, 2) + 0.5) * std::cos(x2); + double x3Derivative = + std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)); + double x4Derivative = std::exp(std::cosh(x4)) * std::sinh(x4); double **u = myalloc2(4, 1); double **z = myalloc2(4, 4); @@ -984,18 +974,18 @@ BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Reverse) BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][3] == x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::exp(1.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::exp(1.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == std::exp(1.)*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][3] == std::exp(1.)*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == -2.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == -2.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == -2.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][3] == -2.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][0] == std::exp(2.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][1] == std::exp(2.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][2] == std::exp(2.)*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][3] == std::exp(2.)*x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::exp(1.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::exp(1.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == std::exp(1.) * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][3] == std::exp(1.) * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == -2. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == -2. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == -2. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][3] == -2. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][0] == std::exp(2.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][1] == std::exp(2.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][2] == std::exp(2.) * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][3] == std::exp(2.) * x4Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -1008,8 +998,7 @@ BOOST_AUTO_TEST_CASE(CompositeHyperbOperator_FOV_Reverse) * 2.0*x1*x3*exp(x3) + x1*pow(x3, 2)*exp(x3) * ) */ -BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Forward) { double x1 = 2.31, x2 = 1.32, x3 = 3.21, out; adouble ax1, ax2, ax3; @@ -1018,16 +1007,16 @@ BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ax1 = fmax(ax1*pow(ax3, 2), ax2*pow(ax3, 2))*exp(ax3); + ax1 = fmax(ax1 * pow(ax3, 2), ax2 * pow(ax3, 2)) * exp(ax3); ax1 >>= out; trace_off(); - double x1Derivative = std::pow(x3, 2)*std::exp(x3); + double x1Derivative = std::pow(x3, 2) * std::exp(x3); double x2Derivative = 0.0; - double x3Derivative = 2.0*x1*x3*std::exp(x3) - + x1*std::pow(x3, 2)*std::exp(x3); - x1 = std::fmax(x1*std::pow(x3, 2), x2*std::pow(x3, 2))*std::exp(x3); + double x3Derivative = + 2.0 * x1 * x3 * std::exp(x3) + x1 * std::pow(x3, 2) * std::exp(x3); + x1 = std::fmax(x1 * std::pow(x3, 2), x2 * std::pow(x3, 2)) * std::exp(x3); double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -1061,8 +1050,7 @@ BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Reverse) { double x1 = 2.31, x2 = 1.32, x3 = 3.21, out; adouble ax1, ax2, ax3; @@ -1071,15 +1059,15 @@ BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ax1 = fmax(ax1*pow(ax3, 2), ax2*pow(ax3, 2))*exp(ax3); + ax1 = fmax(ax1 * pow(ax3, 2), ax2 * pow(ax3, 2)) * exp(ax3); ax1 >>= out; trace_off(); - double x1Derivative = std::pow(x3, 2)*std::exp(x3); + double x1Derivative = std::pow(x3, 2) * std::exp(x3); double x2Derivative = 0.0; - double x3Derivative = 2.0*x1*x3*std::exp(x3) - + x1*std::pow(x3, 2)*std::exp(x3); + double x3Derivative = + 2.0 * x1 * x3 * std::exp(x3) + x1 * std::pow(x3, 2) * std::exp(x3); double **u = myalloc2(3, 1); double **z = myalloc2(3, 3); @@ -1093,12 +1081,12 @@ BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::sqrt(5.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::sqrt(5.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == std::sqrt(5.)*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == -std::sqrt(10.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == -std::sqrt(10.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == -std::sqrt(10.)*x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::sqrt(5.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::sqrt(5.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == std::sqrt(5.) * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == -std::sqrt(10.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == -std::sqrt(10.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == -std::sqrt(10.) * x3Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -1111,8 +1099,7 @@ BOOST_AUTO_TEST_CASE(CompositeFmaxOperator_FOV_Reverse) * 2.0*x2*x3*exp(x3) + x2*pow(x3, 2)*exp(x3) * ) */ -BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Forward) { double x1 = 2.31, x2 = 1.32, x3 = 3.21, out; adouble ax1, ax2, ax3; @@ -1121,16 +1108,16 @@ BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ax1 = fmin(ax1*pow(ax3, 2), ax2*pow(ax3, 2))*exp(ax3); + ax1 = fmin(ax1 * pow(ax3, 2), ax2 * pow(ax3, 2)) * exp(ax3); ax1 >>= out; trace_off(); double x1Derivative = 0.0; - double x2Derivative = std::pow(x3, 2)*std::exp(x3); - double x3Derivative = 2.0*x2*x3*std::exp(x3) - + x2*std::pow(x3, 2)*std::exp(x3); - x1 = std::fmin(x1*std::pow(x3, 2), x2*std::pow(x3, 2))*std::exp(x3); + double x2Derivative = std::pow(x3, 2) * std::exp(x3); + double x3Derivative = + 2.0 * x2 * x3 * std::exp(x3) + x2 * std::pow(x3, 2) * std::exp(x3); + x1 = std::fmin(x1 * std::pow(x3, 2), x2 * std::pow(x3, 2)) * std::exp(x3); double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -1164,8 +1151,7 @@ BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Reverse) { double x1 = 2.31, x2 = 1.32, x3 = 3.21, out; adouble ax1, ax2, ax3; @@ -1174,15 +1160,15 @@ BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ax1 = fmin(ax1*pow(ax3, 2), ax2*pow(ax3, 2))*exp(ax3); + ax1 = fmin(ax1 * pow(ax3, 2), ax2 * pow(ax3, 2)) * exp(ax3); ax1 >>= out; trace_off(); double x1Derivative = 0.0; - double x2Derivative = std::pow(x3, 2)*std::exp(x3); - double x3Derivative = 2.0*x2*x3*std::exp(x3) - + x2*std::pow(x3, 2)*std::exp(x3); + double x2Derivative = std::pow(x3, 2) * std::exp(x3); + double x3Derivative = + 2.0 * x2 * x3 * std::exp(x3) + x2 * std::pow(x3, 2) * std::exp(x3); double **u = myalloc2(3, 1); double **z = myalloc2(3, 3); @@ -1196,12 +1182,12 @@ BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::sqrt(6.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::sqrt(6.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == std::sqrt(6.)*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == -std::sqrt(3.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == -std::sqrt(3.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == -std::sqrt(3.)*x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::sqrt(6.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::sqrt(6.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == std::sqrt(6.) * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == -std::sqrt(3.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == -std::sqrt(3.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == -std::sqrt(3.) * x3Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -1222,8 +1208,7 @@ BOOST_AUTO_TEST_CASE(CompositeFminOperator_FOV_Reverse) * erf(fabs(x1 - x2)*sinh(x3 - x4))*cos(x5) * ) */ -BOOST_AUTO_TEST_CASE(CompositeErfFabs_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CompositeErfFabs_FOV_Forward) { double x1 = 4.56, x2 = 5.46, x3 = 4.65, x4 = 6.54, x5 = 6.45, out; adouble ax1, ax2, ax3, ax4, ax5; @@ -1234,30 +1219,30 @@ BOOST_AUTO_TEST_CASE(CompositeErfFabs_FOV_Forward) ax4 <<= x4; ax5 <<= x5; - ax1 = erf(fabs(ax1 - ax2)*sinh(ax3 - ax4))*sin(ax5); + ax1 = erf(fabs(ax1 - ax2) * sinh(ax3 - ax4)) * sin(ax5); ax1 >>= out; trace_off(); - double x1Derivative = -2./std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - x2) - * std::sinh(x3 - x4), 2)) * std::sin(x5) - * std::sinh(x3 - x4); - double x2Derivative = 2./std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - x2) - * std::sinh(x3 - x4), 2)) * std::sin(x5) - * std::sinh(x3 - x4); - double x3Derivative = 2./std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - x2) - * std::sinh(x3 - x4), 2)) * std::sin(x5) - * std::fabs(x1 - x2) * std::cosh(x3 - x4); - double x4Derivative = -2./std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - x2) - * std::sinh(x3 - x4), 2)) * std::sin(x5) - * std::fabs(x1 - x2) * std::cosh(x3 - x4); - double x5Derivative = std::erf(std::fabs(x1 - x2)*std::sinh(x3 - x4)) - * std::cos(x5); - x1 = std::erf(std::fabs(x1 - x2)*std::sinh(x3 - x4))*std::sin(x5); + double x1Derivative = + -2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - x2) * std::sinh(x3 - x4), 2)) * + std::sin(x5) * std::sinh(x3 - x4); + double x2Derivative = + 2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - x2) * std::sinh(x3 - x4), 2)) * + std::sin(x5) * std::sinh(x3 - x4); + double x3Derivative = + 2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - x2) * std::sinh(x3 - x4), 2)) * + std::sin(x5) * std::fabs(x1 - x2) * std::cosh(x3 - x4); + double x4Derivative = + -2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - x2) * std::sinh(x3 - x4), 2)) * + std::sin(x5) * std::fabs(x1 - x2) * std::cosh(x3 - x4); + double x5Derivative = + std::erf(std::fabs(x1 - x2) * std::sinh(x3 - x4)) * std::cos(x5); + x1 = std::erf(std::fabs(x1 - x2) * std::sinh(x3 - x4)) * std::sin(x5); double *x = myalloc1(5); double **xd = myalloc2(5, 5); @@ -1295,8 +1280,7 @@ BOOST_AUTO_TEST_CASE(CompositeErfFabs_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CompositeErfFabsOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CompositeErfFabsOperator_FOV_Reverse) { double x1 = 4.56, x2 = 5.46, x3 = 4.65, x4 = 6.54, x5 = 6.45, out; adouble ax1, ax2, ax3, ax4, ax5; @@ -1307,29 +1291,29 @@ BOOST_AUTO_TEST_CASE(CompositeErfFabsOperator_FOV_Reverse) ax4 <<= x4; ax5 <<= x5; - ax1 = erf(fabs(ax1 - ax2)*sinh(ax3 - ax4))*sin(ax5); + ax1 = erf(fabs(ax1 - ax2) * sinh(ax3 - ax4)) * sin(ax5); ax1 >>= out; trace_off(); - double x1Derivative = -2./std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - x2) - * std::sinh(x3 - x4), 2)) * std::sin(x5) - * std::sinh(x3 - x4); - double x2Derivative = 2./std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - x2) - * std::sinh(x3 - x4), 2)) * std::sin(x5) - * std::sinh(x3 - x4); - double x3Derivative = 2./std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - x2) - * std::sinh(x3 - x4), 2)) * std::sin(x5) - * std::fabs(x1 - x2) * std::cosh(x3 - x4); - double x4Derivative = -2./std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - x2) - * std::sinh(x3 - x4), 2)) * std::sin(x5) - * std::fabs(x1 - x2) * std::cosh(x3 - x4); - double x5Derivative = std::erf(std::fabs(x1 - x2)*std::sinh(x3 - x4)) - * std::cos(x5); + double x1Derivative = + -2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - x2) * std::sinh(x3 - x4), 2)) * + std::sin(x5) * std::sinh(x3 - x4); + double x2Derivative = + 2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - x2) * std::sinh(x3 - x4), 2)) * + std::sin(x5) * std::sinh(x3 - x4); + double x3Derivative = + 2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - x2) * std::sinh(x3 - x4), 2)) * + std::sin(x5) * std::fabs(x1 - x2) * std::cosh(x3 - x4); + double x4Derivative = + -2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - x2) * std::sinh(x3 - x4), 2)) * + std::sin(x5) * std::fabs(x1 - x2) * std::cosh(x3 - x4); + double x5Derivative = + std::erf(std::fabs(x1 - x2) * std::sinh(x3 - x4)) * std::cos(x5); double **u = myalloc2(5, 1); double **z = myalloc2(5, 5); @@ -1347,26 +1331,26 @@ BOOST_AUTO_TEST_CASE(CompositeErfFabsOperator_FOV_Reverse) BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][3] == x4Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][4] == x5Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::sqrt(5.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::sqrt(5.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == std::sqrt(5.)*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][3] == std::sqrt(5.)*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][4] == std::sqrt(5.)*x5Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == -std::sqrt(2.)*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == -std::sqrt(2.)*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == -std::sqrt(2.)*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][3] == -std::sqrt(2.)*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][4] == -std::sqrt(2.)*x5Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][0] == 7.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][1] == 7.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][2] == 7.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][3] == 7.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[3][4] == 7.*x5Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][0] == -9.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][1] == -9.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][2] == -9.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][3] == -9.*x4Derivative, tt::tolerance(tol)); - BOOST_TEST(z[4][4] == -9.*x5Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::sqrt(5.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::sqrt(5.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == std::sqrt(5.) * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][3] == std::sqrt(5.) * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][4] == std::sqrt(5.) * x5Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == -std::sqrt(2.) * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == -std::sqrt(2.) * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == -std::sqrt(2.) * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][3] == -std::sqrt(2.) * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][4] == -std::sqrt(2.) * x5Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][0] == 7. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][1] == 7. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][2] == 7. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][3] == 7. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[3][4] == 7. * x5Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][0] == -9. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][1] == -9. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][2] == -9. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][3] == -9. * x4Derivative, tt::tolerance(tol)); + BOOST_TEST(z[4][4] == -9. * x5Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -1382,8 +1366,7 @@ BOOST_AUTO_TEST_CASE(CompositeErfFabsOperator_FOV_Reverse) * * log(sqrt(x2)) * ) */ -BOOST_AUTO_TEST_CASE(ExpTrigSqrt_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(ExpTrigSqrt_FOV_Forward) { double x1 = 2.1, x2 = 1.2, x3 = 0.12, out; adouble ax1, ax2, ax3; @@ -1392,22 +1375,20 @@ BOOST_AUTO_TEST_CASE(ExpTrigSqrt_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ax1 = 5. * exp(sin(ax1)*cos(ax1)) * pow(sqrt(ax2), ax3); + ax1 = 5. * exp(sin(ax1) * cos(ax1)) * pow(sqrt(ax2), ax3); ax1 >>= out; trace_off(); - double x1Derivative = 5. * std::exp(std::sin(x1)*std::cos(x1)) - * (std::cos(x1)*std::cos(x1) - - std::sin(x1)*std::sin(x1)) - * std::pow(std::sqrt(x2), x3); - double x2Derivative = 5. * std::exp(std::sin(x1)*std::cos(x1)) - * x3 * std::pow(std::sqrt(x2), x3 - 1.) - / (2.*std::sqrt(x2)); - double x3Derivative = 5. * std::exp(std::sin(x1)*std::cos(x1)) - * std::pow(std::sqrt(x2), x3) - * std::log(std::sqrt(x2)); - x1 = 5.*std::exp(std::sin(x1)*std::cos(x1))*std::pow(std::sqrt(x2), x3); + double x1Derivative = + 5. * std::exp(std::sin(x1) * std::cos(x1)) * + (std::cos(x1) * std::cos(x1) - std::sin(x1) * std::sin(x1)) * + std::pow(std::sqrt(x2), x3); + double x2Derivative = 5. * std::exp(std::sin(x1) * std::cos(x1)) * x3 * + std::pow(std::sqrt(x2), x3 - 1.) / (2. * std::sqrt(x2)); + double x3Derivative = 5. * std::exp(std::sin(x1) * std::cos(x1)) * + std::pow(std::sqrt(x2), x3) * std::log(std::sqrt(x2)); + x1 = 5. * std::exp(std::sin(x1) * std::cos(x1)) * std::pow(std::sqrt(x2), x3); double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -1441,8 +1422,7 @@ BOOST_AUTO_TEST_CASE(ExpTrigSqrt_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(ExpTrigSqrtFabsOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(ExpTrigSqrtFabsOperator_FOV_Reverse) { double x1 = 2.1, x2 = 1.2, x3 = 0.12, out; adouble ax1, ax2, ax3; @@ -1451,21 +1431,19 @@ BOOST_AUTO_TEST_CASE(ExpTrigSqrtFabsOperator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ax1 = 5. * exp(sin(ax1)*cos(ax1)) * pow(sqrt(ax2), ax3); + ax1 = 5. * exp(sin(ax1) * cos(ax1)) * pow(sqrt(ax2), ax3); ax1 >>= out; trace_off(); - double x1Derivative = 5. * std::exp(std::sin(x1)*std::cos(x1)) - * (std::cos(x1)*std::cos(x1) - - std::sin(x1)*std::sin(x1)) - * std::pow(std::sqrt(x2), x3); - double x2Derivative = 5. * std::exp(std::sin(x1)*std::cos(x1)) - * x3 * std::pow(std::sqrt(x2), x3 - 1.) - / (2.*std::sqrt(x2)); - double x3Derivative = 5. * std::exp(std::sin(x1)*std::cos(x1)) - * std::pow(std::sqrt(x2), x3) - * std::log(std::sqrt(x2)); + double x1Derivative = + 5. * std::exp(std::sin(x1) * std::cos(x1)) * + (std::cos(x1) * std::cos(x1) - std::sin(x1) * std::sin(x1)) * + std::pow(std::sqrt(x2), x3); + double x2Derivative = 5. * std::exp(std::sin(x1) * std::cos(x1)) * x3 * + std::pow(std::sqrt(x2), x3 - 1.) / (2. * std::sqrt(x2)); + double x3Derivative = 5. * std::exp(std::sin(x1) * std::cos(x1)) * + std::pow(std::sqrt(x2), x3) * std::log(std::sqrt(x2)); double **u = myalloc2(3, 1); double **z = myalloc2(3, 3); @@ -1479,12 +1457,12 @@ BOOST_AUTO_TEST_CASE(ExpTrigSqrtFabsOperator_FOV_Reverse) BOOST_TEST(z[0][0] == x1Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == x2Derivative, tt::tolerance(tol)); BOOST_TEST(z[0][2] == x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 3.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == 3.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[1][2] == 3.*x3Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][0] == -5.*x1Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][1] == -5.*x2Derivative, tt::tolerance(tol)); - BOOST_TEST(z[2][2] == -5.*x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 3. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == 3. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[1][2] == 3. * x3Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][0] == -5. * x1Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][1] == -5. * x2Derivative, tt::tolerance(tol)); + BOOST_TEST(z[2][2] == -5. * x3Derivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -1507,8 +1485,7 @@ BOOST_AUTO_TEST_CASE(ExpTrigSqrtFabsOperator_FOV_Reverse) * (-x2/(x1*x1 + x2*x2), x1/(x1*x1 + x2*x2), 0.0) * ) */ -BOOST_AUTO_TEST_CASE(PolarCoord_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(PolarCoord_FOV_Forward) { double x1 = 8.17, x2 = -3.41, x3 = 10.01, out1, out2, out3; double y1, y2, y3; adouble ax1, ax2, ax3; @@ -1519,33 +1496,34 @@ BOOST_AUTO_TEST_CASE(PolarCoord_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ay1 = sqrt(ax1*ax1 + ax2*ax2 + ax3*ax3); - ay2 = atan(sqrt(ax1*ax1 + ax2*ax2)/ax3); - ay3 = atan(ax2/ax1); + ay1 = sqrt(ax1 * ax1 + ax2 * ax2 + ax3 * ax3); + ay2 = atan(sqrt(ax1 * ax1 + ax2 * ax2) / ax3); + ay3 = atan(ax2 / ax1); ay1 >>= out1; ay2 >>= out2; ay3 >>= out3; trace_off(); -/* The obvious naming convention is applied here: The derivative of - * component yi in the direction xj is saved in yixjDerivative. - */ - double y1x1Derivative = x1 / std::sqrt(x1*x1 + x2*x2 + x3*x3); - double y1x2Derivative = x2 / std::sqrt(x1*x1 + x2*x2 + x3*x3); - double y1x3Derivative = x3 / std::sqrt(x1*x1 + x2*x2 + x3*x3); - double y2x1Derivative = x1*x3 / ((x1*x1 + x2*x2 + x3*x3) - * std::sqrt(x1*x1 + x2*x2)); - double y2x2Derivative = x2*x3 / ((x1*x1 + x2*x2 + x3*x3) - * std::sqrt(x1*x1 + x2*x2)); - double y2x3Derivative = -std::sqrt(x1*x1 + x2*x2) / (x1*x1 + x2*x2 + x3*x3); - double y3x1Derivative = -x2 / (x1*x1 + x2*x2); - double y3x2Derivative = x1 / (x1*x1 + x2*x2); + /* The obvious naming convention is applied here: The derivative of + * component yi in the direction xj is saved in yixjDerivative. + */ + double y1x1Derivative = x1 / std::sqrt(x1 * x1 + x2 * x2 + x3 * x3); + double y1x2Derivative = x2 / std::sqrt(x1 * x1 + x2 * x2 + x3 * x3); + double y1x3Derivative = x3 / std::sqrt(x1 * x1 + x2 * x2 + x3 * x3); + double y2x1Derivative = + x1 * x3 / ((x1 * x1 + x2 * x2 + x3 * x3) * std::sqrt(x1 * x1 + x2 * x2)); + double y2x2Derivative = + x2 * x3 / ((x1 * x1 + x2 * x2 + x3 * x3) * std::sqrt(x1 * x1 + x2 * x2)); + double y2x3Derivative = + -std::sqrt(x1 * x1 + x2 * x2) / (x1 * x1 + x2 * x2 + x3 * x3); + double y3x1Derivative = -x2 / (x1 * x1 + x2 * x2); + double y3x2Derivative = x1 / (x1 * x1 + x2 * x2); double y3x3Derivative = 0.0; - y1 = std::sqrt(x1*x1 + x2*x2 + x3*x3); - y2 = std::atan(std::sqrt(x1*x1 + x2*x2)/x3); - y3 = std::atan(x2/x1); + y1 = std::sqrt(x1 * x1 + x2 * x2 + x3 * x3); + y2 = std::atan(std::sqrt(x1 * x1 + x2 * x2) / x3); + y3 = std::atan(x2 / x1); double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -1587,8 +1565,7 @@ BOOST_AUTO_TEST_CASE(PolarCoord_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(PolarCoordOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(PolarCoordOperator_FOV_Reverse) { double x1 = 8.17, x2 = -3.41, x3 = 10.01, out1, out2, out3; double y1, y2, y3; adouble ax1, ax2, ax3; @@ -1599,28 +1576,29 @@ BOOST_AUTO_TEST_CASE(PolarCoordOperator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = sqrt(ax1*ax1 + ax2*ax2 + ax3*ax3); - ay2 = atan(sqrt(ax1*ax1 + ax2*ax2)/ax3); - ay3 = atan(ax2/ax1); + ay1 = sqrt(ax1 * ax1 + ax2 * ax2 + ax3 * ax3); + ay2 = atan(sqrt(ax1 * ax1 + ax2 * ax2) / ax3); + ay3 = atan(ax2 / ax1); ay1 >>= out1; ay2 >>= out2; ay3 >>= out3; trace_off(); -/* The obvious naming convention is applied here: The derivative of - * component yi in the direction xj is saved in yixjDerivative. - */ - double y1x1Derivative = x1 / std::sqrt(x1*x1 + x2*x2 + x3*x3); - double y1x2Derivative = x2 / std::sqrt(x1*x1 + x2*x2 + x3*x3); - double y1x3Derivative = x3 / std::sqrt(x1*x1 + x2*x2 + x3*x3); - double y2x1Derivative = x1*x3 / ((x1*x1 + x2*x2 + x3*x3) - * std::sqrt(x1*x1 + x2*x2)); - double y2x2Derivative = x2*x3 / ((x1*x1 + x2*x2 + x3*x3) - * std::sqrt(x1*x1 + x2*x2)); - double y2x3Derivative = -std::sqrt(x1*x1 + x2*x2) / (x1*x1 + x2*x2 + x3*x3); - double y3x1Derivative = -x2 / (x1*x1 + x2*x2); - double y3x2Derivative = x1 / (x1*x1 + x2*x2); + /* The obvious naming convention is applied here: The derivative of + * component yi in the direction xj is saved in yixjDerivative. + */ + double y1x1Derivative = x1 / std::sqrt(x1 * x1 + x2 * x2 + x3 * x3); + double y1x2Derivative = x2 / std::sqrt(x1 * x1 + x2 * x2 + x3 * x3); + double y1x3Derivative = x3 / std::sqrt(x1 * x1 + x2 * x2 + x3 * x3); + double y2x1Derivative = + x1 * x3 / ((x1 * x1 + x2 * x2 + x3 * x3) * std::sqrt(x1 * x1 + x2 * x2)); + double y2x2Derivative = + x2 * x3 / ((x1 * x1 + x2 * x2 + x3 * x3) * std::sqrt(x1 * x1 + x2 * x2)); + double y2x3Derivative = + -std::sqrt(x1 * x1 + x2 * x2) / (x1 * x1 + x2 * x2 + x3 * x3); + double y3x1Derivative = -x2 / (x1 * x1 + x2 * x2); + double y3x2Derivative = x1 / (x1 * x1 + x2 * x2); double y3x3Derivative = 0.0; double **u = myalloc2(3, 3); @@ -1660,8 +1638,7 @@ BOOST_AUTO_TEST_CASE(PolarCoordOperator_FOV_Reverse) * (x2, x1, 0.0) * ) */ -BOOST_AUTO_TEST_CASE(SimpleProd_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(SimpleProd_FOV_Forward) { double x1 = 2.52, x2 = 5.22, x3 = -2.25, out1, out2, out3; double y1, y2, y3; adouble ax1, ax2, ax3; @@ -1672,9 +1649,9 @@ BOOST_AUTO_TEST_CASE(SimpleProd_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ay1 = ax2*ax3; - ay2 = ax1*ax3; - ay3 = ax1*ax2; + ay1 = ax2 * ax3; + ay2 = ax1 * ax3; + ay3 = ax1 * ax2; ay1 >>= out1; ay2 >>= out2; @@ -1691,9 +1668,9 @@ BOOST_AUTO_TEST_CASE(SimpleProd_FOV_Forward) double y3x2Derivative = x1; double y3x3Derivative = 0.0; - y1 = x2*x3; - y2 = x1*x3; - y3 = x1*x2; + y1 = x2 * x3; + y2 = x1 * x3; + y3 = x1 * x2; double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -1734,8 +1711,7 @@ BOOST_AUTO_TEST_CASE(SimpleProd_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(SimpleProdOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(SimpleProdOperator_FOV_Reverse) { double x1 = 2.52, x2 = 5.22, x3 = -2.25, out1, out2, out3; double y1, y2, y3; adouble ax1, ax2, ax3; @@ -1746,9 +1722,9 @@ BOOST_AUTO_TEST_CASE(SimpleProdOperator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = ax2*ax3; - ay2 = ax1*ax3; - ay3 = ax1*ax2; + ay1 = ax2 * ax3; + ay2 = ax1 * ax3; + ay3 = ax1 * ax2; ay1 >>= out1; ay2 >>= out2; @@ -1802,8 +1778,7 @@ BOOST_AUTO_TEST_CASE(SimpleProdOperator_FOV_Reverse) * (1.0, 1.0, 0.0) * ) */ -BOOST_AUTO_TEST_CASE(SimpleSum_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(SimpleSum_FOV_Forward) { double x1 = 2.52, x2 = 5.22, x3 = -2.25, out1, out2, out3; double y1, y2, y3; adouble ax1, ax2, ax3; @@ -1876,8 +1851,7 @@ BOOST_AUTO_TEST_CASE(SimpleSum_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(SimpleSumOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(SimpleSumOperator_FOV_Reverse) { double x1 = 2.52, x2 = 5.22, x3 = -2.25, out1, out2, out3; double y1, y2, y3; adouble ax1, ax2, ax3; @@ -1950,8 +1924,7 @@ BOOST_AUTO_TEST_CASE(SimpleSumOperator_FOV_Reverse) * -(x1 + x2)/(pow(x1 + x2, 2) + pow(x3 + x4, 2))) * ) */ -BOOST_AUTO_TEST_CASE(TrigProd_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(TrigProd_FOV_Forward) { double x1 = 5.5, x2 = 0.5, x3 = 5.55, x4 = 2.33, out1, out2, out3, out4; double y1, y2, y3, y4; adouble ax1, ax2, ax3, ax4; @@ -1963,10 +1936,10 @@ BOOST_AUTO_TEST_CASE(TrigProd_FOV_Forward) ax3 <<= x3; ax4 <<= x4; - ay1 = ax1*cos(ax2) + sqrt(ax3*ax4); + ay1 = ax1 * cos(ax2) + sqrt(ax3 * ax4); ay2 = ax4; - ay3 = ax1*ax2*ax3*ax4; - ay4 = atan((ax1 + ax2)/(ax3 + ax4)); + ay3 = ax1 * ax2 * ax3 * ax4; + ay4 = atan((ax1 + ax2) / (ax3 + ax4)); ay1 >>= out1; ay2 >>= out2; @@ -1975,30 +1948,30 @@ BOOST_AUTO_TEST_CASE(TrigProd_FOV_Forward) trace_off(); double y1x1Derivative = std::cos(x2); - double y1x2Derivative = -x1*std::sin(x2); - double y1x3Derivative = 0.5*std::sqrt(x4/x3); - double y1x4Derivative = 0.5*std::sqrt(x3/x4); + double y1x2Derivative = -x1 * std::sin(x2); + double y1x3Derivative = 0.5 * std::sqrt(x4 / x3); + double y1x4Derivative = 0.5 * std::sqrt(x3 / x4); double y2x1Derivative = 0.0; double y2x2Derivative = 0.0; double y2x3Derivative = 0.0; double y2x4Derivative = 1.0; - double y3x1Derivative = x2*x3*x4; - double y3x2Derivative = x1*x3*x4; - double y3x3Derivative = x1*x2*x4; - double y3x4Derivative = x1*x2*x3; - double y4x1Derivative = (x3 + x4)/(std::pow(x1 + x2, 2) - + std::pow(x3 + x4, 2)); - double y4x2Derivative = (x3 + x4)/(std::pow(x1 + x2, 2) - + std::pow(x3 + x4, 2)); - double y4x3Derivative = -(x1 + x2)/(std::pow(x1 + x2, 2) - + std::pow(x3 + x4, 2)); - double y4x4Derivative = -(x1 + x2)/(std::pow(x1 + x2, 2) - + std::pow(x3 + x4, 2)); - - y1 = x1*std::cos(x2) + std::sqrt(x3*x4); + double y3x1Derivative = x2 * x3 * x4; + double y3x2Derivative = x1 * x3 * x4; + double y3x3Derivative = x1 * x2 * x4; + double y3x4Derivative = x1 * x2 * x3; + double y4x1Derivative = + (x3 + x4) / (std::pow(x1 + x2, 2) + std::pow(x3 + x4, 2)); + double y4x2Derivative = + (x3 + x4) / (std::pow(x1 + x2, 2) + std::pow(x3 + x4, 2)); + double y4x3Derivative = + -(x1 + x2) / (std::pow(x1 + x2, 2) + std::pow(x3 + x4, 2)); + double y4x4Derivative = + -(x1 + x2) / (std::pow(x1 + x2, 2) + std::pow(x3 + x4, 2)); + + y1 = x1 * std::cos(x2) + std::sqrt(x3 * x4); y2 = x4; - y3 = x1*x2*x3*x4; - y4 = std::atan((x1 + x2)/(x3 + x4)); + y3 = x1 * x2 * x3 * x4; + y4 = std::atan((x1 + x2) / (x3 + x4)); double *x = myalloc1(4); double **xd = myalloc2(4, 4); @@ -2048,8 +2021,7 @@ BOOST_AUTO_TEST_CASE(TrigProd_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(TrigProdOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(TrigProdOperator_FOV_Reverse) { double x1 = 5.5, x2 = 0.5, x3 = 5.55, x4 = 2.33, out1, out2, out3, out4; double y1, y2, y3, y4; adouble ax1, ax2, ax3, ax4; @@ -2061,10 +2033,10 @@ BOOST_AUTO_TEST_CASE(TrigProdOperator_FOV_Reverse) ax3 <<= x3; ax4 <<= x4; - ay1 = ax1*cos(ax2) + sqrt(ax3*ax4); + ay1 = ax1 * cos(ax2) + sqrt(ax3 * ax4); ay2 = ax4; - ay3 = ax1*ax2*ax3*ax4; - ay4 = atan((ax1 + ax2)/(ax3 + ax4)); + ay3 = ax1 * ax2 * ax3 * ax4; + ay4 = atan((ax1 + ax2) / (ax3 + ax4)); ay1 >>= out1; ay2 >>= out2; @@ -2073,25 +2045,25 @@ BOOST_AUTO_TEST_CASE(TrigProdOperator_FOV_Reverse) trace_off(); double y1x1Derivative = std::cos(x2); - double y1x2Derivative = -x1*std::sin(x2); - double y1x3Derivative = 0.5*std::sqrt(x4/x3); - double y1x4Derivative = 0.5*std::sqrt(x3/x4); + double y1x2Derivative = -x1 * std::sin(x2); + double y1x3Derivative = 0.5 * std::sqrt(x4 / x3); + double y1x4Derivative = 0.5 * std::sqrt(x3 / x4); double y2x1Derivative = 0.0; double y2x2Derivative = 0.0; double y2x3Derivative = 0.0; double y2x4Derivative = 1.0; - double y3x1Derivative = x2*x3*x4; - double y3x2Derivative = x1*x3*x4; - double y3x3Derivative = x1*x2*x4; - double y3x4Derivative = x1*x2*x3; - double y4x1Derivative = (x3 + x4)/(std::pow(x1 + x2, 2) - + std::pow(x3 + x4, 2)); - double y4x2Derivative = (x3 + x4)/(std::pow(x1 + x2, 2) - + std::pow(x3 + x4, 2)); - double y4x3Derivative = -(x1 + x2)/(std::pow(x1 + x2, 2) - + std::pow(x3 + x4, 2)); - double y4x4Derivative = -(x1 + x2)/(std::pow(x1 + x2, 2) - + std::pow(x3 + x4, 2)); + double y3x1Derivative = x2 * x3 * x4; + double y3x2Derivative = x1 * x3 * x4; + double y3x3Derivative = x1 * x2 * x4; + double y3x4Derivative = x1 * x2 * x3; + double y4x1Derivative = + (x3 + x4) / (std::pow(x1 + x2, 2) + std::pow(x3 + x4, 2)); + double y4x2Derivative = + (x3 + x4) / (std::pow(x1 + x2, 2) + std::pow(x3 + x4, 2)); + double y4x3Derivative = + -(x1 + x2) / (std::pow(x1 + x2, 2) + std::pow(x3 + x4, 2)); + double y4x4Derivative = + -(x1 + x2) / (std::pow(x1 + x2, 2) + std::pow(x3 + x4, 2)); double **u = myalloc2(4, 4); double **z = myalloc2(4, 4); @@ -2139,8 +2111,7 @@ BOOST_AUTO_TEST_CASE(TrigProdOperator_FOV_Reverse) * (cos(x3), 0.0, -x1*sin(x3)), * ) */ -BOOST_AUTO_TEST_CASE(PolarCoordInv_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(PolarCoordInv_FOV_Forward) { double x1 = 4.21, x2 = -0.98, x3 = 3.02, out1, out2, out3; double y1, y2, y3; adouble ax1, ax2, ax3; @@ -2151,28 +2122,28 @@ BOOST_AUTO_TEST_CASE(PolarCoordInv_FOV_Forward) ax2 <<= x2; ax3 <<= x3; - ay1 = ax1*cos(ax2)*sin(ax3); - ay2 = ax1*sin(ax2)*sin(ax3); - ay3 = ax1*cos(ax3); + ay1 = ax1 * cos(ax2) * sin(ax3); + ay2 = ax1 * sin(ax2) * sin(ax3); + ay3 = ax1 * cos(ax3); ay1 >>= out1; ay2 >>= out2; ay3 >>= out3; trace_off(); - double y1x1Derivative = std::cos(x2)*std::sin(x3); - double y1x2Derivative = -x1*std::sin(x2)*std::sin(x3); - double y1x3Derivative = x1*std::cos(x2)*std::cos(x3); - double y2x1Derivative = std::sin(x2)*std::sin(x3); - double y2x2Derivative = x1*std::cos(x2)*std::sin(x3); - double y2x3Derivative = x1*std::sin(x2)*std::cos(x3); + double y1x1Derivative = std::cos(x2) * std::sin(x3); + double y1x2Derivative = -x1 * std::sin(x2) * std::sin(x3); + double y1x3Derivative = x1 * std::cos(x2) * std::cos(x3); + double y2x1Derivative = std::sin(x2) * std::sin(x3); + double y2x2Derivative = x1 * std::cos(x2) * std::sin(x3); + double y2x3Derivative = x1 * std::sin(x2) * std::cos(x3); double y3x1Derivative = std::cos(x3); double y3x2Derivative = 0.0; - double y3x3Derivative = -x1*std::sin(x3); + double y3x3Derivative = -x1 * std::sin(x3); - y1 = x1*std::cos(x2)*std::sin(x3); - y2 = x1*std::sin(x2)*std::sin(x3); - y3 = x1*std::cos(x3); + y1 = x1 * std::cos(x2) * std::sin(x3); + y2 = x1 * std::sin(x2) * std::sin(x3); + y3 = x1 * std::cos(x3); double *x = myalloc1(3); double **xd = myalloc2(3, 3); @@ -2213,8 +2184,7 @@ BOOST_AUTO_TEST_CASE(PolarCoordInv_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(PolarCoordInvProdOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(PolarCoordInvProdOperator_FOV_Reverse) { double x1 = 4.21, x2 = -0.98, x3 = 3.02, out1, out2, out3; double y1, y2, y3; adouble ax1, ax2, ax3; @@ -2225,24 +2195,24 @@ BOOST_AUTO_TEST_CASE(PolarCoordInvProdOperator_FOV_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = ax1*cos(ax2)*sin(ax3); - ay2 = ax1*sin(ax2)*sin(ax3); - ay3 = ax1*cos(ax3); + ay1 = ax1 * cos(ax2) * sin(ax3); + ay2 = ax1 * sin(ax2) * sin(ax3); + ay3 = ax1 * cos(ax3); ay1 >>= out1; ay2 >>= out2; ay3 >>= out3; trace_off(); - double y1x1Derivative = std::cos(x2)*std::sin(x3); - double y1x2Derivative = -x1*std::sin(x2)*std::sin(x3); - double y1x3Derivative = x1*std::cos(x2)*std::cos(x3); - double y2x1Derivative = std::sin(x2)*std::sin(x3); - double y2x2Derivative = x1*std::cos(x2)*std::sin(x3); - double y2x3Derivative = x1*std::sin(x2)*std::cos(x3); + double y1x1Derivative = std::cos(x2) * std::sin(x3); + double y1x2Derivative = -x1 * std::sin(x2) * std::sin(x3); + double y1x3Derivative = x1 * std::cos(x2) * std::cos(x3); + double y2x1Derivative = std::sin(x2) * std::sin(x3); + double y2x2Derivative = x1 * std::cos(x2) * std::sin(x3); + double y2x3Derivative = x1 * std::sin(x2) * std::cos(x3); double y3x1Derivative = std::cos(x3); double y3x2Derivative = 0.0; - double y3x3Derivative = -x1*std::sin(x3); + double y3x3Derivative = -x1 * std::sin(x3); double **u = myalloc2(3, 3); double **z = myalloc2(3, 3); @@ -2286,8 +2256,7 @@ BOOST_AUTO_TEST_CASE(PolarCoordInvProdOperator_FOV_Reverse) * (sinh(x1)/sinh(x2), -cosh(x1)/(sinh(x2)*cosh(x2))) * ) */ -BOOST_AUTO_TEST_CASE(MultiHyperb_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(MultiHyperb_FOV_Forward) { double x1 = 1., x2 = 0.1, out1, out2, out3, out4; double y1, y2, y3, y4; adouble ax1, ax2; @@ -2297,10 +2266,10 @@ BOOST_AUTO_TEST_CASE(MultiHyperb_FOV_Forward) ax1 <<= x1; ax2 <<= x2; - ay1 = sinh(ax1*ax1)*cosh(ax2*ax2*ax2); + ay1 = sinh(ax1 * ax1) * cosh(ax2 * ax2 * ax2); ay2 = pow(cosh(pow(ax1, 4.)), 2.) - pow(cosh(pow(ax1, 4.)), 2.); - ay3 = -cosh(sqrt(ax1)*ax2)*ax2; - ay4 = cosh(ax1)/sinh(ax2); + ay3 = -cosh(sqrt(ax1) * ax2) * ax2; + ay4 = cosh(ax1) / sinh(ax2); ay1 >>= out1; ay2 >>= out2; @@ -2308,23 +2277,25 @@ BOOST_AUTO_TEST_CASE(MultiHyperb_FOV_Forward) ay4 >>= out4; trace_off(); - double y1x1Derivative = 2.*x1*std::cosh(x1*x1)*std::cosh(x2*x2*x2); - double y1x2Derivative = 3.*x2*x2*std::sinh(x1*x1)*std::sinh(x2*x2*x2); + double y1x1Derivative = + 2. * x1 * std::cosh(x1 * x1) * std::cosh(x2 * x2 * x2); + double y1x2Derivative = + 3. * x2 * x2 * std::sinh(x1 * x1) * std::sinh(x2 * x2 * x2); double y2x1Derivative = 0.0; double y2x2Derivative = 0.0; - double y3x1Derivative = -0.5*std::sinh(std::sqrt(x1)*x2)*x2*x2 - / std::sqrt(x1); - double y3x2Derivative = -std::sinh(std::sqrt(x1)*x2)*std::sqrt(x1)*x2 - - std::cosh(std::sqrt(x1)*x2); - double y4x1Derivative = std::sinh(x1)/std::sinh(x2); - double y4x2Derivative = -std::cosh(x1)*std::cosh(x2) - / std::pow(std::sinh(x2), 2.); - - y1 = std::sinh(x1*x1)*std::cosh(x2*x2*x2); - y2 = std::pow(std::cosh(std::pow(x1, 4)), 2) - - std::pow(std::cosh(std::pow(x1, 4)), 2); - y3 = -std::cosh(std::sqrt(x1)*x2)*x2; - y4 = std::cosh(x1)/std::sinh(x2); + double y3x1Derivative = + -0.5 * std::sinh(std::sqrt(x1) * x2) * x2 * x2 / std::sqrt(x1); + double y3x2Derivative = -std::sinh(std::sqrt(x1) * x2) * std::sqrt(x1) * x2 - + std::cosh(std::sqrt(x1) * x2); + double y4x1Derivative = std::sinh(x1) / std::sinh(x2); + double y4x2Derivative = + -std::cosh(x1) * std::cosh(x2) / std::pow(std::sinh(x2), 2.); + + y1 = std::sinh(x1 * x1) * std::cosh(x2 * x2 * x2); + y2 = std::pow(std::cosh(std::pow(x1, 4)), 2) - + std::pow(std::cosh(std::pow(x1, 4)), 2); + y3 = -std::cosh(std::sqrt(x1) * x2) * x2; + y4 = std::cosh(x1) / std::sinh(x2); double *x = myalloc1(2); double **xd = myalloc2(2, 2); @@ -2364,8 +2335,7 @@ BOOST_AUTO_TEST_CASE(MultiHyperb_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(MultiHyperbProdOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(MultiHyperbProdOperator_FOV_Reverse) { double x1 = 1., x2 = 0.1, out1, out2, out3, out4; double y1, y2, y3, y4; adouble ax1, ax2; @@ -2375,10 +2345,10 @@ BOOST_AUTO_TEST_CASE(MultiHyperbProdOperator_FOV_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = sinh(ax1*ax1)*cosh(ax2*ax2*ax2); + ay1 = sinh(ax1 * ax1) * cosh(ax2 * ax2 * ax2); ay2 = pow(cosh(pow(ax1, 4.)), 2.) - pow(cosh(pow(ax1, 4.)), 2.); - ay3 = -cosh(sqrt(ax1)*ax2)*ax2; - ay4 = cosh(ax1)/sinh(ax2); + ay3 = -cosh(sqrt(ax1) * ax2) * ax2; + ay4 = cosh(ax1) / sinh(ax2); ay1 >>= out1; ay2 >>= out2; @@ -2386,17 +2356,19 @@ BOOST_AUTO_TEST_CASE(MultiHyperbProdOperator_FOV_Reverse) ay4 >>= out4; trace_off(); - double y1x1Derivative = 2.*x1*std::cosh(x1*x1)*std::cosh(x2*x2*x2); - double y1x2Derivative = 3.*x2*x2*std::sinh(x1*x1)*std::sinh(x2*x2*x2); + double y1x1Derivative = + 2. * x1 * std::cosh(x1 * x1) * std::cosh(x2 * x2 * x2); + double y1x2Derivative = + 3. * x2 * x2 * std::sinh(x1 * x1) * std::sinh(x2 * x2 * x2); double y2x1Derivative = 0.0; double y2x2Derivative = 0.0; - double y3x1Derivative = -0.5*std::sinh(std::sqrt(x1)*x2)*x2*x2 - / std::sqrt(x1); - double y3x2Derivative = -std::sinh(std::sqrt(x1)*x2)*std::sqrt(x1)*x2 - - std::cosh(std::sqrt(x1)*x2); - double y4x1Derivative = std::sinh(x1)/std::sinh(x2); - double y4x2Derivative = -std::cosh(x1)*std::cosh(x2) - / std::pow(std::sinh(x2), 2.); + double y3x1Derivative = + -0.5 * std::sinh(std::sqrt(x1) * x2) * x2 * x2 / std::sqrt(x1); + double y3x2Derivative = -std::sinh(std::sqrt(x1) * x2) * std::sqrt(x1) * x2 - + std::cosh(std::sqrt(x1) * x2); + double y4x1Derivative = std::sinh(x1) / std::sinh(x2); + double y4x2Derivative = + -std::cosh(x1) * std::cosh(x2) / std::pow(std::sinh(x2), 2.); double **u = myalloc2(4, 4); double **z = myalloc2(4, 2); @@ -2425,6 +2397,4 @@ BOOST_AUTO_TEST_CASE(MultiHyperbProdOperator_FOV_Reverse) myfree2(z); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/ADOL-C/boost-test/traceExtDiff.cpp b/ADOL-C/boost-test/traceExtDiff.cpp index 5c464679d..ae1809c2d 100644 --- a/ADOL-C/boost-test/traceExtDiff.cpp +++ b/ADOL-C/boost-test/traceExtDiff.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_DYN_LINK -#include #include +#include namespace tt = boost::test_tools; @@ -18,15 +18,13 @@ namespace tt = boost::test_tools; * * This is the function to be treated as externally differentiable. */ -template -static int f(int n, T* x, int m, T* y) -{ +template static int f(int n, T *x, int m, T *y) { assert(n == 3 && m == 1); y[0] = 0; for (int i = 0; i < n; ++i) { - const T z = x[i]*x[i]; - y[0] += z*z; + const T z = x[i] * x[i]; + y[0] += z * z; } y[0] += x[0] * x[1]; @@ -35,8 +33,7 @@ static int f(int n, T* x, int m, T* y) const int f_tape = 1; -static int f_nested(int n, double* x, int m, double* y) -{ +static int f_nested(int n, double *x, int m, double *y) { trace_on(f_tape); std::vector xa(n), ya(m); @@ -56,8 +53,8 @@ static int f_nested(int n, double* x, int m, double* y) /** * Implement first derivatives by calling fos_forward */ -static int f_fos_forward(int n, double* x, double* dx, int m, double* y, double* dy) -{ +static int f_fos_forward(int n, double *x, double *dx, int m, double *y, + double *dy) { const int keep = 2; return fos_forward(f_tape, m, n, keep, x, dx, y, dy); } @@ -65,53 +62,58 @@ static int f_fos_forward(int n, double* x, double* dx, int m, double* y, double* /** * Implement first derivatives by hand */ -static int f_fos_forward_manual(int n, double* x, double* dx, int m, double* y, double* dy) -{ +static int f_fos_forward_manual(int n, double *x, double *dx, int m, double *y, + double *dy) { assert(n == 3 && m == 1); - y[0] = x[0]*x[0]*x[0]*x[0] + x[1]*x[1]*x[1]*x[1] + x[2]*x[2]*x[2]*x[2] + x[0]*x[1]; - dy[0] = 4.0*x[0]*x[0]*x[0]*dx[0] + 4.0*x[1]*x[1]*x[1]*dx[1] + 4.0*x[2]*x[2]*x[2]*dx[2] + x[1]*dx[0] + x[0]*dx[1]; + y[0] = x[0] * x[0] * x[0] * x[0] + x[1] * x[1] * x[1] * x[1] + + x[2] * x[2] * x[2] * x[2] + x[0] * x[1]; + dy[0] = 4.0 * x[0] * x[0] * x[0] * dx[0] + 4.0 * x[1] * x[1] * x[1] * dx[1] + + 4.0 * x[2] * x[2] * x[2] * dx[2] + x[1] * dx[0] + x[0] * dx[1]; return 0; } /** * Implement derivatives calling hos_ti_reverse */ -static int f_hos_ti_reverse(int m, double** u, int n, int d, double** z, double** x, double** y) -{ +static int f_hos_ti_reverse(int m, double **u, int n, int d, double **z, + double **x, double **y) { int const ret = hos_ti_reverse(f_tape, m, n, d, u, z); return ret; } /** - * Hand-code the expected outcome of hos_ti_reverse for the particular test function + * Hand-code the expected outcome of hos_ti_reverse for the particular test + * function */ -static int f_hos_ti_reverse_manual(int m, double** u, int n, int d, double** z, double** x, double** y) -{ +static int f_hos_ti_reverse_manual(int m, double **u, int n, int d, double **z, + double **x, double **y) { assert(n == 3 && m == 1 && d == 1); // First column z0 of Z: z0^T = u0^T F'(x0) - z[0][0] = u[0][0] * (4*x[0][0]*x[0][0]*x[0][0] + x[1][0]); - z[1][0] = u[0][0] * (4*x[1][0]*x[1][0]*x[1][0] + x[0][0]); - z[2][0] = u[0][0] * 4*x[2][0]*x[2][0]*x[2][0]; + z[0][0] = u[0][0] * (4 * x[0][0] * x[0][0] * x[0][0] + x[1][0]); + z[1][0] = u[0][0] * (4 * x[1][0] * x[1][0] * x[1][0] + x[0][0]); + z[2][0] = u[0][0] * 4 * x[2][0] * x[2][0] * x[2][0]; // Second column z1 of Z: u0^T (Hessian(F) x1) + u1^T F'(x0)? // Hessian(F) = [12 x0^2, 1, 0; 1, 12 x1^2, 0; 0, 0, 12 x2^2] - z[0][1] = u[0][0] * (12*x[0][0]*x[0][0]*x[0][1] + x[1][1]) + u[0][1] * (4*x[0][0]*x[0][0]*x[0][0] + x[1][0]); - z[1][1] = u[0][0] * (12*x[1][0]*x[1][0]*x[1][1] + x[0][1]) + u[0][1] * (4*x[1][0]*x[1][0]*x[1][0] + x[0][0]); - z[2][1] = u[0][0] * 12*x[2][0]*x[2][0]*x[2][1] + u[0][1] * 4*x[2][0]*x[2][0]*x[2][0]; + z[0][1] = u[0][0] * (12 * x[0][0] * x[0][0] * x[0][1] + x[1][1]) + + u[0][1] * (4 * x[0][0] * x[0][0] * x[0][0] + x[1][0]); + z[1][1] = u[0][0] * (12 * x[1][0] * x[1][0] * x[1][1] + x[0][1]) + + u[0][1] * (4 * x[1][0] * x[1][0] * x[1][0] + x[0][0]); + z[2][1] = u[0][0] * 12 * x[2][0] * x[2][0] * x[2][1] + + u[0][1] * 4 * x[2][0] * x[2][0] * x[2][0]; return 0; } /* Compute y = g(x0, x1, x2) = f(x0^2, x1, x2)^2 using given implementation of f * - * This is the full test function. It adds a few operations before and after the call - * to f, to make sure handing data to and from externally differentiated functions works as expected. + * This is the full test function. It adds a few operations before and after + * the call to f, to make sure handing data to and from externally + * differentiated functions works as expected. */ -template -static double g(int n, const double* x, F f) -{ +template static double g(int n, const double *x, F f) { assert(n == 3); std::vector xa(n), ya(1); @@ -131,23 +133,29 @@ static double g(int n, const double* x, F f) /* * The Hessian of g, implemented by hand */ -static std::array< std::array, 3> -g_hessian(int n, const double* x) -{ +static std::array, 3> g_hessian(int n, const double *x) { assert(n == 3); using std::pow; - std::array< std::array, 3> hessian = {{ - { 240.*pow(x[0], 14) + 180.*pow(x[0], 8)*x[1] + 112.*pow(x[0], 6)*pow(x[1], 4) + 112.*pow(x[0],6)*pow(x[2], 4) + 12.*x[0]*x[0]*x[1]*x[1] + 4.*pow(x[1], 5) + 4.*x[1]*pow(x[2],4), - 20.*pow(x[0], 9) + 64.*pow(x[0], 7)*pow(x[1], 3) + 8.*pow(x[0], 3)*x[1] + 20.*x[0]*pow(x[1], 4) + 4.*x[0]*pow(x[2], 4), - 64.*pow(x[0], 7)*pow(x[2], 3) + 16.*x[0]*x[1]*pow(x[2], 3) }, - { 0., - 24.*pow(x[0], 8)*x[1]*x[1] + 2.*pow(x[0], 4) + 40.*x[0]*x[0]*pow(x[1], 3) + 56.*pow(x[1], 6) + 24.*x[1]*x[1]*pow(x[2], 4), - 8.*x[0]*x[0]*pow(x[2], 3) + 32.*pow(x[1], 3)*pow(x[2], 3) }, - { 0., - 0., - 24.*pow(x[0], 8)*x[2]*x[2] + 24.*x[0]*x[0]*x[1]*x[2]*x[2] + 24.*pow(x[1], 4)*x[2]*x[2] + 56.*pow(x[2], 6) } - }}; + std::array, 3> hessian = { + {{240. * pow(x[0], 14) + 180. * pow(x[0], 8) * x[1] + + 112. * pow(x[0], 6) * pow(x[1], 4) + + 112. * pow(x[0], 6) * pow(x[2], 4) + + 12. * x[0] * x[0] * x[1] * x[1] + 4. * pow(x[1], 5) + + 4. * x[1] * pow(x[2], 4), + 20. * pow(x[0], 9) + 64. * pow(x[0], 7) * pow(x[1], 3) + + 8. * pow(x[0], 3) * x[1] + 20. * x[0] * pow(x[1], 4) + + 4. * x[0] * pow(x[2], 4), + 64. * pow(x[0], 7) * pow(x[2], 3) + 16. * x[0] * x[1] * pow(x[2], 3)}, + {0., + 24. * pow(x[0], 8) * x[1] * x[1] + 2. * pow(x[0], 4) + + 40. * x[0] * x[0] * pow(x[1], 3) + 56. * pow(x[1], 6) + + 24. * x[1] * x[1] * pow(x[2], 4), + 8. * x[0] * x[0] * pow(x[2], 3) + 32. * pow(x[1], 3) * pow(x[2], 3)}, + {0., 0., + 24. * pow(x[0], 8) * x[2] * x[2] + + 24. * x[0] * x[0] * x[1] * x[2] * x[2] + + 24. * pow(x[1], 4) * x[2] * x[2] + 56. * pow(x[2], 6)}}}; hessian[1][0] = hessian[0][1]; hessian[2][0] = hessian[0][2]; hessian[2][1] = hessian[1][2]; @@ -156,38 +164,36 @@ g_hessian(int n, const double* x) } /* Manage test suite fixtures */ -struct Fixture -{ - Fixture() - { - f_ext = reg_ext_fct(f_nested); - f_ext->zos_forward = f; - f_ext->fos_forward = f_fos_forward; - f_ext->hos_ti_reverse = f_hos_ti_reverse; - f_ext->nestedAdolc = 1; - - f_ext_manual = reg_ext_fct(f); - f_ext_manual->fos_forward = f_fos_forward_manual; - f_ext_manual->hos_ti_reverse = f_hos_ti_reverse_manual; - - call_f_direct = f; - call_f_nested = [this](int n, adouble* xa, int m, adouble* ya) - { return call_ext_fct(f_ext, n, xa, m, ya); }; - call_f_manual = [this](int n, adouble* xa, int m, adouble* ya) - { return call_ext_fct(f_ext_manual, n, xa, m, ya); }; - } - - ext_diff_fct* f_ext; - ext_diff_fct* f_ext_manual; - std::function call_f_direct, call_f_manual, call_f_nested; +struct Fixture { + Fixture() { + f_ext = reg_ext_fct(f_nested); + f_ext->zos_forward = f; + f_ext->fos_forward = f_fos_forward; + f_ext->hos_ti_reverse = f_hos_ti_reverse; + f_ext->nestedAdolc = 1; + + f_ext_manual = reg_ext_fct(f); + f_ext_manual->fos_forward = f_fos_forward_manual; + f_ext_manual->hos_ti_reverse = f_hos_ti_reverse_manual; + + call_f_direct = f; + call_f_nested = [this](int n, adouble *xa, int m, adouble *ya) { + return call_ext_fct(f_ext, n, xa, m, ya); + }; + call_f_manual = [this](int n, adouble *xa, int m, adouble *ya) { + return call_ext_fct(f_ext_manual, n, xa, m, ya); + }; + } + + ext_diff_fct *f_ext; + ext_diff_fct *f_ext_manual; + std::function call_f_direct, + call_f_manual, call_f_nested; }; BOOST_FIXTURE_TEST_SUITE(trace_ext_diff, Fixture) - -template -static void g_hess_vec(F f) -{ +template static void g_hess_vec(F f) { const int g_tape = 0; trace_on(g_tape); @@ -199,8 +205,7 @@ static void g_hess_vec(F f) const auto hessian = g_hessian(x.size(), x.data()); - for (int i = 0; i < x.size(); ++i) - { + for (int i = 0; i < x.size(); ++i) { std::array dx{0.0, 0.0, 0.0}; dx[i] = 1.0; std::array dy; @@ -210,27 +215,17 @@ static void g_hess_vec(F f) } } -BOOST_AUTO_TEST_CASE(g_hess_vec_direct) -{ - g_hess_vec(call_f_direct); -} +BOOST_AUTO_TEST_CASE(g_hess_vec_direct) { g_hess_vec(call_f_direct); } -BOOST_AUTO_TEST_CASE(g_hess_vec_nested) -{ - g_hess_vec(call_f_nested); -} +BOOST_AUTO_TEST_CASE(g_hess_vec_nested) { g_hess_vec(call_f_nested); } -BOOST_AUTO_TEST_CASE(g_hess_vec_manual) -{ - g_hess_vec(call_f_manual); -} +BOOST_AUTO_TEST_CASE(g_hess_vec_manual) { g_hess_vec(call_f_manual); } /** - * \tparam H The ADOL-C method to compute the Hessian (either 'hessian' or 'hessian2') + * \tparam H The ADOL-C method to compute the Hessian (either 'hessian' or + * 'hessian2') */ -template -static void test_g_hessian(H hessian, F f) -{ +template static void test_g_hessian(H hessian, F f) { const int g_tape = 0; trace_on(g_tape); @@ -243,7 +238,7 @@ static void test_g_hessian(H hessian, F f) const auto hess = g_hessian(x.size(), x.data()); std::array h_; - std::array h{h_.data(), h_.data()+1, h_.data()+3}; + std::array h{h_.data(), h_.data() + 1, h_.data() + 3}; const int ret = hessian(g_tape, x.size(), x.data(), h.data()); BOOST_TEST(ret >= 0); @@ -257,18 +252,15 @@ static void test_g_hessian(H hessian, F f) BOOST_TEST(h[2][2] == hess[2][2]); } -BOOST_AUTO_TEST_CASE(test_g_hessian_direct) -{ +BOOST_AUTO_TEST_CASE(test_g_hessian_direct) { test_g_hessian(hessian, call_f_direct); } -BOOST_AUTO_TEST_CASE(test_g_hessian_nested) -{ +BOOST_AUTO_TEST_CASE(test_g_hessian_nested) { test_g_hessian(hessian, call_f_nested); } -BOOST_AUTO_TEST_CASE(test_g_hessian_manual) -{ +BOOST_AUTO_TEST_CASE(test_g_hessian_manual) { test_g_hessian(hessian, call_f_manual); } diff --git a/ADOL-C/boost-test/traceFixedPointScalarTests.cpp b/ADOL-C/boost-test/traceFixedPointScalarTests.cpp index 406fd2b35..6ee5576eb 100644 --- a/ADOL-C/boost-test/traceFixedPointScalarTests.cpp +++ b/ADOL-C/boost-test/traceFixedPointScalarTests.cpp @@ -7,8 +7,7 @@ namespace tt = boost::test_tools; #include "const.h" -BOOST_AUTO_TEST_SUITE( trace_fixed_point_scalar ) - +BOOST_AUTO_TEST_SUITE(trace_fixed_point_scalar) /************************************************************/ /* Tests for automatic differentiation of fixed-point loops */ @@ -22,47 +21,42 @@ BOOST_AUTO_TEST_SUITE( trace_fixed_point_scalar ) * \tparam T The number type. Both double and adouble versions are needed */ template -static int iteration(T* x, T* u, T* y, int dim_x, int dim_u) -{ +static int iteration(T *x, T *u, T *y, int dim_x, int dim_u) { // Newton update: x = x - f(x)/f'(x) = x - (x*x-z) / 2x = x - x/2 + z/2x - y[0] = 0.5*(x[0] + u[0]/x[0]); + y[0] = 0.5 * (x[0] + u[0] / x[0]); return 0; } -static double norm(double* x, int dim) -{ +static double norm(double *x, int dim) { double norm = 0; - for (int i=0; i, - iteration, - norm, - norm, // Norm for the termination criterion for the adjoint - 1e-8, // Termination threshold for fixed-point iteration - 1e-8, // Termination threshold - 6, // Maximum number of iterations - 6, // Maximum number of adjoint iterations - &x, // [in] Initial iterate of fixed-point iteration - &u, // [in] The parameters: We compute the derivative wrt this - &y, // [out] Final state of the iteration - 1, // Size of the vector x_0 - 1); // Number of parameters + fp_iteration(subTapeNumber, iteration, iteration, norm, + norm, // Norm for the termination criterion for the adjoint + 1e-8, // Termination threshold for fixed-point iteration + 1e-8, // Termination threshold + 6, // Maximum number of iterations + 6, // Maximum number of adjoint iterations + &x, // [in] Initial iterate of fixed-point iteration + &u, // [in] The parameters: We compute the derivative wrt this + &y, // [out] Final state of the iteration + 1, // Size of the vector x_0 + 1); // Number of parameters double out; y >>= out; @@ -74,34 +68,33 @@ static double traceNewtonForSquareRoot(int tapeNumber, int subTapeNumber, double /* Check whether tracing works, and whether the value of the * square root function can be recovered from the tape. */ -BOOST_AUTO_TEST_CASE(NewtonScalarFixedPoint_zos_forward) -{ +BOOST_AUTO_TEST_CASE(NewtonScalarFixedPoint_zos_forward) { // Compute the square root of 2.0 const double argument[1] = {2.0}; - double out = traceNewtonForSquareRoot(1, // tape number - 2, // subtape number - argument[0]); // Where to evaluate the square root function + double out = traceNewtonForSquareRoot( + 1, // tape number + 2, // subtape number + argument[0]); // Where to evaluate the square root function // Did taping really produce the correct value? BOOST_TEST(out == std::sqrt(argument[0]), tt::tolerance(tol)); double value[1]; - zos_forward(1, // Tape number - 1, // Number of dependent variables - 1, // Number of indepdent variables - 0, // Don't keep anything - argument, // Where to evaluate the function - value); // Function value + zos_forward(1, // Tape number + 1, // Number of dependent variables + 1, // Number of indepdent variables + 0, // Don't keep anything + argument, // Where to evaluate the function + value); // Function value BOOST_TEST(value[0] == sqrt(argument[0]), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(NewtonScalarFixedPoint_fos_forward) -{ +BOOST_AUTO_TEST_CASE(NewtonScalarFixedPoint_fos_forward) { // Compute the square root of 2.0 const double argument[1] = {2.0}; - double out = traceNewtonForSquareRoot(1,2,argument[0]); + double out = traceNewtonForSquareRoot(1, 2, argument[0]); // Did taping really produce the correct value? BOOST_TEST(out == std::sqrt(argument[0]), tt::tolerance(tol)); @@ -113,36 +106,34 @@ BOOST_AUTO_TEST_CASE(NewtonScalarFixedPoint_fos_forward) const double tangent[1] = {1.0}; - fos_forward(1, // Tape number - 1, // Number of dependent variables - 1, // Number of independent variables, - 0, // Don't keep anything - argument, // Where to evalute the derivative + fos_forward(1, // Tape number + 1, // Number of dependent variables + 1, // Number of independent variables, + 0, // Don't keep anything + argument, // Where to evalute the derivative tangent, - value, // The computed function value - derivative); // The computed derivative + value, // The computed function value + derivative); // The computed derivative - double exactDerivative = 1.0/(2*sqrt(argument[0])); + double exactDerivative = 1.0 / (2 * sqrt(argument[0])); BOOST_TEST(value[0] == out, tt::tolerance(tol)); BOOST_TEST(derivative[0] == exactDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(NewtonForSquareRootFixedPoint_fov_forward) -{ +BOOST_AUTO_TEST_CASE(NewtonForSquareRootFixedPoint_fov_forward) { // Compute the square root of 2.0 const double argument[1] = {2.0}; - double out = traceNewtonForSquareRoot(1, // tape number - 2, - argument[0]); + double out = traceNewtonForSquareRoot(1, // tape number + 2, argument[0]); // Did taping really produce the correct value? BOOST_TEST(out == std::sqrt(argument[0]), tt::tolerance(tol)); // Use fov_forward to compute the first derivative - int m = 1; // Number of dependent variables - int n = 1; // Number of independent variables - int p = 1; // Number of tangents + int m = 1; // Number of dependent variables + int n = 1; // Number of independent variables + int p = 1; // Number of tangents double **xd = myalloc2(n, p); double value[m]; @@ -155,16 +146,16 @@ BOOST_AUTO_TEST_CASE(NewtonForSquareRootFixedPoint_fov_forward) } } - fov_forward(1, // Tape number - m, // Number of dependent variables - n, // Number of independent variables - p, // Number of tangents - argument, // Where to evaluate the derivative - xd, // The tangents - value, // The compute function value - yd); // The computed derivative + fov_forward(1, // Tape number + m, // Number of dependent variables + n, // Number of independent variables + p, // Number of tangents + argument, // Where to evaluate the derivative + xd, // The tangents + value, // The compute function value + yd); // The computed derivative - double exactDerivative = 1.0/(2*sqrt(argument[0])); + double exactDerivative = 1.0 / (2 * sqrt(argument[0])); BOOST_TEST(value[0] == out, tt::tolerance(tol)); BOOST_TEST(yd[0][0] == exactDerivative, tt::tolerance(tol)); @@ -174,4 +165,3 @@ BOOST_AUTO_TEST_CASE(NewtonForSquareRootFixedPoint_fov_forward) } BOOST_AUTO_TEST_SUITE_END() - diff --git a/ADOL-C/boost-test/traceOperatorScalar.cpp b/ADOL-C/boost-test/traceOperatorScalar.cpp index 0136bfdab..9f3353360 100644 --- a/ADOL-C/boost-test/traceOperatorScalar.cpp +++ b/ADOL-C/boost-test/traceOperatorScalar.cpp @@ -7,8 +7,7 @@ namespace tt = boost::test_tools; #include "const.h" -BOOST_AUTO_TEST_SUITE( trace_scalar ) - +BOOST_AUTO_TEST_SUITE(trace_scalar) /**********************************************/ /* Tests for ADOL-C trace scalar mode drivers */ @@ -16,7 +15,6 @@ BOOST_AUTO_TEST_SUITE( trace_scalar ) /* Author: Philipp Schuette */ /**********************************************/ - /* Naming convention for test cases: Operatorname_Operator_ZOS_Forward for * primal value (= zero order derivative), Operatorname_Operator_FOS_Forward * for foward derivative evulation and Operatorname_Operator_FOS_Reverse for @@ -27,8 +25,7 @@ BOOST_AUTO_TEST_SUITE( trace_scalar ) * as well. */ -BOOST_AUTO_TEST_CASE(ExpOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(ExpOperator_ZOS_Forward) { double a = 2., aout; adouble ad; @@ -48,7 +45,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_ZOS_Forward) double *y = myalloc1(1); *x = 2.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -57,8 +54,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(ExpOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(ExpOperator_FOS_Forward) { double a = 2., aout; adouble ad; @@ -80,7 +76,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_FOS_Forward) *x = 2.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -92,8 +88,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(ExpOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(ExpOperator_FOS_Reverse) { double a = 2., aout; adouble ad; @@ -111,7 +106,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -120,8 +115,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(MultOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(MultOperator_ZOS_Forward) { double a = 2., b = 3.5, out; adouble ad, bd; @@ -141,10 +135,10 @@ BOOST_AUTO_TEST_CASE(MultOperator_ZOS_Forward) double *x = myalloc1(2); double *y = myalloc1(1); - //x[0] = 2.; + // x[0] = 2.; *x = 2.; *(x + 1) = 3.5; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -153,8 +147,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(MultOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(MultOperator_FOS_Forward) { double a = 2., b = 3.5, out; adouble ad, bd; @@ -181,7 +174,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOS_Forward) *(x + 1) = 3.5; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -190,7 +183,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOS_Forward) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -201,8 +194,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(MultOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(MultOperator_FOS_Reverse) { double a = 2., b = 3.5, out; adouble ad, bd; @@ -222,7 +214,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOS_Reverse) double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -232,8 +224,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(AddOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AddOperator_ZOS_Forward) { double a = 2.5, b = 3., out; adouble ad, bd; @@ -255,7 +246,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_ZOS_Forward) *x = 2.5; *(x + 1) = 3.; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -264,8 +255,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(AddOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AddOperator_FOS_Forward) { double a = 2.5, b = 3., out; adouble ad, bd; @@ -292,7 +282,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOS_Forward) *(x + 1) = 3.; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -301,7 +291,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOS_Forward) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -312,8 +302,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(AddOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(AddOperator_FOS_Reverse) { double a = 2.5, b = 3., out; adouble ad, bd; @@ -333,7 +322,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOS_Reverse) double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -343,8 +332,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(SubOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SubOperator_ZOS_Forward) { double a = 1.5, b = 3.2, out; adouble ad, bd; @@ -366,7 +354,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_ZOS_Forward) *x = 1.5; *(x + 1) = 3.2; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -375,8 +363,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(SubOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SubOperator_FOS_Forward) { double a = 1.5, b = 3.2, out; adouble ad, bd; @@ -403,7 +390,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOS_Forward) *(x + 1) = 3.2; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -412,7 +399,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOS_Forward) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -423,8 +410,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(SubOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(SubOperator_FOS_Reverse) { double a = 1.5, b = 3.2, out; adouble ad, bd; @@ -444,7 +430,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOS_Reverse) double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -454,8 +440,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(DivOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(DivOperator_ZOS_Forward) { double a = 0.5, b = 4.5, out; adouble ad, bd; @@ -477,7 +462,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_ZOS_Forward) *x = 0.5; *(x + 1) = 4.5; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -486,8 +471,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(DivOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(DivOperator_FOS_Forward) { double a = 0.5, b = 4.5, out; adouble ad, bd; @@ -501,7 +485,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOS_Forward) trace_off(); double aDerivative = 1. / b; - double bDerivative = -a / (b*b); + double bDerivative = -a / (b * b); a = a / b; double *x = myalloc1(2); @@ -514,7 +498,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOS_Forward) *(x + 1) = 4.5; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -523,7 +507,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOS_Forward) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -534,8 +518,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(DivOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(DivOperator_FOS_Reverse) { double a = 0.5, b = 4.5, out; adouble ad, bd; @@ -549,13 +532,13 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOS_Reverse) trace_off(); double aDerivative = 1. / b; - double bDerivative = -a / (b*b); + double bDerivative = -a / (b * b); double *u = myalloc1(1); double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -565,8 +548,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(TanOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(TanOperator_ZOS_Forward) { double a = 0.7, aout; adouble ad; @@ -586,7 +568,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_ZOS_Forward) double *y = myalloc1(1); *x = 0.7; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -595,8 +577,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(TanOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(TanOperator_FOS_Forward) { double a = 0.7, aout; adouble ad; @@ -609,7 +590,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOS_Forward) trace_off(); a = std::tan(a); - double aDerivative = 1. + a*a; + double aDerivative = 1. + a * a; double *x = myalloc1(1); double *xd = myalloc1(1); @@ -618,7 +599,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOS_Forward) *x = 0.7; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -630,8 +611,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(TanOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(TanOperator_FOS_Reverse) { double a = 0.7, aout; adouble ad; @@ -644,13 +624,13 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOS_Reverse) trace_off(); a = std::tan(a); - double aDerivative = 1. + a*a; + double aDerivative = 1. + a * a; double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -659,8 +639,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(SinOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SinOperator_ZOS_Forward) { double a = 1.2, aout; adouble ad; @@ -680,7 +659,7 @@ BOOST_AUTO_TEST_CASE(SinOperator_ZOS_Forward) double *y = myalloc1(1); *x = 1.2; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -689,8 +668,7 @@ BOOST_AUTO_TEST_CASE(SinOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(SinOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SinOperator_FOS_Forward) { double a = 1.2, aout; adouble ad; @@ -712,7 +690,7 @@ BOOST_AUTO_TEST_CASE(SinOperator_FOS_Forward) *x = 1.2; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -724,8 +702,7 @@ BOOST_AUTO_TEST_CASE(SinOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(SinOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(SinOperator_FOS_Reverse) { double a = 1.2, aout; adouble ad; @@ -744,7 +721,7 @@ BOOST_AUTO_TEST_CASE(SinOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -753,8 +730,7 @@ BOOST_AUTO_TEST_CASE(SinOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(CosOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CosOperator_ZOS_Forward) { double a = 1.2, aout; adouble ad; @@ -774,7 +750,7 @@ BOOST_AUTO_TEST_CASE(CosOperator_ZOS_Forward) double *y = myalloc1(1); *x = 1.2; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -783,8 +759,7 @@ BOOST_AUTO_TEST_CASE(CosOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(CosOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CosOperator_FOS_Forward) { double a = 1.2, aout; adouble ad; @@ -806,7 +781,7 @@ BOOST_AUTO_TEST_CASE(CosOperator_FOS_Forward) *x = 1.2; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -818,8 +793,7 @@ BOOST_AUTO_TEST_CASE(CosOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(CosOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(CosOperator_FOS_Reverse) { double a = 1.2, aout; adouble ad; @@ -838,7 +812,7 @@ BOOST_AUTO_TEST_CASE(CosOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -847,8 +821,7 @@ BOOST_AUTO_TEST_CASE(CosOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(SqrtOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SqrtOperator_ZOS_Forward) { double a = 2.2, aout; adouble ad; @@ -868,7 +841,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_ZOS_Forward) double *y = myalloc1(1); *x = 2.2; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -877,8 +850,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Forward) { double a = 2.2, aout; adouble ad; @@ -891,7 +863,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Forward) trace_off(); a = std::sqrt(a); - double aDerivative = 1. / (2*a); + double aDerivative = 1. / (2 * a); double *x = myalloc1(1); double *xd = myalloc1(1); @@ -900,7 +872,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Forward) *x = 2.2; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -912,8 +884,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Reverse) { double a = 2.2, aout; adouble ad; @@ -926,13 +897,13 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Reverse) trace_off(); a = std::sqrt(a); - double aDerivative = 1. / (2*a); + double aDerivative = 1. / (2 * a); double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -941,8 +912,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(LogOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(LogOperator_ZOS_Forward) { double a = 4.9, aout; adouble ad; @@ -962,7 +932,7 @@ BOOST_AUTO_TEST_CASE(LogOperator_ZOS_Forward) double *y = myalloc1(1); *x = 4.9; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -971,8 +941,7 @@ BOOST_AUTO_TEST_CASE(LogOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(LogOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(LogOperator_FOS_Forward) { double a = 4.9, aout; adouble ad; @@ -994,7 +963,7 @@ BOOST_AUTO_TEST_CASE(LogOperator_FOS_Forward) *x = 4.9; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1006,8 +975,7 @@ BOOST_AUTO_TEST_CASE(LogOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(LogOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(LogOperator_FOS_Reverse) { double a = 4.9, aout; adouble ad; @@ -1026,7 +994,7 @@ BOOST_AUTO_TEST_CASE(LogOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1035,8 +1003,7 @@ BOOST_AUTO_TEST_CASE(LogOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(SinhOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SinhOperator_ZOS_Forward) { double a = 4., aout; adouble ad; @@ -1056,7 +1023,7 @@ BOOST_AUTO_TEST_CASE(SinhOperator_ZOS_Forward) double *y = myalloc1(1); *x = 4.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1065,8 +1032,7 @@ BOOST_AUTO_TEST_CASE(SinhOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(SinhOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SinhOperator_FOS_Forward) { double a = 4., aout; adouble ad; @@ -1088,7 +1054,7 @@ BOOST_AUTO_TEST_CASE(SinhOperator_FOS_Forward) *x = 4.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1100,8 +1066,7 @@ BOOST_AUTO_TEST_CASE(SinhOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(SinhOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(SinhOperator_FOS_Reverse) { double a = 4., aout; adouble ad; @@ -1120,7 +1085,7 @@ BOOST_AUTO_TEST_CASE(SinhOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1129,8 +1094,7 @@ BOOST_AUTO_TEST_CASE(SinhOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(CoshOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CoshOperator_ZOS_Forward) { double a = 4., aout; adouble ad; @@ -1150,7 +1114,7 @@ BOOST_AUTO_TEST_CASE(CoshOperator_ZOS_Forward) double *y = myalloc1(1); *x = 4.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1159,8 +1123,7 @@ BOOST_AUTO_TEST_CASE(CoshOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(CoshOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CoshOperator_FOS_Forward) { double a = 4., aout; adouble ad; @@ -1182,7 +1145,7 @@ BOOST_AUTO_TEST_CASE(CoshOperator_FOS_Forward) *x = 4.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1194,8 +1157,7 @@ BOOST_AUTO_TEST_CASE(CoshOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(CoshOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(CoshOperator_FOS_Reverse) { double a = 4., aout; adouble ad; @@ -1214,7 +1176,7 @@ BOOST_AUTO_TEST_CASE(CoshOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1223,8 +1185,7 @@ BOOST_AUTO_TEST_CASE(CoshOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(TanhOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(TanhOperator_ZOS_Forward) { double a = 4., aout; adouble ad; @@ -1244,7 +1205,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_ZOS_Forward) double *y = myalloc1(1); *x = 4.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1253,8 +1214,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Forward) { double a = 4., aout; adouble ad; @@ -1267,7 +1227,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Forward) trace_off(); a = std::tanh(a); - double aDerivative = 1. - a*a; + double aDerivative = 1. - a * a; double *x = myalloc1(1); double *xd = myalloc1(1); @@ -1276,7 +1236,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Forward) *x = 4.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1288,8 +1248,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Reverse) { double a = 4., aout; adouble ad; @@ -1302,13 +1261,13 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Reverse) trace_off(); a = std::tanh(a); - double aDerivative = 1. - a*a; + double aDerivative = 1. - a * a; double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1317,8 +1276,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(AsinOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AsinOperator_ZOS_Forward) { double a = 0.9, aout; adouble ad; @@ -1338,7 +1296,7 @@ BOOST_AUTO_TEST_CASE(AsinOperator_ZOS_Forward) double *y = myalloc1(1); *x = 0.9; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1347,8 +1305,7 @@ BOOST_AUTO_TEST_CASE(AsinOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Forward) { double a = 0.9, aout; adouble ad; @@ -1360,7 +1317,7 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(1. - a*a)); + double aDerivative = 1. / (std::sqrt(1. - a * a)); a = std::asin(a); double *x = myalloc1(1); @@ -1370,7 +1327,7 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Forward) *x = 0.9; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1382,8 +1339,7 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Reverse) { double a = 0.9, aout; adouble ad; @@ -1395,14 +1351,14 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(1. - a*a)); + double aDerivative = 1. / (std::sqrt(1. - a * a)); a = std::asin(a); double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1411,8 +1367,7 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(AcosOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AcosOperator_ZOS_Forward) { double a = 0.8, aout; adouble ad; @@ -1432,7 +1387,7 @@ BOOST_AUTO_TEST_CASE(AcosOperator_ZOS_Forward) double *y = myalloc1(1); *x = 0.8; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1441,8 +1396,7 @@ BOOST_AUTO_TEST_CASE(AcosOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Forward) { double a = 0.8, aout; adouble ad; @@ -1454,7 +1408,7 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Forward) ad >>= aout; trace_off(); - double aDerivative = -1. / (std::sqrt(1. - a*a)); + double aDerivative = -1. / (std::sqrt(1. - a * a)); a = std::acos(a); double *x = myalloc1(1); @@ -1464,7 +1418,7 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Forward) *x = 0.8; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1476,8 +1430,7 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Reverse) { double a = 0.8, aout; adouble ad; @@ -1489,14 +1442,14 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Reverse) ad >>= aout; trace_off(); - double aDerivative = -1. / (std::sqrt(1. - a*a)); + double aDerivative = -1. / (std::sqrt(1. - a * a)); a = std::acos(a); double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1505,8 +1458,7 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(AtanOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AtanOperator_ZOS_Forward) { double a = 9.8, aout; adouble ad; @@ -1526,7 +1478,7 @@ BOOST_AUTO_TEST_CASE(AtanOperator_ZOS_Forward) double *y = myalloc1(1); *x = 9.8; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1535,8 +1487,7 @@ BOOST_AUTO_TEST_CASE(AtanOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Forward) { double a = 9.8, aout; adouble ad; @@ -1548,7 +1499,7 @@ BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (1. + a*a); + double aDerivative = 1. / (1. + a * a); a = std::atan(a); double *x = myalloc1(1); @@ -1558,7 +1509,7 @@ BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Forward) *x = 9.8; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1570,8 +1521,7 @@ BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Reverse) { double a = 9.8, aout; adouble ad; @@ -1583,14 +1533,14 @@ BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (1. + a*a); + double aDerivative = 1. / (1. + a * a); a = std::atan(a); double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1599,8 +1549,7 @@ BOOST_AUTO_TEST_CASE(AtanOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(Log10Operator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(Log10Operator_ZOS_Forward) { double a = 12.3, aout; adouble ad; @@ -1620,7 +1569,7 @@ BOOST_AUTO_TEST_CASE(Log10Operator_ZOS_Forward) double *y = myalloc1(1); *x = 12.3; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1629,8 +1578,7 @@ BOOST_AUTO_TEST_CASE(Log10Operator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Forward) { double a = 12.3, aout; adouble ad; @@ -1642,7 +1590,7 @@ BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (a*std::log(10)); + double aDerivative = 1. / (a * std::log(10)); a = std::log10(a); double *x = myalloc1(1); @@ -1652,7 +1600,7 @@ BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Forward) *x = 12.3; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1664,8 +1612,7 @@ BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Reverse) { double a = 12.3, aout; adouble ad; @@ -1677,14 +1624,14 @@ BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (a*std::log(10)); + double aDerivative = 1. / (a * std::log(10)); a = std::log10(a); double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1693,8 +1640,7 @@ BOOST_AUTO_TEST_CASE(Log10Operator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(AsinhOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AsinhOperator_ZOS_Forward) { double a = 0.6, aout; adouble ad; @@ -1714,7 +1660,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_ZOS_Forward) double *y = myalloc1(1); *x = 0.6; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1723,8 +1669,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Forward) { double a = 0.6, aout; adouble ad; @@ -1736,7 +1681,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(a*a + 1.)); + double aDerivative = 1. / (std::sqrt(a * a + 1.)); a = std::asinh(a); double *x = myalloc1(1); @@ -1746,7 +1691,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Forward) *x = 0.6; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1758,8 +1703,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Reverse) { double a = 0.6, aout; adouble ad; @@ -1771,14 +1715,14 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(a*a + 1.)); + double aDerivative = 1. / (std::sqrt(a * a + 1.)); a = std::asinh(a); double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1787,8 +1731,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(AcoshOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AcoshOperator_ZOS_Forward) { double a = 1.7, aout; adouble ad; @@ -1808,7 +1751,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_ZOS_Forward) double *y = myalloc1(1); *x = 1.7; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1817,8 +1760,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Forward) { double a = 1.7, aout; adouble ad; @@ -1830,7 +1772,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(a*a - 1)); + double aDerivative = 1. / (std::sqrt(a * a - 1)); a = std::acosh(a); double *x = myalloc1(1); @@ -1840,7 +1782,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Forward) *x = 1.7; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1852,8 +1794,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Reverse) { double a = 1.7, aout; adouble ad; @@ -1865,14 +1806,14 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(a*a - 1.)); + double aDerivative = 1. / (std::sqrt(a * a - 1.)); a = std::acosh(a); double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1881,8 +1822,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(AtanhOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AtanhOperator_ZOS_Forward) { double a = 0.6, aout; adouble ad; @@ -1902,7 +1842,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_ZOS_Forward) double *y = myalloc1(1); *x = 0.6; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1911,8 +1851,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Forward) { double a = 0.6, aout; adouble ad; @@ -1924,7 +1863,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (1. - a*a); + double aDerivative = 1. / (1. - a * a); a = std::atanh(a); double *x = myalloc1(1); @@ -1934,7 +1873,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Forward) *x = 0.6; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -1946,8 +1885,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Reverse) { double a = 0.6, aout; adouble ad; @@ -1959,14 +1897,14 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (1. - a*a); + double aDerivative = 1. / (1. - a * a); a = std::atanh(a); double *u = myalloc1(1); double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -1975,8 +1913,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(InclOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(InclOperator_ZOS_Forward) { double a = 5., aout; adouble ad; @@ -1996,7 +1933,7 @@ BOOST_AUTO_TEST_CASE(InclOperator_ZOS_Forward) double *y = myalloc1(1); *x = 5.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2005,8 +1942,7 @@ BOOST_AUTO_TEST_CASE(InclOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(InclOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(InclOperator_FOS_Forward) { double a = 5., aout; adouble ad; @@ -2028,7 +1964,7 @@ BOOST_AUTO_TEST_CASE(InclOperator_FOS_Forward) *x = 5.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2040,8 +1976,7 @@ BOOST_AUTO_TEST_CASE(InclOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(InclOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(InclOperator_FOS_Reverse) { double a = 5., aout; adouble ad; @@ -2060,7 +1995,7 @@ BOOST_AUTO_TEST_CASE(InclOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2069,8 +2004,7 @@ BOOST_AUTO_TEST_CASE(InclOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(DeclOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(DeclOperator_ZOS_Forward) { double a = 5., aout; adouble ad; @@ -2090,7 +2024,7 @@ BOOST_AUTO_TEST_CASE(DeclOperator_ZOS_Forward) double *y = myalloc1(1); *x = 5.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2099,8 +2033,7 @@ BOOST_AUTO_TEST_CASE(DeclOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(DeclOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(DeclOperator_FOS_Forward) { double a = 5., aout; adouble ad; @@ -2122,7 +2055,7 @@ BOOST_AUTO_TEST_CASE(DeclOperator_FOS_Forward) *x = 5.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2134,8 +2067,7 @@ BOOST_AUTO_TEST_CASE(DeclOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(DeclOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(DeclOperator_FOS_Reverse) { double a = 5., aout; adouble ad; @@ -2154,7 +2086,7 @@ BOOST_AUTO_TEST_CASE(DeclOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2163,8 +2095,7 @@ BOOST_AUTO_TEST_CASE(DeclOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(SignPlusOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SignPlusOperator_ZOS_Forward) { double a = 1.5, aout; adouble ad; @@ -2184,7 +2115,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_ZOS_Forward) double *y = myalloc1(1); *x = 1.5; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2193,8 +2124,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(SignPlusOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SignPlusOperator_FOS_Forward) { double a = 1.5, aout; adouble ad; @@ -2216,7 +2146,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_FOS_Forward) *x = 1.5; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2228,8 +2158,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(SignPlusOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(SignPlusOperator_FOS_Reverse) { double a = 1.5, aout; adouble ad; @@ -2248,7 +2177,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2257,8 +2186,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(SignMinusOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SignMinusOperator_ZOS_Forward) { double a = 1.5, aout; adouble ad; @@ -2278,7 +2206,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_ZOS_Forward) double *y = myalloc1(1); *x = 1.5; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2287,8 +2215,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(SignMinusOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(SignMinusOperator_FOS_Forward) { double a = 1.5, aout; adouble ad; @@ -2310,7 +2237,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_FOS_Forward) *x = 1.5; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2322,8 +2249,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(SignMinusOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(SignMinusOperator_FOS_Reverse) { double a = 1.5, aout; adouble ad; @@ -2342,7 +2268,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2351,8 +2277,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(Atan2Operator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(Atan2Operator_ZOS_Forward) { double a = 12.3, b = 2.1, out; adouble ad, bd; @@ -2374,7 +2299,7 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_ZOS_Forward) *x = 12.3; *(x + 1) = 2.1; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2383,8 +2308,7 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Forward) { double a = 12.3, b = 2.1, out; adouble ad, bd; @@ -2397,8 +2321,8 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Forward) ad >>= out; trace_off(); - double aDerivative = b / (a*a + b*b); - double bDerivative = -a / (a*a + b*b); + double aDerivative = b / (a * a + b * b); + double bDerivative = -a / (a * a + b * b); a = std::atan2(a, b); double *x = myalloc1(2); @@ -2411,7 +2335,7 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Forward) *(x + 1) = 2.1; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2420,7 +2344,7 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Forward) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -2431,8 +2355,7 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Reverse) { double a = 12.3, b = 2.1, out; adouble ad, bd; @@ -2445,14 +2368,14 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Reverse) ad >>= out; trace_off(); - double aDerivative = b / (a*a + b*b); - double bDerivative = -a / (a*a + b*b); + double aDerivative = b / (a * a + b * b); + double bDerivative = -a / (a * a + b * b); double *u = myalloc1(1); double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2462,8 +2385,7 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_1) { double a = 2.3, e = 3.5, aout; adouble ad; @@ -2483,7 +2405,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_1) double *y = myalloc1(1); *x = 2.3; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2492,8 +2414,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_1) myfree1(y); } -BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_1) { double a = 2.3, e = 3.5, aout; adouble ad; @@ -2515,7 +2436,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_1) *x = 2.3; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2547,7 +2468,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_1) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2556,8 +2477,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_1) myfree1(z); } */ -BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_2) { double a = 2.3, b = 3.5, out; adouble ad, bd; @@ -2579,7 +2499,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_2) *x = 2.3; *(x + 1) = 3.5; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2588,8 +2508,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_2) myfree1(y); } -BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_2) { double a = 2.3, b = 3.5, out; adouble ad, bd; @@ -2616,7 +2535,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_2) *(x + 1) = 3.5; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2625,7 +2544,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_2) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -2636,8 +2555,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_2) myfree1(yd); } -BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_2) { double a = 2.3, b = 3.5, out; adouble ad, bd; @@ -2657,7 +2575,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_2) double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2667,8 +2585,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_2) myfree1(z); } -BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_3) -{ +BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_3) { double a = 2.3, e = 3.5, eout; adouble ed; @@ -2688,7 +2605,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_3) double *y = myalloc1(1); *x = 3.5; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == e, tt::tolerance(tol)); @@ -2697,8 +2614,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_ZOS_Forward_3) myfree1(y); } -BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_3) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_3) { double a = 2.3, e = 3.5, eout; adouble ed; @@ -2720,7 +2636,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_3) *x = 3.5; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == e, tt::tolerance(tol)); @@ -2732,8 +2648,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Forward_3) myfree1(yd); } -BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_3) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_3) { double a = 2.3, e = 3.5, eout; adouble ed; @@ -2752,7 +2667,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOS_Reverse_3) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == eDerivative, tt::tolerance(tol)); @@ -2786,7 +2701,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_ZOS_Forward_1) *x = 4.; *(x + 1) = 3.; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2822,7 +2737,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Forward_1) *(x + 1) = 3.; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2830,7 +2745,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Forward_1) *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -2862,7 +2777,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Reverse_1) double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2872,8 +2787,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Reverse_1) myfree1(z); } */ -BOOST_AUTO_TEST_CASE(LdexpOperator_ZOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_ZOS_Forward_2) { double a = 4., e = 3., aout; adouble ad; @@ -2893,7 +2807,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_ZOS_Forward_2) double *y = myalloc1(1); *x = 4.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2902,8 +2816,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_ZOS_Forward_2) myfree1(y); } -BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Forward_2) { double a = 4., e = 3., aout; adouble ad; @@ -2925,7 +2838,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Forward_2) *x = 4.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -2937,8 +2850,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Forward_2) myfree1(yd); } -BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Reverse_2) { double a = 4., e = 3., aout; adouble ad; @@ -2957,7 +2869,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Reverse_2) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -2987,7 +2899,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_ZOS_Forward_3) double *y = myalloc1(1); *x = 3.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == e, tt::tolerance(tol)); @@ -3019,7 +2931,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Forward_3) *x = 3.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == e, tt::tolerance(tol)); @@ -3051,7 +2963,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Reverse_3) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == eDerivative, tt::tolerance(tol)); @@ -3061,8 +2973,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOS_Reverse_3) } */ -BOOST_AUTO_TEST_CASE(FabsOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(FabsOperator_ZOS_Forward) { double a = 1.4, b = -5., c = 0., aout; adouble ad; @@ -3090,7 +3001,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_ZOS_Forward) *x1 = 1.4; *x2 = -5.; *x3 = 0.; - + zos_forward(1, 1, 1, 0, x1, y1); zos_forward(1, 1, 1, 0, x2, y2); zos_forward(1, 1, 1, 0, x3, y3); @@ -3107,8 +3018,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_ZOS_Forward) myfree1(y3); } -BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Forward) { double a = 1.4, b = -5., c = 0., aout, bout, cout; adouble ad; @@ -3138,7 +3048,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Forward) *xd1 = 1.; *x2 = -5.; *xd2 = 1.; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); fos_forward(1, 1, 1, 0, x2, xd2, y2, yd2); @@ -3182,8 +3092,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Forward) myfree1(yd3); } -BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Pos) -{ +BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Pos) { double a = 1.4, aout; adouble ad; @@ -3201,7 +3110,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Pos) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -3210,8 +3119,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Pos) myfree1(z); } -BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Neg) -{ +BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Neg) { double a = -5., aout; adouble ad; @@ -3229,7 +3137,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Neg) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -3238,8 +3146,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Neg) myfree1(z); } -BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Zero) -{ +BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Zero) { double a = 0., aout; adouble ad; @@ -3258,7 +3165,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Zero) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -3267,8 +3174,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOS_Reverse_Zero) myfree1(z); } -BOOST_AUTO_TEST_CASE(CeilOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CeilOperator_ZOS_Forward) { double a = 3.573, aout; adouble ad; @@ -3288,7 +3194,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_ZOS_Forward) double *y = myalloc1(1); *x = 3.573; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3297,8 +3203,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(CeilOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CeilOperator_FOS_Forward) { double a = 3.573, aout; adouble ad; @@ -3320,7 +3225,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_FOS_Forward) *x = 3.573; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3332,8 +3237,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(CeilOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(CeilOperator_FOS_Reverse) { double a = 3.573, aout; adouble ad; @@ -3351,7 +3255,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -3360,8 +3264,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(FloorOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(FloorOperator_ZOS_Forward) { double a = 4.483, aout; adouble ad; @@ -3381,7 +3284,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_ZOS_Forward) double *y = myalloc1(1); *x = 4.483; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3390,8 +3293,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(FloorOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(FloorOperator_FOS_Forward) { double a = 4.483, aout; adouble ad; @@ -3413,7 +3315,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_FOS_Forward) *x = 4.483; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3425,8 +3327,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(FloorOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(FloorOperator_FOS_Reverse) { double a = 4.483, aout; adouble ad; @@ -3444,7 +3345,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -3453,8 +3354,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_1) { double a = 4., b = 3.2, out; adouble ad, bd; @@ -3476,7 +3376,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_1) *x = 4.; *(x + 1) = 3.2; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3485,8 +3385,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_1) myfree1(y); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_1) { double a = 4., b = 3.2, out; adouble ad, bd; @@ -3513,7 +3412,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_1) *(x + 1) = 3.2; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3522,7 +3421,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_1) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -3542,7 +3441,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_1) *(x1 + 1) = 2.5; *xd1 = 1.3; *(xd1 + 1) = 3.7; - + fos_forward(1, 1, 2, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == 2.5, tt::tolerance(tol)); @@ -3554,8 +3453,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_1) myfree1(yd1); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_1) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_1) { double a = 4., b = 3.2, out; adouble ad, bd; @@ -3575,7 +3473,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_1) double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -3601,7 +3499,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_1) double *z1 = myalloc1(2); *u1 = 1.; - + fos_reverse(1, 1, 2, u1, z1); BOOST_TEST(*z1 == 0.5, tt::tolerance(tol)); @@ -3611,8 +3509,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_1) myfree1(z1); } -BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -3632,7 +3529,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_2) double *y = myalloc1(1); *x = 3.2; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == b, tt::tolerance(tol)); @@ -3641,8 +3538,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_2) myfree1(y); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -3654,7 +3550,8 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_2) bd >>= bout; trace_off(); - /* Derivative value is 0.0, as the active variable is smaller than the passive one. */ + /* Derivative value is 0.0, as the active variable is smaller than the passive + * one. */ double bDerivative = 0.; b = std::fmax(a, b); @@ -3665,7 +3562,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_2) *x = 3.2; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == b, tt::tolerance(tol)); @@ -3698,7 +3595,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_2) *x1 = 2.5; *xd1 = -1.3; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == b1, tt::tolerance(tol)); @@ -3706,7 +3603,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_2) *xd1 = 3.7; b1Derivative = 3.7; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == b1, tt::tolerance(tol)); @@ -3718,8 +3615,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_2) myfree1(yd1); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -3738,7 +3634,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_2) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == bDerivative, tt::tolerance(tol)); @@ -3765,7 +3661,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_2) double *z1 = myalloc1(1); *u1 = 1.; - + fos_reverse(1, 1, 1, u1, z1); BOOST_TEST(*z1 == b1Derivative, tt::tolerance(tol)); @@ -3774,8 +3670,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_2) myfree1(z1); } -BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_3) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -3795,7 +3690,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_3) double *y = myalloc1(1); *x = 4.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3804,8 +3699,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_ZOS_Forward_3) myfree1(y); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_3) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -3817,7 +3711,8 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_3) ad >>= aout; trace_off(); - /* Derivative value is 1.0, as the active variable is grater than the passive one. */ + /* Derivative value is 1.0, as the active variable is grater than the passive + * one. */ double aDerivative = 1.; a = std::fmax(a, b); @@ -3828,7 +3723,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_3) *x = 4.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3861,7 +3756,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_3) *x1 = 2.5; *xd1 = -1.3; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == a1, tt::tolerance(tol)); @@ -3869,7 +3764,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_3) *xd1 = 3.7; a1Derivative = 3.7; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == a1, tt::tolerance(tol)); @@ -3881,8 +3776,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Forward_3) myfree1(yd1); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_3) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -3901,7 +3795,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_3) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -3928,7 +3822,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_3) double *z1 = myalloc1(1); *u1 = 1.; - + fos_reverse(1, 1, 1, u1, z1); BOOST_TEST(*z1 == a1Derivative, tt::tolerance(tol)); @@ -3937,8 +3831,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOS_Reverse_3) myfree1(z1); } -BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_1) { double a = 4., b = 3.2, out; adouble ad, bd; @@ -3960,7 +3853,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_1) *x = 4.; *(x + 1) = 3.2; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -3969,8 +3862,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_1) myfree1(y); } -BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_1) { double a = 4., b = 3.2, out; adouble ad, bd; @@ -3997,7 +3889,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_1) *(x + 1) = 3.2; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4006,7 +3898,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_1) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -4026,7 +3918,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_1) *(x1 + 1) = 2.5; *xd1 = 1.3; *(xd1 + 1) = 3.7; - + fos_forward(1, 1, 2, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == 2.5, tt::tolerance(tol)); @@ -4038,8 +3930,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_1) myfree1(yd1); } -BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_1) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_1) { double a = 4., b = 3.2, out; adouble ad, bd; @@ -4059,7 +3950,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_1) double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -4085,7 +3976,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_1) double *z1 = myalloc1(2); *u1 = 1.; - + fos_reverse(1, 1, 2, u1, z1); BOOST_TEST(*z1 == 0.5, tt::tolerance(tol)); @@ -4095,8 +3986,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_1) myfree1(z1); } -BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -4116,7 +4006,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_2) double *y = myalloc1(1); *x = 3.2; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == b, tt::tolerance(tol)); @@ -4125,8 +4015,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_2) myfree1(y); } -BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -4138,7 +4027,8 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_2) bd >>= bout; trace_off(); - /* Derivative value is 1.0, as the active variable is smaller than the passive one. */ + /* Derivative value is 1.0, as the active variable is smaller than the passive + * one. */ double bDerivative = 1.; b = std::fmin(a, b); @@ -4149,7 +4039,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_2) *x = 3.2; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == b, tt::tolerance(tol)); @@ -4182,7 +4072,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_2) *x1 = 2.5; *xd1 = -1.3; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == b1, tt::tolerance(tol)); @@ -4190,7 +4080,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_2) *xd1 = 3.7; b1Derivative = 0.; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == b1, tt::tolerance(tol)); @@ -4202,8 +4092,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_2) myfree1(yd1); } -BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -4222,7 +4111,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_2) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == bDerivative, tt::tolerance(tol)); @@ -4249,7 +4138,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_2) double *z1 = myalloc1(1); *u1 = 1.; - + fos_reverse(1, 1, 1, u1, z1); BOOST_TEST(*z1 == b1Derivative, tt::tolerance(tol)); @@ -4258,8 +4147,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_2) myfree1(z1); } -BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_3) -{ +BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -4279,7 +4167,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_3) double *y = myalloc1(1); *x = 4.; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4288,8 +4176,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_ZOS_Forward_3) myfree1(y); } -BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_3) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -4301,7 +4188,8 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_3) ad >>= aout; trace_off(); - /* Derivative value is 0.0, as the active variable is grater than the passive one. */ + /* Derivative value is 0.0, as the active variable is grater than the passive + * one. */ double aDerivative = 0.; a = std::fmin(a, b); @@ -4312,7 +4200,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_3) *x = 4.; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4345,7 +4233,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_3) *x1 = 2.5; *xd1 = -1.3; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == a1, tt::tolerance(tol)); @@ -4353,7 +4241,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_3) *xd1 = 3.7; a1Derivative = 0.; - + fos_forward(1, 1, 1, 0, x1, xd1, y1, yd1); BOOST_TEST(*y1 == a1, tt::tolerance(tol)); @@ -4365,8 +4253,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Forward_3) myfree1(yd1); } -BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_3) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -4385,7 +4272,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_3) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -4412,7 +4299,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_3) double *z1 = myalloc1(1); *u1 = 1.; - + fos_reverse(1, 1, 1, u1, z1); BOOST_TEST(*z1 == a1Derivative, tt::tolerance(tol)); @@ -4421,8 +4308,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOS_Reverse_3) myfree1(z1); } -BOOST_AUTO_TEST_CASE(ErfOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(ErfOperator_ZOS_Forward) { double a = 7.1, aout; adouble ad; @@ -4442,7 +4328,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_ZOS_Forward) double *y = myalloc1(1); *x = 7.1; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4451,8 +4337,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(ErfOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(ErfOperator_FOS_Forward) { double a = 7.1, aout; adouble ad; @@ -4474,7 +4359,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOS_Forward) *x = 7.1; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4486,8 +4371,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(ErfOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(ErfOperator_FOS_Reverse) { double a = 7.1, aout; adouble ad; @@ -4505,7 +4389,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -4514,8 +4398,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(ErfcOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(ErfcOperator_ZOS_Forward) { double a = 7.1, aout; adouble ad; @@ -4535,7 +4418,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_ZOS_Forward) double *y = myalloc1(1); *x = 7.1; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4544,8 +4427,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(ErfcOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(ErfcOperator_FOS_Forward) { double a = 7.1, aout; adouble ad; @@ -4567,7 +4449,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOS_Forward) *x = 7.1; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4579,8 +4461,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(ErfcOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(ErfcOperator_FOS_Reverse) { double a = 7.1, aout; adouble ad; @@ -4598,7 +4479,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -4607,8 +4488,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(EqOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(EqOperator_ZOS_Forward) { double a = 10.01, aout; adouble ad, bd; @@ -4626,7 +4506,7 @@ BOOST_AUTO_TEST_CASE(EqOperator_ZOS_Forward) double *y = myalloc1(1); *x = 10.01; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4635,8 +4515,7 @@ BOOST_AUTO_TEST_CASE(EqOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(EqOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(EqOperator_FOS_Forward) { double a = 10.01, aout; adouble ad, bd; @@ -4657,7 +4536,7 @@ BOOST_AUTO_TEST_CASE(EqOperator_FOS_Forward) *x = 10.01; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4669,8 +4548,7 @@ BOOST_AUTO_TEST_CASE(EqOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(EqOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(EqOperator_FOS_Reverse) { double a = 10.01, aout; adouble ad, bd; @@ -4688,7 +4566,7 @@ BOOST_AUTO_TEST_CASE(EqOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -4697,8 +4575,7 @@ BOOST_AUTO_TEST_CASE(EqOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(EqPlusOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(EqPlusOperator_ZOS_Forward) { double a = 5.132, aout; adouble ad; @@ -4718,7 +4595,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_ZOS_Forward) double *y = myalloc1(1); *x = 5.132; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4727,8 +4604,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(EqPlusOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(EqPlusOperator_FOS_Forward) { double a = 5.132, aout; adouble ad; @@ -4750,7 +4626,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_FOS_Forward) *x = 5.132; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4762,8 +4638,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(EqPlusOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(EqPlusOperator_FOS_Reverse) { double a = 5.132, aout; adouble ad; @@ -4782,7 +4657,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -4791,8 +4666,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(EqMinusOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(EqMinusOperator_ZOS_Forward) { double a = 5.132, aout; adouble ad; @@ -4812,7 +4686,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_ZOS_Forward) double *y = myalloc1(1); *x = 5.132; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4821,8 +4695,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(EqMinusOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(EqMinusOperator_FOS_Forward) { double a = 5.132, aout; adouble ad; @@ -4844,7 +4717,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_FOS_Forward) *x = 5.132; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4856,8 +4729,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_FOS_Forward) myfree1(yd); } -BOOST_AUTO_TEST_CASE(EqMinusOperator_FOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(EqMinusOperator_FOS_Reverse) { double a = 5.132, aout; adouble ad; @@ -4876,7 +4748,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_FOS_Reverse) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -4885,8 +4757,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_FOS_Reverse) myfree1(z); } -BOOST_AUTO_TEST_CASE(EqTimesOperator_ZOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperator_ZOS_Forward_1) { double a = 5.132, aout; adouble ad; @@ -4906,7 +4777,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_ZOS_Forward_1) double *y = myalloc1(1); *x = 5.132; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4915,8 +4786,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_ZOS_Forward_1) myfree1(y); } -BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_1) { double a = 5.132, aout; adouble ad; @@ -4938,7 +4808,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_1) *x = 5.132; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -4950,8 +4820,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_1) myfree1(yd); } -BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Reverse_1) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Reverse_1) { double a = 5.132, aout; adouble ad; @@ -4970,7 +4839,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Reverse_1) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -4979,8 +4848,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Reverse_1) myfree1(z); } -BOOST_AUTO_TEST_CASE(EqTimesOperator_ZOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperator_ZOS_Forward_2) { double a = 5.132, b = 11.1, out; adouble ad, bd; @@ -5002,7 +4870,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_ZOS_Forward_2) *x = 5.132; *(x + 1) = 11.1; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -5011,8 +4879,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_ZOS_Forward_2) myfree1(y); } -BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_2) { double a = 5.132, b = 11.1, out; adouble ad, bd; @@ -5039,7 +4906,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_2) *(x + 1) = 11.1; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -5048,7 +4915,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_2) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -5059,8 +4926,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Forward_2) myfree1(yd); } -BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Reverse_2) { double a = 5.132, b = 11.1, out; adouble ad, bd; @@ -5080,7 +4946,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Reverse_2) double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -5090,8 +4956,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOS_Reverse_2) myfree1(z); } -BOOST_AUTO_TEST_CASE(EqDivOperator_ZOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(EqDivOperator_ZOS_Forward_1) { double a = 5.132, aout; adouble ad; @@ -5111,7 +4976,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_ZOS_Forward_1) double *y = myalloc1(1); *x = 5.132; - + zos_forward(1, 1, 1, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -5120,8 +4985,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_ZOS_Forward_1) myfree1(y); } -BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_1) -{ +BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_1) { double a = 5.132, aout; adouble ad; @@ -5143,7 +5007,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_1) *x = 5.132; *xd = 1.; - + fos_forward(1, 1, 1, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -5155,8 +5019,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_1) myfree1(yd); } -BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Reverse_1) -{ +BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Reverse_1) { double a = 5.132, aout; adouble ad; @@ -5175,7 +5038,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Reverse_1) double *z = myalloc1(1); *u = 1.; - + fos_reverse(1, 1, 1, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -5184,8 +5047,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Reverse_1) myfree1(z); } -BOOST_AUTO_TEST_CASE(EqDivOperator_ZOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(EqDivOperator_ZOS_Forward_2) { double a = 5.132, b = 11.1, out; adouble ad, bd; @@ -5207,7 +5069,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_ZOS_Forward_2) *x = 5.132; *(x + 1) = 11.1; - + zos_forward(1, 1, 2, 0, x, y); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -5216,8 +5078,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_ZOS_Forward_2) myfree1(y); } -BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_2) -{ +BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_2) { double a = 5.132, b = 11.1, out; adouble ad, bd; @@ -5231,7 +5092,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_2) trace_off(); double aDerivative = 1. / b; - double bDerivative = -a / (b*b); + double bDerivative = -a / (b * b); a /= b; double *x = myalloc1(2); @@ -5244,7 +5105,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_2) *(x + 1) = 11.1; *xd = 1.; *(xd + 1) = 0.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); @@ -5253,7 +5114,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_2) /* Test partial derivative wrt b. */ *xd = 0.; *(xd + 1) = 1.; - + fos_forward(1, 1, 2, 0, x, xd, y, yd); BOOST_TEST(*yd == bDerivative, tt::tolerance(tol)); @@ -5264,8 +5125,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Forward_2) myfree1(yd); } -BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Reverse_2) { double a = 5.132, b = 11.1, out; adouble ad, bd; @@ -5279,13 +5139,13 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Reverse_2) trace_off(); double aDerivative = 1. / b; - double bDerivative = -a / (b*b); + double bDerivative = -a / (b * b); double *u = myalloc1(1); double *z = myalloc1(2); *u = 1.; - + fos_reverse(1, 1, 2, u, z); BOOST_TEST(*z == aDerivative, tt::tolerance(tol)); @@ -5295,8 +5155,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOS_Reverse_2) myfree1(z); } -BOOST_AUTO_TEST_CASE(CondassignOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CondassignOperator_ZOS_Forward) { double out; adouble cond, arg1, arg2; adouble p; @@ -5319,7 +5178,7 @@ BOOST_AUTO_TEST_CASE(CondassignOperator_ZOS_Forward) *x = 1.; *(x + 1) = 3.5; *(x + 2) = 5.3; - + zos_forward(1, 1, 3, 0, x, y); BOOST_TEST(*y == 3.5, tt::tolerance(tol)); @@ -5328,8 +5187,7 @@ BOOST_AUTO_TEST_CASE(CondassignOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(CondassignOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CondassignOperator_FOS_Forward) { double out; adouble cond, arg1, arg2; adouble p; @@ -5357,7 +5215,7 @@ BOOST_AUTO_TEST_CASE(CondassignOperator_FOS_Forward) *xd = 0.; *(xd + 1) = 0.1; *(xd + 2) = 0.2; - + fos_forward(1, 1, 3, 0, x, xd, y, yd); BOOST_TEST(*y == 3.5, tt::tolerance(tol)); @@ -5392,7 +5250,7 @@ BOOST_AUTO_TEST_CASE(CondassignOperator_FOS_Reverse) double *z = myalloc1(3); *u = 1.; - + fos_reverse(1, 1, 3, u, z); BOOST_TEST(*z == 0., tt::tolerance(tol)); @@ -5403,8 +5261,7 @@ BOOST_AUTO_TEST_CASE(CondassignOperator_FOS_Reverse) myfree1(z); } */ -BOOST_AUTO_TEST_CASE(CondeqassignOperator_ZOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CondeqassignOperator_ZOS_Forward) { double out; adouble cond, arg1, arg2; adouble p; @@ -5427,7 +5284,7 @@ BOOST_AUTO_TEST_CASE(CondeqassignOperator_ZOS_Forward) *x = 1.; *(x + 1) = 3.5; *(x + 2) = 5.3; - + zos_forward(1, 1, 3, 0, x, y); BOOST_TEST(*y == 3.5, tt::tolerance(tol)); @@ -5436,8 +5293,7 @@ BOOST_AUTO_TEST_CASE(CondeqassignOperator_ZOS_Forward) myfree1(y); } -BOOST_AUTO_TEST_CASE(CondeqassignOperator_FOS_Forward) -{ +BOOST_AUTO_TEST_CASE(CondeqassignOperator_FOS_Forward) { double out; adouble cond, arg1, arg2; adouble p; @@ -5465,7 +5321,7 @@ BOOST_AUTO_TEST_CASE(CondeqassignOperator_FOS_Forward) *xd = 0.; *(xd + 1) = 0.1; *(xd + 2) = 0.2; - + fos_forward(1, 1, 3, 0, x, xd, y, yd); BOOST_TEST(*y == 3.5, tt::tolerance(tol)); @@ -5500,7 +5356,7 @@ BOOST_AUTO_TEST_CASE(CondeqassignOperator_FOS_Reverse) double *z = myalloc1(3); *u = 1.; - + fos_reverse(1, 1, 3, u, z); BOOST_TEST(*z == 0., tt::tolerance(tol)); @@ -5516,16 +5372,14 @@ BOOST_AUTO_TEST_CASE(CondeqassignOperator_FOS_Reverse) * activated. This advanced branching is not tested here. */ -BOOST_AUTO_TEST_CASE(TraceNotOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TraceNotOperatorPrimal) { double a = 1.0; adouble ad = a; BOOST_TEST(!a == 0.0, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TraceCompNeqOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TraceCompNeqOperatorPrimal) { double a = 1.5, b = 0.5; adouble ad = a, bd = b; @@ -5540,8 +5394,7 @@ BOOST_AUTO_TEST_CASE(TraceCompNeqOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TraceCompEqOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TraceCompEqOperatorPrimal) { double a = 0.5, b = 1.5; adouble ad = a, bd = b; @@ -5556,8 +5409,7 @@ BOOST_AUTO_TEST_CASE(TraceCompEqOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TraceCompLeqOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TraceCompLeqOperatorPrimal) { double a = 1.0, b = 0.99; adouble ad = a, bd = b; @@ -5572,8 +5424,7 @@ BOOST_AUTO_TEST_CASE(TraceCompLeqOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TraceCompGeqOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TraceCompGeqOperatorPrimal) { double a = 1.2, b = 2.5; adouble ad = a, bd = b; @@ -5588,8 +5439,7 @@ BOOST_AUTO_TEST_CASE(TraceCompGeqOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TraceCompLeOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TraceCompLeOperatorPrimal) { double a = 1.1, b = 1.1; adouble ad = a, bd = b; @@ -5604,8 +5454,7 @@ BOOST_AUTO_TEST_CASE(TraceCompLeOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TraceCompGeOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TraceCompGeOperatorPrimal) { double a = 1.7, b = 7.5; adouble ad = a, bd = b; @@ -5632,9 +5481,4 @@ BOOST_AUTO_TEST_CASE(TraceCompGeOperatorPrimal) /* What does reverse mode do for fmax(), fmin() with a = b? */ - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/ADOL-C/boost-test/traceOperatorVector.cpp b/ADOL-C/boost-test/traceOperatorVector.cpp index 0fb6c5942..799264ff0 100644 --- a/ADOL-C/boost-test/traceOperatorVector.cpp +++ b/ADOL-C/boost-test/traceOperatorVector.cpp @@ -7,15 +7,13 @@ namespace tt = boost::test_tools; #include "const.h" -BOOST_AUTO_TEST_SUITE( trace_vector ) - +BOOST_AUTO_TEST_SUITE(trace_vector) /***********************************/ /* Tests for trace vector mode */ /* Author: Philipp Schuette */ /***********************************/ - /* Naming convention for test cases: Operatorname_Operator_FOV_Forward for * forward derivative evaluation in vector mode. * @@ -24,8 +22,7 @@ BOOST_AUTO_TEST_SUITE( trace_vector ) * as well. */ -BOOST_AUTO_TEST_CASE(ExpOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(ExpOperator_FOV_Forward) { double a = 2., aout; adouble ad; @@ -63,8 +60,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(ExpOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(ExpOperator_FOV_Reverse) { double a = 2., aout; adouble ad; @@ -87,14 +83,13 @@ BOOST_AUTO_TEST_CASE(ExpOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::exp(3.), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::exp(3.), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { double a = 2., b = 3.5, out; adouble ad, bd; @@ -141,8 +136,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(MultOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(MultOperator_FOV_Reverse) { double a = 2., b = 3.5, aout; adouble ad, bd; @@ -168,15 +162,14 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOV_Reverse) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 2.*aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == 2.*bDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 2. * aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == 2. * bDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) { double a = 2.5, b = 3., out; adouble ad, bd; @@ -223,8 +216,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(AddOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(AddOperator_FOV_Reverse) { double a = 2.5, b = 3., aout; adouble ad, bd; @@ -250,15 +242,14 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOV_Reverse) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 9.*aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == 9.*bDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 9. * aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == 9. * bDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { double a = 1.5, b = 3.2, out; adouble ad, bd; @@ -305,8 +296,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(SubOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(SubOperator_FOV_Reverse) { double a = 1.5, b = 3.2, aout; adouble ad, bd; @@ -332,15 +322,14 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOV_Reverse) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == std::sqrt(2)*aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == std::sqrt(2)*bDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == std::sqrt(2) * aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == std::sqrt(2) * bDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) { double a = 0.5, b = 4.5, out; adouble ad, bd; @@ -354,7 +343,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) trace_off(); double aDerivative = 1. / b; - double bDerivative = -a / (b*b); + double bDerivative = -a / (b * b); a = a / b; double *x = myalloc1(2); @@ -387,8 +376,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(DivOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(DivOperator_FOV_Reverse) { double a = 0.5, b = 4.5, aout; adouble ad, bd; @@ -402,7 +390,7 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOV_Reverse) trace_off(); double aDerivative = 1. / b; - double bDerivative = -a / (b*b); + double bDerivative = -a / (b * b); double **u = myalloc2(2, 1); double **z = myalloc2(2, 2); @@ -414,15 +402,14 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOV_Reverse) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 0.9*aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == 0.9*bDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 0.9 * aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == 0.9 * bDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(TanOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(TanOperator_FOV_Forward) { double a = 0.7, aout; adouble ad; @@ -435,7 +422,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOV_Forward) trace_off(); a = tan(a); - double aDerivative = 1. + a*a; + double aDerivative = 1. + a * a; double *x = myalloc1(1); double **xd = myalloc2(1, 2); @@ -451,8 +438,10 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOV_Forward) fov_forward(1, 1, 1, 2, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); - BOOST_TEST(yd[0][0] == aDerivative * (1. + std::pow(2, 0)), tt::tolerance(tol)); - BOOST_TEST(yd[0][1] == aDerivative * (1. + std::pow(2, 1)), tt::tolerance(tol)); + BOOST_TEST(yd[0][0] == aDerivative * (1. + std::pow(2, 0)), + tt::tolerance(tol)); + BOOST_TEST(yd[0][1] == aDerivative * (1. + std::pow(2, 1)), + tt::tolerance(tol)); myfree1(x); myfree2(xd); @@ -460,8 +449,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(TanOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(TanOperator_FOV_Reverse) { double a = 0.7, aout; adouble ad; @@ -474,7 +462,7 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOV_Reverse) trace_off(); a = std::tan(a); - double aDerivative = 1. + a*a; + double aDerivative = 1. + a * a; double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -485,14 +473,13 @@ BOOST_AUTO_TEST_CASE(TanOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*1.1, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * 1.1, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(SinOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(SinOperator_FOV_Forward) { double a = 1.2, aout; adouble ad; @@ -521,7 +508,7 @@ BOOST_AUTO_TEST_CASE(SinOperator_FOV_Forward) fov_forward(1, 1, 1, 2, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); - BOOST_TEST(yd[0][0] == aDerivative , tt::tolerance(tol)); + BOOST_TEST(yd[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(yd[0][1] == aDerivative * (-1.), tt::tolerance(tol)); myfree1(x); @@ -530,8 +517,7 @@ BOOST_AUTO_TEST_CASE(SinOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(SinOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(SinOperator_FOV_Reverse) { double a = 1.2, aout; adouble ad; @@ -554,14 +540,13 @@ BOOST_AUTO_TEST_CASE(SinOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::tan(4.4), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::tan(4.4), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(CosOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CosOperator_FOV_Forward) { double a = 1.2, aout; adouble ad; @@ -599,8 +584,7 @@ BOOST_AUTO_TEST_CASE(CosOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CosOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CosOperator_FOV_Reverse) { double a = 1.2, aout; adouble ad; @@ -623,14 +607,13 @@ BOOST_AUTO_TEST_CASE(CosOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::log(2.), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::log(2.), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(SqrtOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(SqrtOperator_FOV_Forward) { double a = 2.2, aout; adouble ad; @@ -643,7 +626,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOV_Forward) trace_off(); a = std::sqrt(a); - double aDerivative = 1. / (2.*a); + double aDerivative = 1. / (2. * a); double *x = myalloc1(1); double **xd = myalloc2(1, 2); @@ -668,8 +651,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(SqrtOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(SqrtOperator_FOV_Reverse) { double a = 2.2, aout; adouble ad; @@ -681,7 +663,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (2.*std::sqrt(a)); + double aDerivative = 1. / (2. * std::sqrt(a)); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -692,14 +674,13 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::exp(2.), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::exp(2.), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(LogOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(LogOperator_FOV_Forward) { double a = 4.9, aout; adouble ad; @@ -737,8 +718,7 @@ BOOST_AUTO_TEST_CASE(LogOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(LogOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(LogOperator_FOV_Reverse) { double a = 4.9, aout; adouble ad; @@ -761,14 +741,13 @@ BOOST_AUTO_TEST_CASE(LogOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::exp(-1.), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::exp(-1.), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(SinhOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(SinhOperator_FOV_Forward) { double a = 4., aout; adouble ad; @@ -791,14 +770,15 @@ BOOST_AUTO_TEST_CASE(SinhOperator_FOV_Forward) x[0] = 4.; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - std::sqrt(2.*i); + xd[0][i] = 1. - std::sqrt(2. * i); } fov_forward(1, 1, 1, 2, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); BOOST_TEST(yd[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(yd[0][1] == aDerivative * (1. - std::sqrt(2.)), tt::tolerance(tol)); + BOOST_TEST(yd[0][1] == aDerivative * (1. - std::sqrt(2.)), + tt::tolerance(tol)); myfree1(x); myfree2(xd); @@ -806,8 +786,7 @@ BOOST_AUTO_TEST_CASE(SinhOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(SinhOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(SinhOperator_FOV_Reverse) { double a = 4., aout; adouble ad; @@ -830,14 +809,13 @@ BOOST_AUTO_TEST_CASE(SinhOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::cosh(3.5), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::cosh(3.5), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(CoshOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CoshOperator_FOV_Forward) { double a = 4., aout; adouble ad; @@ -875,8 +853,7 @@ BOOST_AUTO_TEST_CASE(CoshOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CoshOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CoshOperator_FOV_Reverse) { double a = 4., aout; adouble ad; @@ -899,14 +876,13 @@ BOOST_AUTO_TEST_CASE(CoshOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::sinh(3.5), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::sinh(3.5), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Forward) { double a = 4., aout; adouble ad; @@ -919,7 +895,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Forward) trace_off(); a = std::tanh(a); - double aDerivative = 1. - a*a; + double aDerivative = 1. - a * a; double *x = myalloc1(1); double **xd = myalloc2(1, 2); @@ -929,7 +905,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Forward) x[0] = 4.; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - 1.3*i; + xd[0][i] = 1. - 1.3 * i; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -944,8 +920,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Reverse) { double a = 4., aout; adouble ad; @@ -958,7 +933,7 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Reverse) trace_off(); a = std::tanh(a); - double aDerivative = 1. - a*a; + double aDerivative = 1. - a * a; double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -969,14 +944,13 @@ BOOST_AUTO_TEST_CASE(TanhOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 5.4*aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 5.4 * aDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(AsinOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(AsinOperator_FOV_Forward) { double a = 0.9, aout; adouble ad; @@ -988,7 +962,7 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOV_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(1. - a*a)); + double aDerivative = 1. / (std::sqrt(1. - a * a)); a = std::asin(a); double *x = myalloc1(1); @@ -999,14 +973,14 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOV_Forward) x[0] = 0.9; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*(i + 1.7)*4.3; + xd[0][i] = 1. + i * (i + 1.7) * 4.3; } fov_forward(1, 1, 1, 2, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); BOOST_TEST(yd[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(yd[0][1] == aDerivative*(1. + 2.7*4.3), tt::tolerance(tol)); + BOOST_TEST(yd[0][1] == aDerivative * (1. + 2.7 * 4.3), tt::tolerance(tol)); myfree1(x); myfree2(xd); @@ -1014,8 +988,7 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(AsinOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(AsinOperator_FOV_Reverse) { double a = 0.9, aout; adouble ad; @@ -1027,25 +1000,24 @@ BOOST_AUTO_TEST_CASE(AsinOperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(1. - a*a)); + double aDerivative = 1. / (std::sqrt(1. - a * a)); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); u[0][0] = 1.; - u[1][0] = 1. + 2.7*4.3; + u[1][0] = 1. + 2.7 * 4.3; fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*(1. + 2.7*4.3), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * (1. + 2.7 * 4.3), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(AcosOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(AcosOperator_FOV_Forward) { double a = 0.8, aout; adouble ad; @@ -1057,7 +1029,7 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOV_Forward) ad >>= aout; trace_off(); - double aDerivative = -1. / (std::sqrt(1. - a*a)); + double aDerivative = -1. / (std::sqrt(1. - a * a)); a = std::acos(a); double *x = myalloc1(1); @@ -1068,14 +1040,14 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOV_Forward) x[0] = 0.8; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*(i + 0.7)*3.4; + xd[0][i] = 1. - i * (i + 0.7) * 3.4; } fov_forward(1, 1, 1, 2, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); BOOST_TEST(yd[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(yd[0][1] == aDerivative*(1. - 1.7*3.4), tt::tolerance(tol)); + BOOST_TEST(yd[0][1] == aDerivative * (1. - 1.7 * 3.4), tt::tolerance(tol)); myfree1(x); myfree2(xd); @@ -1083,8 +1055,7 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(AcosOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(AcosOperator_FOV_Reverse) { double a = 0.8, aout; adouble ad; @@ -1096,25 +1067,24 @@ BOOST_AUTO_TEST_CASE(AcosOperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = -1. / (std::sqrt(1. - a*a)); + double aDerivative = -1. / (std::sqrt(1. - a * a)); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); u[0][0] = 1.; - u[1][0] = 1. - 1.7*3.4; + u[1][0] = 1. - 1.7 * 3.4; fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*(1. - 1.7*3.4), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * (1. - 1.7 * 3.4), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(AtanOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(AtanOperator_FOV_Forward) { double a = 9.8, aout; adouble ad; @@ -1126,7 +1096,7 @@ BOOST_AUTO_TEST_CASE(AtanOperator_FOV_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (1. + a*a); + double aDerivative = 1. / (1. + a * a); a = std::atan(a); double *x = myalloc1(1); @@ -1137,14 +1107,14 @@ BOOST_AUTO_TEST_CASE(AtanOperator_FOV_Forward) x[0] = 9.8; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*(i - 0.3)*4.3; + xd[0][i] = 1. - i * (i - 0.3) * 4.3; } fov_forward(1, 1, 1, 2, x, xd, y, yd); BOOST_TEST(*y == a, tt::tolerance(tol)); BOOST_TEST(yd[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(yd[0][1] == aDerivative*(1. - 0.7*4.3), tt::tolerance(tol)); + BOOST_TEST(yd[0][1] == aDerivative * (1. - 0.7 * 4.3), tt::tolerance(tol)); myfree1(x); myfree2(xd); @@ -1152,8 +1122,7 @@ BOOST_AUTO_TEST_CASE(AtanOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(Atanperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(Atanperator_FOV_Reverse) { double a = 9.8, aout; adouble ad; @@ -1165,25 +1134,24 @@ BOOST_AUTO_TEST_CASE(Atanperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (1. + a*a); + double aDerivative = 1. / (1. + a * a); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); u[0][0] = 1.; - u[1][0] = 1. - 0.7*4.3; + u[1][0] = 1. - 0.7 * 4.3; fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*(1. - 0.7*4.3), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * (1. - 0.7 * 4.3), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(Log10Operator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(Log10Operator_FOV_Forward) { double a = 12.3, aout; adouble ad; @@ -1206,7 +1174,7 @@ BOOST_AUTO_TEST_CASE(Log10Operator_FOV_Forward) x[0] = 12.3; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*9.9; + xd[0][i] = 1. + i * 9.9; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1221,8 +1189,7 @@ BOOST_AUTO_TEST_CASE(Log10Operator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(Log10perator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(Log10perator_FOV_Reverse) { double a = 12.3, aout; adouble ad; @@ -1234,7 +1201,7 @@ BOOST_AUTO_TEST_CASE(Log10perator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (a*std::log(10)); + double aDerivative = 1. / (a * std::log(10)); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -1245,14 +1212,13 @@ BOOST_AUTO_TEST_CASE(Log10perator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*(1. + 9.9), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * (1. + 9.9), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(AsinhOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(AsinhOperator_FOV_Forward) { double a = 0.6, aout; adouble ad; @@ -1264,7 +1230,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_FOV_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(a*a + 1.)); + double aDerivative = 1. / (std::sqrt(a * a + 1.)); a = std::asinh(a); double *x = myalloc1(1); @@ -1275,7 +1241,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_FOV_Forward) x[0] = 0.6; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*6.2; + xd[0][i] = 1. - i * 6.2; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1290,8 +1256,7 @@ BOOST_AUTO_TEST_CASE(AsinhOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(Asinhperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(Asinhperator_FOV_Reverse) { double a = 0.6, aout; adouble ad; @@ -1303,7 +1268,7 @@ BOOST_AUTO_TEST_CASE(Asinhperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(a*a + 1.)); + double aDerivative = 1. / (std::sqrt(a * a + 1.)); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -1314,14 +1279,13 @@ BOOST_AUTO_TEST_CASE(Asinhperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*(1. - 6.1), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * (1. - 6.1), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(AcoshOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(AcoshOperator_FOV_Forward) { double a = 1.7, aout; adouble ad; @@ -1333,7 +1297,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_FOV_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(a*a - 1.)); + double aDerivative = 1. / (std::sqrt(a * a - 1.)); a = std::acosh(a); double *x = myalloc1(1); @@ -1344,7 +1308,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_FOV_Forward) x[0] = 1.7; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*3.1; + xd[0][i] = 1. + i * 3.1; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1359,8 +1323,7 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(Acoshperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(Acoshperator_FOV_Reverse) { double a = 1.6, aout; adouble ad; @@ -1372,7 +1335,7 @@ BOOST_AUTO_TEST_CASE(Acoshperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (std::sqrt(a*a - 1.)); + double aDerivative = 1. / (std::sqrt(a * a - 1.)); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -1383,14 +1346,13 @@ BOOST_AUTO_TEST_CASE(Acoshperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*(1. + 3.1), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * (1. + 3.1), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(AtanhOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(AtanhOperator_FOV_Forward) { double a = 0.6, aout; adouble ad; @@ -1402,7 +1364,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_FOV_Forward) ad >>= aout; trace_off(); - double aDerivative = 1. / (1. - a*a); + double aDerivative = 1. / (1. - a * a); a = std::atanh(a); double *x = myalloc1(1); @@ -1413,7 +1375,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_FOV_Forward) x[0] = 0.6; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*2.2; + xd[0][i] = 1. + i * 2.2; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1428,8 +1390,7 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(Atanhperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(Atanhperator_FOV_Reverse) { double a = 0.6, aout; adouble ad; @@ -1441,7 +1402,7 @@ BOOST_AUTO_TEST_CASE(Atanhperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1. / (1. - a*a); + double aDerivative = 1. / (1. - a * a); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -1452,14 +1413,13 @@ BOOST_AUTO_TEST_CASE(Atanhperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*(1. + 2.2), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * (1. + 2.2), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(InclOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(InclOperator_FOV_Forward) { double a = 5., aout; adouble ad; @@ -1482,7 +1442,7 @@ BOOST_AUTO_TEST_CASE(InclOperator_FOV_Forward) x[0] = 5.; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*4.2; + xd[0][i] = 1. - i * 4.2; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1497,8 +1457,7 @@ BOOST_AUTO_TEST_CASE(InclOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(Inclperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(Inclperator_FOV_Reverse) { double a = 5., aout; adouble ad; @@ -1521,14 +1480,13 @@ BOOST_AUTO_TEST_CASE(Inclperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::sqrt(5), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::sqrt(5), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(DeclOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(DeclOperator_FOV_Forward) { double a = 5., aout; adouble ad; @@ -1551,7 +1509,7 @@ BOOST_AUTO_TEST_CASE(DeclOperator_FOV_Forward) x[0] = 5.; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*4.2; + xd[0][i] = 1. - i * 4.2; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1566,8 +1524,7 @@ BOOST_AUTO_TEST_CASE(DeclOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(Declperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(Declperator_FOV_Reverse) { double a = 5., aout; adouble ad; @@ -1590,14 +1547,13 @@ BOOST_AUTO_TEST_CASE(Declperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::sqrt(5), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::sqrt(5), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(SignPlusOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(SignPlusOperator_FOV_Forward) { double a = 1.5, aout; adouble ad; @@ -1620,7 +1576,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_FOV_Forward) x[0] = 1.5; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*0.8; + xd[0][i] = 1. + i * 0.8; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1635,8 +1591,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(SignPlusOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(SignPlusOperator_FOV_Reverse) { double a = 1.5, aout; adouble ad; @@ -1659,14 +1614,13 @@ BOOST_AUTO_TEST_CASE(SignPlusOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::sqrt(3), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::sqrt(3), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(SignMinusOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(SignMinusOperator_FOV_Forward) { double a = 1.5, aout; adouble ad; @@ -1689,7 +1643,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_FOV_Forward) x[0] = 1.5; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*0.8; + xd[0][i] = 1. + i * 0.8; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1704,8 +1658,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(SignMinusOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(SignMinusOperator_FOV_Reverse) { double a = 1.5, aout; adouble ad; @@ -1728,14 +1681,13 @@ BOOST_AUTO_TEST_CASE(SignMinusOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::sqrt(3), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::sqrt(3), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(Atan2Operator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(Atan2Operator_FOV_Forward) { double a = 12.3, b = 2.1, out; adouble ad, bd; @@ -1748,8 +1700,8 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOV_Forward) ad >>= out; trace_off(); - double aDerivative = b / (a*a + b*b); - double bDerivative = -a / (a*a + b*b); + double aDerivative = b / (a * a + b * b); + double bDerivative = -a / (a * a + b * b); a = std::atan2(a, b); double *x = myalloc1(2); @@ -1782,8 +1734,7 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(Atan2Operator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(Atan2Operator_FOV_Reverse) { double a = 12.3, b = 2.1, aout; adouble ad, bd; @@ -1796,8 +1747,8 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = b / (a*a + b*b); - double bDerivative = -a / (a*a + b*b); + double aDerivative = b / (a * a + b * b); + double bDerivative = -a / (a * a + b * b); double **u = myalloc2(2, 1); double **z = myalloc2(2, 2); @@ -1809,15 +1760,14 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_FOV_Reverse) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::exp(1.), tt::tolerance(tol)); - BOOST_TEST(z[1][1] == bDerivative*std::exp(1.), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::exp(1.), tt::tolerance(tol)); + BOOST_TEST(z[1][1] == bDerivative * std::exp(1.), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_1) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_1) { double a = 2.3, e = 3.5, aout; adouble ad; @@ -1840,7 +1790,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_1) x[0] = 2.3; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*0.5; + xd[0][i] = 1. + i * 0.5; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -1885,8 +1835,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_1) myfree2(z); } */ -BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_2) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_2) { double a = 2.3, b = 3.5, out; adouble ad, bd; @@ -1933,8 +1882,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_2) myfree2(yd); } -BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_2) { double a = 2.3, b = 3.5, aout; adouble ad, bd; @@ -1948,7 +1896,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_2) trace_off(); double aDerivative = b * std::pow(a, b - 1.); - double bDerivative = std::pow(a, b)*std::log(a); + double bDerivative = std::pow(a, b) * std::log(a); double **u = myalloc2(2, 1); double **z = myalloc2(2, 2); @@ -1960,15 +1908,14 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_2) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 2.*aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == 2.*bDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 2. * aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == 2. * bDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_3) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_3) { double a = 2.3, e = 3.5, eout; adouble ed; @@ -1991,7 +1938,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_3) x[0] = 3.5; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*0.5; + xd[0][i] = 1. + i * 0.5; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -2006,8 +1953,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_3) myfree2(yd); } -BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_3) -{ +BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_3) { double a = 2.3, e = 3.4, eout; adouble ed; @@ -2019,7 +1965,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_3) ed >>= eout; trace_off(); - double eDerivative = std::pow(a, e)*std::log(a); + double eDerivative = std::pow(a, e) * std::log(a); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -2030,7 +1976,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_3) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == eDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == -1.1*eDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == -1.1 * eDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); @@ -2038,8 +1984,7 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_3) /* Frexp operator is not differentiable and does not have to be tested. */ -BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_1) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_1) { double a = 4., b = 3., out; adouble ad, bd; @@ -2086,8 +2031,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_1) myfree2(yd); } -BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_1) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_1) { double a = 4., b = 3., aout; adouble ad, bd; @@ -2101,7 +2045,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_1) trace_off(); double aDerivative = std::pow(2., b); - double bDerivative = a * std::pow(2., b)*std::log(2.); + double bDerivative = a * std::pow(2., b) * std::log(2.); double **u = myalloc2(2, 1); double **z = myalloc2(2, 2); @@ -2113,15 +2057,14 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_1) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == -2.*aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == -2.*bDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == -2. * aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == -2. * bDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_2) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_2) { double a = 4., e = 3., aout; adouble ad; @@ -2159,8 +2102,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_2) myfree2(yd); } -BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_2) { double a = 4., e = 3., aout; adouble ad; @@ -2183,16 +2125,14 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_2) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST( - z[1][0] == std::exp(std::log(10.))*aDerivative, tt::tolerance(tol) - ); + BOOST_TEST(z[1][0] == std::exp(std::log(10.)) * aDerivative, + tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_3) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_3) { double a = 4., e = 3., eout; adouble ed; @@ -2230,8 +2170,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Forward_3) myfree2(yd); } -BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_3) -{ +BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_3) { double a = 4., e = 3., eout; adouble ed; @@ -2254,14 +2193,13 @@ BOOST_AUTO_TEST_CASE(LdexpOperator_FOV_Reverse_3) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == eDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 2.2*eDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 2.2 * eDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Forward) { double a = 1.4, aout; adouble ad; @@ -2284,7 +2222,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Forward) x[0] = 1.4; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*1.5; + xd[0][i] = 1. - i * 1.5; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -2321,8 +2259,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Reverse) { double a = 1.4, aout; adouble ad; @@ -2345,7 +2282,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 3.3*aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 3.3 * aDerivative, tt::tolerance(tol)); a = -5.; @@ -2365,7 +2302,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 3.3*aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 3.3 * aDerivative, tt::tolerance(tol)); a = 0.; @@ -2389,8 +2326,7 @@ BOOST_AUTO_TEST_CASE(FabsOperator_FOV_Reverse) myfree2(z); } -BOOST_AUTO_TEST_CASE(CeilOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CeilOperator_FOV_Forward) { double a = 3.573, aout; adouble ad; @@ -2413,7 +2349,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_FOV_Forward) x[0] = 3.573; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. + i*5.8; + xd[0][i] = 1. + i * 5.8; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -2428,8 +2364,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CeilOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(CeilOperator_FOV_Reverse) { double a = 3.573, aout; adouble ad; @@ -2458,8 +2393,7 @@ BOOST_AUTO_TEST_CASE(CeilOperator_FOV_Reverse) myfree2(z); } -BOOST_AUTO_TEST_CASE(FloorOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(FloorOperator_FOV_Forward) { double a = 4.483, aout; adouble ad; @@ -2482,7 +2416,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_FOV_Forward) x[0] = 4.483; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*5.8; + xd[0][i] = 1. - i * 5.8; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -2497,8 +2431,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(FloorOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(FloorOperator_FOV_Reverse) { double a = 4.483, aout; adouble ad; @@ -2527,8 +2460,7 @@ BOOST_AUTO_TEST_CASE(FloorOperator_FOV_Reverse) myfree2(z); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_1) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_1) { double a = 4., b = 3.2, out; adouble ad, bd; @@ -2593,8 +2525,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_1) myfree2(yd); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_1) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_1) { double a = 4., b = 3.2, aout; adouble ad, bd; @@ -2620,8 +2551,8 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_1) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 2.*aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == 2.*bDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 2. * aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == 2. * bDerivative, tt::tolerance(tol)); a = 2.5, b = 2.5; @@ -2648,8 +2579,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_1) myfree2(z); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_2) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -2672,7 +2602,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_2) x[0] = 3.2; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -2684,7 +2614,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_2) x[0] = 5.2; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } b = std::fmax(a, x[0]); @@ -2699,7 +2629,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_2) x[0] = 4.5; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } b = std::fmax(a, x[0]); @@ -2717,8 +2647,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_2) myfree2(yd); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -2787,8 +2716,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_2) myfree2(z); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_3) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -2811,7 +2739,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_3) x[0] = 4.; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -2823,7 +2751,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_3) x[0] = 2.3; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } a = std::fmax(x[0], b); @@ -2838,7 +2766,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_3) x[0] = 3.2; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } a = std::fmax(x[0], b); @@ -2856,8 +2784,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Forward_3) myfree2(yd); } -BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_3) -{ +BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -2926,8 +2853,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperator_FOV_Reverse_3) myfree2(z); } -BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_1) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_1) { double a = 4., b = 3.2, out; adouble ad, bd; @@ -2992,8 +2918,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_1) myfree2(yd); } -BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_1) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_1) { double a = 4., b = 3.2, aout; adouble ad, bd; @@ -3019,8 +2944,8 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_1) BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); BOOST_TEST(z[0][1] == bDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == 2.*aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][1] == 2.*bDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == 2. * aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][1] == 2. * bDerivative, tt::tolerance(tol)); a = 2.5, b = 2.5; @@ -3047,8 +2972,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_1) myfree2(z); } -BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_2) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -3071,7 +2995,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_2) x[0] = 3.2; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -3083,7 +3007,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_2) x[0] = 5.2; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } b = std::fmin(a, x[0]); @@ -3098,7 +3022,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_2) x[0] = 4.5; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } b = std::fmin(a, x[0]); @@ -3116,8 +3040,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_2) myfree2(yd); } -BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_2) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_2) { double a = 4., b = 3.2, bout; adouble bd; @@ -3186,8 +3109,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_2) myfree2(z); } -BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_3) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -3210,7 +3132,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_3) x[0] = 4.; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -3222,7 +3144,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_3) x[0] = 2.3; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } a = std::fmin(x[0], b); @@ -3237,7 +3159,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_3) x[0] = 3.2; for (int i = 0; i < 2; i++) { - xd[0][i] = 1. - i*2.1; + xd[0][i] = 1. - i * 2.1; } a = std::fmin(x[0], b); @@ -3255,8 +3177,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Forward_3) myfree2(yd); } -BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_3) -{ +BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_3) { double a = 4., b = 3.2, aout; adouble ad; @@ -3325,8 +3246,7 @@ BOOST_AUTO_TEST_CASE(FminOperator_FOV_Reverse_3) myfree2(z); } -BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Forward) { double a = 7.1, aout; adouble ad; @@ -3338,7 +3258,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Forward) ad >>= aout; trace_off(); - double aDerivative = 2. / std::sqrt(std::acos(-1.)) * std::exp(-a*a); + double aDerivative = 2. / std::sqrt(std::acos(-1.)) * std::exp(-a * a); a = std::erf(a); double *x = myalloc1(1); @@ -3349,7 +3269,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Forward) x[0] = 7.1; for (int i = 0; i < 2; i++) { - xd[0][i] = std::pow(3., i*2.); + xd[0][i] = std::pow(3., i * 2.); } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -3364,8 +3284,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Reverse) { double a = 7.1, aout; adouble ad; @@ -3377,7 +3296,7 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 2. / std::sqrt(std::acos(-1.)) * std::exp(-a*a); + double aDerivative = 2. / std::sqrt(std::acos(-1.)) * std::exp(-a * a); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -3388,14 +3307,13 @@ BOOST_AUTO_TEST_CASE(ErfOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == -1.1*aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == -1.1 * aDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Forward) { double a = 7.1, aout; adouble ad; @@ -3407,7 +3325,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Forward) ad >>= aout; trace_off(); - double aDerivative = -2. / std::sqrt(std::acos(-1.)) * std::exp(-a*a); + double aDerivative = -2. / std::sqrt(std::acos(-1.)) * std::exp(-a * a); a = std::erfc(a); double *x = myalloc1(1); @@ -3418,7 +3336,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Forward) x[0] = 7.1; for (int i = 0; i < 2; i++) { - xd[0][i] = std::pow(3., i*2.); + xd[0][i] = std::pow(3., i * 2.); } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -3433,8 +3351,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Reverse) { double a = 7.1, aout; adouble ad; @@ -3446,7 +3363,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = -2. / std::sqrt(std::acos(-1.)) * std::exp(-a*a); + double aDerivative = -2. / std::sqrt(std::acos(-1.)) * std::exp(-a * a); double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -3457,14 +3374,13 @@ BOOST_AUTO_TEST_CASE(ErfcOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == -1.1*aDerivative, tt::tolerance(tol)); + BOOST_TEST(z[1][0] == -1.1 * aDerivative, tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(EqPlusOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(EqPlusOperator_FOV_Forward) { double a = 5.132, aout; adouble ad; @@ -3487,7 +3403,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_FOV_Forward) x[0] = 5.132; for (int i = 0; i < 2; i++) { - xd[0][i] = std::pow(4., i*1.5); + xd[0][i] = std::pow(4., i * 1.5); } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -3502,8 +3418,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(EqPlusOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(EqPlusOperator_FOV_Reverse) { double a = 5.132, aout; adouble ad; @@ -3526,14 +3441,13 @@ BOOST_AUTO_TEST_CASE(EqPlusOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::pow(2., -1.1), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::pow(2., -1.1), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(EqMinusOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(EqMinusOperator_FOV_Forward) { double a = 5.132, aout; adouble ad; @@ -3556,7 +3470,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_FOV_Forward) x[0] = 5.132; for (int i = 0; i < 2; i++) { - xd[0][i] = std::pow(4., i*1.5); + xd[0][i] = std::pow(4., i * 1.5); } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -3571,8 +3485,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(EqMinusOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(EqMinusOperator_FOV_Reverse) { double a = 5.132, aout; adouble ad; @@ -3595,14 +3508,13 @@ BOOST_AUTO_TEST_CASE(EqMinusOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::pow(2., -1.1), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::pow(2., -1.1), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(EqTimesOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperator_FOV_Forward) { double a = 5.132, aout; adouble ad; @@ -3625,7 +3537,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOV_Forward) x[0] = 5.132; for (int i = 0; i < 2; i++) { - xd[0][i] = std::pow(4., i*1.5); + xd[0][i] = std::pow(4., i * 1.5); } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -3640,8 +3552,7 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(EqTimesOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperator_FOV_Reverse) { double a = 5.132, aout; adouble ad; @@ -3664,14 +3575,13 @@ BOOST_AUTO_TEST_CASE(EqTimesOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::pow(2., -1.1), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::pow(2., -1.1), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(EqDivOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(EqDivOperator_FOV_Forward) { double a = 5.132, aout; adouble ad; @@ -3694,7 +3604,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOV_Forward) x[0] = 5.132; for (int i = 0; i < 2; i++) { - xd[0][i] = std::pow(4., i*1.5); + xd[0][i] = std::pow(4., i * 1.5); } fov_forward(1, 1, 1, 2, x, xd, y, yd); @@ -3709,8 +3619,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(EqDivOperator_FOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(EqDivOperator_FOV_Reverse) { double a = 5.132, aout; adouble ad; @@ -3722,7 +3631,7 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOV_Reverse) ad >>= aout; trace_off(); - double aDerivative = 1./5.2; + double aDerivative = 1. / 5.2; double **u = myalloc2(2, 1); double **z = myalloc2(2, 1); @@ -3733,14 +3642,13 @@ BOOST_AUTO_TEST_CASE(EqDivOperator_FOV_Reverse) fov_reverse(1, 1, 1, 2, u, z); BOOST_TEST(z[0][0] == aDerivative, tt::tolerance(tol)); - BOOST_TEST(z[1][0] == aDerivative*std::pow(2., -1.1), tt::tolerance(tol)); + BOOST_TEST(z[1][0] == aDerivative * std::pow(2., -1.1), tt::tolerance(tol)); myfree2(u); myfree2(z); } -BOOST_AUTO_TEST_CASE(CondassignOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CondassignOperator_FOV_Forward) { double out; adouble cond, arg1, arg2; adouble p; @@ -3786,8 +3694,7 @@ BOOST_AUTO_TEST_CASE(CondassignOperator_FOV_Forward) myfree2(yd); } -BOOST_AUTO_TEST_CASE(CondeqassignOperator_FOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CondeqassignOperator_FOV_Forward) { double out; adouble cond, arg1, arg2; adouble p; @@ -3833,6 +3740,4 @@ BOOST_AUTO_TEST_CASE(CondeqassignOperator_FOV_Forward) myfree2(yd); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/ADOL-C/boost-test/traceSecOrderScalar.cpp b/ADOL-C/boost-test/traceSecOrderScalar.cpp index 960e4b83c..4a3731e1d 100644 --- a/ADOL-C/boost-test/traceSecOrderScalar.cpp +++ b/ADOL-C/boost-test/traceSecOrderScalar.cpp @@ -7,8 +7,7 @@ namespace tt = boost::test_tools; #include "const.h" -BOOST_AUTO_TEST_SUITE( trace_sec_order ) - +BOOST_AUTO_TEST_SUITE(trace_sec_order) /**************************************/ /* Tests for ADOL-C trace scalar mode */ @@ -17,7 +16,6 @@ BOOST_AUTO_TEST_SUITE( trace_sec_order ) /* Author: Philipp Schuette */ /**************************************/ - /* This file contains custom tests for the higher order derivative * evaluation drivers hos_forward, 'hessian'. As 'hessian' uses * hos_reverse internally (after a call to fos_foward), this effectively @@ -33,8 +31,7 @@ BOOST_AUTO_TEST_SUITE( trace_sec_order ) * First derivative: 2.*3.*x*x * Second derivative: 2.*3.*2.*x */ -BOOST_AUTO_TEST_CASE(CustomCube_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomCube_HOS) { double x = 3.; adouble ax; double y; @@ -43,25 +40,25 @@ BOOST_AUTO_TEST_CASE(CustomCube_HOS) trace_on(1, 1); ax <<= x; - ay = 2.*ax*ax*ax; + ay = 2. * ax * ax * ax; ay >>= y; trace_off(); // Calculate primitive value analytically for testing. - double yprim = 2.*x*x*x; + double yprim = 2. * x * x * x; // Calculate first and second derivative analytically for testing. - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 2.*3.*x*x; - yDerivative[0][1] = 2.*3.*x*x + 0.5*(2.*3.*2.*x); + yDerivative[0][0] = 2. * 3. * x * x; + yDerivative[0][1] = 2. * 3. * x * x + 0.5 * (2. * 3. * 2. * x); - double** X; + double **X; X = myalloc2(1, 2); X[0][0] = 1.; X[0][1] = 1.; - double** Y; + double **Y; Y = myalloc2(1, 2); // Signature: hos_forward(tag, m, n, d, keep, x[n], X[n][d], y[m], Y[m][d]) @@ -71,11 +68,11 @@ BOOST_AUTO_TEST_CASE(CustomCube_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(1, 1); // Calculate Hessian matrix analytically: - double yxxDerivative = 2.*3.*2.*x; + double yxxDerivative = 2. * 3. * 2. * x; hessian(1, 1, &x, H); @@ -92,8 +89,7 @@ BOOST_AUTO_TEST_CASE(CustomCube_HOS) * Second derivatives: (-cos(x1)*sin(x2), -sin(x1)*cos(x2), * -sin(x1)*cos(x2), -cos(x1)*sin(x2)) */ -BOOST_AUTO_TEST_CASE(CustomTrigProd_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomTrigProd_HOS) { double x1 = 1.3, x2 = 3.1; adouble ax1, ax2; double y; @@ -103,32 +99,32 @@ BOOST_AUTO_TEST_CASE(CustomTrigProd_HOS) ax1 <<= x1; ax2 <<= x2; - ay = cos(ax1)*sin(ax2); + ay = cos(ax1) * sin(ax2); ay >>= y; trace_off(); - double yprim = std::cos(x1)*std::sin(x2); + double yprim = std::cos(x1) * std::sin(x2); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = -std::sin(x1)*std::sin(x2); - yDerivative[0][1] = std::cos(x1)*std::cos(x2) - + 0.5*(-std::cos(x1))*std::sin(x2); + yDerivative[0][0] = -std::sin(x1) * std::sin(x2); + yDerivative[0][1] = + std::cos(x1) * std::cos(x2) + 0.5 * (-std::cos(x1)) * std::sin(x2); - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -137,12 +133,12 @@ BOOST_AUTO_TEST_CASE(CustomTrigProd_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = -std::cos(x1)*std::sin(x2); - double yx1x2Derivative = -std::sin(x1)*std::cos(x2); - double yx2x2Derivative = -std::cos(x1)*std::sin(x2); + double yx1x1Derivative = -std::cos(x1) * std::sin(x2); + double yx1x2Derivative = -std::sin(x1) * std::cos(x2); + double yx2x2Derivative = -std::cos(x1) * std::sin(x2); hessian(1, 2, x, H); @@ -173,8 +169,7 @@ BOOST_AUTO_TEST_CASE(CustomTrigProd_HOS) * 2.*pow(x1, x2)*log(x1)*exp(2.*x3) * 4.*pow(x1, x2)*exp(2.*x3))) */ -BOOST_AUTO_TEST_CASE(CustomTrigPow_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomTrigPow_HOS) { double x1 = 1.1, x2 = 4.53, x3 = -3.03; adouble ax1, ax2, ax3; double y; @@ -185,36 +180,36 @@ BOOST_AUTO_TEST_CASE(CustomTrigPow_HOS) ax2 <<= x2; ax3 <<= x3; - ay = pow(ax1, ax2)*exp(2.*ax3); + ay = pow(ax1, ax2) * exp(2. * ax3); ay >>= y; trace_off(); - double yprim = std::pow(x1, x2)*std::exp(2.*x3); + double yprim = std::pow(x1, x2) * std::exp(2. * x3); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = x2*std::pow(x1, x2 - 1)*std::exp(2.*x3) - + 0.1*std::pow(x1, x2)*std::log(x1)*std::exp(2.*x3); - yDerivative[0][1] = std::pow(x1, x2)*std::log(x1)*std::exp(2.*x3) - + 0.2*2.*std::pow(x1, x2)*std::exp(2.*x3) - + 0.5*(x2*(x2 - 1)*std::pow(x1, x2 - 2)*std::exp(2.*x3) - + 0.1*x2*std::pow(x1, x2 - 1)*std::log(x1) - *std::exp(2.*x3) - + 0.1*std::pow(x1, x2 - 1)*std::exp(2.*x3) - + 0.1*std::pow(x1, x2 - 1)*std::exp(2.*x3) - + 0.1*x2*std::pow(x1, x2 - 1)*std::log(x1) - *std::exp(2.*x3) - + 0.01*std::pow(x1, x2) - *std::pow(std::log(x1), 2)*std::exp(2.*x3)); - - double* x; + yDerivative[0][0] = x2 * std::pow(x1, x2 - 1) * std::exp(2. * x3) + + 0.1 * std::pow(x1, x2) * std::log(x1) * std::exp(2. * x3); + yDerivative[0][1] = + std::pow(x1, x2) * std::log(x1) * std::exp(2. * x3) + + 0.2 * 2. * std::pow(x1, x2) * std::exp(2. * x3) + + 0.5 * + (x2 * (x2 - 1) * std::pow(x1, x2 - 2) * std::exp(2. * x3) + + 0.1 * x2 * std::pow(x1, x2 - 1) * std::log(x1) * std::exp(2. * x3) + + 0.1 * std::pow(x1, x2 - 1) * std::exp(2. * x3) + + 0.1 * std::pow(x1, x2 - 1) * std::exp(2. * x3) + + 0.1 * x2 * std::pow(x1, x2 - 1) * std::log(x1) * std::exp(2. * x3) + + 0.01 * std::pow(x1, x2) * std::pow(std::log(x1), 2) * + std::exp(2. * x3)); + + double *x; x = myalloc1(3); x[0] = x1; x[1] = x2; x[2] = x3; - double** X; + double **X; X = myalloc2(3, 2); X[0][0] = 1.; X[1][0] = 0.1; @@ -223,7 +218,7 @@ BOOST_AUTO_TEST_CASE(CustomTrigPow_HOS) X[1][1] = 1.; X[2][1] = 0.2; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 3, 2, 1, x, X, &y, Y); @@ -232,17 +227,20 @@ BOOST_AUTO_TEST_CASE(CustomTrigPow_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(3, 3); - double yx1x1Derivative = x2*(x2 - 1)*std::pow(x1, x2 - 2)*std::exp(2.*x3); - double yx2x1Derivative = x2*std::pow(x1, x2 - 1)*std::log(x1)*std::exp(2.*x3) - + std::pow(x1, x2 - 1)*std::exp(2.*x3); - double yx3x1Derivative = 2.*x2*std::pow(x1, x2 - 1)*std::exp(2.*x3); - double yx2x2Derivative = std::pow(x1, x2)*std::pow(std::log(x1), 2) - *std::exp(2.*x3); - double yx3x2Derivative = 2.*std::pow(x1, x2)*std::log(x1)*std::exp(2.*x3); - double yx3x3Derivative = 4.*std::pow(x1, x2)*std::exp(2.*x3); + double yx1x1Derivative = + x2 * (x2 - 1) * std::pow(x1, x2 - 2) * std::exp(2. * x3); + double yx2x1Derivative = + x2 * std::pow(x1, x2 - 1) * std::log(x1) * std::exp(2. * x3) + + std::pow(x1, x2 - 1) * std::exp(2. * x3); + double yx3x1Derivative = 2. * x2 * std::pow(x1, x2 - 1) * std::exp(2. * x3); + double yx2x2Derivative = + std::pow(x1, x2) * std::pow(std::log(x1), 2) * std::exp(2. * x3); + double yx3x2Derivative = + 2. * std::pow(x1, x2) * std::log(x1) * std::exp(2. * x3); + double yx3x3Derivative = 4. * std::pow(x1, x2) * std::exp(2. * x3); hessian(1, 3, x, H); @@ -265,8 +263,7 @@ BOOST_AUTO_TEST_CASE(CustomTrigPow_HOS) * Second derivatives: (4.*cosh(2.*x1)*sinh(3.*x2), 6.*sinh(2.*x1)*cosh(3.*x2), * 6.*sinh(2.*x1)*cosh(3.*x2), 9.*cosh(2.*x1)*sinh(3.*x2)) */ -BOOST_AUTO_TEST_CASE(CustomHyperbProd_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomHyperbProd_HOS) { double x1 = 2.22, x2 = -2.22; adouble ax1, ax2; double y; @@ -276,32 +273,32 @@ BOOST_AUTO_TEST_CASE(CustomHyperbProd_HOS) ax1 <<= x1; ax2 <<= x2; - ay = cosh(2.*ax1)*sinh(3.*ax2); + ay = cosh(2. * ax1) * sinh(3. * ax2); ay >>= y; trace_off(); - double yprim = std::cosh(2.*x1)*std::sinh(3.*x2); + double yprim = std::cosh(2. * x1) * std::sinh(3. * x2); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 2.*std::sinh(2.*x1)*std::sinh(3.*x2); - yDerivative[0][1] = 3.*std::cosh(2.*x1)*std::cosh(3.*x2) - + 0.5*4.*std::cosh(2.*x1)*std::sinh(3.*x2); + yDerivative[0][0] = 2. * std::sinh(2. * x1) * std::sinh(3. * x2); + yDerivative[0][1] = 3. * std::cosh(2. * x1) * std::cosh(3. * x2) + + 0.5 * 4. * std::cosh(2. * x1) * std::sinh(3. * x2); - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -310,12 +307,12 @@ BOOST_AUTO_TEST_CASE(CustomHyperbProd_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = 4.*std::cosh(2.*x1)*std::sinh(3.*x2); - double yx1x2Derivative = 6.*std::sinh(2.*x1)*std::cosh(3.*x2); - double yx2x2Derivative = 9.*std::cosh(2.*x1)*std::sinh(3.*x2); + double yx1x1Derivative = 4. * std::cosh(2. * x1) * std::sinh(3. * x2); + double yx1x2Derivative = 6. * std::sinh(2. * x1) * std::cosh(3. * x2); + double yx2x2Derivative = 9. * std::cosh(2. * x1) * std::sinh(3. * x2); hessian(1, 2, x, H); @@ -346,8 +343,7 @@ BOOST_AUTO_TEST_CASE(CustomHyperbProd_HOS) * * (-cos(x2) + pow(sin(x2), 2)*log(sin(x1))) * ) */ -BOOST_AUTO_TEST_CASE(CustomPowTrig_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomPowTrig_HOS) { double x1 = 0.531, x2 = 3.12; adouble ax1, ax2; double y; @@ -364,29 +360,30 @@ BOOST_AUTO_TEST_CASE(CustomPowTrig_HOS) double yprim = std::pow(std::sin(x1), std::cos(x2)); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = std::pow(std::sin(x1), std::cos(x2)) - * std::cos(x2)*std::cos(x1)/std::sin(x1); - yDerivative[0][1] = -std::pow(std::sin(x1), std::cos(x2)) - *std::sin(x2)*std::log(std::sin(x1)) - + 0.5*(std::pow(std::sin(x1), std::cos(x2))*std::cos(x2) - *(-1 + std::pow(std::cos(x1)/std::sin(x1), 2) - *(std::cos(x2) - 1))); - - double* x; + yDerivative[0][0] = std::pow(std::sin(x1), std::cos(x2)) * std::cos(x2) * + std::cos(x1) / std::sin(x1); + yDerivative[0][1] = + -std::pow(std::sin(x1), std::cos(x2)) * std::sin(x2) * + std::log(std::sin(x1)) + + 0.5 * (std::pow(std::sin(x1), std::cos(x2)) * std::cos(x2) * + (-1 + + std::pow(std::cos(x1) / std::sin(x1), 2) * (std::cos(x2) - 1))); + + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -395,18 +392,19 @@ BOOST_AUTO_TEST_CASE(CustomPowTrig_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = std::pow(std::sin(x1), std::cos(x2))*std::cos(x2) - *(-1 + std::pow(std::cos(x1)/std::sin(x1), 2) - *(std::cos(x2) - 1)); - double yx1x2Derivative = -std::pow(std::sin(x1), std::cos(x2))*std::sin(x2) - *(std::cos(x1)/std::sin(x1) + std::log(std::sin(x1)) - *std::cos(x2)*std::cos(x1)/std::sin(x1)); - double yx2x2Derivative = std::pow(std::sin(x1), std::cos(x2)) - *std::log(std::sin(x1))*(-std::cos(x2) - +std::pow(std::sin(x2), 2)*std::log(std::sin(x1))); + double yx1x1Derivative = + std::pow(std::sin(x1), std::cos(x2)) * std::cos(x2) * + (-1 + std::pow(std::cos(x1) / std::sin(x1), 2) * (std::cos(x2) - 1)); + double yx1x2Derivative = + -std::pow(std::sin(x1), std::cos(x2)) * std::sin(x2) * + (std::cos(x1) / std::sin(x1) + + std::log(std::sin(x1)) * std::cos(x2) * std::cos(x1) / std::sin(x1)); + double yx2x2Derivative = + std::pow(std::sin(x1), std::cos(x2)) * std::log(std::sin(x1)) * + (-std::cos(x2) + std::pow(std::sin(x2), 2) * std::log(std::sin(x1))); hessian(1, 2, x, H); @@ -430,8 +428,7 @@ BOOST_AUTO_TEST_CASE(CustomPowTrig_HOS) * pow(x1, x2)*pow(log(x1), 2) * ) */ -BOOST_AUTO_TEST_CASE(CustomPow_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomPow_HOS) { double x1 = 1.04, x2 = -2.01; adouble ax1, ax2; double y; @@ -448,25 +445,25 @@ BOOST_AUTO_TEST_CASE(CustomPow_HOS) double yprim = std::pow(x1, x2); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = x2*std::pow(x1, x2 - 1); - yDerivative[0][1] = std::pow(x1, x2)*std::log(x1) - + 0.5*x2*(x2 - 1)*std::pow(x1, x2 - 2); + yDerivative[0][0] = x2 * std::pow(x1, x2 - 1); + yDerivative[0][1] = std::pow(x1, x2) * std::log(x1) + + 0.5 * x2 * (x2 - 1) * std::pow(x1, x2 - 2); - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -475,12 +472,12 @@ BOOST_AUTO_TEST_CASE(CustomPow_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = x2*(x2 - 1)*pow(x1, x2 - 2); - double yx1x2Derivative = std::pow(x1, x2 - 1)*(1 + x2*std::log(x1)); - double yx2x2Derivative = std::pow(x1, x2)*std::pow(std::log(x1), 2); + double yx1x1Derivative = x2 * (x2 - 1) * pow(x1, x2 - 2); + double yx1x2Derivative = std::pow(x1, x2 - 1) * (1 + x2 * std::log(x1)); + double yx2x2Derivative = std::pow(x1, x2) * std::pow(std::log(x1), 2); hessian(1, 2, x, H); @@ -519,8 +516,7 @@ BOOST_AUTO_TEST_CASE(CustomPow_HOS) * 49.*exp(x1 + 3.*x2 +5.*x3 + 7.*x4) * ) */ -BOOST_AUTO_TEST_CASE(CustomExpSum_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomExpSum_HOS) { double x1 = -1.1, x2 = -4.53, x3 = 3.03, x4 = 0.; adouble ax1, ax2, ax3, ax4; double y; @@ -532,29 +528,30 @@ BOOST_AUTO_TEST_CASE(CustomExpSum_HOS) ax3 <<= x3; ax4 <<= x4; - ay = exp(ax1 + 3.*ax2 + 5.*ax3 + 7.*ax4); + ay = exp(ax1 + 3. * ax2 + 5. * ax3 + 7. * ax4); ay >>= y; trace_off(); - double yprim = std::exp(x1 + 3.*x2 + 5.*x3 + 7.*x4); + double yprim = std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4) - *(1. + 0.1*3. -0.01*7.); - yDerivative[0][1] = std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4) - *(3. + 0.2*5. + 0.5*(1. + 0.3 - 0.07 - + 0.1*(3. + 0.9 - 0.21) - 0.01*(7. + 2.1 - 0.49))); - - double* x; + yDerivative[0][0] = + std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4) * (1. + 0.1 * 3. - 0.01 * 7.); + yDerivative[0][1] = std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4) * + (3. + 0.2 * 5. + + 0.5 * (1. + 0.3 - 0.07 + 0.1 * (3. + 0.9 - 0.21) - + 0.01 * (7. + 2.1 - 0.49))); + + double *x; x = myalloc1(4); x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4; - double** X; + double **X; X = myalloc2(4, 2); X[0][0] = 1.; X[1][0] = 0.1; @@ -565,7 +562,7 @@ BOOST_AUTO_TEST_CASE(CustomExpSum_HOS) X[2][1] = 0.2; X[3][1] = 0.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 4, 2, 1, x, X, &y, Y); @@ -574,19 +571,19 @@ BOOST_AUTO_TEST_CASE(CustomExpSum_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(4, 4); - double yx1x1Derivative = std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx2x1Derivative = 3.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx3x1Derivative = 5.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx4x1Derivative = 7.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx2x2Derivative = 9.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx3x2Derivative = 15.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx4x2Derivative = 21.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx3x3Derivative = 25.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx4x3Derivative = 35.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double yx4x4Derivative = 49.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); + double yx1x1Derivative = std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx2x1Derivative = 3. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx3x1Derivative = 5. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx4x1Derivative = 7. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx2x2Derivative = 9. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx3x2Derivative = 15. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx4x2Derivative = 21. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx3x3Derivative = 25. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx4x3Derivative = 35. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double yx4x4Derivative = 49. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); hessian(1, 4, x, H); @@ -625,8 +622,7 @@ BOOST_AUTO_TEST_CASE(CustomExpSum_HOS) * *(4*tanh(x1)/acos(-1) - 4*x2*exp(x2*x2)/sqrt(acos(-1))) * ) */ -BOOST_AUTO_TEST_CASE(CustomHypErf_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomHypErf_HOS) { double x1 = 5.55, x2 = 9.99; adouble ax1, ax2; double y; @@ -636,37 +632,37 @@ BOOST_AUTO_TEST_CASE(CustomHypErf_HOS) ax1 <<= x1; ax2 <<= x2; - ay = exp(tanh(ax1)*erf(ax2)); + ay = exp(tanh(ax1) * erf(ax2)); ay >>= y; trace_off(); - double yprim = std::exp(std::tanh(x1)*std::erf(x2)); + double yprim = std::exp(std::tanh(x1) * std::erf(x2)); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = std::exp(std::tanh(x1)*std::erf(x2)) - *(1 - std::pow(std::tanh(x1), 2))*std::erf(x2); - yDerivative[0][1] = std::exp(std::tanh(x1)*std::erf(x2))*std::tanh(x1) - *std::exp(-x2*x2)*2/std::sqrt(std::acos(-1)) - + 0.5*std::exp(std::tanh(x1)*std::erf(x2)) - *(1 - std::pow(std::tanh(x1), 2))*std::erf(x2) - *((1 - std::pow(std::tanh(x1), 2))*std::erf(x2) - - 2*std::tanh(x1)); - - double* x; + yDerivative[0][0] = std::exp(std::tanh(x1) * std::erf(x2)) * + (1 - std::pow(std::tanh(x1), 2)) * std::erf(x2); + yDerivative[0][1] = + std::exp(std::tanh(x1) * std::erf(x2)) * std::tanh(x1) * + std::exp(-x2 * x2) * 2 / std::sqrt(std::acos(-1)) + + 0.5 * std::exp(std::tanh(x1) * std::erf(x2)) * + (1 - std::pow(std::tanh(x1), 2)) * std::erf(x2) * + ((1 - std::pow(std::tanh(x1), 2)) * std::erf(x2) - 2 * std::tanh(x1)); + + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -675,20 +671,22 @@ BOOST_AUTO_TEST_CASE(CustomHypErf_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = std::exp(std::tanh(x1)*std::erf(x2)) - *(1 - std::pow(std::tanh(x1), 2))*std::erf(x2) - *((1 - std::pow(std::tanh(x1), 2))*std::erf(x2) - - 2*std::tanh(x1)); - double yx1x2Derivative = std::exp(std::tanh(x1)*std::erf(x2)) - *std::exp(-x2*x2)*(1 - std::pow(std::tanh(x1), 2)) - *2/std::sqrt(std::acos(-1)) - *(1 + std::tanh(x1)*std::erf(x2)); - double yx2x2Derivative = std::exp(std::tanh(x1)*std::erf(x2))*std::tanh(x1) - *std::exp(-2*x2*x2)*(4*std::tanh(x1)/std::acos(-1) - - 4*x2*std::exp(x2*x2)/std::sqrt(std::acos(-1))); + double yx1x1Derivative = + std::exp(std::tanh(x1) * std::erf(x2)) * + (1 - std::pow(std::tanh(x1), 2)) * std::erf(x2) * + ((1 - std::pow(std::tanh(x1), 2)) * std::erf(x2) - 2 * std::tanh(x1)); + double yx1x2Derivative = + std::exp(std::tanh(x1) * std::erf(x2)) * std::exp(-x2 * x2) * + (1 - std::pow(std::tanh(x1), 2)) * 2 / std::sqrt(std::acos(-1)) * + (1 + std::tanh(x1) * std::erf(x2)); + double yx2x2Derivative = + std::exp(std::tanh(x1) * std::erf(x2)) * std::tanh(x1) * + std::exp(-2 * x2 * x2) * + (4 * std::tanh(x1) / std::acos(-1) - + 4 * x2 * std::exp(x2 * x2) / std::sqrt(std::acos(-1))); hessian(1, 2, x, H); @@ -710,8 +708,7 @@ BOOST_AUTO_TEST_CASE(CustomHypErf_HOS) * 0, -2.*x2/pow(1. + x2*x2, 2) * ) */ -BOOST_AUTO_TEST_CASE(CustomHypAtan_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomHypAtan_HOS) { double x1 = 7.19, x2 = -4.32; adouble ax1, ax2; double y; @@ -721,32 +718,32 @@ BOOST_AUTO_TEST_CASE(CustomHypAtan_HOS) ax1 <<= x1; ax2 <<= x2; - ay = (pow(cosh(ax1), 2) - pow(sinh(ax1), 2))*atan(ax2); + ay = (pow(cosh(ax1), 2) - pow(sinh(ax1), 2)) * atan(ax2); ay >>= y; trace_off(); - double yprim = (std::pow(std::cosh(x1), 2) - std::pow(std::sinh(x1), 2)) - *std::atan(x2); + double yprim = + (std::pow(std::cosh(x1), 2) - std::pow(std::sinh(x1), 2)) * std::atan(x2); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); yDerivative[0][0] = 0.; - yDerivative[0][1] = 1./(1. + x2*x2) + 0.5*0.; + yDerivative[0][1] = 1. / (1. + x2 * x2) + 0.5 * 0.; - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -755,12 +752,12 @@ BOOST_AUTO_TEST_CASE(CustomHypAtan_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); double yx1x1Derivative = 0.; double yx1x2Derivative = 0.; - double yx2x2Derivative = -2.*x2/std::pow(1. + x2*x2, 2); + double yx2x2Derivative = -2. * x2 / std::pow(1. + x2 * x2, 2); hessian(1, 2, x, H); @@ -783,8 +780,7 @@ BOOST_AUTO_TEST_CASE(CustomHypAtan_HOS) * 0., 0., 6.*x3 + 12.*x3*x3 * ) */ -BOOST_AUTO_TEST_CASE(CustomLongSum_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomLongSum_HOS) { double x1 = 99.99, x2 = std::exp(-0.44), x3 = std::sqrt(2); adouble ax1, ax2, ax3; double y; @@ -795,27 +791,28 @@ BOOST_AUTO_TEST_CASE(CustomLongSum_HOS) ax2 <<= x2; ax3 <<= x3; - ay = 1. + ax1 + ax1*ax1 + ax2*ax2 + ax2*ax2*ax2 - + ax3*ax3*ax3 + ax3*ax3*ax3*ax3; + ay = 1. + ax1 + ax1 * ax1 + ax2 * ax2 + ax2 * ax2 * ax2 + ax3 * ax3 * ax3 + + ax3 * ax3 * ax3 * ax3; ay >>= y; trace_off(); - double yprim = 1. + x1 + x1*x1 + x2*x2 + x2*x2*x2 + x3*x3*x3 + x3*x3*x3*x3; + double yprim = 1. + x1 + x1 * x1 + x2 * x2 + x2 * x2 * x2 + x3 * x3 * x3 + + x3 * x3 * x3 * x3; - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 1. + 2.*x1 - 0.01*(3.*x3*x3 + 4.*x3*x3*x3); - yDerivative[0][1] = 0.3*(2.*x2 + 3.*x2*x2) - + 0.5*(2. + 0.01*0.01*(6.*x3 + 12.*x3*x3)); + yDerivative[0][0] = 1. + 2. * x1 - 0.01 * (3. * x3 * x3 + 4. * x3 * x3 * x3); + yDerivative[0][1] = 0.3 * (2. * x2 + 3. * x2 * x2) + + 0.5 * (2. + 0.01 * 0.01 * (6. * x3 + 12. * x3 * x3)); - double* x; + double *x; x = myalloc1(3); x[0] = x1; x[1] = x2; x[2] = x3; - double** X; + double **X; X = myalloc2(3, 2); X[0][0] = 1.; X[1][0] = 0.; @@ -824,7 +821,7 @@ BOOST_AUTO_TEST_CASE(CustomLongSum_HOS) X[1][1] = 0.3; X[2][1] = 0.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 3, 2, 1, x, X, &y, Y); @@ -833,15 +830,15 @@ BOOST_AUTO_TEST_CASE(CustomLongSum_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(3, 3); double yx1x1Derivative = 2.; double yx2x1Derivative = 0.; double yx3x1Derivative = 0.; - double yx2x2Derivative = 2. + 6.*x2; + double yx2x2Derivative = 2. + 6. * x2; double yx3x2Derivative = 0.; - double yx3x3Derivative = 6.*x3 + 12.*x3*x3; + double yx3x3Derivative = 6. * x3 + 12. * x3 * x3; hessian(1, 3, x, H); @@ -875,8 +872,7 @@ BOOST_AUTO_TEST_CASE(CustomLongSum_HOS) * 2.*exp(x1)*sqrt(2.*x2) * ) */ -BOOST_AUTO_TEST_CASE(CustomExpSqrt_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomExpSqrt_HOS) { double x1 = -0.77, x2 = 10.01, x3 = 0.99; adouble ax1, ax2, ax3; double y; @@ -887,26 +883,26 @@ BOOST_AUTO_TEST_CASE(CustomExpSqrt_HOS) ax2 <<= x2; ax3 <<= x3; - ay = exp(ax1)*sqrt(2.*ax2)*pow(ax3, 2); + ay = exp(ax1) * sqrt(2. * ax2) * pow(ax3, 2); ay >>= y; trace_off(); - double yprim = std::exp(x1)*std::sqrt(2.*x2)*std::pow(x3, 2); + double yprim = std::exp(x1) * std::sqrt(2. * x2) * std::pow(x3, 2); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = std::exp(x1)*std::sqrt(2.*x2)*std::pow(x3, 2); - yDerivative[0][1] = 2.*exp(x1)*pow(x3, 2)/sqrt(2.*x2) - + 0.5*exp(x1)*sqrt(2.*x2)*pow(x3, 2); + yDerivative[0][0] = std::exp(x1) * std::sqrt(2. * x2) * std::pow(x3, 2); + yDerivative[0][1] = 2. * exp(x1) * pow(x3, 2) / sqrt(2. * x2) + + 0.5 * exp(x1) * sqrt(2. * x2) * pow(x3, 2); - double* x; + double *x; x = myalloc1(3); x[0] = x1; x[1] = x2; x[2] = x3; - double** X; + double **X; X = myalloc2(3, 2); X[0][0] = 1.; X[1][0] = 0.; @@ -915,7 +911,7 @@ BOOST_AUTO_TEST_CASE(CustomExpSqrt_HOS) X[1][1] = 2.; X[2][1] = 0.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 3, 2, 1, x, X, &y, Y); @@ -924,16 +920,16 @@ BOOST_AUTO_TEST_CASE(CustomExpSqrt_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(3, 3); - double yx1x1Derivative = std::exp(x1)*std::sqrt(2.*x2)*std::pow(x3, 2); - double yx2x1Derivative = std::exp(x1)*std::pow(x3, 2)/std::sqrt(2.*x2); - double yx3x1Derivative = std::exp(x1)*std::sqrt(2.*x2)*2.*x3; - double yx2x2Derivative = -std::exp(x1)*std::pow(x3, 2) - /std::pow(std::sqrt(2.*x2), 3); - double yx3x2Derivative = std::exp(x1)*2.*x3/std::sqrt(2.*x2); - double yx3x3Derivative = 2.*std::exp(x1)*std::sqrt(2.*x2); + double yx1x1Derivative = std::exp(x1) * std::sqrt(2. * x2) * std::pow(x3, 2); + double yx2x1Derivative = std::exp(x1) * std::pow(x3, 2) / std::sqrt(2. * x2); + double yx3x1Derivative = std::exp(x1) * std::sqrt(2. * x2) * 2. * x3; + double yx2x2Derivative = + -std::exp(x1) * std::pow(x3, 2) / std::pow(std::sqrt(2. * x2), 3); + double yx3x2Derivative = std::exp(x1) * 2. * x3 / std::sqrt(2. * x2); + double yx3x3Derivative = 2. * std::exp(x1) * std::sqrt(2. * x2); hessian(1, 3, x, H); @@ -958,8 +954,7 @@ BOOST_AUTO_TEST_CASE(CustomExpSqrt_HOS) * 4.*x1/(1. - x2*x2), 4.*x1*x1*x2/pow(1. - x2*x2, 2) * ) */ -BOOST_AUTO_TEST_CASE(CustomInvHyperb_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomInvHyperb_HOS) { double x1 = -3.03, x2 = 0.11; adouble ax1, ax2; double y; @@ -969,31 +964,31 @@ BOOST_AUTO_TEST_CASE(CustomInvHyperb_HOS) ax1 <<= x1; ax2 <<= x2; - ay = 2.*acosh(cosh(ax1*ax1))*atanh(ax2); + ay = 2. * acosh(cosh(ax1 * ax1)) * atanh(ax2); ay >>= y; trace_off(); - double yprim = 2.*std::acosh(std::cosh(x1*x1))*std::atanh(x2); + double yprim = 2. * std::acosh(std::cosh(x1 * x1)) * std::atanh(x2); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 4.*x1*std::atanh(x2); - yDerivative[0][1] = 3.*x1*x1/(1. - x2*x2) + 2.*std::atanh(x2); + yDerivative[0][0] = 4. * x1 * std::atanh(x2); + yDerivative[0][1] = 3. * x1 * x1 / (1. - x2 * x2) + 2. * std::atanh(x2); - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.5; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -1002,12 +997,12 @@ BOOST_AUTO_TEST_CASE(CustomInvHyperb_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = 4.*std::atanh(x2); - double yx1x2Derivative = 4.*x1/(1. - x2*x2); - double yx2x2Derivative = 4.*x1*x1*x2/std::pow(1. - x2*x2, 2); + double yx1x1Derivative = 4. * std::atanh(x2); + double yx1x2Derivative = 4. * x1 / (1. - x2 * x2); + double yx2x2Derivative = 4. * x1 * x1 * x2 / std::pow(1. - x2 * x2, 2); hessian(1, 2, x, H); @@ -1029,8 +1024,7 @@ BOOST_AUTO_TEST_CASE(CustomInvHyperb_HOS) * 0., 0., 0., -1., * 0., 0., -1., 0.) */ -BOOST_AUTO_TEST_CASE(CustomFminFmaxFabs_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomFminFmaxFabs_HOS) { double x1 = 1., x2 = 2.5, x3 = -4.5, x4 = -1.; adouble ax1, ax2, ax3, ax4; double y; @@ -1042,26 +1036,26 @@ BOOST_AUTO_TEST_CASE(CustomFminFmaxFabs_HOS) ax3 <<= x3; ax4 <<= x4; - ay = fmax(fmin(ax1, ax2), fabs(ax3))*ax4; + ay = fmax(fmin(ax1, ax2), fabs(ax3)) * ax4; ay >>= y; trace_off(); - double yprim = std::fmax(std::fmin(x1, x2), std::fabs(x3))*x4; + double yprim = std::fmax(std::fmin(x1, x2), std::fabs(x3)) * x4; - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 0.01*x3; - yDerivative[0][1] = -0.2*x4 + 0.5*0.; + yDerivative[0][0] = 0.01 * x3; + yDerivative[0][1] = -0.2 * x4 + 0.5 * 0.; - double* x; + double *x; x = myalloc1(4); x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4; - double** X; + double **X; X = myalloc2(4, 2); X[0][0] = 1.; X[1][0] = 0.1; @@ -1072,7 +1066,7 @@ BOOST_AUTO_TEST_CASE(CustomFminFmaxFabs_HOS) X[2][1] = 0.2; X[3][1] = 0.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 4, 2, 1, x, X, &y, Y); @@ -1081,7 +1075,7 @@ BOOST_AUTO_TEST_CASE(CustomFminFmaxFabs_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(4, 4); double yx1x1Derivative = 0.; @@ -1130,9 +1124,8 @@ BOOST_AUTO_TEST_CASE(CustomFminFmaxFabs_HOS) * -3.*(x1 + x2)*sin(x3)*cos(x4) * ) */ -BOOST_AUTO_TEST_CASE(CustomInvTrig_HOS) -{ - double x1 = 0.11, x2 = 0.33, x3 = 0.1*std::acos(0.), x4 = std::exp(-1.); +BOOST_AUTO_TEST_CASE(CustomInvTrig_HOS) { + double x1 = 0.11, x2 = 0.33, x3 = 0.1 * std::acos(0.), x4 = std::exp(-1.); adouble ax1, ax2, ax3, ax4; double y; adouble ay; @@ -1143,32 +1136,34 @@ BOOST_AUTO_TEST_CASE(CustomInvTrig_HOS) ax3 <<= x3; ax4 <<= x4; - ay = 3.*asin(sin(ax1 + ax2))*sin(ax3)*cos(ax4); + ay = 3. * asin(sin(ax1 + ax2)) * sin(ax3) * cos(ax4); ay >>= y; trace_off(); - double yprim = 3.*std::asin(std::sin(x1 + x2))*std::sin(x3)*std::cos(x4); + double yprim = + 3. * std::asin(std::sin(x1 + x2)) * std::sin(x3) * std::cos(x4); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 3.*std::sin(x3)*std::cos(x4) - + 0.1*3.*std::sin(x3)*std::cos(x4) - + 0.01*3.*(x1 + x2)*std::sin(x3)*std::sin(x4); - yDerivative[0][1] = 3.*std::sin(x3)*std::cos(x4) - + 0.2*3.*(x1 + x2)*std::cos(x3)*std::cos(x4) - - 0.5*0.01*(-2.*3.*std::sin(x3)*std::sin(x4) - - 0.2*3.*std::sin(x3)*std::sin(x4) - + 0.01*3.*(x1 + x2)*std::sin(x3)*std::cos(x4)); - - double* x; + yDerivative[0][0] = 3. * std::sin(x3) * std::cos(x4) + + 0.1 * 3. * std::sin(x3) * std::cos(x4) + + 0.01 * 3. * (x1 + x2) * std::sin(x3) * std::sin(x4); + yDerivative[0][1] = 3. * std::sin(x3) * std::cos(x4) + + 0.2 * 3. * (x1 + x2) * std::cos(x3) * std::cos(x4) - + 0.5 * 0.01 * + (-2. * 3. * std::sin(x3) * std::sin(x4) - + 0.2 * 3. * std::sin(x3) * std::sin(x4) + + 0.01 * 3. * (x1 + x2) * std::sin(x3) * std::cos(x4)); + + double *x; x = myalloc1(4); x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4; - double** X; + double **X; X = myalloc2(4, 2); X[0][0] = 1.; X[1][0] = 0.1; @@ -1179,7 +1174,7 @@ BOOST_AUTO_TEST_CASE(CustomInvTrig_HOS) X[2][1] = 0.2; X[3][1] = 0.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 4, 2, 1, x, X, &y, Y); @@ -1188,19 +1183,19 @@ BOOST_AUTO_TEST_CASE(CustomInvTrig_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(4, 4); double yx1x1Derivative = 0.; double yx2x1Derivative = 0.; - double yx3x1Derivative = 3*std::cos(x3)*std::cos(x4); - double yx4x1Derivative = -3.*sin(x3)*sin(x4); + double yx3x1Derivative = 3 * std::cos(x3) * std::cos(x4); + double yx4x1Derivative = -3. * sin(x3) * sin(x4); double yx2x2Derivative = 0.; - double yx3x2Derivative = 3.*std::cos(x3)*std::cos(x4); - double yx4x2Derivative = -3.*std::sin(x3)*std::sin(x4); - double yx3x3Derivative = -3.*(x1 + x2)*std::sin(x3)*std::cos(x4); - double yx4x3Derivative = -3.*(x1 + x2)*std::cos(x3)*std::sin(x4); - double yx4x4Derivative = -3.*(x1 + x2)*std::sin(x3)*std::cos(x4); + double yx3x2Derivative = 3. * std::cos(x3) * std::cos(x4); + double yx4x2Derivative = -3. * std::sin(x3) * std::sin(x4); + double yx3x3Derivative = -3. * (x1 + x2) * std::sin(x3) * std::cos(x4); + double yx4x3Derivative = -3. * (x1 + x2) * std::cos(x3) * std::sin(x4); + double yx4x4Derivative = -3. * (x1 + x2) * std::sin(x3) * std::cos(x4); hessian(1, 4, x, H); @@ -1231,8 +1226,7 @@ BOOST_AUTO_TEST_CASE(CustomInvTrig_HOS) * atan(x1)*x2/pow(sqrt(1. - x2*x2), 3) * ) */ -BOOST_AUTO_TEST_CASE(CustomInvTrig2_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomInvTrig2_HOS) { double x1 = 0.53, x2 = -0.01; adouble ax1, ax2; double y; @@ -1242,32 +1236,32 @@ BOOST_AUTO_TEST_CASE(CustomInvTrig2_HOS) ax1 <<= x1; ax2 <<= x2; - ay = atan(ax1)*asin(ax2); + ay = atan(ax1) * asin(ax2); ay >>= y; trace_off(); - double yprim = std::atan(x1)*std::asin(x2); + double yprim = std::atan(x1) * std::asin(x2); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = std::asin(x2)/(1. + x1*x1); - yDerivative[0][1] = 1.5*std::atan(x1)/std::sqrt(1. - x2*x2) - - 0.5*2.*x1*std::asin(x2)/std::pow(1. + x1*x1, 2); + yDerivative[0][0] = std::asin(x2) / (1. + x1 * x1); + yDerivative[0][1] = 1.5 * std::atan(x1) / std::sqrt(1. - x2 * x2) - + 0.5 * 2. * x1 * std::asin(x2) / std::pow(1. + x1 * x1, 2); - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.5; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -1276,12 +1270,13 @@ BOOST_AUTO_TEST_CASE(CustomInvTrig2_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = -2.*x1*std::asin(x2)/std::pow(1. + x1*x1, 2); - double yx1x2Derivative = 1./((1. + x1*x1)*std::sqrt(1. - x2*x2)); - double yx2x2Derivative = std::atan(x1)*x2/std::pow(std::sqrt(1. - x2*x2), 3); + double yx1x1Derivative = -2. * x1 * std::asin(x2) / std::pow(1. + x1 * x1, 2); + double yx1x2Derivative = 1. / ((1. + x1 * x1) * std::sqrt(1. - x2 * x2)); + double yx2x2Derivative = + std::atan(x1) * x2 / std::pow(std::sqrt(1. - x2 * x2), 3); hessian(1, 2, x, H); @@ -1302,8 +1297,7 @@ BOOST_AUTO_TEST_CASE(CustomInvTrig2_HOS) * Second derivatives: (2., 0., 0., 0. * ) */ -BOOST_AUTO_TEST_CASE(CustomFabsFmax_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomFabsFmax_HOS) { double x1 = 9.9, x2 = -4.7; adouble ax1, ax2; double y; @@ -1313,31 +1307,31 @@ BOOST_AUTO_TEST_CASE(CustomFabsFmax_HOS) ax1 <<= x1; ax2 <<= x2; - ay = fmax(fabs(ax1*ax1), fabs(ax2*ax2)); + ay = fmax(fabs(ax1 * ax1), fabs(ax2 * ax2)); ay >>= y; trace_off(); - double yprim = std::fmax(std::fabs(x1*x1), std::fabs(x2*x2)); + double yprim = std::fmax(std::fabs(x1 * x1), std::fabs(x2 * x2)); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 2.*x1; - yDerivative[0][1] = 0.5*2.; + yDerivative[0][0] = 2. * x1; + yDerivative[0][1] = 0.5 * 2.; - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.5; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -1346,7 +1340,7 @@ BOOST_AUTO_TEST_CASE(CustomFabsFmax_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); double yx1x1Derivative = 2.; @@ -1372,8 +1366,7 @@ BOOST_AUTO_TEST_CASE(CustomFabsFmax_HOS) * Second derivatives: (0., 0., 0., 2. * ) */ -BOOST_AUTO_TEST_CASE(CustomFabsFmin_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomFabsFmin_HOS) { double x1 = 9.9, x2 = -4.7; adouble ax1, ax2; double y; @@ -1383,31 +1376,31 @@ BOOST_AUTO_TEST_CASE(CustomFabsFmin_HOS) ax1 <<= x1; ax2 <<= x2; - ay = fmin(fabs(ax1*ax1), fabs(ax2*ax2)); + ay = fmin(fabs(ax1 * ax1), fabs(ax2 * ax2)); ay >>= y; trace_off(); - double yprim = std::fmin(std::fabs(x1*x1), std::fabs(x2*x2)); + double yprim = std::fmin(std::fabs(x1 * x1), std::fabs(x2 * x2)); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); yDerivative[0][0] = 0.; - yDerivative[0][1] = 1.5*2.*x2; + yDerivative[0][1] = 1.5 * 2. * x2; - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.5; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -1416,7 +1409,7 @@ BOOST_AUTO_TEST_CASE(CustomFabsFmin_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); double yx1x1Derivative = 0.; @@ -1443,8 +1436,7 @@ BOOST_AUTO_TEST_CASE(CustomFabsFmin_HOS) * -2.*x1*sin(x2), -x1*x1*cos(x2) * ) */ -BOOST_AUTO_TEST_CASE(CustomFmaxTrigExp_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomFmaxTrigExp_HOS) { double x1 = 21.07, x2 = 1.5; adouble ax1, ax2; double y; @@ -1454,33 +1446,32 @@ BOOST_AUTO_TEST_CASE(CustomFmaxTrigExp_HOS) ax1 <<= x1; ax2 <<= x2; - ay = fmax(ax1*ax1*cos(ax2), sin(ax1)*cos(ax2)*exp(ax2)); + ay = fmax(ax1 * ax1 * cos(ax2), sin(ax1) * cos(ax2) * exp(ax2)); ay >>= y; trace_off(); - double yprim = std::fmax( - x1*x1*std::cos(x2), std::sin(x1)*std::cos(x2)*std::exp(x2) - ); + double yprim = std::fmax(x1 * x1 * std::cos(x2), + std::sin(x1) * std::cos(x2) * std::exp(x2)); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 2.*x1*std::cos(x2); - yDerivative[0][1] = -1.5*x1*x1*std::sin(x2) + 0.5*2.*std::cos(x2); + yDerivative[0][0] = 2. * x1 * std::cos(x2); + yDerivative[0][1] = -1.5 * x1 * x1 * std::sin(x2) + 0.5 * 2. * std::cos(x2); - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.5; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -1489,12 +1480,12 @@ BOOST_AUTO_TEST_CASE(CustomFmaxTrigExp_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = 2.*std::cos(x2); - double yx1x2Derivative = -2.*x1*std::sin(x2); - double yx2x2Derivative = -x1*x1*std::cos(x2); + double yx1x1Derivative = 2. * std::cos(x2); + double yx1x2Derivative = -2. * x1 * std::sin(x2); + double yx2x2Derivative = -x1 * x1 * std::cos(x2); hessian(1, 2, x, H); @@ -1520,8 +1511,7 @@ BOOST_AUTO_TEST_CASE(CustomFmaxTrigExp_HOS) * - sin(x1)*sin(x2*exp(x2))*(2. + x2)*exp(x2) * ) */ -BOOST_AUTO_TEST_CASE(CustomFminTrigExp_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomFminTrigExp_HOS) { double x1 = 21.07, x2 = 1.5; adouble ax1, ax2; double y; @@ -1531,34 +1521,33 @@ BOOST_AUTO_TEST_CASE(CustomFminTrigExp_HOS) ax1 <<= x1; ax2 <<= x2; - ay = fmin(ax1*ax1*cos(ax2), sin(ax1)*cos(ax2*exp(ax2))); + ay = fmin(ax1 * ax1 * cos(ax2), sin(ax1) * cos(ax2 * exp(ax2))); ay >>= y; trace_off(); - double yprim = std::fmin( - x1*x1*std::cos(x2), std::sin(x1)*std::cos(x2*std::exp(x2)) - ); + double yprim = std::fmin(x1 * x1 * std::cos(x2), + std::sin(x1) * std::cos(x2 * std::exp(x2))); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = std::cos(x1)*std::cos(x2*std::exp(x2)); - yDerivative[0][1] = -1.5*sin(x1)*sin(x2*exp(x2))*(1. + x2)*exp(x2) - - 0.5*std::sin(x1)*std::cos(x2*std::exp(x2)); + yDerivative[0][0] = std::cos(x1) * std::cos(x2 * std::exp(x2)); + yDerivative[0][1] = -1.5 * sin(x1) * sin(x2 * exp(x2)) * (1. + x2) * exp(x2) - + 0.5 * std::sin(x1) * std::cos(x2 * std::exp(x2)); - double* x; + double *x; x = myalloc1(2); x[0] = x1; x[1] = x2; - double** X; + double **X; X = myalloc2(2, 2); X[0][0] = 1.; X[0][1] = 0.; X[1][0] = 0.; X[1][1] = 1.5; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 2, 2, 1, x, X, &y, Y); @@ -1567,16 +1556,16 @@ BOOST_AUTO_TEST_CASE(CustomFminTrigExp_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(2, 2); - double yx1x1Derivative = -std::sin(x1)*std::cos(x2*std::exp(x2)); - double yx1x2Derivative = -std::cos(x1)*std::sin(x2*std::exp(x2)) - *(1. + x2)*std::exp(x2); - double yx2x2Derivative = -std::sin(x1)*std::cos(x2*std::exp(x2)) - *std::pow((1. + x2)*std::exp(x2), 2) - - std::sin(x1)*std::sin(x2*std::exp(x2)) - *(2. + x2)*std::exp(x2); + double yx1x1Derivative = -std::sin(x1) * std::cos(x2 * std::exp(x2)); + double yx1x2Derivative = + -std::cos(x1) * std::sin(x2 * std::exp(x2)) * (1. + x2) * std::exp(x2); + double yx2x2Derivative = + -std::sin(x1) * std::cos(x2 * std::exp(x2)) * + std::pow((1. + x2) * std::exp(x2), 2) - + std::sin(x1) * std::sin(x2 * std::exp(x2)) * (2. + x2) * std::exp(x2); hessian(1, 2, x, H); @@ -1614,8 +1603,7 @@ BOOST_AUTO_TEST_CASE(CustomFminTrigExp_HOS) * *(1. + 2.*tan(x3) + pow(tan(x3), 2)) * ) */ -BOOST_AUTO_TEST_CASE(CustomPowExpTan_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomPowExpTan_HOS) { double x1 = -5.2, x2 = 1.1, x3 = 5.4; adouble ax1, ax2, ax3; double y; @@ -1626,30 +1614,31 @@ BOOST_AUTO_TEST_CASE(CustomPowExpTan_HOS) ax2 <<= x2; ax3 <<= x3; - ay = pow(ax1, 3)*pow(ax2, 4)*exp(tan(ax3)) + ax3 + sqrt(11); + ay = pow(ax1, 3) * pow(ax2, 4) * exp(tan(ax3)) + ax3 + sqrt(11); ay >>= y; trace_off(); - double yprim = std::pow(x1, 3)*std::pow(x2, 4)*std::exp(std::tan(x3)) - + x3 + sqrt(11); + double yprim = std::pow(x1, 3) * std::pow(x2, 4) * std::exp(std::tan(x3)) + + x3 + sqrt(11); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); - yDerivative[0][0] = 0.6*std::pow(x1, 2)*std::pow(x2, 4) - *std::exp(std::tan(x3)); - yDerivative[0][1] = 4.*std::pow(x1, 3)*std::pow(x2, 3)*std::exp(std::tan(x3)) - + 0.1*std::pow(x1, 3)*std::pow(x2, 4) - *std::exp(std::tan(x3))*(1. + std::pow(std::tan(x3), 2)) - + 0.1 + 0.12*x1*std::pow(x2, 4)*std::exp(std::tan(x3)); - - double* x; + yDerivative[0][0] = + 0.6 * std::pow(x1, 2) * std::pow(x2, 4) * std::exp(std::tan(x3)); + yDerivative[0][1] = + 4. * std::pow(x1, 3) * std::pow(x2, 3) * std::exp(std::tan(x3)) + + 0.1 * std::pow(x1, 3) * std::pow(x2, 4) * std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)) + + 0.1 + 0.12 * x1 * std::pow(x2, 4) * std::exp(std::tan(x3)); + + double *x; x = myalloc1(3); x[0] = x1; x[1] = x2; x[2] = x3; - double** X; + double **X; X = myalloc2(3, 2); X[0][0] = 0.2; X[1][0] = 0.; @@ -1658,7 +1647,7 @@ BOOST_AUTO_TEST_CASE(CustomPowExpTan_HOS) X[1][1] = 1.; X[2][1] = 0.1; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 3, 2, 1, x, X, &y, Y); @@ -1667,24 +1656,24 @@ BOOST_AUTO_TEST_CASE(CustomPowExpTan_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(3, 3); - double yx1x1Derivative = 6.*x1*std::pow(x2, 4)*std::exp(std::tan(x3)); - double yx2x1Derivative = 12.*std::pow(x1, 2)*std::pow(x2, 3) - *std::exp(std::tan(x3)); - double yx3x1Derivative = 3.*std::pow(x1, 2)*std::pow(x2, 4) - *std::exp(std::tan(x3)) - *(1. + std::pow(std::tan(x3), 2)); - double yx2x2Derivative = 12.*std::pow(x1, 3)*std::pow(x2, 2) - *std::exp(std::tan(x3)); - double yx3x2Derivative = 4.*std::pow(x1, 3)*std::pow(x2, 3) - *std::exp(std::tan(x3)) - *(1. + std::pow(std::tan(x3), 2)); - double yx3x3Derivative = std::pow(x1, 3)*std::pow(x2, 4) - *std::exp(std::tan(x3)) - *(1. + std::pow(std::tan(x3), 2)) - *(1. + 2.*std::tan(x3) + std::pow(std::tan(x3), 2)); + double yx1x1Derivative = 6. * x1 * std::pow(x2, 4) * std::exp(std::tan(x3)); + double yx2x1Derivative = + 12. * std::pow(x1, 2) * std::pow(x2, 3) * std::exp(std::tan(x3)); + double yx3x1Derivative = 3. * std::pow(x1, 2) * std::pow(x2, 4) * + std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)); + double yx2x2Derivative = + 12. * std::pow(x1, 3) * std::pow(x2, 2) * std::exp(std::tan(x3)); + double yx3x2Derivative = 4. * std::pow(x1, 3) * std::pow(x2, 3) * + std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)); + double yx3x3Derivative = std::pow(x1, 3) * std::pow(x2, 4) * + std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)) * + (1. + 2. * std::tan(x3) + std::pow(std::tan(x3), 2)); hessian(1, 3, x, H); @@ -1713,8 +1702,7 @@ BOOST_AUTO_TEST_CASE(CustomPowExpTan_HOS) * 0., 0., 0., 0., 0., 1. * ) */ -BOOST_AUTO_TEST_CASE(CustomManyVariabl_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomManyVariabl_HOS) { double x1 = 1.5, x2 = -1.5, x3 = 3., x4 = -3., x5 = 4.5, x6 = -4.5; adouble ax1, ax2, ax3, ax4, ax5, ax6; double y; @@ -1728,19 +1716,21 @@ BOOST_AUTO_TEST_CASE(CustomManyVariabl_HOS) ax5 <<= x5; ax6 <<= x6; - ay = 0.5*(ax1*ax1 + ax2*ax2 + ax3*ax3 + ax4*ax4 + ax5*ax5 + ax6*ax6); + ay = 0.5 * + (ax1 * ax1 + ax2 * ax2 + ax3 * ax3 + ax4 * ax4 + ax5 * ax5 + ax6 * ax6); ay >>= y; trace_off(); - double yprim = 0.5*(x1*x1 + x2*x2 + x3*x3 + x4*x4 + x5*x5 + x6*x6); + double yprim = + 0.5 * (x1 * x1 + x2 * x2 + x3 * x3 + x4 * x4 + x5 * x5 + x6 * x6); - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); yDerivative[0][0] = x1; - yDerivative[0][1] = x3 + 0.5*1.; + yDerivative[0][1] = x3 + 0.5 * 1.; - double* x; + double *x; x = myalloc1(6); x[0] = x1; x[1] = x2; @@ -1749,7 +1739,7 @@ BOOST_AUTO_TEST_CASE(CustomManyVariabl_HOS) x[4] = x5; x[5] = x6; - double** X; + double **X; X = myalloc2(6, 2); X[0][0] = 1.; X[1][0] = 0.; @@ -1764,7 +1754,7 @@ BOOST_AUTO_TEST_CASE(CustomManyVariabl_HOS) X[4][1] = 0.; X[5][1] = 0.; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 6, 2, 1, x, X, &y, Y); @@ -1773,7 +1763,7 @@ BOOST_AUTO_TEST_CASE(CustomManyVariabl_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(6, 6); hessian(1, 6, x, H); @@ -1818,8 +1808,7 @@ BOOST_AUTO_TEST_CASE(CustomManyVariabl_HOS) * 0., 0., 0., 0., 0., 0. * ) */ -BOOST_AUTO_TEST_CASE(CustomConstant_HOS) -{ +BOOST_AUTO_TEST_CASE(CustomConstant_HOS) { double x1 = 1., x2 = -1., x3 = 3.5, x4 = -3.5, x5 = 4., x6 = -4.; adouble ax1, ax2, ax3, ax4, ax5, ax6; double y; @@ -1840,12 +1829,12 @@ BOOST_AUTO_TEST_CASE(CustomConstant_HOS) double yprim = 0.001001; - double** yDerivative; + double **yDerivative; yDerivative = myalloc2(1, 2); yDerivative[0][0] = 0.; yDerivative[0][1] = 0.; - double* x; + double *x; x = myalloc1(6); x[0] = x1; x[1] = x2; @@ -1854,7 +1843,7 @@ BOOST_AUTO_TEST_CASE(CustomConstant_HOS) x[4] = x5; x[5] = x6; - double** X; + double **X; X = myalloc2(6, 2); X[0][0] = 1.; X[1][0] = 3.1; @@ -1869,7 +1858,7 @@ BOOST_AUTO_TEST_CASE(CustomConstant_HOS) X[4][1] = 9.91; X[5][1] = 2.345; - double** Y; + double **Y; Y = myalloc2(1, 2); hos_forward(1, 1, 6, 2, 1, x, X, &y, Y); @@ -1878,7 +1867,7 @@ BOOST_AUTO_TEST_CASE(CustomConstant_HOS) BOOST_TEST(Y[0][0] == yDerivative[0][0], tt::tolerance(tol)); BOOST_TEST(Y[0][1] == yDerivative[0][1], tt::tolerance(tol)); - double** H; + double **H; H = myalloc2(6, 6); hessian(1, 6, x, H); @@ -1912,7 +1901,6 @@ BOOST_AUTO_TEST_CASE(CustomConstant_HOS) myfree2(H); } - /* Next, tests for the ADOL-C driver hos_reverse are implemented. They * are stated separately in order not to clutter the hos_forward and * hessian driver test cases. Analytical derivatives are not state @@ -1925,8 +1913,7 @@ BOOST_AUTO_TEST_CASE(CustomConstant_HOS) * hos_forward with appropriate keep parameter. */ -BOOST_AUTO_TEST_CASE(customSimpleSum_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customSimpleSum_HOS_Reverse) { double x1 = 1., x2 = -1., x3 = 0.; adouble ax1, ax2, ax3; double y1, y2; @@ -1937,7 +1924,7 @@ BOOST_AUTO_TEST_CASE(customSimpleSum_HOS_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = ax1*exp(ax2 + ax3); + ay1 = ax1 * exp(ax2 + ax3); ay2 = ax1 + ax2 + ax3; ay1 >>= y1; @@ -1945,8 +1932,8 @@ BOOST_AUTO_TEST_CASE(customSimpleSum_HOS_Reverse) trace_off(); double y1x1Derivative = std::exp(x2 + x3); - double y1x2Derivative = x1*std::exp(x2 + x3); - double y1x3Derivative = x1*std::exp(x2 + x3); + double y1x2Derivative = x1 * std::exp(x2 + x3); + double y1x3Derivative = x1 * std::exp(x2 + x3); double y2x1Derivative = 1.; double y2x2Derivative = 1.; double y2x3Derivative = 1.; @@ -1958,14 +1945,14 @@ BOOST_AUTO_TEST_CASE(customSimpleSum_HOS_Reverse) double y2x1x2Derivative = 0.; double y2x1x3Derivative = 0.; double y1x2x1Derivative = std::exp(x2 + x3); - double y1x2x2Derivative = x1*std::exp(x2 + x3); - double y1x2x3Derivative = x1*std::exp(x2 + x3); + double y1x2x2Derivative = x1 * std::exp(x2 + x3); + double y1x2x3Derivative = x1 * std::exp(x2 + x3); double y2x2x1Derivative = 0.; double y2x2x2Derivative = 0.; double y2x2x3Derivative = 0.; double y1x3x1Derivative = std::exp(x2 + x3); - double y1x3x2Derivative = x1*std::exp(x2 + x3); - double y1x3x3Derivative = x1*std::exp(x2 + x3); + double y1x3x2Derivative = x1 * std::exp(x2 + x3); + double y1x3x3Derivative = x1 * std::exp(x2 + x3); double y2x3x1Derivative = 0.; double y2x3x2Derivative = 0.; double y2x3x3Derivative = 0.; @@ -2089,8 +2076,7 @@ BOOST_AUTO_TEST_CASE(customSimpleSum_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customTrigExp_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customTrigExp_HOS_Reverse) { double x1 = 1.78, x2 = -7.81, x3 = 0.03; adouble ax1, ax2, ax3; double y1, y2; @@ -2101,64 +2087,60 @@ BOOST_AUTO_TEST_CASE(customTrigExp_HOS_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = ax1*exp(sin(ax2)*cos(ax3) + sqrt(2) + 3.*ax3); - ay2 = 2.*ax1*ax1 + 3.*ax2*ax2 + 4.*ax3*ax3 + ax1*ax2*ax3; + ay1 = ax1 * exp(sin(ax2) * cos(ax3) + sqrt(2) + 3. * ax3); + ay2 = 2. * ax1 * ax1 + 3. * ax2 * ax2 + 4. * ax3 * ax3 + ax1 * ax2 * ax3; ay1 >>= y1; ay2 >>= y2; trace_off(); - double y1x1Derivative = std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3); - double y1x2Derivative = x1 * std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * std::cos(x2)*std::cos(x3); - double y1x3Derivative = x1 * std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * (3. - std::sin(x2)*std::sin(x3)); - double y2x1Derivative = 4.*x1 + x2*x3; - double y2x2Derivative = 6.*x2 + x1*x3; - double y2x3Derivative = 8.*x3 + x1*x2; + double y1x1Derivative = + std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3); + double y1x2Derivative = + x1 * std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + std::cos(x2) * std::cos(x3); + double y1x3Derivative = + x1 * std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + (3. - std::sin(x2) * std::sin(x3)); + double y2x1Derivative = 4. * x1 + x2 * x3; + double y2x2Derivative = 6. * x2 + x1 * x3; + double y2x3Derivative = 8. * x3 + x1 * x2; double y1x1x1Derivative = 0.; - double y1x1x2Derivative = std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * std::cos(x2)*std::cos(x3); - double y1x1x3Derivative = std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * (3. - std::sin(x2)*std::sin(x3)); + double y1x1x2Derivative = + std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + std::cos(x2) * std::cos(x3); + double y1x1x3Derivative = + std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + (3. - std::sin(x2) * std::sin(x3)); double y2x1x1Derivative = 4.; double y2x1x2Derivative = x3; double y2x1x3Derivative = x2; - double y1x2x1Derivative = std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * std::cos(x2)*std::cos(x3); - double y1x2x2Derivative = x1 * std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * (std::cos(x2) * std::cos(x3) - * std::cos(x2)*std::cos(x3) - - std::sin(x2)*std::cos(x3)); - double y1x2x3Derivative = x1 * std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * (std::cos(x2) * std::cos(x3) - * (-std::sin(x2)*std::sin(x3) + 3.) - - std::cos(x2)*std::sin(x3)); + double y1x2x1Derivative = + std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + std::cos(x2) * std::cos(x3); + double y1x2x2Derivative = + x1 * std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + (std::cos(x2) * std::cos(x3) * std::cos(x2) * std::cos(x3) - + std::sin(x2) * std::cos(x3)); + double y1x2x3Derivative = + x1 * std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + (std::cos(x2) * std::cos(x3) * (-std::sin(x2) * std::sin(x3) + 3.) - + std::cos(x2) * std::sin(x3)); double y2x2x1Derivative = x3; double y2x2x2Derivative = 6.; double y2x2x3Derivative = x1; - double y1x3x1Derivative = std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * (3. - std::sin(x2)*std::sin(x3)); - double y1x3x2Derivative = x1 * std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * (std::cos(x2) * std::cos(x3) - * (-std::sin(x2)*std::sin(x3) + 3.) - - std::cos(x2)*std::sin(x3)); - double y1x3x3Derivative = x1 * std::exp(std::sin(x2)*std::cos(x3) - + std::sqrt(2) + 3.*x3) - * ((3. - std::sin(x2)*std::sin(x3)) - * (3. - std::sin(x2)*std::sin(x3)) - - std::sin(x2)*std::cos(x3)); + double y1x3x1Derivative = + std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + (3. - std::sin(x2) * std::sin(x3)); + double y1x3x2Derivative = + x1 * std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + (std::cos(x2) * std::cos(x3) * (-std::sin(x2) * std::sin(x3) + 3.) - + std::cos(x2) * std::sin(x3)); + double y1x3x3Derivative = + x1 * std::exp(std::sin(x2) * std::cos(x3) + std::sqrt(2) + 3. * x3) * + ((3. - std::sin(x2) * std::sin(x3)) * (3. - std::sin(x2) * std::sin(x3)) - + std::sin(x2) * std::cos(x3)); double y2x3x1Derivative = x2; double y2x3x2Derivative = x1; @@ -2279,8 +2261,7 @@ BOOST_AUTO_TEST_CASE(customTrigExp_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customPowPow_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customPowPow_HOS_Reverse) { double x1 = 2.35, x2 = 5.6, x3 = 2.66; adouble ax1, ax2, ax3; double y1, y2; @@ -2292,51 +2273,51 @@ BOOST_AUTO_TEST_CASE(customPowPow_HOS_Reverse) ax3 <<= x3; ay1 = pow(ax1, ax2) + pow(ax3, 9.2); - ay2 = pow(ax1, -2.4)*pow(ax2, 2.4)*pow(ax3, 3.); + ay2 = pow(ax1, -2.4) * pow(ax2, 2.4) * pow(ax3, 3.); ay1 >>= y1; ay2 >>= y2; trace_off(); - double y1x1Derivative = x2*std::pow(x1, x2 - 1.); - double y1x2Derivative = std::pow(x1, x2)*std::log(x1); - double y1x3Derivative = 9.2*std::pow(x3, 8.2); - double y2x1Derivative = -2.4*std::pow(x1, -3.4)*std::pow(x2, 2.4) - * std::pow(x3, 3.); - double y2x2Derivative = 2.4*std::pow(x1, -2.4)*std::pow(x2, 1.4) - * std::pow(x3, 3.); - double y2x3Derivative = 3.*std::pow(x1, -2.4)*std::pow(x2, 2.4) - * std::pow(x3, 2.); - - double y1x1x1Derivative = x2*(x2 - 1.)*std::pow(x1, x2 - 2.); - double y1x1x2Derivative = std::pow(x1, x2 - 1.) + x2*std::pow(x1, x2 - 1.) - * std::log(x1); + double y1x1Derivative = x2 * std::pow(x1, x2 - 1.); + double y1x2Derivative = std::pow(x1, x2) * std::log(x1); + double y1x3Derivative = 9.2 * std::pow(x3, 8.2); + double y2x1Derivative = + -2.4 * std::pow(x1, -3.4) * std::pow(x2, 2.4) * std::pow(x3, 3.); + double y2x2Derivative = + 2.4 * std::pow(x1, -2.4) * std::pow(x2, 1.4) * std::pow(x3, 3.); + double y2x3Derivative = + 3. * std::pow(x1, -2.4) * std::pow(x2, 2.4) * std::pow(x3, 2.); + + double y1x1x1Derivative = x2 * (x2 - 1.) * std::pow(x1, x2 - 2.); + double y1x1x2Derivative = + std::pow(x1, x2 - 1.) + x2 * std::pow(x1, x2 - 1.) * std::log(x1); double y1x1x3Derivative = 0.; - double y2x1x1Derivative = 2.4*3.4*std::pow(x1, -4.4)*std::pow(x2, 2.4) - * std::pow(x3, 3.); - double y2x1x2Derivative = -2.4*2.4*std::pow(x1, -3.4)*std::pow(x2, 1.4) - * std::pow(x3, 3.); - double y2x1x3Derivative = -2.4*3.*std::pow(x1, -3.4)*std::pow(x2, 2.4) - * std::pow(x3, 2.); - double y1x2x1Derivative = std::pow(x1, x2 - 1.) + x2*std::pow(x1, x2 - 1.) - * std::log(x1); - double y1x2x2Derivative = std::pow(x1, x2)*std::pow(std::log(x1), 2.); + double y2x1x1Derivative = + 2.4 * 3.4 * std::pow(x1, -4.4) * std::pow(x2, 2.4) * std::pow(x3, 3.); + double y2x1x2Derivative = + -2.4 * 2.4 * std::pow(x1, -3.4) * std::pow(x2, 1.4) * std::pow(x3, 3.); + double y2x1x3Derivative = + -2.4 * 3. * std::pow(x1, -3.4) * std::pow(x2, 2.4) * std::pow(x3, 2.); + double y1x2x1Derivative = + std::pow(x1, x2 - 1.) + x2 * std::pow(x1, x2 - 1.) * std::log(x1); + double y1x2x2Derivative = std::pow(x1, x2) * std::pow(std::log(x1), 2.); double y1x2x3Derivative = 0.; - double y2x2x1Derivative = -2.4*2.4*std::pow(x1, -3.4)*std::pow(x2, 1.4) - * std::pow(x3, 3.); - double y2x2x2Derivative = 2.4*1.4*std::pow(x1, -2.4)*std::pow(x2, 0.4) - * std::pow(x3, 3.); - double y2x2x3Derivative = 2.4*3.*std::pow(x1, -2.4)*std::pow(x2, 1.4) - * std::pow(x3, 2.); + double y2x2x1Derivative = + -2.4 * 2.4 * std::pow(x1, -3.4) * std::pow(x2, 1.4) * std::pow(x3, 3.); + double y2x2x2Derivative = + 2.4 * 1.4 * std::pow(x1, -2.4) * std::pow(x2, 0.4) * std::pow(x3, 3.); + double y2x2x3Derivative = + 2.4 * 3. * std::pow(x1, -2.4) * std::pow(x2, 1.4) * std::pow(x3, 2.); double y1x3x1Derivative = 0.; double y1x3x2Derivative = 0.; - double y1x3x3Derivative = 9.2*8.2*std::pow(x3, 7.2); - double y2x3x1Derivative = -2.4*3.*std::pow(x1, -3.4)*std::pow(x2, 2.4) - * std::pow(x3, 2.); - double y2x3x2Derivative = 2.4*3.*std::pow(x1, -2.4)*std::pow(x2, 1.4) - * std::pow(x3, 2.); - double y2x3x3Derivative = 3.*2.*std::pow(x1, -2.4)*std::pow(x2, 2.4) - * std::pow(x3, 1.); + double y1x3x3Derivative = 9.2 * 8.2 * std::pow(x3, 7.2); + double y2x3x1Derivative = + -2.4 * 3. * std::pow(x1, -3.4) * std::pow(x2, 2.4) * std::pow(x3, 2.); + double y2x3x2Derivative = + 2.4 * 3. * std::pow(x1, -2.4) * std::pow(x2, 1.4) * std::pow(x3, 2.); + double y2x3x3Derivative = + 3. * 2. * std::pow(x1, -2.4) * std::pow(x2, 2.4) * std::pow(x3, 1.); double *x = myalloc1(3); double *xd = myalloc1(3); @@ -2453,8 +2434,7 @@ BOOST_AUTO_TEST_CASE(customPowPow_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customCube_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customCube_HOS_Reverse) { double x1 = 3.; adouble ax1; double y1; @@ -2463,14 +2443,14 @@ BOOST_AUTO_TEST_CASE(customCube_HOS_Reverse) trace_on(1, 1); ax1 <<= x1; - ay1 = 2.*ax1*ax1*ax1; + ay1 = 2. * ax1 * ax1 * ax1; ay1 >>= y1; trace_off(); - double y1x1Derivative = 6.*x1*x1; + double y1x1Derivative = 6. * x1 * x1; - double y1x1x1Derivative = 12.*x1; + double y1x1x1Derivative = 12. * x1; double *x = myalloc1(1); double *xd = myalloc1(1); @@ -2500,8 +2480,7 @@ BOOST_AUTO_TEST_CASE(customCube_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customTrigProd_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customTrigProd_HOS_Reverse) { double x1 = 1.3, x2 = 3.1; adouble ax1, ax2; double y1; @@ -2511,18 +2490,18 @@ BOOST_AUTO_TEST_CASE(customTrigProd_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = cos(ax1)*sin(ax2); + ay1 = cos(ax1) * sin(ax2); ay1 >>= y1; trace_off(); - double y1x1Derivative = -std::sin(x1)*std::sin(x2); - double y1x2Derivative = std::cos(x1)*std::cos(x2); + double y1x1Derivative = -std::sin(x1) * std::sin(x2); + double y1x2Derivative = std::cos(x1) * std::cos(x2); - double y1x1x1Derivative = -std::cos(x1)*std::sin(x2); - double y1x1x2Derivative = -std::sin(x1)*std::cos(x2); - double y1x2x1Derivative = -std::sin(x1)*std::cos(x2); - double y1x2x2Derivative = -std::cos(x1)*std::sin(x2); + double y1x1x1Derivative = -std::cos(x1) * std::sin(x2); + double y1x1x2Derivative = -std::sin(x1) * std::cos(x2); + double y1x2x1Derivative = -std::sin(x1) * std::cos(x2); + double y1x2x2Derivative = -std::cos(x1) * std::sin(x2); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -2570,8 +2549,7 @@ BOOST_AUTO_TEST_CASE(customTrigProd_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customTrigPow_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customTrigPow_HOS_Reverse) { double x1 = 1.1, x2 = 4.53, x3 = -3.03; adouble ax1, ax2, ax3; double y1; @@ -2582,28 +2560,32 @@ BOOST_AUTO_TEST_CASE(customTrigPow_HOS_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = pow(ax1, ax2)*exp(2.*ax3); + ay1 = pow(ax1, ax2) * exp(2. * ax3); ay1 >>= y1; trace_off(); - double y1x1Derivative = x2*pow(x1, x2 - 1)*exp(2.*x3); - double y1x2Derivative = pow(x1, x2)*log(x1)*exp(2.*x3); - double y1x3Derivative = 2.*pow(x1, x2)*exp(2.*x3); - - double y1x1x1Derivative = x2*(x2 - 1)*std::pow(x1, x2 - 2)*std::exp(2.*x3); - double y1x1x2Derivative = x2*std::pow(x1, x2 - 1)*std::log(x1) - * std::exp(2.*x3) + std::pow(x1, x2 - 1)*exp(2.*x3); - double y1x1x3Derivative = 2.*x2*std::pow(x1, x2 - 1)*std::exp(2.*x3); - double y1x2x1Derivative = std::pow(x1, x2)*std::exp(2.*x3)/x1 - + x2*std::pow(x1, x2 - 1)*std::log(x1) - * std::exp(2.*x3); - double y1x2x2Derivative = std::pow(x1, x2)*std::log(x1)*std::log(x1) - * std::exp(2.*x3); - double y1x2x3Derivative = 2.*std::pow(x1, x2)*std::log(x1)*std::exp(2.*x3); - double y1x3x1Derivative = 2.*x2*std::pow(x1, x2 - 1)*std::exp(2.*x3); - double y1x3x2Derivative = 2.*std::pow(x1, x2)*std::log(x1)*std::exp(2.*x3); - double y1x3x3Derivative = 4.*std::pow(x1, x2)*std::exp(2.*x3); + double y1x1Derivative = x2 * pow(x1, x2 - 1) * exp(2. * x3); + double y1x2Derivative = pow(x1, x2) * log(x1) * exp(2. * x3); + double y1x3Derivative = 2. * pow(x1, x2) * exp(2. * x3); + + double y1x1x1Derivative = + x2 * (x2 - 1) * std::pow(x1, x2 - 2) * std::exp(2. * x3); + double y1x1x2Derivative = + x2 * std::pow(x1, x2 - 1) * std::log(x1) * std::exp(2. * x3) + + std::pow(x1, x2 - 1) * exp(2. * x3); + double y1x1x3Derivative = 2. * x2 * std::pow(x1, x2 - 1) * std::exp(2. * x3); + double y1x2x1Derivative = + std::pow(x1, x2) * std::exp(2. * x3) / x1 + + x2 * std::pow(x1, x2 - 1) * std::log(x1) * std::exp(2. * x3); + double y1x2x2Derivative = + std::pow(x1, x2) * std::log(x1) * std::log(x1) * std::exp(2. * x3); + double y1x2x3Derivative = + 2. * std::pow(x1, x2) * std::log(x1) * std::exp(2. * x3); + double y1x3x1Derivative = 2. * x2 * std::pow(x1, x2 - 1) * std::exp(2. * x3); + double y1x3x2Derivative = + 2. * std::pow(x1, x2) * std::log(x1) * std::exp(2. * x3); + double y1x3x3Derivative = 4. * std::pow(x1, x2) * std::exp(2. * x3); double *x = myalloc1(3); double *xd = myalloc1(3); @@ -2674,8 +2656,7 @@ BOOST_AUTO_TEST_CASE(customTrigPow_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customHyperbProd_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customHyperbProd_HOS_Reverse) { double x1 = 2.22, x2 = -2.22; adouble ax1, ax2; double y1; @@ -2685,18 +2666,18 @@ BOOST_AUTO_TEST_CASE(customHyperbProd_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = cosh(2.*ax1)*sinh(3.*ax2); + ay1 = cosh(2. * ax1) * sinh(3. * ax2); ay1 >>= y1; trace_off(); - double y1x1Derivative = 2.*std::sinh(2.*x1)*std::sinh(3.*x2); - double y1x2Derivative = std::cosh(2.*x1)*3.*std::cosh(3.*x2); + double y1x1Derivative = 2. * std::sinh(2. * x1) * std::sinh(3. * x2); + double y1x2Derivative = std::cosh(2. * x1) * 3. * std::cosh(3. * x2); - double y1x1x1Derivative = 4.*std::cosh(2.*x1)*std::sinh(3.*x2); - double y1x1x2Derivative = 6.*std::sinh(2.*x1)*std::cosh(3.*x2); - double y1x2x1Derivative = 6.*std::sinh(2.*x1)*std::cosh(3.*x2); - double y1x2x2Derivative = 9.*std::cosh(2.*x1)*std::sinh(3.*x2); + double y1x1x1Derivative = 4. * std::cosh(2. * x1) * std::sinh(3. * x2); + double y1x1x2Derivative = 6. * std::sinh(2. * x1) * std::cosh(3. * x2); + double y1x2x1Derivative = 6. * std::sinh(2. * x1) * std::cosh(3. * x2); + double y1x2x2Derivative = 9. * std::cosh(2. * x1) * std::sinh(3. * x2); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -2744,8 +2725,7 @@ BOOST_AUTO_TEST_CASE(customHyperbProd_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customPowTrig_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customPowTrig_HOS_Reverse) { double x1 = 0.531, x2 = 3.12; adouble ax1, ax2; double y1; @@ -2760,27 +2740,25 @@ BOOST_AUTO_TEST_CASE(customPowTrig_HOS_Reverse) ay1 >>= y1; trace_off(); - double y1x1Derivative = std::pow(std::sin(x1), std::cos(x2))*std::cos(x2) - * std::cos(x1)/std::sin(x1); - double y1x2Derivative = -std::pow(std::sin(x1), std::cos(x2))*std::sin(x2) - * std::log(std::sin(x1)); - - double y1x1x1Derivative = std::pow(std::sin(x1), std::cos(x2))*std::cos(x2) - * (-1 + std::pow(std::cos(x1)/std::sin(x1), 2) - *(std::cos(x2) - 1)); - double y1x1x2Derivative = -std::pow(std::sin(x1), std::cos(x2))*std::sin(x2) - * (std::cos(x1)/std::sin(x1) - + std::log(std::sin(x1))*std::cos(x2) - *std::cos(x1)/std::sin(x1)); - double y1x2x1Derivative = -std::pow(std::sin(x1), std::cos(x2))*std::sin(x2) - * (std::cos(x1)/std::sin(x1) - + std::log(std::sin(x1))*std::cos(x2) - *std::cos(x1)/std::sin(x1)); - double y1x2x2Derivative = std::pow(std::sin(x1), std::cos(x2)) - * std::log(std::sin(x1)) - * (-std::cos(x2) - + std::pow(std::sin(x2), 2) - *std::log(std::sin(x1))); + double y1x1Derivative = std::pow(std::sin(x1), std::cos(x2)) * std::cos(x2) * + std::cos(x1) / std::sin(x1); + double y1x2Derivative = -std::pow(std::sin(x1), std::cos(x2)) * std::sin(x2) * + std::log(std::sin(x1)); + + double y1x1x1Derivative = + std::pow(std::sin(x1), std::cos(x2)) * std::cos(x2) * + (-1 + std::pow(std::cos(x1) / std::sin(x1), 2) * (std::cos(x2) - 1)); + double y1x1x2Derivative = + -std::pow(std::sin(x1), std::cos(x2)) * std::sin(x2) * + (std::cos(x1) / std::sin(x1) + + std::log(std::sin(x1)) * std::cos(x2) * std::cos(x1) / std::sin(x1)); + double y1x2x1Derivative = + -std::pow(std::sin(x1), std::cos(x2)) * std::sin(x2) * + (std::cos(x1) / std::sin(x1) + + std::log(std::sin(x1)) * std::cos(x2) * std::cos(x1) / std::sin(x1)); + double y1x2x2Derivative = + std::pow(std::sin(x1), std::cos(x2)) * std::log(std::sin(x1)) * + (-std::cos(x2) + std::pow(std::sin(x2), 2) * std::log(std::sin(x1))); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -2828,8 +2806,7 @@ BOOST_AUTO_TEST_CASE(customPowTrig_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customPow_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customPow_HOS_Reverse) { double x1 = 1.04, x2 = -2.01; adouble ax1, ax2; double y1; @@ -2844,13 +2821,13 @@ BOOST_AUTO_TEST_CASE(customPow_HOS_Reverse) ay1 >>= y1; trace_off(); - double y1x1Derivative = x2*std::pow(x1, x2 - 1); - double y1x2Derivative = std::pow(x1, x2)*std::log(x1); + double y1x1Derivative = x2 * std::pow(x1, x2 - 1); + double y1x2Derivative = std::pow(x1, x2) * std::log(x1); - double y1x1x1Derivative = x2*(x2 - 1)*std::pow(x1, x2 - 2); - double y1x1x2Derivative = std::pow(x1, x2 - 1)*(1 + x2*std::log(x1)); - double y1x2x1Derivative = std::pow(x1, x2 - 1)*(1 + x2*std::log(x1)); - double y1x2x2Derivative = std::pow(x1, x2)*std::pow(std::log(x1), 2); + double y1x1x1Derivative = x2 * (x2 - 1) * std::pow(x1, x2 - 2); + double y1x1x2Derivative = std::pow(x1, x2 - 1) * (1 + x2 * std::log(x1)); + double y1x2x1Derivative = std::pow(x1, x2 - 1) * (1 + x2 * std::log(x1)); + double y1x2x2Derivative = std::pow(x1, x2) * std::pow(std::log(x1), 2); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -2898,8 +2875,7 @@ BOOST_AUTO_TEST_CASE(customPow_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customExpSum_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customExpSum_HOS_Reverse) { double x1 = -1.1, x2 = -4.53, x3 = 3.03, x4 = 0.; adouble ax1, ax2, ax3, ax4; double y1; @@ -2911,32 +2887,32 @@ BOOST_AUTO_TEST_CASE(customExpSum_HOS_Reverse) ax3 <<= x3; ax4 <<= x4; - ay1 = exp(ax1 + 3.*ax2 + 5.*ax3 + 7.*ax4); + ay1 = exp(ax1 + 3. * ax2 + 5. * ax3 + 7. * ax4); ay1 >>= y1; trace_off(); - double y1x1Derivative = std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x2Derivative = 3.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x3Derivative = 5.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x4Derivative = 7.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - - double y1x1x1Derivative = std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x1x2Derivative = 3.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x1x3Derivative = 5.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x1x4Derivative = 7.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x2x1Derivative = 3.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x2x2Derivative = 9.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x2x3Derivative = 15.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x2x4Derivative = 21.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x3x1Derivative = 5.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x3x2Derivative = 15.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x3x3Derivative = 25.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x3x4Derivative = 35.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x4x1Derivative = 7.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x4x2Derivative = 21.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x4x3Derivative = 35.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); - double y1x4x4Derivative = 49.*std::exp(x1 + 3.*x2 +5.*x3 + 7.*x4); + double y1x1Derivative = std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x2Derivative = 3. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x3Derivative = 5. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x4Derivative = 7. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + + double y1x1x1Derivative = std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x1x2Derivative = 3. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x1x3Derivative = 5. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x1x4Derivative = 7. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x2x1Derivative = 3. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x2x2Derivative = 9. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x2x3Derivative = 15. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x2x4Derivative = 21. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x3x1Derivative = 5. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x3x2Derivative = 15. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x3x3Derivative = 25. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x3x4Derivative = 35. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x4x1Derivative = 7. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x4x2Derivative = 21. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x4x3Derivative = 35. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); + double y1x4x4Derivative = 49. * std::exp(x1 + 3. * x2 + 5. * x3 + 7. * x4); double *x = myalloc1(4); double *xd = myalloc1(4); @@ -3036,8 +3012,7 @@ BOOST_AUTO_TEST_CASE(customExpSum_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customHypErf_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customHypErf_HOS_Reverse) { double x1 = 5.55, x2 = 9.99; adouble ax1, ax2; double y1; @@ -3047,33 +3022,33 @@ BOOST_AUTO_TEST_CASE(customHypErf_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = exp(tanh(ax1)*erf(ax2)); + ay1 = exp(tanh(ax1) * erf(ax2)); ay1 >>= y1; trace_off(); - double y1x1Derivative = std::exp(std::tanh(x1)*std::erf(x2)) - * (1. - std::pow(std::tanh(x1), 2))*std::erf(x2); - double y1x2Derivative = std::exp(std::tanh(x1)*std::erf(x2))*std::tanh(x1) - * std::exp(-x2*x2)*2./std::sqrt(std::acos(-1)); - - double y1x1x1Derivative = std::exp(std::tanh(x1)*std::erf(x2)) - * (1 - std::pow(std::tanh(x1), 2))*std::erf(x2) - * ((1 - std::pow(std::tanh(x1), 2)) - *std::erf(x2) - 2*std::tanh(x1)); - double y1x1x2Derivative = std::exp(std::tanh(x1)*std::erf(x2)) - * std::exp(-x2*x2)*(1 - std::pow(std::tanh(x1), 2)) - * 2/std::sqrt(std::acos(-1)) - * (1 + std::tanh(x1)*std::erf(x2)); - double y1x2x1Derivative = std::exp(std::tanh(x1)*std::erf(x2)) - * std::exp(-x2*x2)*(1 - std::pow(std::tanh(x1), 2)) - * 2/std::sqrt(std::acos(-1)) - * (1 + std::tanh(x1)*std::erf(x2)); - double y1x2x2Derivative = std::exp(std::tanh(x1)*std::erf(x2)) - * std::exp(-x2*x2) - * (4*std::pow(std::tanh(x1), 2)/std::acos(-1) - *std::exp(-x2*x2) - - 4.*x2*std::tanh(x1)/std::sqrt(std::acos(-1))); + double y1x1Derivative = std::exp(std::tanh(x1) * std::erf(x2)) * + (1. - std::pow(std::tanh(x1), 2)) * std::erf(x2); + double y1x2Derivative = std::exp(std::tanh(x1) * std::erf(x2)) * + std::tanh(x1) * std::exp(-x2 * x2) * 2. / + std::sqrt(std::acos(-1)); + + double y1x1x1Derivative = + std::exp(std::tanh(x1) * std::erf(x2)) * + (1 - std::pow(std::tanh(x1), 2)) * std::erf(x2) * + ((1 - std::pow(std::tanh(x1), 2)) * std::erf(x2) - 2 * std::tanh(x1)); + double y1x1x2Derivative = + std::exp(std::tanh(x1) * std::erf(x2)) * std::exp(-x2 * x2) * + (1 - std::pow(std::tanh(x1), 2)) * 2 / std::sqrt(std::acos(-1)) * + (1 + std::tanh(x1) * std::erf(x2)); + double y1x2x1Derivative = + std::exp(std::tanh(x1) * std::erf(x2)) * std::exp(-x2 * x2) * + (1 - std::pow(std::tanh(x1), 2)) * 2 / std::sqrt(std::acos(-1)) * + (1 + std::tanh(x1) * std::erf(x2)); + double y1x2x2Derivative = + std::exp(std::tanh(x1) * std::erf(x2)) * std::exp(-x2 * x2) * + (4 * std::pow(std::tanh(x1), 2) / std::acos(-1) * std::exp(-x2 * x2) - + 4. * x2 * std::tanh(x1) / std::sqrt(std::acos(-1))); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -3121,8 +3096,7 @@ BOOST_AUTO_TEST_CASE(customHypErf_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customHypAtan_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customHypAtan_HOS_Reverse) { double x1 = 7.19, x2 = -4.32; adouble ax1, ax2; double y1; @@ -3132,18 +3106,18 @@ BOOST_AUTO_TEST_CASE(customHypAtan_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = (pow(cosh(ax1), 2) - pow(sinh(ax1), 2))*atan(ax2); + ay1 = (pow(cosh(ax1), 2) - pow(sinh(ax1), 2)) * atan(ax2); ay1 >>= y1; trace_off(); double y1x1Derivative = 0; - double y1x2Derivative = 1./(1. + x2*x2); + double y1x2Derivative = 1. / (1. + x2 * x2); double y1x1x1Derivative = 0.; double y1x1x2Derivative = 0.; double y1x2x1Derivative = 0.; - double y1x2x2Derivative = -2.*x2/std::pow(1. + x2*x2, 2); + double y1x2x2Derivative = -2. * x2 / std::pow(1. + x2 * x2, 2); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -3191,8 +3165,7 @@ BOOST_AUTO_TEST_CASE(customHypAtan_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customLongSum_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customLongSum_HOS_Reverse) { double x1 = 99.99, x2 = std::exp(-0.44), x3 = std::sqrt(2); adouble ax1, ax2, ax3; double y1; @@ -3203,25 +3176,25 @@ BOOST_AUTO_TEST_CASE(customLongSum_HOS_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = 1. + ax1 + ax1*ax1 + ax2*ax2 + ax2*ax2*ax2 + ax3*ax3*ax3 - + ax3*ax3*ax3*ax3; + ay1 = 1. + ax1 + ax1 * ax1 + ax2 * ax2 + ax2 * ax2 * ax2 + ax3 * ax3 * ax3 + + ax3 * ax3 * ax3 * ax3; ay1 >>= y1; trace_off(); - double y1x1Derivative = 1. + 2.*x1; - double y1x2Derivative = 2.*x2 + 3.*x2*x2; - double y1x3Derivative = 3.*x3*x3 + 4.*x3*x3*x3; + double y1x1Derivative = 1. + 2. * x1; + double y1x2Derivative = 2. * x2 + 3. * x2 * x2; + double y1x3Derivative = 3. * x3 * x3 + 4. * x3 * x3 * x3; double y1x1x1Derivative = 2.; double y1x1x2Derivative = 0.; double y1x1x3Derivative = 0.; double y1x2x1Derivative = 0.; - double y1x2x2Derivative = 2. + 6.*x2; + double y1x2x2Derivative = 2. + 6. * x2; double y1x2x3Derivative = 0.; double y1x3x1Derivative = 0.; double y1x3x2Derivative = 0.; - double y1x3x3Derivative = 6.*x3 + 12.*x3*x3; + double y1x3x3Derivative = 6. * x3 + 12. * x3 * x3; double *x = myalloc1(3); double *xd = myalloc1(3); @@ -3292,8 +3265,7 @@ BOOST_AUTO_TEST_CASE(customLongSum_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customExpSqrt_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customExpSqrt_HOS_Reverse) { double x1 = -0.77, x2 = 10.01, x3 = 0.99; adouble ax1, ax2, ax3; double y1; @@ -3304,25 +3276,25 @@ BOOST_AUTO_TEST_CASE(customExpSqrt_HOS_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = exp(ax1)*sqrt(2.*ax2)*pow(ax3, 2); + ay1 = exp(ax1) * sqrt(2. * ax2) * pow(ax3, 2); ay1 >>= y1; trace_off(); - double y1x1Derivative = std::exp(x1)*std::sqrt(2.*x2)*std::pow(x3, 2); - double y1x2Derivative = std::exp(x1)*std::pow(x3, 2)/std::sqrt(2.*x2); - double y1x3Derivative = std::exp(x1)*std::sqrt(2.*x2)*2.*x3; - - double y1x1x1Derivative = std::exp(x1)*std::sqrt(2.*x2)*std::pow(x3, 2); - double y1x1x2Derivative = std::exp(x1)*std::pow(x3, 2)/std::sqrt(2.*x2); - double y1x1x3Derivative = std::exp(x1)*std::sqrt(2.*x2)*2.*x3; - double y1x2x1Derivative = std::exp(x1)*std::pow(x3, 2)/std::sqrt(2.*x2); - double y1x2x2Derivative = -std::exp(x1)*std::pow(x3, 2) - / std::pow(std::sqrt(2.*x2), 3); - double y1x2x3Derivative = std::exp(x1)*2.*x3/std::sqrt(2.*x2); - double y1x3x1Derivative = std::exp(x1)*std::sqrt(2.*x2)*2.*x3; - double y1x3x2Derivative = std::exp(x1)*2.*x3/std::sqrt(2.*x2); - double y1x3x3Derivative = 2.*std::exp(x1)*std::sqrt(2.*x2); + double y1x1Derivative = std::exp(x1) * std::sqrt(2. * x2) * std::pow(x3, 2); + double y1x2Derivative = std::exp(x1) * std::pow(x3, 2) / std::sqrt(2. * x2); + double y1x3Derivative = std::exp(x1) * std::sqrt(2. * x2) * 2. * x3; + + double y1x1x1Derivative = std::exp(x1) * std::sqrt(2. * x2) * std::pow(x3, 2); + double y1x1x2Derivative = std::exp(x1) * std::pow(x3, 2) / std::sqrt(2. * x2); + double y1x1x3Derivative = std::exp(x1) * std::sqrt(2. * x2) * 2. * x3; + double y1x2x1Derivative = std::exp(x1) * std::pow(x3, 2) / std::sqrt(2. * x2); + double y1x2x2Derivative = + -std::exp(x1) * std::pow(x3, 2) / std::pow(std::sqrt(2. * x2), 3); + double y1x2x3Derivative = std::exp(x1) * 2. * x3 / std::sqrt(2. * x2); + double y1x3x1Derivative = std::exp(x1) * std::sqrt(2. * x2) * 2. * x3; + double y1x3x2Derivative = std::exp(x1) * 2. * x3 / std::sqrt(2. * x2); + double y1x3x3Derivative = 2. * std::exp(x1) * std::sqrt(2. * x2); double *x = myalloc1(3); double *xd = myalloc1(3); @@ -3393,8 +3365,7 @@ BOOST_AUTO_TEST_CASE(customExpSqrt_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customInvHyperb_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customInvHyperb_HOS_Reverse) { double x1 = -3.03, x2 = 0.11; adouble ax1, ax2; double y1; @@ -3404,18 +3375,18 @@ BOOST_AUTO_TEST_CASE(customInvHyperb_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = 2.*acosh(cosh(ax1*ax1))*atanh(ax2); + ay1 = 2. * acosh(cosh(ax1 * ax1)) * atanh(ax2); ay1 >>= y1; trace_off(); - double y1x1Derivative = 4.*x1*std::atanh(x2); - double y1x2Derivative = 2.*x1*x1/(1. - x2*x2); + double y1x1Derivative = 4. * x1 * std::atanh(x2); + double y1x2Derivative = 2. * x1 * x1 / (1. - x2 * x2); - double y1x1x1Derivative = 4.*std::atanh(x2); - double y1x1x2Derivative = 4.*x1/(1. - x2*x2); - double y1x2x1Derivative = 4.*x1/(1. - x2*x2); - double y1x2x2Derivative = 4.*x1*x1*x2/std::pow(1. - x2*x2, 2); + double y1x1x1Derivative = 4. * std::atanh(x2); + double y1x1x2Derivative = 4. * x1 / (1. - x2 * x2); + double y1x2x1Derivative = 4. * x1 / (1. - x2 * x2); + double y1x2x2Derivative = 4. * x1 * x1 * x2 / std::pow(1. - x2 * x2, 2); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -3463,8 +3434,7 @@ BOOST_AUTO_TEST_CASE(customInvHyperb_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customFminFmaxFabs_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customFminFmaxFabs_HOS_Reverse) { double x1 = 1., x2 = 2.5, x3 = -4.5, x4 = -1.; adouble ax1, ax2, ax3, ax4; double y1; @@ -3476,7 +3446,7 @@ BOOST_AUTO_TEST_CASE(customFminFmaxFabs_HOS_Reverse) ax3 <<= x3; ax4 <<= x4; - ay1 = fmax(fmin(ax1, ax2), fabs(ax3))*ax4; + ay1 = fmax(fmin(ax1, ax2), fabs(ax3)) * ax4; ay1 >>= y1; trace_off(); @@ -3601,9 +3571,8 @@ BOOST_AUTO_TEST_CASE(customFminFmaxFabs_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customInvTrig_HOS_Reverse) -{ - double x1 = 0.11, x2 = 0.33, x3 = 0.1*std::acos(0.), x4 = std::exp(-1.); +BOOST_AUTO_TEST_CASE(customInvTrig_HOS_Reverse) { + double x1 = 0.11, x2 = 0.33, x3 = 0.1 * std::acos(0.), x4 = std::exp(-1.); adouble ax1, ax2, ax3, ax4; double y1; adouble ay1; @@ -3614,32 +3583,32 @@ BOOST_AUTO_TEST_CASE(customInvTrig_HOS_Reverse) ax3 <<= x3; ax4 <<= x4; - ay1 = 3.*asin(sin(ax1 + ax2))*sin(ax3)*cos(ax4); + ay1 = 3. * asin(sin(ax1 + ax2)) * sin(ax3) * cos(ax4); ay1 >>= y1; trace_off(); - double y1x1Derivative = 3.*std::sin(x3)*std::cos(x4); - double y1x2Derivative = 3.*std::sin(x3)*std::cos(x4); - double y1x3Derivative = 3.*(x1 + x2)*std::cos(x3)*std::cos(x4); - double y1x4Derivative = -3.*(x1 + x2)*std::sin(x3)*std::sin(x4); + double y1x1Derivative = 3. * std::sin(x3) * std::cos(x4); + double y1x2Derivative = 3. * std::sin(x3) * std::cos(x4); + double y1x3Derivative = 3. * (x1 + x2) * std::cos(x3) * std::cos(x4); + double y1x4Derivative = -3. * (x1 + x2) * std::sin(x3) * std::sin(x4); double y1x1x1Derivative = 0.; double y1x1x2Derivative = 0.; - double y1x1x3Derivative = 3*std::cos(x3)*std::cos(x4); - double y1x1x4Derivative = -3.*std::sin(x3)*std::sin(x4); + double y1x1x3Derivative = 3 * std::cos(x3) * std::cos(x4); + double y1x1x4Derivative = -3. * std::sin(x3) * std::sin(x4); double y1x2x1Derivative = 0.; double y1x2x2Derivative = 0.; - double y1x2x3Derivative = 3*std::cos(x3)*std::cos(x4); - double y1x2x4Derivative = -3.*std::sin(x3)*std::sin(x4); - double y1x3x1Derivative = 3.*std::cos(x3)*std::cos(x4); - double y1x3x2Derivative = 3.*std::cos(x3)*std::cos(x4); - double y1x3x3Derivative = -3.*(x1 + x2)*std::sin(x3)*std::cos(x4); - double y1x3x4Derivative = -3.*(x1 + x2)*std::cos(x3)*std::sin(x4); - double y1x4x1Derivative = -3.*std::sin(x3)*std::sin(x4); - double y1x4x2Derivative = -3.*std::sin(x3)*std::sin(x4); - double y1x4x3Derivative = -3.*(x1 + x2)*std::cos(x3)*std::sin(x4); - double y1x4x4Derivative = -3.*(x1 + x2)*std::sin(x3)*std::cos(x4); + double y1x2x3Derivative = 3 * std::cos(x3) * std::cos(x4); + double y1x2x4Derivative = -3. * std::sin(x3) * std::sin(x4); + double y1x3x1Derivative = 3. * std::cos(x3) * std::cos(x4); + double y1x3x2Derivative = 3. * std::cos(x3) * std::cos(x4); + double y1x3x3Derivative = -3. * (x1 + x2) * std::sin(x3) * std::cos(x4); + double y1x3x4Derivative = -3. * (x1 + x2) * std::cos(x3) * std::sin(x4); + double y1x4x1Derivative = -3. * std::sin(x3) * std::sin(x4); + double y1x4x2Derivative = -3. * std::sin(x3) * std::sin(x4); + double y1x4x3Derivative = -3. * (x1 + x2) * std::cos(x3) * std::sin(x4); + double y1x4x4Derivative = -3. * (x1 + x2) * std::sin(x3) * std::cos(x4); double *x = myalloc1(4); double *xd = myalloc1(4); @@ -3648,7 +3617,7 @@ BOOST_AUTO_TEST_CASE(customInvTrig_HOS_Reverse) x[0] = 0.11; x[1] = 0.33; - x[2] = 0.1*std::acos(0.); + x[2] = 0.1 * std::acos(0.); x[3] = std::exp(-1.); xd[0] = 1.; xd[1] = 0.; @@ -3739,8 +3708,7 @@ BOOST_AUTO_TEST_CASE(customInvTrig_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customInvTrig2_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customInvTrig2_HOS_Reverse) { double x1 = 0.53, x2 = -0.01; adouble ax1, ax2; double y1; @@ -3750,19 +3718,20 @@ BOOST_AUTO_TEST_CASE(customInvTrig2_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = atan(ax1)*asin(ax2); + ay1 = atan(ax1) * asin(ax2); ay1 >>= y1; trace_off(); - double y1x1Derivative = std::asin(x2)/(1. + x1*x1); - double y1x2Derivative = std::atan(x1)/std::sqrt(1. - x2*x2); + double y1x1Derivative = std::asin(x2) / (1. + x1 * x1); + double y1x2Derivative = std::atan(x1) / std::sqrt(1. - x2 * x2); - double y1x1x1Derivative = -2.*x1*std::asin(x2)/std::pow(1. + x1*x1, 2); - double y1x1x2Derivative = 1./((1. + x1*x1)*std::sqrt(1. - x2*x2)); - double y1x2x1Derivative = 1./((1. + x1*x1)*std::sqrt(1. - x2*x2)); - double y1x2x2Derivative = std::atan(x1)*x2 - / std::pow(std::sqrt(1. - x2*x2), 3); + double y1x1x1Derivative = + -2. * x1 * std::asin(x2) / std::pow(1. + x1 * x1, 2); + double y1x1x2Derivative = 1. / ((1. + x1 * x1) * std::sqrt(1. - x2 * x2)); + double y1x2x1Derivative = 1. / ((1. + x1 * x1) * std::sqrt(1. - x2 * x2)); + double y1x2x2Derivative = + std::atan(x1) * x2 / std::pow(std::sqrt(1. - x2 * x2), 3); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -3810,8 +3779,7 @@ BOOST_AUTO_TEST_CASE(customInvTrig2_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customFabsFmax_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customFabsFmax_HOS_Reverse) { double x1 = 9.9, x2 = -4.7; adouble ax1, ax2; double y1; @@ -3821,12 +3789,12 @@ BOOST_AUTO_TEST_CASE(customFabsFmax_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = fmax(fabs(ax1*ax1), fabs(ax2*ax2)); + ay1 = fmax(fabs(ax1 * ax1), fabs(ax2 * ax2)); ay1 >>= y1; trace_off(); - double y1x1Derivative = 2.*x1; + double y1x1Derivative = 2. * x1; double y1x2Derivative = 0.; double y1x1x1Derivative = 2.; @@ -3880,8 +3848,7 @@ BOOST_AUTO_TEST_CASE(customFabsFmax_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customFabsFmin_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customFabsFmin_HOS_Reverse) { double x1 = 9.9, x2 = -4.7; adouble ax1, ax2; double y1; @@ -3891,13 +3858,13 @@ BOOST_AUTO_TEST_CASE(customFabsFmin_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = fmin(fabs(ax1*ax1), fabs(ax2*ax2)); + ay1 = fmin(fabs(ax1 * ax1), fabs(ax2 * ax2)); ay1 >>= y1; trace_off(); double y1x1Derivative = 0.; - double y1x2Derivative = 2.*x2; + double y1x2Derivative = 2. * x2; double y1x1x1Derivative = 0.; double y1x1x2Derivative = 0.; @@ -3950,8 +3917,7 @@ BOOST_AUTO_TEST_CASE(customFabsFmin_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customFmaxTrig_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customFmaxTrig_HOS_Reverse) { double x1 = 21.07, x2 = 1.5; adouble ax1, ax2; double y1; @@ -3961,18 +3927,18 @@ BOOST_AUTO_TEST_CASE(customFmaxTrig_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = fmax(ax1*ax1*cos(ax2), sin(ax1)*cos(ax2)*exp(ax2)); + ay1 = fmax(ax1 * ax1 * cos(ax2), sin(ax1) * cos(ax2) * exp(ax2)); ay1 >>= y1; trace_off(); - double y1x1Derivative = 2.*x1*std::cos(x2); - double y1x2Derivative = -x1*x1*std::sin(x2); + double y1x1Derivative = 2. * x1 * std::cos(x2); + double y1x2Derivative = -x1 * x1 * std::sin(x2); - double y1x1x1Derivative = 2.*std::cos(x2); - double y1x1x2Derivative = -2.*x1*std::sin(x2); - double y1x2x1Derivative = -2.*x1*std::sin(x2); - double y1x2x2Derivative = -x1*x1*std::cos(x2); + double y1x1x1Derivative = 2. * std::cos(x2); + double y1x1x2Derivative = -2. * x1 * std::sin(x2); + double y1x2x1Derivative = -2. * x1 * std::sin(x2); + double y1x2x2Derivative = -x1 * x1 * std::cos(x2); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -4020,8 +3986,7 @@ BOOST_AUTO_TEST_CASE(customFmaxTrig_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customFminTrig_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customFminTrig_HOS_Reverse) { double x1 = 21.07, x2 = 1.5; adouble ax1, ax2; double y1; @@ -4031,24 +3996,24 @@ BOOST_AUTO_TEST_CASE(customFminTrig_HOS_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = fmin(ax1*ax1*cos(ax2), sin(ax1)*cos(ax2*exp(ax2))); + ay1 = fmin(ax1 * ax1 * cos(ax2), sin(ax1) * cos(ax2 * exp(ax2))); ay1 >>= y1; trace_off(); - double y1x1Derivative = std::cos(x1)*std::cos(x2*std::exp(x2)); - double y1x2Derivative = -std::sin(x1)*std::sin(x2*std::exp(x2)) - * (1. + x2)*std::exp(x2); + double y1x1Derivative = std::cos(x1) * std::cos(x2 * std::exp(x2)); + double y1x2Derivative = + -std::sin(x1) * std::sin(x2 * std::exp(x2)) * (1. + x2) * std::exp(x2); - double y1x1x1Derivative = -std::sin(x1)*std::cos(x2*std::exp(x2)); - double y1x1x2Derivative = -std::cos(x1)*std::sin(x2*std::exp(x2)) - * (1. + x2)*std::exp(x2); - double y1x2x1Derivative = -std::cos(x1)*std::sin(x2*std::exp(x2)) - * (1. + x2)*std::exp(x2); - double y1x2x2Derivative = -std::sin(x1)*std::cos(x2*std::exp(x2)) - * std::pow((1. + x2)*std::exp(x2), 2) - - std::sin(x1)*std::sin(x2*exp(x2))*(2. + x2) - *std::exp(x2); + double y1x1x1Derivative = -std::sin(x1) * std::cos(x2 * std::exp(x2)); + double y1x1x2Derivative = + -std::cos(x1) * std::sin(x2 * std::exp(x2)) * (1. + x2) * std::exp(x2); + double y1x2x1Derivative = + -std::cos(x1) * std::sin(x2 * std::exp(x2)) * (1. + x2) * std::exp(x2); + double y1x2x2Derivative = + -std::sin(x1) * std::cos(x2 * std::exp(x2)) * + std::pow((1. + x2) * std::exp(x2), 2) - + std::sin(x1) * std::sin(x2 * exp(x2)) * (2. + x2) * std::exp(x2); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -4096,8 +4061,7 @@ BOOST_AUTO_TEST_CASE(customFminTrig_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customPowExpTan_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customPowExpTan_HOS_Reverse) { double x1 = -5.2, x2 = 1.1, x3 = 5.4; adouble ax1, ax2, ax3; double y1; @@ -4108,41 +4072,41 @@ BOOST_AUTO_TEST_CASE(customPowExpTan_HOS_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = pow(ax1, 3)*pow(ax2, 4)*exp(tan(ax3)) + ax3 + sqrt(11); + ay1 = pow(ax1, 3) * pow(ax2, 4) * exp(tan(ax3)) + ax3 + sqrt(11); ay1 >>= y1; trace_off(); - double y1x1Derivative = 3.*std::pow(x1, 2)*std::pow(x2, 4) - * std::exp(std::tan(x3)); - double y1x2Derivative = 4.*std::pow(x1, 3)*std::pow(x2, 3) - * std::exp(std::tan(x3)); - double y1x3Derivative = std::pow(x1, 3)*std::pow(x2, 4) - * std::exp(std::tan(x3)) - *(1. + std::pow(std::tan(x3), 2)) + 1.; - - double y1x1x1Derivative = 6.*x1*std::pow(x2, 4)*std::exp(std::tan(x3)); - double y1x1x2Derivative = 12.*std::pow(x1, 2)*std::pow(x2, 3) - * std::exp(std::tan(x3)); - double y1x1x3Derivative = 3.*std::pow(x1, 2)*std::pow(x2, 4) - * std::exp(std::tan(x3)) - * (1. + std::pow(std::tan(x3), 2)); - double y1x2x1Derivative = 12.*pow(x1, 2)*pow(x2, 3)*exp(tan(x3)); - double y1x2x2Derivative = 12.*pow(x1, 3)*pow(x2, 2)*exp(tan(x3)); - double y1x2x3Derivative = 4.*std::pow(x1, 3)*std::pow(x2, 3) - * std::exp(std::tan(x3)) - * (1. + std::pow(std::tan(x3), 2)); - double y1x3x1Derivative = 3.*std::pow(x1, 2)*std::pow(x2, 4) - * std::exp(std::tan(x3)) - * (1. + std::pow(std::tan(x3), 2)); - double y1x3x2Derivative = 4.*std::pow(x1, 3)*std::pow(x2, 3) - * std::exp(std::tan(x3)) - * (1. + std::pow(std::tan(x3), 2)); - double y1x3x3Derivative = std::pow(x1, 3)*std::pow(x2, 4) - * std::exp(std::tan(x3)) - * (1. + std::pow(std::tan(x3), 2)) - * (1. + 2.*std::tan(x3) - + std::pow(std::tan(x3), 2)); + double y1x1Derivative = + 3. * std::pow(x1, 2) * std::pow(x2, 4) * std::exp(std::tan(x3)); + double y1x2Derivative = + 4. * std::pow(x1, 3) * std::pow(x2, 3) * std::exp(std::tan(x3)); + double y1x3Derivative = std::pow(x1, 3) * std::pow(x2, 4) * + std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)) + + 1.; + + double y1x1x1Derivative = 6. * x1 * std::pow(x2, 4) * std::exp(std::tan(x3)); + double y1x1x2Derivative = + 12. * std::pow(x1, 2) * std::pow(x2, 3) * std::exp(std::tan(x3)); + double y1x1x3Derivative = 3. * std::pow(x1, 2) * std::pow(x2, 4) * + std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)); + double y1x2x1Derivative = 12. * pow(x1, 2) * pow(x2, 3) * exp(tan(x3)); + double y1x2x2Derivative = 12. * pow(x1, 3) * pow(x2, 2) * exp(tan(x3)); + double y1x2x3Derivative = 4. * std::pow(x1, 3) * std::pow(x2, 3) * + std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)); + double y1x3x1Derivative = 3. * std::pow(x1, 2) * std::pow(x2, 4) * + std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)); + double y1x3x2Derivative = 4. * std::pow(x1, 3) * std::pow(x2, 3) * + std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)); + double y1x3x3Derivative = + std::pow(x1, 3) * std::pow(x2, 4) * std::exp(std::tan(x3)) * + (1. + std::pow(std::tan(x3), 2)) * + (1. + 2. * std::tan(x3) + std::pow(std::tan(x3), 2)); double *x = myalloc1(3); double *xd = myalloc1(3); @@ -4213,8 +4177,7 @@ BOOST_AUTO_TEST_CASE(customPowExpTan_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customManyVariabl_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customManyVariabl_HOS_Reverse) { double x1 = 1.5, x2 = -1.5, x3 = 3., x4 = -3., x5 = 4.5, x6 = -4.5; adouble ax1, ax2, ax3, ax4, ax5, ax6; double y1; @@ -4228,7 +4191,8 @@ BOOST_AUTO_TEST_CASE(customManyVariabl_HOS_Reverse) ax5 <<= x5; ax6 <<= x6; - ay1 = 0.5*(ax1*ax1 + ax2*ax2 + ax3*ax3 + ax4*ax4 + ax5*ax5 + ax6*ax6); + ay1 = 0.5 * + (ax1 * ax1 + ax2 * ax2 + ax3 * ax3 + ax4 * ax4 + ax5 * ax5 + ax6 * ax6); ay1 >>= y1; trace_off(); @@ -4451,8 +4415,7 @@ BOOST_AUTO_TEST_CASE(customManyVariabl_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customConstant_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customConstant_HOS_Reverse) { double x1 = 1.5, x2 = -1.5, x3 = 3., x4 = -3., x5 = 4.5, x6 = -4.5; adouble ax1, ax2, ax3, ax4, ax5, ax6; double y1; @@ -4689,9 +4652,8 @@ BOOST_AUTO_TEST_CASE(customConstant_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customSphereCoord_HOS_Reverse) -{ - double x1 = 21.87, x2 = std::acos(0) - 0.01, x3 = 0.5*std::acos(0); +BOOST_AUTO_TEST_CASE(customSphereCoord_HOS_Reverse) { + double x1 = 21.87, x2 = std::acos(0) - 0.01, x3 = 0.5 * std::acos(0); adouble ax1, ax2, ax3; double y1, y2, y3; adouble ay1, ay2, ay3; @@ -4701,52 +4663,52 @@ BOOST_AUTO_TEST_CASE(customSphereCoord_HOS_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = ax1*cos(ax2)*sin(ax3); - ay2 = ax1*sin(ax2)*sin(ax3); - ay3 = ax1*cos(ax3); + ay1 = ax1 * cos(ax2) * sin(ax3); + ay2 = ax1 * sin(ax2) * sin(ax3); + ay3 = ax1 * cos(ax3); ay1 >>= y1; ay2 >>= y2; ay3 >>= y3; trace_off(); - double y1x1Derivative = std::cos(x2)*std::sin(x3); - double y1x2Derivative = -x1*std::sin(x2)*std::sin(x3); - double y1x3Derivative = x1*std::cos(x2)*std::cos(x3); - double y2x1Derivative = std::sin(x2)*std::sin(x3); - double y2x2Derivative = x1*std::cos(x2)*std::sin(x3); - double y2x3Derivative = x1*std::sin(x2)*std::cos(x3); + double y1x1Derivative = std::cos(x2) * std::sin(x3); + double y1x2Derivative = -x1 * std::sin(x2) * std::sin(x3); + double y1x3Derivative = x1 * std::cos(x2) * std::cos(x3); + double y2x1Derivative = std::sin(x2) * std::sin(x3); + double y2x2Derivative = x1 * std::cos(x2) * std::sin(x3); + double y2x3Derivative = x1 * std::sin(x2) * std::cos(x3); double y3x1Derivative = std::cos(x3); double y3x2Derivative = 0.; - double y3x3Derivative = -x1*std::sin(x3); + double y3x3Derivative = -x1 * std::sin(x3); double y1x1x1Derivative = 0.; - double y1x1x2Derivative = -std::sin(x2)*std::sin(x3); - double y1x1x3Derivative = std::cos(x2)*std::cos(x3); + double y1x1x2Derivative = -std::sin(x2) * std::sin(x3); + double y1x1x3Derivative = std::cos(x2) * std::cos(x3); double y2x1x1Derivative = 0.; - double y2x1x2Derivative = std::cos(x2)*std::sin(x3); - double y2x1x3Derivative = std::sin(x2)*std::cos(x3); + double y2x1x2Derivative = std::cos(x2) * std::sin(x3); + double y2x1x3Derivative = std::sin(x2) * std::cos(x3); double y3x1x1Derivative = 0.; double y3x1x2Derivative = 0.; double y3x1x3Derivative = -std::sin(x3); - double y1x2x1Derivative = -std::sin(x2)*std::sin(x3); - double y1x2x2Derivative = -x1*std::cos(x2)*std::sin(x3); - double y1x2x3Derivative = -x1*std::sin(x2)*std::cos(x3); - double y2x2x1Derivative = std::cos(x2)*std::sin(x3); - double y2x2x2Derivative = -x1*std::sin(x2)*std::sin(x3); - double y2x2x3Derivative = x1*std::cos(x2)*std::cos(x3); + double y1x2x1Derivative = -std::sin(x2) * std::sin(x3); + double y1x2x2Derivative = -x1 * std::cos(x2) * std::sin(x3); + double y1x2x3Derivative = -x1 * std::sin(x2) * std::cos(x3); + double y2x2x1Derivative = std::cos(x2) * std::sin(x3); + double y2x2x2Derivative = -x1 * std::sin(x2) * std::sin(x3); + double y2x2x3Derivative = x1 * std::cos(x2) * std::cos(x3); double y3x2x1Derivative = 0.; double y3x2x2Derivative = 0.; double y3x2x3Derivative = 0.; - double y1x3x1Derivative = std::cos(x2)*std::cos(x3); - double y1x3x2Derivative = -x1*std::sin(x2)*std::cos(x3); - double y1x3x3Derivative = -x1*std::cos(x2)*std::sin(x3); - double y2x3x1Derivative = std::sin(x2)*std::cos(x3); - double y2x3x2Derivative = x1*std::cos(x2)*std::cos(x3); - double y2x3x3Derivative = -x1*std::sin(x2)*std::sin(x3); + double y1x3x1Derivative = std::cos(x2) * std::cos(x3); + double y1x3x2Derivative = -x1 * std::sin(x2) * std::cos(x3); + double y1x3x3Derivative = -x1 * std::cos(x2) * std::sin(x3); + double y2x3x1Derivative = std::sin(x2) * std::cos(x3); + double y2x3x2Derivative = x1 * std::cos(x2) * std::cos(x3); + double y2x3x3Derivative = -x1 * std::sin(x2) * std::sin(x3); double y3x3x1Derivative = -std::sin(x3); double y3x3x2Derivative = 0.; - double y3x3x3Derivative = -x1*std::cos(x3); + double y3x3x3Derivative = -x1 * std::cos(x3); double *x = myalloc1(3); double *xd = myalloc1(3); @@ -4755,7 +4717,7 @@ BOOST_AUTO_TEST_CASE(customSphereCoord_HOS_Reverse) x[0] = 21.87; x[1] = std::acos(0) - 0.01; - x[2] = 0.5*std::acos(0); + x[2] = 0.5 * std::acos(0); xd[0] = 1.; xd[1] = 0.; xd[2] = 0.; @@ -4911,8 +4873,7 @@ BOOST_AUTO_TEST_CASE(customSphereCoord_HOS_Reverse) myfree2(Z); } -BOOST_AUTO_TEST_CASE(customCylinderCoord_HOS_Reverse) -{ +BOOST_AUTO_TEST_CASE(customCylinderCoord_HOS_Reverse) { double x1 = 21.87, x2 = std::acos(0) - 0.01, x3 = 105.05; adouble ax1, ax2, ax3; double y1, y2, y3; @@ -4923,8 +4884,8 @@ BOOST_AUTO_TEST_CASE(customCylinderCoord_HOS_Reverse) ax2 <<= x2; ax3 <<= x3; - ay1 = ax1*cos(ax2); - ay2 = ax1*sin(ax2); + ay1 = ax1 * cos(ax2); + ay2 = ax1 * sin(ax2); ay3 = ax3; ay1 >>= y1; @@ -4933,10 +4894,10 @@ BOOST_AUTO_TEST_CASE(customCylinderCoord_HOS_Reverse) trace_off(); double y1x1Derivative = std::cos(x2); - double y1x2Derivative = -x1*std::sin(x2); + double y1x2Derivative = -x1 * std::sin(x2); double y1x3Derivative = 0.; double y2x1Derivative = std::sin(x2); - double y2x2Derivative = x1*std::cos(x2); + double y2x2Derivative = x1 * std::cos(x2); double y2x3Derivative = 0.; double y3x1Derivative = 0.; double y3x2Derivative = 0.; @@ -4952,10 +4913,10 @@ BOOST_AUTO_TEST_CASE(customCylinderCoord_HOS_Reverse) double y3x1x2Derivative = 0.; double y3x1x3Derivative = 0.; double y1x2x1Derivative = -std::sin(x2); - double y1x2x2Derivative = -x1*std::cos(x2); + double y1x2x2Derivative = -x1 * std::cos(x2); double y1x2x3Derivative = 0.; double y2x2x1Derivative = std::cos(x2); - double y2x2x2Derivative = -x1*std::sin(x2); + double y2x2x2Derivative = -x1 * std::sin(x2); double y2x2x3Derivative = 0.; double y3x2x1Derivative = 0.; double y3x2x2Derivative = 0.; @@ -5133,11 +5094,4 @@ BOOST_AUTO_TEST_CASE(customCylinderCoord_HOS_Reverse) myfree2(Z); } - - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/ADOL-C/boost-test/traceSecOrderVector.cpp b/ADOL-C/boost-test/traceSecOrderVector.cpp index 3ed9e6b16..1635cb38f 100644 --- a/ADOL-C/boost-test/traceSecOrderVector.cpp +++ b/ADOL-C/boost-test/traceSecOrderVector.cpp @@ -7,8 +7,7 @@ namespace tt = boost::test_tools; #include "const.h" -BOOST_AUTO_TEST_SUITE( trace_sec_order_vec ) - +BOOST_AUTO_TEST_SUITE(trace_sec_order_vec) /**************************************/ /* Tests for ADOL-C trace vector mode */ @@ -16,7 +15,6 @@ BOOST_AUTO_TEST_SUITE( trace_sec_order_vec ) /* Author: Philipp Schuette */ /**************************************/ - /* This file contains custom tests for the higher order derivative * evaluation drivers hov_forward, hov_reverse. * @@ -32,8 +30,7 @@ BOOST_AUTO_TEST_SUITE( trace_sec_order_vec ) * First derivative: 2.*3.*x*x * Second derivative: 2.*3.*2.*x */ -BOOST_AUTO_TEST_CASE(CustomCube_HOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CustomCube_HOV_Forward) { double x1 = 3.; adouble ax1; double y1; @@ -42,29 +39,31 @@ BOOST_AUTO_TEST_CASE(CustomCube_HOV_Forward) trace_on(1, 1); ax1 <<= x1; - ay1 = 2.*ax1*ax1*ax1; + ay1 = 2. * ax1 * ax1 * ax1; ay1 >>= y1; trace_off(); - double* yprim; + double *yprim; yprim = myalloc1(1); - yprim[0] = 2.*x1*x1*x1; + yprim[0] = 2. * x1 * x1 * x1; - double*** yDerivative; + double ***yDerivative; yDerivative = myalloc3(1, 3, 2); - yDerivative[0][0][0] = 2.*3.*x1*x1; - yDerivative[0][0][1] = 2.*3.*x1*x1 + 0.5*(2.*3.*2.*x1); - yDerivative[0][1][0] = 2.*2.*3.*x1*x1; - yDerivative[0][1][1] = 2.*2.*3.*x1*x1 + 0.5*(2.*3.*2.*x1)*2.*2.; - yDerivative[0][2][0] = 3.*2.*3.*x1*x1; - yDerivative[0][2][1] = 3.*2.*3.*x1*x1 + 0.5*(2.*3.*2.*x1)*3.*3.; - - double* x; + yDerivative[0][0][0] = 2. * 3. * x1 * x1; + yDerivative[0][0][1] = 2. * 3. * x1 * x1 + 0.5 * (2. * 3. * 2. * x1); + yDerivative[0][1][0] = 2. * 2. * 3. * x1 * x1; + yDerivative[0][1][1] = + 2. * 2. * 3. * x1 * x1 + 0.5 * (2. * 3. * 2. * x1) * 2. * 2.; + yDerivative[0][2][0] = 3. * 2. * 3. * x1 * x1; + yDerivative[0][2][1] = + 3. * 2. * 3. * x1 * x1 + 0.5 * (2. * 3. * 2. * x1) * 3. * 3.; + + double *x; x = myalloc1(1); x[0] = 3.; - double*** X; + double ***X; X = myalloc3(1, 3, 2); X[0][0][0] = 1.; X[0][1][0] = 2.; @@ -73,10 +72,10 @@ BOOST_AUTO_TEST_CASE(CustomCube_HOV_Forward) X[0][1][1] = 2.; X[0][2][1] = 3.; - double* y; + double *y; y = myalloc1(1); - double*** Y; + double ***Y; Y = myalloc3(1, 3, 2); hov_forward(1, 1, 1, 2, 3, x, X, y, Y); @@ -97,8 +96,7 @@ BOOST_AUTO_TEST_CASE(CustomCube_HOV_Forward) myfree3(Y); } -BOOST_AUTO_TEST_CASE(customCube_HOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(customCube_HOV_Reverse) { double x1 = 3.; adouble ax1; double y1; @@ -107,14 +105,14 @@ BOOST_AUTO_TEST_CASE(customCube_HOV_Reverse) trace_on(1, 1); ax1 <<= x1; - ay1 = 2.*ax1*ax1*ax1; + ay1 = 2. * ax1 * ax1 * ax1; ay1 >>= y1; trace_off(); - double y1x1Derivative = 6.*x1*x1; + double y1x1Derivative = 6. * x1 * x1; - double y1x1x1Derivative = 12.*x1; + double y1x1x1Derivative = 12. * x1; double *x = myalloc1(1); double *xd = myalloc1(1); @@ -126,12 +124,12 @@ BOOST_AUTO_TEST_CASE(customCube_HOV_Reverse) fos_forward(1, 1, 1, 2, x, xd, y, yd); - double** U = myalloc2(2, 1); - double*** Z = myalloc3(2, 1, 2); - short int** nz = (short int**)malloc(sizeof(short int*)*2); + double **U = myalloc2(2, 1); + double ***Z = myalloc3(2, 1, 2); + short int **nz = (short int **)malloc(sizeof(short int *) * 2); - nz[0] = (short int*)malloc(sizeof(short int)*1); - nz[1] = (short int*)malloc(sizeof(short int)*1); + nz[0] = (short int *)malloc(sizeof(short int) * 1); + nz[1] = (short int *)malloc(sizeof(short int) * 1); nz[0][0] = 1; nz[1][0] = 1; @@ -142,8 +140,8 @@ BOOST_AUTO_TEST_CASE(customCube_HOV_Reverse) BOOST_TEST(Z[0][0][0] == y1x1Derivative, tt::tolerance(tol)); BOOST_TEST(Z[0][0][1] == y1x1x1Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][0][0] == 5.*y1x1Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][0][1] == 5.*y1x1x1Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][0][0] == 5. * y1x1Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][0][1] == 5. * y1x1x1Derivative, tt::tolerance(tol)); myfree1(x); myfree1(xd); @@ -162,8 +160,7 @@ BOOST_AUTO_TEST_CASE(customCube_HOV_Reverse) * Second derivatives: (-cos(x1)*sin(x2), -sin(x1)*cos(x2), * -sin(x1)*cos(x2), -cos(x1)*sin(x2)) */ -BOOST_AUTO_TEST_CASE(CustomTrigProd_HOV_Forward) -{ +BOOST_AUTO_TEST_CASE(CustomTrigProd_HOV_Forward) { double x1 = 1.3, x2 = 3.1; adouble ax1, ax2; double y1; @@ -173,38 +170,38 @@ BOOST_AUTO_TEST_CASE(CustomTrigProd_HOV_Forward) ax1 <<= x1; ax2 <<= x2; - ay1 = cos(ax1)*sin(ax2); + ay1 = cos(ax1) * sin(ax2); ay1 >>= y1; trace_off(); - double* yprim; + double *yprim; yprim = myalloc1(1); - yprim[0] = std::cos(x1)*std::sin(x2); + yprim[0] = std::cos(x1) * std::sin(x2); - double*** yDerivative; + double ***yDerivative; yDerivative = myalloc3(1, 3, 2); - yDerivative[0][0][0] = -std::sin(x1)*std::sin(x2); - yDerivative[0][0][1] = -std::sin(x1)*std::sin(x2) - - 0.5*std::cos(x1)*std::sin(x2); - yDerivative[0][1][0] = std::cos(x1)*std::cos(x2); - yDerivative[0][1][1] = std::cos(x1)*std::cos(x2) - - 0.5*std::cos(x1)*std::sin(x2); - yDerivative[0][2][0] = -5.*std::sin(x1)*std::sin(x2) - + 3.*std::cos(x1)*std::cos(x2); - yDerivative[0][2][1] = -std::sin(x1)*std::sin(x2) - - std::cos(x1)*std::cos(x2) - + 0.5*(5.*(-5.*std::cos(x1)*std::sin(x2) - - 3.*std::sin(x1)*std::cos(x2)) - + 3.*(-5.*std::sin(x1)*std::cos(x2) - + 3.*-std::cos(x1)*std::sin(x2))); - - double* x; + yDerivative[0][0][0] = -std::sin(x1) * std::sin(x2); + yDerivative[0][0][1] = + -std::sin(x1) * std::sin(x2) - 0.5 * std::cos(x1) * std::sin(x2); + yDerivative[0][1][0] = std::cos(x1) * std::cos(x2); + yDerivative[0][1][1] = + std::cos(x1) * std::cos(x2) - 0.5 * std::cos(x1) * std::sin(x2); + yDerivative[0][2][0] = + -5. * std::sin(x1) * std::sin(x2) + 3. * std::cos(x1) * std::cos(x2); + yDerivative[0][2][1] = -std::sin(x1) * std::sin(x2) - + std::cos(x1) * std::cos(x2) + + 0.5 * (5. * (-5. * std::cos(x1) * std::sin(x2) - + 3. * std::sin(x1) * std::cos(x2)) + + 3. * (-5. * std::sin(x1) * std::cos(x2) + + 3. * -std::cos(x1) * std::sin(x2))); + + double *x; x = myalloc1(2); x[0] = 1.3; x[1] = 3.1; - double*** X; + double ***X; X = myalloc3(2, 3, 2); X[0][0][0] = 1.; X[0][1][0] = 0.; @@ -220,10 +217,10 @@ BOOST_AUTO_TEST_CASE(CustomTrigProd_HOV_Forward) X[1][1][1] = 1.; X[1][2][1] = -1.; - double* y; + double *y; y = myalloc1(1); - double*** Y; + double ***Y; Y = myalloc3(1, 3, 2); hov_forward(1, 1, 2, 2, 3, x, X, y, Y); @@ -244,8 +241,7 @@ BOOST_AUTO_TEST_CASE(CustomTrigProd_HOV_Forward) myfree3(Y); } -BOOST_AUTO_TEST_CASE(customTrigProd_HOV_Reverse) -{ +BOOST_AUTO_TEST_CASE(customTrigProd_HOV_Reverse) { double x1 = 1.3, x2 = 3.1; adouble ax1, ax2; double y1; @@ -255,18 +251,18 @@ BOOST_AUTO_TEST_CASE(customTrigProd_HOV_Reverse) ax1 <<= x1; ax2 <<= x2; - ay1 = cos(ax1)*sin(ax2); + ay1 = cos(ax1) * sin(ax2); ay1 >>= y1; trace_off(); - double y1x1Derivative = -std::sin(x1)*std::sin(x2); - double y1x2Derivative = std::cos(x1)*std::cos(x2); + double y1x1Derivative = -std::sin(x1) * std::sin(x2); + double y1x2Derivative = std::cos(x1) * std::cos(x2); - double y1x1x1Derivative = -std::cos(x1)*std::sin(x2); - double y1x1x2Derivative = -std::sin(x1)*std::cos(x2); - double y1x2x1Derivative = -std::sin(x1)*cos(x2); - double y1x2x2Derivative = -std::cos(x1)*std::sin(x2); + double y1x1x1Derivative = -std::cos(x1) * std::sin(x2); + double y1x1x2Derivative = -std::sin(x1) * std::cos(x2); + double y1x2x1Derivative = -std::sin(x1) * cos(x2); + double y1x2x2Derivative = -std::cos(x1) * std::sin(x2); double *x = myalloc1(2); double *xd = myalloc1(2); @@ -280,12 +276,12 @@ BOOST_AUTO_TEST_CASE(customTrigProd_HOV_Reverse) fos_forward(1, 1, 2, 2, x, xd, y, yd); - double** U = myalloc2(2, 1); - double*** Z = myalloc3(2, 2, 2); - short int** nz = (short int**)malloc(sizeof(short int*)*2); + double **U = myalloc2(2, 1); + double ***Z = myalloc3(2, 2, 2); + short int **nz = (short int **)malloc(sizeof(short int *) * 2); - nz[0] = (short int*)malloc(sizeof(short int)*2); - nz[1] = (short int*)malloc(sizeof(short int)*2); + nz[0] = (short int *)malloc(sizeof(short int) * 2); + nz[1] = (short int *)malloc(sizeof(short int) * 2); nz[0][0] = 4; nz[0][1] = 4; nz[1][0] = 4; @@ -300,10 +296,10 @@ BOOST_AUTO_TEST_CASE(customTrigProd_HOV_Reverse) BOOST_TEST(Z[0][1][0] == y1x2Derivative, tt::tolerance(tol)); BOOST_TEST(Z[0][0][1] == y1x1x1Derivative, tt::tolerance(tol)); BOOST_TEST(Z[0][1][1] == y1x1x2Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][0][0] == 5.*y1x1Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][1][0] == 5.*y1x2Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][0][1] == 5.*y1x1x1Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][1][1] == 5.*y1x1x2Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][0][0] == 5. * y1x1Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][1][0] == 5. * y1x2Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][0][1] == 5. * y1x1x1Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][1][1] == 5. * y1x1x2Derivative, tt::tolerance(tol)); xd[0] = 0.; xd[1] = 1.; @@ -316,10 +312,10 @@ BOOST_AUTO_TEST_CASE(customTrigProd_HOV_Reverse) BOOST_TEST(Z[0][1][0] == y1x2Derivative, tt::tolerance(tol)); BOOST_TEST(Z[0][0][1] == y1x2x1Derivative, tt::tolerance(tol)); BOOST_TEST(Z[0][1][1] == y1x2x2Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][0][0] == 5.*y1x1Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][1][0] == 5.*y1x2Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][0][1] == 5.*y1x2x1Derivative, tt::tolerance(tol)); - BOOST_TEST(Z[1][1][1] == 5.*y1x2x2Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][0][0] == 5. * y1x1Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][1][0] == 5. * y1x2Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][0][1] == 5. * y1x2x1Derivative, tt::tolerance(tol)); + BOOST_TEST(Z[1][1][1] == 5. * y1x2x2Derivative, tt::tolerance(tol)); myfree1(x); myfree1(xd); @@ -333,11 +329,4 @@ BOOST_AUTO_TEST_CASE(customTrigProd_HOV_Reverse) free(nz); } - - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/ADOL-C/boost-test/tracelessCompositeTests.cpp b/ADOL-C/boost-test/tracelessCompositeTests.cpp index 47172f70a..f844c9bbe 100644 --- a/ADOL-C/boost-test/tracelessCompositeTests.cpp +++ b/ADOL-C/boost-test/tracelessCompositeTests.cpp @@ -8,8 +8,7 @@ typedef adtl::adouble adouble; #include "const.h" -BOOST_AUTO_TEST_SUITE( traceless_composite ) - +BOOST_AUTO_TEST_SUITE(traceless_composite) /************************************/ /* Tests for traceless mode with */ @@ -22,49 +21,47 @@ BOOST_AUTO_TEST_SUITE( traceless_composite ) * test functions and derivatives can be found there. */ -BOOST_AUTO_TEST_CASE(CompositeTrig1_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig1_Traceless) { double x1 = 0.289, x2 = 1.927; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::sin(ax1)*adtl::sin(ax1) + adtl::cos(ax1)*adtl::cos(ax1) + ax2; + ax1 = adtl::sin(ax1) * adtl::sin(ax1) + adtl::cos(ax1) * adtl::cos(ax1) + ax2; double x1Derivative = 0.; double x2Derivative = 1.; - x1 = std::sin(x1)*std::sin(x1) + std::cos(x1)*std::cos(x1) + x2; + x1 = std::sin(x1) * std::sin(x1) + std::cos(x1) * std::cos(x1) + x2; BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeTrig2_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig2_Traceless) { double x1 = 1.11, x2 = 2.22; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = 2.*adtl::sin(adtl::cos(ax1))*adtl::exp(ax2) - 2.*adtl::sin(ax2); + ax1 = 2. * adtl::sin(adtl::cos(ax1)) * adtl::exp(ax2) - 2. * adtl::sin(ax2); - double x1Derivative = -2.*std::cos(std::cos(x1))*std::sin(x1)*std::exp(x2); - double x2Derivative = 2.*std::sin(std::cos(x1))*std::exp(x2) - - 2.*std::cos(x2); + double x1Derivative = + -2. * std::cos(std::cos(x1)) * std::sin(x1) * std::exp(x2); + double x2Derivative = + 2. * std::sin(std::cos(x1)) * std::exp(x2) - 2. * std::cos(x2); - x1 = 2.*std::sin(std::cos(x1))*std::exp(x2) - 2.*std::sin(x2); + x1 = 2. * std::sin(std::cos(x1)) * std::exp(x2) - 2. * std::sin(x2); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeTrig3_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig3_Traceless) { double x1 = 0.516, x2 = 9.89; adouble ax1 = x1, ax2 = x2; @@ -73,11 +70,11 @@ BOOST_AUTO_TEST_CASE(CompositeTrig3_Traceless) ax1 = adtl::pow(adtl::sin(ax1), adtl::cos(ax1) - ax2); - double x1Derivative = std::pow(std::sin(x1), std::cos(x1) - x2) - * (-std::sin(x1)*std::log(std::sin(x1)) - + (std::cos(x1) - x2)*std::cos(x1)/std::sin(x1)); - double x2Derivative = -std::log(std::sin(x1)) - * std::pow(std::sin(x1), std::cos(x1) - x2); + double x1Derivative = std::pow(std::sin(x1), std::cos(x1) - x2) * + (-std::sin(x1) * std::log(std::sin(x1)) + + (std::cos(x1) - x2) * std::cos(x1) / std::sin(x1)); + double x2Derivative = + -std::log(std::sin(x1)) * std::pow(std::sin(x1), std::cos(x1) - x2); x1 = std::pow(std::sin(x1), std::cos(x1) - x2); @@ -86,256 +83,248 @@ BOOST_AUTO_TEST_CASE(CompositeTrig3_Traceless) BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeTrig4_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeTrig4_Traceless) { double x1 = 1.56, x2 = 8.99; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::atan(adtl::tan(ax1))*adtl::exp(ax2); + ax1 = adtl::atan(adtl::tan(ax1)) * adtl::exp(ax2); double x1Derivative = std::exp(x2); - double x2Derivative = x1*std::exp(x2); + double x2Derivative = x1 * std::exp(x2); - x1 = std::atan(std::tan(x1))*std::exp(x2); + x1 = std::atan(std::tan(x1)) * std::exp(x2); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LongSum_Traceless) -{ +BOOST_AUTO_TEST_CASE(LongSum_Traceless) { double x1 = 6.091, x2 = -0.004; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = std::pow(2., 10.)*ax1 + ax2 + std::sqrt(2.)*ax1 + (-3.5)*ax1 - 9.9*ax2 - - 10000.001; + ax1 = std::pow(2., 10.) * ax1 + ax2 + std::sqrt(2.) * ax1 + (-3.5) * ax1 - + 9.9 * ax2 - 10000.001; double x1Derivative = std::pow(2., 10.) + std::sqrt(2.) - 3.5; double x2Derivative = 1. - 9.9; - x1 = std::pow(2., 10.)*x1 + x2 + std::sqrt(2.)*x1 + (-3.5)*x1 - 9.9*x2 - - 10000.001; + x1 = std::pow(2., 10.) * x1 + x2 + std::sqrt(2.) * x1 + (-3.5) * x1 - + 9.9 * x2 - 10000.001; BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(InverseFunc_Traceless) -{ +BOOST_AUTO_TEST_CASE(InverseFunc_Traceless) { double x1 = 3.77, x2 = -21.12; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::sqrt(adtl::pow(ax1, 2.))*ax2; + ax1 = adtl::sqrt(adtl::pow(ax1, 2.)) * ax2; double x1Derivative = x2; double x2Derivative = x1; - x1 = x1*x2; + x1 = x1 * x2; BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(ExpPow_Traceless) -{ +BOOST_AUTO_TEST_CASE(ExpPow_Traceless) { double x1 = 0.642, x2 = 6.42; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::exp(ax1 + adtl::exp(ax2))*pow(ax1, ax2); + ax1 = adtl::exp(ax1 + adtl::exp(ax2)) * pow(ax1, ax2); - double x1Derivative = std::exp(x1 + std::exp(x2)) * std::pow(x1, x2) - + std::exp(x1 + std::exp(x2)) - * x2 * std::pow(x1, x2 - 1); - double x2Derivative = std::exp(x1 + std::exp(x2))*std::exp(x2) - * std::pow(x1, x2) + std::exp(x1 + std::exp(x2)) - * std::pow(x1, x2)*std::log(x1); + double x1Derivative = std::exp(x1 + std::exp(x2)) * std::pow(x1, x2) + + std::exp(x1 + std::exp(x2)) * x2 * std::pow(x1, x2 - 1); + double x2Derivative = + std::exp(x1 + std::exp(x2)) * std::exp(x2) * std::pow(x1, x2) + + std::exp(x1 + std::exp(x2)) * std::pow(x1, x2) * std::log(x1); - x1 = std::exp(x1 + std::exp(x2))*std::pow(x1, x2); + x1 = std::exp(x1 + std::exp(x2)) * std::pow(x1, x2); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeSqrt_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeSqrt_Traceless) { double x1 = 2.22, x2 = -2.14; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::sqrt(adtl::sqrt(ax1*adtl::exp(ax2))); + ax1 = adtl::sqrt(adtl::sqrt(ax1 * adtl::exp(ax2))); - double x1Derivative = 0.25*std::pow(x1*std::exp(x2), -0.75)*std::exp(x2); - double x2Derivative = 0.25*std::pow(x1*std::exp(x2), -0.75)*x1*std::exp(x2); + double x1Derivative = + 0.25 * std::pow(x1 * std::exp(x2), -0.75) * std::exp(x2); + double x2Derivative = + 0.25 * std::pow(x1 * std::exp(x2), -0.75) * x1 * std::exp(x2); - x1 = std::sqrt(std::sqrt(x1*std::exp(x2))); + x1 = std::sqrt(std::sqrt(x1 * std::exp(x2))); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeHyper_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeHyper_Traceless) { double x1 = 0.1, x2 = 5.099; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::tanh(adtl::acos(adtl::pow(ax1, 2) + 0.5)*adtl::sin(ax2)); + ax1 = adtl::tanh(adtl::acos(adtl::pow(ax1, 2) + 0.5) * adtl::sin(ax2)); - double x1Derivative = -(1. - std::pow(std::tanh(std::acos(std::pow(x1, 2)+0.5) - * std::sin(x2)), 2)) * std::sin(x2) * 2. * x1 - / (std::sqrt(1. - std::pow(std::pow(x1, 2) + 0.5, 2))); - double x2Derivative = (1. - std::pow(std::tanh(std::acos(std::pow(x1, 2)+0.5) - * std::sin(x2)), 2)) * std::cos(x2) - * std::acos(std::pow(x1, 2) + 0.5); + double x1Derivative = + -(1. - + std::pow(std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)), + 2)) * + std::sin(x2) * 2. * x1 / + (std::sqrt(1. - std::pow(std::pow(x1, 2) + 0.5, 2))); + double x2Derivative = + (1. - std::pow(std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)), + 2)) * + std::cos(x2) * std::acos(std::pow(x1, 2) + 0.5); - x1 = std::tanh(std::acos(std::pow(x1, 2) + 0.5)*std::sin(x2)); + x1 = std::tanh(std::acos(std::pow(x1, 2) + 0.5) * std::sin(x2)); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeFmax_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeFmax_Traceless) { double x1 = 2.31, x2 = 1.32; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::fmax(ax1*std::sqrt(2.), ax2*std::sqrt(3.)); + ax1 = adtl::fmax(ax1 * std::sqrt(2.), ax2 * std::sqrt(3.)); double x1Derivative = std::sqrt(2.); double x2Derivative = 0.; - x1 = std::fmax(x1*std::sqrt(2.), x2*std::sqrt(2.)); + x1 = std::fmax(x1 * std::sqrt(2.), x2 * std::sqrt(2.)); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeFmin_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeFmin_Traceless) { double x1 = 2.31, x2 = 1.32; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::fmin(ax1*std::sqrt(2.), ax2*std::sqrt(3.)); + ax1 = adtl::fmin(ax1 * std::sqrt(2.), ax2 * std::sqrt(3.)); double x1Derivative = 0.; double x2Derivative = std::sqrt(3.); - x1 = std::fmin(x1*std::sqrt(2.), x2*std::sqrt(3.)); + x1 = std::fmin(x1 * std::sqrt(2.), x2 * std::sqrt(3.)); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeErfFabs_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeErfFabs_Traceless) { double x1 = 4.56, x2 = 6.45; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::erf(adtl::fabs(ax1 - 2.)*adtl::sinh(ax2)); + ax1 = adtl::erf(adtl::fabs(ax1 - 2.) * adtl::sinh(ax2)); - double x1Derivative = 2. / std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - 2.) - * std::sinh(x2), 2)) - * std::sinh(x2); - double x2Derivative = 2. / std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - 2.) - * std::sinh(x2), 2)) - * std::fabs(x1 - 2.) * std::cosh(x2); + double x1Derivative = + 2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - 2.) * std::sinh(x2), 2)) * + std::sinh(x2); + double x2Derivative = + 2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - 2.) * std::sinh(x2), 2)) * + std::fabs(x1 - 2.) * std::cosh(x2); - x1 = std::erf(std::fabs(x1 - 2.)*std::sinh(x2)); + x1 = std::erf(std::fabs(x1 - 2.) * std::sinh(x2)); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompositeErfcFabs_Traceless) -{ +BOOST_AUTO_TEST_CASE(CompositeErfcFabs_Traceless) { double x1 = 4.56, x2 = 6.45; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = adtl::erfc(adtl::fabs(ax1 - 2.)*adtl::sinh(ax2)); + ax1 = adtl::erfc(adtl::fabs(ax1 - 2.) * adtl::sinh(ax2)); - double x1Derivative = -2. / std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - 2.) - * std::sinh(x2), 2)) - * std::sinh(x2); - double x2Derivative = -2. / std::sqrt(std::acos(-1.)) - * std::exp(-std::pow(std::fabs(x1 - 2.) - * std::sinh(x2), 2)) - * std::fabs(x1 - 2.) * std::cosh(x2); + double x1Derivative = + -2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - 2.) * std::sinh(x2), 2)) * + std::sinh(x2); + double x2Derivative = + -2. / std::sqrt(std::acos(-1.)) * + std::exp(-std::pow(std::fabs(x1 - 2.) * std::sinh(x2), 2)) * + std::fabs(x1 - 2.) * std::cosh(x2); - x1 = std::erfc(std::fabs(x1 - 2.)*std::sinh(x2)); + x1 = std::erfc(std::fabs(x1 - 2.) * std::sinh(x2)); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(ExpTrigSqrt_Traceless) -{ +BOOST_AUTO_TEST_CASE(ExpTrigSqrt_Traceless) { double x1 = 1.2, x2 = 2.1; adouble ax1 = x1, ax2 = x2; ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ax1 = 5. * adtl::exp(adtl::sin(ax1)*adtl::cos(ax1)) - * adtl::pow(adtl::sqrt(ax2), 5.); + ax1 = 5. * adtl::exp(adtl::sin(ax1) * adtl::cos(ax1)) * + adtl::pow(adtl::sqrt(ax2), 5.); - double x1Derivative = 5. * std::exp(std::sin(x1)*std::cos(x1)) - * (std::cos(x1)*std::cos(x1) - - std::sin(x1)*std::sin(x1)) - * std::pow(std::sqrt(x2), 5.); - double x2Derivative = 5. * std::exp(std::sin(x1)*std::cos(x1)) - * 5. * std::pow(std::sqrt(x2), 4.) - / (2.*std::sqrt(x2)); + double x1Derivative = + 5. * std::exp(std::sin(x1) * std::cos(x1)) * + (std::cos(x1) * std::cos(x1) - std::sin(x1) * std::sin(x1)) * + std::pow(std::sqrt(x2), 5.); + double x2Derivative = 5. * std::exp(std::sin(x1) * std::cos(x1)) * 5. * + std::pow(std::sqrt(x2), 4.) / (2. * std::sqrt(x2)); - x1 = 5. * std::exp(std::sin(x1)*std::cos(x1)) * std::pow(std::sqrt(x2), 5.); + x1 = 5. * std::exp(std::sin(x1) * std::cos(x1)) * std::pow(std::sqrt(x2), 5.); BOOST_TEST(ax1.getValue() == x1, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(0) == x1Derivative, tt::tolerance(tol)); BOOST_TEST(ax1.getADValue(1) == x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PolarCoord_Traceless) -{ +BOOST_AUTO_TEST_CASE(PolarCoord_Traceless) { double x1 = 8.17, x2 = -0.42; adouble ax1 = x1, ax2 = x2; double y1, y2; @@ -363,8 +352,7 @@ BOOST_AUTO_TEST_CASE(PolarCoord_Traceless) BOOST_TEST(ay2.getADValue(1) == y2x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SimpleProd_Traceless) -{ +BOOST_AUTO_TEST_CASE(SimpleProd_Traceless) { double x1 = -5.25, x2 = 2.52; adouble ax1 = x1, ax2 = x2; double y1, y2; @@ -373,16 +361,16 @@ BOOST_AUTO_TEST_CASE(SimpleProd_Traceless) ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ay1 = ax2*ax2; - ay2 = ax1*ax1; + ay1 = ax2 * ax2; + ay2 = ax1 * ax1; double y1x1Derivative = 0.; - double y1x2Derivative = 2.*x2; - double y2x1Derivative = 2.*x1; + double y1x2Derivative = 2. * x2; + double y2x1Derivative = 2. * x1; double y2x2Derivative = 0.; - y1 = x2*x2; - y2 = x1*x1; + y1 = x2 * x2; + y2 = x1 * x1; BOOST_TEST(ay1.getValue() == y1, tt::tolerance(tol)); BOOST_TEST(ay1.getADValue(0) == y1x1Derivative, tt::tolerance(tol)); @@ -392,8 +380,7 @@ BOOST_AUTO_TEST_CASE(SimpleProd_Traceless) BOOST_TEST(ay2.getADValue(1) == y2x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SimpleSum_Traceless) -{ +BOOST_AUTO_TEST_CASE(SimpleSum_Traceless) { double x1 = -5.25, x2 = 2.52; adouble ax1 = x1, ax2 = x2; double y1, y2; @@ -421,8 +408,7 @@ BOOST_AUTO_TEST_CASE(SimpleSum_Traceless) BOOST_TEST(ay2.getADValue(1) == y2x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TrigProd_Traceless) -{ +BOOST_AUTO_TEST_CASE(TrigProd_Traceless) { double x1 = 5.5, x2 = 0.5; adouble ax1 = x1, ax2 = x2; double y1, y2; @@ -431,16 +417,16 @@ BOOST_AUTO_TEST_CASE(TrigProd_Traceless) ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ay1 = adtl::sin(ax1)*adtl::cos(ax2); - ay2 = adtl::cos(ax1)*adtl::sin(ax2); + ay1 = adtl::sin(ax1) * adtl::cos(ax2); + ay2 = adtl::cos(ax1) * adtl::sin(ax2); - double y1x1Derivative = std::cos(x1)*std::cos(x2); - double y1x2Derivative = -std::sin(x1)*std::sin(x2); - double y2x1Derivative = -std::sin(x1)*std::sin(x2); - double y2x2Derivative = std::cos(x1)*std::cos(x2); + double y1x1Derivative = std::cos(x1) * std::cos(x2); + double y1x2Derivative = -std::sin(x1) * std::sin(x2); + double y2x1Derivative = -std::sin(x1) * std::sin(x2); + double y2x2Derivative = std::cos(x1) * std::cos(x2); - y1 = std::sin(x1)*std::cos(x2); - y2 = std::cos(x1)*std::sin(x2); + y1 = std::sin(x1) * std::cos(x2); + y2 = std::cos(x1) * std::sin(x2); BOOST_TEST(ay1.getValue() == y1, tt::tolerance(tol)); BOOST_TEST(ay1.getADValue(0) == y1x1Derivative, tt::tolerance(tol)); @@ -450,8 +436,7 @@ BOOST_AUTO_TEST_CASE(TrigProd_Traceless) BOOST_TEST(ay2.getADValue(1) == y2x2Derivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(MultiHyperb_Traceless) -{ +BOOST_AUTO_TEST_CASE(MultiHyperb_Traceless) { double x1 = 1., x2 = 0.1; adouble ax1 = x1, ax2 = x2; double y1, y2, y3, y4; @@ -460,29 +445,31 @@ BOOST_AUTO_TEST_CASE(MultiHyperb_Traceless) ax1.setADValue(0, 1.); ax2.setADValue(1, 1.); - ay1 = adtl::sinh(ax1*ax1) * adtl::cosh(ax2*ax2*ax2); - ay2 = adtl::pow(adtl::cosh(adtl::pow(ax1, 4.)), 2.) - - adtl::pow(adtl::cosh(adtl::pow(ax1, 4.)), 2.); - ay3 = -adtl::cosh(adtl::sqrt(ax1)*ax2)*ax2; + ay1 = adtl::sinh(ax1 * ax1) * adtl::cosh(ax2 * ax2 * ax2); + ay2 = adtl::pow(adtl::cosh(adtl::pow(ax1, 4.)), 2.) - + adtl::pow(adtl::cosh(adtl::pow(ax1, 4.)), 2.); + ay3 = -adtl::cosh(adtl::sqrt(ax1) * ax2) * ax2; ay4 = adtl::cosh(ax1) / adtl::sinh(ax2); - double y1x1Derivative = 2.*x1*std::cosh(x1*x1)*std::cosh(x2*x2*x2); - double y1x2Derivative = 3.*x2*x2*std::sinh(x1*x1)*std::sinh(x2*x2*x2); + double y1x1Derivative = + 2. * x1 * std::cosh(x1 * x1) * std::cosh(x2 * x2 * x2); + double y1x2Derivative = + 3. * x2 * x2 * std::sinh(x1 * x1) * std::sinh(x2 * x2 * x2); double y2x1Derivative = 0.0; double y2x2Derivative = 0.0; - double y3x1Derivative = -0.5*std::sinh(std::sqrt(x1)*x2)*x2*x2 - / std::sqrt(x1); - double y3x2Derivative = -std::sinh(std::sqrt(x1)*x2)*std::sqrt(x1)*x2 - - std::cosh(std::sqrt(x1)*x2); - double y4x1Derivative = std::sinh(x1)/std::sinh(x2); - double y4x2Derivative = -std::cosh(x1)*std::cosh(x2) - / std::pow(std::sinh(x2), 2.); - - y1 = std::sinh(x1*x1)*std::cosh(x2*x2*x2); - y2 = std::pow(std::cosh(std::pow(x1, 4)), 2) - - std::pow(std::cosh(std::pow(x1, 4)), 2); - y3 = -std::cosh(std::sqrt(x1)*x2)*x2; - y4 = std::cosh(x1)/std::sinh(x2); + double y3x1Derivative = + -0.5 * std::sinh(std::sqrt(x1) * x2) * x2 * x2 / std::sqrt(x1); + double y3x2Derivative = -std::sinh(std::sqrt(x1) * x2) * std::sqrt(x1) * x2 - + std::cosh(std::sqrt(x1) * x2); + double y4x1Derivative = std::sinh(x1) / std::sinh(x2); + double y4x2Derivative = + -std::cosh(x1) * std::cosh(x2) / std::pow(std::sinh(x2), 2.); + + y1 = std::sinh(x1 * x1) * std::cosh(x2 * x2 * x2); + y2 = std::pow(std::cosh(std::pow(x1, 4)), 2) - + std::pow(std::cosh(std::pow(x1, 4)), 2); + y3 = -std::cosh(std::sqrt(x1) * x2) * x2; + y4 = std::cosh(x1) / std::sinh(x2); BOOST_TEST(ay1.getValue() == y1, tt::tolerance(tol)); BOOST_TEST(ay1.getADValue(0) == y1x1Derivative, tt::tolerance(tol)); @@ -498,6 +485,4 @@ BOOST_AUTO_TEST_CASE(MultiHyperb_Traceless) BOOST_TEST(ay4.getADValue(1) == y4x2Derivative, tt::tolerance(tol)); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/ADOL-C/boost-test/tracelessOperatorScalar.cpp b/ADOL-C/boost-test/tracelessOperatorScalar.cpp index 007379027..881142d69 100644 --- a/ADOL-C/boost-test/tracelessOperatorScalar.cpp +++ b/ADOL-C/boost-test/tracelessOperatorScalar.cpp @@ -8,22 +8,19 @@ typedef adtl::adouble adouble; #include "const.h" -BOOST_AUTO_TEST_SUITE( traceless_scalar ) - +BOOST_AUTO_TEST_SUITE(traceless_scalar) /***********************************/ /* Tests for traceless scalar mode */ /* Author: Philipp Schuette */ /***********************************/ - /* Naming convention for test cases: Operatorname_Operator_Primal for primal * function value. Operatorname_Operator_Derivative(_WrtX) for function * derivative (or partial derivative wrt variable X). */ -BOOST_AUTO_TEST_CASE(ExpOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(ExpOperatorPrimal) { double a = 2.; adouble ad = a; @@ -33,8 +30,7 @@ BOOST_AUTO_TEST_CASE(ExpOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(ExpOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(ExpOperatorDerivative) { double a = 2.; adouble ad = a; @@ -50,8 +46,7 @@ BOOST_AUTO_TEST_CASE(ExpOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(MultOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(MultOperatorPrimal) { double a = 2., b = 3.5; adouble ad = a, bd = b; @@ -65,37 +60,34 @@ BOOST_AUTO_TEST_CASE(MultOperatorPrimal) * derivatives are tested. */ -BOOST_AUTO_TEST_CASE(MultOperatorDerivativeWrtA) -{ +BOOST_AUTO_TEST_CASE(MultOperatorDerivativeWrtA) { double a = 2., b = 3.5; adouble ad = a, bd = b; - double cDerivative = 3.5; - + double cDerivative = 3.5; + ad.setADValue(0, 1.); adouble cd = ad * bd; /* The expected derivative value is cdot = a*bdot + adot*b = b, because * adot = 1., bdot = 0. (by default). */ - BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(MultOperatorDerivativeWrtB) -{ +BOOST_AUTO_TEST_CASE(MultOperatorDerivativeWrtB) { double a = 2., b = 3.5; adouble ad = a, bd = b; double cDerivative = 2.; - - bd.setADValue(0,1.); + + bd.setADValue(0, 1.); adouble cd = ad * bd; - BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AddOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(AddOperatorPrimal) { double a = 2.5, b = 3.; adouble ad = a, bd = b; @@ -105,8 +97,7 @@ BOOST_AUTO_TEST_CASE(AddOperatorPrimal) BOOST_TEST(cd.getValue() == c, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtA) -{ +BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtA) { double a = 2.5, b = 3.; adouble ad = a, bd = b; @@ -116,11 +107,10 @@ BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtA) ad.setADValue(0, 1.); adouble cd = ad + bd; - BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtB) -{ +BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtB) { double a = 2.5, b = 3.; adouble ad = a, bd = b; @@ -129,11 +119,10 @@ BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtB) bd.setADValue(0, 1.); adouble cd = ad + bd; - BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtAB) -{ +BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtAB) { double a = 2.5, b = 3.; adouble ad = a, bd = b; @@ -144,22 +133,20 @@ BOOST_AUTO_TEST_CASE(AddOperatorDerivativeWrtAB) bd.setADValue(0, 5.5); adouble cd = ad + bd; - BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SubOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(SubOperatorPrimal) { double a = 1.5, b = 3.2; adouble ad = a, bd = b; double c = a - b; adouble cd = ad - bd; - BOOST_TEST(cd.getValue() == c, tt::tolerance(tol)); + BOOST_TEST(cd.getValue() == c, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtA) -{ +BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtA) { double a = 1.5, b = 3.2; adouble ad = a, bd = b; @@ -172,8 +159,7 @@ BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtA) BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtB) -{ +BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtB) { double a = 1.5, b = 3.2; adouble ad = a, bd = b; @@ -185,8 +171,7 @@ BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtB) BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtAB) -{ +BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtAB) { double a = 1.5, b = 3.2; adouble ad = a, bd = b; @@ -199,8 +184,7 @@ BOOST_AUTO_TEST_CASE(SubOperatorDerivateWrtAB) BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(DivOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(DivOperatorPrimal) { double a = 0.5, b = 4.5; adouble ad = a, bd = b; @@ -210,8 +194,7 @@ BOOST_AUTO_TEST_CASE(DivOperatorPrimal) BOOST_TEST(cd.getValue() == c, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtA) -{ +BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtA) { double a = 0.5, b = 4.5; adouble ad = a, bd = b; @@ -224,8 +207,7 @@ BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtA) BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtB) -{ +BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtB) { double a = 0.5, b = 4.5; adouble ad = a, bd = b; @@ -238,8 +220,7 @@ BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtB) BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtAB) -{ +BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtAB) { double a = 0.5, b = 4.5; adouble ad = a, bd = b; @@ -253,8 +234,7 @@ BOOST_AUTO_TEST_CASE(DivOperatorDerivativeWrtAB) BOOST_TEST(cd.getADValue(0) == cDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TanOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TanOperatorPrimal) { double a = 0.7; adouble ad = a; @@ -264,14 +244,14 @@ BOOST_AUTO_TEST_CASE(TanOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TanOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(TanOperatorDerivative) { double a = 0.7; adouble ad = a; a = std::tan(a); - /* Derivative value: tan = sin/cos --> tan_prime = 1./(cos*cos) = 1 + tan*tan. */ - double aDerivative = (1. + a*a); + /* Derivative value: tan = sin/cos --> tan_prime = 1./(cos*cos) = 1 + tan*tan. + */ + double aDerivative = (1. + a * a); ad.setADValue(0, 1.); ad = adtl::tan(ad); @@ -279,8 +259,7 @@ BOOST_AUTO_TEST_CASE(TanOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SinOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(SinOperatorPrimal) { double a = 1.2; adouble ad = a; @@ -290,8 +269,7 @@ BOOST_AUTO_TEST_CASE(SinOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SinOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(SinOperatorDerivative) { double a = 1.2; adouble ad = a; @@ -304,8 +282,7 @@ BOOST_AUTO_TEST_CASE(SinOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CosOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CosOperatorPrimal) { double a = 1.2; adouble ad = a; @@ -315,8 +292,7 @@ BOOST_AUTO_TEST_CASE(CosOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CosOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(CosOperatorDerivative) { double a = 1.2; adouble ad = a; @@ -329,8 +305,7 @@ BOOST_AUTO_TEST_CASE(CosOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SqrtOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(SqrtOperatorPrimal) { double a = 2.2; adouble ad = a; @@ -340,8 +315,7 @@ BOOST_AUTO_TEST_CASE(SqrtOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SqrtOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(SqrtOperatorDerivative) { double a = 2.2; adouble ad = a; @@ -352,11 +326,10 @@ BOOST_AUTO_TEST_CASE(SqrtOperatorDerivative) ad.setADValue(0, 1.); ad = adtl::sqrt(ad); - BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); + BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LogOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(LogOperatorPrimal) { double a = 4.9; adouble ad = a; @@ -366,8 +339,7 @@ BOOST_AUTO_TEST_CASE(LogOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LogOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(LogOperatorDerivative) { double a = 4.9; adouble ad = a; @@ -380,8 +352,7 @@ BOOST_AUTO_TEST_CASE(LogOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SinhOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(SinhOperatorPrimal) { double a = 4.; adouble ad = a; @@ -391,8 +362,7 @@ BOOST_AUTO_TEST_CASE(SinhOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SinhOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(SinhOperatorDerivative) { double a = 4.; adouble ad = a; @@ -405,8 +375,7 @@ BOOST_AUTO_TEST_CASE(SinhOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CoshOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CoshOperatorPrimal) { double a = 4.; adouble ad = a; @@ -416,8 +385,7 @@ BOOST_AUTO_TEST_CASE(CoshOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CoshOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(CoshOperatorDerivative) { double a = 4.; adouble ad = a; @@ -430,8 +398,7 @@ BOOST_AUTO_TEST_CASE(CoshOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TanhOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(TanhOperatorPrimal) { double a = 4.; adouble ad = a; @@ -441,14 +408,13 @@ BOOST_AUTO_TEST_CASE(TanhOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TanhOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(TanhOperatorDerivative) { double a = 4.; adouble ad = a; a = std::tanh(a); /* Derivative value 1./(cosh*cosh) = 1 - tanh*tanh. */ - double aDerivative = 1 - a*a; + double aDerivative = 1 - a * a; ad.setADValue(0, 1.); ad = adtl::tanh(ad); @@ -456,8 +422,7 @@ BOOST_AUTO_TEST_CASE(TanhOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AsinOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(AsinOperatorPrimal) { double a = 0.9; adouble ad = a; @@ -467,13 +432,12 @@ BOOST_AUTO_TEST_CASE(AsinOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AsinOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(AsinOperatorDerivative) { double a = 0.9; adouble ad = a; /* Derivative value 1. / sqrt(1. - a*a). */ - double aDerivative = 1. / (std::sqrt(1. - a*a)); + double aDerivative = 1. / (std::sqrt(1. - a * a)); ad.setADValue(0, 1.); ad = adtl::asin(ad); @@ -481,8 +445,7 @@ BOOST_AUTO_TEST_CASE(AsinOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AcosOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(AcosOperatorPrimal) { double a = 0.8; adouble ad = a; @@ -492,13 +455,12 @@ BOOST_AUTO_TEST_CASE(AcosOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AcosOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(AcosOperatorDerivative) { double a = 0.8; adouble ad = a; /* Derivative value -1. / sqrt(1. - a*a). */ - double aDerivative = -1. / (std::sqrt(1. - a*a)); + double aDerivative = -1. / (std::sqrt(1. - a * a)); ad.setADValue(0, 1.); ad = adtl::acos(ad); @@ -506,8 +468,7 @@ BOOST_AUTO_TEST_CASE(AcosOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AtanOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(AtanOperatorPrimal) { double a = 9.8; adouble ad = a; @@ -517,13 +478,12 @@ BOOST_AUTO_TEST_CASE(AtanOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AtanOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(AtanOperatorDerivative) { double a = 9.8; adouble ad = a; /* Derivative value 1./(1. + a*a). */ - double aDerivative = 1. / (1. + a*a); + double aDerivative = 1. / (1. + a * a); ad.setADValue(0, 1.); ad = adtl::atan(ad); @@ -531,19 +491,17 @@ BOOST_AUTO_TEST_CASE(AtanOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(Log10OperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(Log10OperatorPrimal) { double a = 12.3; adouble ad = a; a = std::log10(a); ad = adtl::log10(ad); - BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); + BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(Log10OperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(Log10OperatorDerivative) { double a = 12.3; adouble ad = a; @@ -553,83 +511,76 @@ BOOST_AUTO_TEST_CASE(Log10OperatorDerivative) ad.setADValue(0, 1.); ad = adtl::log10(ad); - BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); + BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AsinhOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(AsinhOperatorPrimal) { double a = 0.6; adouble ad = a; a = std::asinh(a); ad = adtl::asinh(ad); - BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); + BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AsinhOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(AsinhOperatorDerivative) { double a = 0.6; adouble ad = a; - double aDerivative = 1. / (std::sqrt(a*a + 1.)); - + double aDerivative = 1. / (std::sqrt(a * a + 1.)); + ad.setADValue(0, 1.); ad = adtl::asinh(ad); - - BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); + + BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AcoshOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(AcoshOperatorPrimal) { double a = 1.7; adouble ad = a; a = std::acosh(a); ad = adtl::acosh(ad); - BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); + BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AcoshOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(AcoshOperatorDerivative) { double a = 1.7; adouble ad = a; - double aDerivative = 1. / (std::sqrt(a*a - 1.)); - + double aDerivative = 1. / (std::sqrt(a * a - 1.)); + ad.setADValue(0, 1.); ad = adtl::acosh(ad); - - BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); + + BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AtanhOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(AtanhOperatorPrimal) { double a = 0.6; adouble ad = a; a = std::atanh(a); ad = adtl::atanh(ad); - BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); + BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AtanhOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(AtanhOperatorDerivative) { double a = 0.6; adouble ad = a; - double aDerivative = 1. / (1. - a*a); - + double aDerivative = 1. / (1. - a * a); + ad.setADValue(0, 1.); ad = adtl::atanh(ad); - - BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); + + BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(InclOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(InclOperatorPrimal) { double a = 5.; adouble ad = a; @@ -639,8 +590,7 @@ BOOST_AUTO_TEST_CASE(InclOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(InclOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(InclOperatorDerivative) { double a = 5.; adouble ad = a; @@ -652,8 +602,7 @@ BOOST_AUTO_TEST_CASE(InclOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(DeclOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(DeclOperatorPrimal) { double a = 5.; adouble ad = a; @@ -663,8 +612,7 @@ BOOST_AUTO_TEST_CASE(DeclOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(DeclOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(DeclOperatorDerivative) { double a = 5.; adouble ad = a; @@ -676,8 +624,7 @@ BOOST_AUTO_TEST_CASE(DeclOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SignPlusOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(SignPlusOperatorPrimal) { double a = 1.5; adouble ad = a; @@ -687,8 +634,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SignPlusOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(SignPlusOperatorDerivative) { double a = 1.5; adouble ad = a; @@ -700,8 +646,7 @@ BOOST_AUTO_TEST_CASE(SignPlusOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SignMinusOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(SignMinusOperatorPrimal) { double a = 1.5; adouble ad = a; @@ -711,8 +656,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SignMinusOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(SignMinusOperatorDerivative) { double a = 1.5; adouble ad = a; @@ -725,8 +669,7 @@ BOOST_AUTO_TEST_CASE(SignMinusOperatorDerivative) } /* The atan2 operator is defined as atan2(a, b) = atan(a/b). */ -BOOST_AUTO_TEST_CASE(Atan2OperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(Atan2OperatorPrimal) { double a = 12.3, b = 2.1; adouble ad = a, bd = b; @@ -736,13 +679,12 @@ BOOST_AUTO_TEST_CASE(Atan2OperatorPrimal) BOOST_TEST(cd.getValue() == c, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeWrtA) -{ +BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeWrtA) { double a = 12.3, b = 2.1; adouble ad = a, bd = b; /* Partial derivative wrt a of atan2(a, b) is b/(a*a + b*b). */ - double c = b / (a*a + b*b); + double c = b / (a * a + b * b); ad.setADValue(0, 1.); adouble cd = adtl::atan2(ad, bd); @@ -750,13 +692,12 @@ BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeWrtA) BOOST_TEST(cd.getADValue(0) == c, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeWrtB) -{ +BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeWrtB) { double a = 12.3, b = 2.1; adouble ad = a, bd = b; /* Partial derivative wrt b of atan2(a, b) is -a/(a*a + b*b). */ - double c = -a / (a*a + b*b); + double c = -a / (a * a + b * b); bd.setADValue(0, 1.); adouble cd = adtl::atan2(ad, bd); @@ -764,18 +705,19 @@ BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeWrtB) BOOST_TEST(cd.getADValue(0) == c, tt::tolerance(tol)); } -/* For the pow operator (pow(x, n) = x^n), ADOL-C provides three different options with - * the following signatures: +/* For the pow operator (pow(x, n) = x^n), ADOL-C provides three different + * options with the following signatures: * - * (1) adouble pow(adouble, double) --> can be differentiated wrt the base adouble - * (2) adouble pow(adouble, adouble) --> can be differentiated wrt both base and exponent - * (3) adouble pow(double, adouble) --> can be differentiated wrt the exponent adouble + * (1) adouble pow(adouble, double) --> can be differentiated wrt the base + * adouble (2) adouble pow(adouble, adouble) --> can be differentiated wrt both + * base and exponent (3) adouble pow(double, adouble) --> can be differentiated + * wrt the exponent adouble * - * tests for these three are implemented separately for both primal and derivative value. + * tests for these three are implemented separately for both primal and + * derivative value. */ -BOOST_AUTO_TEST_CASE(PowOperatorPrimal_1) -{ +BOOST_AUTO_TEST_CASE(PowOperatorPrimal_1) { double a = 2.3; adouble ad = a; @@ -788,8 +730,7 @@ BOOST_AUTO_TEST_CASE(PowOperatorPrimal_1) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PowOperatorDerivative_1) -{ +BOOST_AUTO_TEST_CASE(PowOperatorDerivative_1) { double a = 2.3; adouble ad = a; @@ -804,8 +745,7 @@ BOOST_AUTO_TEST_CASE(PowOperatorDerivative_1) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PowOperatorPrimal_2) -{ +BOOST_AUTO_TEST_CASE(PowOperatorPrimal_2) { double a = 2.3, e = 3.5; adouble ad = a, ed = e; @@ -815,8 +755,7 @@ BOOST_AUTO_TEST_CASE(PowOperatorPrimal_2) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PowOperatorDerivative_2_WrtA) -{ +BOOST_AUTO_TEST_CASE(PowOperatorDerivative_2_WrtA) { double a = 2.3, e = 3.5; adouble ad = a, ed = e; @@ -828,8 +767,7 @@ BOOST_AUTO_TEST_CASE(PowOperatorDerivative_2_WrtA) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PowOperatorDerivative_2_WrtB) -{ +BOOST_AUTO_TEST_CASE(PowOperatorDerivative_2_WrtB) { double a = 2.3, e = 3.5; adouble ad = a, ed = e; @@ -842,8 +780,7 @@ BOOST_AUTO_TEST_CASE(PowOperatorDerivative_2_WrtB) BOOST_TEST(ed.getADValue(0) == eDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PowOperatorPrimal_3) -{ +BOOST_AUTO_TEST_CASE(PowOperatorPrimal_3) { double e = 3.5; adouble ed = e; @@ -856,8 +793,7 @@ BOOST_AUTO_TEST_CASE(PowOperatorPrimal_3) BOOST_TEST(ed.getValue() == e, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PowOperatorDerivative_3) -{ +BOOST_AUTO_TEST_CASE(PowOperatorDerivative_3) { double e = 3.5; adouble ed = e; @@ -875,8 +811,7 @@ BOOST_AUTO_TEST_CASE(PowOperatorDerivative_3) /* Only the primitive value of frexp has to be tested, as this function * is not differentiable. */ -BOOST_AUTO_TEST_CASE(FrexpOperatorPrimal_Derivative) -{ +BOOST_AUTO_TEST_CASE(FrexpOperatorPrimal_Derivative) { double a = 4.348; adouble ad = a; @@ -885,7 +820,7 @@ BOOST_AUTO_TEST_CASE(FrexpOperatorPrimal_Derivative) n = &m; double aValue = std::frexp(a, n); - + ad.setADValue(0, 1.); ad = adtl::frexp(ad, n); @@ -894,8 +829,7 @@ BOOST_AUTO_TEST_CASE(FrexpOperatorPrimal_Derivative) BOOST_TEST(ad.getADValue(0) == 0., tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_1) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_1) { double a = 4., b = 3.; adouble ad = a, bd = b; @@ -905,8 +839,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_1) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_1_WrtA) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_1_WrtA) { double a = 4., b = 3.; adouble ad = a, bd = b; @@ -918,8 +851,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_1_WrtA) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_1_WrtB) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_1_WrtB) { double a = 4., b = 3.; adouble ad = a, bd = b; @@ -931,8 +863,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_1_WrtB) BOOST_TEST(bd.getADValue(0) == bDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_2) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_2) { double a = 4., b = 3.; adouble ad = a; @@ -942,8 +873,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_2) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_2) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_2) { double a = 4., b = 3.; adouble ad = a; @@ -955,8 +885,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_2) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_3) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_3) { double a = 4., b = 3.; adouble bd = b; @@ -966,8 +895,7 @@ BOOST_AUTO_TEST_CASE(LdexpOperatorPrimal_3) BOOST_TEST(bd.getValue() == b, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_3) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_3) { double a = 4., b = 3.; adouble bd = b; @@ -983,11 +911,11 @@ BOOST_AUTO_TEST_CASE(LdexpOperatorDerivative_3) * * (1) Primal value is tested on positive, negative and zero; * (2) Derivative value is tested on positive value, negative value; - * (3) Derivative value is tested on zero in positive direction, negative direction. + * (3) Derivative value is tested on zero in positive direction, negative + * direction. */ -BOOST_AUTO_TEST_CASE(FabsOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(FabsOperatorPrimal) { double a = 1.4, b = -5.; adouble ad = a, bd = b; @@ -1004,13 +932,12 @@ BOOST_AUTO_TEST_CASE(FabsOperatorPrimal) BOOST_TEST(cd.getValue() == 0, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeAtNonZero) -{ +BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeAtNonZero) { double a = 1.4, b = -5.; adouble ad = a, bd = b; double aDerivative = 1.; - + ad.setADValue(0, 1.); ad = adtl::fabs(ad); @@ -1023,16 +950,15 @@ BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeAtNonZero) BOOST_TEST(bd.getADValue(0) == bDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeAtZero) -{ +BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeAtZero) { adouble ad = 0; adouble bd = 0; - + ad.setADValue(0, 2.5); bd.setADValue(0, -3.5); - double posDerivative = 2.5; /* ADValue * (+1.) */ - double negDerivative = 3.5; /* ADValue * (-1.) */ + double posDerivative = 2.5; /* ADValue * (+1.) */ + double negDerivative = 3.5; /* ADValue * (-1.) */ ad = adtl::fabs(ad); bd = adtl::fabs(bd); @@ -1041,11 +967,10 @@ BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeAtZero) BOOST_TEST(bd.getADValue(0) == negDerivative, tt::tolerance(tol)); } -/* The ceil operator is implemented as to 'destroy' any derivative calculations: Its - * derivative is set to 0 regardless of Value/ADValue. +/* The ceil operator is implemented as to 'destroy' any derivative calculations: + * Its derivative is set to 0 regardless of Value/ADValue. */ -BOOST_AUTO_TEST_CASE(CeilOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CeilOperatorPrimal) { double a = 3.573; adouble ad = a; @@ -1055,8 +980,7 @@ BOOST_AUTO_TEST_CASE(CeilOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CeilOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(CeilOperatorDerivative) { double a = 3.573; adouble ad = a; @@ -1070,8 +994,7 @@ BOOST_AUTO_TEST_CASE(CeilOperatorDerivative) } /* To the floor operator comments similar to those regarding ceil apply. */ -BOOST_AUTO_TEST_CASE(FloorOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(FloorOperatorPrimal) { double a = 4.483; adouble ad = a; @@ -1081,8 +1004,7 @@ BOOST_AUTO_TEST_CASE(FloorOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FloorOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(FloorOperatorDerivative) { double a = 4.483; adouble ad = a; @@ -1094,19 +1016,19 @@ BOOST_AUTO_TEST_CASE(FloorOperatorDerivative) BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); } -/* For the fmax and fmin operators, ADOL-C provides three different options with the - * following signatures: +/* For the fmax and fmin operators, ADOL-C provides three different options with + * the following signatures: * - * (1) adouble fmax(adouble, adouble) --> can be differentiated wrt both variables - * (2) adouble fmax(double, adouble) --> can be differentiated wrt the second variable - * (3) adouble fmax(adouble, double) --> can be differentiated wrt the first variable + * (1) adouble fmax(adouble, adouble) --> can be differentiated wrt both + * variables (2) adouble fmax(double, adouble) --> can be differentiated wrt the + * second variable (3) adouble fmax(adouble, double) --> can be differentiated + * wrt the first variable * * tests for these three are implemented separately for both primal and * derivative value. */ -BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_1) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_1) { double a = 4., b = 3.2; adouble ad = a, bd = b; @@ -1121,8 +1043,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_1) * the derivative value. Thus, the cases a > b and a = b are tested. */ -BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_1) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_1) { /* First partial derivative, a > b. */ double a1 = 4., b1 = 3.2; adouble a1d = a1, b1d = b1; @@ -1131,7 +1052,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_1) a1d.setADValue(0, 1.); adouble c1d = adtl::fmax(a1d, b1d); - + BOOST_TEST(c1d.getADValue(0) == derivative1, tt::tolerance(tol)); /* Second partial derivative, a > b. */ @@ -1142,7 +1063,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_1) b2d.setADValue(0, 1.); adouble c2d = adtl::fmax(a2d, b2d); - + BOOST_TEST(c2d.getADValue(0) == derivative2, tt::tolerance(tol)); /* Derivative for a = b, with a.ADVal < b.ADVal. */ @@ -1158,8 +1079,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_1) BOOST_TEST(c3d.getADValue(0) == derivative3, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_2) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_2) { double a = 4., b = 3.2; adouble bd = b; @@ -1175,8 +1095,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_2) * introduces 0.0 as derivative value for negative b.ADVal. */ -BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_2) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_2) { /* Case a > b. */ double a1 = 4., b1 = 3.2; adouble b1d = b1; @@ -1185,7 +1104,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_2) b1d.setADValue(0, 1.); adouble c1d = adtl::fmax(a1, b1d); - + BOOST_TEST(c1d.getADValue(0) == derivative1, tt::tolerance(tol)); /* Case a < b. */ @@ -1196,7 +1115,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_2) b2d.setADValue(0, 1.); adouble c2d = adtl::fmax(a2, b2d); - + BOOST_TEST(c2d.getADValue(0) == derivative2, tt::tolerance(tol)); /* Case a = b. */ @@ -1211,8 +1130,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_2) BOOST_TEST(c3d.getADValue(0) == derivative3, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_3) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_3) { double a = 4., b = 3.2; adouble ad = a; @@ -1226,8 +1144,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorPrimal_3) * signature fmax(double, adouble). */ -BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_3) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_3) { /* Case a > b. */ double a1 = 4., b1 = 3.2; adouble a1d = a1; @@ -1236,7 +1153,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_3) a1d.setADValue(0, 1.); adouble c1d = adtl::fmax(a1d, b1); - + BOOST_TEST(c1d.getADValue(0) == derivative1, tt::tolerance(tol)); /* Case a < b. */ @@ -1247,7 +1164,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_3) a2d.setADValue(0, 1.); adouble c2d = adtl::fmax(a2d, b2); - + BOOST_TEST(c2d.getADValue(0) == derivative2, tt::tolerance(tol)); /* Case a = b. */ @@ -1264,8 +1181,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivative_3) /* The procedure for fmin() is completely analogous to that for fmax(). */ -BOOST_AUTO_TEST_CASE(FminOperatorPrimal_1) -{ +BOOST_AUTO_TEST_CASE(FminOperatorPrimal_1) { double a = 4., b = 3.2; adouble ad = a, bd = b; @@ -1275,8 +1191,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorPrimal_1) BOOST_TEST(cd.getValue() == c, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FminOperatorDerivative_1) -{ +BOOST_AUTO_TEST_CASE(FminOperatorDerivative_1) { /* First partial derivative, a > b. */ double a1 = 4., b1 = 3.2; adouble a1d = a1, b1d = b1; @@ -1285,7 +1200,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_1) a1d.setADValue(0, 1.); adouble c1d = adtl::fmin(a1d, b1d); - + BOOST_TEST(c1d.getADValue(0) == derivative1, tt::tolerance(tol)); /* Second partial derivative, a > b. */ @@ -1296,7 +1211,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_1) b2d.setADValue(0, 1.); adouble c2d = adtl::fmin(a2d, b2d); - + BOOST_TEST(c2d.getADValue(0) == derivative2, tt::tolerance(tol)); /* Derivative for a = b, with a.ADVal < b.ADVal. */ @@ -1312,8 +1227,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_1) BOOST_TEST(c3d.getADValue(0) == derivative3, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FminOperatorPrimal_2) -{ +BOOST_AUTO_TEST_CASE(FminOperatorPrimal_2) { double a = 4., b = 3.2; adouble bd = b; @@ -1323,8 +1237,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorPrimal_2) BOOST_TEST(cd.getValue() == c, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FminOperatorDerivative_2) -{ +BOOST_AUTO_TEST_CASE(FminOperatorDerivative_2) { /* Case a > b. */ double a1 = 4., b1 = 3.2; adouble b1d = b1; @@ -1333,7 +1246,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_2) b1d.setADValue(0, 1.); adouble c1d = adtl::fmin(a1, b1d); - + BOOST_TEST(c1d.getADValue(0) == derivative1, tt::tolerance(tol)); /* Case a < b. */ @@ -1344,7 +1257,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_2) b2d.setADValue(0, 1.); adouble c2d = adtl::fmin(a2, b2d); - + BOOST_TEST(c2d.getADValue(0) == derivative2, tt::tolerance(tol)); /* Case a = b. */ @@ -1359,8 +1272,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_2) BOOST_TEST(c3d.getADValue(0) == derivative3, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FminOperatorPrimal_3) -{ +BOOST_AUTO_TEST_CASE(FminOperatorPrimal_3) { double a = 4., b = 3.2; adouble ad = a; @@ -1370,8 +1282,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorPrimal_3) BOOST_TEST(cd.getValue() == c, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FminOperatorDerivative_3) -{ +BOOST_AUTO_TEST_CASE(FminOperatorDerivative_3) { /* Case a > b. */ double a1 = 4., b1 = 3.2; adouble a1d = a1; @@ -1380,7 +1291,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_3) a1d.setADValue(0, 1.); adouble c1d = adtl::fmin(a1d, b1); - + BOOST_TEST(c1d.getADValue(0) == derivative1, tt::tolerance(tol)); /* Case a < b. */ @@ -1391,7 +1302,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_3) a2d.setADValue(0, 1.); adouble c2d = adtl::fmin(a2d, b2); - + BOOST_TEST(c2d.getADValue(0) == derivative2, tt::tolerance(tol)); /* Case a = b. */ @@ -1409,8 +1320,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivative_3) /* The error function erf(a) is defined as * 2. / sqrt(pi) * int_{0, a} (exp(- t^2))dt. */ -BOOST_AUTO_TEST_CASE(ErfOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(ErfOperatorPrimal) { double a = 7.1; adouble ad = a; @@ -1420,8 +1330,7 @@ BOOST_AUTO_TEST_CASE(ErfOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(ErfOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(ErfOperatorDerivative) { double a = 7.1; adouble ad = a; @@ -1439,8 +1348,7 @@ BOOST_AUTO_TEST_CASE(ErfOperatorDerivative) /* The complementary error function erfc(a) is defined as * 1.0 - erf(a). */ -BOOST_AUTO_TEST_CASE(ErfcOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(ErfcOperatorPrimal) { double a = 7.1; adouble ad = a; @@ -1450,8 +1358,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperatorPrimal) BOOST_TEST(ad.getValue() == a, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(ErfcOperatorDerivative) -{ +BOOST_AUTO_TEST_CASE(ErfcOperatorDerivative) { double a = 7.1; adouble ad = a; @@ -1468,8 +1375,7 @@ BOOST_AUTO_TEST_CASE(ErfcOperatorDerivative) /* Test the primitive non-temporary operations =, +=, -=, *=, /=. */ -BOOST_AUTO_TEST_CASE(EqOperatorPrimal_Derivative) -{ +BOOST_AUTO_TEST_CASE(EqOperatorPrimal_Derivative) { double a = 10.01; adouble ad = a; @@ -1488,8 +1394,7 @@ BOOST_AUTO_TEST_CASE(EqOperatorPrimal_Derivative) BOOST_TEST(ad.getADValue(0) == bd.getADValue(0), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqPlusOperatorPrimal_Derivative) -{ +BOOST_AUTO_TEST_CASE(EqPlusOperatorPrimal_Derivative) { double a = 5.132; adouble ad = a; @@ -1511,8 +1416,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperatorPrimal_Derivative) BOOST_TEST(ad.getADValue(0) == ADValue, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqMinusOperatorPrimal_Derivative) -{ +BOOST_AUTO_TEST_CASE(EqMinusOperatorPrimal_Derivative) { double a = 5.132; adouble ad = a; @@ -1534,8 +1438,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperatorPrimal_Derivative) BOOST_TEST(ad.getADValue(0) == ADValue, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqTimesOperatorPrimal_Derivative) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperatorPrimal_Derivative) { double a = 5.132; adouble ad = a; @@ -1552,13 +1455,12 @@ BOOST_AUTO_TEST_CASE(EqTimesOperatorPrimal_Derivative) ad *= bd; double Value = (5.132 * 5.2 * 1.1); - double ADValue = (2.1*5.2*1.1) + (5.132*5.2*11.1); + double ADValue = (2.1 * 5.2 * 1.1) + (5.132 * 5.2 * 11.1); BOOST_TEST(ad.getValue() == Value, tt::tolerance(tol)); BOOST_TEST(ad.getADValue(0) == ADValue, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqDivOperatorPrimal_Derivative) -{ +BOOST_AUTO_TEST_CASE(EqDivOperatorPrimal_Derivative) { double a = 5.132; adouble ad = a; @@ -1575,21 +1477,19 @@ BOOST_AUTO_TEST_CASE(EqDivOperatorPrimal_Derivative) ad /= bd; double Value = ((5.132 / 5.2) / 1.1); - double ADValue = (2.1/5.2)/1.1 - (5.132/5.2)*11.1/(1.1*1.1); + double ADValue = (2.1 / 5.2) / 1.1 - (5.132 / 5.2) * 11.1 / (1.1 * 1.1); BOOST_TEST(ad.getValue() == Value, tt::tolerance(tol)); BOOST_TEST(ad.getADValue(0) == ADValue, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(NotOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(NotOperatorPrimal) { double a = 1.0; adouble ad = a; BOOST_TEST(!a == 0.0, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompNeqOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CompNeqOperatorPrimal) { double a = 1.5, b = 0.5; adouble ad = a, bd = b; @@ -1604,8 +1504,7 @@ BOOST_AUTO_TEST_CASE(CompNeqOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompEqOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CompEqOperatorPrimal) { double a = 0.5, b = 1.5; adouble ad = a, bd = b; @@ -1620,8 +1519,7 @@ BOOST_AUTO_TEST_CASE(CompEqOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompLeqOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CompLeqOperatorPrimal) { double a = 1.0, b = 0.99; adouble ad = a, bd = b; @@ -1636,8 +1534,7 @@ BOOST_AUTO_TEST_CASE(CompLeqOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompGeqOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CompGeqOperatorPrimal) { double a = 1.2, b = 2.5; adouble ad = a, bd = b; @@ -1652,8 +1549,7 @@ BOOST_AUTO_TEST_CASE(CompGeqOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompLeOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CompLeOperatorPrimal) { double a = 1.1, b = 1.1; adouble ad = a, bd = b; @@ -1668,8 +1564,7 @@ BOOST_AUTO_TEST_CASE(CompLeOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CompGeOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CompGeOperatorPrimal) { double a = 1.7, b = 7.5; adouble ad = a, bd = b; @@ -1684,8 +1579,7 @@ BOOST_AUTO_TEST_CASE(CompGeOperatorPrimal) BOOST_TEST(k == l, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CondassignOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CondassignOperatorPrimal) { adouble cond = 1., arg1 = 3.5, arg2 = 5.3; adouble p; @@ -1698,8 +1592,7 @@ BOOST_AUTO_TEST_CASE(CondassignOperatorPrimal) BOOST_TEST(p.getADValue(0) == arg1.getADValue(0), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CondeqassignOperatorPrimal) -{ +BOOST_AUTO_TEST_CASE(CondeqassignOperatorPrimal) { adouble cond = 0., arg1 = 3.5, arg2 = 5.3; adouble p; @@ -1712,9 +1605,4 @@ BOOST_AUTO_TEST_CASE(CondeqassignOperatorPrimal) BOOST_TEST(p.getADValue(0) == arg1.getADValue(0), tt::tolerance(tol)); } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/ADOL-C/boost-test/tracelessOperatorVector.cpp b/ADOL-C/boost-test/tracelessOperatorVector.cpp index e060098b9..2bda93443 100644 --- a/ADOL-C/boost-test/tracelessOperatorVector.cpp +++ b/ADOL-C/boost-test/tracelessOperatorVector.cpp @@ -11,40 +11,37 @@ typedef adtl::adouble adouble; #include "const.h" -BOOST_AUTO_TEST_SUITE( traceless_vector ) - +BOOST_AUTO_TEST_SUITE(traceless_vector) /***********************************/ /* Tests for traceless vector mode */ /* Author: Philipp Schuette */ /***********************************/ - /* For consistency, the primitive traceless mode functions of ADOL-C * are tested in vector mode in the same order as in scalar mode. For * implementation details, please refer to the scalar mode tests. */ -BOOST_AUTO_TEST_CASE(ExpOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(ExpOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 2.; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*2.); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 2.); } double aDerivative = std::exp(a); ad = adtl::exp(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*2.), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 2.), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(MultOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(MultOperatorDerivativeVectorMode) { double a = 2.5, b = 4.; adouble ad = a, bd = b; @@ -60,8 +57,7 @@ BOOST_AUTO_TEST_CASE(MultOperatorDerivativeVectorMode) BOOST_TEST(cd.getADValue(1) == bDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(AddOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(AddOperatorDerivativeVectorMode) { double a = 1.2, b = 2.1; adouble ad = a, bd = b; @@ -77,8 +73,7 @@ BOOST_AUTO_TEST_CASE(AddOperatorDerivativeVectorMode) BOOST_TEST(cd.getADValue(1) == bDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(SubOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(SubOperatorDerivativeVectorMode) { double a = 3.2, b = 1.5; adouble ad = a, bd = b; @@ -94,8 +89,7 @@ BOOST_AUTO_TEST_CASE(SubOperatorDerivativeVectorMode) BOOST_TEST(cd.getADValue(1) == bDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(DivOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(DivOperatorDerivativeVectorMode) { double a = 0.6, b = 4.4; adouble ad = a, bd = b; @@ -103,7 +97,7 @@ BOOST_AUTO_TEST_CASE(DivOperatorDerivativeVectorMode) bd.setADValue(1, 1.); double aDerivative = 1. / b; - double bDerivative = -a / (b*b); + double bDerivative = -a / (b * b); adouble cd = ad / bd; @@ -111,361 +105,360 @@ BOOST_AUTO_TEST_CASE(DivOperatorDerivativeVectorMode) BOOST_TEST(cd.getADValue(1) == bDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(TanOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(TanOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 0.8; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*1.1); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 1.1); } a = std::tan(a); - double aDerivative = 1 + a*a; + double aDerivative = 1 + a * a; ad = adtl::tan(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*1.1), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 1.1), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(SinOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(SinOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 0.72; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*(-1.1)); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * (-1.1)); } double aDerivative = std::cos(a); ad = adtl::sin(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*(-1.1)), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * (-1.1)), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(CosOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(CosOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = -1.12; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*3.2); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 3.2); } double aDerivative = -std::sin(a); ad = adtl::cos(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*3.2), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 3.2), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(SqrtOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(SqrtOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 6.1; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*0.8); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 0.8); } - double aDerivative = 1. / (2*std::sqrt(a)); + double aDerivative = 1. / (2 * std::sqrt(a)); ad = adtl::sqrt(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*0.8), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 0.8), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(LogOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(LogOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 9.4; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. - j*0.7); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. - j * 0.7); } double aDerivative = 1. / a; ad = adtl::log(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. - j*0.7), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. - j * 0.7), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(SinhOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(SinhOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 40.; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*1.5); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 1.5); } double aDerivative = std::cosh(a); ad = adtl::sinh(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*1.5), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 1.5), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(CoshOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(CoshOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 40.; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*1.5); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 1.5); } double aDerivative = std::sinh(a); ad = adtl::cosh(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*1.5), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 1.5), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(TanhOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(TanhOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 40.0; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*1.5); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 1.5); } a = std::tanh(a); - double aDerivative = 1. - a*a; + double aDerivative = 1. - a * a; ad = adtl::tanh(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*1.5), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 1.5), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(AsinOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(AsinOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 0.91; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. - j*8.0); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. - j * 8.0); } - double aDerivative = 1. / (std::sqrt(1. - a*a)); + double aDerivative = 1. / (std::sqrt(1. - a * a)); ad = adtl::asin(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. - j*8.0), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. - j * 8.0), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(AcosOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(AcosOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 0.35; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*0.6); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 0.6); } - double aDerivative = -1. / (std::sqrt(1. - a*a)); + double aDerivative = -1. / (std::sqrt(1. - a * a)); ad = adtl::acos(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*0.6), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 0.6), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(AtanOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(AtanOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 16.3; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*0.5); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 0.5); } - double aDerivative = 1. / (1. + a*a); + double aDerivative = 1. / (1. + a * a); ad = adtl::atan(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*0.5), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 0.5), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(Log10OperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(Log10OperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 13.2; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. - j*1.8); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. - j * 1.8); } double aDerivative = 1. / (a * std::log(10)); ad = adtl::log10(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. - j*1.8), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. - j * 1.8), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(AsinhOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(AsinhOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 1.6; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*0.6); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 0.6); } - double aDerivative = 1. / (std::sqrt(a*a + 1.)); + double aDerivative = 1. / (std::sqrt(a * a + 1.)); ad = adtl::asinh(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*0.6), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 0.6), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(AcoshOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(AcoshOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 1.7; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. - j*2.1); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. - j * 2.1); } - double aDerivative = 1. / (std::sqrt(a*a - 1.)); + double aDerivative = 1. / (std::sqrt(a * a - 1.)); ad = adtl::acosh(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. - j*2.1), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. - j * 2.1), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(AtanhOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(AtanhOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 0.75; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*1.3); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 1.3); } - double aDerivative = 1. / (1. - a*a); + double aDerivative = 1. / (1. - a * a); ad = adtl::atanh(ad); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*1.3), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 1.3), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(InclOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(InclOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 5.5; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*1.); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 1.); } double aDerivative = 1.; ad = ++ad; - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*1.), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 1.), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(DeclOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(DeclOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 5.; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*1.5); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 1.5); } double aDerivative = 1.; ad = --ad; - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*1.5), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 1.5), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(SignPlusOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(SignPlusOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 1.6; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. - j*0.4); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. - j * 0.4); } double aDerivative = 1.; ad = +ad; - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. - j*0.4), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. - j * 0.4), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(SignMinusOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(SignMinusOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 1.6; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*0.25); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 0.25); } double aDerivative = -1.; ad = -ad; - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*0.25), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 0.25), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeVectorMode) { double a = 13.2, b = 1.2; adouble ad = a, bd = b; ad.setADValue(0, 1.); bd.setADValue(1, 1.); - double aDerivative = b / (a*a + b*b); - double bDerivative = -a / (a*a + b*b); + double aDerivative = b / (a * a + b * b); + double bDerivative = -a / (a * a + b * b); adouble cd = adtl::atan2(ad, bd); @@ -473,26 +466,25 @@ BOOST_AUTO_TEST_CASE(Atan2OperatorDerivativeVectorMode) BOOST_TEST(cd.getADValue(1) == bDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PowOperatorDerivativeVectorMode_1) -{ +BOOST_AUTO_TEST_CASE(PowOperatorDerivativeVectorMode_1) { const size_t numDir = adtl::getNumDir(); double a = 2.3, e = 5.3; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. - j*0.35); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. - j * 0.35); } double aDerivative = e * std::pow(a, e - 1.); ad = adtl::pow(ad, e); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. - j*0.35), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. - j * 0.35), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(PowOperatorDerivativeVectorMode_2) -{ +BOOST_AUTO_TEST_CASE(PowOperatorDerivativeVectorMode_2) { double a = 2.3, e = 5.3; adouble ad = a, ed = e; @@ -508,28 +500,27 @@ BOOST_AUTO_TEST_CASE(PowOperatorDerivativeVectorMode_2) BOOST_TEST(cd.getADValue(1) == eDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(PowOperatorDerivativeVectorMode_3) -{ +BOOST_AUTO_TEST_CASE(PowOperatorDerivativeVectorMode_3) { const size_t numDir = adtl::getNumDir(); double a = 2.3, e = 5.3; adouble ed = e; - for(size_t j = 0; j < numDir; j++) { - ed.setADValue(j, 1. - j*0.35); + for (size_t j = 0; j < numDir; j++) { + ed.setADValue(j, 1. - j * 0.35); } double eDerivative = std::log(a) * std::pow(a, e); ed = adtl::pow(a, ed); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ed.getADValue(j) == eDerivative*(1. - j*0.35), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ed.getADValue(j) == eDerivative * (1. - j * 0.35), + tt::tolerance(tol)); } } /* Frexp is not differentiable and so does not need to be tested. */ -BOOST_AUTO_TEST_CASE(LdexpOperatorDerivativeVectorMode_1) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorDerivativeVectorMode_1) { double a = 3., b = 4.; adouble ad = a, bd = b; @@ -545,53 +536,52 @@ BOOST_AUTO_TEST_CASE(LdexpOperatorDerivativeVectorMode_1) BOOST_TEST(cd.getADValue(1) == bDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(LdexpOperatorDerivativeVectorMode_2) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorDerivativeVectorMode_2) { const size_t numDir = adtl::getNumDir(); double a = 3., b = 4.; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + j*1.); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + j * 1.); } double aDerivative = std::pow(2., b); ad = adtl::ldexp(ad, b); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + j*1.), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + j * 1.), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(LdexpOperatorDerivativeVectorMode_3) -{ +BOOST_AUTO_TEST_CASE(LdexpOperatorDerivativeVectorMode_3) { const size_t numDir = adtl::getNumDir(); double a = 3., b = 4.; adouble bd = b; - for(size_t j = 0; j < numDir; j++) { - bd.setADValue(j, 1. - j*1.); + for (size_t j = 0; j < numDir; j++) { + bd.setADValue(j, 1. - j * 1.); } double bDerivative = a * std::log(2.) * std::pow(2., b); bd = adtl::ldexp(a, bd); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(bd.getADValue(j) == bDerivative*(1. - j*1.), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(bd.getADValue(j) == bDerivative * (1. - j * 1.), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeVectorMode_NonZero) -{ +BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeVectorMode_NonZero) { const size_t numDir = adtl::getNumDir(); double a = 1.4, b = -5.; adouble ad = a, bd = b; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, 1. + std::pow(2., j)); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, 1. + std::pow(2., j)); } - for(size_t j = 0; j < numDir; j++) { - bd.setADValue(j, 1. + std::pow(3., j)); + for (size_t j = 0; j < numDir; j++) { + bd.setADValue(j, 1. + std::pow(3., j)); } double aDerivative = 1.; @@ -600,16 +590,17 @@ BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeVectorMode_NonZero) ad = adtl::fabs(ad); bd = adtl::fabs(bd); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative*(1. + std::pow(2., j)), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative * (1. + std::pow(2., j)), + tt::tolerance(tol)); } - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(bd.getADValue(j) == bDerivative*(1. + std::pow(3., j)), tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(bd.getADValue(j) == bDerivative * (1. + std::pow(3., j)), + tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeVectorMode_AtZero) -{ +BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeVectorMode_AtZero) { double c = 0.; adouble cd = c; @@ -622,47 +613,44 @@ BOOST_AUTO_TEST_CASE(FabsOperatorDerivativeVectorMode_AtZero) cd = adtl::fabs(cd); BOOST_TEST(cd.getADValue(0) == posDerivative, tt::tolerance(tol)); - BOOST_TEST(cd.getADValue(1) == negDerivative, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(1) == negDerivative, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CeilOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(CeilOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 4.617; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, std::pow(j, 10.)); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, std::pow(j, 10.)); } double aDerivative = 0.; ad = adtl::ceil(ad); - for(size_t j = 0; j < numDir; j++) { + for (size_t j = 0; j < numDir; j++) { BOOST_TEST(ad.getADValue(j) == aDerivative, tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(FloorOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(FloorOperatorDerivativeVectorMode) { const size_t numDir = adtl::getNumDir(); double a = 9.989; adouble ad = a; - for(size_t j = 0; j < numDir; j++) { - ad.setADValue(j, std::pow(j, 5.5)); + for (size_t j = 0; j < numDir; j++) { + ad.setADValue(j, std::pow(j, 5.5)); } double aDerivative = 0.; ad = adtl::floor(ad); - for(size_t j = 0; j < numDir; j++) { + for (size_t j = 0; j < numDir; j++) { BOOST_TEST(ad.getADValue(j) == aDerivative, tt::tolerance(tol)); } } -BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_1) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_1) { /* Derivative for a proper maximum of two input values. */ double a = 4., b = 3.2; adouble ad = a, bd = b; @@ -674,7 +662,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_1) bd.setADValue(1, 1.); adouble cd = adtl::fmax(ad, bd); - + BOOST_TEST(cd.getADValue(0) == aDerivative, tt::tolerance(tol)); BOOST_TEST(cd.getADValue(1) == bDerivative, tt::tolerance(tol)); @@ -695,8 +683,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_1) BOOST_TEST(ed.getADValue(1) == Derivative2, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_2) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_2) { /* Derivative for a proper maximum of two input values. */ double a = 4., b = 3.2; adouble bd = b; @@ -707,9 +694,9 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_2) bd.setADValue(1, 3.21); adouble cd = adtl::fmax(a, bd); - - BOOST_TEST(cd.getADValue(0) == bDerivative*1.0, tt::tolerance(tol)); - BOOST_TEST(cd.getADValue(1) == bDerivative*3.21, tt::tolerance(tol)); + + BOOST_TEST(cd.getADValue(0) == bDerivative * 1.0, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(1) == bDerivative * 3.21, tt::tolerance(tol)); /* Derivative for equal input values. */ a = 2.5, b = 2.5; @@ -726,8 +713,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_2) BOOST_TEST(ed.getADValue(1) == Derivative2, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_3) -{ +BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_3) { /* Derivative for a proper maximum of two input values. */ double a = 4., b = 3.2; adouble ad = a; @@ -738,9 +724,9 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_3) ad.setADValue(1, 3.21); adouble cd = adtl::fmax(ad, b); - - BOOST_TEST(cd.getADValue(0) == aDerivative*1.0, tt::tolerance(tol)); - BOOST_TEST(cd.getADValue(1) == aDerivative*3.21, tt::tolerance(tol)); + + BOOST_TEST(cd.getADValue(0) == aDerivative * 1.0, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(1) == aDerivative * 3.21, tt::tolerance(tol)); /* Derivative for equal input values. */ a = 2.5, b = 2.5; @@ -757,8 +743,7 @@ BOOST_AUTO_TEST_CASE(FmaxOperatorDerivativeVectorMode_3) BOOST_TEST(ed.getADValue(1) == Derivative2, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_1) -{ +BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_1) { /* Derivative for a proper minimum of two input values. */ double a = 4., b = 3.2; adouble ad = a, bd = b; @@ -770,7 +755,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_1) bd.setADValue(1, 1.); adouble cd = adtl::fmin(ad, bd); - + BOOST_TEST(cd.getADValue(0) == aDerivative, tt::tolerance(tol)); BOOST_TEST(cd.getADValue(1) == bDerivative, tt::tolerance(tol)); @@ -791,8 +776,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_1) BOOST_TEST(ed.getADValue(1) == Derivative2, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_2) -{ +BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_2) { /* Derivative for a proper minimum of two input values. */ double a = 4., b = 3.2; adouble bd = b; @@ -803,9 +787,9 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_2) bd.setADValue(1, 3.21); adouble cd = adtl::fmin(a, bd); - - BOOST_TEST(cd.getADValue(0) == bDerivative*1.0, tt::tolerance(tol)); - BOOST_TEST(cd.getADValue(1) == bDerivative*3.21, tt::tolerance(tol)); + + BOOST_TEST(cd.getADValue(0) == bDerivative * 1.0, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(1) == bDerivative * 3.21, tt::tolerance(tol)); /* Derivative for equal input values. */ a = 2.5, b = 2.5; @@ -822,8 +806,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_2) BOOST_TEST(ed.getADValue(1) == Derivative2, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_3) -{ +BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_3) { /* Derivative for a proper minimum of two input values. */ double a = 4., b = 3.2; adouble ad = a; @@ -834,9 +817,9 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_3) ad.setADValue(1, 3.21); adouble cd = adtl::fmin(ad, b); - - BOOST_TEST(cd.getADValue(0) == aDerivative*1.0, tt::tolerance(tol)); - BOOST_TEST(cd.getADValue(1) == aDerivative*3.21, tt::tolerance(tol)); + + BOOST_TEST(cd.getADValue(0) == aDerivative * 1.0, tt::tolerance(tol)); + BOOST_TEST(cd.getADValue(1) == aDerivative * 3.21, tt::tolerance(tol)); /* Derivative for equal input values. */ a = 2.5, b = 2.5; @@ -853,8 +836,7 @@ BOOST_AUTO_TEST_CASE(FminOperatorDerivativeVectorMode_3) BOOST_TEST(ed.getADValue(1) == Derivative2, tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(ErfOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(ErfOperatorDerivativeVectorMode) { double a = 7.1; adouble ad = a; @@ -865,11 +847,10 @@ BOOST_AUTO_TEST_CASE(ErfOperatorDerivativeVectorMode) ad = adtl::erf(ad); BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); - BOOST_TEST(ad.getADValue(1) == aDerivative*(-2.5), tt::tolerance(tol)); + BOOST_TEST(ad.getADValue(1) == aDerivative * (-2.5), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(ErfcOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(ErfcOperatorDerivativeVectorMode) { double a = 7.1; adouble ad = a; @@ -880,11 +861,10 @@ BOOST_AUTO_TEST_CASE(ErfcOperatorDerivativeVectorMode) ad = adtl::erfc(ad); BOOST_TEST(ad.getADValue(0) == aDerivative, tt::tolerance(tol)); - BOOST_TEST(ad.getADValue(1) == aDerivative*(-2.5), tt::tolerance(tol)); + BOOST_TEST(ad.getADValue(1) == aDerivative * (-2.5), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(EqOperatorDerivativeVectorMode) { double a = 10.01; adouble ad = a; @@ -903,8 +883,7 @@ BOOST_AUTO_TEST_CASE(EqOperatorDerivativeVectorMode) BOOST_TEST(ad.getADValue(1) == bd.getADValue(1), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqPlusOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(EqPlusOperatorDerivativeVectorMode) { double a = 5.132; adouble ad = a; @@ -925,8 +904,7 @@ BOOST_AUTO_TEST_CASE(EqPlusOperatorDerivativeVectorMode) BOOST_TEST(ad.getADValue(1) == (2.1 - 2.6), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqMinusOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(EqMinusOperatorDerivativeVectorMode) { double a = 5.132; adouble ad = a; @@ -947,8 +925,7 @@ BOOST_AUTO_TEST_CASE(EqMinusOperatorDerivativeVectorMode) BOOST_TEST(ad.getADValue(1) == (2.1 - (-2.6)), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqTimesOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(EqTimesOperatorDerivativeVectorMode) { double a = 5.132; adouble ad = a; @@ -965,12 +942,13 @@ BOOST_AUTO_TEST_CASE(EqTimesOperatorDerivativeVectorMode) bd.setADValue(1, -2.1); ad *= bd; - BOOST_TEST(ad.getADValue(0) == (5.132*5.2*11.1 + 1.1*5.2*1.0), tt::tolerance(tol)); - BOOST_TEST(ad.getADValue(1) == (5.132*5.2*(-2.1) + 1.1*5.2*(-7.1)), tt::tolerance(tol)); + BOOST_TEST(ad.getADValue(0) == (5.132 * 5.2 * 11.1 + 1.1 * 5.2 * 1.0), + tt::tolerance(tol)); + BOOST_TEST(ad.getADValue(1) == (5.132 * 5.2 * (-2.1) + 1.1 * 5.2 * (-7.1)), + tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(EqDivOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(EqDivOperatorDerivativeVectorMode) { double a = 5.132; adouble ad = a; @@ -988,18 +966,20 @@ BOOST_AUTO_TEST_CASE(EqDivOperatorDerivativeVectorMode) bd.setADValue(1, 11.1); ad /= bd; - double Derivative1 = (1.0/1.1)*(1.0/5.2) - (5.132/(5.2*1.1*1.1)*1.0); - double Derivative2 = (1.0/1.1)*(-2.1/5.2) - (5.132/(5.2*1.1*1.1)*11.1); + double Derivative1 = + (1.0 / 1.1) * (1.0 / 5.2) - (5.132 / (5.2 * 1.1 * 1.1) * 1.0); + double Derivative2 = + (1.0 / 1.1) * (-2.1 / 5.2) - (5.132 / (5.2 * 1.1 * 1.1) * 11.1); BOOST_TEST(ad.getADValue(0) == Derivative1, tt::tolerance(tol)); BOOST_TEST(ad.getADValue(1) == Derivative2, tt::tolerance(tol)); } -/* The not, neq and eq comparison operators have no effect on the derivatives, so - * the scalar tests suffice for them. The same holds for leq, geq, greater and less. +/* The not, neq and eq comparison operators have no effect on the derivatives, + * so the scalar tests suffice for them. The same holds for leq, geq, greater + * and less. */ -BOOST_AUTO_TEST_CASE(CondassignOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(CondassignOperatorDerivativeVectorMode) { adouble cond = 1., arg1 = 3.5, arg2 = 5.3; adouble p; @@ -1014,8 +994,7 @@ BOOST_AUTO_TEST_CASE(CondassignOperatorDerivativeVectorMode) BOOST_TEST(p.getADValue(1) == arg1.getADValue(1), tt::tolerance(tol)); } -BOOST_AUTO_TEST_CASE(CondeqassignOperatorDerivativeVectorMode) -{ +BOOST_AUTO_TEST_CASE(CondeqassignOperatorDerivativeVectorMode) { adouble cond = 1., arg1 = 3.5, arg2 = 5.3; adouble p; @@ -1031,26 +1010,20 @@ BOOST_AUTO_TEST_CASE(CondeqassignOperatorDerivativeVectorMode) } /* Test the derivative value assignment by pointer. */ -BOOST_AUTO_TEST_CASE(SetADValueOperatorVectorMode) -{ +BOOST_AUTO_TEST_CASE(SetADValueOperatorVectorMode) { const size_t numDir = adtl::getNumDir(); adouble ad = 0.0; std::vector aDerivative(numDir); - for(size_t i = 0; i < numDir; i++) { - aDerivative[i] = 1.0 + std::exp(10*i)*std::sqrt(2.5*i); + for (size_t i = 0; i < numDir; i++) { + aDerivative[i] = 1.0 + std::exp(10 * i) * std::sqrt(2.5 * i); } ad.setADValue(aDerivative.data()); - for(size_t j = 0; j < numDir; j++) { - BOOST_TEST(ad.getADValue(j) == aDerivative[j], tt::tolerance(tol)); + for (size_t j = 0; j < numDir; j++) { + BOOST_TEST(ad.getADValue(j) == aDerivative[j], tt::tolerance(tol)); } } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/ADOL-C/c_interface/ADOLC_TB_interface.cpp b/ADOL-C/c_interface/ADOLC_TB_interface.cpp index 6dfcea24f..6f243cc14 100644 --- a/ADOL-C/c_interface/ADOLC_TB_interface.cpp +++ b/ADOL-C/c_interface/ADOLC_TB_interface.cpp @@ -1,315 +1,231 @@ -#include #include "ADOLC_TB_interface.h" +#include /* Constructor & Destructor for class tape-based adouble */ -extern "C" -{ - TBAdoubleHandle create_tb_adouble(const double x) - { - return new adouble(x); - } - TBAdoubleHandle create_tb_adouble_empty() - { - return new adouble(); - } +extern "C" { +TBAdoubleHandle create_tb_adouble(const double x) { return new adouble(x); } +TBAdoubleHandle create_tb_adouble_empty() { return new adouble(); } - void free_tb_adouble(TBAdoubleHandle a) - { - return delete static_cast(a); - } +void free_tb_adouble(TBAdoubleHandle a) { + return delete static_cast(a); +} } /* Utilities for adouble */ -extern "C" -{ - double get_tb_value(TBAdoubleHandle a) - { - return static_cast(a)->getValue(); - } +extern "C" { +double get_tb_value(TBAdoubleHandle a) { + return static_cast(a)->getValue(); +} } /* Arithmetics for class adouble */ -extern "C" -{ - TBAdoubleHandle add_tb_adouble(const TBAdoubleHandle a, const TBAdoubleHandle b) - { - return new adouble(*static_cast(a) + *static_cast(b)); - } - TBAdoubleHandle add_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return new adouble(x + *static_cast(b)); - } - TBAdoubleHandle add_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return new adouble(*static_cast(a) + x); - } - TBAdoubleHandle mult_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return new adouble(*static_cast(a) * *static_cast(b)); - } - TBAdoubleHandle mult_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return new adouble(x * *static_cast(b)); - } - TBAdoubleHandle mult_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return new adouble(*static_cast(a) * x); - } - TBAdoubleHandle subtr_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return new adouble(*static_cast(a) - *static_cast(b)); - } - TBAdoubleHandle subtr_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return new adouble(x - *static_cast(b)); - } - TBAdoubleHandle subtr_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return new adouble(*static_cast(a) - x); - } - TBAdoubleHandle div_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return new adouble(*static_cast(a) / *static_cast(b)); - } - TBAdoubleHandle div_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return new adouble(x / *static_cast(b)); - } - TBAdoubleHandle div_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return new adouble(*static_cast(a) / x); - } - TBAdoubleHandle max_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return new adouble(fmax(*static_cast(a), *static_cast(b))); - } - TBAdoubleHandle max_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return new adouble(fmax(x, *static_cast(b))); - } - TBAdoubleHandle max_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return new adouble(fmax(*static_cast(a), x)); - } - TBAdoubleHandle min_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return new adouble(fmin(*static_cast(a), *static_cast(b))); - } - TBAdoubleHandle min_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return new adouble(fmin(x, *static_cast(b))); - } - TBAdoubleHandle min_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return new adouble(fmin(*static_cast(a), x)); - } - TBAdoubleHandle pow_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return new adouble(pow(*static_cast(a), *static_cast(b))); - } - TBAdoubleHandle pow_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return new adouble(pow(*static_cast(a), x)); - } - bool ge_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return *static_cast(a) >= *static_cast(b); - } - bool ge_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return x >= *static_cast(b); - } - bool ge_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return *static_cast(a) >= x; - } - bool g_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return *static_cast(a) > *static_cast(b); - } - bool g_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return x > *static_cast(b); - } - bool g_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return *static_cast(a) > x; - } - bool le_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return *static_cast(a) <= *static_cast(b); - } - bool le_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return x <= *static_cast(b); - } - bool le_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return *static_cast(a) <= x; - } - bool l_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return *static_cast(a) < *static_cast(b); - } - bool l_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return x < *static_cast(b); - } - bool l_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return *static_cast(a) < x; - } - bool eq_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) - { - return *static_cast(a) == *static_cast(b); - } - bool eq_double_tb_adouble(const double x, TBAdoubleHandle b) - { - return x == *static_cast(b); - } - bool eq_tb_adouble_double(TBAdoubleHandle a, const double x) - { - return *static_cast(a) == x; - } - TBAdoubleHandle tb_abs(TBAdoubleHandle a) - { - return new adouble(fabs(*static_cast(a))); - } - TBAdoubleHandle tb_sqrt(TBAdoubleHandle a) - { - return new adouble(sqrt(*static_cast(a))); - } - TBAdoubleHandle tb_log(TBAdoubleHandle a) - { - return new adouble(log(*static_cast(a))); - } - TBAdoubleHandle tb_log10(TBAdoubleHandle a) - { - return new adouble(log10(*static_cast(a))); - } - TBAdoubleHandle tb_sin(TBAdoubleHandle a) - { - return new adouble(sin(*static_cast(a))); - } - TBAdoubleHandle tb_cos(TBAdoubleHandle a) - { - return new adouble(cos(*static_cast(a))); - } - TBAdoubleHandle tb_tan(TBAdoubleHandle a) - { - return new adouble(tan(*static_cast(a))); - } - TBAdoubleHandle tb_exp(TBAdoubleHandle a) - { - return new adouble(exp(*static_cast(a))); - } - TBAdoubleHandle tb_asin(TBAdoubleHandle a) - { - return new adouble(asin(*static_cast(a))); - } - TBAdoubleHandle tb_acos(TBAdoubleHandle a) - { - return new adouble(acos(*static_cast(a))); - } - TBAdoubleHandle tb_atan(TBAdoubleHandle a) - { - return new adouble(atan(*static_cast(a))); - } - TBAdoubleHandle tb_sinh(TBAdoubleHandle a) - { - return new adouble(sinh(*static_cast(a))); - } - TBAdoubleHandle tb_cosh(TBAdoubleHandle a) - { - return new adouble(cosh(*static_cast(a))); - } - TBAdoubleHandle tb_tanh(TBAdoubleHandle a) - { - return new adouble(tanh(*static_cast(a))); - } - TBAdoubleHandle tb_asinh(TBAdoubleHandle a) - { - return new adouble(asinh(*static_cast(a))); - } - TBAdoubleHandle tb_acosh(TBAdoubleHandle a) - { - return new adouble(acosh(*static_cast(a))); - } - TBAdoubleHandle tb_atanh(TBAdoubleHandle a) - { - return new adouble(atanh(*static_cast(a))); - } - TBAdoubleHandle tb_ceil(TBAdoubleHandle a) - { - return new adouble(ceil(*static_cast(a))); - } - TBAdoubleHandle tb_floor(TBAdoubleHandle a) - { - return new adouble(floor(*static_cast(a))); - } - TBAdoubleHandle tb_ldexp(TBAdoubleHandle a, const int n) - { - return new adouble(ldexp(*static_cast(a), n)); - } - TBAdoubleHandle tb_erf(TBAdoubleHandle a) - { - return new adouble(erf(*static_cast(a))); - } - TBAdoubleHandle tb_erfc(TBAdoubleHandle a) - { - return new adouble(erfc(*static_cast(a))); - } +extern "C" { +TBAdoubleHandle add_tb_adouble(const TBAdoubleHandle a, + const TBAdoubleHandle b) { + return new adouble(*static_cast(a) + *static_cast(b)); +} +TBAdoubleHandle add_double_tb_adouble(const double x, TBAdoubleHandle b) { + return new adouble(x + *static_cast(b)); +} +TBAdoubleHandle add_tb_adouble_double(TBAdoubleHandle a, const double x) { + return new adouble(*static_cast(a) + x); +} +TBAdoubleHandle mult_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return new adouble(*static_cast(a) * *static_cast(b)); +} +TBAdoubleHandle mult_double_tb_adouble(const double x, TBAdoubleHandle b) { + return new adouble(x * *static_cast(b)); +} +TBAdoubleHandle mult_tb_adouble_double(TBAdoubleHandle a, const double x) { + return new adouble(*static_cast(a) * x); +} +TBAdoubleHandle subtr_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return new adouble(*static_cast(a) - *static_cast(b)); +} +TBAdoubleHandle subtr_double_tb_adouble(const double x, TBAdoubleHandle b) { + return new adouble(x - *static_cast(b)); +} +TBAdoubleHandle subtr_tb_adouble_double(TBAdoubleHandle a, const double x) { + return new adouble(*static_cast(a) - x); +} +TBAdoubleHandle div_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return new adouble(*static_cast(a) / *static_cast(b)); +} +TBAdoubleHandle div_double_tb_adouble(const double x, TBAdoubleHandle b) { + return new adouble(x / *static_cast(b)); +} +TBAdoubleHandle div_tb_adouble_double(TBAdoubleHandle a, const double x) { + return new adouble(*static_cast(a) / x); +} +TBAdoubleHandle max_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return new adouble( + fmax(*static_cast(a), *static_cast(b))); +} +TBAdoubleHandle max_double_tb_adouble(const double x, TBAdoubleHandle b) { + return new adouble(fmax(x, *static_cast(b))); +} +TBAdoubleHandle max_tb_adouble_double(TBAdoubleHandle a, const double x) { + return new adouble(fmax(*static_cast(a), x)); +} +TBAdoubleHandle min_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return new adouble( + fmin(*static_cast(a), *static_cast(b))); +} +TBAdoubleHandle min_double_tb_adouble(const double x, TBAdoubleHandle b) { + return new adouble(fmin(x, *static_cast(b))); +} +TBAdoubleHandle min_tb_adouble_double(TBAdoubleHandle a, const double x) { + return new adouble(fmin(*static_cast(a), x)); +} +TBAdoubleHandle pow_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return new adouble( + pow(*static_cast(a), *static_cast(b))); +} +TBAdoubleHandle pow_tb_adouble_double(TBAdoubleHandle a, const double x) { + return new adouble(pow(*static_cast(a), x)); +} +bool ge_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return *static_cast(a) >= *static_cast(b); +} +bool ge_double_tb_adouble(const double x, TBAdoubleHandle b) { + return x >= *static_cast(b); +} +bool ge_tb_adouble_double(TBAdoubleHandle a, const double x) { + return *static_cast(a) >= x; +} +bool g_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return *static_cast(a) > *static_cast(b); +} +bool g_double_tb_adouble(const double x, TBAdoubleHandle b) { + return x > *static_cast(b); +} +bool g_tb_adouble_double(TBAdoubleHandle a, const double x) { + return *static_cast(a) > x; +} +bool le_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return *static_cast(a) <= *static_cast(b); +} +bool le_double_tb_adouble(const double x, TBAdoubleHandle b) { + return x <= *static_cast(b); +} +bool le_tb_adouble_double(TBAdoubleHandle a, const double x) { + return *static_cast(a) <= x; +} +bool l_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return *static_cast(a) < *static_cast(b); +} +bool l_double_tb_adouble(const double x, TBAdoubleHandle b) { + return x < *static_cast(b); +} +bool l_tb_adouble_double(TBAdoubleHandle a, const double x) { + return *static_cast(a) < x; +} +bool eq_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b) { + return *static_cast(a) == *static_cast(b); +} +bool eq_double_tb_adouble(const double x, TBAdoubleHandle b) { + return x == *static_cast(b); +} +bool eq_tb_adouble_double(TBAdoubleHandle a, const double x) { + return *static_cast(a) == x; +} +TBAdoubleHandle tb_abs(TBAdoubleHandle a) { + return new adouble(fabs(*static_cast(a))); +} +TBAdoubleHandle tb_sqrt(TBAdoubleHandle a) { + return new adouble(sqrt(*static_cast(a))); +} +TBAdoubleHandle tb_log(TBAdoubleHandle a) { + return new adouble(log(*static_cast(a))); +} +TBAdoubleHandle tb_log10(TBAdoubleHandle a) { + return new adouble(log10(*static_cast(a))); +} +TBAdoubleHandle tb_sin(TBAdoubleHandle a) { + return new adouble(sin(*static_cast(a))); +} +TBAdoubleHandle tb_cos(TBAdoubleHandle a) { + return new adouble(cos(*static_cast(a))); +} +TBAdoubleHandle tb_tan(TBAdoubleHandle a) { + return new adouble(tan(*static_cast(a))); +} +TBAdoubleHandle tb_exp(TBAdoubleHandle a) { + return new adouble(exp(*static_cast(a))); +} +TBAdoubleHandle tb_asin(TBAdoubleHandle a) { + return new adouble(asin(*static_cast(a))); +} +TBAdoubleHandle tb_acos(TBAdoubleHandle a) { + return new adouble(acos(*static_cast(a))); +} +TBAdoubleHandle tb_atan(TBAdoubleHandle a) { + return new adouble(atan(*static_cast(a))); +} +TBAdoubleHandle tb_sinh(TBAdoubleHandle a) { + return new adouble(sinh(*static_cast(a))); +} +TBAdoubleHandle tb_cosh(TBAdoubleHandle a) { + return new adouble(cosh(*static_cast(a))); +} +TBAdoubleHandle tb_tanh(TBAdoubleHandle a) { + return new adouble(tanh(*static_cast(a))); +} +TBAdoubleHandle tb_asinh(TBAdoubleHandle a) { + return new adouble(asinh(*static_cast(a))); +} +TBAdoubleHandle tb_acosh(TBAdoubleHandle a) { + return new adouble(acosh(*static_cast(a))); +} +TBAdoubleHandle tb_atanh(TBAdoubleHandle a) { + return new adouble(atanh(*static_cast(a))); +} +TBAdoubleHandle tb_ceil(TBAdoubleHandle a) { + return new adouble(ceil(*static_cast(a))); +} +TBAdoubleHandle tb_floor(TBAdoubleHandle a) { + return new adouble(floor(*static_cast(a))); +} +TBAdoubleHandle tb_ldexp(TBAdoubleHandle a, const int n) { + return new adouble(ldexp(*static_cast(a), n)); +} +TBAdoubleHandle tb_erf(TBAdoubleHandle a) { + return new adouble(erf(*static_cast(a))); +} +TBAdoubleHandle tb_erfc(TBAdoubleHandle a) { + return new adouble(erfc(*static_cast(a))); +} } /* Tape utilities */ -extern "C" -{ - int c_trace_on(short int tag, int keep) - { - return trace_on(tag, keep); - } - void c_trace_off(int flag) - { - return trace_off(flag); - } - void create_independent(TBAdoubleHandle a, const double x) - { - *static_cast(a) <<= x; - } - void create_dependent(TBAdoubleHandle a, double *y) - { - *static_cast(a) >>= *y; - } - size_t num_independent(short tape_id) - { - size_t y[STAT_SIZE]; - tapestats(tape_id, y); - return y[NUM_INDEPENDENTS]; - } - size_t num_dependent(short tape_id) - { - size_t y[STAT_SIZE]; - tapestats(tape_id, y); - return y[NUM_DEPENDENTS]; - } - void enable_min_max_using_abs() - { - return enableMinMaxUsingAbs(); - } - void disable_min_max_using_abs() - { - return disableMinMaxUsingAbs(); - } - TBAdoubleHandle mkparam_(const double val) - { - return new adouble(mkparam(val)); - } +extern "C" { +int c_trace_on(short int tag, int keep) { return trace_on(tag, keep); } +void c_trace_off(int flag) { return trace_off(flag); } +void create_independent(TBAdoubleHandle a, const double x) { + *static_cast(a) <<= x; +} +void create_dependent(TBAdoubleHandle a, double *y) { + *static_cast(a) >>= *y; +} +size_t num_independent(short tape_id) { + size_t y[STAT_SIZE]; + tapestats(tape_id, y); + return y[NUM_INDEPENDENTS]; +} +size_t num_dependent(short tape_id) { + size_t y[STAT_SIZE]; + tapestats(tape_id, y); + return y[NUM_DEPENDENTS]; +} +void enable_min_max_using_abs() { return enableMinMaxUsingAbs(); } +void disable_min_max_using_abs() { return disableMinMaxUsingAbs(); } +TBAdoubleHandle mkparam_(const double val) { return new adouble(mkparam(val)); } } diff --git a/ADOL-C/c_interface/ADOLC_TB_interface.h b/ADOL-C/c_interface/ADOLC_TB_interface.h index bce1d0efd..21bace9d6 100644 --- a/ADOL-C/c_interface/ADOLC_TB_interface.h +++ b/ADOL-C/c_interface/ADOLC_TB_interface.h @@ -2,11 +2,10 @@ #define ADOLC_TB_INTERFACE_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - // Used to handle Tape-based adouble as void* - typedef void *TBAdoubleHandle; +// Used to handle Tape-based adouble as void* +typedef void *TBAdoubleHandle; #ifdef __cplusplus } #endif @@ -15,15 +14,14 @@ extern "C" Constructor & Destructor for class adouble */ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - // Constructor - TBAdoubleHandle create_tb_adouble(const double x); - TBAdoubleHandle create_tb_adouble_empty(); +// Constructor +TBAdoubleHandle create_tb_adouble(const double x); +TBAdoubleHandle create_tb_adouble_empty(); - // Destructor - void free_tb_adouble(TBAdoubleHandle a); +// Destructor +void free_tb_adouble(TBAdoubleHandle a); #ifdef __cplusplus } #endif @@ -32,10 +30,9 @@ extern "C" Utilities for adouble */ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - double get_tb_value(TBAdoubleHandle a); +double get_tb_value(TBAdoubleHandle a); #ifdef __cplusplus } #endif @@ -44,78 +41,77 @@ extern "C" Arithmetics for class tb adouble */ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - TBAdoubleHandle add_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - TBAdoubleHandle add_double_tb_adouble(const double x, TBAdoubleHandle b); - TBAdoubleHandle add_tb_adouble_double(TBAdoubleHandle a, const double x); - - TBAdoubleHandle mult_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - TBAdoubleHandle mult_double_tb_adouble(const double x, TBAdoubleHandle b); - TBAdoubleHandle mult_tb_adouble_double(TBAdoubleHandle a, const double x); - - TBAdoubleHandle subtr_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - TBAdoubleHandle subtr_double_tb_adouble(const double x, TBAdoubleHandle b); - TBAdoubleHandle subtr_tb_adouble_double(TBAdoubleHandle a, const double x); - - TBAdoubleHandle div_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - TBAdoubleHandle div_double_tb_adouble(const double x, TBAdoubleHandle b); - TBAdoubleHandle div_tb_adouble_double(TBAdoubleHandle a, const double x); - - TBAdoubleHandle max_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - TBAdoubleHandle max_double_tb_adouble(const double x, TBAdoubleHandle b); - TBAdoubleHandle max_tb_adouble_double(TBAdoubleHandle a, const double x); - - TBAdoubleHandle min_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - TBAdoubleHandle min_double_tb_adouble(const double x, TBAdoubleHandle b); - TBAdoubleHandle min_tb_adouble_double(TBAdoubleHandle a, const double x); - - TBAdoubleHandle pow_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - TBAdoubleHandle pow_tb_adouble_double(TBAdoubleHandle a, const double x); - - bool ge_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - bool ge_double_tb_adouble(const double x, TBAdoubleHandle b); - bool ge_tb_adouble_double(TBAdoubleHandle a, const double x); - - bool g_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - bool g_double_tb_adouble(const double x, TBAdoubleHandle b); - bool g_tb_adouble_double(TBAdoubleHandle a, const double x); - - bool le_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - bool le_double_tb_adouble(const double x, TBAdoubleHandle b); - bool le_tb_adouble_double(TBAdoubleHandle a, const double x); - - bool l_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - bool l_double_tb_adouble(const double x, TBAdoubleHandle b); - bool l_tb_adouble_double(TBAdoubleHandle a, const double x); - - bool eq_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); - bool eq_double_tb_adouble(const double x, TBAdoubleHandle b); - bool eq_tb_adouble_double(TBAdoubleHandle a, const double x); - - TBAdoubleHandle tb_abs(TBAdoubleHandle a); - TBAdoubleHandle tb_sqrt(TBAdoubleHandle a); - TBAdoubleHandle tb_log(TBAdoubleHandle a); - TBAdoubleHandle tb_log10(TBAdoubleHandle a); - TBAdoubleHandle tb_sin(TBAdoubleHandle a); - TBAdoubleHandle tb_cos(TBAdoubleHandle a); - TBAdoubleHandle tb_tan(TBAdoubleHandle a); - TBAdoubleHandle tb_exp(TBAdoubleHandle a); - TBAdoubleHandle tb_asin(TBAdoubleHandle a); - TBAdoubleHandle tb_acos(TBAdoubleHandle a); - TBAdoubleHandle tb_atan(TBAdoubleHandle a); - TBAdoubleHandle tb_sinh(TBAdoubleHandle a); - TBAdoubleHandle tb_cosh(TBAdoubleHandle a); - TBAdoubleHandle tb_tanh(TBAdoubleHandle a); - TBAdoubleHandle tb_asinh(TBAdoubleHandle a); - TBAdoubleHandle tb_acosh(TBAdoubleHandle a); - TBAdoubleHandle tb_atanh(TBAdoubleHandle a); - TBAdoubleHandle tb_ceil(TBAdoubleHandle a); - TBAdoubleHandle tb_floor(TBAdoubleHandle a); - TBAdoubleHandle tb_ldexp(TBAdoubleHandle a, int n); - TBAdoubleHandle tb_erf(TBAdoubleHandle a); - TBAdoubleHandle tb_erfc(TBAdoubleHandle a); +TBAdoubleHandle add_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +TBAdoubleHandle add_double_tb_adouble(const double x, TBAdoubleHandle b); +TBAdoubleHandle add_tb_adouble_double(TBAdoubleHandle a, const double x); + +TBAdoubleHandle mult_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +TBAdoubleHandle mult_double_tb_adouble(const double x, TBAdoubleHandle b); +TBAdoubleHandle mult_tb_adouble_double(TBAdoubleHandle a, const double x); + +TBAdoubleHandle subtr_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +TBAdoubleHandle subtr_double_tb_adouble(const double x, TBAdoubleHandle b); +TBAdoubleHandle subtr_tb_adouble_double(TBAdoubleHandle a, const double x); + +TBAdoubleHandle div_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +TBAdoubleHandle div_double_tb_adouble(const double x, TBAdoubleHandle b); +TBAdoubleHandle div_tb_adouble_double(TBAdoubleHandle a, const double x); + +TBAdoubleHandle max_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +TBAdoubleHandle max_double_tb_adouble(const double x, TBAdoubleHandle b); +TBAdoubleHandle max_tb_adouble_double(TBAdoubleHandle a, const double x); + +TBAdoubleHandle min_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +TBAdoubleHandle min_double_tb_adouble(const double x, TBAdoubleHandle b); +TBAdoubleHandle min_tb_adouble_double(TBAdoubleHandle a, const double x); + +TBAdoubleHandle pow_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +TBAdoubleHandle pow_tb_adouble_double(TBAdoubleHandle a, const double x); + +bool ge_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +bool ge_double_tb_adouble(const double x, TBAdoubleHandle b); +bool ge_tb_adouble_double(TBAdoubleHandle a, const double x); + +bool g_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +bool g_double_tb_adouble(const double x, TBAdoubleHandle b); +bool g_tb_adouble_double(TBAdoubleHandle a, const double x); + +bool le_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +bool le_double_tb_adouble(const double x, TBAdoubleHandle b); +bool le_tb_adouble_double(TBAdoubleHandle a, const double x); + +bool l_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +bool l_double_tb_adouble(const double x, TBAdoubleHandle b); +bool l_tb_adouble_double(TBAdoubleHandle a, const double x); + +bool eq_tb_adouble(TBAdoubleHandle a, TBAdoubleHandle b); +bool eq_double_tb_adouble(const double x, TBAdoubleHandle b); +bool eq_tb_adouble_double(TBAdoubleHandle a, const double x); + +TBAdoubleHandle tb_abs(TBAdoubleHandle a); +TBAdoubleHandle tb_sqrt(TBAdoubleHandle a); +TBAdoubleHandle tb_log(TBAdoubleHandle a); +TBAdoubleHandle tb_log10(TBAdoubleHandle a); +TBAdoubleHandle tb_sin(TBAdoubleHandle a); +TBAdoubleHandle tb_cos(TBAdoubleHandle a); +TBAdoubleHandle tb_tan(TBAdoubleHandle a); +TBAdoubleHandle tb_exp(TBAdoubleHandle a); +TBAdoubleHandle tb_asin(TBAdoubleHandle a); +TBAdoubleHandle tb_acos(TBAdoubleHandle a); +TBAdoubleHandle tb_atan(TBAdoubleHandle a); +TBAdoubleHandle tb_sinh(TBAdoubleHandle a); +TBAdoubleHandle tb_cosh(TBAdoubleHandle a); +TBAdoubleHandle tb_tanh(TBAdoubleHandle a); +TBAdoubleHandle tb_asinh(TBAdoubleHandle a); +TBAdoubleHandle tb_acosh(TBAdoubleHandle a); +TBAdoubleHandle tb_atanh(TBAdoubleHandle a); +TBAdoubleHandle tb_ceil(TBAdoubleHandle a); +TBAdoubleHandle tb_floor(TBAdoubleHandle a); +TBAdoubleHandle tb_ldexp(TBAdoubleHandle a, int n); +TBAdoubleHandle tb_erf(TBAdoubleHandle a); +TBAdoubleHandle tb_erfc(TBAdoubleHandle a); #ifdef __cplusplus } #endif @@ -124,18 +120,17 @@ extern "C" Tape utilities */ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - int c_trace_on(short int tag, int keep = 0); - void c_trace_off(int flag = 0); - void create_independent(TBAdoubleHandle a, const double x); - void create_dependent(TBAdoubleHandle a, double *y); - size_t num_independent(short tape_id); - size_t num_dependent(short tape_id); - void enable_min_max_using_abs(); - void disable_min_max_using_abs(); - TBAdoubleHandle mkparam_(const double val); +int c_trace_on(short int tag, int keep = 0); +void c_trace_off(int flag = 0); +void create_independent(TBAdoubleHandle a, const double x); +void create_dependent(TBAdoubleHandle a, double *y); +size_t num_independent(short tape_id); +size_t num_dependent(short tape_id); +void enable_min_max_using_abs(); +void disable_min_max_using_abs(); +TBAdoubleHandle mkparam_(const double val); #ifdef __cplusplus } #endif diff --git a/ADOL-C/c_interface/ADOLC_TL_interface.cpp b/ADOL-C/c_interface/ADOLC_TL_interface.cpp index 05beab39a..de1b2e52d 100644 --- a/ADOL-C/c_interface/ADOLC_TL_interface.cpp +++ b/ADOL-C/c_interface/ADOLC_TL_interface.cpp @@ -1,299 +1,233 @@ -#include #include "ADOLC_TL_interface.h" +#include /* Constructor & Destructor for class tape-less adouble */ -extern "C" -{ - TLAdoubleHandle create_tl_adouble(const double x) - { - return new adtl::adouble(x); - } - TLAdoubleHandle create_tl_adouble_empty() - { - return new adtl::adouble(); - } - TLAdoubleHandle create_tl_adouble_with_ad(const double val, const double *ad_val) - { - return new adtl::adouble(val, ad_val); - } - void free_tl_adouble(TLAdoubleHandle a) - { - return delete static_cast(a); - } +extern "C" { +TLAdoubleHandle create_tl_adouble(const double x) { + return new adtl::adouble(x); +} +TLAdoubleHandle create_tl_adouble_empty() { return new adtl::adouble(); } +TLAdoubleHandle create_tl_adouble_with_ad(const double val, + const double *ad_val) { + return new adtl::adouble(val, ad_val); +} +void free_tl_adouble(TLAdoubleHandle a) { + return delete static_cast(a); +} } /* Utilities for adouble */ -extern "C" -{ - void set_num_dir(const size_t n) - { - return adtl::setNumDir(n); - } +extern "C" { +void set_num_dir(const size_t n) { return adtl::setNumDir(n); } - void set_tl_value(TLAdoubleHandle a, const double val) - { - return static_cast(a)->setValue(val); - } +void set_tl_value(TLAdoubleHandle a, const double val) { + return static_cast(a)->setValue(val); +} - void set_tl_ad_value(TLAdoubleHandle a, const double *const val) - { - return static_cast(a)->setADValue(val); - } +void set_tl_ad_value(TLAdoubleHandle a, const double *const val) { + return static_cast(a)->setADValue(val); +} - void set_tl_ad_value_idx(TLAdoubleHandle a, const size_t pos, const double val) - { - return static_cast(a)->setADValue(pos, val); - } +void set_tl_ad_value_idx(TLAdoubleHandle a, const size_t pos, + const double val) { + return static_cast(a)->setADValue(pos, val); +} - double get_tl_value(const TLAdoubleHandle a) - { - return static_cast(a)->getValue(); - } - const double *get_tl_ad_values(const TLAdoubleHandle a) - { - return (static_cast(a))->getADValue(); - } - double get_tl_ad_value_idx(const TLAdoubleHandle a, const size_t pos) - { - return static_cast(a)->getADValue(pos); - } +double get_tl_value(const TLAdoubleHandle a) { + return static_cast(a)->getValue(); +} +const double *get_tl_ad_values(const TLAdoubleHandle a) { + return (static_cast(a))->getADValue(); +} +double get_tl_ad_value_idx(const TLAdoubleHandle a, const size_t pos) { + return static_cast(a)->getADValue(pos); +} } /* Arithmetics for class adouble */ -extern "C" -{ - TLAdoubleHandle add_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return new adtl::adouble(*static_cast(a) + *static_cast(b)); - } - TLAdoubleHandle add_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return new adtl::adouble(x + *static_cast(b)); - } - TLAdoubleHandle add_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return new adtl::adouble(*static_cast(a) + x); - } - TLAdoubleHandle mult_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return new adtl::adouble(*static_cast(a) * *static_cast(b)); - } - TLAdoubleHandle mult_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return new adtl::adouble(x * *static_cast(b)); - } - TLAdoubleHandle mult_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return new adtl::adouble(*static_cast(a) * x); - } - TLAdoubleHandle subtr_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return new adtl::adouble(*static_cast(a) - *static_cast(b)); - } - TLAdoubleHandle subtr_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return new adtl::adouble(x - *static_cast(b)); - } - TLAdoubleHandle subtr_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return new adtl::adouble(*static_cast(a) - x); - } - TLAdoubleHandle div_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return new adtl::adouble(*static_cast(a) / *static_cast(b)); - } - TLAdoubleHandle div_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return new adtl::adouble(x / *static_cast(b)); - } - TLAdoubleHandle div_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return new adtl::adouble(*static_cast(a) / x); - } - TLAdoubleHandle max_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return new adtl::adouble(fmax(*static_cast(a), *static_cast(b))); - } - TLAdoubleHandle max_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return new adtl::adouble(fmax(x, *static_cast(b))); - } - TLAdoubleHandle max_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return new adtl::adouble(fmax(*static_cast(a), x)); - } - TLAdoubleHandle min_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return new adtl::adouble(fmin(*static_cast(a), *static_cast(b))); - } - TLAdoubleHandle min_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return new adtl::adouble(fmin(x, *static_cast(b))); - } - TLAdoubleHandle min_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return new adtl::adouble(fmin(*static_cast(a), x)); - } - TLAdoubleHandle pow_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return new adtl::adouble(pow(*static_cast(a), *static_cast(b))); - } - TLAdoubleHandle pow_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return new adtl::adouble(pow(*static_cast(a), x)); - } - bool ge_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return *static_cast(a) >= *static_cast(b); - } - bool ge_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return x >= *static_cast(b); - } - bool ge_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return *static_cast(a) >= x; - } - bool g_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return *static_cast(a) > *static_cast(b); - } - bool g_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return x > *static_cast(b); - } - bool g_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return *static_cast(a) > x; - } - bool le_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return *static_cast(a) <= *static_cast(b); - } - bool le_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return x <= *static_cast(b); - } - bool le_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return *static_cast(a) <= x; - } - bool l_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return *static_cast(a) < *static_cast(b); - } - bool l_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return x < *static_cast(b); - } - bool l_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return *static_cast(a) < x; - } - bool eq_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) - { - return *static_cast(a) == *static_cast(b); - } - bool eq_double_tl_adouble(const double x, TLAdoubleHandle b) - { - return x == *static_cast(b); - } - bool eq_tl_adouble_double(TLAdoubleHandle a, const double x) - { - return *static_cast(a) == x; - } - TLAdoubleHandle tl_abs(TLAdoubleHandle a) - { - return new adtl::adouble(fabs(*static_cast(a))); - } - TLAdoubleHandle tl_sqrt(TLAdoubleHandle a) - { - return new adtl::adouble(sqrt(*static_cast(a))); - } - TLAdoubleHandle tl_log(TLAdoubleHandle a) - { - return new adtl::adouble(log(*static_cast(a))); - } - TLAdoubleHandle tl_log10(TLAdoubleHandle a) - { - return new adtl::adouble(log10(*static_cast(a))); - } - TLAdoubleHandle tl_sin(TLAdoubleHandle a) - { - return new adtl::adouble(sin(*static_cast(a))); - } - TLAdoubleHandle tl_cos(TLAdoubleHandle a) - { - return new adtl::adouble(cos(*static_cast(a))); - } - TLAdoubleHandle tl_tan(TLAdoubleHandle a) - { - return new adtl::adouble(tan(*static_cast(a))); - } - TLAdoubleHandle tl_exp(TLAdoubleHandle a) - { - return new adtl::adouble(exp(*static_cast(a))); - } - TLAdoubleHandle tl_asin(TLAdoubleHandle a) - { - return new adtl::adouble(asin(*static_cast(a))); - } - TLAdoubleHandle tl_acos(TLAdoubleHandle a) - { - return new adtl::adouble(acos(*static_cast(a))); - } - TLAdoubleHandle tl_atan(TLAdoubleHandle a) - { - return new adtl::adouble(atan(*static_cast(a))); - } - TLAdoubleHandle tl_sinh(TLAdoubleHandle a) - { - return new adtl::adouble(sinh(*static_cast(a))); - } - TLAdoubleHandle tl_cosh(TLAdoubleHandle a) - { - return new adtl::adouble(cosh(*static_cast(a))); - } - TLAdoubleHandle tl_tanh(TLAdoubleHandle a) - { - return new adtl::adouble(tanh(*static_cast(a))); - } - TLAdoubleHandle tl_asinh(TLAdoubleHandle a) - { - return new adtl::adouble(asinh(*static_cast(a))); - } - TLAdoubleHandle tl_acosh(TLAdoubleHandle a) - { - return new adtl::adouble(acosh(*static_cast(a))); - } - TLAdoubleHandle tl_atanh(TLAdoubleHandle a) - { - return new adtl::adouble(atanh(*static_cast(a))); - } - TLAdoubleHandle tl_ceil(TLAdoubleHandle a) - { - return new adtl::adouble(ceil(*static_cast(a))); - } - TLAdoubleHandle tl_floor(TLAdoubleHandle a) - { - return new adtl::adouble(floor(*static_cast(a))); - } - TLAdoubleHandle tl_ldexp(TLAdoubleHandle a, const int n) - { - return new adtl::adouble(ldexp(*static_cast(a), n)); - } - TLAdoubleHandle tl_erf(TLAdoubleHandle a) - { - return new adtl::adouble(erf(*static_cast(a))); - } - TLAdoubleHandle tl_erfc(TLAdoubleHandle a) - { - return new adtl::adouble(erfc(*static_cast(a))); - } +extern "C" { +TLAdoubleHandle add_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return new adtl::adouble(*static_cast(a) + + *static_cast(b)); +} +TLAdoubleHandle add_double_tl_adouble(const double x, TLAdoubleHandle b) { + return new adtl::adouble(x + *static_cast(b)); +} +TLAdoubleHandle add_tl_adouble_double(TLAdoubleHandle a, const double x) { + return new adtl::adouble(*static_cast(a) + x); +} +TLAdoubleHandle mult_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return new adtl::adouble(*static_cast(a) * + *static_cast(b)); +} +TLAdoubleHandle mult_double_tl_adouble(const double x, TLAdoubleHandle b) { + return new adtl::adouble(x * *static_cast(b)); +} +TLAdoubleHandle mult_tl_adouble_double(TLAdoubleHandle a, const double x) { + return new adtl::adouble(*static_cast(a) * x); +} +TLAdoubleHandle subtr_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return new adtl::adouble(*static_cast(a) - + *static_cast(b)); +} +TLAdoubleHandle subtr_double_tl_adouble(const double x, TLAdoubleHandle b) { + return new adtl::adouble(x - *static_cast(b)); +} +TLAdoubleHandle subtr_tl_adouble_double(TLAdoubleHandle a, const double x) { + return new adtl::adouble(*static_cast(a) - x); +} +TLAdoubleHandle div_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return new adtl::adouble(*static_cast(a) / + *static_cast(b)); +} +TLAdoubleHandle div_double_tl_adouble(const double x, TLAdoubleHandle b) { + return new adtl::adouble(x / *static_cast(b)); +} +TLAdoubleHandle div_tl_adouble_double(TLAdoubleHandle a, const double x) { + return new adtl::adouble(*static_cast(a) / x); +} +TLAdoubleHandle max_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return new adtl::adouble( + fmax(*static_cast(a), *static_cast(b))); +} +TLAdoubleHandle max_double_tl_adouble(const double x, TLAdoubleHandle b) { + return new adtl::adouble(fmax(x, *static_cast(b))); +} +TLAdoubleHandle max_tl_adouble_double(TLAdoubleHandle a, const double x) { + return new adtl::adouble(fmax(*static_cast(a), x)); +} +TLAdoubleHandle min_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return new adtl::adouble( + fmin(*static_cast(a), *static_cast(b))); +} +TLAdoubleHandle min_double_tl_adouble(const double x, TLAdoubleHandle b) { + return new adtl::adouble(fmin(x, *static_cast(b))); +} +TLAdoubleHandle min_tl_adouble_double(TLAdoubleHandle a, const double x) { + return new adtl::adouble(fmin(*static_cast(a), x)); +} +TLAdoubleHandle pow_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return new adtl::adouble( + pow(*static_cast(a), *static_cast(b))); +} +TLAdoubleHandle pow_tl_adouble_double(TLAdoubleHandle a, const double x) { + return new adtl::adouble(pow(*static_cast(a), x)); +} +bool ge_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return *static_cast(a) >= *static_cast(b); +} +bool ge_double_tl_adouble(const double x, TLAdoubleHandle b) { + return x >= *static_cast(b); +} +bool ge_tl_adouble_double(TLAdoubleHandle a, const double x) { + return *static_cast(a) >= x; +} +bool g_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return *static_cast(a) > *static_cast(b); +} +bool g_double_tl_adouble(const double x, TLAdoubleHandle b) { + return x > *static_cast(b); +} +bool g_tl_adouble_double(TLAdoubleHandle a, const double x) { + return *static_cast(a) > x; +} +bool le_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return *static_cast(a) <= *static_cast(b); +} +bool le_double_tl_adouble(const double x, TLAdoubleHandle b) { + return x <= *static_cast(b); +} +bool le_tl_adouble_double(TLAdoubleHandle a, const double x) { + return *static_cast(a) <= x; +} +bool l_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return *static_cast(a) < *static_cast(b); +} +bool l_double_tl_adouble(const double x, TLAdoubleHandle b) { + return x < *static_cast(b); +} +bool l_tl_adouble_double(TLAdoubleHandle a, const double x) { + return *static_cast(a) < x; +} +bool eq_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b) { + return *static_cast(a) == *static_cast(b); +} +bool eq_double_tl_adouble(const double x, TLAdoubleHandle b) { + return x == *static_cast(b); +} +bool eq_tl_adouble_double(TLAdoubleHandle a, const double x) { + return *static_cast(a) == x; +} +TLAdoubleHandle tl_abs(TLAdoubleHandle a) { + return new adtl::adouble(fabs(*static_cast(a))); +} +TLAdoubleHandle tl_sqrt(TLAdoubleHandle a) { + return new adtl::adouble(sqrt(*static_cast(a))); +} +TLAdoubleHandle tl_log(TLAdoubleHandle a) { + return new adtl::adouble(log(*static_cast(a))); +} +TLAdoubleHandle tl_log10(TLAdoubleHandle a) { + return new adtl::adouble(log10(*static_cast(a))); +} +TLAdoubleHandle tl_sin(TLAdoubleHandle a) { + return new adtl::adouble(sin(*static_cast(a))); +} +TLAdoubleHandle tl_cos(TLAdoubleHandle a) { + return new adtl::adouble(cos(*static_cast(a))); +} +TLAdoubleHandle tl_tan(TLAdoubleHandle a) { + return new adtl::adouble(tan(*static_cast(a))); +} +TLAdoubleHandle tl_exp(TLAdoubleHandle a) { + return new adtl::adouble(exp(*static_cast(a))); +} +TLAdoubleHandle tl_asin(TLAdoubleHandle a) { + return new adtl::adouble(asin(*static_cast(a))); +} +TLAdoubleHandle tl_acos(TLAdoubleHandle a) { + return new adtl::adouble(acos(*static_cast(a))); +} +TLAdoubleHandle tl_atan(TLAdoubleHandle a) { + return new adtl::adouble(atan(*static_cast(a))); +} +TLAdoubleHandle tl_sinh(TLAdoubleHandle a) { + return new adtl::adouble(sinh(*static_cast(a))); +} +TLAdoubleHandle tl_cosh(TLAdoubleHandle a) { + return new adtl::adouble(cosh(*static_cast(a))); +} +TLAdoubleHandle tl_tanh(TLAdoubleHandle a) { + return new adtl::adouble(tanh(*static_cast(a))); +} +TLAdoubleHandle tl_asinh(TLAdoubleHandle a) { + return new adtl::adouble(asinh(*static_cast(a))); +} +TLAdoubleHandle tl_acosh(TLAdoubleHandle a) { + return new adtl::adouble(acosh(*static_cast(a))); +} +TLAdoubleHandle tl_atanh(TLAdoubleHandle a) { + return new adtl::adouble(atanh(*static_cast(a))); +} +TLAdoubleHandle tl_ceil(TLAdoubleHandle a) { + return new adtl::adouble(ceil(*static_cast(a))); +} +TLAdoubleHandle tl_floor(TLAdoubleHandle a) { + return new adtl::adouble(floor(*static_cast(a))); +} +TLAdoubleHandle tl_ldexp(TLAdoubleHandle a, const int n) { + return new adtl::adouble(ldexp(*static_cast(a), n)); +} +TLAdoubleHandle tl_erf(TLAdoubleHandle a) { + return new adtl::adouble(erf(*static_cast(a))); +} +TLAdoubleHandle tl_erfc(TLAdoubleHandle a) { + return new adtl::adouble(erfc(*static_cast(a))); +} } diff --git a/ADOL-C/c_interface/ADOLC_TL_interface.h b/ADOL-C/c_interface/ADOLC_TL_interface.h index e329644b1..d0862d8ee 100644 --- a/ADOL-C/c_interface/ADOLC_TL_interface.h +++ b/ADOL-C/c_interface/ADOLC_TL_interface.h @@ -2,11 +2,10 @@ #define ADOLC_TL_INTERFACE_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - // Used to handle Tape-Less adouble as void* - typedef void *TLAdoubleHandle; +// Used to handle Tape-Less adouble as void* +typedef void *TLAdoubleHandle; #ifdef __cplusplus } #endif @@ -15,16 +14,16 @@ extern "C" Constructor & Destructor for class tape-less adouble */ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - // Constructor - TLAdoubleHandle create_tl_adouble(const double x); - TLAdoubleHandle create_tl_adouble_with_ad(const double val, const double *ad_val); - TLAdoubleHandle create_tl_adouble_empty(); - - // Destructor - void free_tl_adouble(TLAdoubleHandle a); +// Constructor +TLAdoubleHandle create_tl_adouble(const double x); +TLAdoubleHandle create_tl_adouble_with_ad(const double val, + const double *ad_val); +TLAdoubleHandle create_tl_adouble_empty(); + +// Destructor +void free_tl_adouble(TLAdoubleHandle a); #ifdef __cplusplus } #endif @@ -33,16 +32,15 @@ extern "C" Utilities for tape-less adouble */ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - void set_num_dir(const size_t n); - void set_tl_value(TLAdoubleHandle a, const double val); - void set_tl_ad_value(TLAdoubleHandle a, const double *const val); - void set_tl_ad_value_idx(TLAdoubleHandle a, const size_t pos, const double val); - double get_tl_value(TLAdoubleHandle a); - const double *get_tl_ad_values(TLAdoubleHandle a); - double get_tl_ad_value_idx(TLAdoubleHandle a, const size_t pos); +void set_num_dir(const size_t n); +void set_tl_value(TLAdoubleHandle a, const double val); +void set_tl_ad_value(TLAdoubleHandle a, const double *const val); +void set_tl_ad_value_idx(TLAdoubleHandle a, const size_t pos, const double val); +double get_tl_value(TLAdoubleHandle a); +const double *get_tl_ad_values(TLAdoubleHandle a); +double get_tl_ad_value_idx(TLAdoubleHandle a, const size_t pos); #ifdef __cplusplus } #endif @@ -51,78 +49,77 @@ extern "C" Arithmetics for class tape-less adouble */ #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - TLAdoubleHandle add_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - TLAdoubleHandle add_double_tl_adouble(const double x, TLAdoubleHandle b); - TLAdoubleHandle add_tl_adouble_double(TLAdoubleHandle a, const double x); - - TLAdoubleHandle mult_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - TLAdoubleHandle mult_double_tl_adouble(const double x, TLAdoubleHandle b); - TLAdoubleHandle mult_tl_adouble_double(TLAdoubleHandle a, const double x); - - TLAdoubleHandle subtr_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - TLAdoubleHandle subtr_double_tl_adouble(const double x, TLAdoubleHandle b); - TLAdoubleHandle subtr_tl_adouble_double(TLAdoubleHandle a, const double x); - - TLAdoubleHandle div_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - TLAdoubleHandle div_double_tl_adouble(const double x, TLAdoubleHandle b); - TLAdoubleHandle div_tl_adouble_double(TLAdoubleHandle a, const double x); - - TLAdoubleHandle max_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - TLAdoubleHandle max_double_tl_adouble(const double x, TLAdoubleHandle b); - TLAdoubleHandle max_tl_adouble_double(TLAdoubleHandle a, const double x); - - TLAdoubleHandle min_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - TLAdoubleHandle min_double_tl_adouble(const double x, TLAdoubleHandle b); - TLAdoubleHandle min_tl_adouble_double(TLAdoubleHandle a, const double x); - - TLAdoubleHandle pow_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - TLAdoubleHandle pow_tl_adouble_double(TLAdoubleHandle a, const double x); - - bool ge_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - bool ge_double_tl_adouble(const double x, TLAdoubleHandle b); - bool ge_tl_adouble_double(TLAdoubleHandle a, const double x); - - bool g_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - bool g_double_tl_adouble(const double x, TLAdoubleHandle b); - bool g_tl_adouble_double(TLAdoubleHandle a, const double x); - - bool le_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - bool le_double_tl_adouble(const double x, TLAdoubleHandle b); - bool le_tl_adouble_double(TLAdoubleHandle a, const double x); - - bool l_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - bool l_double_tl_adouble(const double x, TLAdoubleHandle b); - bool l_tl_adouble_double(TLAdoubleHandle a, const double x); - - bool eq_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); - bool eq_double_tl_adouble(const double x, TLAdoubleHandle b); - bool eq_tl_adouble_double(TLAdoubleHandle a, const double x); - - TLAdoubleHandle tl_abs(TLAdoubleHandle a); - TLAdoubleHandle tl_sqrt(TLAdoubleHandle a); - TLAdoubleHandle tl_log(TLAdoubleHandle a); - TLAdoubleHandle tl_log10(TLAdoubleHandle a); - TLAdoubleHandle tl_sin(TLAdoubleHandle a); - TLAdoubleHandle tl_cos(TLAdoubleHandle a); - TLAdoubleHandle tl_tan(TLAdoubleHandle a); - TLAdoubleHandle tl_exp(TLAdoubleHandle a); - TLAdoubleHandle tl_asin(TLAdoubleHandle a); - TLAdoubleHandle tl_acos(TLAdoubleHandle a); - TLAdoubleHandle tl_atan(TLAdoubleHandle a); - TLAdoubleHandle tl_sinh(TLAdoubleHandle a); - TLAdoubleHandle tl_cosh(TLAdoubleHandle a); - TLAdoubleHandle tl_tanh(TLAdoubleHandle a); - TLAdoubleHandle tl_asinh(TLAdoubleHandle a); - TLAdoubleHandle tl_acosh(TLAdoubleHandle a); - TLAdoubleHandle tl_atanh(TLAdoubleHandle a); - TLAdoubleHandle tl_ceil(TLAdoubleHandle a); - TLAdoubleHandle tl_floor(TLAdoubleHandle a); - TLAdoubleHandle tl_ldexp(TLAdoubleHandle a, const int n); - TLAdoubleHandle tl_erf(TLAdoubleHandle a); - TLAdoubleHandle tl_erfc(TLAdoubleHandle a); +TLAdoubleHandle add_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +TLAdoubleHandle add_double_tl_adouble(const double x, TLAdoubleHandle b); +TLAdoubleHandle add_tl_adouble_double(TLAdoubleHandle a, const double x); + +TLAdoubleHandle mult_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +TLAdoubleHandle mult_double_tl_adouble(const double x, TLAdoubleHandle b); +TLAdoubleHandle mult_tl_adouble_double(TLAdoubleHandle a, const double x); + +TLAdoubleHandle subtr_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +TLAdoubleHandle subtr_double_tl_adouble(const double x, TLAdoubleHandle b); +TLAdoubleHandle subtr_tl_adouble_double(TLAdoubleHandle a, const double x); + +TLAdoubleHandle div_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +TLAdoubleHandle div_double_tl_adouble(const double x, TLAdoubleHandle b); +TLAdoubleHandle div_tl_adouble_double(TLAdoubleHandle a, const double x); + +TLAdoubleHandle max_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +TLAdoubleHandle max_double_tl_adouble(const double x, TLAdoubleHandle b); +TLAdoubleHandle max_tl_adouble_double(TLAdoubleHandle a, const double x); + +TLAdoubleHandle min_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +TLAdoubleHandle min_double_tl_adouble(const double x, TLAdoubleHandle b); +TLAdoubleHandle min_tl_adouble_double(TLAdoubleHandle a, const double x); + +TLAdoubleHandle pow_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +TLAdoubleHandle pow_tl_adouble_double(TLAdoubleHandle a, const double x); + +bool ge_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +bool ge_double_tl_adouble(const double x, TLAdoubleHandle b); +bool ge_tl_adouble_double(TLAdoubleHandle a, const double x); + +bool g_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +bool g_double_tl_adouble(const double x, TLAdoubleHandle b); +bool g_tl_adouble_double(TLAdoubleHandle a, const double x); + +bool le_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +bool le_double_tl_adouble(const double x, TLAdoubleHandle b); +bool le_tl_adouble_double(TLAdoubleHandle a, const double x); + +bool l_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +bool l_double_tl_adouble(const double x, TLAdoubleHandle b); +bool l_tl_adouble_double(TLAdoubleHandle a, const double x); + +bool eq_tl_adouble(TLAdoubleHandle a, TLAdoubleHandle b); +bool eq_double_tl_adouble(const double x, TLAdoubleHandle b); +bool eq_tl_adouble_double(TLAdoubleHandle a, const double x); + +TLAdoubleHandle tl_abs(TLAdoubleHandle a); +TLAdoubleHandle tl_sqrt(TLAdoubleHandle a); +TLAdoubleHandle tl_log(TLAdoubleHandle a); +TLAdoubleHandle tl_log10(TLAdoubleHandle a); +TLAdoubleHandle tl_sin(TLAdoubleHandle a); +TLAdoubleHandle tl_cos(TLAdoubleHandle a); +TLAdoubleHandle tl_tan(TLAdoubleHandle a); +TLAdoubleHandle tl_exp(TLAdoubleHandle a); +TLAdoubleHandle tl_asin(TLAdoubleHandle a); +TLAdoubleHandle tl_acos(TLAdoubleHandle a); +TLAdoubleHandle tl_atan(TLAdoubleHandle a); +TLAdoubleHandle tl_sinh(TLAdoubleHandle a); +TLAdoubleHandle tl_cosh(TLAdoubleHandle a); +TLAdoubleHandle tl_tanh(TLAdoubleHandle a); +TLAdoubleHandle tl_asinh(TLAdoubleHandle a); +TLAdoubleHandle tl_acosh(TLAdoubleHandle a); +TLAdoubleHandle tl_atanh(TLAdoubleHandle a); +TLAdoubleHandle tl_ceil(TLAdoubleHandle a); +TLAdoubleHandle tl_floor(TLAdoubleHandle a); +TLAdoubleHandle tl_ldexp(TLAdoubleHandle a, const int n); +TLAdoubleHandle tl_erf(TLAdoubleHandle a); +TLAdoubleHandle tl_erfc(TLAdoubleHandle a); #ifdef __cplusplus } #endif diff --git a/ADOL-C/c_interface/array_handler.cpp b/ADOL-C/c_interface/array_handler.cpp index 25b62035e..597b19b05 100644 --- a/ADOL-C/c_interface/array_handler.cpp +++ b/ADOL-C/c_interface/array_handler.cpp @@ -3,49 +3,32 @@ /* Setter and getter for vectors, matrizes and tensors. */ -extern "C" -{ - const double getindex_vec(const double *A, const int row) - { - return A[row]; - } - void setindex_vec(double *A, const double val, const int row) - { - A[row] = val; - } +extern "C" { +const double getindex_vec(const double *A, const int row) { return A[row]; } +void setindex_vec(double *A, const double val, const int row) { A[row] = val; } - const double getindex_mat(const double **A, const int row, const int col) - { - return A[row][col]; - } - void setindex_mat(double **A, const double val, const int row, const int col) - { - A[row][col] = val; - } - const double **getindex_ten(const double ***A, const int dim) - { - return A[dim]; - } - const double getindex_tens(const double ***A, const int dim, const int row, const int col) - { - return A[dim][row][col]; - } - void setindex_tens(double ***A, const double val, const int dim, const int row, const int col) - { - A[dim][row][col] = val; - } +const double getindex_mat(const double **A, const int row, const int col) { + return A[row][col]; +} +void setindex_mat(double **A, const double val, const int row, const int col) { + A[row][col] = val; +} +const double **getindex_ten(const double ***A, const int dim) { return A[dim]; } +const double getindex_tens(const double ***A, const int dim, const int row, + const int col) { + return A[dim][row][col]; +} +void setindex_tens(double ***A, const double val, const int dim, const int row, + const int col) { + A[dim][row][col] = val; +} - short **alloc_short_mat(const int rows, const int cols) - { - short **s = new short *[rows]; - for (int i = 0; i < rows; i++) - { - s[i] = new short[cols]; - } - return s; - } - void free_short_mat(short **s) - { - delete s; - } +short **alloc_short_mat(const int rows, const int cols) { + short **s = new short *[rows]; + for (int i = 0; i < rows; i++) { + s[i] = new short[cols]; + } + return s; +} +void free_short_mat(short **s) { delete s; } } \ No newline at end of file diff --git a/ADOL-C/c_interface/array_handler.h b/ADOL-C/c_interface/array_handler.h index 95fdeb61e..f6766fb89 100644 --- a/ADOL-C/c_interface/array_handler.h +++ b/ADOL-C/c_interface/array_handler.h @@ -2,18 +2,19 @@ #define ARRAY_HANDLER_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - const double getindex_vec(const double *A, const int row); - void setindex_vec(double *A, const double val, const int row); - const double getindex_mat(const double **A, const int row, const int col); - void setindex_mat(double **A, const double val, const int row, const int col); - const double **getindex_ten(const double ***A, const int dim); - const double getindex_tens(const double ***A, const int dim, const int row, const int col); - void setindex_tens(double ***A, const double val, const int dim, const int row, const int col); - short **alloc_short_mat(const int row, const int col); - void free_short_mat(short **s); +const double getindex_vec(const double *A, const int row); +void setindex_vec(double *A, const double val, const int row); +const double getindex_mat(const double **A, const int row, const int col); +void setindex_mat(double **A, const double val, const int row, const int col); +const double **getindex_ten(const double ***A, const int dim); +const double getindex_tens(const double ***A, const int dim, const int row, + const int col); +void setindex_tens(double ***A, const double val, const int dim, const int row, + const int col); +short **alloc_short_mat(const int row, const int col); +void free_short_mat(short **s); #ifdef __cplusplus } #endif diff --git a/ADOL-C/c_interface/driver_interface.cpp b/ADOL-C/c_interface/driver_interface.cpp index 9512bcc7c..1ea68fd5b 100644 --- a/ADOL-C/c_interface/driver_interface.cpp +++ b/ADOL-C/c_interface/driver_interface.cpp @@ -1,168 +1,63 @@ -#include #include "driver_interface.h" +#include /* -This file generates an interface to the overloaded forward and reverse mode calls. +This file generates an interface to the overloaded forward and reverse mode +calls. */ -int forward1(short tag, - int m, - int n, - int d, - int keep, - double **X, - double **Y) -{ - return forward(tag, m, n, d, keep, X, Y); -} -int forward2(short tag, - int m, - int n, - int d, - int keep, - double **X, - double *Y) -{ - return forward(tag, m, n, d, keep, X, Y); -} -int forward3(short tag, - int m, - int n, - int d, - int keep, - double *X, - double *Y) -{ - return forward(tag, m, n, d, keep, X, Y); -} -int forward4(short tag, - int m, - int n, - int keep, - double *X, - double *Y) -{ - return forward(tag, m, n, keep, X, Y); -} -int forward5(short tag, - int m, - int n, - int d, - int p, - double *x, - double ***X, - double *y, - double ***Y) -{ - return forward(tag, m, n, d, p, x, X, y, Y); +int forward1(short tag, int m, int n, int d, int keep, double **X, double **Y) { + return forward(tag, m, n, d, keep, X, Y); +} +int forward2(short tag, int m, int n, int d, int keep, double **X, double *Y) { + return forward(tag, m, n, d, keep, X, Y); +} +int forward3(short tag, int m, int n, int d, int keep, double *X, double *Y) { + return forward(tag, m, n, d, keep, X, Y); +} +int forward4(short tag, int m, int n, int keep, double *X, double *Y) { + return forward(tag, m, n, keep, X, Y); +} +int forward5(short tag, int m, int n, int d, int p, double *x, double ***X, + double *y, double ***Y) { + return forward(tag, m, n, d, p, x, X, y, Y); } -int forward6(short tag, - int m, - int n, - int p, - double *x, - double **X, - double *y, - double **Y) -{ - return forward(tag, m, n, p, x, X, y, Y); -} -int reverse1(short tag, - int m, - int n, - int d, - double *u, - double **Z) -{ - return reverse(tag, m, n, d, u, Z); -} -int reverse2(short tag, - int m, - int n, - int d, - double u, - double **Z) -{ - return reverse(tag, m, n, d, u, Z); -} -int reverse3(short tag, - int m, - int n, - int d, - double *u, - double *Z) -{ - return reverse(tag, m, n, d, u, Z); -} -int reverse4(short tag, - int m, - int n, - int d, - double u, - double *Z) -{ - return reverse(tag, m, n, d, u, Z); -} -int reverse5(short tag, - int m, - int n, - int d, - int q, - double **U, - double ***Z, - short **nz) -{ - return reverse(tag, m, n, d, q, U, Z, nz); -} -int reverse6(short tag, - int m, - int n, - int d, - int q, - double *U, - double ***Z, - short **nz) -{ - return reverse(tag, m, n, d, q, U, Z, nz); +int forward6(short tag, int m, int n, int p, double *x, double **X, double *y, + double **Y) { + return forward(tag, m, n, p, x, X, y, Y); +} +int reverse1(short tag, int m, int n, int d, double *u, double **Z) { + return reverse(tag, m, n, d, u, Z); +} +int reverse2(short tag, int m, int n, int d, double u, double **Z) { + return reverse(tag, m, n, d, u, Z); +} +int reverse3(short tag, int m, int n, int d, double *u, double *Z) { + return reverse(tag, m, n, d, u, Z); +} +int reverse4(short tag, int m, int n, int d, double u, double *Z) { + return reverse(tag, m, n, d, u, Z); +} +int reverse5(short tag, int m, int n, int d, int q, double **U, double ***Z, + short **nz) { + return reverse(tag, m, n, d, q, U, Z, nz); +} +int reverse6(short tag, int m, int n, int d, int q, double *U, double ***Z, + short **nz) { + return reverse(tag, m, n, d, q, U, Z, nz); } -int reverse7(short tag, - int m, - int n, - int d, - int q, - double **U, - double **Z) -{ - return reverse(tag, m, n, d, q, U, Z); +int reverse7(short tag, int m, int n, int d, int q, double **U, double **Z) { + return reverse(tag, m, n, d, q, U, Z); } -int reverse8(short tag, - int m, - int n, - int q, - double **U, - double **Z) -{ - return reverse(tag, m, n, q, U, Z); -} -int reverse9(short tag, - int m, - int n, - int d, - int q, - double *U, - double **Z) -{ - return reverse(tag, m, n, d, q, U, Z); +int reverse8(short tag, int m, int n, int q, double **U, double **Z) { + return reverse(tag, m, n, q, U, Z); +} +int reverse9(short tag, int m, int n, int d, int q, double *U, double **Z) { + return reverse(tag, m, n, d, q, U, Z); } -int reverse10(short tag, - int m, - int n, - int d, - double ***Z, - short **nz) -{ - return reverse(tag, m, n, d, Z, nz); +int reverse10(short tag, int m, int n, int d, double ***Z, short **nz) { + return reverse(tag, m, n, d, Z, nz); } diff --git a/ADOL-C/c_interface/driver_interface.h b/ADOL-C/c_interface/driver_interface.h index b7f5bc337..12828da21 100644 --- a/ADOL-C/c_interface/driver_interface.h +++ b/ADOL-C/c_interface/driver_interface.h @@ -1,155 +1,65 @@ /* -This file generates an interface to the overloaded forward and reverse mode calls. +This file generates an interface to the overloaded forward and reverse mode +calls. */ #ifndef DRIVER_INTERFACE_H #define DRIVER_INTERFACE_H #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - /* forward(tag, m, n, d, keep, X[n][d+1], Y[m][d+1]) */ - int forward1(short tag, - int m, - int n, - int d, - int keep, - double **X, - double **Y); - - /* forward(tag, m, n, d, keep, X[n][d+1], Y[d+1]) : hos || fos || zos */ - int forward2(short tag, - int m, - int n, - int d, - int keep, - double **X, - double *Y); - - /* forward(tag, m, n, d, keep, X[n], Y[m]) : zos */ - int forward3(short tag, - int m, - int n, - int d, - int keep, - double *X, - double *Y); - - /* forward(tag, m, n, keep, X[n], Y[m]) : zos */ - int forward4(short tag, - int m, - int n, - int keep, - double *X, - double *Y); - - /* forward(tag, m, n, d, p, x[n], X[n][p][d], y[m], Y[m][p][d]) : hov */ - int forward5(short tag, - int m, - int n, - int d, - int p, - double *x, - double ***X, - double *y, - double ***Y); - - /* forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]) : fov */ - int forward6(short tag, - int m, - int n, - int p, - double *x, - double **X, - double *y, - double **Y); - - /* reverse(tag, m, n, d, u[m], Z[n][d + 1]) */ - int reverse1(short tag, - int m, - int n, - int d, - double *u, - double **Z); - - /* reverse(tag, 1, n, 0, u, Z[n][d+1]), m=1 => u scalar */ - int reverse2(short tag, - int m, - int n, - int d, - double u, - double **Z); - - /* reverse(tag, m, n, 0, u[m], Z[n]), d=0 */ - int reverse3(short tag, - int m, - int n, - int d, - double *u, - double *Z); - - /* reverse(tag, 1, n, 0, u, Z[n]), m=1 and d=0 => u and Z scalars */ - int reverse4(short tag, - int m, - int n, - int d, - double u, - double *Z); - - /* reverse(tag, m, n, d, q, U[q][m], Z[q][n][d+1], nz[q][n]) */ - int reverse5(short tag, - int m, - int n, - int d, - int q, - double **U, - double ***Z, - short **nz); - - /* reverse(tag, m, n, d, q, U[q], Z[q][n][d+1], nz[q][n]) : hov */ - int reverse6(short tag, - int m, - int n, - int d, - int q, - double *U, - double ***Z, - short **nz); - - /* reverse(tag, 1, n, d, q, U[q], Z[q][n][d+1], nz[q][n]), m=1 => u vector */ - int reverse7(short tag, - int m, - int n, - int d, - int q, - double **U, - double **Z); - - /* reverse(tag, m, n, q, U[q][m], Z[q][n]) */ - int reverse8(short tag, - int m, - int n, - int q, - double **U, - double **Z); - - /* reverse(tag, m, n, d, q, U[q], Z[q][n]) */ - int reverse9(short tag, - int m, - int n, - int d, - int q, - double *U, - double **Z); - - /* reverse(tag, m, n, d, Z[q][n][d+1], nz[q][n]) : hov */ - int reverse10(short tag, - int m, - int n, - int d, - double ***Z, - short **nz); +/* forward(tag, m, n, d, keep, X[n][d+1], Y[m][d+1]) */ +int forward1(short tag, int m, int n, int d, int keep, double **X, double **Y); + +/* forward(tag, m, n, d, keep, X[n][d+1], Y[d+1]) : hos || fos || zos */ +int forward2(short tag, int m, int n, int d, int keep, double **X, double *Y); + +/* forward(tag, m, n, d, keep, X[n], Y[m]) : zos */ +int forward3(short tag, int m, int n, int d, int keep, double *X, double *Y); + +/* forward(tag, m, n, keep, X[n], Y[m]) : zos */ +int forward4(short tag, int m, int n, int keep, double *X, double *Y); + +/* forward(tag, m, n, d, p, x[n], X[n][p][d], y[m], Y[m][p][d]) : hov */ +int forward5(short tag, int m, int n, int d, int p, double *x, double ***X, + double *y, double ***Y); + +/* forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]) : fov */ +int forward6(short tag, int m, int n, int p, double *x, double **X, double *y, + double **Y); + +/* reverse(tag, m, n, d, u[m], Z[n][d + 1]) */ +int reverse1(short tag, int m, int n, int d, double *u, double **Z); + +/* reverse(tag, 1, n, 0, u, Z[n][d+1]), m=1 => u scalar */ +int reverse2(short tag, int m, int n, int d, double u, double **Z); + +/* reverse(tag, m, n, 0, u[m], Z[n]), d=0 */ +int reverse3(short tag, int m, int n, int d, double *u, double *Z); + +/* reverse(tag, 1, n, 0, u, Z[n]), m=1 and d=0 => u and Z scalars */ +int reverse4(short tag, int m, int n, int d, double u, double *Z); + +/* reverse(tag, m, n, d, q, U[q][m], Z[q][n][d+1], nz[q][n]) */ +int reverse5(short tag, int m, int n, int d, int q, double **U, double ***Z, + short **nz); + +/* reverse(tag, m, n, d, q, U[q], Z[q][n][d+1], nz[q][n]) : hov */ +int reverse6(short tag, int m, int n, int d, int q, double *U, double ***Z, + short **nz); + +/* reverse(tag, 1, n, d, q, U[q], Z[q][n][d+1], nz[q][n]), m=1 => u vector */ +int reverse7(short tag, int m, int n, int d, int q, double **U, double **Z); + +/* reverse(tag, m, n, q, U[q][m], Z[q][n]) */ +int reverse8(short tag, int m, int n, int q, double **U, double **Z); + +/* reverse(tag, m, n, d, q, U[q], Z[q][n]) */ +int reverse9(short tag, int m, int n, int d, int q, double *U, double **Z); + +/* reverse(tag, m, n, d, Z[q][n][d+1], nz[q][n]) : hov */ +int reverse10(short tag, int m, int n, int d, double ***Z, short **nz); #ifdef __cplusplus } diff --git a/ADOL-C/examples/additional_examples/checkpointing/checkpointing.cpp b/ADOL-C/examples/additional_examples/checkpointing/checkpointing.cpp index 5a9e4e67c..4273e5d31 100644 --- a/ADOL-C/examples/additional_examples/checkpointing/checkpointing.cpp +++ b/ADOL-C/examples/additional_examples/checkpointing/checkpointing.cpp @@ -5,30 +5,28 @@ Contents: example for checkpointing Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ -#include #include +#include #define h 0.01 #define steps 100 // time step function -// double version +// double version int euler_step(int n, double *y); -// adouble version +// adouble version int euler_step_act(int n, adouble *y); int tag_full, tag_part, tag_check; - -int main() -{ +int main() { // time interval double t0, tf; @@ -43,11 +41,11 @@ int main() // target value; double f; - //variables for derivative calculation + // variables for derivative calculation double grad[2]; int i; - + // tape identifiers tag_full = 1; tag_part = 2; @@ -60,29 +58,28 @@ int main() t0 = 0.0; tf = 1.0; - //control + // control conp[0] = 1.0; conp[1] = 1.0; // basis variant: full taping of time step loop trace_on(tag_full); - con[0] <<= conp[0]; - con[1] <<= conp[1]; - y[0] = con[0]; - y[1] = con[1]; - - for(i=0;i>= f; + con[0] <<= conp[0]; + con[1] <<= conp[1]; + y[0] = con[0]; + y[1] = con[1]; + + for (i = 0; i < steps; i++) { + euler_step_act(n, y); + } + + y[0] + y[1] >>= f; trace_off(1); - gradient(tag_full,2,conp,grad); - - printf(" full taping:\n gradient=( %f, %f)\n\n",grad[0],grad[1]); + gradient(tag_full, 2, conp, grad); + + printf(" full taping:\n gradient=( %f, %f)\n\n", grad[0], grad[1]); // Now using checkpointing facilities @@ -112,40 +109,38 @@ int main() cpc.setAlwaysRetaping(false); trace_on(tag_part); - con[0] <<= conp[0]; - con[1] <<= conp[1]; - y[0] = con[0]; - y[1] = con[1]; - - cpc.checkpointing(); - - y[0] + y[1] >>= f; + con[0] <<= conp[0]; + con[1] <<= conp[1]; + y[0] = con[0]; + y[1] = con[1]; + + cpc.checkpointing(); + + y[0] + y[1] >>= f; trace_off(1); - gradient(tag_part,2,conp,grad); - - printf(" taping with checkpointing facility:\n gradient=( %f, %f)\n\n",grad[0],grad[1]); + gradient(tag_part, 2, conp, grad); + + printf(" taping with checkpointing facility:\n gradient=( %f, %f)\n\n", + grad[0], grad[1]); return 0; } -int euler_step(int n, double *y) -{ +int euler_step(int n, double *y) { - // Euler step, double version - y[0] = y[0]+h*y[0]; - y[1] = y[1]+h*2*y[1]; + // Euler step, double version + y[0] = y[0] + h * y[0]; + y[1] = y[1] + h * 2 * y[1]; - return 1; + return 1; } -int euler_step_act(int n, adouble *y) -{ +int euler_step_act(int n, adouble *y) { - // Euler step, adouble version - - y[0] = y[0]+h*y[0]; - y[1] = y[1]+h*2*y[1]; + // Euler step, adouble version - return 1; -} + y[0] = y[0] + h * y[0]; + y[1] = y[1] + h * 2 * y[1]; + return 1; +} diff --git a/ADOL-C/examples/additional_examples/clock/myclock.cpp b/ADOL-C/examples/additional_examples/clock/myclock.cpp index 9e9dfe2ee..3f71a5523 100644 --- a/ADOL-C/examples/additional_examples/clock/myclock.cpp +++ b/ADOL-C/examples/additional_examples/clock/myclock.cpp @@ -4,32 +4,29 @@ Revision: $Id$ Contents: timing utilities - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ - + /****************************************************************************/ /* INCLUDES */ +#include "myclock.h" #include #include -#include "myclock.h" - - /****************************************************************************/ /* CLOCK UTILITIES */ -double myclock( int normalize ) { - struct timeb tb; +double myclock(int normalize) { + struct timeb tb; - ftime(&tb); - return ((double)tb.time+(double)tb.millitm/1000.); + ftime(&tb); + return ((double)tb.time + (double)tb.millitm / 1000.); } void normalize() {} - diff --git a/ADOL-C/examples/additional_examples/clock/myclock.h b/ADOL-C/examples/additional_examples/clock/myclock.h index 210e1cc7a..3bc4b9ee0 100644 --- a/ADOL-C/examples/additional_examples/clock/myclock.h +++ b/ADOL-C/examples/additional_examples/clock/myclock.h @@ -4,13 +4,13 @@ Revision: $Id$ Contents: timing utilities - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #ifndef _MYCLOCK_H_ #define _MYCLOCK_H_ @@ -19,22 +19,12 @@ /* CLOCKS PER SECOND */ extern double clocksPerSecond; - /****************************************************************************/ /* CLOCK */ double myclock(int normalize = 0); - /****************************************************************************/ /* NORMALIZE CLOCK */ -void normalizeMyclock( void ); +void normalizeMyclock(void); #endif - - - - - - - - diff --git a/ADOL-C/examples/additional_examples/detexam/detexam-old.cpp b/ADOL-C/examples/additional_examples/detexam/detexam-old.cpp index 79d684dee..ac7f4c1db 100644 --- a/ADOL-C/examples/additional_examples/detexam/detexam-old.cpp +++ b/ADOL-C/examples/additional_examples/detexam/detexam-old.cpp @@ -4,204 +4,211 @@ Revision: $Id$ Contents: computation of determinants - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include #include "../clock/myclock.h" - +#include /****************************************************************************/ /* DOUBLE ROUTINE */ -int n,it; -double** PA; -double pdet( int k, int m ) { - if (m == 0) - return 1.0; - else { - double* pt = PA[k-1]; - double t = 0; - int p = 1; - int s; - if (k%2) - s = 1; - else - s = -1; - for (int i=0; i= p) { - t += *pt*s*pdet(k-1, m-p); - s = -s; - } - ++pt; - p = p1; - } - return t; +int n, it; +double **PA; +double pdet(int k, int m) { + if (m == 0) + return 1.0; + else { + double *pt = PA[k - 1]; + double t = 0; + int p = 1; + int s; + if (k % 2) + s = 1; + else + s = -1; + for (int i = 0; i < n; i++) { + int p1 = 2 * p; + if (m % p1 >= p) { + t += *pt * s * pdet(k - 1, m - p); + s = -s; + } + ++pt; + p = p1; } + return t; + } } /****************************************************************************/ /* ADOUBLE ROUTINE */ -adouble** A; -adouble det( int k, int m ) { - if (m == 0) - return 1.0; - else { - adouble* pt = A[k-1]; - adouble t = 0; - int p = 1; - int s; - if (k%2) - s = 1; - else - s = -1; - for (int i=0; i= p) { - t += *pt*s*det(k-1, m-p); - s = -s; - } - ++pt; - p = p1; - } - return t; +adouble **A; +adouble det(int k, int m) { + if (m == 0) + return 1.0; + else { + adouble *pt = A[k - 1]; + adouble t = 0; + int p = 1; + int s; + if (k % 2) + s = 1; + else + s = -1; + for (int i = 0; i < n; i++) { + int p1 = 2 * p; + if (m % p1 >= p) { + t += *pt * s * det(k - 1, m - p); + s = -s; + } + ++pt; + p = p1; } + return t; + } } /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i, j; - int tag = 1; - - /*--------------------------------------------------------------------------*/ - /* Input */ - fprintf(stdout,"COMPUTATION OF DETERMINANTS (old type) (ADOL-C Example)\n\n"); - fprintf(stdout,"order of matrix = ? \n"); - scanf("%d",&n); - A = new adouble*[n]; - PA = new double*[n]; - int n2 = n*n; - double* a = new double[n2]; - double diag = 0; - int m = 1; - - /*--------------------------------------------------------------------------*/ - /* Preparation */ - double* pa = a; - for (i=0; i>= detout; - trace_off(); - double t01 = myclock(); - fprintf(stdout,"\n %f =? %f should be the same \n",detout,diag); - - /*--------------------------------------------------------------------------*/ - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - /*--------------------------------------------------------------------------*/ - int itu = 8-n; - itu = itu*itu*itu*itu; - itu = itu > 0 ? itu : 1; - double raus; - - /*--------------------------------------------------------------------------*/ - double t10 = myclock(); /* 1. time (original) */ - for (it = 0; it < itu; it++) - raus = pdet(n,m-1); - double t11 = myclock(); - double rtu = itu/(t11-t10); - - double* B = new double[n2]; - double* detaut = new double[1]; - - /*--------------------------------------------------------------------------*/ - double t40 = myclock(); /* 4. time (forward no keep) */ - for (it = 0; it < itu; it++) - forward(tag,1,n2,0,0,a,detaut); - double t41 = myclock(); - - /*--------------------------------------------------------------------------*/ - double t20 = myclock(); /* 2. time (forward+keep) */ - for (it = 0; it < itu; it++) - forward(tag,1,n2,0,1,a,detaut); - double t21 = myclock(); - - double u[1]; - u[0] = 1.0; - - /*--------------------------------------------------------------------------*/ - double t30 = myclock(); /* 3. time (reverse) */ - for (it = 0; it < itu; it++) - reverse(tag,1,n2,0,u,B); - double t31 = myclock(); - - /*--------------------------------------------------------------------------*/ - /* output of results */ - // optional generation of tape_doc.tex - // tape_doc(tag,1,n2,a,detaut); - fprintf(stdout,"\n first base? : \n"); - for (i=0; i>= detout; + trace_off(); + double t01 = myclock(); + fprintf(stdout, "\n %f =? %f should be the same \n", detout, diag); + + /*--------------------------------------------------------------------------*/ + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + /*--------------------------------------------------------------------------*/ + int itu = 8 - n; + itu = itu * itu * itu * itu; + itu = itu > 0 ? itu : 1; + double raus; + + /*--------------------------------------------------------------------------*/ + double t10 = myclock(); /* 1. time (original) */ + for (it = 0; it < itu; it++) + raus = pdet(n, m - 1); + double t11 = myclock(); + double rtu = itu / (t11 - t10); + + double *B = new double[n2]; + double *detaut = new double[1]; + + /*--------------------------------------------------------------------------*/ + double t40 = myclock(); /* 4. time (forward no keep) */ + for (it = 0; it < itu; it++) + forward(tag, 1, n2, 0, 0, a, detaut); + double t41 = myclock(); + + /*--------------------------------------------------------------------------*/ + double t20 = myclock(); /* 2. time (forward+keep) */ + for (it = 0; it < itu; it++) + forward(tag, 1, n2, 0, 1, a, detaut); + double t21 = myclock(); + + double u[1]; + u[0] = 1.0; + + /*--------------------------------------------------------------------------*/ + double t30 = myclock(); /* 3. time (reverse) */ + for (it = 0; it < itu; it++) + reverse(tag, 1, n2, 0, u, B); + double t31 = myclock(); + + /*--------------------------------------------------------------------------*/ + /* output of results */ + // optional generation of tape_doc.tex + // tape_doc(tag,1,n2,a,detaut); + fprintf(stdout, "\n first base? : \n"); + for (i = 0; i < n; i++) { + adouble sum = 0; + adouble *pt; + pt = A[i]; + for (j = 0; j < n; j++) + sum += (*pt++) * B[j]; + fprintf(stdout, "%E ", sum.value()); + } + fprintf(stdout, "\n\n times for "); + fprintf(stdout, "\n tracing : \t%E", (t01 - t00) * rtu); + fprintf(stdout, " units \t%E seconds", (t01 - t00)); + fprintf(stdout, "\n forward (no keep): \t%E", (t41 - t40) * rtu / itu); + fprintf(stdout, " units \t%E seconds", (t41 - t40) / itu); + fprintf(stdout, "\n forward + keep : \t%E", (t21 - t20) * rtu / itu); + fprintf(stdout, " units \t%E seconds", (t21 - t20) / itu); + fprintf(stdout, "\n reverse : \t%E", (t31 - t30) * rtu / itu); + fprintf(stdout, " units \t%E seconds\n", (t31 - t30) / itu); + + return 1; } - diff --git a/ADOL-C/examples/additional_examples/detexam/detexam.cpp b/ADOL-C/examples/additional_examples/detexam/detexam.cpp index 1011ec22e..35141591c 100644 --- a/ADOL-C/examples/additional_examples/detexam/detexam.cpp +++ b/ADOL-C/examples/additional_examples/detexam/detexam.cpp @@ -4,222 +4,229 @@ Revision: $Id$ Contents: modified computation of determinants - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include #include "../clock/myclock.h" - +#include /****************************************************************************/ /* DOUBLE ROUTINE */ -int n,it; -double** PA; -double pdet( int k, int m ) { - if (m == 0) - return 1.0 ; - else { - double* pt = PA[k-1]; - double t = 0; - int p = 1; - int s; - if (k%2) - s = 1; - else - s = -1; - for (int i=0; i= p) { - if (m == p) { - if (s>0) - t += *pt; - else - t -= *pt; - } else { - if (s>0) - t += *pt*pdet(k-1, m-p); - else - t -= *pt*pdet(k-1, m-p); - } - s = -s; - } - ++pt; - p = p1; +int n, it; +double **PA; +double pdet(int k, int m) { + if (m == 0) + return 1.0; + else { + double *pt = PA[k - 1]; + double t = 0; + int p = 1; + int s; + if (k % 2) + s = 1; + else + s = -1; + for (int i = 0; i < n; i++) { + int p1 = 2 * p; + if (m % p1 >= p) { + if (m == p) { + if (s > 0) + t += *pt; + else + t -= *pt; + } else { + if (s > 0) + t += *pt * pdet(k - 1, m - p); + else + t -= *pt * pdet(k - 1, m - p); } - return t; + s = -s; + } + ++pt; + p = p1; } + return t; + } } /****************************************************************************/ /* ADOUBLE ROUTINE */ -adouble** A; +adouble **A; adouble zero = 0; -adouble det( int k, int m ) { - if (m == 0) - return 1.0; - else { - adouble* pt = A[k-1]; - adouble t = zero; - int p = 1; - int s; - if (k%2) - s = 1; - else - s = -1; - for (int i=0; i= p) { - if (m == p) { - if (s>0) - t += *pt; - else - t -= *pt; - } else { - if (s>0) - t += *pt*det(k-1, m-p); - else - t -= *pt*det(k-1, m-p); - } - s = -s; - } - ++pt; - p = p1; +adouble det(int k, int m) { + if (m == 0) + return 1.0; + else { + adouble *pt = A[k - 1]; + adouble t = zero; + int p = 1; + int s; + if (k % 2) + s = 1; + else + s = -1; + for (int i = 0; i < n; i++) { + int p1 = 2 * p; + if (m % p1 >= p) { + if (m == p) { + if (s > 0) + t += *pt; + else + t -= *pt; + } else { + if (s > 0) + t += *pt * det(k - 1, m - p); + else + t -= *pt * det(k - 1, m - p); } - return t; + s = -s; + } + ++pt; + p = p1; } + return t; + } } /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i, j; - int tag = 1; - fprintf(stdout,"COMPUTATION OF DETERMINANTS Type 1 (ADOL-C Example)\n\n"); - fprintf(stdout,"order of matrix = ? \n"); - scanf("%d",&n); - A = new adouble*[n]; - PA = new double*[n]; - int n2 = n*n; - double* a = new double[n2]; - - /*--------------------------------------------------------------------------*/ - /* Preparation */ - double diag = 0; - int m = 1; - double* pa = a; - for (i=0; i>= detout; - trace_off(); - double t01 = myclock(); - fprintf(stdout,"\n %f =? %f should be the same \n",detout,diag); - - /*--------------------------------------------------------------------------*/ - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - /*--------------------------------------------------------------------------*/ - int itu = 8-n; - itu = itu*itu*itu*itu; - itu = itu > 0 ? itu : 1; - double raus; - - /*--------------------------------------------------------------------------*/ - double t10 = myclock(); /* 1. time (original) */ - for (it = 0; it < itu; it++) - raus = pdet(n,m-1); - double t11 = myclock(); - double rtu = itu/(t11-t10); - - double* B = new double[n2]; - double* detaut = new double[1]; - - /*--------------------------------------------------------------------------*/ - double t40 = myclock(); /* 4. time (forward no keep) */ - for (it = 0; it < itu; it++) - forward(tag,1,n2,0,a,detaut); - double t41 = myclock(); - - /*--------------------------------------------------------------------------*/ - double t20 = myclock(); /* 2. time (forward+keep) */ - for(it = 0; it < itu; it++) - forward(tag,1,n2,1,a,detaut); - double t21 = myclock(); - // fprintf(stdout,"\n %f =? %f should be the same \n",detout,*detaut); - - double u[1]; - u[0] = 1.0; - - /*--------------------------------------------------------------------------*/ - double t30 = myclock(); /* 3. time (reverse) */ - for (it = 0; it < itu; it++) - reverse(tag,1,n2,0,u,B); - double t31 = myclock(); - - /*--------------------------------------------------------------------------*/ - /* output of results */ - // optional generation of tape_doc.tex - // tape_doc(tag,1,n2,a,detaut); - fprintf(stdout,"\n first base? : \n"); - for (i=0; i>= detout; + trace_off(); + double t01 = myclock(); + fprintf(stdout, "\n %f =? %f should be the same \n", detout, diag); + + /*--------------------------------------------------------------------------*/ + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + /*--------------------------------------------------------------------------*/ + int itu = 8 - n; + itu = itu * itu * itu * itu; + itu = itu > 0 ? itu : 1; + double raus; + + /*--------------------------------------------------------------------------*/ + double t10 = myclock(); /* 1. time (original) */ + for (it = 0; it < itu; it++) + raus = pdet(n, m - 1); + double t11 = myclock(); + double rtu = itu / (t11 - t10); + + double *B = new double[n2]; + double *detaut = new double[1]; + + /*--------------------------------------------------------------------------*/ + double t40 = myclock(); /* 4. time (forward no keep) */ + for (it = 0; it < itu; it++) + forward(tag, 1, n2, 0, a, detaut); + double t41 = myclock(); + + /*--------------------------------------------------------------------------*/ + double t20 = myclock(); /* 2. time (forward+keep) */ + for (it = 0; it < itu; it++) + forward(tag, 1, n2, 1, a, detaut); + double t21 = myclock(); + // fprintf(stdout,"\n %f =? %f should be the same \n",detout,*detaut); + + double u[1]; + u[0] = 1.0; + + /*--------------------------------------------------------------------------*/ + double t30 = myclock(); /* 3. time (reverse) */ + for (it = 0; it < itu; it++) + reverse(tag, 1, n2, 0, u, B); + double t31 = myclock(); + + /*--------------------------------------------------------------------------*/ + /* output of results */ + // optional generation of tape_doc.tex + // tape_doc(tag,1,n2,a,detaut); + fprintf(stdout, "\n first base? : \n"); + for (i = 0; i < n; i++) { + adouble sum = 0; + adouble *pt; + pt = A[i]; + for (j = 0; j < n; j++) + sum += (*pt++) * B[j]; + fprintf(stdout, "%E ", sum.value()); + } + fprintf(stdout, "\n\n times for "); + fprintf(stdout, "\n tracing : \t%E", (t01 - t00) * rtu); + fprintf(stdout, " units \t%E seconds", (t01 - t00)); + fprintf(stdout, "\n forward (no keep): \t%E", (t41 - t40) * rtu / itu); + fprintf(stdout, " units \t%E seconds", (t41 - t40) / itu); + fprintf(stdout, "\n forward + keep : \t%E", (t21 - t20) * rtu / itu); + fprintf(stdout, " units \t%E seconds", (t21 - t20) / itu); + fprintf(stdout, "\n reverse : \t%E", (t31 - t30) * rtu / itu); + fprintf(stdout, " units \t%E seconds\n", (t31 - t30) / itu); + + return 1; } diff --git a/ADOL-C/examples/additional_examples/ext_diff_func/edfootest.cpp b/ADOL-C/examples/additional_examples/ext_diff_func/edfootest.cpp index 78fb72f08..e9ac9e7bd 100644 --- a/ADOL-C/examples/additional_examples/ext_diff_func/edfootest.cpp +++ b/ADOL-C/examples/additional_examples/ext_diff_func/edfootest.cpp @@ -5,15 +5,15 @@ Contents: example for external differentiated functions Copyright (c) Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ -#include #include #include +#include #define h 0.01 #define steps 100 @@ -22,67 +22,69 @@ using namespace std; class euler_step_edf : public EDFobject { protected: - short tag_ext_fct; + short tag_ext_fct; + public: - euler_step_edf(short tag) : tag_ext_fct(tag), EDFobject() {} - virtual ~euler_step_edf() {} - virtual int function(int n, double *yin, int m, double *yout) { - // Euler step, double version - yout[0] = yin[0]+h*yin[0]; - yout[1] = yin[1]+h*2*yin[1]; - return 1; - } - virtual int zos_forward(int n, double *yin, int m, double *yout) { - int rc; - set_nested_ctx(tag_ext_fct,true); - rc = ::zos_forward(tag_ext_fct, 2, 2, 0, yin, yout); - set_nested_ctx(tag_ext_fct,false); - return rc; - } - virtual int fos_forward(int n, double *yin, double *yindot, int m, double *yout, double *youtdot) { - int rc; - set_nested_ctx(tag_ext_fct,true); - rc = ::fos_forward(tag_ext_fct, 2, 2, 0, yin, yindot, yout, youtdot); - set_nested_ctx(tag_ext_fct,false); - return rc; - } - virtual int fov_forward(int n, double *yin, int p, double **yindot, int m, double *yout, double **youtdot) { - int rc; - set_nested_ctx(tag_ext_fct,true); - rc = ::fov_forward(tag_ext_fct, 2, 2, p, yin, yindot, yout, youtdot); - set_nested_ctx(tag_ext_fct,false); - return rc; - } - virtual int fos_reverse(int n, double *u, int m, double *z, double */* unused */, double */*unused*/) { - int rc; - set_nested_ctx(tag_ext_fct,true); - ::zos_forward(tag_ext_fct, 2, 2, 1, edf->dp_x, edf->dp_y); - rc = ::fos_reverse(tag_ext_fct, 2, 2, u, z); - set_nested_ctx(tag_ext_fct,false); - return rc; - } - virtual int fov_reverse(int n, int p, double **U, int m, double **Z, double */* unused */, double */*unused*/) { - int rc; - set_nested_ctx(tag_ext_fct,true); - ::zos_forward(tag_ext_fct, 2, 2, 1, edf->dp_x, edf->dp_y); - rc = ::fov_reverse(tag_ext_fct, 2, 2, p, U, Z); - set_nested_ctx(tag_ext_fct,false); - return rc; - } + euler_step_edf(short tag) : tag_ext_fct(tag), EDFobject() {} + virtual ~euler_step_edf() {} + virtual int function(int n, double *yin, int m, double *yout) { + // Euler step, double version + yout[0] = yin[0] + h * yin[0]; + yout[1] = yin[1] + h * 2 * yin[1]; + return 1; + } + virtual int zos_forward(int n, double *yin, int m, double *yout) { + int rc; + set_nested_ctx(tag_ext_fct, true); + rc = ::zos_forward(tag_ext_fct, 2, 2, 0, yin, yout); + set_nested_ctx(tag_ext_fct, false); + return rc; + } + virtual int fos_forward(int n, double *yin, double *yindot, int m, + double *yout, double *youtdot) { + int rc; + set_nested_ctx(tag_ext_fct, true); + rc = ::fos_forward(tag_ext_fct, 2, 2, 0, yin, yindot, yout, youtdot); + set_nested_ctx(tag_ext_fct, false); + return rc; + } + virtual int fov_forward(int n, double *yin, int p, double **yindot, int m, + double *yout, double **youtdot) { + int rc; + set_nested_ctx(tag_ext_fct, true); + rc = ::fov_forward(tag_ext_fct, 2, 2, p, yin, yindot, yout, youtdot); + set_nested_ctx(tag_ext_fct, false); + return rc; + } + virtual int fos_reverse(int n, double *u, int m, double *z, + double * /* unused */, double * /*unused*/) { + int rc; + set_nested_ctx(tag_ext_fct, true); + ::zos_forward(tag_ext_fct, 2, 2, 1, edf->dp_x, edf->dp_y); + rc = ::fos_reverse(tag_ext_fct, 2, 2, u, z); + set_nested_ctx(tag_ext_fct, false); + return rc; + } + virtual int fov_reverse(int n, int p, double **U, int m, double **Z, + double * /* unused */, double * /*unused*/) { + int rc; + set_nested_ctx(tag_ext_fct, true); + ::zos_forward(tag_ext_fct, 2, 2, 1, edf->dp_x, edf->dp_y); + rc = ::fov_reverse(tag_ext_fct, 2, 2, p, U, Z); + set_nested_ctx(tag_ext_fct, false); + return rc; + } }; -void euler_step_act(int n, adouble *yin, int m, adouble *yout) -{ +void euler_step_act(int n, adouble *yin, int m, adouble *yout) { - // Euler step, adouble version - - yout[0] = yin[0]+h*yin[0]; - yout[1] = yin[1]+h*2*yin[1]; -} + // Euler step, adouble version + yout[0] = yin[0] + h * yin[0]; + yout[1] = yin[1] + h * 2 * yin[1]; +} -int main() -{ +int main() { // time interval double t0, tf; @@ -98,14 +100,13 @@ int main() // target value; double f; - //variables for derivative caluclation + // variables for derivative caluclation double yp[2], ynewp[2]; double u[2], z[2]; double grad[2]; + int i, j; - int i,j; - // tape identifiers short tag_full = 1; short tag_part = 2; @@ -120,62 +121,60 @@ int main() t0 = 0.0; tf = 1.0; - //control + // control conp[0] = 1.0; conp[1] = 1.0; trace_on(tag_full); - con[0] <<= conp[0]; - con[1] <<= conp[1]; - y[0] = con[0]; - y[1] = con[1]; - - for(i=0;i>= f; + con[0] <<= conp[0]; + con[1] <<= conp[1]; + y[0] = con[0]; + y[1] = con[1]; + + for (i = 0; i < steps; i++) { + euler_step_act(n, y, m, ynew); + for (j = 0; j < 2; j++) + y[j] = ynew[j]; + } + y[0] + y[1] >>= f; trace_off(1); - gradient(tag_full,2,conp,grad); - - printf(" full taping:\n gradient=( %f, %f)\n\n",grad[0],grad[1]); + gradient(tag_full, 2, conp, grad); + + printf(" full taping:\n gradient=( %f, %f)\n\n", grad[0], grad[1]); // Now using external function facilities // tape external differentiated function trace_on(tag_ext_fct); - y[0] <<= conp[0]; - y[1] <<= conp[1]; - - euler_step_act(2,y,2,ynew); - ynew[0] >>= f; - ynew[1] >>= f; + y[0] <<= conp[0]; + y[1] <<= conp[1]; + + euler_step_act(2, y, 2, ynew); + ynew[0] >>= f; + ynew[1] >>= f; trace_off(1); euler_step_edf edf(tag_ext_fct); trace_on(tag_part); - con[0] <<= conp[0]; - con[1] <<= conp[1]; - y[0] = con[0]; - y[1] = con[1]; - - for(i=0;i>= f; + con[0] <<= conp[0]; + con[1] <<= conp[1]; + y[0] = con[0]; + y[1] = con[1]; + + for (i = 0; i < steps; i++) { + edf.call(2, y, 2, ynew); + for (j = 0; j < 2; j++) + y[j] = ynew[j]; + } + y[0] + y[1] >>= f; trace_off(1); - gradient(tag_part,2,conp,grad); - - printf(" taping with external function facility:\n gradient=( %f, %f)\n\n",grad[0],grad[1]); + gradient(tag_part, 2, conp, grad); - return 0; + printf(" taping with external function facility:\n gradient=( %f, %f)\n\n", + grad[0], grad[1]); + return 0; } diff --git a/ADOL-C/examples/additional_examples/ext_diff_func/ext_diff_func.cpp b/ADOL-C/examples/additional_examples/ext_diff_func/ext_diff_func.cpp index dd77c030a..62daf98ab 100644 --- a/ADOL-C/examples/additional_examples/ext_diff_func/ext_diff_func.cpp +++ b/ADOL-C/examples/additional_examples/ext_diff_func/ext_diff_func.cpp @@ -5,26 +5,25 @@ Contents: example for external differentiated functions Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ -#include #include +#include #define h 0.01 #define steps 100 // time step function -// double version +// double version int euler_step(int n, double *yin, int m, double *yout); -// adouble version +// adouble version void euler_step_act(int n, adouble *yin, int m, adouble *yout); - // versions for usage as external differentiated function ADOLC_ext_fct zos_for_euler_step; ADOLC_ext_fct_fos_reverse fos_rev_euler_step; @@ -32,9 +31,7 @@ ADOLC_ext_fct_fos_reverse fos_rev_euler_step; ext_diff_fct *edf; int tag_full, tag_part, tag_ext_fct; - -int main() -{ +int main() { // time interval double t0, tf; @@ -50,14 +47,13 @@ int main() // target value; double f; - //variables for derivative caluclation + // variables for derivative caluclation double yp[2], ynewp[2]; double u[2], z[2]; double grad[2]; + int i, j; - int i,j; - // tape identifiers tag_full = 1; tag_part = 2; @@ -72,49 +68,47 @@ int main() t0 = 0.0; tf = 1.0; - //control + // control conp[0] = 1.0; conp[1] = 1.0; trace_on(tag_full); - con[0] <<= conp[0]; - con[1] <<= conp[1]; - y[0] = con[0]; - y[1] = con[1]; - - for(i=0;i>= f; + con[0] <<= conp[0]; + con[1] <<= conp[1]; + y[0] = con[0]; + y[1] = con[1]; + + for (i = 0; i < steps; i++) { + euler_step_act(n, y, m, ynew); + for (j = 0; j < 2; j++) + y[j] = ynew[j]; + } + y[0] + y[1] >>= f; trace_off(1); - gradient(tag_full,2,conp,grad); - - printf(" full taping:\n gradient=( %f, %f)\n\n",grad[0],grad[1]); + gradient(tag_full, 2, conp, grad); + + printf(" full taping:\n gradient=( %f, %f)\n\n", grad[0], grad[1]); // Now using external function facilities // tape external differentiated function trace_on(tag_ext_fct); - y[0] <<= conp[0]; - y[1] <<= conp[1]; - - euler_step_act(2,y,2,ynew); - ynew[0] >>= f; - ynew[1] >>= f; - trace_off(1); + y[0] <<= conp[0]; + y[1] <<= conp[1]; + euler_step_act(2, y, 2, ynew); + ynew[0] >>= f; + ynew[1] >>= f; + trace_off(1); // register external function edf = reg_ext_fct(euler_step); // information for Zero-Order-Scalar (=zos) forward -// yp = new double[2]; -// ynewp = new double[2]; + // yp = new double[2]; + // ynewp = new double[2]; edf->zos_forward = zos_for_euler_step; edf->dp_x = yp; edf->dp_y = ynewp; @@ -124,64 +118,61 @@ int main() edf->dp_Z = z; trace_on(tag_part); - con[0] <<= conp[0]; - con[1] <<= conp[1]; - y[0] = con[0]; - y[1] = con[1]; - - for(i=0;i>= f; + con[0] <<= conp[0]; + con[1] <<= conp[1]; + y[0] = con[0]; + y[1] = con[1]; + + for (i = 0; i < steps; i++) { + call_ext_fct(edf, 2, y, 2, ynew); + for (j = 0; j < 2; j++) + y[j] = ynew[j]; + } + y[0] + y[1] >>= f; trace_off(1); - gradient(tag_part,2,conp,grad); - - printf(" taping with external function facility:\n gradient=( %f, %f)\n\n",grad[0],grad[1]); + gradient(tag_part, 2, conp, grad); + + printf(" taping with external function facility:\n gradient=( %f, %f)\n\n", + grad[0], grad[1]); return 0; } -void euler_step_act(int n, adouble *yin, int m, adouble *yout) -{ +void euler_step_act(int n, adouble *yin, int m, adouble *yout) { + + // Euler step, adouble version - // Euler step, adouble version - - yout[0] = yin[0]+h*yin[0]; - yout[1] = yin[1]+h*2*yin[1]; + yout[0] = yin[0] + h * yin[0]; + yout[1] = yin[1] + h * 2 * yin[1]; } -int euler_step(int n, double *yin, int m, double *yout) -{ +int euler_step(int n, double *yin, int m, double *yout) { - // Euler step, double version - yout[0] = yin[0]+h*yin[0]; - yout[1] = yin[1]+h*2*yin[1]; + // Euler step, double version + yout[0] = yin[0] + h * yin[0]; + yout[1] = yin[1] + h * 2 * yin[1]; - return 1; + return 1; } -int zos_for_euler_step(int n, double *yin, int m, double *yout) -{ +int zos_for_euler_step(int n, double *yin, int m, double *yout) { int rc; - set_nested_ctx(tag_ext_fct,true); + set_nested_ctx(tag_ext_fct, true); rc = zos_forward(tag_ext_fct, 2, 2, 0, yin, yout); - set_nested_ctx(tag_ext_fct,false); + set_nested_ctx(tag_ext_fct, false); return rc; } -int fos_rev_euler_step(int n, double *u, int m, double *z, double */* unused */, double */*unused*/) -{ +int fos_rev_euler_step(int n, double *u, int m, double *z, + double * /* unused */, double * /*unused*/) { int rc; - set_nested_ctx(tag_ext_fct,true); + set_nested_ctx(tag_ext_fct, true); zos_forward(tag_ext_fct, 2, 2, 1, edf->dp_x, edf->dp_y); rc = fos_reverse(tag_ext_fct, 2, 2, u, z); - set_nested_ctx(tag_ext_fct,false); + set_nested_ctx(tag_ext_fct, false); return rc; } diff --git a/ADOL-C/examples/additional_examples/fixpoint_exam/fixpoint_exam.cpp b/ADOL-C/examples/additional_examples/fixpoint_exam/fixpoint_exam.cpp index 04bd9c8a5..f2e8e0c3f 100644 --- a/ADOL-C/examples/additional_examples/fixpoint_exam/fixpoint_exam.cpp +++ b/ADOL-C/examples/additional_examples/fixpoint_exam/fixpoint_exam.cpp @@ -5,111 +5,99 @@ Contents: example for differentiation of fixpoint iterations Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ -#include #include +#include #define imax 100 #define imax_deriv 100 // fixpoint iteration -// double version +// double version int fixpoint_iter(double *x, double *u, double *y, int dim_x, int dim_u); double norm(double *x, int dim_x); -// adouble version +// adouble version int fixpoint_iter_act(adouble *x, adouble *u, adouble *y, int dim_x, int dim_u); adouble norm(adouble *x, int dim_x); - int tag_full, tag_part, tag_fixpoint; - -int main() -{ +int main() { adouble x[1]; adouble u[1]; adouble y[1]; adouble diff[1]; - double eps=1.0e-6; - + double eps = 1.0e-6; + double up[1]; double yp[1]; double grad[1]; int i; - + tag_full = 1; tag_part = 2; tag_fixpoint = 3; trace_on(tag_full); - i = 0; - u[0] <<= 0.5; - y[0] = 1.57079632679; - - do - { - i++; - x[0] = y[0]; - fixpoint_iter_act(x,u,y,1,1); - printf(" i = %3d y = %12.9f\n",i,y[0].value()); - diff[0] = x[0]-y[0]; - } - while((norm(diff,1)>eps) && (i>= yp[0]; + i = 0; + u[0] <<= 0.5; + y[0] = 1.57079632679; + + do { + i++; + x[0] = y[0]; + fixpoint_iter_act(x, u, y, 1, 1); + printf(" i = %3d y = %12.9f\n", i, y[0].value()); + diff[0] = x[0] - y[0]; + } while ((norm(diff, 1) > eps) && (i < imax)); + y[0] >>= yp[0]; trace_off(1); up[0] = 0.5; - gradient(tag_full,1,up,grad); + gradient(tag_full, 1, up, grad); - printf("\n full taping:\n gradient = ( %f )\n",grad[0]); + printf("\n full taping:\n gradient = ( %f )\n", grad[0]); printf("\n taping with fixpoint facility:\n\n"); trace_on(tag_part); - i = 0; - u[0] <<= 0.5; - x[0] = 1.57079632679; + i = 0; + u[0] <<= 0.5; + x[0] = 1.57079632679; - fp_iteration(tag_fixpoint,fixpoint_iter,fixpoint_iter_act,norm,norm,eps,eps,imax,imax_deriv,x,u,y,1,1); + fp_iteration(tag_fixpoint, fixpoint_iter, fixpoint_iter_act, norm, norm, eps, + eps, imax, imax_deriv, x, u, y, 1, 1); - y[0] >>= yp[0]; + y[0] >>= yp[0]; trace_off(1); up[0] = 0.5; - gradient(tag_part,1,up,grad); + gradient(tag_part, 1, up, grad); - printf("\n=> gradient = ( %f )\n",grad[0]); + printf("\n=> gradient = ( %f )\n", grad[0]); return 0; } -int fixpoint_iter(double *x, double *u, double *y, int dim_x, int dim_u) -{ - y[0] = u[0]*(x[0]+cos(x[0])); - +int fixpoint_iter(double *x, double *u, double *y, int dim_x, int dim_u) { + y[0] = u[0] * (x[0] + cos(x[0])); + return 0; } -double norm(double *x, int dim_x) -{ - return fabs(x[0]); -} +double norm(double *x, int dim_x) { return fabs(x[0]); } -int fixpoint_iter_act(adouble *x, adouble *u, adouble *y, int dim_x, int dim_u) -{ - y[0] = u[0]*(x[0]+cos(x[0])); - - return 0; -} +int fixpoint_iter_act(adouble *x, adouble *u, adouble *y, int dim_x, + int dim_u) { + y[0] = u[0] * (x[0] + cos(x[0])); -adouble norm(adouble *x, int dim_x) -{ - return fabs(x[0]); + return 0; } +adouble norm(adouble *x, int dim_x) { return fabs(x[0]); } diff --git a/ADOL-C/examples/additional_examples/helm/helm-auto-exam.cpp b/ADOL-C/examples/additional_examples/helm/helm-auto-exam.cpp index 8e0530048..5a32c6ffd 100644 --- a/ADOL-C/examples/additional_examples/helm/helm-auto-exam.cpp +++ b/ADOL-C/examples/additional_examples/helm/helm-auto-exam.cpp @@ -2,16 +2,16 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: helm-auto-exam.cpp Revision: $Id$ - Contents: example for Helmholtz energy example + Contents: example for Helmholtz energy example Computes gradient using AD driver reverse(..) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ @@ -20,86 +20,80 @@ #include - /****************************************************************************/ /* CONSTANTS & VARIABLES */ const double TE = 0.01; /* originally 0.0 */ -const double R = sqrt(2.0); - +const double R = sqrt(2.0); /****************************************************************************/ /* HELMHOLTZ ENERGY */ -adouble energy( int n, adouble x[], double bv[] ) { - adouble he, xax, bx, tem; - int i,j; - xax = 0; - bx = 0; - he = 0; - for (i=0; i>= result; - trace_off(); - fprintf(stdout, "%14.6E -- energy\n",result); - - /*--------------------------------------------------------------------------*/ - reverse(1,1,n,0,1.0,grad); /* reverse computation of gradient */ - - /*--------------------------------------------------------------------------*/ - for (l=0; l>= result; + trace_off(); + fprintf(stdout, "%14.6E -- energy\n", result); + + /*--------------------------------------------------------------------------*/ + reverse(1, 1, n, 0, 1.0, grad); /* reverse computation of gradient */ + + /*--------------------------------------------------------------------------*/ + for (l = 0; l < n; l++) /* results */ + fprintf(stdout, "%3d: %14.6E, \n", l, grad[l]); + fprintf(stdout, "%14.6E -- energy\n", result); + + delete[] x; + delete[] bv; + delete[] grad; + + return 1; } - /****************************************************************************/ /* THAT'S ALL */ - diff --git a/ADOL-C/examples/additional_examples/helm/helm-diff-exam.cpp b/ADOL-C/examples/additional_examples/helm/helm-diff-exam.cpp index b977d5450..32d5b97fb 100644 --- a/ADOL-C/examples/additional_examples/helm/helm-diff-exam.cpp +++ b/ADOL-C/examples/additional_examples/helm/helm-diff-exam.cpp @@ -2,105 +2,101 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: helm-diff-exam.cpp Revision: $Id$ - Contents: example for Helmholtz energy example + Contents: example for Helmholtz energy example Computes gradient using divide differences - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include #include +#include -#include #include - +#include /****************************************************************************/ /* CONSTANTS & VARIABLES */ #define delta 0.000001 -#define TE 0.01 -#define R sqrt(2.0) - +#define TE 0.01 +#define R sqrt(2.0) /****************************************************************************/ /* HELMHOLTZ ENERGY */ -double energy( int n, double x[], double bv[] ) { - double he, xax, bx, tem; - int i,j; - xax = 0; - bx = 0; - he = 0; - for (i=0; i -#include #include +#include using namespace std; /****************************************************************************/ /* MAIN */ int main() { - int i,j,l,m,n,d,q,bd, keep; - - /*--------------------------------------------------------------------------*/ - /* inputs */ - cout << "vector x Hessian x matrix for the function \n\n"; - cout << " y[0] = cos(x[0])* ...*cos(x[n]) \n"; - cout << " y[1] = x[0]^n \n"; - cout << " y[2] = condassign(y[i],y[0]>y[1],y[1],y[0]) \n"; - cout << " y[3] = sin(x[0])+ ...+sin(x[n]) \n"; - cout << " y[4] = exp(x[0])- ...-exp(x[n]) \n"; - cout << " y[5] = pow(y[1],3) \n"; - cout << " y[6] += y[5]*y[4] \n"; - cout << " y[7] -= y[6]*y[5] \n"; - cout << " y[j] = 1/x[0]/ .../x[n], j > 3 \n\n"; - - cout << " Number of independents = ?\n "; - cin >> n; - cout << " Number of dependents = ?\n "; - cin >> m; - cout << " Degree d (for forward) = ?\n"; - cin >> d; - cout << " keep (degree of corresponding reverse = keep-1) = ?\n"; - cout << " keep <= d+1 must be valid \n"; - cin >> keep; - cout << " Number of directions = ?\n "; - cin >> q; - - /*--------------------------------------------------------------------------*/ - /* allocations and inits */ - - double* xp = new double[n]; /* passive indeps */ - double* yp = new double[m]; /* passive depends */ - - /* vector x Hessian x matrix = Upp x H x XPPP */ - - double* Up = myalloc(m); /* vector on left-hand side */ - double** Upp = myalloc(m,d+1); /* vector on left-hand side */ - double*** Xppp = myalloc(n,q,d); /* matrix on right-hand side */ - double*** Zppp = myalloc(q,n,d+1); /* result of Up x H x XPPP */ - - double*** Yppp = myalloc(m,q,d); /* results of needed hos_wk_forward */ - - /* check results with usual lagra-Hess-vec */ - - double** Xpp = myalloc(n,d); - double** V = myalloc(n,q); - double** W = myalloc(q,n); - double** H = myalloc(n,n); - double** Ypp = myalloc(m,d); - double** Zpp = myalloc(n,d+1); - /* inits */ - - for (l=0; ly[1],y[1],y[0]) \n"; + cout << " y[3] = sin(x[0])+ ...+sin(x[n]) \n"; + cout << " y[4] = exp(x[0])- ...-exp(x[n]) \n"; + cout << " y[5] = pow(y[1],3) \n"; + cout << " y[6] += y[5]*y[4] \n"; + cout << " y[7] -= y[6]*y[5] \n"; + cout << " y[j] = 1/x[0]/ .../x[n], j > 3 \n\n"; + + cout << " Number of independents = ?\n "; + cin >> n; + cout << " Number of dependents = ?\n "; + cin >> m; + cout << " Degree d (for forward) = ?\n"; + cin >> d; + cout << " keep (degree of corresponding reverse = keep-1) = ?\n"; + cout << " keep <= d+1 must be valid \n"; + cin >> keep; + cout << " Number of directions = ?\n "; + cin >> q; + + /*--------------------------------------------------------------------------*/ + /* allocations and inits */ + + double *xp = new double[n]; /* passive indeps */ + double *yp = new double[m]; /* passive depends */ + + /* vector x Hessian x matrix = Upp x H x XPPP */ + + double *Up = myalloc(m); /* vector on left-hand side */ + double **Upp = myalloc(m, d + 1); /* vector on left-hand side */ + double ***Xppp = myalloc(n, q, d); /* matrix on right-hand side */ + double ***Zppp = myalloc(q, n, d + 1); /* result of Up x H x XPPP */ + + double ***Yppp = myalloc(m, q, d); /* results of needed hos_wk_forward */ + + /* check results with usual lagra-Hess-vec */ + + double **Xpp = myalloc(n, d); + double **V = myalloc(n, q); + double **W = myalloc(q, n); + double **H = myalloc(n, n); + double **Ypp = myalloc(m, d); + double **Zpp = myalloc(n, d + 1); + /* inits */ + + for (l = 0; l < d; l++) /* first everything is set to zero */ + for (i = 0; i < n; i++) + for (j = 0; j < q; j++) + Xppp[i][j][l] = 0; + + /* now carthesian directions as choosen as */ + /* matrix on right-hand side of Up x H x XPPP */ + bd = (n < q) ? n : q; + for (j = 0; j < bd; j++) + Xppp[j][j][0] = 1; + + for (i = 0; i < m; i++) /* vector on left-hand side of Up x H x XPPP */ + { + Up[i] = 1; /* is initialised with 1's */ + Upp[i][0] = 1; + for (j = 1; j <= d; j++) + Upp[i][j] = 0; + } + + for (i = 0; i < n; i++) /* first everything is set to zero */ + for (j = 0; j < d; j++) + Xpp[i][j] = 0; + Xpp[0][0] = 1; /* now one carthesian direction as choosen */ + /* as vector for lagra-Hess-vec */ + + for (i = 0; i < n; i++) /* inits of passive indeps */ + xp[i] = (i + 1.0) / (2.0 + i); + + for (i = 0; i < n; i++) { + for (j = 0; j < q; j++) + V[i][j] = 0; + if (i < q) + V[i][i] = 1; + } + + /*--------------------------------------------------------------------------*/ + trace_on(1); /* tracing the function */ + + adouble *x = new adouble[n]; /* active indeps */ + adouble *y = new adouble[m]; /* active depends */ + for (i = 0; i < m; i++) + y[i] = 1; + for (i = 0; i < n; i++) { + x[i] <<= xp[i]; + y[0] *= cos(x[i]); + } + + for (i = 1; i < m; i++) + for (j = 0; j < n; j++) { + switch (i) { + case 1: + y[i] *= x[0]; + break; + case 2: #ifndef ADOLC_ADVANCED_BRANCHING - condassign(y[i],adouble(y[0]>y[1]),y[1],y[0]); -#else - condassign(y[i],(y[0]>y[1]),y[1],y[0]); -#endif - break; - case 3 : - y[i] -= sin(x[j]); - break; - case 4 : - y[i] -= exp(x[j]); - break; - case 5 : - y[5] = pow(y[1],3); - case 6 : - y[6] += y[5]*y[4]; - case 7 : - y[7] -= y[6]*y[5]; - default : - y[i] /= x[j]; - } - } - for (i=0; i>= yp[i] ; - trace_off(); - - - /*--------------------------------------------------------------------------*/ - /* work on the tape */ - - - /* compute results of lagra_hess_vec */ - /* the following is equal to calls inside of lagra_hess_vec(..) */ - /* direct calls to the basic routines hos_forward and hos_reverse */ - /* seem to be faster than call of lagra_hess_vec(..) */ - /* at least in some of our test cases */ - - hos_forward(1,m,n,d,keep,xp,Xpp,yp,Ypp); - hos_reverse(1,m,n,keep-1,Up,Zpp); - - printf("\n Results of hos_reverse:\n\n"); - - for (i=0; i<=d; i++) { - printf(" d = %d \n",i); - for (j=0;j y[1]), y[1], y[0]); +#else + condassign(y[i], (y[0] > y[1]), y[1], y[0]); +#endif + break; + case 3: + y[i] -= sin(x[j]); + break; + case 4: + y[i] -= exp(x[j]); + break; + case 5: + y[5] = pow(y[1], 3); + case 6: + y[6] += y[5] * y[4]; + case 7: + y[7] -= y[6] * y[5]; + default: + y[i] /= x[j]; + } } - - /* The new drivers. First, hov_wk_forward(..) is called. - So far, it was impossible to store the results of - a higher-order-vector (=hov) forward in order to perform - a corresponding reverse sweep (for no particular reason. - Now we have hov with keep (=wk) and the results needed on - the way back are stored in a specific tape */ - - hov_wk_forward(1,m,n,d,keep,q,xp,Xppp,yp,Yppp); - - /* The corresponding reverse sweep - So far we had only a higher-order-scalar (=hos, scalar because - only one vector on the left-hand-side) for a scalar forward - call. - Now, we use the stored vector information (= hos vector) - to compute multiple lagra_hess_vec at once */ - - hos_ov_reverse(1,m,n,keep-1,q,Upp,Zppp); - - printf("\n Results of hos_ov_reverse:\n"); - - for (l=0; l>= yp[i]; + trace_off(); + + /*--------------------------------------------------------------------------*/ + /* work on the tape */ + + /* compute results of lagra_hess_vec */ + /* the following is equal to calls inside of lagra_hess_vec(..) */ + /* direct calls to the basic routines hos_forward and hos_reverse */ + /* seem to be faster than call of lagra_hess_vec(..) */ + /* at least in some of our test cases */ + + hos_forward(1, m, n, d, keep, xp, Xpp, yp, Ypp); + hos_reverse(1, m, n, keep - 1, Up, Zpp); + + printf("\n Results of hos_reverse:\n\n"); + + for (i = 0; i <= d; i++) { + printf(" d = %d \n", i); + for (j = 0; j < n; j++) + printf(" %6.3f ", Zpp[j][i]); + printf("\n"); + } + + /* The new drivers. First, hov_wk_forward(..) is called. + So far, it was impossible to store the results of + a higher-order-vector (=hov) forward in order to perform + a corresponding reverse sweep (for no particular reason. + Now we have hov with keep (=wk) and the results needed on + the way back are stored in a specific tape */ + + hov_wk_forward(1, m, n, d, keep, q, xp, Xppp, yp, Yppp); + + /* The corresponding reverse sweep + So far we had only a higher-order-scalar (=hos, scalar because + only one vector on the left-hand-side) for a scalar forward + call. + Now, we use the stored vector information (= hos vector) + to compute multiple lagra_hess_vec at once */ + + hos_ov_reverse(1, m, n, keep - 1, q, Upp, Zppp); + + printf("\n Results of hos_ov_reverse:\n"); + + for (l = 0; l < q; l++) { + for (i = 0; i <= d; i++) { + printf(" d = %d \n", i); + for (j = 0; j < n; j++) + printf(" %6.3f ", Zppp[l][j][i]); + printf("\n"); } - - if (m==1) { - printf("hess_mat:\n"); - hess_mat(1,n,q,xp,V,W); - for (i=0; i bool MyADOLC_NLP::eval_obj(Index n, const T *x, T& obj_value) -{ +template +bool MyADOLC_NLP::eval_obj(Index n, const T *x, T &obj_value) { T a1, a2; obj_value = 0.; - for (Index i=0; i bool MyADOLC_NLP::eval_constraints(Index n, const T *x, Index m, T* g) -{ - for (Index i=0; i +bool MyADOLC_NLP::eval_constraints(Index n, const T *x, Index m, T *g) { + for (Index i = 0; i < m; i++) { + g[i] = 3. * pow(x[i + 1], 3.) + 2. * x[i + 2] - 5. + + sin(x[i + 1] - x[i + 2]) * sin(x[i + 1] + x[i + 2]) + 4. * x[i + 1] - + x[i] * exp(x[i] - x[i + 1]) - 3.; } return true; @@ -132,72 +128,66 @@ template bool MyADOLC_NLP::eval_constraints(Index n, const T *x, Index // //************************************************************************* - -bool MyADOLC_NLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value) -{ - eval_obj(n,x,obj_value); +bool MyADOLC_NLP::eval_f(Index n, const Number *x, bool new_x, + Number &obj_value) { + eval_obj(n, x, obj_value); return true; } -bool MyADOLC_NLP::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) -{ +bool MyADOLC_NLP::eval_grad_f(Index n, const Number *x, bool new_x, + Number *grad_f) { - gradient(tag_f,n,x,grad_f); + gradient(tag_f, n, x, grad_f); return true; } -bool MyADOLC_NLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g) -{ +bool MyADOLC_NLP::eval_g(Index n, const Number *x, bool new_x, Index m, + Number *g) { - eval_constraints(n,x,m,g); + eval_constraints(n, x, m, g); return true; } -bool MyADOLC_NLP::eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, Index *jCol, - Number* values) -{ +bool MyADOLC_NLP::eval_jac_g(Index n, const Number *x, bool new_x, Index m, + Index nele_jac, Index *iRow, Index *jCol, + Number *values) { if (values == NULL) { - // return the structure of the jacobian, + // return the structure of the jacobian, // assuming that the Jacobian is dense Index idx = 0; - for(Index i=0; i(x),Hess); + set_param_vec(tag_L, m + 1, obj_lam); + hessian(tag_L, n, const_cast(x), Hess); Index idx = 0; - for(Index i = 0; i>= dummy; + obj_value >>= dummy; trace_off(); - + trace_on(tag_g); - - for(Index i=0;i>= dummy; + for (Index i = 0; i < m; i++) + g[i] >>= dummy; trace_off(); - trace_on(tag_L); - - for(Index i=0;i>= dummy; + for (Index i = 0; i < m; i++) + obj_value += g[i] * mkparam(lam[i]); + + obj_value >>= dummy; trace_off(); @@ -338,5 +321,4 @@ void MyADOLC_NLP::generate_tapes(Index n, Index m) delete[] lamp; delete[] zu; delete[] zl; - } diff --git a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/ADOL-C_NLP.hpp b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/ADOL-C_NLP.hpp index fabea9cb1..3721bd503 100644 --- a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/ADOL-C_NLP.hpp +++ b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/ADOL-C_NLP.hpp @@ -3,15 +3,15 @@ File: ADOL-C_NLP.hpp Revision: $$ Contents: class myADOL-C_NPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + This code is based on the file MyNLP.hpp contained in the Ipopt package - with the authors: Carl Laird, Andreas Waechter + with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ //************************************************************************* @@ -25,8 +25,8 @@ #ifndef __MYADOLCNLP_HPP__ #define __MYADOLCNLP_HPP__ -#include #include +#include #define tag_f 1 #define tag_g 2 @@ -34,8 +34,7 @@ using namespace Ipopt; -class MyADOLC_NLP : public TNLP -{ +class MyADOLC_NLP : public TNLP { public: /** default constructor */ MyADOLC_NLP(); @@ -46,92 +45,91 @@ class MyADOLC_NLP : public TNLP /**@name Overloaded from TNLP */ //@{ /** Method to return some info about the nlp */ - virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style); + virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, + Index &nnz_h_lag, IndexStyleEnum &index_style); /** Method to return the bounds for my problem */ - virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u); + virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, + Number *g_l, Number *g_u); /** Method to return the starting point for the algorithm */ - virtual bool get_starting_point(Index n, bool init_x, Number* x, - bool init_z, Number* z_L, Number* z_U, - Index m, bool init_lambda, - Number* lambda); + virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, + Number *z_L, Number *z_U, Index m, + bool init_lambda, Number *lambda); /** Template to return the objective value */ - template bool eval_obj(Index n, const T *x, T& obj_value); + template bool eval_obj(Index n, const T *x, T &obj_value); - /** Template to compute contraints */ - template bool eval_constraints(Index n, const T *x, Index m, T *g); + template bool eval_constraints(Index n, const T *x, Index m, T *g); /** Original method from Ipopt to return the objective value */ /** remains unchanged */ - virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value); + virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value); /** Original method from Ipopt to return the gradient of the objective */ /** remains unchanged */ - virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f); + virtual bool eval_grad_f(Index n, const Number *x, bool new_x, + Number *grad_f); /** Original method from Ipopt to return the constraint residuals */ /** remains unchanged */ - virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g); + virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g); /** Original method from Ipopt to return: * 1) The structure of the jacobian (if "values" is NULL) * 2) The values of the jacobian (if "values" is not NULL) */ /** remains unchanged */ - virtual bool eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, Index *jCol, - Number* values); + virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, + Index nele_jac, Index *iRow, Index *jCol, + Number *values); /** Original method from Ipopt to return: * 1) The structure of the hessian of the lagrangian (if "values" is NULL) * 2) The values of the hessian of the lagrangian (if "values" is not NULL) */ /** remains unchanged */ - virtual bool eval_h(Index n, const Number* x, bool new_x, - Number obj_factor, Index m, const Number* lambda, - bool new_lambda, Index nele_hess, Index* iRow, - Index* jCol, Number* values); + virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, + Index m, const Number *lambda, bool new_lambda, + Index nele_hess, Index *iRow, Index *jCol, + Number *values); //@} /** @name Solution Methods */ //@{ - /** This method is called when the algorithm is complete so the TNLP can store/write the solution */ - virtual void finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); + /** This method is called when the algorithm is complete so the TNLP can + * store/write the solution */ + virtual void finalize_solution(SolverReturn status, Index n, const Number *x, + const Number *z_L, const Number *z_U, Index m, + const Number *g, const Number *lambda, + Number obj_value, const IpoptData *ip_data, + IpoptCalculatedQuantities *ip_cq); //@} -//*************** start ADOL-C part *********************************** + //*************** start ADOL-C part *********************************** - /** Method to generate the required tapes */ + /** Method to generate the required tapes */ virtual void generate_tapes(Index n, Index m); -//*************** end ADOL-C part *********************************** + //*************** end ADOL-C part *********************************** private: /**@name Methods to block default compiler methods. * The compiler automatically generates the following three methods. * Since the default compiler implementation is generally not what - * you want (for all but the most simple classes), we usually + * you want (for all but the most simple classes), we usually * put the declarations of these methods in the private section * and never implement them. This prevents the compiler from * implementing an incorrect "default" behavior without us * knowing. (See Scott Meyers book, "Effective C++") - * + * */ //@{ // MyADOLC_NLP(); - MyADOLC_NLP(const MyADOLC_NLP&); - MyADOLC_NLP& operator=(const MyADOLC_NLP&); + MyADOLC_NLP(const MyADOLC_NLP &); + MyADOLC_NLP &operator=(const MyADOLC_NLP &); //@} //@{ @@ -140,7 +138,6 @@ class MyADOLC_NLP : public TNLP double *obj_lam; double **Hess; //@} - }; #endif diff --git a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/cpp_example.cpp b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/cpp_example.cpp index 33ed9c8b0..df26ba4a1 100644 --- a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/cpp_example.cpp +++ b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1/cpp_example.cpp @@ -3,15 +3,15 @@ File: cpp_example.cpp Revision: $$ Contents: example for class myADOLC_NPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - - This code is based on the file corresponding file cpp_example.cpp contained - in the Ipopt package with the authors: Carl Laird, Andreas Waechter + + This code is based on the file corresponding file cpp_example.cpp contained + in the Ipopt package with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ //************************************************************************* @@ -22,14 +22,13 @@ // //************************************************************************* +#include "ADOL-C_NLP.hpp" #include #include -#include "ADOL-C_NLP.hpp" using namespace Ipopt; -int main(int argv, char* argc[]) -{ +int main(int argv, char *argc[]) { // Create an instance of your nlp... SmartPtr myadolc_nlp = new MyADOLC_NLP(); @@ -41,7 +40,7 @@ int main(int argv, char* argc[]) status = app->Initialize(); if (status != Solve_Succeeded) { printf("\n\n*** Error during initialization!\n"); - return (int) status; + return (int)status; } status = app->OptimizeTNLP(myadolc_nlp); @@ -52,8 +51,9 @@ int main(int argv, char* argc[]) printf("\n\n*** The problem solved in %d iterations!\n", iter_count); Number final_obj = app->Statistics()->FinalObjective(); - printf("\n\n*** The final value of the objective function is %e.\n", final_obj); + printf("\n\n*** The final value of the objective function is %e.\n", + final_obj); } - return (int) status; + return (int)status; } diff --git a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/ADOL-C_sparseNLP.cpp b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/ADOL-C_sparseNLP.cpp index 313efb4fc..87c38c9de 100644 --- a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/ADOL-C_sparseNLP.cpp +++ b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/ADOL-C_sparseNLP.cpp @@ -3,20 +3,20 @@ File: ADOL-C_sparseNLP.cpp Revision: $$ Contents: class myADOLC_sparseNPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + This code is based on the file MyNLP.cpp contained in the Ipopt package - with the authors: Carl Laird, Andreas Waechter + with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ /** C++ Example NLP for interfacing a problem with IPOPT and ADOL-C. - * MyADOLC_sparseNLP implements a C++ example showing how to interface - * with IPOPT and ADOL-C through the TNLP interface. This class + * MyADOLC_sparseNLP implements a C++ example showing how to interface + * with IPOPT and ADOL-C through the TNLP interface. This class * implements the Example 5.1 from "Sparse and Parially Separable * Test Problems for Unconstrained and Equality Constrained * Optimization" by L. Luksan and J. Vlcek taking sparsity @@ -33,18 +33,16 @@ using namespace Ipopt; /* Constructor. */ -MyADOLC_sparseNLP::MyADOLC_sparseNLP() -{} +MyADOLC_sparseNLP::MyADOLC_sparseNLP() {} -MyADOLC_sparseNLP::~MyADOLC_sparseNLP() -{} +MyADOLC_sparseNLP::~MyADOLC_sparseNLP() {} -bool MyADOLC_sparseNLP::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style) -{ +bool MyADOLC_sparseNLP::get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, + Index &nnz_h_lag, + IndexStyleEnum &index_style) { n = 4000; - m = n-2; + m = n - 2; generate_tapes(n, m, nnz_jac_g, nnz_h_lag); @@ -54,17 +52,16 @@ bool MyADOLC_sparseNLP::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, return true; } -bool MyADOLC_sparseNLP::get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u) -{ +bool MyADOLC_sparseNLP::get_bounds_info(Index n, Number *x_l, Number *x_u, + Index m, Number *g_l, Number *g_u) { // none of the variables have bounds - for (Index i=0; i bool MyADOLC_sparseNLP::eval_obj(Index n, const T *x, T& obj_value) -{ +template +bool MyADOLC_sparseNLP::eval_obj(Index n, const T *x, T &obj_value) { T a1, a2; obj_value = 0.; - for (Index i=0; i bool MyADOLC_sparseNLP::eval_constraints(Index n, const T *x, Index m, T* g) -{ - for (Index i=0; i +bool MyADOLC_sparseNLP::eval_constraints(Index n, const T *x, Index m, T *g) { + for (Index i = 0; i < m; i++) { + g[i] = 3. * pow(x[i + 1], 3.) + 2. * x[i + 2] - 5. + + sin(x[i + 1] - x[i + 2]) * sin(x[i + 1] + x[i + 2]) + 4. * x[i + 1] - + x[i] * exp(x[i] - x[i + 1]) - 3.; } return true; @@ -128,106 +124,98 @@ template bool MyADOLC_sparseNLP::eval_constraints(Index n, const T *x, // //************************************************************************* - -bool MyADOLC_sparseNLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value) -{ - eval_obj(n,x,obj_value); +bool MyADOLC_sparseNLP::eval_f(Index n, const Number *x, bool new_x, + Number &obj_value) { + eval_obj(n, x, obj_value); return true; } -bool MyADOLC_sparseNLP::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) -{ +bool MyADOLC_sparseNLP::eval_grad_f(Index n, const Number *x, bool new_x, + Number *grad_f) { - gradient(tag_f,n,x,grad_f); + gradient(tag_f, n, x, grad_f); return true; } -bool MyADOLC_sparseNLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g) -{ +bool MyADOLC_sparseNLP::eval_g(Index n, const Number *x, bool new_x, Index m, + Number *g) { - eval_constraints(n,x,m,g); + eval_constraints(n, x, m, g); return true; } -bool MyADOLC_sparseNLP::eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, Index *jCol, - Number* values) -{ +bool MyADOLC_sparseNLP::eval_jac_g(Index n, const Number *x, bool new_x, + Index m, Index nele_jac, Index *iRow, + Index *jCol, Number *values) { if (values == NULL) { // return the structure of the jacobian - for(Index idx=0; idx(x), &nnz_L, &rind_L, &cind_L, &hessval, options_L); - - for(Index idx = 0; idx (x), &nnz_L, &rind_L, &cind_L, + &hessval, options_L); + + for (Index idx = 0; idx < nnz_L; idx++) { + values[idx] = hessval[idx]; + } } return true; } -void MyADOLC_sparseNLP::finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq) -{ +void MyADOLC_sparseNLP::finalize_solution(SolverReturn status, Index n, + const Number *x, const Number *z_L, + const Number *z_U, Index m, + const Number *g, const Number *lambda, + Number obj_value, + const IpoptData *ip_data, + IpoptCalculatedQuantities *ip_cq) { printf("\n\nObjective value\n"); printf("f(x*) = %e\n", obj_value); -// memory deallocation of ADOL-C variables + // memory deallocation of ADOL-C variables delete[] obj_lam; free(rind_g); @@ -236,95 +224,93 @@ void MyADOLC_sparseNLP::finalize_solution(SolverReturn status, free(cind_L); free(jacval); free(hessval); - } - //*************** ADOL-C part *********************************** -void MyADOLC_sparseNLP::generate_tapes(Index n, Index m, Index& nnz_jac_g, Index& nnz_h_lag) -{ - Number *xp = new double[n]; - Number *lamp = new double[m]; - Number *zl = new double[m]; - Number *zu = new double[m]; +void MyADOLC_sparseNLP::generate_tapes(Index n, Index m, Index &nnz_jac_g, + Index &nnz_h_lag) { + Number *xp = new double[n]; + Number *lamp = new double[m]; + Number *zl = new double[m]; + Number *zu = new double[m]; - adouble *xa = new adouble[n]; - adouble *g = new adouble[m]; - double *lam = new double[m]; + adouble *xa = new adouble[n]; + adouble *g = new adouble[m]; + double *lam = new double[m]; double sig; adouble obj_value; - + double dummy; - int i,j,k,l,ii; + int i, j, k, l, ii; - obj_lam = new double[m+1]; + obj_lam = new double[m + 1]; get_starting_point(n, 1, xp, 0, zl, zu, m, 0, lamp); trace_on(tag_f); - - for(Index idx=0;idx>= dummy; + obj_value >>= dummy; trace_off(); - + trace_on(tag_g); - - for(Index idx=0;idx>= dummy; + for (Index idx = 0; idx < m; idx++) + g[idx] >>= dummy; trace_off(); trace_on(tag_L); - - for(Index idx=0;idx>= dummy; + for (Index idx = 0; idx < m; idx++) + obj_value += g[idx] * mkparam(lam[idx]); + + obj_value >>= dummy; trace_off(); - rind_g = NULL; + rind_g = NULL; cind_g = NULL; rind_L = NULL; cind_L = NULL; - options_g[0] = 0; /* sparsity pattern by index domains (default) */ - options_g[1] = 0; /* safe mode (default) */ + options_g[0] = 0; /* sparsity pattern by index domains (default) */ + options_g[1] = 0; /* safe mode (default) */ options_g[2] = 0; - options_g[3] = 0; /* column compression (default) */ - - jacval=NULL; - hessval=NULL; - sparse_jac(tag_g, m, n, 0, xp, &nnz_jac, &rind_g, &cind_g, &jacval, options_g); + options_g[3] = 0; /* column compression (default) */ + + jacval = NULL; + hessval = NULL; + sparse_jac(tag_g, m, n, 0, xp, &nnz_jac, &rind_g, &cind_g, &jacval, + options_g); nnz_jac_g = nnz_jac; - options_L[0] = 0; - options_L[1] = 1; + options_L[0] = 0; + options_L[1] = 1; sparse_hess(tag_L, n, 0, xp, &nnz_L, &rind_L, &cind_L, &hessval, options_L); nnz_h_lag = nnz_L; diff --git a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/ADOL-C_sparseNLP.hpp b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/ADOL-C_sparseNLP.hpp index 994ad01b5..385c3fb24 100644 --- a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/ADOL-C_sparseNLP.hpp +++ b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/ADOL-C_sparseNLP.hpp @@ -3,15 +3,15 @@ File: ADOL-C_sparseNLP.hpp Revision: $$ Contents: class myADOL-C_sparseNPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + This code is based on the file MyNLP.hpp contained in the Ipopt package - with the authors: Carl Laird, Andreas Waechter + with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ //************************************************************************* @@ -25,9 +25,9 @@ #ifndef __MYADOLCNLP_HPP__ #define __MYADOLCNLP_HPP__ -#include #include #include +#include #define tag_f 1 #define tag_g 2 @@ -36,8 +36,7 @@ using namespace Ipopt; -class MyADOLC_sparseNLP : public TNLP -{ +class MyADOLC_sparseNLP : public TNLP { public: /** default constructor */ MyADOLC_sparseNLP(); @@ -48,92 +47,92 @@ class MyADOLC_sparseNLP : public TNLP /**@name Overloaded from TNLP */ //@{ /** Method to return some info about the nlp */ - virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style); + virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, + Index &nnz_h_lag, IndexStyleEnum &index_style); /** Method to return the bounds for my problem */ - virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u); + virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, + Number *g_l, Number *g_u); /** Method to return the starting point for the algorithm */ - virtual bool get_starting_point(Index n, bool init_x, Number* x, - bool init_z, Number* z_L, Number* z_U, - Index m, bool init_lambda, - Number* lambda); + virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, + Number *z_L, Number *z_U, Index m, + bool init_lambda, Number *lambda); /** Template to return the objective value */ - template bool eval_obj(Index n, const T *x, T& obj_value); + template bool eval_obj(Index n, const T *x, T &obj_value); - /** Template to compute contraints */ - template bool eval_constraints(Index n, const T *x, Index m, T *g); + template bool eval_constraints(Index n, const T *x, Index m, T *g); /** Original method from Ipopt to return the objective value */ /** remains unchanged */ - virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value); + virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value); /** Original method from Ipopt to return the gradient of the objective */ /** remains unchanged */ - virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f); + virtual bool eval_grad_f(Index n, const Number *x, bool new_x, + Number *grad_f); /** Original method from Ipopt to return the constraint residuals */ /** remains unchanged */ - virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g); + virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g); /** Original method from Ipopt to return: * 1) The structure of the jacobian (if "values" is NULL) * 2) The values of the jacobian (if "values" is not NULL) */ /** remains unchanged */ - virtual bool eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, Index *jCol, - Number* values); + virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, + Index nele_jac, Index *iRow, Index *jCol, + Number *values); /** Original method from Ipopt to return: * 1) The structure of the hessian of the lagrangian (if "values" is NULL) * 2) The values of the hessian of the lagrangian (if "values" is not NULL) */ /** remains unchanged */ - virtual bool eval_h(Index n, const Number* x, bool new_x, - Number obj_factor, Index m, const Number* lambda, - bool new_lambda, Index nele_hess, Index* iRow, - Index* jCol, Number* values); + virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, + Index m, const Number *lambda, bool new_lambda, + Index nele_hess, Index *iRow, Index *jCol, + Number *values); //@} /** @name Solution Methods */ //@{ - /** This method is called when the algorithm is complete so the TNLP can store/write the solution */ - virtual void finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); + /** This method is called when the algorithm is complete so the TNLP can + * store/write the solution */ + virtual void finalize_solution(SolverReturn status, Index n, const Number *x, + const Number *z_L, const Number *z_U, Index m, + const Number *g, const Number *lambda, + Number obj_value, const IpoptData *ip_data, + IpoptCalculatedQuantities *ip_cq); //@} -//*************** start ADOL-C part *********************************** + //*************** start ADOL-C part *********************************** - /** Method to generate the required tapes */ - virtual void generate_tapes(Index n, Index m, Index& nnz_jac_g, Index& nnz_h_lag); + /** Method to generate the required tapes */ + virtual void generate_tapes(Index n, Index m, Index &nnz_jac_g, + Index &nnz_h_lag); -//*************** end ADOL-C part *********************************** + //*************** end ADOL-C part *********************************** private: /**@name Methods to block default compiler methods. * The compiler automatically generates the following three methods. * Since the default compiler implementation is generally not what - * you want (for all but the most simple classes), we usually + * you want (for all but the most simple classes), we usually * put the declarations of these methods in the private section * and never implement them. This prevents the compiler from * implementing an incorrect "default" behavior without us * knowing. (See Scott Meyers book, "Effective C++") - * + * */ //@{ // MyADOLC_sparseNLP(); - MyADOLC_sparseNLP(const MyADOLC_sparseNLP&); - MyADOLC_sparseNLP& operator=(const MyADOLC_sparseNLP&); + MyADOLC_sparseNLP(const MyADOLC_sparseNLP &); + MyADOLC_sparseNLP &operator=(const MyADOLC_sparseNLP &); //@} //@{ @@ -141,19 +140,18 @@ class MyADOLC_sparseNLP : public TNLP double *obj_lam; //** variables for sparsity exploitation - unsigned int *rind_g; /* row indices */ - unsigned int *cind_g; /* column indices */ - double *jacval; /* values */ - unsigned int *rind_L; /* row indices */ - unsigned int *cind_L; /* column indices */ - double *hessval; /* values */ + unsigned int *rind_g; /* row indices */ + unsigned int *cind_g; /* column indices */ + double *jacval; /* values */ + unsigned int *rind_L; /* row indices */ + unsigned int *cind_L; /* column indices */ + double *hessval; /* values */ int nnz_jac; int nnz_L; int options_g[4]; int options_L[4]; - - //@} + //@} }; #endif diff --git a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/cpp_example.cpp b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/cpp_example.cpp index 1a28ee59a..57d985814 100644 --- a/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/cpp_example.cpp +++ b/ADOL-C/examples/additional_examples/ipopt/LuksanVlcek1_sparse/cpp_example.cpp @@ -3,15 +3,15 @@ File: cpp_example.cpp Revision: $$ Contents: example for class myADOLC_sparseNPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - - This code is based on the file corresponding file cpp_example.cpp contained - in the Ipopt package with the authors: Carl Laird, Andreas Waechter + + This code is based on the file corresponding file cpp_example.cpp contained + in the Ipopt package with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ //************************************************************************* @@ -22,14 +22,13 @@ // //************************************************************************* +#include "ADOL-C_sparseNLP.hpp" #include #include -#include "ADOL-C_sparseNLP.hpp" using namespace Ipopt; -int main(int argv, char* argc[]) -{ +int main(int argv, char *argc[]) { // Create an instance of your nlp... SmartPtr myadolc_nlp = new MyADOLC_sparseNLP(); @@ -41,7 +40,7 @@ int main(int argv, char* argc[]) status = app->Initialize(); if (status != Solve_Succeeded) { printf("\n\n*** Error during initialization!\n"); - return (int) status; + return (int)status; } status = app->OptimizeTNLP(myadolc_nlp); @@ -52,8 +51,9 @@ int main(int argv, char* argc[]) printf("\n\n*** The problem solved in %d iterations!\n", iter_count); Number final_obj = app->Statistics()->FinalObjective(); - printf("\n\n*** The final value of the objective function is %e.\n", final_obj); + printf("\n\n*** The final value of the objective function is %e.\n", + final_obj); } - return (int) status; + return (int)status; } diff --git a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/ADOL-C_NLP.cpp b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/ADOL-C_NLP.cpp index eaec783af..e196a6f74 100644 --- a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/ADOL-C_NLP.cpp +++ b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/ADOL-C_NLP.cpp @@ -3,20 +3,20 @@ File: ADOL-C_NLP.cpp Revision: $$ Contents: class myADOLC_NPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + This code is based on the file MyNLP.cpp contained in the Ipopt package - with the authors: Carl Laird, Andreas Waechter + with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ /** C++ Example NLP for interfacing a problem with IPOPT and ADOL-C. - * MyADOL-C_NLP implements a C++ example showing how to interface - * with IPOPT and ADOL-C through the TNLP interface. This class + * MyADOL-C_NLP implements a C++ example showing how to interface + * with IPOPT and ADOL-C through the TNLP interface. This class * implements a distributed control problem with homogeneous * Neumann boundary conditions, as formulated by Hans Mittelmann as * Examples 4-6 in "Optimization Techniques for Solving Elliptic @@ -31,92 +31,75 @@ #include "ADOL-C_NLP.hpp" -#define alpha_ 0.01 -#define b_0j_ 1. -#define b_1j_ 1. -#define b_i0_ 1. -#define b_i1_ 1. +#define alpha_ 0.01 +#define b_0j_ 1. +#define b_1j_ 1. +#define b_i0_ 1. +#define b_i1_ 1. double *y_d_; -int N_; -double h_; -double hh_; - -int y_index(int i, int j) - { - return j + (N_+2)*i; - } +int N_; +double h_; +double hh_; - int u_index(int i, int j) - { - return (N_+2)*(N_+2) + (j-1) + (N_)*(i-1); - } +int y_index(int i, int j) { return j + (N_ + 2) * i; } -int pde_index(int i, int j) - { - return (j-1) + N_*(i-1); - } +int u_index(int i, int j) { + return (N_ + 2) * (N_ + 2) + (j - 1) + (N_) * (i - 1); +} -double y_d_cont(double x1, double x2) - { - return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.)); - } +int pde_index(int i, int j) { return (j - 1) + N_ * (i - 1); } -adouble fint_cont(double x1, double x2, adouble y, adouble u) - { - adouble diff_y = y-y_d_cont(x1,x2); - return 0.5*(diff_y*diff_y + alpha_*u*u); - } +double y_d_cont(double x1, double x2) { + return 3. + 5. * (x1 * (x1 - 1.) * x2 * (x2 - 1.)); +} -adouble d_cont(double x1, double x2, adouble y, adouble u) - { - return -exp(y) - u; - } +adouble fint_cont(double x1, double x2, adouble y, adouble u) { + adouble diff_y = y - y_d_cont(x1, x2); + return 0.5 * (diff_y * diff_y + alpha_ * u * u); +} -double fint_cont(double x1, double x2, double y, double u) - { - double diff_y = y-y_d_cont(x1,x2); - return 0.5*(diff_y*diff_y + alpha_*u*u); - } +adouble d_cont(double x1, double x2, adouble y, adouble u) { + return -exp(y) - u; +} -double d_cont(double x1, double x2, double y, double u) - { - return -exp(y) - u; - } +double fint_cont(double x1, double x2, double y, double u) { + double diff_y = y - y_d_cont(x1, x2); + return 0.5 * (diff_y * diff_y + alpha_ * u * u); +} +double d_cont(double x1, double x2, double y, double u) { return -exp(y) - u; } using namespace Ipopt; /* Constructor. */ -MyADOLC_NLP::MyADOLC_NLP() -{} +MyADOLC_NLP::MyADOLC_NLP() {} -MyADOLC_NLP::~MyADOLC_NLP(){} +MyADOLC_NLP::~MyADOLC_NLP() {} -bool MyADOLC_NLP::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style) -{ +bool MyADOLC_NLP::get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, + Index &nnz_h_lag, IndexStyleEnum &index_style) { N_ = 10; - h_ = (1.0/(N_+1)); - hh_= (h_*h_); + h_ = (1.0 / (N_ + 1)); + hh_ = (h_ * h_); - y_d_ = new double[(N_+2)*(N_+2)]; - for (int j=0; j<= N_+1; j++) { - for (int i=0; i<= N_+1; i++) { - y_d_[y_index(i,j)] = y_d_cont(h_*1.*i,h_*1.*j); + y_d_ = new double[(N_ + 2) * (N_ + 2)]; + for (int j = 0; j <= N_ + 1; j++) { + for (int i = 0; i <= N_ + 1; i++) { + y_d_[y_index(i, j)] = y_d_cont(h_ * 1. * i, h_ * 1. * j); } } - n = (N_+2)*(N_+2) + N_*N_; + n = (N_ + 2) * (N_ + 2) + N_ * N_; - m = N_*N_ + 4*N_; + m = N_ * N_ + 4 * N_; // in this example the jacobian is dense. Hence, it contains n*m nonzeros - nnz_jac_g = n*m; + nnz_jac_g = n * m; // the hessian is also dense and has n*n total nonzeros, but we // only need the lower left corner (since it is symmetric) - nnz_h_lag = n*(n-1)/2+n; + nnz_h_lag = n * (n - 1) / 2 + n; generate_tapes(n, m); @@ -126,17 +109,16 @@ bool MyADOLC_NLP::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, return true; } -bool MyADOLC_NLP::get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u) -{ +bool MyADOLC_NLP::get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, + Number *g_l, Number *g_u) { // none of the variables have bounds - for (Index i=0; i bool MyADOLC_NLP::eval_obj(Index n, const T *x, T& obj_value) -{ +template +bool MyADOLC_NLP::eval_obj(Index n, const T *x, T &obj_value) { // return the value of the objective function obj_value = 0.; - for (int i=1; i<=N_; i++) { - for (int j=1; j<= N_; j++) { - int iy = y_index(i,j); - int iu = u_index(i,j); - obj_value += fint_cont(h_*1.*i, h_*1.*j, x[iy], x[iu]); + for (int i = 1; i <= N_; i++) { + for (int j = 1; j <= N_; j++) { + int iy = y_index(i, j); + int iu = u_index(i, j); + obj_value += fint_cont(h_ * 1. * i, h_ * 1. * j, x[iy], x[iu]); } } obj_value *= hh_; @@ -190,43 +171,42 @@ template bool MyADOLC_NLP::eval_obj(Index n, const T *x, T& obj_value) return true; } -template bool MyADOLC_NLP::eval_constraints(Index n, const T *x, Index m, T* g) -{ +template +bool MyADOLC_NLP::eval_constraints(Index n, const T *x, Index m, T *g) { T val; // compute the discretized PDE for each interior grid point - for (int i=1; i<=N_; i++) { - for (int j=1; j<=N_; j++) { + for (int i = 1; i <= N_; i++) { + for (int j = 1; j <= N_; j++) { // Start with the discretized Laplacian operator - val = 4.* x[y_index(i,j)] - - x[y_index(i-1,j)] - x[y_index(i+1,j)] - - x[y_index(i,j-1)] - x[y_index(i,j+1)]; + val = 4. * x[y_index(i, j)] - x[y_index(i - 1, j)] - + x[y_index(i + 1, j)] - x[y_index(i, j - 1)] - x[y_index(i, j + 1)]; // Add the forcing term (including the step size here) - val += hh_*d_cont(h_*1.*i, h_*1.*j,x[y_index(i,j)], x[u_index(i,j)]); - g[pde_index(i,j)] = val; + val += hh_ * d_cont(h_ * 1. * i, h_ * 1. * j, x[y_index(i, j)], + x[u_index(i, j)]); + g[pde_index(i, j)] = val; } } - int ig = N_*N_; + int ig = N_ * N_; // set up the Neumann boundary conditions - for (int i=1; i<= N_; i++) { - g[ig] = (1.+h_*b_i0_)*x[y_index(i,0)] - x[y_index(i,1)]; + for (int i = 1; i <= N_; i++) { + g[ig] = (1. + h_ * b_i0_) * x[y_index(i, 0)] - x[y_index(i, 1)]; ig++; } - for (int i=1; i<= N_; i++) { - g[ig] = (1.+h_*b_i1_)*x[y_index(i,N_+1)] - x[y_index(i,N_)]; + for (int i = 1; i <= N_; i++) { + g[ig] = (1. + h_ * b_i1_) * x[y_index(i, N_ + 1)] - x[y_index(i, N_)]; ig++; } - for (int j=1; j<= N_; j++) { - g[ig] = (1.+h_*b_0j_)*x[y_index(0,j)] - x[y_index(1,j)]; + for (int j = 1; j <= N_; j++) { + g[ig] = (1. + h_ * b_0j_) * x[y_index(0, j)] - x[y_index(1, j)]; ig++; } - for (int j=1; j<= N_; j++) { - g[ig] = (1.+h_*b_1j_)*x[y_index(N_+1,j)] - x[y_index(N_,j)]; + for (int j = 1; j <= N_; j++) { + g[ig] = (1. + h_ * b_1j_) * x[y_index(N_ + 1, j)] - x[y_index(N_, j)]; ig++; - } - + } return true; } @@ -239,72 +219,66 @@ template bool MyADOLC_NLP::eval_constraints(Index n, const T *x, Index // //************************************************************************* - -bool MyADOLC_NLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value) -{ - eval_obj(n,x,obj_value); +bool MyADOLC_NLP::eval_f(Index n, const Number *x, bool new_x, + Number &obj_value) { + eval_obj(n, x, obj_value); return true; } -bool MyADOLC_NLP::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) -{ +bool MyADOLC_NLP::eval_grad_f(Index n, const Number *x, bool new_x, + Number *grad_f) { - gradient(tag_f,n,x,grad_f); + gradient(tag_f, n, x, grad_f); return true; } -bool MyADOLC_NLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g) -{ +bool MyADOLC_NLP::eval_g(Index n, const Number *x, bool new_x, Index m, + Number *g) { - eval_constraints(n,x,m,g); + eval_constraints(n, x, m, g); return true; } -bool MyADOLC_NLP::eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, Index *jCol, - Number* values) -{ +bool MyADOLC_NLP::eval_jac_g(Index n, const Number *x, bool new_x, Index m, + Index nele_jac, Index *iRow, Index *jCol, + Number *values) { if (values == NULL) { - // return the structure of the jacobian, + // return the structure of the jacobian, // assuming that the Jacobian is dense Index idx = 0; - for(Index i=0; i(x),Hess); + set_param_vec(tag_L, m + 1, obj_lam); + hessian(tag_L, n, const_cast(x), Hess); Index idx = 0; - for(Index i = 0; i>= dummy; + eval_obj(n, xa, obj_value); + + obj_value >>= dummy; trace_off(); - + trace_on(tag_g); - - for(Index i=0;i>= dummy; + for (Index i = 0; i < m; i++) + g[i] >>= dummy; trace_off(); - trace_on(tag_L); - - for(Index i=0;i>= dummy; + obj_value >>= dummy; trace_off(); diff --git a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/ADOL-C_NLP.hpp b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/ADOL-C_NLP.hpp index fabea9cb1..3721bd503 100644 --- a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/ADOL-C_NLP.hpp +++ b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/ADOL-C_NLP.hpp @@ -3,15 +3,15 @@ File: ADOL-C_NLP.hpp Revision: $$ Contents: class myADOL-C_NPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + This code is based on the file MyNLP.hpp contained in the Ipopt package - with the authors: Carl Laird, Andreas Waechter + with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ //************************************************************************* @@ -25,8 +25,8 @@ #ifndef __MYADOLCNLP_HPP__ #define __MYADOLCNLP_HPP__ -#include #include +#include #define tag_f 1 #define tag_g 2 @@ -34,8 +34,7 @@ using namespace Ipopt; -class MyADOLC_NLP : public TNLP -{ +class MyADOLC_NLP : public TNLP { public: /** default constructor */ MyADOLC_NLP(); @@ -46,92 +45,91 @@ class MyADOLC_NLP : public TNLP /**@name Overloaded from TNLP */ //@{ /** Method to return some info about the nlp */ - virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style); + virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, + Index &nnz_h_lag, IndexStyleEnum &index_style); /** Method to return the bounds for my problem */ - virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u); + virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, + Number *g_l, Number *g_u); /** Method to return the starting point for the algorithm */ - virtual bool get_starting_point(Index n, bool init_x, Number* x, - bool init_z, Number* z_L, Number* z_U, - Index m, bool init_lambda, - Number* lambda); + virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, + Number *z_L, Number *z_U, Index m, + bool init_lambda, Number *lambda); /** Template to return the objective value */ - template bool eval_obj(Index n, const T *x, T& obj_value); + template bool eval_obj(Index n, const T *x, T &obj_value); - /** Template to compute contraints */ - template bool eval_constraints(Index n, const T *x, Index m, T *g); + template bool eval_constraints(Index n, const T *x, Index m, T *g); /** Original method from Ipopt to return the objective value */ /** remains unchanged */ - virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value); + virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value); /** Original method from Ipopt to return the gradient of the objective */ /** remains unchanged */ - virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f); + virtual bool eval_grad_f(Index n, const Number *x, bool new_x, + Number *grad_f); /** Original method from Ipopt to return the constraint residuals */ /** remains unchanged */ - virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g); + virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g); /** Original method from Ipopt to return: * 1) The structure of the jacobian (if "values" is NULL) * 2) The values of the jacobian (if "values" is not NULL) */ /** remains unchanged */ - virtual bool eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, Index *jCol, - Number* values); + virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, + Index nele_jac, Index *iRow, Index *jCol, + Number *values); /** Original method from Ipopt to return: * 1) The structure of the hessian of the lagrangian (if "values" is NULL) * 2) The values of the hessian of the lagrangian (if "values" is not NULL) */ /** remains unchanged */ - virtual bool eval_h(Index n, const Number* x, bool new_x, - Number obj_factor, Index m, const Number* lambda, - bool new_lambda, Index nele_hess, Index* iRow, - Index* jCol, Number* values); + virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, + Index m, const Number *lambda, bool new_lambda, + Index nele_hess, Index *iRow, Index *jCol, + Number *values); //@} /** @name Solution Methods */ //@{ - /** This method is called when the algorithm is complete so the TNLP can store/write the solution */ - virtual void finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); + /** This method is called when the algorithm is complete so the TNLP can + * store/write the solution */ + virtual void finalize_solution(SolverReturn status, Index n, const Number *x, + const Number *z_L, const Number *z_U, Index m, + const Number *g, const Number *lambda, + Number obj_value, const IpoptData *ip_data, + IpoptCalculatedQuantities *ip_cq); //@} -//*************** start ADOL-C part *********************************** + //*************** start ADOL-C part *********************************** - /** Method to generate the required tapes */ + /** Method to generate the required tapes */ virtual void generate_tapes(Index n, Index m); -//*************** end ADOL-C part *********************************** + //*************** end ADOL-C part *********************************** private: /**@name Methods to block default compiler methods. * The compiler automatically generates the following three methods. * Since the default compiler implementation is generally not what - * you want (for all but the most simple classes), we usually + * you want (for all but the most simple classes), we usually * put the declarations of these methods in the private section * and never implement them. This prevents the compiler from * implementing an incorrect "default" behavior without us * knowing. (See Scott Meyers book, "Effective C++") - * + * */ //@{ // MyADOLC_NLP(); - MyADOLC_NLP(const MyADOLC_NLP&); - MyADOLC_NLP& operator=(const MyADOLC_NLP&); + MyADOLC_NLP(const MyADOLC_NLP &); + MyADOLC_NLP &operator=(const MyADOLC_NLP &); //@} //@{ @@ -140,7 +138,6 @@ class MyADOLC_NLP : public TNLP double *obj_lam; double **Hess; //@} - }; #endif diff --git a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/cpp_example.cpp b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/cpp_example.cpp index 33ed9c8b0..df26ba4a1 100644 --- a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/cpp_example.cpp +++ b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA/cpp_example.cpp @@ -3,15 +3,15 @@ File: cpp_example.cpp Revision: $$ Contents: example for class myADOLC_NPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - - This code is based on the file corresponding file cpp_example.cpp contained - in the Ipopt package with the authors: Carl Laird, Andreas Waechter + + This code is based on the file corresponding file cpp_example.cpp contained + in the Ipopt package with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ //************************************************************************* @@ -22,14 +22,13 @@ // //************************************************************************* +#include "ADOL-C_NLP.hpp" #include #include -#include "ADOL-C_NLP.hpp" using namespace Ipopt; -int main(int argv, char* argc[]) -{ +int main(int argv, char *argc[]) { // Create an instance of your nlp... SmartPtr myadolc_nlp = new MyADOLC_NLP(); @@ -41,7 +40,7 @@ int main(int argv, char* argc[]) status = app->Initialize(); if (status != Solve_Succeeded) { printf("\n\n*** Error during initialization!\n"); - return (int) status; + return (int)status; } status = app->OptimizeTNLP(myadolc_nlp); @@ -52,8 +51,9 @@ int main(int argv, char* argc[]) printf("\n\n*** The problem solved in %d iterations!\n", iter_count); Number final_obj = app->Statistics()->FinalObjective(); - printf("\n\n*** The final value of the objective function is %e.\n", final_obj); + printf("\n\n*** The final value of the objective function is %e.\n", + final_obj); } - return (int) status; + return (int)status; } diff --git a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/ADOL-C_sparseNLP.cpp b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/ADOL-C_sparseNLP.cpp index 7ee62a498..81254189e 100644 --- a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/ADOL-C_sparseNLP.cpp +++ b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/ADOL-C_sparseNLP.cpp @@ -3,20 +3,20 @@ File: ADOL-C_sparseNLP.cpp Revision: $$ Contents: class myADOLC_sparseNPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + This code is based on the file MyNLP.cpp contained in the Ipopt package - with the authors: Carl Laird, Andreas Waechter + with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ /** C++ Example NLP for interfacing a problem with IPOPT and ADOL-C. - * MyADOL-C_sparseNLP implements a C++ example showing how to interface - * with IPOPT and ADOL-C through the TNLP interface. This class + * MyADOL-C_sparseNLP implements a C++ example showing how to interface + * with IPOPT and ADOL-C through the TNLP interface. This class * implements a distributed control problem with homogeneous * Neumann boundary conditions, as formulated by Hans Mittelmann as * Examples 4-6 in "Optimization Techniques for Solving Elliptic @@ -31,85 +31,69 @@ #include "ADOL-C_sparseNLP.hpp" -#define alpha_ 0.01 -#define b_0j_ 1. -#define b_1j_ 1. -#define b_i0_ 1. -#define b_i1_ 1. +#define alpha_ 0.01 +#define b_0j_ 1. +#define b_1j_ 1. +#define b_i0_ 1. +#define b_i1_ 1. double *y_d_; -int N_; -double h_; -double hh_; +int N_; +double h_; +double hh_; -int y_index(int i, int j) - { - return j + (N_+2)*i; - } +int y_index(int i, int j) { return j + (N_ + 2) * i; } - int u_index(int i, int j) - { - return (N_+2)*(N_+2) + (j-1) + (N_)*(i-1); - } +int u_index(int i, int j) { + return (N_ + 2) * (N_ + 2) + (j - 1) + (N_) * (i - 1); +} -int pde_index(int i, int j) - { - return (j-1) + N_*(i-1); - } +int pde_index(int i, int j) { return (j - 1) + N_ * (i - 1); } -double y_d_cont(double x1, double x2) - { - return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.)); - } +double y_d_cont(double x1, double x2) { + return 3. + 5. * (x1 * (x1 - 1.) * x2 * (x2 - 1.)); +} -adouble fint_cont(double x1, double x2, adouble y, adouble u) - { - adouble diff_y = y-y_d_cont(x1,x2); - return 0.5*(diff_y*diff_y + alpha_*u*u); - } +adouble fint_cont(double x1, double x2, adouble y, adouble u) { + adouble diff_y = y - y_d_cont(x1, x2); + return 0.5 * (diff_y * diff_y + alpha_ * u * u); +} -adouble d_cont(double x1, double x2, adouble y, adouble u) - { - return -exp(y) - u; - } +adouble d_cont(double x1, double x2, adouble y, adouble u) { + return -exp(y) - u; +} -double fint_cont(double x1, double x2, double y, double u) - { - double diff_y = y-y_d_cont(x1,x2); - return 0.5*(diff_y*diff_y + alpha_*u*u); - } +double fint_cont(double x1, double x2, double y, double u) { + double diff_y = y - y_d_cont(x1, x2); + return 0.5 * (diff_y * diff_y + alpha_ * u * u); +} -double d_cont(double x1, double x2, double y, double u) - { - return -exp(y) - u; - } +double d_cont(double x1, double x2, double y, double u) { return -exp(y) - u; } using namespace Ipopt; /* Constructor. */ -MyADOLC_sparseNLP::MyADOLC_sparseNLP() -{} +MyADOLC_sparseNLP::MyADOLC_sparseNLP() {} -MyADOLC_sparseNLP::~MyADOLC_sparseNLP() -{} +MyADOLC_sparseNLP::~MyADOLC_sparseNLP() {} -bool MyADOLC_sparseNLP::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style) -{ +bool MyADOLC_sparseNLP::get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, + Index &nnz_h_lag, + IndexStyleEnum &index_style) { N_ = 15; - h_ = (1.0/(N_+1)); - hh_= (h_*h_); + h_ = (1.0 / (N_ + 1)); + hh_ = (h_ * h_); - y_d_ = new double[(N_+2)*(N_+2)]; - for (int j=0; j<= N_+1; j++) { - for (int i=0; i<= N_+1; i++) { - y_d_[y_index(i,j)] = y_d_cont(h_*1.*i,h_*1.*j); + y_d_ = new double[(N_ + 2) * (N_ + 2)]; + for (int j = 0; j <= N_ + 1; j++) { + for (int i = 0; i <= N_ + 1; i++) { + y_d_[y_index(i, j)] = y_d_cont(h_ * 1. * i, h_ * 1. * j); } } - n = (N_+2)*(N_+2) + N_*N_; + n = (N_ + 2) * (N_ + 2) + N_ * N_; - m = N_*N_ + 4*N_; + m = N_ * N_ + 4 * N_; generate_tapes(n, m, nnz_jac_g, nnz_h_lag); @@ -119,17 +103,16 @@ bool MyADOLC_sparseNLP::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, return true; } -bool MyADOLC_sparseNLP::get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u) -{ +bool MyADOLC_sparseNLP::get_bounds_info(Index n, Number *x_l, Number *x_u, + Index m, Number *g_l, Number *g_u) { // none of the variables have bounds - for (Index i=0; i bool MyADOLC_sparseNLP::eval_obj(Index n, const T *x, T& obj_value) -{ +template +bool MyADOLC_sparseNLP::eval_obj(Index n, const T *x, T &obj_value) { // return the value of the objective function obj_value = 0.; - for (int i=1; i<=N_; i++) { - for (int j=1; j<= N_; j++) { - int iy = y_index(i,j); - int iu = u_index(i,j); - obj_value += fint_cont(h_*1.*i, h_*1.*j, x[iy], x[iu]); + for (int i = 1; i <= N_; i++) { + for (int j = 1; j <= N_; j++) { + int iy = y_index(i, j); + int iu = u_index(i, j); + obj_value += fint_cont(h_ * 1. * i, h_ * 1. * j, x[iy], x[iu]); } } obj_value *= hh_; @@ -184,43 +165,43 @@ template bool MyADOLC_sparseNLP::eval_obj(Index n, const T *x, T& obj_ return true; } -template bool MyADOLC_sparseNLP::eval_constraints(Index n, const T *x, Index m, T* g) -{ +template +bool MyADOLC_sparseNLP::eval_constraints(Index n, const T *x, Index m, T *g) { T val; // compute the discretized PDE for each interior grid point - for (int i=1; i<=N_; i++) { - for (int j=1; j<=N_; j++) { + for (int i = 1; i <= N_; i++) { + for (int j = 1; j <= N_; j++) { // Start with the discretized Laplacian operator - val = 4.* x[y_index(i,j)] - - x[y_index(i-1,j)] - x[y_index(i+1,j)] - - x[y_index(i,j-1)] - x[y_index(i,j+1)]; + val = 4. * x[y_index(i, j)] - x[y_index(i - 1, j)] - + x[y_index(i + 1, j)] - x[y_index(i, j - 1)] - x[y_index(i, j + 1)]; // Add the forcing term (including the step size here) - val += hh_*d_cont(h_*1.*i, h_*1.*j,x[y_index(i,j)], x[u_index(i,j)]); - g[pde_index(i,j)] = val; + val += hh_ * d_cont(h_ * 1. * i, h_ * 1. * j, x[y_index(i, j)], + x[u_index(i, j)]); + g[pde_index(i, j)] = val; } } - int ig = N_*N_; + int ig = N_ * N_; // set up the Neumann boundary conditions - for (int i=1; i<= N_; i++) { - g[ig] = (1.+h_*b_i0_)*x[y_index(i,0)] - x[y_index(i,1)]; + for (int i = 1; i <= N_; i++) { + g[ig] = (1. + h_ * b_i0_) * x[y_index(i, 0)] - x[y_index(i, 1)]; ig++; } - for (int i=1; i<= N_; i++) { - g[ig] = (1.+h_*b_i1_)*x[y_index(i,N_+1)] - x[y_index(i,N_)]; + for (int i = 1; i <= N_; i++) { + g[ig] = (1. + h_ * b_i1_) * x[y_index(i, N_ + 1)] - x[y_index(i, N_)]; ig++; } - for (int j=1; j<= N_; j++) { - g[ig] = (1.+h_*b_0j_)*x[y_index(0,j)] - x[y_index(1,j)]; + for (int j = 1; j <= N_; j++) { + g[ig] = (1. + h_ * b_0j_) * x[y_index(0, j)] - x[y_index(1, j)]; ig++; } - for (int j=1; j<= N_; j++) { - g[ig] = (1.+h_*b_1j_)*x[y_index(N_+1,j)] - x[y_index(N_,j)]; + for (int j = 1; j <= N_; j++) { + g[ig] = (1. + h_ * b_1j_) * x[y_index(N_ + 1, j)] - x[y_index(N_, j)]; ig++; - } - + } + return true; } @@ -232,106 +213,98 @@ template bool MyADOLC_sparseNLP::eval_constraints(Index n, const T *x, // //************************************************************************* - -bool MyADOLC_sparseNLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value) -{ - eval_obj(n,x,obj_value); +bool MyADOLC_sparseNLP::eval_f(Index n, const Number *x, bool new_x, + Number &obj_value) { + eval_obj(n, x, obj_value); return true; } -bool MyADOLC_sparseNLP::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) -{ +bool MyADOLC_sparseNLP::eval_grad_f(Index n, const Number *x, bool new_x, + Number *grad_f) { - gradient(tag_f,n,x,grad_f); + gradient(tag_f, n, x, grad_f); return true; } -bool MyADOLC_sparseNLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g) -{ +bool MyADOLC_sparseNLP::eval_g(Index n, const Number *x, bool new_x, Index m, + Number *g) { - eval_constraints(n,x,m,g); + eval_constraints(n, x, m, g); return true; } -bool MyADOLC_sparseNLP::eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, Index *jCol, - Number* values) -{ +bool MyADOLC_sparseNLP::eval_jac_g(Index n, const Number *x, bool new_x, + Index m, Index nele_jac, Index *iRow, + Index *jCol, Number *values) { if (values == NULL) { // return the structure of the jacobian - for(Index idx=0; idx(x), &nnz_L, &rind_L, &cind_L, &hessval, options_L); - - for(Index idx = 0; idx < nnz_L ; idx++) - { - values[idx] = hessval[idx]; - } + for (Index idx = 0; idx < m; idx++) + obj_lam[1 + idx] = lambda[idx]; + + set_param_vec(tag_L, m + 1, obj_lam); + sparse_hess(tag_L, n, 1, const_cast(x), &nnz_L, &rind_L, &cind_L, + &hessval, options_L); + + for (Index idx = 0; idx < nnz_L; idx++) { + values[idx] = hessval[idx]; + } } return true; } -void MyADOLC_sparseNLP::finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq) -{ +void MyADOLC_sparseNLP::finalize_solution(SolverReturn status, Index n, + const Number *x, const Number *z_L, + const Number *z_U, Index m, + const Number *g, const Number *lambda, + Number obj_value, + const IpoptData *ip_data, + IpoptCalculatedQuantities *ip_cq) { printf("\n\nObjective value\n"); printf("f(x*) = %e\n", obj_value); -// memory deallocation of ADOL-C variables + // memory deallocation of ADOL-C variables delete[] obj_lam; delete[] y_d_; @@ -341,95 +314,93 @@ void MyADOLC_sparseNLP::finalize_solution(SolverReturn status, free(cind_L); free(jacval); free(hessval); - } - //*************** ADOL-C part *********************************** -void MyADOLC_sparseNLP::generate_tapes(Index n, Index m, Index& nnz_jac_g, Index& nnz_h_lag) -{ - Number *xp = new double[n]; - Number *lamp = new double[m]; - Number *zl = new double[m]; - Number *zu = new double[m]; +void MyADOLC_sparseNLP::generate_tapes(Index n, Index m, Index &nnz_jac_g, + Index &nnz_h_lag) { + Number *xp = new double[n]; + Number *lamp = new double[m]; + Number *zl = new double[m]; + Number *zu = new double[m]; - adouble *xa = new adouble[n]; - adouble *g = new adouble[m]; - double *lam = new double[m]; + adouble *xa = new adouble[n]; + adouble *g = new adouble[m]; + double *lam = new double[m]; double sig; adouble obj_value; - + double dummy; - int i,j,k,l,ii; + int i, j, k, l, ii; - obj_lam = new double[m+1]; + obj_lam = new double[m + 1]; get_starting_point(n, 1, xp, 0, zl, zu, m, 0, lamp); trace_on(tag_f); - - for(Index idx=0;idx>= dummy; + obj_value >>= dummy; trace_off(); - + trace_on(tag_g); - - for(Index idx=0;idx>= dummy; + for (Index idx = 0; idx < m; idx++) + g[idx] >>= dummy; trace_off(); trace_on(tag_L); - - for(Index idx=0;idx>= dummy; + for (Index idx = 0; idx < m; idx++) + obj_value += g[idx] * mkparam(lam[idx]); + + obj_value >>= dummy; trace_off(); - rind_g = NULL; + rind_g = NULL; cind_g = NULL; rind_L = NULL; cind_L = NULL; - options_g[0] = 0; /* sparsity pattern by index domains (default) */ - options_g[1] = 0; /* safe mode (default) */ + options_g[0] = 0; /* sparsity pattern by index domains (default) */ + options_g[1] = 0; /* safe mode (default) */ options_g[2] = 0; - options_g[3] = 0; /* column compression (default) */ - - jacval=NULL; - hessval=NULL; - sparse_jac(tag_g, m, n, 0, xp, &nnz_jac, &rind_g, &cind_g, &jacval, options_g); + options_g[3] = 0; /* column compression (default) */ + + jacval = NULL; + hessval = NULL; + sparse_jac(tag_g, m, n, 0, xp, &nnz_jac, &rind_g, &cind_g, &jacval, + options_g); nnz_jac_g = nnz_jac; - options_L[0] = 0; - options_L[1] = 1; + options_L[0] = 0; + options_L[1] = 1; sparse_hess(tag_L, n, 0, xp, &nnz_L, &rind_L, &cind_L, &hessval, options_L); nnz_h_lag = nnz_L; diff --git a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/ADOL-C_sparseNLP.hpp b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/ADOL-C_sparseNLP.hpp index bccd33f14..1248b9ac3 100644 --- a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/ADOL-C_sparseNLP.hpp +++ b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/ADOL-C_sparseNLP.hpp @@ -3,15 +3,15 @@ File: ADOL-C_sparseNLP.hpp Revision: $$ Contents: class myADOL-C_sparseNPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + This code is based on the file MyNLP.hpp contained in the Ipopt package - with the authors: Carl Laird, Andreas Waechter + with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ //************************************************************************* @@ -25,9 +25,9 @@ #ifndef __MYADOLCNLP_HPP__ #define __MYADOLCNLP_HPP__ -#include #include #include +#include #define tag_f 1 #define tag_g 2 @@ -36,8 +36,7 @@ using namespace Ipopt; -class MyADOLC_sparseNLP : public TNLP -{ +class MyADOLC_sparseNLP : public TNLP { public: /** default constructor */ MyADOLC_sparseNLP(); @@ -48,111 +47,110 @@ class MyADOLC_sparseNLP : public TNLP /**@name Overloaded from TNLP */ //@{ /** Method to return some info about the nlp */ - virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, - Index& nnz_h_lag, IndexStyleEnum& index_style); + virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, + Index &nnz_h_lag, IndexStyleEnum &index_style); /** Method to return the bounds for my problem */ - virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, - Index m, Number* g_l, Number* g_u); + virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, + Number *g_l, Number *g_u); /** Method to return the starting point for the algorithm */ - virtual bool get_starting_point(Index n, bool init_x, Number* x, - bool init_z, Number* z_L, Number* z_U, - Index m, bool init_lambda, - Number* lambda); + virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, + Number *z_L, Number *z_U, Index m, + bool init_lambda, Number *lambda); /** Template to return the objective value */ - template bool eval_obj(Index n, const T *x, T& obj_value); + template bool eval_obj(Index n, const T *x, T &obj_value); - /** Template to compute contraints */ - template bool eval_constraints(Index n, const T *x, Index m, T *g); + template bool eval_constraints(Index n, const T *x, Index m, T *g); /** Original method from Ipopt to return the objective value */ /** remains unchanged */ - virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value); + virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value); /** Original method from Ipopt to return the gradient of the objective */ /** remains unchanged */ - virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f); + virtual bool eval_grad_f(Index n, const Number *x, bool new_x, + Number *grad_f); /** Original method from Ipopt to return the constraint residuals */ /** remains unchanged */ - virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g); + virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g); /** Original method from Ipopt to return: * 1) The structure of the jacobian (if "values" is NULL) * 2) The values of the jacobian (if "values" is not NULL) */ /** remains unchanged */ - virtual bool eval_jac_g(Index n, const Number* x, bool new_x, - Index m, Index nele_jac, Index* iRow, Index *jCol, - Number* values); + virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, + Index nele_jac, Index *iRow, Index *jCol, + Number *values); /** Original method from Ipopt to return: * 1) The structure of the hessian of the lagrangian (if "values" is NULL) * 2) The values of the hessian of the lagrangian (if "values" is not NULL) */ /** remains unchanged */ - virtual bool eval_h(Index n, const Number* x, bool new_x, - Number obj_factor, Index m, const Number* lambda, - bool new_lambda, Index nele_hess, Index* iRow, - Index* jCol, Number* values); + virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, + Index m, const Number *lambda, bool new_lambda, + Index nele_hess, Index *iRow, Index *jCol, + Number *values); //@} /** @name Solution Methods */ //@{ - /** This method is called when the algorithm is complete so the TNLP can store/write the solution */ - virtual void finalize_solution(SolverReturn status, - Index n, const Number* x, const Number* z_L, const Number* z_U, - Index m, const Number* g, const Number* lambda, - Number obj_value, - const IpoptData* ip_data, - IpoptCalculatedQuantities* ip_cq); + /** This method is called when the algorithm is complete so the TNLP can + * store/write the solution */ + virtual void finalize_solution(SolverReturn status, Index n, const Number *x, + const Number *z_L, const Number *z_U, Index m, + const Number *g, const Number *lambda, + Number obj_value, const IpoptData *ip_data, + IpoptCalculatedQuantities *ip_cq); //@} -//*************** start ADOL-C part *********************************** + //*************** start ADOL-C part *********************************** - /** Method to generate the required tapes */ - virtual void generate_tapes(Index n, Index m, Index& nnz_jac_g, Index& nnz_h_lag); + /** Method to generate the required tapes */ + virtual void generate_tapes(Index n, Index m, Index &nnz_jac_g, + Index &nnz_h_lag); -//*************** end ADOL-C part *********************************** + //*************** end ADOL-C part *********************************** private: /**@name Methods to block default compiler methods. * The compiler automatically generates the following three methods. * Since the default compiler implementation is generally not what - * you want (for all but the most simple classes), we usually + * you want (for all but the most simple classes), we usually * put the declarations of these methods in the private section * and never implement them. This prevents the compiler from * implementing an incorrect "default" behavior without us * knowing. (See Scott Meyers book, "Effective C++") - * + * */ //@{ // MyADOLC_sparseNLP(); - MyADOLC_sparseNLP(const MyADOLC_sparseNLP&); - MyADOLC_sparseNLP& operator=(const MyADOLC_sparseNLP&); + MyADOLC_sparseNLP(const MyADOLC_sparseNLP &); + MyADOLC_sparseNLP &operator=(const MyADOLC_sparseNLP &); //@} //@{ double *obj_lam; //** variables for sparsity exploitation - unsigned int *rind_g; /* row indices */ - unsigned int *cind_g; /* column indices */ - double *jacval; /* values */ - unsigned int *rind_L; /* row indices */ - unsigned int *cind_L; /* column indices */ - double *hessval; /* values */ + unsigned int *rind_g; /* row indices */ + unsigned int *cind_g; /* column indices */ + double *jacval; /* values */ + unsigned int *rind_L; /* row indices */ + unsigned int *cind_L; /* column indices */ + double *hessval; /* values */ int nnz_jac; int nnz_L; int options_g[4]; int options_L[4]; - - //@} + //@} }; #endif diff --git a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/cpp_example.cpp b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/cpp_example.cpp index 1a28ee59a..57d985814 100644 --- a/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/cpp_example.cpp +++ b/ADOL-C/examples/additional_examples/ipopt/MittelmannDistCntrlNeumA_sparse/cpp_example.cpp @@ -3,15 +3,15 @@ File: cpp_example.cpp Revision: $$ Contents: example for class myADOLC_sparseNPL for interfacing with Ipopt - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - - This code is based on the file corresponding file cpp_example.cpp contained - in the Ipopt package with the authors: Carl Laird, Andreas Waechter + + This code is based on the file corresponding file cpp_example.cpp contained + in the Ipopt package with the authors: Carl Laird, Andreas Waechter ----------------------------------------------------------------------------*/ //************************************************************************* @@ -22,14 +22,13 @@ // //************************************************************************* +#include "ADOL-C_sparseNLP.hpp" #include #include -#include "ADOL-C_sparseNLP.hpp" using namespace Ipopt; -int main(int argv, char* argc[]) -{ +int main(int argv, char *argc[]) { // Create an instance of your nlp... SmartPtr myadolc_nlp = new MyADOLC_sparseNLP(); @@ -41,7 +40,7 @@ int main(int argv, char* argc[]) status = app->Initialize(); if (status != Solve_Succeeded) { printf("\n\n*** Error during initialization!\n"); - return (int) status; + return (int)status; } status = app->OptimizeTNLP(myadolc_nlp); @@ -52,8 +51,9 @@ int main(int argv, char* argc[]) printf("\n\n*** The problem solved in %d iterations!\n", iter_count); Number final_obj = app->Statistics()->FinalObjective(); - printf("\n\n*** The final value of the objective function is %e.\n", final_obj); + printf("\n\n*** The final value of the objective function is %e.\n", + final_obj); } - return (int) status; + return (int)status; } diff --git a/ADOL-C/examples/additional_examples/lie/GantryCrane.cpp b/ADOL-C/examples/additional_examples/lie/GantryCrane.cpp index f6e462519..c896e04da 100644 --- a/ADOL-C/examples/additional_examples/lie/GantryCrane.cpp +++ b/ADOL-C/examples/additional_examples/lie/GantryCrane.cpp @@ -3,21 +3,21 @@ File: GantryCrane.cpp Revision: $Id$ Contents: example for calculation of Lie derivatives - - + + Copyright (c) Siquian Wang, Klaus Röbenack, Jan Winkler, Mirko Franke - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ -/** By the example of the gantry crane (as shown in Röbenack, Winkler and - * Wang. 'LIEDRIVERS - A Toolbox for the Efficient Computation of Lie - * Derivatives Based on the Object-Oriented Algorithmic Differentiation - * Package ADOL-C') the usage of the drivers of the Lie Toolbox is - * illustrated. +/** By the example of the gantry crane (as shown in Röbenack, Winkler and + * Wang. 'LIEDRIVERS - A Toolbox for the Efficient Computation of Lie + * Derivatives Based on the Object-Oriented Algorithmic Differentiation + * Package ADOL-C') the usage of the drivers of the Lie Toolbox is + * illustrated. * Beside Lie derivatives of scalar fields and their gradients also Lie * brackets are computed. */ @@ -38,148 +38,143 @@ using namespace std; /****************************************************************************/ /* MAIN PROGRAM */ -int main() -{ - const int n = 4, m_H = 2; - double* x0 = myalloc(n); - double vf[n], vg[n], vh[n]; - adouble aX[n], af[n], ag[n], ah[m_H]; - const double mc = 1.0, ml = 1.0, l = 1.0, g = 9.81; - - - /**************************** - * Trace for vector field f * - ****************************/ - trace_on(TAPE_F); - { - for (int i = 0; i < n; i++) - aX[i] <<= x0[i]; - - af[0] = aX[2]; - af[1] = aX[3]; - af[2] = (ml*l*pow(aX[3],2)*sin(aX[1]) + ml*g*sin(aX[1])*cos(aX[1]))/(ml*pow(sin(aX[1]),2)+mc); - af[3] = -(ml*l*pow(aX[3],2)*sin(aX[1])*cos(aX[1]) + (ml + mc)*g*sin(aX[1]))/(l*(ml*pow(sin(aX[1]),2)+mc)); - - for (int i = 0; i < n; i++) - af[i] >>= vf[i]; - } - trace_off(); - - - /**************************** - * Trace for vector field g * - ****************************/ - trace_on(TAPE_G); - { - for (int i = 0; i < n; i++) - aX[i] <<= x0[i]; - - ag[0] = 0; - ag[1] = 0; - ag[2] = 1/(ml*pow(sin(aX[1]),2)+mc); - ag[3] = -cos(aX[1])/(l*(ml*pow(sin(aX[1]),2)+mc)); - - for (int i = 0; i < n; i++) - ag[i] >>= vg[i]; - } - trace_off(); - - - /********************************** - * Trace for scalar fields h1, h2 * - **********************************/ - trace_on(TAPE_H); - { - for (int i = 0; i < n; i++) - aX[i] <<= x0[i]; - - ah[0] = aX[0] + l*sin(aX[1]); - ah[1] = l*cos(aX[1]); - - for (int i = 0; i < m_H; i++) - ah[i] >>= vh[i]; - } - trace_off(); - - - const int d = 12; - - x0[0] = 1.; - x0[1] = 0.2; - x0[2] = -0.5; - x0[3] = -0.4; - - cout.precision(6); cout << scientific; - - - /*************************************************** - * calculation of Lie derivatives of scalar fields * - ***************************************************/ - - double** scalar = myalloc2(m_H, d+1); - - cout << "Lie derivatives:" << endl << endl; - - // calculate Lie derivatives using Lie drivers - lie_scalar(TAPE_F, TAPE_H, n, m_H, x0, d, scalar); - - for (int i = 0; i <= d; i++) - { - for (int j = 0; j < m_H; j++) - cout << "Lfh_" << i << "_" << j << " =\t" << scalar[j][i] << endl; - cout << endl; - } - - cout << endl; - myfree2(scalar); - - - /**************************************************************** - * calculation of gradients of Lie derivatives of scalar fields * - ****************************************************************/ - - double*** gradient = myalloc3(m_H, n, d+1); - - cout << "gradients of Lie derivatives:" << endl << endl; - - // calculate gradients of Lie derivatives using Lie drivers - lie_gradient(TAPE_F, TAPE_H, n, m_H, x0, d, gradient); - - for (int i = 0; i <= d; i++) - { - for (int j = 0; j < m_H; j++) - cout << "dLfh_" << i << "_" << j << " =\t" << gradient[j][0][i] << "\t" << gradient[j][1][i] << "\t" << gradient[j][2][i] << "\t" << gradient[j][3][i] << endl; - cout << endl; - } - - cout << endl; - myfree3(gradient); +int main() { + const int n = 4, m_H = 2; + double *x0 = myalloc(n); + double vf[n], vg[n], vh[n]; + adouble aX[n], af[n], ag[n], ah[m_H]; + const double mc = 1.0, ml = 1.0, l = 1.0, g = 9.81; + + /**************************** + * Trace for vector field f * + ****************************/ + trace_on(TAPE_F); + { + for (int i = 0; i < n; i++) + aX[i] <<= x0[i]; + + af[0] = aX[2]; + af[1] = aX[3]; + af[2] = (ml * l * pow(aX[3], 2) * sin(aX[1]) + + ml * g * sin(aX[1]) * cos(aX[1])) / + (ml * pow(sin(aX[1]), 2) + mc); + af[3] = -(ml * l * pow(aX[3], 2) * sin(aX[1]) * cos(aX[1]) + + (ml + mc) * g * sin(aX[1])) / + (l * (ml * pow(sin(aX[1]), 2) + mc)); + + for (int i = 0; i < n; i++) + af[i] >>= vf[i]; + } + trace_off(); + + /**************************** + * Trace for vector field g * + ****************************/ + trace_on(TAPE_G); + { + for (int i = 0; i < n; i++) + aX[i] <<= x0[i]; + + ag[0] = 0; + ag[1] = 0; + ag[2] = 1 / (ml * pow(sin(aX[1]), 2) + mc); + ag[3] = -cos(aX[1]) / (l * (ml * pow(sin(aX[1]), 2) + mc)); + + for (int i = 0; i < n; i++) + ag[i] >>= vg[i]; + } + trace_off(); + + /********************************** + * Trace for scalar fields h1, h2 * + **********************************/ + trace_on(TAPE_H); + { + for (int i = 0; i < n; i++) + aX[i] <<= x0[i]; + + ah[0] = aX[0] + l * sin(aX[1]); + ah[1] = l * cos(aX[1]); + + for (int i = 0; i < m_H; i++) + ah[i] >>= vh[i]; + } + trace_off(); + + const int d = 12; + + x0[0] = 1.; + x0[1] = 0.2; + x0[2] = -0.5; + x0[3] = -0.4; + + cout.precision(6); + cout << scientific; + + /*************************************************** + * calculation of Lie derivatives of scalar fields * + ***************************************************/ + + double **scalar = myalloc2(m_H, d + 1); + + cout << "Lie derivatives:" << endl << endl; + + // calculate Lie derivatives using Lie drivers + lie_scalar(TAPE_F, TAPE_H, n, m_H, x0, d, scalar); + + for (int i = 0; i <= d; i++) { + for (int j = 0; j < m_H; j++) + cout << "Lfh_" << i << "_" << j << " =\t" << scalar[j][i] << endl; + cout << endl; + } + + cout << endl; + myfree2(scalar); + + /**************************************************************** + * calculation of gradients of Lie derivatives of scalar fields * + ****************************************************************/ + + double ***gradient = myalloc3(m_H, n, d + 1); + + cout << "gradients of Lie derivatives:" << endl << endl; + + // calculate gradients of Lie derivatives using Lie drivers + lie_gradient(TAPE_F, TAPE_H, n, m_H, x0, d, gradient); + + for (int i = 0; i <= d; i++) { + for (int j = 0; j < m_H; j++) + cout << "dLfh_" << i << "_" << j << " =\t" << gradient[j][0][i] << "\t" + << gradient[j][1][i] << "\t" << gradient[j][2][i] << "\t" + << gradient[j][3][i] << endl; + cout << endl; + } + + cout << endl; + myfree3(gradient); - - /******************************* - * calculation of Lie brackets * - *******************************/ + /******************************* + * calculation of Lie brackets * + *******************************/ - double** bracket = myalloc2(n, d+1); + double **bracket = myalloc2(n, d + 1); - cout << "Lie brackets:" << endl << endl; + cout << "Lie brackets:" << endl << endl; - // calculate Lie brackets using Lie drivers - lie_bracket(TAPE_F, TAPE_G, n, x0, d, bracket); + // calculate Lie brackets using Lie drivers + lie_bracket(TAPE_F, TAPE_G, n, x0, d, bracket); - for (int i = 0; i <= d; i++) - { - for (int j = 0; j < n; j++) - cout << "adfg_" << i << "_" << j << " =\t" << bracket[j][i] << endl; - cout << endl; - } + for (int i = 0; i <= d; i++) { + for (int j = 0; j < n; j++) + cout << "adfg_" << i << "_" << j << " =\t" << bracket[j][i] << endl; + cout << endl; + } - myfree2(bracket); - myfree(x0); + myfree2(bracket); + myfree(x0); - - cout << "Press RETURN to continue" << endl; - cin.get(); + cout << "Press RETURN to continue" << endl; + cin.get(); - return 0; + return 0; } diff --git a/ADOL-C/examples/additional_examples/lighthouse/cubic-2.cpp b/ADOL-C/examples/additional_examples/lighthouse/cubic-2.cpp index 29ecdb2f4..66f8757c7 100644 --- a/ADOL-C/examples/additional_examples/lighthouse/cubic-2.cpp +++ b/ADOL-C/examples/additional_examples/lighthouse/cubic-2.cpp @@ -5,13 +5,13 @@ Contents: example for cubic lighthouse example of Griewank's Book using Cardan's formula with conditionals - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ @@ -21,100 +21,102 @@ #include #define PI 3.1415926536 - /****************************************************************************/ /* ADOUBLE ROUTINE */ -adouble activeCubicLighthouse( adouble t ) { - adouble p, q, d, r, u, u1, u2, v, a, b, c, z; - /*---------------------*/ - p = tan(t); - q = p - 0.2; - p /= 3.0; - d = q*q; - d -= p*p*p; - /* 1. branch ----------*/ - r = sqrt(d); - u = q + r; - u1 = pow(fabs(u),1.0/3.0); - u2 = -u1; - condassign(u,u,u1,u2); - v = q - r; - u1 = pow(fabs(v),1.0/3.0); - u2 = -u1; - condassign(v,v,u1,u2); - c = u + v; - /* 2. branch ----------*/ - p = fabs(p); - p = sqrt(p); - q /= p*p*p; - a = acos(q); - a /= 3.0; - z = cos(a); - b = a + PI/3.0; - b = -cos(b); - z = fmin(z,b); - b = a - PI/3.0; - b = -cos(b); - z = fmin(z,b); - z = 2.0*z*p; - /*---------------------*/ - condassign(z,d,c); - z += 2.0; - return z; +adouble activeCubicLighthouse(adouble t) { + adouble p, q, d, r, u, u1, u2, v, a, b, c, z; + /*---------------------*/ + p = tan(t); + q = p - 0.2; + p /= 3.0; + d = q * q; + d -= p * p * p; + /* 1. branch ----------*/ + r = sqrt(d); + u = q + r; + u1 = pow(fabs(u), 1.0 / 3.0); + u2 = -u1; + condassign(u, u, u1, u2); + v = q - r; + u1 = pow(fabs(v), 1.0 / 3.0); + u2 = -u1; + condassign(v, v, u1, u2); + c = u + v; + /* 2. branch ----------*/ + p = fabs(p); + p = sqrt(p); + q /= p * p * p; + a = acos(q); + a /= 3.0; + z = cos(a); + b = a + PI / 3.0; + b = -cos(b); + z = fmin(z, b); + b = a - PI / 3.0; + b = -cos(b); + z = fmin(z, b); + z = 2.0 * z * p; + /*---------------------*/ + condassign(z, d, c); + z += 2.0; + return z; } /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i, vc; - int tag = 1; - double z, t, tmin, tmax, tdist, dz; - - /*--------------------------------------------------------------------------*/ - /* Preparation */ - fprintf(stdout,"CUBIC LIGHTHOUSE Using CARDAN (ADOL-C Example)\n\n"); - tmin = 0.15; - tmax = 0.24; - fprintf(stdout,"How many values = ? \n"); - scanf("%d",&vc); - - /*--------------------------------------------------------------------------*/ - t = 0.1; - adouble az,at; - trace_on(tag); - at <<= t; - az = activeCubicLighthouse(at); - az >>= z; - trace_off(); - - /*--------------------------------------------------------------------------*/ - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - - /*--------------------------------------------------------------------------*/ - tdist = (tmax-tmin)/((double) (vc-1)); - t = tmin; - for (i=0; i>= z; + trace_off(); + + /*--------------------------------------------------------------------------*/ + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + /*--------------------------------------------------------------------------*/ + tdist = (tmax - tmin) / ((double)(vc - 1)); + t = tmin; + for (i = 0; i < vc; i++) { + function(tag, 1, 1, &t, &z); + gradient(tag, 1, &t, &dz); + fprintf(stdout, "%e %e %e\n", t, z, dz); + t += tdist; + } + + /*--------------------------------------------------------------------------*/ + return 1; } - - - - diff --git a/ADOL-C/examples/additional_examples/lighthouse/cubic-iter-2.cpp b/ADOL-C/examples/additional_examples/lighthouse/cubic-iter-2.cpp index 3d40b6b0b..aea318b60 100644 --- a/ADOL-C/examples/additional_examples/lighthouse/cubic-iter-2.cpp +++ b/ADOL-C/examples/additional_examples/lighthouse/cubic-iter-2.cpp @@ -6,13 +6,13 @@ using iterative solvers (output of z_k and dz_k for fixed t) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ @@ -20,78 +20,83 @@ #include #include - /****************************************************************************/ /* ADOUBLE ROUTINE */ -adouble g( adouble z, adouble t ) { - adouble v1, v15, v2, v3, res; - v1 = z - 2.0; - v15 = v1*v1*v1; - v15 += 0.4; - v2 = tan(t); - v15 -= z * v2; - v3 = 3.0*v1*v1-v2; - v3 = fabs(v3); - res = z - v15/v3; - return res; +adouble g(adouble z, adouble t) { + adouble v1, v15, v2, v3, res; + v1 = z - 2.0; + v15 = v1 * v1 * v1; + v15 += 0.4; + v2 = tan(t); + v15 -= z * v2; + v3 = 3.0 * v1 * v1 - v2; + v3 = fabs(v3); + res = z - v15 / v3; + return res; } /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int j, ic; - int tag = 1; - double z, dz, z0, dz0, t; - double x[2], gradg[2]; + int j, ic; + int tag = 1; + double z, dz, z0, dz0, t; + double x[2], gradg[2]; - /*--------------------------------------------------------------------------*/ - /* Preparation */ - fprintf(stdout,"CUBIC LIGHTHOUSE Using ITERATION 2 (ADOL-C Example)\n\n"); - z0 = 2.1; - dz0 = 0.0; - fprintf(stdout,"t = ? \n"); - scanf("%le",&t); - fprintf(stdout,"How many iterations = ? \n"); - scanf("%d",&ic); + /*--------------------------------------------------------------------------*/ + /* Preparation */ + fprintf(stdout, "CUBIC LIGHTHOUSE Using ITERATION 2 (ADOL-C Example)\n\n"); + z0 = 2.1; + dz0 = 0.0; + fprintf(stdout, "t = ? \n"); + scanf("%le", &t); + fprintf(stdout, "How many iterations = ? \n"); + scanf("%d", &ic); + /*--------------------------------------------------------------------------*/ + /* 0. time (taping) */ + trace_on(tag); + adouble az, at; + az <<= z0; + at <<= t; + az = g(az, at); + az >>= z; + trace_off(); - /*--------------------------------------------------------------------------*/ - /* 0. time (taping) */ - trace_on(tag); - adouble az,at; - az <<= z0; - at <<= t; - az = g(az,at); - az >>= z; - trace_off(); + /*--------------------------------------------------------------------------*/ + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); - /*--------------------------------------------------------------------------*/ - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); + /*--------------------------------------------------------------------------*/ + x[1] = t; + x[0] = z0; + dz = dz0; + fprintf(stdout, " %e %e\n", x[0], dz); + for (j = 0; j < ic; j++) { + function(tag, 1, 2, x, &z); + gradient(tag, 2, x, gradg); + x[0] = z; + dz = gradg[0] * dz + gradg[1]; + fprintf(stdout, " %e %e\n", x[0], dz); + } - /*--------------------------------------------------------------------------*/ - x[1] = t; - x[0] = z0; - dz = dz0; - fprintf(stdout," %e %e\n",x[0],dz); - for (j=0; j - /****************************************************************************/ /* ADOUBLE ROUTINE */ -adouble g( adouble z, adouble t ) { - adouble v1, v15, v2, v3, res; - v1 = z - 2.0; - v15 = v1*v1*v1; - v15 += 0.4; - v2 = tan(t); - v15 -= z * v2; - v3 = 3.0*v1*v1-v2; - v3 = fabs(v3); - res = z - v15/v3; - return res; +adouble g(adouble z, adouble t) { + adouble v1, v15, v2, v3, res; + v1 = z - 2.0; + v15 = v1 * v1 * v1; + v15 += 0.4; + v2 = tan(t); + v15 -= z * v2; + v3 = 3.0 * v1 * v1 - v2; + v3 = fabs(v3); + res = z - v15 / v3; + return res; } /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i, j, vc, ic; - int tag = 1; - double z, dz, z0, dz0, t, tmin, tmax, tdist; - double x[2], gradg[2]; + int i, j, vc, ic; + int tag = 1; + double z, dz, z0, dz0, t, tmin, tmax, tdist; + double x[2], gradg[2]; - /*--------------------------------------------------------------------------*/ - /* Preparation */ - fprintf(stdout,"CUBIC LIGHTHOUSE Using ITERATION (ADOL-C Example)\n\n"); - tmin = 0.1; - tmax = 0.3; - z0 = 2.1; - dz0 = 0.0; - fprintf(stdout,"How many values = ? \n"); - scanf("%d",&vc); - fprintf(stdout,"How many iterations = ? \n"); - scanf("%d",&ic); + /*--------------------------------------------------------------------------*/ + /* Preparation */ + fprintf(stdout, "CUBIC LIGHTHOUSE Using ITERATION (ADOL-C Example)\n\n"); + tmin = 0.1; + tmax = 0.3; + z0 = 2.1; + dz0 = 0.0; + fprintf(stdout, "How many values = ? \n"); + scanf("%d", &vc); + fprintf(stdout, "How many iterations = ? \n"); + scanf("%d", &ic); + /*--------------------------------------------------------------------------*/ + /* 0. time (taping) */ + t = 0.1; + trace_on(tag); + adouble az, at; + az <<= z0; + at <<= t; + az = g(az, at); + az >>= z; + trace_off(); - /*--------------------------------------------------------------------------*/ - /* 0. time (taping) */ - t = 0.1; - trace_on(tag); - adouble az,at; - az <<= z0; - at <<= t; - az = g(az,at); - az >>= z; - trace_off(); + /*--------------------------------------------------------------------------*/ + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); - /*--------------------------------------------------------------------------*/ - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - /*--------------------------------------------------------------------------*/ - tdist = (tmax-tmin)/((double) (vc-1)); - x[1] = tmin; - for (i=0; i #define PI 3.1415926536 - /****************************************************************************/ /* ADOUBLE ROUTINE */ -adouble activeCubicLighthouse1( adouble t ) { - adouble p, q, d, r, u, u1,u2, v, c; - /*---------------------*/ - p = tan(t); - q = p - 0.2; - p /= 3.0; - d = q*q; - d -= p*p*p; - /* 1. branch ----------*/ - r = sqrt(d); - u = q + r; - u1 = pow(fabs(u),1.0/3.0); - u2 = -u1; - condassign(u,u,u1,u2); - v = q - r; - u1 = pow(fabs(v),1.0/3.0); - u2 = -u1; - condassign(v,v,u1,u2); - c = u + v; - /*---------------------*/ - c += 2.0; - return c; +adouble activeCubicLighthouse1(adouble t) { + adouble p, q, d, r, u, u1, u2, v, c; + /*---------------------*/ + p = tan(t); + q = p - 0.2; + p /= 3.0; + d = q * q; + d -= p * p * p; + /* 1. branch ----------*/ + r = sqrt(d); + u = q + r; + u1 = pow(fabs(u), 1.0 / 3.0); + u2 = -u1; + condassign(u, u, u1, u2); + v = q - r; + u1 = pow(fabs(v), 1.0 / 3.0); + u2 = -u1; + condassign(v, v, u1, u2); + c = u + v; + /*---------------------*/ + c += 2.0; + return c; } /****************************************************************************/ /* ADOUBLE ROUTINE */ -adouble activeCubicLighthouse2( adouble t ) { - adouble p, q, d, r, u, v, c, a, z, b; - /*---------------------*/ - p = tan(t); - q = p - 0.2; - p /= 3.0; - d = q*q; - d -= p*p*p; - /* 2. branch ----------*/ - p = fabs(p); - p = sqrt(p); - q /= p*p*p; - a = acos(q); - a /= 3.0; - z = cos(a); - b = a + PI/3.0; - b = -cos(b); - z = fmin(z,b); - b = a - PI/3.0; - b = -cos(b); - z = fmin(z,b); - z = 2.0*z*p; - /*---------------------*/ - z += 2.0; - return z; +adouble activeCubicLighthouse2(adouble t) { + adouble p, q, d, r, u, v, c, a, z, b; + /*---------------------*/ + p = tan(t); + q = p - 0.2; + p /= 3.0; + d = q * q; + d -= p * p * p; + /* 2. branch ----------*/ + p = fabs(p); + p = sqrt(p); + q /= p * p * p; + a = acos(q); + a /= 3.0; + z = cos(a); + b = a + PI / 3.0; + b = -cos(b); + z = fmin(z, b); + b = a - PI / 3.0; + b = -cos(b); + z = fmin(z, b); + z = 2.0 * z * p; + /*---------------------*/ + z += 2.0; + return z; } /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i, vc; - int tag1 = 1, tag2 = 2; - double z, z1, z2, t, tmin, tmax, tdist, dz; - - /*--------------------------------------------------------------------------*/ - /* Preparation */ - fprintf(stdout,"CUBIC LIGHTHOUSE Using CARDAN (ADOL-C Example)\n\n"); - tmin = 0.15; - tmax = 0.24; - fprintf(stdout,"How many values = ? \n"); - scanf("%d",&vc); - - /*--------------------------------------------------------------------------*/ - t = 0.1; - adouble az,at; - trace_on(tag1); - at <<= t; - az = activeCubicLighthouse1(at); - az >>= z; - trace_off(); - trace_on(tag2); - at <<= t; - az = activeCubicLighthouse2(at); - az >>= z; - trace_off(); - - /*--------------------------------------------------------------------------*/ - size_t tape_stats[STAT_SIZE]; - - tapestats(tag1,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - tapestats(tag2,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - /*--------------------------------------------------------------------------*/ - tdist = (tmax-tmin)/((double) (vc-1)); - t = tmin; - for (i=0; i>= z; + trace_off(); + trace_on(tag2); + at <<= t; + az = activeCubicLighthouse2(at); + az >>= z; + trace_off(); + + /*--------------------------------------------------------------------------*/ + size_t tape_stats[STAT_SIZE]; + + tapestats(tag1, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + tapestats(tag2, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + /*--------------------------------------------------------------------------*/ + tdist = (tmax - tmin) / ((double)(vc - 1)); + t = tmin; + for (i = 0; i < vc; i++) { + function(tag1, 1, 1, &t, &z1); + function(tag2, 1, 1, &t, &z2); + if (!(z1 == z1)) // check for NaN + { + gradient(tag2, 1, &t, &dz); + fprintf(stdout, "%e %e %e\n", t, z2, dz); + } else { + gradient(tag1, 1, &t, &dz); + fprintf(stdout, "%e %e %e\n", t, z1, dz); } + t += tdist; + } - /*--------------------------------------------------------------------------*/ - return 1; + /*--------------------------------------------------------------------------*/ + return 1; } - - - - diff --git a/ADOL-C/examples/additional_examples/lufact/LU.cpp b/ADOL-C/examples/additional_examples/lufact/LU.cpp index f092ce16a..9337ccdb0 100644 --- a/ADOL-C/examples/additional_examples/lufact/LU.cpp +++ b/ADOL-C/examples/additional_examples/lufact/LU.cpp @@ -4,13 +4,13 @@ Revision: $Id$ Contents: example for 'active' LU-decomposition and according solver - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _LU_C @@ -22,46 +22,44 @@ /* ADOUBLE ROUTINE */ /* Simple LU-factorization according to Crout's algorithm without pivoting */ void LUfact(int n, adouble **A) { - int i, j, k; - adouble dum; - for (j=0; j=0; i--) { - for (j=i+1; j= 0; i--) { + for (j = i + 1; j < n; j++) + bx[i] -= A[i][j] * bx[j]; + bx[i] /= A[i][i]; + } } - /****************************************************************************/ /* END OF FILE */ #undef _LU_C diff --git a/ADOL-C/examples/additional_examples/lufact/LU.h b/ADOL-C/examples/additional_examples/lufact/LU.h index 5e1425bd2..00d60a02c 100644 --- a/ADOL-C/examples/additional_examples/lufact/LU.h +++ b/ADOL-C/examples/additional_examples/lufact/LU.h @@ -4,32 +4,29 @@ Revision: $Id$ Contents: example for 'active' LU-decomposition and according solver - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #ifndef _LU_H #define _LU_H /****************************************************************************/ /* INCLUDES */ -#include // use of ALL ADOL-C interfaces - +#include // use of ALL ADOL-C interfaces /****************************************************************************/ /* Simple LU-factorization according to Crout's algorithm without pivoting */ void LUfact(int n, adouble **A); - /****************************************************************************/ /* Solution of A*x=b by forward and backward substitution */ void LUsolve(int n, adouble **A, adouble *bx); - /****************************************************************************/ /* END OF FILE */ #endif diff --git a/ADOL-C/examples/additional_examples/lufact/LUdet.cpp b/ADOL-C/examples/additional_examples/lufact/LUdet.cpp index 3b3718896..3b70b08d3 100644 --- a/ADOL-C/examples/additional_examples/lufact/LUdet.cpp +++ b/ADOL-C/examples/additional_examples/lufact/LUdet.cpp @@ -4,140 +4,134 @@ Revision: $Id$ Contents: example for * Computation of the determinant of a matrix - by LU-decomposition of the system matrix without pivoting + by LU-decomposition of the system matrix without pivoting * application of tapedoc to observe taping of the new op_codes for the elementary operations - + y += x1 * x2; - y -= x1 * x2; + y -= x1 * x2; - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ #include "LU.h" - /****************************************************************************/ /* MAIN PROGRAM */ int main() { /*------------------------------------------------------------------------*/ - /* variables */ - const int tag = 1; // tape tag - const int size = 5; // system size - const int indep = size*size; // # of indeps - const int depen = 1; // # of deps - - double A[size][size], a1[size], a2[size], det; // passive variables - adouble **AA, *AAp, Adet; // active variables - double *args = myalloc1(indep); // arguments - double *grad = myalloc1(indep); // the gradient - double **hess = myalloc2(indep,indep); // the hessian - - int i,j; - - - /*------------------------------------------------------------------------*/ - /* Info */ - fprintf(stdout,"DETERMINANT by LU-DECOMPOSITION (ADOL-C Example)\n\n"); - - - /*------------------------------------------------------------------------*/ - /* Allcoation und initialization of the system matrix */ - AA = new adouble*[size]; - AAp = new adouble[size*size]; - for (i=0; i>= det; - trace_off(); - fprintf(stdout," Determinant (original): %16.4E\n",det); - - - /*------------------------------------------------------------------------*/ - /* Recomputation of determinant */ - function(tag,depen,indep,args,&det); - fprintf(stdout," Determinant (from tape): %16.4E\n",det); - - - /*------------------------------------------------------------------------*/ - /* Computation of gradient */ - gradient(tag,indep,args,grad); - fprintf(stdout," Gradient:\n"); - for (i=0; i>= det; + trace_off(); + fprintf(stdout, " Determinant (original): %16.4E\n", det); + + /*------------------------------------------------------------------------*/ + /* Recomputation of determinant */ + function(tag, depen, indep, args, &det); + fprintf(stdout, " Determinant (from tape): %16.4E\n", det); + + /*------------------------------------------------------------------------*/ + /* Computation of gradient */ + gradient(tag, indep, args, grad); + fprintf(stdout, " Gradient:\n"); + for (i = 0; i < size; i++) { + for (j = 0; j < size; j++) + fprintf(stdout, " %14.6E", grad[i * size + j]); + fprintf(stdout, "\n"); + } + + /*------------------------------------------------------------------------*/ + /* Computation of hessian */ + hessian(tag, indep, args, hess); + fprintf(stdout, " Part of Hessian:\n"); + for (i = 0; i < size; i++) { + for (j = 0; j < size; j++) + fprintf(stdout, " %14.6E", hess[0][i * size + j]); + fprintf(stdout, "\n"); + } + + /*------------------------------------------------------------------------*/ + /* Tape-documentation */ + tape_doc(tag, depen, indep, args, &det); + + /*------------------------------------------------------------------------*/ + /* Tape statistics */ + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + /*------------------------------------------------------------------------*/ + /* That's it */ + return 1; } - - - - - - - - diff --git a/ADOL-C/examples/additional_examples/lufact/LUsolve.cpp b/ADOL-C/examples/additional_examples/lufact/LUsolve.cpp index d9eb3ed1d..241d0749e 100644 --- a/ADOL-C/examples/additional_examples/lufact/LUsolve.cpp +++ b/ADOL-C/examples/additional_examples/lufact/LUsolve.cpp @@ -4,20 +4,20 @@ Revision: $Id$ Contents: example for * Computation of the determinant of a matrix - by LU-decomposition of the system matrix without pivoting + by LU-decomposition of the system matrix without pivoting * application of tapedoc to observe taping of the new op_codes for the elementary operations - + y += x1 * x2; - y -= x1 * x2; + y -= x1 * x2; - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ @@ -27,123 +27,116 @@ /****************************************************************************/ /* MAIN PROGRAM */ int main() { /*------------------------------------------------------------------------*/ - /* variables */ - const int tag = 1; // tape tag - const int size = 5; // system size - const int indep = size*size+size; // # of indeps - const int depen = size; // # of deps - - double A[size][size], a1[size], a2[size], // passive variables - b[size], x[size]; - adouble **AA, *AAp, *Abx; // active variables - double *args = myalloc1(indep); // arguments - double **jac = myalloc2(depen,indep); // the Jacobian - double *laghessvec = myalloc1(indep); // Hessian-vector product - - int i,j; - - - /*------------------------------------------------------------------------*/ - /* Info */ - fprintf(stdout,"LINEAR SYSTEM SOLVING by " - "LU-DECOMPOSITION (ADOL-C Example)\n\n"); - - - /*------------------------------------------------------------------------*/ - /* Allocation und initialization of the system matrix */ - AA = new adouble*[size]; - AAp = new adouble[size*size]; - for (i=0; i>= x[i]; - trace_off(); - fprintf(stdout," x[0] (original): %16.4E\n",x[0]); - - - /*------------------------------------------------------------------------*/ - /* Recomputation */ - function(tag,depen,indep,args,x); - fprintf(stdout," x[0] (from tape): %16.4E\n",x[0]); - - - /*------------------------------------------------------------------------*/ - /* Computation of Jacobian */ - jacobian(tag,depen,indep,args,jac); - fprintf(stdout," Jacobian:\n"); - for (i=0; i>= x[i]; + trace_off(); + fprintf(stdout, " x[0] (original): %16.4E\n", x[0]); + + /*------------------------------------------------------------------------*/ + /* Recomputation */ + function(tag, depen, indep, args, x); + fprintf(stdout, " x[0] (from tape): %16.4E\n", x[0]); + + /*------------------------------------------------------------------------*/ + /* Computation of Jacobian */ + jacobian(tag, depen, indep, args, jac); + fprintf(stdout, " Jacobian:\n"); + for (i = 0; i < depen; i++) { + for (j = 0; j < indep; j++) + fprintf(stdout, " %14.6E", jac[i][j]); + fprintf(stdout, "\n"); + } + + /*------------------------------------------------------------------------*/ + /* Computation of Lagrange-Hessian-vector product */ + lagra_hess_vec(tag, depen, indep, args, args, x, laghessvec); + fprintf(stdout, " Part of Lagrange-Hessian-vector product:\n"); + for (i = 0; i < size; i++) { + for (j = 0; j < size; j++) + fprintf(stdout, " %14.6E", laghessvec[i * size + j]); + fprintf(stdout, "\n"); + } + + /*------------------------------------------------------------------------*/ + /* Tape-documentation */ + tape_doc(tag, depen, indep, args, x); + + /*------------------------------------------------------------------------*/ + /* Tape statistics */ + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + /*------------------------------------------------------------------------*/ + /* That's it */ + return 1; } - - - - - - - - diff --git a/ADOL-C/examples/additional_examples/ode/vfunc_eutroph.cpp b/ADOL-C/examples/additional_examples/ode/vfunc_eutroph.cpp index 6f32282db..105171e4a 100644 --- a/ADOL-C/examples/additional_examples/ode/vfunc_eutroph.cpp +++ b/ADOL-C/examples/additional_examples/ode/vfunc_eutroph.cpp @@ -4,24 +4,24 @@ Revision: $Id$ Contents: example for function module containing the eutroph example (based on eutroph.C of version 1.7) - + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indEPS_ ) (6) void originalVectorFunction( double* indEPS_, double* dEPS_ ) - (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) + (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _VFUNC_EUTROPH_C_ @@ -31,13 +31,12 @@ #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "eutrophexam.ctrl"; +const char *controlFileName = "eutrophexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -46,168 +45,164 @@ int depDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ -const double IK = 0.11 ; -const double FRZ = 0.3 ; +const double IK = 0.11; +const double FRZ = 0.3; const double EFFUZ = 0.6; const double PRITZ = 1.0e-3; -const double RESP = 5.0e-3; -const double sinK = 5.0e-3; +const double RESP = 5.0e-3; +const double sinK = 5.0e-3; const double PRITA = 0.1; -const double RZ = 1.0e-2; -const double K2 = 4.0e-2; -const double K3 = 5.0e-1; -const double KSP = 2.0e2; -const double KSF = 1.0; -const double BETA = 100.0/1.25; +const double RZ = 1.0e-2; +const double K2 = 4.0e-2; +const double K3 = 5.0e-1; +const double KSP = 2.0e2; +const double KSF = 1.0; +const double BETA = 100.0 / 1.25; const double ALPHA = 0.002; -const double TRZ = 2.0; -const double EPS_P = 0.4; -const double FI1 = 230.4; -const double FI3 = 282.8; -const double FI4 = 127.5; -const double FI5 = 141.9; -const double p = 40.0; +const double TRZ = 2.0; +const double EPS_P = 0.4; +const double FI1 = 230.4; +const double FI3 = 282.8; +const double FI4 = 127.5; +const double FI5 = 141.9; +const double p = 40.0; const double DEPTH = 45; -const double MORITZ= 0.075; -const double Q = 0.786E6; -const double VND = 0.265E9; +const double MORITZ = 0.075; +const double Q = 0.786E6; +const double VND = 0.265E9; /* fix controls */ -const double PRFOS = 0.5*p; -const double M = 0.1; -const double ZMIX = (45+RZ)/2; -const double QIV = 0.297E-02/3; - +const double PRFOS = 0.5 * p; +const double M = 0.1; +const double ZMIX = (45 + RZ) / 2; +const double QIV = 0.297E-02 / 3; /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"EUTROPHEXAM (ADOL-C Example)\n\n"); +void initProblemParameters(void) { + fprintf(stdout, "EUTROPHEXAM (ADOL-C Example)\n\n"); - /* number of indEPS_ & dEPS_ */ - indepDim = 5; - depDim = 5; + /* number of indEPS_ & dEPS_ */ + indepDim = 5; + depDim = 5; } - /****************************************************************************/ /* INITIALIZE INDEPS_ */ -void initIndependents( double* indEPS_ ) { - indEPS_[0] = 0.5; - indEPS_[1] = 0.0005; - indEPS_[2] = 4.0; - indEPS_[3] = 0.01; /* originally 0.0 */ - indEPS_[4] = 0.02; /* originally 0.0 */ +void initIndependents(double *indEPS_) { + indEPS_[0] = 0.5; + indEPS_[1] = 0.0005; + indEPS_[2] = 4.0; + indEPS_[3] = 0.01; /* originally 0.0 */ + indEPS_[4] = 0.02; /* originally 0.0 */ } - /****************************************************************************/ /* ORIGINAL SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The eutroph function */ -void eutroph( double* indEPS_, double* dEPS_ ) { - double T, TEMP, FOTOP, I, PIDI, EPS_, temp, temp2, GROW; - double V; - T = indEPS_[4]; - TEMP = 9.5+7.9*sin(T+FI1); - FOTOP = 12.0+4.19*sin(T+280.0); - I = 229.0+215.0*sin(T+FI3)+15.3*sin(2.0*T+FI4)+ 21.7*sin(3.0*T+FI5); - PIDI = 0.8+.25*cos(T)-.12*cos(2.*T); - V = VND; - if (T < 72) - I *= 0.603; - EPS_ = ALPHA * indEPS_[0] + indEPS_[3] + EPS_P; - temp = I * exp(-EPS_*ZMIX); - temp2 = 2*IK*FOTOP; - GROW = 1.2*FOTOP/EPS_/ZMIX * (1.333 * atan (I / temp2) - -IK*FOTOP / I * log( 1 + pow((I /temp2 ),2)) - -1.333 * atan (temp / temp2) - +IK*FOTOP/temp* log( 1+pow(temp/temp2, 2) )) - * indEPS_[2] /(KSF+indEPS_[2]) - * 0.366 * pow(K2,0.52) * exp(0.09*TEMP) * pow(indEPS_[0],(1-0.52)); - dEPS_[0] = GROW - RESP * TEMP * indEPS_[0] - FRZ - * indEPS_[0] * indEPS_[1] - sinK * PIDI * indEPS_[0] - + (PRITA - indEPS_[0]) * Q/VND; - dEPS_[1] = FRZ * indEPS_[0] / K2 * indEPS_[1] / 1000 - * EFFUZ*KSP / KSP+indEPS_[0] - - RZ * indEPS_[1] - MORITZ * indEPS_[1] + (PRITZ - indEPS_[1] ) * Q/V; - dEPS_[2] = K3 * (-GROW + RESP * TEMP * indEPS_[0] + FRZ * indEPS_[0] - * indEPS_[1] * (1 - EFFUZ*KSP /(KSP+indEPS_[0]) ) + RZ * K2 * 1000 * - indEPS_[1] + MORITZ * K2 * 1000 * indEPS_[1] ) - + (PRFOS - indEPS_[2])* Q/V; - dEPS_[3] = (- indEPS_[3] * Q + BETA * M / TRZ)/VND; - dEPS_[4] = 1; +void eutroph(double *indEPS_, double *dEPS_) { + double T, TEMP, FOTOP, I, PIDI, EPS_, temp, temp2, GROW; + double V; + T = indEPS_[4]; + TEMP = 9.5 + 7.9 * sin(T + FI1); + FOTOP = 12.0 + 4.19 * sin(T + 280.0); + I = 229.0 + 215.0 * sin(T + FI3) + 15.3 * sin(2.0 * T + FI4) + + 21.7 * sin(3.0 * T + FI5); + PIDI = 0.8 + .25 * cos(T) - .12 * cos(2. * T); + V = VND; + if (T < 72) + I *= 0.603; + EPS_ = ALPHA * indEPS_[0] + indEPS_[3] + EPS_P; + temp = I * exp(-EPS_ * ZMIX); + temp2 = 2 * IK * FOTOP; + GROW = + 1.2 * FOTOP / EPS_ / ZMIX * + (1.333 * atan(I / temp2) - IK * FOTOP / I * log(1 + pow((I / temp2), 2)) - + 1.333 * atan(temp / temp2) + + IK * FOTOP / temp * log(1 + pow(temp / temp2, 2))) * + indEPS_[2] / (KSF + indEPS_[2]) * 0.366 * pow(K2, 0.52) * + exp(0.09 * TEMP) * pow(indEPS_[0], (1 - 0.52)); + dEPS_[0] = GROW - RESP * TEMP * indEPS_[0] - FRZ * indEPS_[0] * indEPS_[1] - + sinK * PIDI * indEPS_[0] + (PRITA - indEPS_[0]) * Q / VND; + dEPS_[1] = FRZ * indEPS_[0] / K2 * indEPS_[1] / 1000 * EFFUZ * KSP / KSP + + indEPS_[0] - RZ * indEPS_[1] - MORITZ * indEPS_[1] + + (PRITZ - indEPS_[1]) * Q / V; + dEPS_[2] = + K3 * (-GROW + RESP * TEMP * indEPS_[0] + + FRZ * indEPS_[0] * indEPS_[1] * + (1 - EFFUZ * KSP / (KSP + indEPS_[0])) + + RZ * K2 * 1000 * indEPS_[1] + MORITZ * K2 * 1000 * indEPS_[1]) + + (PRFOS - indEPS_[2]) * Q / V; + dEPS_[3] = (-indEPS_[3] * Q + BETA * M / TRZ) / VND; + dEPS_[4] = 1; } /*--------------------------------------------------------------------------*/ /* The interface function */ -void originalVectorFunction( double* indEPS_, double* dEPS_ ) { - eutroph(indEPS_,dEPS_); +void originalVectorFunction(double *indEPS_, double *dEPS_) { + eutroph(indEPS_, dEPS_); } - /****************************************************************************/ /* TAPING SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The active eutroph function */ -void activeEutroph( adouble* indEPS_, adouble* dEPS_ ) { - adouble T, TEMP, FOTOP, I, PIDI, EPS_, temp, temp2, GROW; - double V; - T = indEPS_[4]; - TEMP = 9.5+7.9*sin(T+FI1); - FOTOP = 12.0+4.19*sin(T+280.0); - I = 229.0+215.0*sin(T+FI3)+15.3*sin(2.0*T+FI4)+ 21.7*sin(3.0*T+FI5); - PIDI = 0.8+.25*cos(T)-.12*cos(2.*T); - V = VND; - if (T < 72) - I *= 0.603; - EPS_ = ALPHA * indEPS_[0] + indEPS_[3] + EPS_P; - temp = I * exp(-EPS_*ZMIX); - temp2 = 2*IK*FOTOP; - GROW = 1.2*FOTOP/EPS_/ZMIX * (1.333 * atan (I / temp2) - -IK*FOTOP / I * log( 1 + pow((I /temp2 ),2)) - -1.333 * atan (temp / temp2) - +IK*FOTOP/temp* log( 1+pow(temp/temp2, 2) )) - * indEPS_[2] /(KSF+indEPS_[2]) - * 0.366 * pow(K2,0.52) * exp(0.09*TEMP) * pow(indEPS_[0],(1-0.52)); - dEPS_[0] = GROW - RESP * TEMP * indEPS_[0] - FRZ - * indEPS_[0] * indEPS_[1] - sinK * PIDI * indEPS_[0] - + (PRITA - indEPS_[0]) * Q/VND; - dEPS_[1] = FRZ * indEPS_[0] / K2 * indEPS_[1] / 1000 - * EFFUZ*KSP / KSP+indEPS_[0] - - RZ * indEPS_[1] - MORITZ * indEPS_[1] + (PRITZ - indEPS_[1] ) * Q/V; - dEPS_[2] = K3 * (-GROW + RESP * TEMP * indEPS_[0] + FRZ * indEPS_[0] - * indEPS_[1] * (1 - EFFUZ*KSP /(KSP+indEPS_[0]) ) + RZ * K2 * 1000 * - indEPS_[1] + MORITZ * K2 * 1000 * indEPS_[1] ) - + (PRFOS - indEPS_[2])* Q/V; - dEPS_[3] = (- indEPS_[3] * Q + BETA * M / TRZ)/VND; - dEPS_[4] = 1; +void activeEutroph(adouble *indEPS_, adouble *dEPS_) { + adouble T, TEMP, FOTOP, I, PIDI, EPS_, temp, temp2, GROW; + double V; + T = indEPS_[4]; + TEMP = 9.5 + 7.9 * sin(T + FI1); + FOTOP = 12.0 + 4.19 * sin(T + 280.0); + I = 229.0 + 215.0 * sin(T + FI3) + 15.3 * sin(2.0 * T + FI4) + + 21.7 * sin(3.0 * T + FI5); + PIDI = 0.8 + .25 * cos(T) - .12 * cos(2. * T); + V = VND; + if (T < 72) + I *= 0.603; + EPS_ = ALPHA * indEPS_[0] + indEPS_[3] + EPS_P; + temp = I * exp(-EPS_ * ZMIX); + temp2 = 2 * IK * FOTOP; + GROW = + 1.2 * FOTOP / EPS_ / ZMIX * + (1.333 * atan(I / temp2) - IK * FOTOP / I * log(1 + pow((I / temp2), 2)) - + 1.333 * atan(temp / temp2) + + IK * FOTOP / temp * log(1 + pow(temp / temp2, 2))) * + indEPS_[2] / (KSF + indEPS_[2]) * 0.366 * pow(K2, 0.52) * + exp(0.09 * TEMP) * pow(indEPS_[0], (1 - 0.52)); + dEPS_[0] = GROW - RESP * TEMP * indEPS_[0] - FRZ * indEPS_[0] * indEPS_[1] - + sinK * PIDI * indEPS_[0] + (PRITA - indEPS_[0]) * Q / VND; + dEPS_[1] = FRZ * indEPS_[0] / K2 * indEPS_[1] / 1000 * EFFUZ * KSP / KSP + + indEPS_[0] - RZ * indEPS_[1] - MORITZ * indEPS_[1] + + (PRITZ - indEPS_[1]) * Q / V; + dEPS_[2] = + K3 * (-GROW + RESP * TEMP * indEPS_[0] + + FRZ * indEPS_[0] * indEPS_[1] * + (1 - EFFUZ * KSP / (KSP + indEPS_[0])) + + RZ * K2 * 1000 * indEPS_[1] + MORITZ * K2 * 1000 * indEPS_[1]) + + (PRFOS - indEPS_[2]) * Q / V; + dEPS_[3] = (-indEPS_[3] * Q + BETA * M / TRZ) / VND; + dEPS_[4] = 1; } - /*--------------------------------------------------------------------------*/ /* The interface function */ -void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) { - int i; - trace_on(tag); - adouble* activeIndEPS_ = new adouble[indepDim]; - adouble* activeDEPS_ = new adouble[depDim]; - adouble* aIP = activeIndEPS_; - double* iP = indEPS_; - for (i=0; i>= *iP++; - trace_off(); +void tapingVectorFunction(int tag, double *indEPS_, double *dEPS_) { + int i; + trace_on(tag); + adouble *activeIndEPS_ = new adouble[indepDim]; + adouble *activeDEPS_ = new adouble[depDim]; + adouble *aIP = activeIndEPS_; + double *iP = indEPS_; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + activeEutroph(activeIndEPS_, activeDEPS_); + aIP = activeDEPS_; + iP = dEPS_; + for (i = 0; i < depDim; i++) + *aIP++ >>= *iP++; + trace_off(); } #undef _VFUNC_EUTROPH_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/ode/vfunc_fic.cpp b/ADOL-C/examples/additional_examples/ode/vfunc_fic.cpp index ebc925a46..83c156920 100644 --- a/ADOL-C/examples/additional_examples/ode/vfunc_fic.cpp +++ b/ADOL-C/examples/additional_examples/ode/vfunc_fic.cpp @@ -3,24 +3,24 @@ File: vfunc_fic.cpp Revision: $Id$ Contents: example for function module containing the flow in a channel - + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indEPS_ ) (6) void originalVectorFunction( double* indEPS_, double* dEPS_ ) - (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) + (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _VFUNC_FIC_C_ @@ -30,13 +30,12 @@ #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "ficexam.ctrl"; +const char *controlFileName = "ficexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -48,300 +47,310 @@ int depDim; int nIntern; double r__; - /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"FICEXAM Flow in a channel (ADOL-C Example)\n\n"); - - /* number of indeps & deps */ - if (indepDim > 0) - nIntern = indepDim; - else { - fprintf(stdout," number of independents/8 = ? "); - fscanf(stdin,"%d",&nIntern); - fprintf(stdout,"\n"); - } - indepDim = nIntern*8; - depDim = indepDim; +void initProblemParameters(void) { + fprintf(stdout, "FICEXAM Flow in a channel (ADOL-C Example)\n\n"); + + /* number of indeps & deps */ + if (indepDim > 0) + nIntern = indepDim; + else { + fprintf(stdout, " number of independents/8 = ? "); + fscanf(stdin, "%d", &nIntern); + fprintf(stdout, "\n"); + } + indepDim = nIntern * 8; + depDim = indepDim; } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - int i, j, var; - double xt, h; - h = 1.0/nIntern; - xt = 0.0; - for (i=1; i<=nIntern; i++) { - var = 8*(i-1); - indeps[var] = xt*xt*(3.0-2.0*xt); - indeps[var+1] = 6.0 * xt * (1.0 - xt); - indeps[var+2] = 6.0 * (1.0 -2.0*xt); - indeps[var+3] = -12.0; - for (j=1; j<=4; j++) - indeps[var+3+j] = 0.0; - xt = xt + h; - } - r__ = 0; +void initIndependents(double *indeps) { + int i, j, var; + double xt, h; + h = 1.0 / nIntern; + xt = 0.0; + for (i = 1; i <= nIntern; i++) { + var = 8 * (i - 1); + indeps[var] = xt * xt * (3.0 - 2.0 * xt); + indeps[var + 1] = 6.0 * xt * (1.0 - xt); + indeps[var + 2] = 6.0 * (1.0 - 2.0 * xt); + indeps[var + 3] = -12.0; + for (j = 1; j <= 4; j++) + indeps[var + 3 + j] = 0.0; + xt = xt + h; + } + r__ = 0; } - /****************************************************************************/ /* ORIGINAL SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The fic function */ -int pdficfj ( int n, double* x, double* fvec, double r__, int nIntern ) { /* Initialized data */ - static double rho[4] = { .0694318413734436035, .330009490251541138, - .66999053955078125, .930568158626556396 }; - - /* System generated locals */ - int i__1; - - /* Local variables */ - static double h__; - static int i__, j, k, m; - static double w[5], nf, hm, dw[40] /* was [5][8] */, rhnfhk[1280] - /* was [4][8][8][5] */, rhoijh; - static int eqn, var; - --fvec; - --x; - - /* Function Body */ - /* Initialization. */ - h__ = 1. / (double) (nIntern); - hm = 1.; - for (m = 0; m <= 4; ++m) { - for (i__ = 1; i__ <= 4; ++i__) { - rhoijh = hm; - for (j = 0; j <= 7; ++j) { - nf = 1.; - for (k = 0; k <= 7; ++k) { - rhnfhk[i__ + (j + (k + (m << 3) << 3) << 2) - 1] = rhoijh - / nf; - nf *= (double) (k + 1); - } - rhoijh *= rho[i__ - 1]; - } +int pdficfj(int n, double *x, double *fvec, double r__, + int nIntern) { /* Initialized data */ + static double rho[4] = {.0694318413734436035, .330009490251541138, + .66999053955078125, .930568158626556396}; + + /* System generated locals */ + int i__1; + + /* Local variables */ + static double h__; + static int i__, j, k, m; + static double w[5], nf, hm, dw[40] /* was [5][8] */, + rhnfhk[1280] + /* was [4][8][8][5] */, + rhoijh; + static int eqn, var; + --fvec; + --x; + + /* Function Body */ + /* Initialization. */ + h__ = 1. / (double)(nIntern); + hm = 1.; + for (m = 0; m <= 4; ++m) { + for (i__ = 1; i__ <= 4; ++i__) { + rhoijh = hm; + for (j = 0; j <= 7; ++j) { + nf = 1.; + for (k = 0; k <= 7; ++k) { + rhnfhk[i__ + (j + (k + (m << 3) << 3) << 2) - 1] = rhoijh / nf; + nf *= (double)(k + 1); } - hm *= h__; + rhoijh *= rho[i__ - 1]; + } } - /* Evaluate the function */ - /* Initialize arrays. */ - i__1 = n; - for (j = 1; j <= i__1; ++j) { - fvec[j] = 0.; + hm *= h__; + } + /* Evaluate the function */ + /* Initialize arrays. */ + i__1 = n; + for (j = 1; j <= i__1; ++j) { + fvec[j] = 0.; + } + for (k = 1; k <= 8; ++k) { + for (j = 1; j <= 5; ++j) { + dw[j + k * 5 - 6] = 0.; } - for (k = 1; k <= 8; ++k) { - for (j = 1; j <= 5; ++j) { - dw[j + k * 5 - 6] = 0.; - } - } - /* Set up the boundary equations at t = 0. u(0) = 0, u'(0) = 0. */ - fvec[1] = x[1]; - fvec[2] = x[2]; - i__1 = nIntern; - for (i__ = 1; i__ <= i__1; ++i__) { - var = i__ - 1 << 3; - /* Set up the collocation equations. */ - eqn = var + 2; - for (k = 1; k <= 4; ++k) { - for (m = 1; m <= 5; ++m) { - w[m - 1] = 0.; - for (j = m; j <= 4; ++j) { - w[m - 1] += rhnfhk[k + (j - m + (j - m + (j - m << 3) << - - 3) << 2) - 1] * x[var + j]; - dw[m + j * 5 - 6] = rhnfhk[k + (j - m + (j - m + (j - m - << - 3) << 3) << 2) - 1]; - } - for (j = 1; j <= 4; ++j) { - w[m - 1] += rhnfhk[k + (j + 4 - m + (j + 4 - m + (4 - m - + - 1 << 3) << 3) << 2) - 1] * x[var + 4 + j]; - dw[m + (j + 4) * 5 - 6] = rhnfhk[k + (j + 4 - m + (j + 4 - - - m + (4 - m + 1 << 3) << 3) << 2) - 1]; - } - } - fvec[eqn + k] = w[4] - r__ * (w[1] * w[2] - w[0] * w[3]); - } - /* Set up the continuity equations. */ - eqn = var + 6; - for (m = 1; m <= 4; ++m) { - w[m - 1] = 0.; - for (j = m; j <= 4; ++j) { - w[m - 1] += rhnfhk[(j - m + (j - m << 3)) * 32] * x[var + j] - ; - - dw[m + j * 5 - 6] = rhnfhk[(j - m + (j - m << 3)) * 32]; - } - for (j = 1; j <= 4; ++j) { - w[m - 1] += rhnfhk[(j + 4 - m + (4 - m + 1 << 3)) * 32] * x[ - var + 4 + j]; - dw[m + (j + 4) * 5 - 6] = rhnfhk[(j + 4 - m + (4 - m + 1 << - 3) - ) * 32]; - } - } - if (i__ == nIntern) { - goto L230; + } + /* Set up the boundary equations at t = 0. u(0) = 0, u'(0) = 0. */ + fvec[1] = x[1]; + fvec[2] = x[2]; + i__1 = nIntern; + for (i__ = 1; i__ <= i__1; ++i__) { + var = i__ - 1 << 3; + /* Set up the collocation equations. */ + eqn = var + 2; + for (k = 1; k <= 4; ++k) { + for (m = 1; m <= 5; ++m) { + w[m - 1] = 0.; + for (j = m; j <= 4; ++j) { + w[m - 1] += rhnfhk[k + + (j - m + + (j - m + (j - m << 3) << + + 3) + << 2) - + 1] * + x[var + j]; + dw[m + j * 5 - 6] = + rhnfhk[k + (j - m + (j - m + (j - m << 3) << 3) << 2) - 1]; } - for (m = 1; m <= 4; ++m) { - fvec[eqn + m] = x[var + 8 + m] - w[m - 1]; + for (j = 1; j <= 4; ++j) { + w[m - 1] += + rhnfhk[k + + (j + 4 - m + (j + 4 - m + (4 - m + 1 << 3) << 3) << 2) - + 1] * + x[var + 4 + j]; + dw[m + (j + 4) * 5 - 6] = rhnfhk[k + + (j + 4 - m + + (j + 4 + + - m + (4 - m + 1 << 3) + << 3) + << 2) - + 1]; } + } + fvec[eqn + k] = w[4] - r__ * (w[1] * w[2] - w[0] * w[3]); } - /* Set up the boundary equations at t = 1. u(1) = 1, u'(1) = 0. */ + /* Set up the continuity equations. */ + eqn = var + 6; + for (m = 1; m <= 4; ++m) { + w[m - 1] = 0.; + for (j = m; j <= 4; ++j) { + w[m - 1] += rhnfhk[(j - m + (j - m << 3)) * 32] * x[var + j]; + + dw[m + j * 5 - 6] = rhnfhk[(j - m + (j - m << 3)) * 32]; + } + for (j = 1; j <= 4; ++j) { + w[m - 1] += + rhnfhk[(j + 4 - m + (4 - m + 1 << 3)) * 32] * x[var + 4 + j]; + dw[m + (j + 4) * 5 - 6] = rhnfhk[(j + 4 - m + (4 - m + 1 << 3)) * 32]; + } + } + if (i__ == nIntern) { + goto L230; + } + for (m = 1; m <= 4; ++m) { + fvec[eqn + m] = x[var + 8 + m] - w[m - 1]; + } + } + /* Set up the boundary equations at t = 1. u(1) = 1, u'(1) = 0. */ L230: - fvec[n - 1] = w[0] - 1.; - fvec[n] = w[1]; - return 0; + fvec[n - 1] = w[0] - 1.; + fvec[n] = w[1]; + return 0; } /*--------------------------------------------------------------------------*/ /* The interface function */ -void originalVectorFunction( double* indeps, double* deps ) { - pdficfj(indepDim,indeps,deps,r__,nIntern); +void originalVectorFunction(double *indeps, double *deps) { + pdficfj(indepDim, indeps, deps, r__, nIntern); } - /****************************************************************************/ /* TAPING SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The active fic function */ -int dficfj( int n, adouble* x, adouble* fvec, double r__, int nIntern ) { - /* Initialized data */ - static adouble rho[4] = { .0694318413734436035, .330009490251541138, - .66999053955078125, .930568158626556396 }; - - /* System generated locals */ - int i__1; - - /* Local variables */ - static adouble h__; - static int i__, j, k, m; - static adouble nf, hm, dw[40] /* was [5][8] */, rhnfhk[1280] - /* was [4][8][8][5] */, rhoijh; - static int eqn, var; - adouble w[5]; - --fvec; - --x; - - /* Function Body */ - /* Initialization. */ - h__ = 1. / (double) (nIntern); - hm = 1.; - for (m = 0; m <= 4; ++m) { - for (i__ = 1; i__ <= 4; ++i__) { - rhoijh = hm; - for (j = 0; j <= 7; ++j) { - nf = 1.; - for (k = 0; k <= 7; ++k) { - rhnfhk[i__ + (j + (k + (m << 3) << 3) << 2) - 1] = rhoijh - / nf; - nf *= (double) (k + 1); - } - rhoijh *= rho[i__ - 1]; - } +int dficfj(int n, adouble *x, adouble *fvec, double r__, int nIntern) { + /* Initialized data */ + static adouble rho[4] = {.0694318413734436035, .330009490251541138, + .66999053955078125, .930568158626556396}; + + /* System generated locals */ + int i__1; + + /* Local variables */ + static adouble h__; + static int i__, j, k, m; + static adouble nf, hm, dw[40] /* was [5][8] */, + rhnfhk[1280] + /* was [4][8][8][5] */, + rhoijh; + static int eqn, var; + adouble w[5]; + --fvec; + --x; + + /* Function Body */ + /* Initialization. */ + h__ = 1. / (double)(nIntern); + hm = 1.; + for (m = 0; m <= 4; ++m) { + for (i__ = 1; i__ <= 4; ++i__) { + rhoijh = hm; + for (j = 0; j <= 7; ++j) { + nf = 1.; + for (k = 0; k <= 7; ++k) { + rhnfhk[i__ + (j + (k + (m << 3) << 3) << 2) - 1] = rhoijh / nf; + nf *= (double)(k + 1); } - hm *= h__; + rhoijh *= rho[i__ - 1]; + } } - /* Evaluate the function */ - /* Initialize arrays. */ - i__1 = n; - for (j = 1; j <= i__1; ++j) { - fvec[j] = 0.; + hm *= h__; + } + /* Evaluate the function */ + /* Initialize arrays. */ + i__1 = n; + for (j = 1; j <= i__1; ++j) { + fvec[j] = 0.; + } + for (k = 1; k <= 8; ++k) { + for (j = 1; j <= 5; ++j) { + dw[j + k * 5 - 6] = 0.; } - for (k = 1; k <= 8; ++k) { - for (j = 1; j <= 5; ++j) { - dw[j + k * 5 - 6] = 0.; - } - } - /* Set up the boundary equations at t = 0. u(0) = 0, u'(0) = 0. */ - fvec[1] = x[1]; - fvec[2] = x[2]; - i__1 = nIntern; - for (i__ = 1; i__ <= i__1; ++i__) { - var = i__ - 1 << 3; - /* Set up the collocation equations. */ - eqn = var + 2; - for (k = 1; k <= 4; ++k) { - for (m = 1; m <= 5; ++m) { - w[m - 1] = 0.; - for (j = m; j <= 4; ++j) { - w[m - 1] += rhnfhk[k + (j - m + (j - m + (j - m << 3) << - - 3) << 2) - 1] * x[var + j]; - dw[m + j * 5 - 6] = rhnfhk[k + (j - m + (j - m + (j - m - << - 3) << 3) << 2) - 1]; - } - for (j = 1; j <= 4; ++j) { - w[m - 1] += rhnfhk[k + (j + 4 - m + (j + 4 - m + (4 - m - + - 1 << 3) << 3) << 2) - 1] * x[var + 4 + j]; - dw[m + (j + 4) * 5 - 6] = rhnfhk[k + (j + 4 - m + (j + 4 - - - m + (4 - m + 1 << 3) << 3) << 2) - 1]; - } - } - fvec[eqn + k] = w[4] - r__ * (w[1] * w[2] - w[0] * w[3]); - } - /* Set up the continuity equations. */ - eqn = var + 6; - for (m = 1; m <= 4; ++m) { - w[m - 1] = 0.; - for (j = m; j <= 4; ++j) { - w[m - 1] += rhnfhk[(j - m + (j - m << 3)) * 32] * x[var + j] - ; - dw[m + j * 5 - 6] = rhnfhk[(j - m + (j - m << 3)) * 32]; - } - for (j = 1; j <= 4; ++j) { - w[m - 1] += rhnfhk[(j + 4 - m + (4 - m + 1 << 3)) * 32] * x[ - var + 4 + j]; - dw[m + (j + 4) * 5 - 6] = rhnfhk[(j + 4 - m + (4 - m + 1 << - 3) - ) * 32]; - } + } + /* Set up the boundary equations at t = 0. u(0) = 0, u'(0) = 0. */ + fvec[1] = x[1]; + fvec[2] = x[2]; + i__1 = nIntern; + for (i__ = 1; i__ <= i__1; ++i__) { + var = i__ - 1 << 3; + /* Set up the collocation equations. */ + eqn = var + 2; + for (k = 1; k <= 4; ++k) { + for (m = 1; m <= 5; ++m) { + w[m - 1] = 0.; + for (j = m; j <= 4; ++j) { + w[m - 1] += rhnfhk[k + + (j - m + + (j - m + (j - m << 3) << + + 3) + << 2) - + 1] * + x[var + j]; + dw[m + j * 5 - 6] = + rhnfhk[k + (j - m + (j - m + (j - m << 3) << 3) << 2) - 1]; } - if (i__ != nIntern) { - for (m = 1; m <= 4; ++m) { - fvec[eqn + m] = x[var + 8 + m] - w[m - 1]; - } + for (j = 1; j <= 4; ++j) { + w[m - 1] += + rhnfhk[k + + (j + 4 - m + (j + 4 - m + (4 - m + 1 << 3) << 3) << 2) - + 1] * + x[var + 4 + j]; + dw[m + (j + 4) * 5 - 6] = rhnfhk[k + + (j + 4 - m + + (j + 4 + + - m + (4 - m + 1 << 3) + << 3) + << 2) - + 1]; } + } + fvec[eqn + k] = w[4] - r__ * (w[1] * w[2] - w[0] * w[3]); } - /* Set up the boundary equations at t = 1. u(1) = 1, u'(1) = 0. */ - fvec[n - 1] = w[0] - 1.; - fvec[n] = w[1]; - return 0; + /* Set up the continuity equations. */ + eqn = var + 6; + for (m = 1; m <= 4; ++m) { + w[m - 1] = 0.; + for (j = m; j <= 4; ++j) { + w[m - 1] += rhnfhk[(j - m + (j - m << 3)) * 32] * x[var + j]; + dw[m + j * 5 - 6] = rhnfhk[(j - m + (j - m << 3)) * 32]; + } + for (j = 1; j <= 4; ++j) { + w[m - 1] += + rhnfhk[(j + 4 - m + (4 - m + 1 << 3)) * 32] * x[var + 4 + j]; + dw[m + (j + 4) * 5 - 6] = rhnfhk[(j + 4 - m + (4 - m + 1 << 3)) * 32]; + } + } + if (i__ != nIntern) { + for (m = 1; m <= 4; ++m) { + fvec[eqn + m] = x[var + 8 + m] - w[m - 1]; + } + } + } + /* Set up the boundary equations at t = 1. u(1) = 1, u'(1) = 0. */ + fvec[n - 1] = w[0] - 1.; + fvec[n] = w[1]; + return 0; } /*--------------------------------------------------------------------------*/ /* The interface function */ -void tapingVectorFunction( int tag, double* indeps, double* deps ) { - int i; - trace_on(tag); - adouble* activeIndeps = new adouble[indepDim]; - adouble* activeDeps = new adouble[depDim]; - adouble* aIP = activeIndeps; - double* iP = indeps; - for (i=0; i>= *iP++; - trace_off(); +void tapingVectorFunction(int tag, double *indeps, double *deps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *activeDeps = new adouble[depDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + dficfj(indepDim, activeIndeps, activeDeps, r__, nIntern); + aIP = activeDeps; + iP = deps; + for (i = 0; i < depDim; i++) + *aIP++ >>= *iP++; + trace_off(); } #undef _VFUNC_FIC_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/ode/vfunc_robertson.cpp b/ADOL-C/examples/additional_examples/ode/vfunc_robertson.cpp index 34b365d37..128c7ffb9 100644 --- a/ADOL-C/examples/additional_examples/ode/vfunc_robertson.cpp +++ b/ADOL-C/examples/additional_examples/ode/vfunc_robertson.cpp @@ -4,24 +4,24 @@ Revision: $Id$ Contents: example for function module containing the Robertson test problem (based on odexam.C of version 1.7) - + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indEPS_ ) (6) void originalVectorFunction( double* indEPS_, double* dEPS_ ) - (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) + (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _VFUNC_ROBERTSON_C_ @@ -31,13 +31,12 @@ #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "robertsonexam.ctrl"; +const char *controlFileName = "robertsonexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -47,81 +46,69 @@ int depDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ - /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"ROBERTSONEXAM (ADOL-C Example)\n\n"); +void initProblemParameters(void) { + fprintf(stdout, "ROBERTSONEXAM (ADOL-C Example)\n\n"); - /* number of indeps & deps */ - indepDim = 3; - depDim = 3; + /* number of indeps & deps */ + indepDim = 3; + depDim = 3; } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - indeps[0] = 1.0; - indeps[1] = 0.01; /* originally 0.0 */ - indeps[2] = 0.02; /* originally 0.0 */ +void initIndependents(double *indeps) { + indeps[0] = 1.0; + indeps[1] = 0.01; /* originally 0.0 */ + indeps[2] = 0.02; /* originally 0.0 */ } - /****************************************************************************/ /* ORIGINAL SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The Robertson test problem */ -void robertson( double* indeps, double* deps ) { - deps[0] = -sin(indeps[2]) + 1.0e8*indeps[2]*(1.0-1.0/indeps[0]); - deps[1] = -10.0*indeps[0] - + 3.0e7*indeps[2]*(1.0-indeps[1]); - deps[2] = -deps[0] - deps[1]; +void robertson(double *indeps, double *deps) { + deps[0] = -sin(indeps[2]) + 1.0e8 * indeps[2] * (1.0 - 1.0 / indeps[0]); + deps[1] = -10.0 * indeps[0] + 3.0e7 * indeps[2] * (1.0 - indeps[1]); + deps[2] = -deps[0] - deps[1]; } /*--------------------------------------------------------------------------*/ /* The interface function */ -void originalVectorFunction( double* indeps, double* deps ) { - robertson(indeps,deps); +void originalVectorFunction(double *indeps, double *deps) { + robertson(indeps, deps); } - /****************************************************************************/ /* TAPING SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The active Robertson test problem */ -void activeRobertson( adouble* indeps, adouble* deps ) { - deps[0] = -sin(indeps[2]) + 1.0e8*indeps[2]*(1.0-1.0/indeps[0]); - deps[1] = -10.0*indeps[0] - + 3.0e7*indeps[2]*(1.0-indeps[1]); - deps[2] = -deps[0] - deps[1]; +void activeRobertson(adouble *indeps, adouble *deps) { + deps[0] = -sin(indeps[2]) + 1.0e8 * indeps[2] * (1.0 - 1.0 / indeps[0]); + deps[1] = -10.0 * indeps[0] + 3.0e7 * indeps[2] * (1.0 - indeps[1]); + deps[2] = -deps[0] - deps[1]; } - /*--------------------------------------------------------------------------*/ /* The interface function */ -void tapingVectorFunction( int tag, double* indeps, double* deps ) { - int i; - trace_on(tag); - adouble* activeIndeps = new adouble[indepDim]; - adouble* activeDeps = new adouble[depDim]; - adouble* aIP = activeIndeps; - double* iP = indeps; - for (i=0; i>= *iP++; - trace_off(); +void tapingVectorFunction(int tag, double *indeps, double *deps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *activeDeps = new adouble[depDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + activeRobertson(activeIndeps, activeDeps); + aIP = activeDeps; + iP = deps; + for (i = 0; i < depDim; i++) + *aIP++ >>= *iP++; + trace_off(); } #undef _VFUNC_ROBERTSON_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/ode/vgenodemain.cpp b/ADOL-C/examples/additional_examples/ode/vgenodemain.cpp index 559a4fc0f..7b9cb86e3 100644 --- a/ADOL-C/examples/additional_examples/ode/vgenodemain.cpp +++ b/ADOL-C/examples/additional_examples/ode/vgenodemain.cpp @@ -2,43 +2,40 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: vgenodemain.cpp Revision: $Id$ - Contents: example for ODE Generic Main File: - for use with function modules containing vector examples + Contents: example for ODE Generic Main File: + for use with function modules containing vector examples (e.g. vgen_eutroph.C) - + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indEPS_ ) (6) void originalVectorFunction( double* indEPS_, double* dEPS_ ) - (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) + (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ ) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - ----------------------------------------------------------------------------*/ +---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include #include "../clock/myclock.h" +#include #include - /****************************************************************************/ /* MACROS */ #define TIMEFORMAT " %12.6E units, %12.6E scunits, %12.6E seconds\n" - /****************************************************************************/ /* EXTERNAL STUFF FROM FUNCTION MODULES*/ @@ -49,254 +46,254 @@ extern int depDim; /*--------------------------------------------------------------------------*/ /* Init Problem Parameters */ -extern void initProblemParameters( void ); +extern void initProblemParameters(void); /*--------------------------------------------------------------------------*/ /* Initialize indeps */ -extern void initIndependents( double* indeps ); +extern void initIndependents(double *indeps); /*--------------------------------------------------------------------------*/ /* original RHS */ -extern void originalVectorFunction( double* indeps, double* deps ); +extern void originalVectorFunction(double *indeps, double *deps); /*--------------------------------------------------------------------------*/ /* taping RHS */ -extern void tapingVectorFunction( int tag, double* indeps, double* deps ); - +extern void tapingVectorFunction(int tag, double *indeps, double *deps); /****************************************************************************/ /* MAIN */ int main() { - int degree, evalCount, taskCount; - int tag = 1; /* tape tag */ - int i, j, k, yes; - double tau; - - fprintf(stdout,"GENERIC ODE EXAMPLE (ADOL-C Example)\n\n"); - /*------------------------------------------------------------------------*/ - /* Initialize all problem parameters (including dimension) */ - initProblemParameters(); - if (indepDim != depDim) { - fprintf(stdout," ERROR indepDim (%d) != depDim (%d)\n",indepDim,depDim); - exit(-1); + int degree, evalCount, taskCount; + int tag = 1; /* tape tag */ + int i, j, k, yes; + double tau; + + fprintf(stdout, "GENERIC ODE EXAMPLE (ADOL-C Example)\n\n"); + /*------------------------------------------------------------------------*/ + /* Initialize all problem parameters (including dimension) */ + initProblemParameters(); + if (indepDim != depDim) { + fprintf(stdout, " ERROR indepDim (%d) != depDim (%d)\n", indepDim, depDim); + exit(-1); + } + + /*------------------------------------------------------------------------*/ + /* Check main parameters */ + fprintf(stdout, " Highest derivatives =? \n "); + scanf("%d", °ree); + fprintf(stdout, " Number of evaluations =? \n "); + scanf("%d", &evalCount); + fprintf(stdout, " Nonzero scaling paramater =?\n "); + scanf("%le", &tau); + + /*------------------------------------------------------------------------*/ + /* Initialize the independent variables */ + double *indeps = new double[indepDim]; + double *deps = new double[depDim]; + double **indeps2 = myalloc(indepDim, degree + 1); + initIndependents(indeps); + for (i = 0; i < indepDim; i++) { + indeps2[i][0] = indeps[i]; + for (j = 1; j <= degree; j++) + indeps2[i][j] = 0.0; + } + + /*------------------------------------------------------------------------*/ + /* Necessary variable */ + double ***B = myalloc(indepDim, indepDim, degree); + double ***A = myalloc(indepDim, indepDim, degree); + double **w = myalloc(indepDim, degree + 1); + ; + short **nonzero = new short *[indepDim]; + for (i = 0; i < indepDim; i++) + nonzero[i] = new short[indepDim]; + + /****************************************************************************/ + /* 0. ORIGINAL FUNCTION EVALUATION */ + /* ---> always */ + taskCount = 0; + fprintf(stdout, "\nTASK %d: Original function evaluation\n", taskCount++); + + double t00 = myclock(); + for (i = 1; i <= evalCount; i++) { + indeps[1] = 1.0 / i; + originalVectorFunction(indeps, deps); + } + double t01 = myclock(); + + double rtu, stu; + if (t01 - t00) { + stu = 2.0 / (t01 - t00) / ((double)degree) / (((double)degree) + 1.0); + rtu = 1.0 / (t01 - t00); + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, 1.0, + 2.0 / ((double)degree) / (((double)degree) + 1.0), + (t01 - t00) / evalCount); + } else { + fprintf(stdout, " !!! zero timing !!!\n"); + fprintf(stdout, " set time unit to 1.0\n"); + rtu = 1.0; + stu = 2.0 / ((double)degree) / (((double)degree) + 1.0); + } + + /****************************************************************************/ + /* 1. TAPING THE FUNCTION */ + /* ---> always */ + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: Taping the function\n", taskCount++); + + t00 = myclock(1); + /* NOTE: taping will be performed ONCE only */ + tapingVectorFunction(tag, indeps, deps); + t01 = myclock(); + + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * rtu * evalCount, + (t01 - t00) * stu * evalCount, (t01 - t00)); + + /****************************************************************************/ + /* 2. FORODE */ + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: forode(tag, n=%d, tau=%f, dnew=%d, X[n][d+1])\n", + taskCount++, indepDim, tau, degree); + t00 = myclock(); + for (j = 0; j < evalCount; j++) + forode(tag, indepDim, tau, degree, indeps2); + t01 = myclock(); + + fprintf(stdout, TIMEFORMAT, (t01 - t00) * rtu, (t01 - t00) * stu, + (t01 - t00) / evalCount); + + /****************************************************************************/ + /* 3. REVERSE */ + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: reverse(tag, m=%d, n=%d, d=%d, Z[n][n][d+1]," + " nz[n][n])\n", + taskCount++, depDim, indepDim, degree - 1); + + t00 = myclock(); + for (j = 0; j < evalCount; j++) + reverse(tag, depDim, indepDim, degree - 1, A, nonzero); + t01 = myclock(); + + fprintf(stdout, TIMEFORMAT, (t01 - t00) * rtu, (t01 - t00) * stu, + (t01 - t00) / evalCount); + + /****************************************************************************/ + /* 4.ACCODE */ + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: accode(tag, n=%d, tau=%f, d=%d, Z[n][n][d+1]," + " B[n][n][d+1], nz[n][n])\n", + taskCount++, indepDim, tau, degree - 1); + + t00 = myclock(); + for (j = 0; j < evalCount; j++) + accode(indepDim, tau, degree - 1, A, B, nonzero); + t01 = myclock(); + + fprintf(stdout, TIMEFORMAT, (t01 - t00) * rtu, (t01 - t00) * stu, + (t01 - t00) / evalCount); + + /****************************************************************************/ + /* 5. RESULTS */ + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: CHECK results\n\n", taskCount++); + + /*------------------------------------------------------------------------*/ + fprintf(stdout, " Print out the nonzero pattern? (0/1)\n "); + scanf("%d", &yes); + if (yes) { + fprintf(stdout, " 4 = transcend , 3 = rational , 2 = polynomial ," + " 1 = linear , 0 = zero \n"); + fprintf(stdout, " negative number k indicate that entries of all " + "B_j with j < -k vanish \n"); + for (i = 0; i < indepDim; i++) { + for (j = 0; j < indepDim; j++) + fprintf(stdout, "%3d ", nonzero[i][j]); + fprintf(stdout, "\n"); } - - /*------------------------------------------------------------------------*/ - /* Check main parameters */ - fprintf(stdout," Highest derivatives =? \n "); - scanf("%d",°ree); - fprintf(stdout," Number of evaluations =? \n "); - scanf("%d",&evalCount); - fprintf(stdout," Nonzero scaling paramater =?\n "); - scanf("%le",&tau); - - /*------------------------------------------------------------------------*/ - /* Initialize the independent variables */ - double* indeps = new double[indepDim]; - double* deps = new double[depDim]; - double** indeps2 = myalloc(indepDim,degree+1); - initIndependents(indeps); - for (i=0; i always */ - taskCount = 0; - fprintf(stdout,"\nTASK %d: Original function evaluation\n", - taskCount++); - - double t00 = myclock(); - for (i=1; i<=evalCount; i++) { - indeps[1] = 1.0/i; - originalVectorFunction(indeps,deps); + } + + /*------------------------------------------------------------------------*/ + /* The D+1 columns of z should now be consistent with the + ODE as represented by the time. Feeding z into forward + we obtain a coeffient array w, whose columns should + equal to the shifted and scaled columns of z */ + fprintf(stdout, "\n Check that forward reproduces the Taylor series \n"); + forward(tag, depDim, indepDim, degree - 1, degree, indeps2, w); + double err = 0, avg; + for (i = 0; i < degree; i++) + for (j = 0; j < indepDim; j++) { + avg = (fabs(w[j][i] * tau) + fabs(indeps2[j][i + 1] * (i + 1))) / 2.0; + if (avg < 0.1) + avg = 0.1; + err += fabs(w[j][i] * tau - indeps2[j][i + 1] * (i + 1)) / avg; } - double t01 = myclock(); - - double rtu, stu; - if (t01-t00) { - stu = 2.0/(t01-t00)/((double)degree)/(((double)degree)+1.0); - rtu = 1.0/(t01-t00); - fprintf(stdout," "); - fprintf(stdout,TIMEFORMAT,1.0,2.0/((double)degree)/(((double)degree)+1.0), - (t01-t00)/evalCount); - } else { - fprintf(stdout," !!! zero timing !!!\n"); - fprintf(stdout," set time unit to 1.0\n"); - rtu = 1.0; - stu = 2.0/((double)degree)/(((double)degree)+1.0); + fprintf(stdout, "%14.6E = total error \n", err); + + /*------------------------------------------------------------------------*/ + /* If desired print out Jacobians of Taylor coeffcients with + respect to the base point */ + fprintf(stdout, "\n Print Jacobian of Taylor coefficient vectors? (0/1)\n "); + scanf("%d", &yes); + if (yes) { + for (i = 0; i < degree; i++) { + fprintf(stdout, "\n\t<-- B(%d)\n", i); + for (j = 0; j < indepDim; j++) { + for (k = 0; k < indepDim; k++) + fprintf(stdout, "%14.6E ", B[j][k][i]); + fprintf(stdout, "\n"); + } } - - - /****************************************************************************/ - /* 1. TAPING THE FUNCTION */ - /* ---> always */ - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: Taping the function\n", - taskCount++); - - t00 = myclock(1); - /* NOTE: taping will be performed ONCE only */ - tapingVectorFunction(tag,indeps,deps); - t01 = myclock(); - - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - fprintf(stdout," "); - fprintf(stdout,TIMEFORMAT,(t01-t00)*rtu*evalCount, - (t01-t00)*stu*evalCount, - (t01-t00)); - - /****************************************************************************/ - /* 2. FORODE */ - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forode(tag, n=%d, tau=%f, dnew=%d, X[n][d+1])\n", - taskCount++,indepDim,tau,degree); - t00 = myclock(); - for (j=0; j %14.6E\n", i, + err); } - /*------------------------------------------------------------------------*/ - /* The D+1 columns of z should now be consistent with the - ODE as represented by the time. Feeding z into forward - we obtain a coeffient array w, whose columns should - equal to the shifted and scaled columns of z */ - fprintf(stdout,"\n Check that forward reproduces the Taylor series \n"); - forward(tag,depDim,indepDim,degree-1,degree,indeps2,w); - double err = 0, avg; - for (i=0; i %14.6E\n", - i,err); - } - - return 1; + return 1; } - /****************************************************************************/ /* THAT'S ALL */ - diff --git a/ADOL-C/examples/additional_examples/openmp_exam/liborpar.cpp b/ADOL-C/examples/additional_examples/openmp_exam/liborpar.cpp index ecd5f183d..550eb018a 100644 --- a/ADOL-C/examples/additional_examples/openmp_exam/liborpar.cpp +++ b/ADOL-C/examples/additional_examples/openmp_exam/liborpar.cpp @@ -3,58 +3,57 @@ File: liborpar.cpp Revision: $Id$ Contents: example for differentiation of OpemMP parallel programs - parallel version + parallel version Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /* Program to compute deltas and vegas of swaption portfolio - from forward and reverse mode pathwise sensitivities - in parallel written by Andrea Walther in 2008-11 based on - code written by written by Mike Giles in 2005-7 which is - again based on code written by Zhao and Glasserman at + from forward and reverse mode pathwise sensitivities + in parallel written by Andrea Walther in 2008-11 based on + code written by written by Mike Giles in 2005-7 which is + again based on code written by Zhao and Glasserman at Columbia University */ using namespace std; -#include -#include -#include #include +#include +#include +#include #include "adolc/adolc.h" #ifdef _OPENMP -#include -#include + #include + #include #endif /* calculate path values */ template -void path_calc(const int N, const int Nmat, const double delta, - ADdouble L[], const double lambda[], ADdouble z[]) -{ - int i, n; - double lam, con1; +void path_calc(const int N, const int Nmat, const double delta, ADdouble L[], + const double lambda[], ADdouble z[]) { + int i, n; + double lam, con1; ADdouble v, vrat; ADdouble sqez; - - for(n=0; n -void portfolio(const int N, const int Nmat, const double delta, - const int Nopt, const int maturities[], - const double swaprates[], - const ADdouble L[], ADdouble& v ) -{ - int i, m, n; +void portfolio(const int N, const int Nmat, const double delta, const int Nopt, + const int maturities[], const double swaprates[], + const ADdouble L[], ADdouble &v) { + int i, m, n; ADdouble b, s, swapval, *B, *S; B = new ADdouble[N]; S = new ADdouble[N]; - + b = 1.0; s = 0.0; - - for (n=Nmat; n>= v[init]; + for (k = 0; k < N; k++) + La[k] <<= 0.050000; + for (j = 0; j < Nmat; j++) + za[j] <<= z[init][j]; + + path_calc(N, Nmat, delta, La, lambda, za); + portfolio(N, Nmat, delta, Nopt, maturities, swaprates, La, va); + + va >>= v[init]; trace_off(1); - - for(l=init;l -#include -#include #include +#include +#include +#include #include /* calculate path values */ template -void path_calc(const int N, const int Nmat, const double delta, - ADdouble L[], const double lambda[], ADdouble z[]) -{ - int i, n; - double lam, con1; +void path_calc(const int N, const int Nmat, const double delta, ADdouble L[], + const double lambda[], ADdouble z[]) { + int i, n; + double lam, con1; ADdouble v, vrat; ADdouble sqez; - - for(n=0; n -void portfolio(const int N, const int Nmat, const double delta, - const int Nopt, const int maturities[], - const double swaprates[], - const ADdouble L[], ADdouble& v ) -{ - int i, m, n; +void portfolio(const int N, const int Nmat, const double delta, const int Nopt, + const int maturities[], const double swaprates[], + const ADdouble L[], ADdouble &v) { + int i, m, n; ADdouble b, s, swapval, *B, *S; B = new ADdouble[N]; S = new ADdouble[N]; - + b = 1.0; s = 0.0; - - for (n=Nmat; n>= v[i]; - trace_off(1); - - for(i=0;i>= v[i]; + trace_off(1); + + for (i = 0; i < npath; i++) + gradient(1, N + Nmat, xp[i], grad[i]); + + delete[] (La); + + vtot = 0; + for (i = 0; i < npath; i++) { + vtot += v[i]; + for (j = 0; j < N; j++) + gradtot[j] += grad[i][j]; + } + vtot = vtot / npath; + for (j = 0; j < N; j++) + gradtot[j] /= npath; + + printf("Gradient: \n"); + for (i = 0; i < N; i++) + printf(" %f \n", gradtot[i]); + + return 0; +} diff --git a/ADOL-C/examples/additional_examples/param/paramexam.cpp b/ADOL-C/examples/additional_examples/param/paramexam.cpp index 4710370d7..1e7f08001 100644 --- a/ADOL-C/examples/additional_examples/param/paramexam.cpp +++ b/ADOL-C/examples/additional_examples/param/paramexam.cpp @@ -3,11 +3,11 @@ File: paramexam.cpp Revision: $Id$ Contents: example for parameter dependent functions - + Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ @@ -23,71 +23,70 @@ using namespace std; /****************************************************************************/ /* CONSTANTS & VARIABLES */ const double TE = 0.01; /* originally 0.0 */ -const double R = sqrt(2.0); - +const double R = sqrt(2.0); /****************************************************************************/ /* HELMHOLTZ ENERGY */ -adouble energy( int n, adouble x[], double bv[] ) { - adouble he, xax, bx, tem; - int i,j; - xax = 0; - bx = 0; - he = 0; - for (i=0; i>= result; - trace_off(); - reverse(1,1,n,0,1.0,grad); /* reverse computation of gradient */ - hessian2(1,n,px,hess); - tt1e = myclock(); - - /*--------------------------------------------------------------------------*/ - imd_rev = 1; /* Tracing with keep */ - tt2s = myclock(); - trace_on(2,imd_rev); - for (j=0; j>= result_p; - trace_off(); - reverse(2,1,n,0,1.0,grad_p); /* reverse computation of gradient */ - hessian2(2,n,px,hess_p); - tt2e = myclock(); - - /*--------------------------------------------------------------------------*/ - - for (j=0; j>= result_a; - trace_off(); - reverse(3,1,2*n,0,1.0,grad_a); /* reverse computation of gradient */ - hessian2(3,2*n,lpx,hess_a); - tt3e = myclock(); - /*--------------------------------------------------------------------------*/ - - printTapeStats(stdout,1); - printTapeStats(stdout,2); - printTapeStats(stdout,3); - fprintf(stdout, "%14.6E -- energy\n",result); - fprintf(stdout, "%14.6E -- energy\n",result_p); - fprintf(stdout, "%14.6E -- energy\n",result_a); - - /*--------------------------------------------------------------------------*/ - - for (l=0; l>= result; - trace_off(); - - reverse(1,1,n,0,1.0,grad); /* reverse computation of gradient */ - hessian2(1,n,px,hess); - trt1e = myclock(); - - fprintf(stdout, "%14.6E -- energy\n",result); - fprintf(stdout, "%14.6E -- energy\n",result_p); - fprintf(stdout, "%14.6E -- energy\n",result_a); - - for (l=0; l>= result; + trace_off(); + reverse(1, 1, n, 0, 1.0, grad); /* reverse computation of gradient */ + hessian2(1, n, px, hess); + tt1e = myclock(); + + /*--------------------------------------------------------------------------*/ + imd_rev = 1; /* Tracing with keep */ + tt2s = myclock(); + trace_on(2, imd_rev); + for (j = 0; j < n; j++) + x[j] <<= px[j]; + he = energy_p(n, x, bv); + he >>= result_p; + trace_off(); + reverse(2, 1, n, 0, 1.0, grad_p); /* reverse computation of gradient */ + hessian2(2, n, px, hess_p); + tt2e = myclock(); + + /*--------------------------------------------------------------------------*/ + + for (j = 0; j < n; j++) { + lpx[j] = px[j]; + lpx[n + j] = bv[j]; + } + imd_rev = 1; /* Tracing with keep */ + tt3s = myclock(); + trace_on(3, imd_rev); + for (j = 0; j < n; j++) + x[j] <<= px[j]; + for (j = 0; j < n; j++) + b[j] <<= bv[j]; + he = energy_a(n, x, b); + he >>= result_a; + trace_off(); + reverse(3, 1, 2 * n, 0, 1.0, grad_a); /* reverse computation of gradient */ + hessian2(3, 2 * n, lpx, hess_a); + tt3e = myclock(); + /*--------------------------------------------------------------------------*/ + + printTapeStats(stdout, 1); + printTapeStats(stdout, 2); + printTapeStats(stdout, 3); + fprintf(stdout, "%14.6E -- energy\n", result); + fprintf(stdout, "%14.6E -- energy\n", result_p); + fprintf(stdout, "%14.6E -- energy\n", result_a); + + /*--------------------------------------------------------------------------*/ + + for (l = 0; l < n; l++) /* results */ + fprintf(stdout, "%3d: 2*%14.6E - %14.6E - %14.6E = %14.6E ( = 0 )\n", l, + grad[l], grad_p[l], grad_a[l], 2 * grad[l] - grad_p[l] - grad_a[l]); + + /*--------------------------------------------------------------------------*/ + /* change constant parameters */ + fprintf(stdout, "changed constant parameters\n"); + for (j = 0; j < n; j++) + bv[j] = 0.01 * (1.0 + fabs(sin(double(j)))); + + /* parameter tape */ + tpxs = myclock(); + set_param_vec(2, n, bv); + zos_forward(2, 1, n, 1, px, &result_p); + reverse(2, 1, n, 0, 1.0, grad_p); + hessian2(2, n, px, hess_p); + tpxe = myclock(); + + /* double independents tape */ + for (j = 0; j < n; j++) { + lpx[j] = px[j]; + lpx[n + j] = bv[j]; + } + tixs = myclock(); + zos_forward(3, 1, 2 * n, 1, lpx, &result_a); + reverse(3, 1, 2 * n, 0, 1.0, grad_a); + hessian2(3, 2 * n, lpx, hess_a); + tixe = myclock(); + + /*--------------------------------------------------------------------------*/ + /* with retaping on tape 1 */ + trt1s = myclock(); + trace_on(1, imd_rev); + for (j = 0; j < n; j++) + x[j] <<= px[j]; + he = energy(n, x, bv); + he >>= result; + trace_off(); + + reverse(1, 1, n, 0, 1.0, grad); /* reverse computation of gradient */ + hessian2(1, n, px, hess); + trt1e = myclock(); + + fprintf(stdout, "%14.6E -- energy\n", result); + fprintf(stdout, "%14.6E -- energy\n", result_p); + fprintf(stdout, "%14.6E -- energy\n", result_a); + + for (l = 0; l < n; l++) /* results */ + fprintf(stdout, "%3d: 2*%14.6E - %14.6E - %14.6E = %14.6E ( = 0 )\n", l, + grad[l], grad_p[l], grad_a[l], 2 * grad[l] - grad_p[l] - grad_a[l]); + + fprintf(stdout, "\n\n Times for "); + fprintf(stdout, "\n Tracing + Reverse + Hess2 1: \t%E", tt1e - tt1s); + fprintf(stdout, "\n Tracing + Reverse + Hess2 2: \t%E", tt2e - tt2s); + fprintf(stdout, "\n Tracing + Reverse + Hess2 3: \t%E", tt3e - tt3s); + fprintf(stdout, "\n Retracing Reverse + Hess2 1: \t%E", trt1e - trt1s); + fprintf(stdout, "\n Point change grad + Hess2 2: \t%E", tpxe - tpxs); + fprintf(stdout, "\n Point change grad + Hess2 3: \t%E", tixe - tixs); + + myfree2(hess); + myfree2(hess_p); + myfree2(hess_a); + delete[] bv; + delete[] px; + delete[] grad; + delete[] grad_p; + delete[] lpx; + delete[] grad_a; + delete[] x; + return 0; } diff --git a/ADOL-C/examples/additional_examples/pow/powexam.cpp b/ADOL-C/examples/additional_examples/pow/powexam.cpp index 01ab7f5fa..986a0e57a 100644 --- a/ADOL-C/examples/additional_examples/pow/powexam.cpp +++ b/ADOL-C/examples/additional_examples/pow/powexam.cpp @@ -4,19 +4,19 @@ Revision: $Id$ Contents: example for computation of n-th power - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include // use of ALL ADOL-C interfaces +#include // use of ALL ADOL-C interfaces #include using namespace std; @@ -26,79 +26,80 @@ using namespace std; /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i,tag = 1; - int n; - double e; + int i, tag = 1; + int n; + double e; - cout << "COMPUTATION OF x^e\n\n"; - cout << "e=? \n"; // input the desired degree - cin >> e; + cout << "COMPUTATION OF x^e\n\n"; + cout << "e=? \n"; // input the desired degree + cin >> e; - n = (int) e; - if (n < 0) - n = -n; - // allocations and initializations - double** X; - double** Y; - X = myalloc2(1,n+4); - Y = myalloc2(1,n+4); - cout << "value of x=? \n"; - cin >> X[0][0]; // function value = 0. coefficient - X[0][1] = 1.0; // first derivative = 1. coefficient - X[0][2] = 0.0; // second derivative = 2. coefficient - for(i=1; i> X[0][0]; // function value = 0. coefficient + X[0][1] = 1.0; // first derivative = 1. coefficient + X[0][2] = 0.0; // second derivative = 2. coefficient + for (i = 1; i < n + 2; i++) + X[0][i + 2] = 0; // further coefficients + double **Z; // used for checking consistency + Z = myalloc2(1, n + 2); // between forward and reverse - adouble y,x; // declare active variables - // beginning of active section - trace_on(tag); // tag = 1 and keep = 0 - x <<= X[0][0]; // only one independent var - y = 1; - for(i=0;i>= Y[0][0]; // only one dependent adouble - trace_off(); // no global adouble has died - // end of active section */ - double u[1]; // weighting vector - u[0]=1; // for reverse call - for(i=0; i>= Y[0][0]; // only one dependent adouble + trace_off(); // no global adouble has died + // end of active section */ + double u[1]; // weighting vector + u[0] = 1; // for reverse call + for (i = 0; i < n + 2; i++) // note that keep = i+1 in call + { + forward(tag, 1, 1, i, i + 1, X, Y); // evaluate the i-the derivative + cout << "Result: " << Y[0][0] << "\n"; + if (i == 0) + cout << i << " " << Y[0][i] << " - " << y.value() << " = " + << Y[0][i] - y.value() << " (should be 0)\n"; + else { + Z[0][i] = Z[0][i - 1] / i; // scale derivative to Taylorcoeff. + cout << i << " " << Y[0][i] << " - " << Z[0][i] << " = " + << Y[0][i] - Z[0][i] << " (should be 0)\n"; + } + reverse(tag, 1, 1, i, u, Z); // evaluate the (i+1)-st deriv. + } // end for - cout << "\n\n"; - trace_on(tag); // tag = 1 and keep = 0 - x <<= X[0][0]; // only one independent var - y = pow(x,e); // actual function call - y >>= Y[0][0]; // only one dependent adouble - trace_off(); // no global adouble has died - // end of active section */ - u[0]=1; // for reverse call - for(i=0; i>= Y[0][0]; // only one dependent adouble + trace_off(); // no global adouble has died + // end of active section */ + u[0] = 1; // for reverse call + for (i = 0; i < n + 2; i++) // note that keep = i+1 in call + { + forward(tag, 1, 1, i, i + 1, X, Y); // evaluate the i-the derivative + cout << "Result: " << Y[0][0] << "\n"; + if (i == 0) + cout << i << " " << Y[0][i] << " - " << y.value() << " = " + << Y[0][i] - y.value() << " (should be 0)\n"; + else { + Z[0][i] = Z[0][i - 1] / i; // scale derivative to Taylorcoeff. + cout << i << " " << Y[0][i] << " - " << Z[0][i] << " = " + << Y[0][i] - Z[0][i] << " (should be 0)\n\n"; + } + reverse(tag, 1, 1, i, u, Z); // evaluate the (i+1)-st deriv. + } // end for - return 1; + return 1; } // end main - diff --git a/ADOL-C/examples/additional_examples/scal/scalexam.cpp b/ADOL-C/examples/additional_examples/scal/scalexam.cpp index 7e38c09e5..30d6385da 100644 --- a/ADOL-C/examples/additional_examples/scal/scalexam.cpp +++ b/ADOL-C/examples/additional_examples/scal/scalexam.cpp @@ -3,186 +3,190 @@ File: scalexam.cpp Revision: $Id$ Contents: - This program can be used to verify the consistency and - correctness of derivatives computed by ADOL-C in its forward - and reverse mode. - Ther use is required to select one integer input id. - For positive n = id the monomial x^n is evaluated recursively - at x=0.5 and all its nonzero Taylor coeffcients at this point - are evaluated in the forward and reverse mode. + This program can be used to verify the consistency and + correctness of derivatives computed by ADOL-C in its forward + and reverse mode. + Ther use is required to select one integer input id. + For positive n = id the monomial x^n is evaluated recursively + at x=0.5 and all its nonzero Taylor coeffcients at this point + are evaluated in the forward and reverse mode. A negative choice of id >= -9 leads to one of nine identities, whose derivatives should be trivial. These identities may be used to check the correctness of particular code segments in the ADOL-C sources uni5_.c and *o_rev.c. No timings are performed in this example program. - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ #include -#include #include +#include using namespace std; /****************************************************************************/ /* POWER */ /* The monomial evaluation routine which has been obtained from the original version by retyping all `doubles' as `adoubles' */ -adouble power( adouble x, int n ) { - adouble z = 1; - if (n > 0) { - int nh =n/2; - z = power(x,nh); - z *= z; - if (2*nh != n) - z *= x; - return z; - } else - if (n == 0) - return z; - else - return 1.0/power(x,-n); +adouble power(adouble x, int n) { + adouble z = 1; + if (n > 0) { + int nh = n / 2; + z = power(x, nh); + z *= z; + if (2 * nh != n) + z *= x; + return z; + } else if (n == 0) + return z; + else + return 1.0 / power(x, -n); } - /****************************************************************************/ /* MAIN */ int main() { - int n, i, id; - int tag = 0; - /*--------------------------------------------------------------------------*/ - fprintf(stdout,"SCALEXAM (ADOL-C Example)\n\n"); - fprintf(stdout,"problem number(-1 .. -10) / degree of monomial =? \n"); - scanf("%d",&id); - n = id >0 ? id : 3; - - double *xp,*yp; - xp = new double[n+4]; - yp = new double[n+4]; - yp[0] = 0; - xp[0] = 0.5; - xp[1] = 1.0; - - /*--------------------------------------------------------------------------*/ - int dum = 1; - trace_on(tag,dum); // Begin taping all calculations with 'adoubles' - adouble y,x; - x <<= xp[0]; - if (id >= 0) { - fprintf(stdout,"Evaluate and differentiate recursive power routine \n"); - y = power(x,n); - } else { - fprintf(stdout, - "Check Operations and Functions by Algebraic Identities \n"); - switch (id) { - case -1 : - fprintf(stdout, - "Addition/Subtraction: y = x + x - (2.0/3)*x - x/3 \n"); - y = x + x - (2.0/3)*x - x/3 ; - break; - case -2 : - fprintf(stdout,"Multiplication/divison: y = x*x/x \n"); - y = x*x/x; - break; - case -3 : - fprintf(stdout,"Square root and power: y = sqrt(pow(x,2)) \n"); - y = sqrt(pow(x,2)); - break; - case -4 : - fprintf(stdout,"Exponential and log: y = exp(log(log(exp(x)))) \n"); - y = exp(log(log(exp(x)))); - break; - case -5 : - fprintf(stdout,"Trig identity: y = x + sin(2*x)-2*cos(x)*sin(x) \n"); - y = x + sin(2.0*x)-2.0*cos(x)*sin(x); - break; - case -6 : - fprintf(stdout,"Check out quadrature macro \n"); - y = exp(myquad(myquad(exp(x)))); - break; - case -7 : - fprintf(stdout,"Arcsin: y = sin(asin(acos(cos(x)))) \n"); - y = sin(asin(acos(cos(x)))); - break; - case -8 : - fprintf(stdout, - "Hyperbolic tangent: y = x + tanh(x)-sinh(x)/cosh(x) \n"); - y = x + tanh(x)-sinh(x)/cosh(x) ; - break; - case -9 : - fprintf(stdout,"Absolute value: y = x + fabs(x) - fabs(-x) \n"); - y = x + fabs(-x) - fabs(x); - break; - case -10 : - fprintf(stdout,"atan2: y = atan2(sin(x-0.5+pi),cos(x-0.5+pi)) \n"); - y = atan2(sin(x),cos(x)); - break; - default : - fprintf(stdout," Please select problem number >= -10 \n"); - exit(-1); - } - } - y >>= yp[0]; - trace_off(); // The (partial) execution trace is completed. - - /*--------------------------------------------------------------------------*/ - if( id < 0 ) - fprintf(stdout,"Round-off error: %14.6E\n",(y-x).value()); - - /*--------------------------------------------------------------------------*/ - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - /*--------------------------------------------------------------------------*/ - double *res; - res = new double[n+2]; - double u[1]; - u[0] = 1; + int n, i, id; + int tag = 0; + /*--------------------------------------------------------------------------*/ + fprintf(stdout, "SCALEXAM (ADOL-C Example)\n\n"); + fprintf(stdout, "problem number(-1 .. -10) / degree of monomial =? \n"); + scanf("%d", &id); + n = id > 0 ? id : 3; + + double *xp, *yp; + xp = new double[n + 4]; + yp = new double[n + 4]; + yp[0] = 0; + xp[0] = 0.5; + xp[1] = 1.0; + + /*--------------------------------------------------------------------------*/ + int dum = 1; + trace_on(tag, dum); // Begin taping all calculations with 'adoubles' + adouble y, x; + x <<= xp[0]; + if (id >= 0) { + fprintf(stdout, "Evaluate and differentiate recursive power routine \n"); + y = power(x, n); + } else { fprintf(stdout, - "\nThe two Taylor coefficients in each row should agree\n\n"); - - double ***V = (double***)new double**[1]; - V[0] = new double*[1]; - V[0][0] = new double[n+2]; - double **U = new double*[1]; - U[0] = new double[1]; - U[0][0] = 1; - double** xpoint = &xp; - double** ypoint = &yp; - double** respoint = &res; - - // tape_doc(tag,depen,indep,*xpoint,*respoint); - - fprintf(stdout," \n \t forward \t reverse \n"); - for (i=0; i < n+2; i++) { - xp[i+2]=0; - forward(tag,1,1,i,i+1,xpoint,respoint); - fprintf(stdout,"%d\t%14.6E\t\t%14.6E\n",i,res[i],yp[i]); - reverse(tag,1,1,i,u,ypoint); // call higher order scalar reverse - reverse(tag,1,1,i,1,U,V); - yp[i+1] = yp[i]/(i+1); - if (V[0][0][i] != yp[i]) - fprintf(stdout,"%d-th component in error %14.6E\n",i,V[0][0][i]-yp[i]); + "Check Operations and Functions by Algebraic Identities \n"); + switch (id) { + case -1: + fprintf(stdout, "Addition/Subtraction: y = x + x - (2.0/3)*x - x/3 \n"); + y = x + x - (2.0 / 3) * x - x / 3; + break; + case -2: + fprintf(stdout, "Multiplication/divison: y = x*x/x \n"); + y = x * x / x; + break; + case -3: + fprintf(stdout, "Square root and power: y = sqrt(pow(x,2)) \n"); + y = sqrt(pow(x, 2)); + break; + case -4: + fprintf(stdout, "Exponential and log: y = exp(log(log(exp(x)))) \n"); + y = exp(log(log(exp(x)))); + break; + case -5: + fprintf(stdout, "Trig identity: y = x + sin(2*x)-2*cos(x)*sin(x) \n"); + y = x + sin(2.0 * x) - 2.0 * cos(x) * sin(x); + break; + case -6: + fprintf(stdout, "Check out quadrature macro \n"); + y = exp(myquad(myquad(exp(x)))); + break; + case -7: + fprintf(stdout, "Arcsin: y = sin(asin(acos(cos(x)))) \n"); + y = sin(asin(acos(cos(x)))); + break; + case -8: + fprintf(stdout, "Hyperbolic tangent: y = x + tanh(x)-sinh(x)/cosh(x) \n"); + y = x + tanh(x) - sinh(x) / cosh(x); + break; + case -9: + fprintf(stdout, "Absolute value: y = x + fabs(x) - fabs(-x) \n"); + y = x + fabs(-x) - fabs(x); + break; + case -10: + fprintf(stdout, "atan2: y = atan2(sin(x-0.5+pi),cos(x-0.5+pi)) \n"); + y = atan2(sin(x), cos(x)); + break; + default: + fprintf(stdout, " Please select problem number >= -10 \n"); + exit(-1); } - cout << "\nWhen n<0 all rows except the first two should vanish \n"; - - return 1; + } + y >>= yp[0]; + trace_off(); // The (partial) execution trace is completed. + + /*--------------------------------------------------------------------------*/ + if (id < 0) + fprintf(stdout, "Round-off error: %14.6E\n", (y - x).value()); + + /*--------------------------------------------------------------------------*/ + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + /*--------------------------------------------------------------------------*/ + double *res; + res = new double[n + 2]; + double u[1]; + u[0] = 1; + fprintf(stdout, "\nThe two Taylor coefficients in each row should agree\n\n"); + + double ***V = (double ***)new double **[1]; + V[0] = new double *[1]; + V[0][0] = new double[n + 2]; + double **U = new double *[1]; + U[0] = new double[1]; + U[0][0] = 1; + double **xpoint = &xp; + double **ypoint = &yp; + double **respoint = &res; + + // tape_doc(tag,depen,indep,*xpoint,*respoint); + + fprintf(stdout, " \n \t forward \t reverse \n"); + for (i = 0; i < n + 2; i++) { + xp[i + 2] = 0; + forward(tag, 1, 1, i, i + 1, xpoint, respoint); + fprintf(stdout, "%d\t%14.6E\t\t%14.6E\n", i, res[i], yp[i]); + reverse(tag, 1, 1, i, u, ypoint); // call higher order scalar reverse + reverse(tag, 1, 1, i, 1, U, V); + yp[i + 1] = yp[i] / (i + 1); + if (V[0][0][i] != yp[i]) + fprintf(stdout, "%d-th component in error %14.6E\n", i, + V[0][0][i] - yp[i]); + } + cout << "\nWhen n<0 all rows except the first two should vanish \n"; + + return 1; } diff --git a/ADOL-C/examples/additional_examples/sparse/jacpatexam.cpp b/ADOL-C/examples/additional_examples/sparse/jacpatexam.cpp index 291ce08b4..94685dba6 100644 --- a/ADOL-C/examples/additional_examples/sparse/jacpatexam.cpp +++ b/ADOL-C/examples/additional_examples/sparse/jacpatexam.cpp @@ -4,23 +4,23 @@ Revision: $Id$ Contents: example for computation of jacobian sparsity pattern - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ +#include "../clock/myclock.h" #include #include -#include "../clock/myclock.h" -#include #include +#include #include using namespace std; @@ -30,7 +30,6 @@ using namespace std; #define TAG 11 - /****************************************************************************/ /* EVALUATION FUNCTIONS */ @@ -38,597 +37,604 @@ using namespace std; const unsigned int N = 5, M = 6; void eval_small(short tag, double *xp, double *yp) { - unsigned int i,j; + unsigned int i, j; - trace_on(tag); + trace_on(tag); - adouble *x,*y; - x = new adouble[N]; - y = new adouble[M]; - for (i=0;i>= yp[j]; + for (j = 0; j < M; j++) + y[j] >>= yp[j]; - delete []x; - delete []y; + delete[] x; + delete[] y; - trace_off(1); // force a numbered tape file to be written + trace_off(1); // force a numbered tape file to be written - cout << "\nproblem definition in "<<__FILE__<<", lines "<>= yp[j]; + for (j = 0; j < NM; j++) + y[j] >>= yp[j]; - delete []x; - delete []y; + delete[] x; + delete[] y; - trace_off(1); // force a numbered tape file to be written + trace_off(1); // force a numbered tape file to be written - cout << "\nproblem definition in "<<__FILE__<<", lines "<> choice ; - - cout << "\n\nOutput Jacobian pattern? (y/n) ?\b"; - cin >> outp; - - cout << "\n\nCompare with the full Jacobian calculation? (y/n) ?\b"; - cin >> full_jac; - if (( full_jac == 'y' ) || ( full_jac == 'Y')) - full_jac = 1; - else - full_jac = 0; - - cout << "----------------------------------------------------------------\n"; - - /*--------------------------------------------------------------------------*/ - - - if ( choice < 0 ) // Take function in the "eval(...)" routines ------------- + short tag; + int ret_c = -1, choice; + int oper, op_buf_size, loc_buf_size, con_buf_size, maxlive, deaths; + unsigned int depen, indep; + size_t tape_stats[STAT_SIZE]; + unsigned int i, j, minnz, maxnz, nz, nzref, nz_rel; + double z1, z2, t0, t1, t2, t3, t4, t5, t6 = 0.0, t7 = 0.0; + char outp, full_jac; + int precision, width; + + /*--------------------------------------------------------------------------*/ + /* variables needed for the Jacobian pattern exploration */ + + unsigned int **jacpat = NULL; // compressed row storage + double *base, *value; + double basepoint; + int ctrl[3]; + + cout << "----------------------------------------------------------------\n"; + cout << "\n Jacobian Pattern Example\n\n"; + cout << "Tape identification tag ( [-4..-1] for standart examples ) : ?\b"; + cin >> choice; + + cout << "\n\nOutput Jacobian pattern? (y/n) ?\b"; + cin >> outp; + + cout << "\n\nCompare with the full Jacobian calculation? (y/n) ?\b"; + cin >> full_jac; + if ((full_jac == 'y') || (full_jac == 'Y')) + full_jac = 1; + else + full_jac = 0; + + cout << "----------------------------------------------------------------\n"; + + /*--------------------------------------------------------------------------*/ + + if (choice < 0) // Take function in the "eval(...)" routines ------------- + { + if (choice > -4) { + base = new double[N]; + for (i = 0; i < N; i++) + base[i] = i + 1; + + value = new double[M]; + + tag = TAG; + eval_small(tag, base, value); + + cout << "\n\nCreated ADOL-C tape with identification tag " << tag + << ".\n\n"; + cout.flush(); + + } else // ( choice == -4 ) ----------------------------------------------- { - if ( choice > -4 ) { - base = new double[N]; - for (i=0;i= 0 ) : Take a written tape ------------------------------ - { - tag = choice; - - cout << "\nproblem definition in tape "<> basepoint; - - base = new double[indep]; - value = new double[depen]; - - for (i=0;i maxnz ) - maxnz = jacpat[i][0]; - } - nz_rel = (int) ceil (100*nz / ((double)depen*indep)); - cout << nz << " non-zero Jacobian elements of total " << depen*indep << " elements <= " << nz_rel << "%\n"; - cout << "min " << minnz << " non-zeros per row; max " << maxnz << " non-zeros per row;\n"; - nzref = nz; - - for (i=0;i maxnz ) - maxnz = jacpat[i][0]; - } - nz_rel = (int) ceil (100*nz / ((double)depen*indep)); - cout << nz << " non-zero Jacobian elements of total " << depen*indep << " elements <= " << nz_rel << "%\n"; - cout << "min " << minnz << " non-zeros per row; max " << maxnz << " non-zeros per row;\n"; - if ( nz != nzref ) - cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; - cout << "\n\n\n"; - - for (i=0;i maxnz ) - maxnz = jacpat[i][0]; + tapestats(tag, tape_stats); /* Reading of tape statistics */ + indep = tape_stats[NUM_INDEPENDENTS]; + depen = tape_stats[NUM_DEPENDENTS]; + op_buf_size = tape_stats[OP_BUFFER_SIZE]; + loc_buf_size = tape_stats[OP_BUFFER_SIZE]; + con_buf_size = tape_stats[OP_BUFFER_SIZE]; + oper = tape_stats[NUM_OPERATIONS]; + deaths = tape_stats[TAY_STACK_SIZE]; + maxlive = tape_stats[NUM_MAX_LIVES]; + + cout << "\nTape " << tag << ": \n"; + cout << " independents " << indep << "\n"; + cout << " dependents " << depen << "\n"; + cout << " operations " << oper << "\n"; + cout << " operations buffer size " << op_buf_size << "\n"; + cout << " locations buffer size " << loc_buf_size << "\n"; + cout << " constants buffer size " << con_buf_size << "\n"; + cout << " maxlive " << maxlive << "\n"; + cout << " valstack size " << deaths << "\n"; + cout << "\n"; + + } else // ( choice >= 0 ) : Take a written tape ------------------------------ + { + tag = choice; + + cout << "\nproblem definition in tape " << tag << "\n"; + + tapestats(tag, tape_stats); + indep = tape_stats[NUM_INDEPENDENTS]; + depen = tape_stats[NUM_DEPENDENTS]; + op_buf_size = tape_stats[OP_BUFFER_SIZE]; + loc_buf_size = tape_stats[OP_BUFFER_SIZE]; + con_buf_size = tape_stats[OP_BUFFER_SIZE]; + oper = tape_stats[NUM_OPERATIONS]; + deaths = tape_stats[TAY_STACK_SIZE]; + maxlive = tape_stats[NUM_MAX_LIVES]; + + cout << "\nTape " << tag << ": \n"; + cout << " independents " << indep << "\n"; + cout << " dependents " << depen << "\n"; + cout << " operations " << oper << "\n"; + cout << " operations buffer size " << op_buf_size << "\n"; + cout << " locations buffer size " << loc_buf_size << "\n"; + cout << " constants buffer size " << con_buf_size << "\n"; + cout << " maxlive " << maxlive << "\n"; + cout << " valstack size " << deaths << "\n"; + + cout << "\n\nbasepoint[0.." << indep << "] = ?\b"; + cin >> basepoint; + + base = new double[indep]; + value = new double[depen]; + + for (i = 0; i < indep; i++) + base[i] = basepoint; + } + + tape_doc(tag, depen, indep, base, value); // write a tape into a tex-file + + /*--------------------------------------------------------------------------*/ + /* Jacobian pattern by index domains, safe */ + + cout << "\nJacobian Pattern by index domain propagation, safe ...\n"; + + jacpat = new unsigned int *[depen]; + + ctrl[0] = 0; // index domain propagation + ctrl[1] = 0; // automatic mode choice (ignored here) + ctrl[2] = 0; // safe + + z1 = myclock(); + ret_c = jac_pat(tag, depen, indep, base, jacpat, ctrl); + z2 = myclock(); + + if ((outp == 'y') || (outp == 'Y')) { + for (i = 0; i < depen; i++) { + cout << "depen[" << i << "], " << jacpat[i][0] << " non-zero entries :\n"; + for (j = 1; j <= jacpat[i][0]; j++) + cout << jacpat[i][j] << " "; + cout << "\n"; } - nz_rel = (int) ceil (100*nz / ((double)depen*indep)); - cout << nz << " non-zero Jacobian elements of total " << depen*indep << " elements <= " << nz_rel << "%\n"; - cout << "min " << minnz << " non-zeros per row; max " << maxnz << " non-zeros per row;\n"; - if ( nz != nzref ) - cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; - - for (i=0;i maxnz) + maxnz = jacpat[i][0]; + } + nz_rel = (int)ceil(100 * nz / ((double)depen * indep)); + cout << nz << " non-zero Jacobian elements of total " << depen * indep + << " elements <= " << nz_rel << "%\n"; + cout << "min " << minnz << " non-zeros per row; max " << maxnz + << " non-zeros per row;\n"; + nzref = nz; + + for (i = 0; i < depen; i++) + myfree1_uint(jacpat[i]); + delete[] jacpat; + jacpat = NULL; + + /*--------------------------------------------------------------------------*/ + /* Jacobian pattern by index domains, tight */ + + cout << "\nJacobian Pattern by index domain propagation, tight ...\n"; + + jacpat = new unsigned int *[depen]; + + ctrl[0] = 0; // index domain propagation + ctrl[1] = 1; // forward (ignored here) + ctrl[2] = 1; // tight + + z1 = myclock(); + ret_c = jac_pat(tag, depen, indep, base, jacpat, ctrl); + z2 = myclock(); + + if ((outp == 'y') || (outp == 'Y')) { + for (i = 0; i < depen; i++) { + cout << "depen[" << i << "], " << jacpat[i][0] << " non-zero entries :\n"; + for (j = 1; j <= jacpat[i][0]; j++) + cout << jacpat[i][j] << " "; + cout << "\n"; } - - t3 = z2 - z1; - - nz = 0; - minnz = indep; - maxnz = 0; - for (i=0;i maxnz ) - maxnz = jacpat[i][0]; + cout.flush(); + } + + t1 = z2 - z1; + + nz = 0; + minnz = indep; + maxnz = 0; + for (i = 0; i < depen; i++) { + nz += jacpat[i][0]; + if (jacpat[i][0] < minnz) + minnz = jacpat[i][0]; + if (jacpat[i][0] > maxnz) + maxnz = jacpat[i][0]; + } + nz_rel = (int)ceil(100 * nz / ((double)depen * indep)); + cout << nz << " non-zero Jacobian elements of total " << depen * indep + << " elements <= " << nz_rel << "%\n"; + cout << "min " << minnz << " non-zeros per row; max " << maxnz + << " non-zeros per row;\n"; + if (nz != nzref) + cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; + cout << "\n\n\n"; + + for (i = 0; i < depen; i++) + myfree1_uint(jacpat[i]); + delete[] jacpat; + jacpat = NULL; + + /*--------------------------------------------------------------------------*/ + /* Jacobian pattern by bit pattern, forward, tight */ + + cout << "\nJacobian Pattern by bit pattern propagation, forward, tight ...\n"; + + jacpat = new unsigned int *[depen]; + + ctrl[0] = 1; // bit pattern propagation + ctrl[0] = 1; // forward + ctrl[1] = 1; // tight + + z1 = myclock(); + ret_c = jac_pat(tag, depen, indep, base, jacpat, ctrl); + z2 = myclock(); + + if ((outp == 'y') || (outp == 'Y')) { + for (i = 0; i < depen; i++) { + cout << "depen[" << i << "], " << jacpat[i][0] << " non-zero entries :\n"; + for (j = 1; j <= jacpat[i][0]; j++) + cout << jacpat[i][j] << " "; + cout << "\n"; } - nz_rel = (int) ceil (100*nz / ((double)depen*indep)); - cout << nz << " non-zero Jacobian elements of total " << depen*indep << " elements <= " << nz_rel << "%\n"; - cout << "min " << minnz << " non-zeros per row; max " << maxnz << " non-zeros per row;\n"; - if ( nz != nzref ) - cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; - cout << "\n\n\n"; - - for (i=0;i maxnz) + maxnz = jacpat[i][0]; + } + nz_rel = (int)ceil(100 * nz / ((double)depen * indep)); + cout << nz << " non-zero Jacobian elements of total " << depen * indep + << " elements <= " << nz_rel << "%\n"; + cout << "min " << minnz << " non-zeros per row; max " << maxnz + << " non-zeros per row;\n"; + if (nz != nzref) + cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; + + for (i = 0; i < depen; i++) + myfree1_uint(jacpat[i]); + delete[] jacpat; + jacpat = NULL; + + /*--------------------------------------------------------------------------*/ + /* Jacobian pattern by bit pattern, forward, safe */ + + cout << "\nJacobian Pattern by bit pattern propagation, forward, safe ...\n"; + + jacpat = new unsigned int *[depen]; + + ctrl[0] = 1; // bit pattern propagation + ctrl[1] = 1; // forward + ctrl[2] = 0; // safe + + z1 = myclock(); + ret_c = jac_pat(tag, depen, indep, base, jacpat, ctrl); + z2 = myclock(); + + if ((outp == 'y') || (outp == 'Y')) { + for (i = 0; i < depen; i++) { + cout << "depen[" << i << "], " << jacpat[i][0] << " non-zero entries :\n"; + for (j = 1; j <= jacpat[i][0]; j++) + cout << jacpat[i][j] << " "; + cout << "\n"; } - - t4 = z2 - z1; - - nz = 0; - minnz = indep; - maxnz = 0; - for (i=0;i maxnz ) - maxnz = jacpat[i][0]; + cout.flush(); + } + + t3 = z2 - z1; + + nz = 0; + minnz = indep; + maxnz = 0; + for (i = 0; i < depen; i++) { + nz += jacpat[i][0]; + if (jacpat[i][0] < minnz) + minnz = jacpat[i][0]; + if (jacpat[i][0] > maxnz) + maxnz = jacpat[i][0]; + } + nz_rel = (int)ceil(100 * nz / ((double)depen * indep)); + cout << nz << " non-zero Jacobian elements of total " << depen * indep + << " elements <= " << nz_rel << "%\n"; + cout << "min " << minnz << " non-zeros per row; max " << maxnz + << " non-zeros per row;\n"; + if (nz != nzref) + cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; + cout << "\n\n\n"; + + for (i = 0; i < depen; i++) + myfree1_uint(jacpat[i]); + delete[] jacpat; + jacpat = NULL; + + /*--------------------------------------------------------------------------*/ + /* Jacobian pattern by bit pattern, reverse, tight */ + + cout << "\nJacobian Pattern by bit pattern propagation, reverse, tight ...\n"; + + jacpat = new unsigned int *[depen]; + + ctrl[0] = 1; // bit pattern propagation + ctrl[1] = 2; // reverse + ctrl[2] = 1; // tight + + z1 = myclock(); + ret_c = jac_pat(tag, depen, indep, base, jacpat, ctrl); + z2 = myclock(); + + if ((outp == 'y') || (outp == 'Y')) { + for (i = 0; i < depen; i++) { + cout << "depen.[" << i << "], " << jacpat[i][0] + << " non-zero entries :\n"; + for (j = 1; j <= jacpat[i][0]; j++) + cout << jacpat[i][j] << " "; + cout << "\n"; } - nz_rel = (int) ceil (100*nz / ((double)depen*indep)); - cout << nz << " non-zero Jacobian elements of total " << depen*indep << " elements <= " << nz_rel << "%\n"; - cout << "min " << minnz << " non-zeros per row; max " << maxnz << " non-zeros per row;\n"; - if ( nz != nzref ) - cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; - - for (i=0;i maxnz) + maxnz = jacpat[i][0]; + } + nz_rel = (int)ceil(100 * nz / ((double)depen * indep)); + cout << nz << " non-zero Jacobian elements of total " << depen * indep + << " elements <= " << nz_rel << "%\n"; + cout << "min " << minnz << " non-zeros per row; max " << maxnz + << " non-zeros per row;\n"; + if (nz != nzref) + cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; + + for (i = 0; i < depen; i++) + myfree1_uint(jacpat[i]); + delete[] jacpat; + jacpat = NULL; + + /*--------------------------------------------------------------------------*/ + /* Jacobian pattern by bit pattern, reverse, safe */ + + cout << "\nJacobian Pattern by bit pattern propagation, reverse, safe ...\n"; + + jacpat = new unsigned int *[depen]; + + ctrl[0] = 1; // bit pattern propagation + ctrl[1] = 2; // reverse + ctrl[2] = 0; // safe + + z1 = myclock(); + ret_c = jac_pat(tag, depen, indep, base, jacpat, ctrl); + z2 = myclock(); + + if ((outp == 'y') || (outp == 'Y')) { + for (i = 0; i < depen; i++) { + cout << "depen.[" << i << "], " << jacpat[i][0] + << " non-zero entries :\n"; + for (j = 1; j <= jacpat[i][0]; j++) + cout << jacpat[i][j] << " "; + cout << "\n"; } - - t5 = z2 - z1; - - nz = 0; - minnz = indep; - maxnz = 0; - for (i=0;i maxnz ) - maxnz = jacpat[i][0]; + cout.flush(); + } + + t5 = z2 - z1; + + nz = 0; + minnz = indep; + maxnz = 0; + for (i = 0; i < depen; i++) { + nz += jacpat[i][0]; + if (jacpat[i][0] < minnz) + minnz = jacpat[i][0]; + if (jacpat[i][0] > maxnz) + maxnz = jacpat[i][0]; + } + nz_rel = (int)ceil(100 * nz / ((double)depen * indep)); + cout << nz << " non-zero Jacobian elements of total " << depen * indep + << " elements <= " << nz_rel << "%\n"; + cout << "min " << minnz << " non-zeros per row; max " << maxnz + << " non-zeros per row;\n"; + if (nz != nzref) + cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; + cout << "\n\n\n"; + + for (i = 0; i < depen; i++) + myfree1_uint(jacpat[i]); + delete[] jacpat; + jacpat = NULL; + + /* full Jacobian evaluation -----------------------------------------------*/ + + if (full_jac) { + /*---------------------------------------------------------------------*/ + /* variables needed for the evaluation routines */ + + double **Jac = new double *[depen]; + for (i = 0; i < depen; i++) + Jac[i] = new double[indep]; + double **I = new double *[indep]; + for (i = 0; i < indep; i++) { + I[i] = new double[indep]; + for (j = 0; j < indep; j++) + I[i][j] = 0.0; + I[i][i] = 1.0; } - nz_rel = (int) ceil (100*nz / ((double)depen*indep)); - cout << nz << " non-zero Jacobian elements of total " << depen*indep << " elements <= " << nz_rel << "%\n"; - cout << "min " << minnz << " non-zeros per row; max " << maxnz << " non-zeros per row;\n"; - if ( nz != nzref ) - cout << "\n\n!!! This method found a different number of non-zeros !!!\n\n"; - cout << "\n\n\n"; - - for (i=0;i -#include #include +#include +#include #include #include #define tag 1 -double feval(double *x); +double feval(double *x); adouble feval_ad(adouble *x); -void printmat(const char* kette, int n, int m, double** M); +void printmat(const char *kette, int n, int m, double **M); int main() { - int n=6; - double f, x[6]; - adouble fad, xad[6]; - - int i, j; + int n = 6; + double f, x[6]; + adouble fad, xad[6]; -/****************************************************************************/ -/******* function evaluation ***************/ -/****************************************************************************/ + int i, j; - for(i=0;i>= f; - trace_off(); + fad = feval_ad(xad); - printf("\n f = %e\n\n\n",f); + fad >>= f; + trace_off(); + printf("\n f = %e\n\n\n", f); -/****************************************************************************/ -/******** For comparisons: Full Hessian ********/ -/****************************************************************************/ + /****************************************************************************/ + /******** For comparisons: Full Hessian ********/ + /****************************************************************************/ - double **H; - H = myalloc2(n,n); + double **H; + H = myalloc2(n, n); - hessian(tag,n,x,H); + hessian(tag, n, x, H); - printmat(" H",n,n,H); - printf("\n"); + printmat(" H", n, n, H); + printf("\n"); + /****************************************************************************/ + /******* sparse Hessians, complete driver ***************/ + /****************************************************************************/ -/****************************************************************************/ -/******* sparse Hessians, complete driver ***************/ -/****************************************************************************/ + /* coordinate format for Hessian */ + unsigned int *rind = NULL; + unsigned int *cind = NULL; + double *values = NULL; + int nnz; + int options[2]; - /* coordinate format for Hessian */ - unsigned int *rind = NULL; - unsigned int *cind = NULL; - double *values = NULL; - int nnz; - int options[2]; + options[0] = 0; /* safe mode (default) */ + options[1] = 0; /* indirect recovery (default) */ - options[0] = 0; /* safe mode (default) */ - options[1] = 0; /* indirect recovery (default) */ + sparse_hess(tag, n, 0, x, &nnz, &rind, &cind, &values, options); - sparse_hess(tag, n, 0, x, &nnz, &rind, &cind, &values, options); + printf("In sparse format:\n"); + for (i = 0; i < nnz; i++) + printf("%2d %2d %10.6f\n\n", rind[i], cind[i], values[i]); - printf("In sparse format:\n"); - for (i=0;i repeat = 1 */ + /* repeated call of sparse_hess with same sparsity pattern => repeat = 1 */ - sparse_hess(tag, n, 0, x, &nnz, &rind, &cind, &values, options); + sparse_hess(tag, n, 0, x, &nnz, &rind, &cind, &values, options); - printf("In sparse format:\n"); - for (i=0;i -#include #include +#include +#include #include #include #define tag 1 -void ceval_ad(adouble *x, adouble *c); -void ceval(double *x, double *c); +void ceval_ad(adouble *x, adouble *c); +void ceval(double *x, double *c); -void printmat(const char* name, int n, int m, double** M); +void printmat(const char *name, int n, int m, double **M); int main() { - int n=6, m=3; - double x[6], c[3]; - adouble xad[6], cad[3]; - - int i, j; - -/****************************************************************************/ -/******* function evaluation ***************/ -/****************************************************************************/ - - for(i=0;i>= c[i]; - trace_off(); - - printf("\n c = "); - for(j=0;j reverse mode, */ - /* sometimes better than forward mode */ - /* due to sparsity structure */ + for (i = 0; i < m; i++) + cad[i] >>= c[i]; + trace_off(); - sparse_jac(tag, m, n, 0, x, &nnz, &rind, &cind, &values, options); + printf("\n c = "); + for (j = 0; j < m; j++) + printf(" %e ", c[j]); + printf("\n"); - printf("In sparse format (using row compression): \n"); - for (i=0;i repeat = 1 */ - - sparse_jac(tag, m, n, 1, x, &nnz, &rind, &cind, &values, options); - - printf("In sparse format:\n"); - for (i=0;i reverse mode, */ - /* sometimes better than forward mode */ - /* due to sparsity structure */ - - sparse_jac(tag, m, n, 0, x, &nnz, &rind, &cind, &values, options); - - printf("In sparse format (using row compression): \n"); - for (i=0;i reverse mode, */ + /* sometimes better than forward mode */ + /* due to sparsity structure */ + + sparse_jac(tag, m, n, 0, x, &nnz, &rind, &cind, &values, options); + + printf("In sparse format (using row compression): \n"); + for (i = 0; i < nnz; i++) + printf("%2d %2d %10.6f\n\n", rind[i], cind[i], values[i]); + + free(rind); + rind = NULL; + free(cind); + cind = NULL; + free(values); + values = NULL; + /*--------------------------------------------------------------------------*/ + /* change value of x, but not the sparsity pattern */ + /*--------------------------------------------------------------------------*/ + + for (i = 0; i < n; i++) + x[i] = 2.0 * i; + + /* For comparisons: Full Jacobian */ + + jacobian(tag, m, n, x, J); + + printmat(" J", m, n, J); + printf("\n"); - jac_pat(tag, m, n, x, JP, ctrl); - - printf("\n"); - printf("Sparsity pattern of Jacobian: \n"); - for (i=0;i repeat = 1 */ + + sparse_jac(tag, m, n, 1, x, &nnz, &rind, &cind, &values, options); + + printf("In sparse format:\n"); + for (i = 0; i < nnz; i++) + printf("%2d %2d %10.6f\n\n", rind[i], cind[i], values[i]); + + free(rind); + rind = NULL; + free(cind); + cind = NULL; + free(values); + values = NULL; + /*--------------------------------------------------------------------------*/ + /* same approach but using row compression */ + /*--------------------------------------------------------------------------*/ + + options[3] = 1; /* row compression => reverse mode, */ + /* sometimes better than forward mode */ + /* due to sparsity structure */ + + sparse_jac(tag, m, n, 0, x, &nnz, &rind, &cind, &values, options); + + printf("In sparse format (using row compression): \n"); + for (i = 0; i < nnz; i++) + printf("%2d %2d %10.6f\n\n", rind[i], cind[i], values[i]); + + free(rind); + rind = NULL; + free(cind); + cind = NULL; + free(values); + values = NULL; + /****************************************************************************/ + /******* sparse Jacobians, separate drivers ***************/ + /****************************************************************************/ + + /*--------------------------------------------------------------------------*/ + /* sparsity pattern Jacobian */ + /*--------------------------------------------------------------------------*/ + + unsigned int **JP = NULL; /* compressed block row storage */ + int ctrl[3]; + + JP = (unsigned int **)malloc(m * sizeof(unsigned int *)); + ctrl[0] = 0; + ctrl[1] = 0; + ctrl[2] = 0; + + jac_pat(tag, m, n, x, JP, ctrl); + + printf("\n"); + printf("Sparsity pattern of Jacobian: \n"); + for (i = 0; i < m; i++) { + printf(" %d: ", i); + for (j = 1; j <= (int)JP[i][0]; j++) + printf(" %d ", JP[i][j]); printf("\n"); + } + printf("\n"); + /*--------------------------------------------------------------------------*/ + /* seed matrix */ + /*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -/* seed matrix */ -/*--------------------------------------------------------------------------*/ - - double **Seed; - int p; - int option = 0; + double **Seed; + int p; + int option = 0; - /* option = 0 column compression (default), - option = 1 rom compression */ - - generate_seed_jac(m, n, JP, &Seed, &p, option); - - printf(" p_J = %d \n",p); - printmat(" Seed matrix",n,p,Seed); - printf("\n"); + /* option = 0 column compression (default), + option = 1 rom compression */ -/*--------------------------------------------------------------------------*/ -/* compressed Jacobian */ -/*--------------------------------------------------------------------------*/ + generate_seed_jac(m, n, JP, &Seed, &p, option); - double **Jcomp; - Jcomp = myalloc2(m,p); + printf(" p_J = %d \n", p); + printmat(" Seed matrix", n, p, Seed); + printf("\n"); - fov_forward(tag,m,n,p,x,Seed,c,Jcomp); - printmat("compressed J:",m,p,Jcomp); - printf("\n"); + /*--------------------------------------------------------------------------*/ + /* compressed Jacobian */ + /*--------------------------------------------------------------------------*/ + double **Jcomp; + Jcomp = myalloc2(m, p); -/*--------------------------------------------------------------------------*/ -/* change value of x, but not the sparsity pattern */ -/*--------------------------------------------------------------------------*/ + fov_forward(tag, m, n, p, x, Seed, c, Jcomp); + printmat("compressed J:", m, p, Jcomp); + printf("\n"); - for(i=0;i #include "../clock/myclock.h" - +#include /****************************************************************************/ /* MACROS */ #define abs(x) ((x >= 0) ? (x) : -(x)) -#define maxabs(x,y) (((x)>abs(y)) ? (x) : abs(y)) +#define maxabs(x, y) (((x) > abs(y)) ? (x) : abs(y)) #define TAG 1 - /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int n,i,it; - size_t tape_stats[STAT_SIZE]; - - /*--------------------------------------------------------------------------*/ - /* Input */ - fprintf(stdout,"SPEELPENNINGS PRODUCT Type 1 (ADOL-C Example)\n\n"); - fprintf(stdout,"number of independent variables = ? \n"); - scanf("%d",&n); - int itu; - fprintf(stdout,"number of evaluations = ? \n"); - scanf("%d",&itu); - - /*--------------------------------------------------------------------------*/ - double yp=0.0; /* 0. time (undifferentiated double code) */ - double *xp = new double[n]; - /* Init */ - for (i=0;i>= yout; - delete [] x; - trace_off(); - double t11 = myclock(); - - fprintf(stdout,"%E =? %E function values should be the same \n",yout,yp); - - /*--------------------------------------------------------------------------*/ - tapestats(TAG,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - /*--------------------------------------------------------------------------*/ - double **r = new double*[1]; - r[0] = new double[1]; - r[0][0] = yp; - double err; - double *z = new double[n]; - double *g = new double[n]; - double* h = new double[n]; - double *ind = new double[n]; - - /*--------------------------------------------------------------------------*/ - double t60 = myclock(); /* 6. time (forward no keep) */ - for (it=0; it>= yout; + delete[] x; + trace_off(); + double t11 = myclock(); + + fprintf(stdout, "%E =? %E function values should be the same \n", yout, yp); + + /*--------------------------------------------------------------------------*/ + tapestats(TAG, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + /*--------------------------------------------------------------------------*/ + double **r = new double *[1]; + r[0] = new double[1]; + r[0][0] = yp; + double err; + double *z = new double[n]; + double *g = new double[n]; + double *h = new double[n]; + double *ind = new double[n]; + + /*--------------------------------------------------------------------------*/ + double t60 = myclock(); /* 6. time (forward no keep) */ + for (it = 0; it < itu; it++) + forward(TAG, 1, n, 0, xp, *r); + double t61 = myclock(); + + /*--------------------------------------------------------------------------*/ + double t20 = myclock(); /* 2. time (forward+keep) */ + for (it = 0; it < itu; it++) + forward(TAG, 1, n, 1, xp, *r); + double t21 = myclock(); + + /*--------------------------------------------------------------------------*/ + double t30 = myclock(); /* 3. time (reverse) */ + for (it = 0; it < itu; it++) + reverse(TAG, 1, n, 0, 1.0, g); + double t31 = myclock(); + + err = 0; + for (i = 0; i < n; i++) // Compare with deleted product + { + err = maxabs(err, xp[i] * g[i] / r[0][0] - 1.0); + ind[i] = xp[i]; + } + + fprintf(stdout, "%E = maximum relative errors in gradient (fw+rv)\n", err); + + /*--------------------------------------------------------------------------*/ + double t40 = myclock(); /* 4. time (gradient) */ + for (it = 0; it < itu; it++) + gradient(TAG, n, ind, z); // last argument lagrange is ommitted + double t41 = myclock(); + + err = 0; + for (i = 0; i < n; i++) // Compare with previous numerical result + err = maxabs(err, g[i] / z[i] - 1.0); + + fprintf(stdout, "%E = gradient error should be exactly zero \n", err); + + /*--------------------------------------------------------------------------*/ + double *tan = new double[n]; /* 5. time (first row of Hessian) */ + for (i = 1; i < n; i++) + tan[i] = 0.0; + tan[0] = 1.0; + + double t50 = myclock(); + for (it = 0; it < itu; it++) + hess_vec(TAG, n, ind, tan, h); // Computes Hessian times direction tan. + double t51 = myclock(); + + err = abs(h[0]); + for (i = 1; i < n; i++) // Compare with doubly deleted product + err = maxabs(err, xp[0] * h[i] / g[i] - 1.0); + + fprintf(stdout, "%E = maximum relative error in Hessian column \n", err); + + /*--------------------------------------------------------------------------*/ + double h1n = h[n - 1]; /* Check for symmetry */ + tan[0] = 0; + tan[n - 1] = 1; + hess_vec(TAG, n, ind, tan, h); // Computes Hessian times direction tan. + + fprintf(stdout, "%E = %E (1,n) and (n,1) entry should be the same\n", h1n, + h[0]); + + /*--------------------------------------------------------------------------*/ + /* output of results */ + if (t01 - t00) { + double rtu = 1.0 / (t01 - t00); + fprintf(stdout, "\n\n times for "); + fprintf(stdout, "\n unitime : \t%E seconds", (t01 - t00) / itu); + fprintf(stdout, "\n tracing : \t%E", (t11 - t10) * rtu * itu); + fprintf(stdout, " units \t%E seconds", (t11 - t10)); fprintf(stdout, - "%E = %E (1,n) and (n,1) entry should be the same\n",h1n,h[0]); - - /*--------------------------------------------------------------------------*/ - /* output of results */ - if (t01-t00) { - double rtu = 1.0/(t01-t00); - fprintf(stdout,"\n\n times for "); - fprintf(stdout,"\n unitime : \t%E seconds",(t01-t00)/itu); - fprintf(stdout,"\n tracing : \t%E",(t11-t10)*rtu*itu); - fprintf(stdout," units \t%E seconds",(t11-t10)); - fprintf(stdout, - "\n----------------------------------------------------------"); - fprintf(stdout,"\n forward (no keep): \t%E",(t61-t60)*rtu); - fprintf(stdout," units \t%E seconds",(t61-t60)/itu); - fprintf(stdout,"\n forward + keep : \t%E",(t21-t20)*rtu); - fprintf(stdout," units \t%E seconds",(t21-t20)/itu); - fprintf(stdout,"\n reverse : \t%E",(t31-t30)*rtu); - fprintf(stdout," units \t%E seconds",(t31-t30)/itu); - fprintf(stdout, - "\n----------------------------------------------------------"); - fprintf(stdout,"\n gradient : \t%E",(t41-t40)*rtu); - fprintf(stdout," units \t%E seconds",(t41-t40)/itu); - fprintf(stdout,"\n hess*vec : \t%E",(t51-t50)*rtu); - fprintf(stdout," units \t%E seconds\n",(t51-t50)/itu); - } else - fprintf(stdout,"\n-> zero timing due to small problem dimension \n"); - - return 1; + "\n----------------------------------------------------------"); + fprintf(stdout, "\n forward (no keep): \t%E", (t61 - t60) * rtu); + fprintf(stdout, " units \t%E seconds", (t61 - t60) / itu); + fprintf(stdout, "\n forward + keep : \t%E", (t21 - t20) * rtu); + fprintf(stdout, " units \t%E seconds", (t21 - t20) / itu); + fprintf(stdout, "\n reverse : \t%E", (t31 - t30) * rtu); + fprintf(stdout, " units \t%E seconds", (t31 - t30) / itu); + fprintf(stdout, + "\n----------------------------------------------------------"); + fprintf(stdout, "\n gradient : \t%E", (t41 - t40) * rtu); + fprintf(stdout, " units \t%E seconds", (t41 - t40) / itu); + fprintf(stdout, "\n hess*vec : \t%E", (t51 - t50) * rtu); + fprintf(stdout, " units \t%E seconds\n", (t51 - t50) / itu); + } else + fprintf(stdout, "\n-> zero timing due to small problem dimension \n"); + + return 1; } - diff --git a/ADOL-C/examples/additional_examples/tapesave/createTape.cpp b/ADOL-C/examples/additional_examples/tapesave/createTape.cpp index 99bcaac62..537404527 100644 --- a/ADOL-C/examples/additional_examples/tapesave/createTape.cpp +++ b/ADOL-C/examples/additional_examples/tapesave/createTape.cpp @@ -6,17 +6,17 @@ How to create a tape with ADOL-C ================================ - + Application of ADOL-C to the example function of Tony Wong to obtain the tape, which will be saved on HD for future use - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ @@ -27,79 +27,56 @@ /****************************************************************************/ /* ACTIVATING FUNCTIONS */ - /* Example of a C function */ -double myf ( double x, double y, double z) { - return x*x + y*y*y + z*z*z*z + 2.0*x*x*x*x*y*y*y - + z*z*z*z*x*x*x*x*x + 3.0*z*z*z*y; +double myf(double x, double y, double z) { + return x * x + y * y * y + z * z * z * z + 2.0 * x * x * x * x * y * y * y + + z * z * z * z * x * x * x * x * x + 3.0 * z * z * z * y; } - /* Example of the corresponding 'active' C function */ -adouble myf ( adouble x, adouble y, adouble z) { - return x*x + y*y*y + z*z*z*z + 2.0*x*x*x*x*y*y*y - + z*z*z*z*x*x*x*x*x + 3.0*z*z*z*y; - +adouble myf(adouble x, adouble y, adouble z) { + return x * x + y * y * y + z * z * z * z + 2.0 * x * x * x * x * y * y * y + + z * z * z * z * x * x * x * x * x + 3.0 * z * z * z * y; } - /****************************************************************************/ /* GENERATING THE EVALUATION TAPE */ - int main() { - double xyz[3], f; /* variables */ - adouble ax, ay, az, af; /* active varaibles */ - - xyz[0] = 1.2; - xyz[1] = 2.6; /* initialize any values */ - xyz[2] = 0.03; - - - /* TRACING THE EVALUATION TAPE */ - trace_on(1); /* start tracing of an evaluation - tape with the identifier 1 */ - ax <<= xyz[0]; /* marking independent variables */ - ay <<= xyz[1]; - az <<= xyz[2]; - af = myf(ax,ay,az); /* calling the 'active' version of - the function to be differentiated - to generate a tape of the evaluation - process; - NOTE: Instead of calling a - C function the whole evaluation code - can be placed here (see example file - DEX/powerexam.C) */ - af >>= f; /* marking the only one dependent - variable */ - trace_off(1); /* stop tracing */ - - /* NOTE: trace_off(..) is called with the value 1 (for the optional - ! argument). This forces ADOL-C to save the generated tapes - ! on harddisc. In particular these are the files - ! - ! _adol-op_tape.1 (operations = opcodes) - ! _adol-in_tape.1 (integers = locations) - ! _adol-rl_tape.1 (real values = doubles) - ! - ! The appendix '1' is determined by the used tape - ! identifier, which was passed to trace_on(..). - */ + double xyz[3], f; /* variables */ + adouble ax, ay, az, af; /* active varaibles */ + + xyz[0] = 1.2; + xyz[1] = 2.6; /* initialize any values */ + xyz[2] = 0.03; + + /* TRACING THE EVALUATION TAPE */ + trace_on(1); /* start tracing of an evaluation + tape with the identifier 1 */ + ax <<= xyz[0]; /* marking independent variables */ + ay <<= xyz[1]; + az <<= xyz[2]; + af = myf(ax, ay, az); /* calling the 'active' version of + the function to be differentiated + to generate a tape of the evaluation + process; + NOTE: Instead of calling a + C function the whole evaluation code + can be placed here (see example file + DEX/powerexam.C) */ + af >>= f; /* marking the only one dependent + variable */ + trace_off(1); /* stop tracing */ + + /* NOTE: trace_off(..) is called with the value 1 (for the optional + ! argument). This forces ADOL-C to save the generated tapes + ! on harddisc. In particular these are the files + ! + ! _adol-op_tape.1 (operations = opcodes) + ! _adol-in_tape.1 (integers = locations) + ! _adol-rl_tape.1 (real values = doubles) + ! + ! The appendix '1' is determined by the used tape + ! identifier, which was passed to trace_on(..). + */ } - - - - - - - - - - - - - - - - - diff --git a/ADOL-C/examples/additional_examples/tapesave/useTape.cpp b/ADOL-C/examples/additional_examples/tapesave/useTape.cpp index dbe6ff048..b44af4880 100644 --- a/ADOL-C/examples/additional_examples/tapesave/useTape.cpp +++ b/ADOL-C/examples/additional_examples/tapesave/useTape.cpp @@ -6,17 +6,17 @@ How to use a tape with ADOL-C ============================= - + Application of ADOL-C to the example function of Tony Wong to use a tape, which was previously saved on HD - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ @@ -26,58 +26,39 @@ #include - /****************************************************************************/ /* USING THE EVALUATION TAPE */ - int main() { - double xyz[3], f, gradf[3]; /* variables */ - - xyz[0] = 1.0; - xyz[1] = 1.0; /* initialize any values */ - xyz[2] = 1.0; - - /* USING THE TAPE FOR DERIVATIVE COMPUTATION */ - - function(1, /* the tape identifier 1 (tag) */ - 1, /* number of dependent variables - = dimension of f */ - 3, /* number of independent variables - = dimension of xyz */ - xyz, /* the point where the function has - to be differentiated */ - &f); /* contains the function value (after - calling 'function(..)') */ - - gradient(1, /* the tape identifier 1 (tag) */ - 3, /* number of independent variables - = dimension of xyz */ - xyz, /* the point where the function has - to be differentiated */ - gradf); /* contains the gradient (after - calling 'gradient(..)') */ - - /* print the results */ - fprintf(stdout,"f = %E\n",f); - fprintf(stdout,"df = (%E, %E, %E)\n",gradf[0],gradf[1],gradf[2]); - - return 0; + double xyz[3], f, gradf[3]; /* variables */ + + xyz[0] = 1.0; + xyz[1] = 1.0; /* initialize any values */ + xyz[2] = 1.0; + + /* USING THE TAPE FOR DERIVATIVE COMPUTATION */ + + function(1, /* the tape identifier 1 (tag) */ + 1, /* number of dependent variables + = dimension of f */ + 3, /* number of independent variables + = dimension of xyz */ + xyz, /* the point where the function has + to be differentiated */ + &f); /* contains the function value (after + calling 'function(..)') */ + + gradient(1, /* the tape identifier 1 (tag) */ + 3, /* number of independent variables + = dimension of xyz */ + xyz, /* the point where the function has + to be differentiated */ + gradf); /* contains the gradient (after + calling 'gradient(..)') */ + + /* print the results */ + fprintf(stdout, "f = %E\n", f); + fprintf(stdout, "df = (%E, %E, %E)\n", gradf[0], gradf[1], gradf[2]); + + return 0; } - - - - - - - - - - - - - - - - - diff --git a/ADOL-C/examples/additional_examples/taylor/accessexam.cpp b/ADOL-C/examples/additional_examples/taylor/accessexam.cpp index e4cad615c..e51c878b1 100644 --- a/ADOL-C/examples/additional_examples/taylor/accessexam.cpp +++ b/ADOL-C/examples/additional_examples/taylor/accessexam.cpp @@ -2,154 +2,154 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: accessexam.cpp Revision: $Id$ - Contents: Test driver 'tensor_value(..)' and access of higher order tensors + Contents: Test driver 'tensor_value(..)' and access of higher order tensors by void pointer strategy - + Copyright (c) Andrea Walther, Andreas Griewank - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ #include -#include #include +#include using namespace std; /****************************************************************************/ /* MAIN */ int main() { - int i,j,n,m,d,p,dim; - - /*--------------------------------------------------------------------------*/ - cout << "ACCESSEXAM (ADOL-C Example)\n\n"; /* inputs */ - cout << " demonstrates accees to higher order " - << "partial derivatives (tensors)\n\n"; - cout << " Number of independents ?\n "; - cin >> n; - cout << " Number of dependents (2 <= m <=n) ?\n "; - cin >> m; - d = 5; - cout << " Degree = " << d <<"\n"; - cout << " Number of directions ?\n "; - cin >> p; - - /*--------------------------------------------------------------------------*/ - int* multi = new int[d]; /* allocations and inits */ - double* xp = new double[n]; - double* yp = new double[m]; - double** S = new double*[n]; - double* test = new double[m]; - double** tensorhelp; - double****** tensor; - - for (i=0; i>= yp[i] ; - trace_off(); - - /*--------------------------------------------------------------------------*/ - dim = binomi(p+d,d); /* tensor_eval */ - tensorhelp = myalloc2(n,dim); - cout <<" d = "<> n; + cout << " Number of dependents (2 <= m <=n) ?\n "; + cin >> m; + d = 5; + cout << " Degree = " << d << "\n"; + cout << " Number of directions ?\n "; + cin >> p; + + /*--------------------------------------------------------------------------*/ + int *multi = new int[d]; /* allocations and inits */ + double *xp = new double[n]; + double *yp = new double[m]; + double **S = new double *[n]; + double *test = new double[m]; + double **tensorhelp; + double ******tensor; + + for (i = 0; i < n; i++) { + xp[i] = (i + 1.0) / (2.0 + i); + S[i] = new double[p]; + for (j = 0; j < p; j++) + S[i][j] = (i == j) ? 1.0 : 0.0; + } + + for (i = 0; i < d; i++) + multi[i] = 0; + + /*--------------------------------------------------------------------------*/ + trace_on(1); /* tracing the function */ + adouble *x = new adouble[n]; + adouble *y = new adouble[m]; + y[0] = 1; + + for (i = 0; i < n; i++) { + x[i] <<= xp[i]; + y[0] *= x[i]; + } + y[1] = sqrt(x[1]); + for (i = 2; i < m; i++) + y[i] = sqrt(x[i]); + for (i = 0; i < m; i++) + y[i] >>= yp[i]; + trace_off(); + + /*--------------------------------------------------------------------------*/ + dim = binomi(p + d, d); /* tensor_eval */ + tensorhelp = myalloc2(n, dim); + cout << " d = " << d << ", dim = " << dim << "\n"; + tensor_eval(1, m, n, d, p, xp, tensorhelp, S); + + /*--------------------------------------------------------------------------*/ + tensor = (double ******)tensorsetup(n, p, d, tensorhelp); /* access */ + cout << "\nTASK 1: Check access to directional derivatives\n"; + + for (i = 0; i < p; i++) { + multi[0] = i + 1; + tensor_value(d, m, test, tensorhelp, multi); + cout << i + 1 << ": "; + for (j = 0; j < m; j++) + cout << " " << test[j] << " "; + cout << "=="; + for (j = 0; j < m; j++) + cout << " " << tensor[j][i + 1][0][0][0][0] << " "; cout << "\n"; - tensor_value(d,m,test,tensorhelp,multi); - cout << " " << test[1] << " == "; - cout << tensor[1][2][2][0][0][0] << "\n\n"; - - /*--------------------------------------------------------------------------*/ - multi[0] = 2; - multi[1] = 2; - multi[2] = 2; - cout <<" Tensor"; - for (i=0; i> zp[0]; - cout << " z_2: (e.g. 3) \n"; - cin >> zp[1]; - cout << "\n Polar coordinates:\n"; - cout << " z_3: (e.g. 5) \n"; - cin >> zp[2]; - cout << " z_4: (e.g. 0.64350110879) \n"; - cin >> zp[3]; - - cout << "\n Highest derivative degree = 3\n"; - - /*--------------------------------------------------------------------------*/ - /* allocations and inits */ - n = 4; - p = 2; - d = 3; - - double** S = new double*[n]; - double** tensor = new double*[n]; - double**** tensorentry; - - for (i=0; i>= gp[0]; - g[1] >>= gp[1]; - z[0] >>= zd[0]; - z[2] >>= zd[1]; - trace_off(); - - /*--------------------------------------------------------------------------*/ - dim = binomi(p+d,d); /* inverse_tensor_eval */ - for(i=0;i> zp[0]; + cout << " z_2: (e.g. 3) \n"; + cin >> zp[1]; + cout << "\n Polar coordinates:\n"; + cout << " z_3: (e.g. 5) \n"; + cin >> zp[2]; + cout << " z_4: (e.g. 0.64350110879) \n"; + cin >> zp[3]; + + cout << "\n Highest derivative degree = 3\n"; + + /*--------------------------------------------------------------------------*/ + /* allocations and inits */ + n = 4; + p = 2; + d = 3; + + double **S = new double *[n]; + double **tensor = new double *[n]; + double ****tensorentry; + + for (i = 0; i < n; i++) { + S[i] = new double[p]; + for (j = 0; j < p; j++) + S[i][j] = 0.0; + } + S[2][0] = 1; + S[3][1] = 1; + + /*--------------------------------------------------------------------------*/ + trace_on(1); /* tracing the function */ + adouble *z = new adouble[n]; + adouble *g = new adouble[2]; + + for (i = 0; i < n; i++) + z[i] <<= zp[i]; + g[0] = z[0] * z[0] + z[1] * z[1] - z[2] * z[2]; + g[1] = cos(z[3]) - z[0] / z[2]; + g[0] >>= gp[0]; + g[1] >>= gp[1]; + z[0] >>= zd[0]; + z[2] >>= zd[1]; + trace_off(); + + /*--------------------------------------------------------------------------*/ + dim = binomi(p + d, d); /* inverse_tensor_eval */ + for (i = 0; i < n; i++) { + tensor[i] = new double[dim]; + for (j = 0; j < dim; j++) + tensor[i][j] = 0; + } + inverse_tensor_eval(1, n, d, p, zp, tensor, S); + tensorentry = (double ****)tensorsetup(n, p, d, tensor); + cout << "\n Some partial derivatives: \n\n"; + cout << " Tensor"; + cout << "[1][1][0][0]: \t"; + cout << tensorentry[1][1][0][0] << "\n\n"; + cout << " Tensor"; + cout << "[1][2][0][0]: \t"; + cout << tensorentry[1][2][0][0] << "\n\n"; + cout << " Tensor"; + cout << "[1][2][1][0]: \t"; + cout << tensorentry[1][2][1][0] << "\n\n"; + free((char *)*tensor); + free((char *)tensor); + freetensor(n, p, d, (double **)tensorentry); + + return 1; } /****************************************************************************/ diff --git a/ADOL-C/examples/additional_examples/taylor/inversexam.cpp b/ADOL-C/examples/additional_examples/taylor/inversexam.cpp index 20945777e..240919f38 100644 --- a/ADOL-C/examples/additional_examples/taylor/inversexam.cpp +++ b/ADOL-C/examples/additional_examples/taylor/inversexam.cpp @@ -2,16 +2,16 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: inversexam.cpp Revision: $Id$ - Contents: Test driver 'inverse_tensor_eval(..)' allows to + Contents: Test driver 'inverse_tensor_eval(..)' allows to compute higher order derivatives of inverse functions Copyright (c) Andrea Walther, Andreas Griewank - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ @@ -25,152 +25,151 @@ using namespace std; /****************************************************************************/ /* MAIN */ int main() { - int i,j,n,d,p,dim; - - /*--------------------------------------------------------------------------*/ - cout << "INVERSEXAM (ADOL-C Example)\n\n"; /* inputs */ - cout << " Number of independents = ?\n "; - cin >> n; - // number of dependents = number of independents !! - cout << " Degree = ?\n "; - cin >> d; - cout << " Number of directions = ?\n "; - cin >> p; - - /*--------------------------------------------------------------------------*/ - int* multi = new int[d]; /* allocations and inits */ - double* xp = new double[n]; - double* yp = new double[n]; - double** S = new double*[n]; - double* test = new double[n]; - double** tensoren; - adouble* x = new adouble[n]; - adouble* y = new adouble[n]; - - for (i=0; i>= yp[i] ; - trace_off(); - - /*--------------------------------------------------------------------------*/ - d = d-1; /* 1. inverse_tensor_eval */ - dim = binomi(p+d,d); - tensoren = myalloc2(n,dim); - cout <<"TASK 1:\n"; - cout <<" d = "<> n; + // number of dependents = number of independents !! + cout << " Degree = ?\n "; + cin >> d; + cout << " Number of directions = ?\n "; + cin >> p; + + /*--------------------------------------------------------------------------*/ + int *multi = new int[d]; /* allocations and inits */ + double *xp = new double[n]; + double *yp = new double[n]; + double **S = new double *[n]; + double *test = new double[n]; + double **tensoren; + adouble *x = new adouble[n]; + adouble *y = new adouble[n]; + + for (i = 0; i < n; i++) { + xp[i] = (i + 1.0) / (2.0 + i); + S[i] = new double[p]; + for (j = 0; j < p; j++) + S[i][j] = (i == j) ? 1.0 : 0.0; + } + + for (i = 0; i < d; i++) + multi[i] = 0; + + /*--------------------------------------------------------------------------*/ + trace_on(1); /* tracing the function */ + for (i = 0; i < n; i++) { + x[i] <<= xp[i]; + y[i] = (i + 1) * x[i]; + } + y[0] += sqrt(x[0]); + for (i = 0; i < n; i++) + y[i] >>= yp[i]; + trace_off(); + + /*--------------------------------------------------------------------------*/ + d = d - 1; /* 1. inverse_tensor_eval */ + dim = binomi(p + d, d); + tensoren = myalloc2(n, dim); + cout << "TASK 1:\n"; + cout << " d = " << d << ", dim = " << dim << "\n"; + + inverse_tensor_eval(1, n, d, p, xp, tensoren, S); + + for (i = 0; i < p; i++) { + multi[0] = i + 1; + tensor_value(d, n, test, tensoren, multi); + cout << i + 1 << ": "; + for (j = 0; j < n; j++) + cout << " " << test[j] << " "; + cout << "\n"; + } + + myfree2(tensoren); + + /*--------------------------------------------------------------------------*/ + d = d + 1; /* 2. inverse_tensor_eval */ + dim = binomi(p + d, d); + cout << "TASK 2:\n"; + cout << " d = " << d << ", dim = " << dim << "\n"; + tensoren = myalloc2(n, dim); + + inverse_tensor_eval(1, n, d, p, xp, tensoren, S); + + for (i = 0; i < p; i++) { + multi[0] = i + 1; + tensor_value(d, n, test, tensoren, multi); + cout << i + 1 << ": "; + for (j = 0; j < n; j++) + cout << " " << test[j] << " "; + cout << "\n"; + } + + /*--------------------------------------------------------------------------*/ + xp[0] = 2 * xp[0]; /* 3. inverse_tensor_eval */ + + cout << "TASK 3:\n"; + cout << " NEW independend values !!!\n"; + cout << " d = " << d << ", dim = " << dim << "\n"; + + inverse_tensor_eval(1, n, d, p, xp, tensoren, S); + + for (i = 0; i < p; i++) { + multi[0] = i + 1; + tensor_value(d, n, test, tensoren, multi); + cout << i + 1 << ": "; + for (j = 0; j < n; j++) + cout << " " << test[j] << " "; + cout << "\n"; + } + + myfree2(tensoren); + + /*--------------------------------------------------------------------------*/ + d = d - 1; /* 4. inverse_tensor_eval */ + dim = binomi(p + d, d); + cout << "TASK 4:\n"; + cout << " d = " << d << ", dim = " << dim << "\n"; + tensoren = myalloc2(n, dim); + + inverse_tensor_eval(1, n, d, p, xp, tensoren, S); + + for (i = 0; i < p; i++) { + multi[0] = i + 1; + tensor_value(d, n, test, tensoren, multi); + cout << i + 1 << ": "; + for (j = 0; j < n; j++) + cout << " " << test[j] << " "; + cout << "\n"; + } + + myfree2(tensoren); + + /*--------------------------------------------------------------------------*/ + d = d + 1; /* 5. inverse_tensor_eval */ + dim = binomi(p + d, d); + xp[0] = 0.5 * xp[0]; + cout << "TASK 5:\n"; + cout << " OLD independend values !!!\n"; + cout << " d = " << d << ", dim = " << dim << "\n"; + tensoren = myalloc2(n, dim); + + inverse_tensor_eval(1, n, d, p, xp, tensoren, S); + + for (i = 0; i < p; i++) { + multi[0] = i + 1; + tensor_value(d, n, test, tensoren, multi); + cout << i + 1 << ": "; + for (j = 0; j < n; j++) + cout << " " << test[j] << " "; + cout << "\n"; + } + + myfree2(tensoren); + + return 1; } - /****************************************************************************/ /* THAT'S ALL */ diff --git a/ADOL-C/examples/additional_examples/taylor/taylorexam.cpp b/ADOL-C/examples/additional_examples/taylor/taylorexam.cpp index dcd9fcd03..3e99b0160 100644 --- a/ADOL-C/examples/additional_examples/taylor/taylorexam.cpp +++ b/ADOL-C/examples/additional_examples/taylor/taylorexam.cpp @@ -6,11 +6,11 @@ higher order derivatives Copyright (c) Andrea Walther, Andreas Griewank - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ @@ -24,159 +24,156 @@ using namespace std; /****************************************************************************/ /* MAIN */ int main() { - int i,j,m,n,d,p,dim; - - /*--------------------------------------------------------------------------*/ - cout << "TAYLOREXAM (ADOL-C Example)\n\n"; /* inputs */ - cout << " Number of indenpendents = ?\n "; - cin >> n; - cout << " Number of dependents = (<=n) ?\n "; - cin >> m; - cout << " Degree = ?\n "; - cin >> d; - cout << " Number of directions = ?\n "; - cin >> p; - - /*--------------------------------------------------------------------------*/ - int* multi = new int[d]; /* allocations and inits */ - double* xp = new double[n]; - double* yp = new double[m]; - double** S = new double*[n]; - double* test = new double[m]; - double** tensoren; - adouble* x = new adouble[n]; - adouble* y = new adouble[m]; - - for (i=0; i>= yp[i] ; - trace_off(); - - /*--------------------------------------------------------------------------*/ - d = d-1; /* 1. tensor_eval */ - dim = binomi(p+d,d); - cout <<"TASK 1:\n"; - cout <<" d = "<> n; + cout << " Number of dependents = (<=n) ?\n "; + cin >> m; + cout << " Degree = ?\n "; + cin >> d; + cout << " Number of directions = ?\n "; + cin >> p; + + /*--------------------------------------------------------------------------*/ + int *multi = new int[d]; /* allocations and inits */ + double *xp = new double[n]; + double *yp = new double[m]; + double **S = new double *[n]; + double *test = new double[m]; + double **tensoren; + adouble *x = new adouble[n]; + adouble *y = new adouble[m]; + + for (i = 0; i < d; i++) + multi[i] = 0; + + for (i = 0; i < n; i++) { + xp[i] = (i + 1.0) / (2.0 + i); + S[i] = new double[p]; + for (j = 0; j < p; j++) + S[i][j] = (i == j) ? 1.0 : 0.0; + } + + /*--------------------------------------------------------------------------*/ + trace_on(1); /* tracing the function */ + // adouble* x = new adouble[n]; + // adouble* y = new adouble[m]; + y[0] = 1; + + for (i = 0; i < n; i++) { + x[i] <<= xp[i]; + y[0] *= x[i]; + } + for (i = 1; i < m; i++) + y[i] = x[i]; + for (i = 0; i < m; i++) + y[i] >>= yp[i]; + trace_off(); + + /*--------------------------------------------------------------------------*/ + d = d - 1; /* 1. tensor_eval */ + dim = binomi(p + d, d); + cout << "TASK 1:\n"; + cout << " d = " << d << ", dim = " << dim << "\n"; + tensoren = myalloc2(m, dim); + + tensor_eval(1, m, n, d, p, xp, tensoren, S); + + for (i = 0; i < p; i++) { + multi[0] = i + 1; + tensor_value(d, m, test, tensoren, multi); + cout << i + 1 << ": "; + for (j = 0; j < m; j++) + cout << " " << test[j] << " "; cout << "\n"; + } + myfree2(tensoren); - /*--------------------------------------------------------------------------*/ - xp[0] = 2*xp[0]; /* 3. tensor_eval */ - - cout <<"TASK 3:\n"; - cout <<" NEW independend values !!!\n"; - cout <<" d = "< - /****************************************************************************/ /* MAIN */ int main() { - int i,j,n,d,p,dim; - - /*--------------------------------------------------------------------------*/ - printf(" TRIGGER CIRCUIT EXAMPLE (ADOL-C Example)\n\n"); /* inputs */ - printf(" # of indeps = 7, # of deps = 7 (fixed)\n"); - - n = 7; - p = 3; - d = 4; - - /*--------------------------------------------------------------------------*/ - double* xp = new double[n]; /* allocations and inits */ - double* Fhp = new double[n]; - double** S = new double*[n]; - double** tensors; - int* multi = new int[d]; - int* add = new int[5]; - - for(i=0;i>= Fhp[i]; - trace_off(); - - /*--------------------------------------------------------------------------*/ - printf("\n Fh(x,0) = \n ("); /* inverse_tensor_eval */ - for(i=0;i>= Fhp[i]; + trace_off(); + + /*--------------------------------------------------------------------------*/ + printf("\n Fh(x,0) = \n ("); /* inverse_tensor_eval */ + for (i = 0; i < n; i++) + printf(" %f", Fhp[i]); + printf(" %15.10f )\n\n", Fhp[n - 1]); + dim = binomi(p + d, d); + tensors = myalloc2(n, dim); + + inverse_tensor_eval(1, n, d, p, xp, tensors, S); + + for (i = 0; i < d; i++) + multi[i] = 0; + multi[d - 1] = 1; + add[0] = tensor_address(d, multi); + multi[d - 2] = 1; + add[1] = tensor_address(d, multi); + multi[d - 3] = 1; + add[2] = tensor_address(d, multi); + multi[d - 1] = 2; + multi[d - 2] = 0; + multi[d - 3] = 0; + add[3] = tensor_address(d, multi); + multi[d - 1] = 3; + add[4] = tensor_address(d, multi); + printf(" Results: \n"); + printf(" Fh^{-1}(0,z) = \n ("); + for (i = 0; i < n - 1; i++) + printf(" %15.10f ,", tensors[i][0]); + printf(" %15.10f )\n\n", tensors[n - 1][0]); + printf(" Fh^{-1}_{z_1}(0,z) = \n ("); + for (i = 0; i < n - 1; i++) + printf(" %15.10f ,", tensors[i][add[0]]); + printf(" %15.10f )\n\n", tensors[n - 1][add[0]]); + printf(" Fh^{-1}_{x_1 x_1}(0,z) = \n ("); + for (i = 0; i < n - 1; i++) + printf(" %15.10f ,", tensors[i][add[1]]); + printf(" %15.10f )\n\n", tensors[n - 1][add[1]]); + printf(" Fh^{-1}_{x_1 x_1 x_1}(0,z) = \n ("); + for (i = 0; i < n - 1; i++) + printf(" %15.10f ,", tensors[i][add[2]]); + printf(" %15.10f )\n\n", tensors[n - 1][add[2]]); + printf(" Fh^{-1}_{x_2}(0,z) = \n ("); + for (i = 0; i < n - 1; i++) + printf(" %15.10f ,", tensors[i][add[3]]); + printf(" %15.10f )\n\n", tensors[n - 1][add[3]]); + printf(" Fh^{-1}_{x_3}(0,z) = \n ("); + for (i = 0; i < n - 1; i++) + printf(" %15.10f ,", tensors[i][add[4]]); + printf(" %15.10f )\n", tensors[n - 1][add[4]]); + + return 1; } /****************************************************************************/ /* THAT'S ALL */ - - diff --git a/ADOL-C/examples/additional_examples/timing/rotations.cpp b/ADOL-C/examples/additional_examples/timing/rotations.cpp index 6baad937d..0e8b7d95a 100644 --- a/ADOL-C/examples/additional_examples/timing/rotations.cpp +++ b/ADOL-C/examples/additional_examples/timing/rotations.cpp @@ -2,25 +2,25 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: rotations.cpp Revision: $Id$ - Contents: + Contents: - ... contains elementary rotations used by the machine tool + ... contains elementary rotations used by the machine tool example of gearing (vfunc_pargear.C) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _ROTATIONS_C_ /****************************************************************************/ /* INCLUDES */ -#include #include "rotations.h" +#include #include @@ -28,374 +28,372 @@ /* ELEMENTARY ROTATIONS */ /*--------------------------------------------------------------------------*/ -void D1 ( double * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - double tmpVec2=locSin*vec[1] + locCos*vec[2]; - vec[1]=locCos*vec[1] - locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D1 ( double * depVec, double * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D1(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=indepVec[0]; - depVec[1]=locCos*indepVec[1] - locSin*indepVec[2]; - depVec[2]=locSin*indepVec[1] + locCos*indepVec[2]; -} - -void D1T ( double * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - double tmpVec2=-locSin*vec[1] + locCos*vec[2]; - vec[1]=locCos*vec[1] + locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D1T ( double * depVec, double * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D1T(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=indepVec[0]; - depVec[1]=locCos*indepVec[1] + locSin*indepVec[2]; - depVec[2]=-locSin*indepVec[1] + locCos*indepVec[2]; +void D1(double *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + double tmpVec2 = locSin * vec[1] + locCos * vec[2]; + vec[1] = locCos * vec[1] - locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D1(double *depVec, double *indepVec, double &alpha) { + if (indepVec == depVec) { + D1(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = indepVec[0]; + depVec[1] = locCos * indepVec[1] - locSin * indepVec[2]; + depVec[2] = locSin * indepVec[1] + locCos * indepVec[2]; +} + +void D1T(double *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + double tmpVec2 = -locSin * vec[1] + locCos * vec[2]; + vec[1] = locCos * vec[1] + locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D1T(double *depVec, double *indepVec, double &alpha) { + if (indepVec == depVec) { + D1T(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = indepVec[0]; + depVec[1] = locCos * indepVec[1] + locSin * indepVec[2]; + depVec[2] = -locSin * indepVec[1] + locCos * indepVec[2]; } /*--------------------------------------------------------------------------*/ -void D2 ( double * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - double tmpVec2=-locSin*vec[0] + locCos*vec[2]; - vec[0]=locCos*vec[0] + locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D2 ( double * depVec, double * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D2(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] + locSin*indepVec[2]; - depVec[1]=indepVec[1]; - depVec[2]=-locSin*indepVec[0] + locCos*indepVec[2]; -} - -void D2T ( double * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - double tmpVec2=locSin*vec[0] + locCos*vec[2]; - vec[0]=locCos*vec[0] - locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D2T ( double * depVec, double * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D2T(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] - locSin*indepVec[2]; - depVec[1]=indepVec[1]; - depVec[2]=locSin*indepVec[0] + locCos*indepVec[2]; +void D2(double *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + double tmpVec2 = -locSin * vec[0] + locCos * vec[2]; + vec[0] = locCos * vec[0] + locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D2(double *depVec, double *indepVec, double &alpha) { + if (indepVec == depVec) { + D2(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] + locSin * indepVec[2]; + depVec[1] = indepVec[1]; + depVec[2] = -locSin * indepVec[0] + locCos * indepVec[2]; +} + +void D2T(double *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + double tmpVec2 = locSin * vec[0] + locCos * vec[2]; + vec[0] = locCos * vec[0] - locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D2T(double *depVec, double *indepVec, double &alpha) { + if (indepVec == depVec) { + D2T(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] - locSin * indepVec[2]; + depVec[1] = indepVec[1]; + depVec[2] = locSin * indepVec[0] + locCos * indepVec[2]; } /*--------------------------------------------------------------------------*/ -void D3 ( double * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - double tmpVec1=locSin*vec[0] + locCos*vec[1]; - vec[0]=locCos*vec[0] - locSin*vec[1]; - vec[1]=tmpVec1; -} - -void D3 ( double * depVec, double * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D3(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] - locSin*indepVec[1]; - depVec[1]=locSin*indepVec[0] + locCos*indepVec[1]; - depVec[2]=indepVec[2]; -} - -void D3T ( double * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - double tmpVec1=-locSin*vec[0] + locCos*vec[1]; - vec[0]=locCos*vec[0] + locSin*vec[1]; - vec[1]=tmpVec1; -} - -void D3T ( double * depVec, double * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D3T(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] + locSin*indepVec[1]; - depVec[1]=-locSin*indepVec[0] + locCos*indepVec[1]; - depVec[2]=indepVec[2]; +void D3(double *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + double tmpVec1 = locSin * vec[0] + locCos * vec[1]; + vec[0] = locCos * vec[0] - locSin * vec[1]; + vec[1] = tmpVec1; +} + +void D3(double *depVec, double *indepVec, double &alpha) { + if (indepVec == depVec) { + D3(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] - locSin * indepVec[1]; + depVec[1] = locSin * indepVec[0] + locCos * indepVec[1]; + depVec[2] = indepVec[2]; +} + +void D3T(double *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + double tmpVec1 = -locSin * vec[0] + locCos * vec[1]; + vec[0] = locCos * vec[0] + locSin * vec[1]; + vec[1] = tmpVec1; +} + +void D3T(double *depVec, double *indepVec, double &alpha) { + if (indepVec == depVec) { + D3T(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] + locSin * indepVec[1]; + depVec[1] = -locSin * indepVec[0] + locCos * indepVec[1]; + depVec[2] = indepVec[2]; } - /****************************************************************************/ /* ACTIVATED ELEMENTARY ROTATIONS */ /*--------------------------------------------------------------------------*/ -void D1 ( adouble * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - adouble tmpVec2=locSin*vec[1] + locCos*vec[2]; - vec[1]=locCos*vec[1] - locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D1 ( adouble * depVec, adouble * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D1(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=indepVec[0]; - depVec[1]=locCos*indepVec[1] - locSin*indepVec[2]; - depVec[2]=locSin*indepVec[1] + locCos*indepVec[2]; -} - -void D1 ( adouble * vec, adouble & alpha ) { - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - adouble tmpVec2=locSin*vec[1] + locCos*vec[2]; - vec[1]=locCos*vec[1] - locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D1 ( adouble * depVec, adouble * indepVec, adouble & alpha ) { - if ( indepVec == depVec ) { - D1(depVec,alpha); - return; - } - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - depVec[0]=indepVec[0]; - depVec[1]=locCos*indepVec[1] - locSin*indepVec[2]; - depVec[2]=locSin*indepVec[1] + locCos*indepVec[2]; -} - -void D1T ( adouble * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - adouble tmpVec2=-locSin*vec[1] + locCos*vec[2]; - vec[1]=locCos*vec[1] + locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D1T ( adouble * depVec, adouble * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D1T(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=indepVec[0]; - depVec[1]=locCos*indepVec[1] + locSin*indepVec[2]; - depVec[2]=-locSin*indepVec[1] + locCos*indepVec[2]; -} - -void D1T ( adouble * vec, adouble & alpha ) { - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - adouble tmpVec2=-locSin*vec[1] + locCos*vec[2]; - vec[1]=locCos*vec[1] + locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D1T ( adouble * depVec, adouble * indepVec, adouble & alpha ) { - if ( indepVec == depVec ) { - D1T(depVec,alpha); - return; - } - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - depVec[0]=indepVec[0]; - depVec[1]=locCos*indepVec[1] + locSin*indepVec[2]; - depVec[2]=-locSin*indepVec[1] + locCos*indepVec[2]; +void D1(adouble *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + adouble tmpVec2 = locSin * vec[1] + locCos * vec[2]; + vec[1] = locCos * vec[1] - locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D1(adouble *depVec, adouble *indepVec, double &alpha) { + if (indepVec == depVec) { + D1(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = indepVec[0]; + depVec[1] = locCos * indepVec[1] - locSin * indepVec[2]; + depVec[2] = locSin * indepVec[1] + locCos * indepVec[2]; +} + +void D1(adouble *vec, adouble &alpha) { + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + adouble tmpVec2 = locSin * vec[1] + locCos * vec[2]; + vec[1] = locCos * vec[1] - locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D1(adouble *depVec, adouble *indepVec, adouble &alpha) { + if (indepVec == depVec) { + D1(depVec, alpha); + return; + } + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + depVec[0] = indepVec[0]; + depVec[1] = locCos * indepVec[1] - locSin * indepVec[2]; + depVec[2] = locSin * indepVec[1] + locCos * indepVec[2]; +} + +void D1T(adouble *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + adouble tmpVec2 = -locSin * vec[1] + locCos * vec[2]; + vec[1] = locCos * vec[1] + locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D1T(adouble *depVec, adouble *indepVec, double &alpha) { + if (indepVec == depVec) { + D1T(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = indepVec[0]; + depVec[1] = locCos * indepVec[1] + locSin * indepVec[2]; + depVec[2] = -locSin * indepVec[1] + locCos * indepVec[2]; +} + +void D1T(adouble *vec, adouble &alpha) { + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + adouble tmpVec2 = -locSin * vec[1] + locCos * vec[2]; + vec[1] = locCos * vec[1] + locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D1T(adouble *depVec, adouble *indepVec, adouble &alpha) { + if (indepVec == depVec) { + D1T(depVec, alpha); + return; + } + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + depVec[0] = indepVec[0]; + depVec[1] = locCos * indepVec[1] + locSin * indepVec[2]; + depVec[2] = -locSin * indepVec[1] + locCos * indepVec[2]; } /*--------------------------------------------------------------------------*/ -void D2 ( adouble * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - adouble tmpVec2=-locSin*vec[0] + locCos*vec[2]; - vec[0]=locCos*vec[0] + locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D2 ( adouble * depVec, adouble * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D2(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] + locSin*indepVec[2]; - depVec[1]=indepVec[1]; - depVec[2]=-locSin*indepVec[0] + locCos*indepVec[2]; -} - -void D2 ( adouble * vec, adouble & alpha ) { - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - adouble tmpVec2=-locSin*vec[0] + locCos*vec[2]; - vec[0]=locCos*vec[0] + locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D2 ( adouble * depVec, adouble * indepVec, adouble & alpha ) { - if ( indepVec == depVec ) { - D2(depVec,alpha); - return; - } - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] + locSin*indepVec[2]; - depVec[1]=indepVec[1]; - depVec[2]=-locSin*indepVec[0] + locCos*indepVec[2]; -} - -void D2T ( adouble * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - adouble tmpVec2=locSin*vec[0] + locCos*vec[2]; - vec[0]=locCos*vec[0] - locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D2T ( adouble * depVec, adouble * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D2T(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] - locSin*indepVec[2]; - depVec[1]=indepVec[1]; - depVec[2]=locSin*indepVec[0] + locCos*indepVec[2]; -} - -void D2T ( adouble * vec, adouble & alpha ) { - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - adouble tmpVec2=locSin*vec[0] + locCos*vec[2]; - vec[0]=locCos*vec[0] - locSin*vec[2]; - vec[2]=tmpVec2; -} - -void D2T ( adouble * depVec, adouble * indepVec, adouble & alpha ) { - if ( indepVec == depVec ) { - D2T(depVec,alpha); - return; - } - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] - locSin*indepVec[2]; - depVec[1]=indepVec[1]; - depVec[2]=locSin*indepVec[0] + locCos*indepVec[2]; +void D2(adouble *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + adouble tmpVec2 = -locSin * vec[0] + locCos * vec[2]; + vec[0] = locCos * vec[0] + locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D2(adouble *depVec, adouble *indepVec, double &alpha) { + if (indepVec == depVec) { + D2(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] + locSin * indepVec[2]; + depVec[1] = indepVec[1]; + depVec[2] = -locSin * indepVec[0] + locCos * indepVec[2]; +} + +void D2(adouble *vec, adouble &alpha) { + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + adouble tmpVec2 = -locSin * vec[0] + locCos * vec[2]; + vec[0] = locCos * vec[0] + locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D2(adouble *depVec, adouble *indepVec, adouble &alpha) { + if (indepVec == depVec) { + D2(depVec, alpha); + return; + } + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] + locSin * indepVec[2]; + depVec[1] = indepVec[1]; + depVec[2] = -locSin * indepVec[0] + locCos * indepVec[2]; +} + +void D2T(adouble *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + adouble tmpVec2 = locSin * vec[0] + locCos * vec[2]; + vec[0] = locCos * vec[0] - locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D2T(adouble *depVec, adouble *indepVec, double &alpha) { + if (indepVec == depVec) { + D2T(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] - locSin * indepVec[2]; + depVec[1] = indepVec[1]; + depVec[2] = locSin * indepVec[0] + locCos * indepVec[2]; +} + +void D2T(adouble *vec, adouble &alpha) { + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + adouble tmpVec2 = locSin * vec[0] + locCos * vec[2]; + vec[0] = locCos * vec[0] - locSin * vec[2]; + vec[2] = tmpVec2; +} + +void D2T(adouble *depVec, adouble *indepVec, adouble &alpha) { + if (indepVec == depVec) { + D2T(depVec, alpha); + return; + } + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] - locSin * indepVec[2]; + depVec[1] = indepVec[1]; + depVec[2] = locSin * indepVec[0] + locCos * indepVec[2]; } /*--------------------------------------------------------------------------*/ -void D3 ( adouble * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - adouble tmpVec1=locSin*vec[0] + locCos*vec[1]; - vec[0]=locCos*vec[0] - locSin*vec[1]; - vec[1]=tmpVec1; -} - -void D3 ( adouble * depVec, adouble * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D3(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] - locSin*indepVec[1]; - depVec[1]=locSin*indepVec[0] + locCos*indepVec[1]; - depVec[2]=indepVec[2]; -} - -void D3 ( adouble * vec, adouble & alpha ) { - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - adouble tmpVec1=locSin*vec[0] + locCos*vec[1]; - vec[0]=locCos*vec[0] - locSin*vec[1]; - vec[1]=tmpVec1; -} - -void D3 ( adouble * depVec, adouble * indepVec, adouble & alpha ) { - if ( indepVec == depVec ) { - D3(depVec,alpha); - return; - } - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] - locSin*indepVec[1]; - depVec[1]=locSin*indepVec[0] + locCos*indepVec[1]; - depVec[2]=indepVec[2]; -} - -void D3T ( adouble * vec, double & alpha ) { - double locCos=cos(alpha); - double locSin=sin(alpha); - adouble tmpVec1=-locSin*vec[0] + locCos*vec[1]; - vec[0]=locCos*vec[0] + locSin*vec[1]; - vec[1]=tmpVec1; -} - -void D3T ( adouble * depVec, adouble * indepVec, double & alpha ) { - if ( indepVec == depVec ) { - D3T(depVec,alpha); - return; - } - double locCos=cos(alpha); - double locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] + locSin*indepVec[1]; - depVec[1]=-locSin*indepVec[0] + locCos*indepVec[1]; - depVec[2]=indepVec[2]; -} - -void D3T ( adouble * vec, adouble & alpha ) { - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - adouble tmpVec1=-locSin*vec[0] + locCos*vec[1]; - vec[0]=locCos*vec[0] + locSin*vec[1]; - vec[1]=tmpVec1; -} - -void D3T ( adouble * depVec, adouble * indepVec, adouble & alpha ) { - if ( indepVec == depVec ) { - D3T(depVec,alpha); - return; - } - adouble locCos=cos(alpha); - adouble locSin=sin(alpha); - depVec[0]=locCos*indepVec[0] + locSin*indepVec[1]; - depVec[1]=-locSin*indepVec[0] + locCos*indepVec[1]; - depVec[2]=indepVec[2]; +void D3(adouble *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + adouble tmpVec1 = locSin * vec[0] + locCos * vec[1]; + vec[0] = locCos * vec[0] - locSin * vec[1]; + vec[1] = tmpVec1; +} + +void D3(adouble *depVec, adouble *indepVec, double &alpha) { + if (indepVec == depVec) { + D3(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] - locSin * indepVec[1]; + depVec[1] = locSin * indepVec[0] + locCos * indepVec[1]; + depVec[2] = indepVec[2]; +} + +void D3(adouble *vec, adouble &alpha) { + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + adouble tmpVec1 = locSin * vec[0] + locCos * vec[1]; + vec[0] = locCos * vec[0] - locSin * vec[1]; + vec[1] = tmpVec1; +} + +void D3(adouble *depVec, adouble *indepVec, adouble &alpha) { + if (indepVec == depVec) { + D3(depVec, alpha); + return; + } + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] - locSin * indepVec[1]; + depVec[1] = locSin * indepVec[0] + locCos * indepVec[1]; + depVec[2] = indepVec[2]; +} + +void D3T(adouble *vec, double &alpha) { + double locCos = cos(alpha); + double locSin = sin(alpha); + adouble tmpVec1 = -locSin * vec[0] + locCos * vec[1]; + vec[0] = locCos * vec[0] + locSin * vec[1]; + vec[1] = tmpVec1; +} + +void D3T(adouble *depVec, adouble *indepVec, double &alpha) { + if (indepVec == depVec) { + D3T(depVec, alpha); + return; + } + double locCos = cos(alpha); + double locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] + locSin * indepVec[1]; + depVec[1] = -locSin * indepVec[0] + locCos * indepVec[1]; + depVec[2] = indepVec[2]; +} + +void D3T(adouble *vec, adouble &alpha) { + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + adouble tmpVec1 = -locSin * vec[0] + locCos * vec[1]; + vec[0] = locCos * vec[0] + locSin * vec[1]; + vec[1] = tmpVec1; +} + +void D3T(adouble *depVec, adouble *indepVec, adouble &alpha) { + if (indepVec == depVec) { + D3T(depVec, alpha); + return; + } + adouble locCos = cos(alpha); + adouble locSin = sin(alpha); + depVec[0] = locCos * indepVec[0] + locSin * indepVec[1]; + depVec[1] = -locSin * indepVec[0] + locCos * indepVec[1]; + depVec[2] = indepVec[2]; } - #undef _ROTATIONS_C_ diff --git a/ADOL-C/examples/additional_examples/timing/rotations.h b/ADOL-C/examples/additional_examples/timing/rotations.h index 6829ed513..ce3fe2c59 100644 --- a/ADOL-C/examples/additional_examples/timing/rotations.h +++ b/ADOL-C/examples/additional_examples/timing/rotations.h @@ -2,18 +2,18 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: rotations.h Revision: $Id$ - Contents: + Contents: - ... contains elementary rotations used by the machine tool + ... contains elementary rotations used by the machine tool example of gearing (vfunc_pargear.C) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #ifndef _ROTATIONS_H_ #define _ROTATIONS_H_ @@ -24,57 +24,54 @@ class adouble; /* ELEMENTARY ROTATIONS */ /*--------------------------------------------------------------------------*/ -void D1 ( double * vec, double & alpha ); -void D1 ( double * depVec, double * indepVec, double & alpha ); -void D1T ( double * vec, double & alpha ); -void D1T ( double * depVec, double * indepVec, double & alpha ); +void D1(double *vec, double &alpha); +void D1(double *depVec, double *indepVec, double &alpha); +void D1T(double *vec, double &alpha); +void D1T(double *depVec, double *indepVec, double &alpha); /*--------------------------------------------------------------------------*/ -void D2 ( double * vec, double & alpha ); -void D2 ( double * depVec, double * indepVec, double & alpha ); -void D2T ( double * vec, double & alpha ); -void D2T ( double * depVec, double * indepVec, double & alpha ); +void D2(double *vec, double &alpha); +void D2(double *depVec, double *indepVec, double &alpha); +void D2T(double *vec, double &alpha); +void D2T(double *depVec, double *indepVec, double &alpha); /*--------------------------------------------------------------------------*/ -void D3 ( double * vec, double & alpha ); -void D3 ( double * depVec, double * indepVec, double & alpha ); -void D3T ( double * vec, double & alpha ); -void D3T ( double * depVec, double * indepVec, double & alpha ); - +void D3(double *vec, double &alpha); +void D3(double *depVec, double *indepVec, double &alpha); +void D3T(double *vec, double &alpha); +void D3T(double *depVec, double *indepVec, double &alpha); /****************************************************************************/ /* ACTIVATED ELEMENTARY ROTATIONS */ /*--------------------------------------------------------------------------*/ -void D1 ( adouble * vec, double & alpha ); -void D1 ( adouble * depVec, adouble * indepVec, double & alpha ); -void D1T ( adouble * vec, double & alpha ); -void D1T ( adouble * depVec, adouble * indepVec, double & alpha ); -void D1 ( adouble * vec, adouble & alpha ); -void D1 ( adouble * depVec, adouble * indepVec, adouble & alpha ); -void D1T ( adouble * vec, adouble & alpha ); -void D1T ( adouble * depVec, adouble * indepVec, adouble & alpha ); +void D1(adouble *vec, double &alpha); +void D1(adouble *depVec, adouble *indepVec, double &alpha); +void D1T(adouble *vec, double &alpha); +void D1T(adouble *depVec, adouble *indepVec, double &alpha); +void D1(adouble *vec, adouble &alpha); +void D1(adouble *depVec, adouble *indepVec, adouble &alpha); +void D1T(adouble *vec, adouble &alpha); +void D1T(adouble *depVec, adouble *indepVec, adouble &alpha); /*--------------------------------------------------------------------------*/ -void D2 ( adouble * vec, double & alpha ); -void D2 ( adouble * depVec, adouble * indepVec, double & alpha ); -void D2T ( adouble * vec, double & alpha ); -void D2T ( adouble * depVec, adouble * indepVec, double & alpha ); -void D2 ( adouble * vec, adouble & alpha ); -void D2 ( adouble * depVec, adouble * indepVec, adouble & alpha ); -void D2T ( adouble * vec, adouble & alpha ); -void D2T ( adouble * depVec, adouble * indepVec, adouble & alpha ); +void D2(adouble *vec, double &alpha); +void D2(adouble *depVec, adouble *indepVec, double &alpha); +void D2T(adouble *vec, double &alpha); +void D2T(adouble *depVec, adouble *indepVec, double &alpha); +void D2(adouble *vec, adouble &alpha); +void D2(adouble *depVec, adouble *indepVec, adouble &alpha); +void D2T(adouble *vec, adouble &alpha); +void D2T(adouble *depVec, adouble *indepVec, adouble &alpha); /*--------------------------------------------------------------------------*/ -void D3 ( adouble * vec, double & alpha ); -void D3 ( adouble * depVec, adouble * indepVec, double & alpha ); -void D3T ( adouble * vec, double & alpha ); -void D3T ( adouble * depVec, adouble * indepVec, double & alpha ); -void D3 ( adouble * vec, adouble & alpha ); -void D3 ( adouble * depVec, adouble * indepVec, adouble & alpha ); -void D3T ( adouble * vec, adouble & alpha ); -void D3T ( adouble * depVec, adouble * indepVec, adouble & alpha ); - +void D3(adouble *vec, double &alpha); +void D3(adouble *depVec, adouble *indepVec, double &alpha); +void D3T(adouble *vec, double &alpha); +void D3T(adouble *depVec, adouble *indepVec, double &alpha); +void D3(adouble *vec, adouble &alpha); +void D3(adouble *depVec, adouble *indepVec, adouble &alpha); +void D3T(adouble *vec, adouble &alpha); +void D3T(adouble *depVec, adouble *indepVec, adouble &alpha); #endif - diff --git a/ADOL-C/examples/additional_examples/timing/sfunc_determinant.cpp b/ADOL-C/examples/additional_examples/timing/sfunc_determinant.cpp index c2fafea6a..61fa32105 100644 --- a/ADOL-C/examples/additional_examples/timing/sfunc_determinant.cpp +++ b/ADOL-C/examples/additional_examples/timing/sfunc_determinant.cpp @@ -3,23 +3,23 @@ File: sfunc_determinant.cpp Revision: $Id$ Contents: function module containing the determinant example - + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SFUNC_DETERMINANT_C_ @@ -27,13 +27,12 @@ /* INCLUDES */ #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "detexam.ctrl"; +const char *controlFileName = "detexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -44,146 +43,137 @@ int indepDim; int matrixDim; int mRec; - /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"COMPUTATION OF DETERMINANTS Type 2 (ADOL-C Example)\n\n"); - if (indepDim > 0) - matrixDim = indepDim; - else { - fprintf(stdout," order of matrix = ? "); - fscanf(stdin,"%d",&matrixDim); - fprintf(stdout,"\n"); - } - indepDim = matrixDim * matrixDim; +void initProblemParameters(void) { + fprintf(stdout, "COMPUTATION OF DETERMINANTS Type 2 (ADOL-C Example)\n\n"); + if (indepDim > 0) + matrixDim = indepDim; + else { + fprintf(stdout, " order of matrix = ? "); + fscanf(stdin, "%d", &matrixDim); + fprintf(stdout, "\n"); + } + indepDim = matrixDim * matrixDim; } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - int i, j; - double* iP = indeps; - mRec = 1; - for (i=0; i= p) { - if (m == p) { - if (s > 0) - t += *pt; - else - t -= *pt; - } else { - if (s > 0) - t += (*pt)*det(k-1, m-p, indeps); - else - t -= (*pt)*det(k-1, m-p, indeps); - } - s = -s; - } - ++pt; - p = p1; +double det(int k, int m, double *indeps) { + int i; + if (m == 0) + return 1.0; + else { + double *pt = indeps + ((k - 1) * matrixDim); + double t = 0; + int p = 1; + int p1, s; + if (k % 2) + s = 1; + else + s = -1; + for (i = 0; i < matrixDim; i++) { + p1 = 2 * p; + if (m % p1 >= p) { + if (m == p) { + if (s > 0) + t += *pt; + else + t -= *pt; + } else { + if (s > 0) + t += (*pt) * det(k - 1, m - p, indeps); + else + t -= (*pt) * det(k - 1, m - p, indeps); } - return t; + s = -s; + } + ++pt; + p = p1; } + return t; + } } /*--------------------------------------------------------------------------*/ /* The interface function */ -double originalScalarFunction( double* indeps ) { - return det(matrixDim, mRec-1, indeps); +double originalScalarFunction(double *indeps) { + return det(matrixDim, mRec - 1, indeps); } - /****************************************************************************/ /* TAPING SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The recursive determinant function */ -adouble activeDet( int k, int m, adouble* indeps ) { - int i; - if (m == 0) - return 1.0; - else { - adouble* pt = indeps + ((k-1)*matrixDim); - adouble t = 0; - int p = 1; - int p1, s; - if (k%2) - s = 1; - else - s = -1; - for (i=0; i= p) { - if (m == p) { - if (s > 0) - t += *pt; - else - t -= *pt; - } else { - if (s > 0) - t += (*pt)*activeDet(k-1, m-p, indeps); - else - t -= (*pt)*activeDet(k-1, m-p, indeps); - } - s = -s; - } - ++pt; - p = p1; +adouble activeDet(int k, int m, adouble *indeps) { + int i; + if (m == 0) + return 1.0; + else { + adouble *pt = indeps + ((k - 1) * matrixDim); + adouble t = 0; + int p = 1; + int p1, s; + if (k % 2) + s = 1; + else + s = -1; + for (i = 0; i < matrixDim; i++) { + p1 = 2 * p; + if (m % p1 >= p) { + if (m == p) { + if (s > 0) + t += *pt; + else + t -= *pt; + } else { + if (s > 0) + t += (*pt) * activeDet(k - 1, m - p, indeps); + else + t -= (*pt) * activeDet(k - 1, m - p, indeps); } - return t; + s = -s; + } + ++pt; + p = p1; } + return t; + } } /*--------------------------------------------------------------------------*/ /* The interface function */ -double tapingScalarFunction( int tag, double* indeps ) { - int i; - trace_on(tag); - adouble* activeIndeps = new adouble[indepDim]; - adouble* aIP = activeIndeps; - double* iP = indeps; - for (i=0; i>= res; - trace_off(); - return res; +double tapingScalarFunction(int tag, double *indeps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + adouble ares = activeDet(matrixDim, mRec - 1, activeIndeps); + double res = 0; + ares >>= res; + trace_off(); + return res; } #undef _SFUNC_DETERMINANT_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/sfunc_experimental.cpp b/ADOL-C/examples/additional_examples/timing/sfunc_experimental.cpp index e57cbc6e6..3c550c02d 100644 --- a/ADOL-C/examples/additional_examples/timing/sfunc_experimental.cpp +++ b/ADOL-C/examples/additional_examples/timing/sfunc_experimental.cpp @@ -3,41 +3,39 @@ File: sfunc_experimental.cpp Revision: $Id$ Contents: function module containing an experimental function - + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SFUNC_EXPERIMENTAL_C_ - /****************************************************************************/ /* INCLUDES */ #include -#include #include - +#include /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "experimental.ctrl"; +const char *controlFileName = "experimental.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -45,87 +43,76 @@ int indepDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ -//#define CODE sqrt(indeps[i]) +// #define CODE sqrt(indeps[i]) #define CODE sin(indeps[i]) -//#define CODE indeps[i]*indeps[i] - +// #define CODE indeps[i]*indeps[i] /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"EXPERIMENTAL EXAMPLE (ADOL-C Example)\n\n"); - if (indepDim <= 0) { - fprintf(stdout," number of independent variables = ? "); - fscanf(stdin,"%d",&indepDim); - fprintf(stdout,"\n"); - } +void initProblemParameters(void) { + fprintf(stdout, "EXPERIMENTAL EXAMPLE (ADOL-C Example)\n\n"); + if (indepDim <= 0) { + fprintf(stdout, " number of independent variables = ? "); + fscanf(stdin, "%d", &indepDim); + fprintf(stdout, "\n"); + } } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - int i; - for (i=0; i>= res; - trace_off(); - return res; +double tapingScalarFunction(int tag, double *indeps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + adouble ares = activeExperimental(indepDim, activeIndeps); + double res = 0; + ares >>= res; + trace_off(); + return res; } #undef _SFUNC_EXPERIMENTAL_C_ - - - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/sfunc_griewank.cpp b/ADOL-C/examples/additional_examples/timing/sfunc_griewank.cpp index 9803b19c2..2fb0a10bf 100644 --- a/ADOL-C/examples/additional_examples/timing/sfunc_griewank.cpp +++ b/ADOL-C/examples/additional_examples/timing/sfunc_griewank.cpp @@ -5,38 +5,36 @@ Contents: function module containing Griewanks function Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SFUNC_GRIEWANK_C_ - /****************************************************************************/ /* INCLUDES */ #include #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "griewankexam.ctrl"; +const char *controlFileName = "griewankexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -46,95 +44,82 @@ int indepDim; /* Other problem dependent parameters */ const double D = 4000.0; - /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"GRIEWANKs FUNCTION (ADOL-C Example)\n\n"); - if (indepDim <= 0) { - fprintf(stdout," number of independent variables = ? "); - fscanf(stdin,"%d",&indepDim); - fprintf(stdout,"\n"); - } +void initProblemParameters(void) { + fprintf(stdout, "GRIEWANKs FUNCTION (ADOL-C Example)\n\n"); + if (indepDim <= 0) { + fprintf(stdout, " number of independent variables = ? "); + fscanf(stdin, "%d", &indepDim); + fprintf(stdout, "\n"); + } } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - int i; - for (i=0; i>= res; - trace_off(); - return res; +double tapingScalarFunction(int tag, double *indeps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + adouble ares = activeGriewank(indepDim, activeIndeps); + double res = 0; + ares >>= res; + trace_off(); + return res; } #undef _SFUNC_GRIEWANK_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/sfunc_helmholtz.cpp b/ADOL-C/examples/additional_examples/timing/sfunc_helmholtz.cpp index 76cc418a1..98339e24b 100644 --- a/ADOL-C/examples/additional_examples/timing/sfunc_helmholtz.cpp +++ b/ADOL-C/examples/additional_examples/timing/sfunc_helmholtz.cpp @@ -5,37 +5,35 @@ Contents: function module containing Helmholtz energy function Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SFUNC_HELMHOLTZ_C_ - /****************************************************************************/ /* INCLUDES */ #include #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "helmholtzexam.ctrl"; +const char *controlFileName = "helmholtzexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -45,115 +43,106 @@ int indepDim; /* Other problem dependent parameters */ double *bv = NULL; const double R = sqrt(2.0); -const double TE= 0.01; /* originally 0.0 */ - +const double TE = 0.01; /* originally 0.0 */ /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"HELMHOLTZ ENERGY (ADOL-C Example)\n\n"); - if (indepDim <= 0) { - fprintf(stdout," number of independent variables = ? "); - fscanf(stdin,"%d",&indepDim); - fprintf(stdout,"\n"); - } +void initProblemParameters(void) { + fprintf(stdout, "HELMHOLTZ ENERGY (ADOL-C Example)\n\n"); + if (indepDim <= 0) { + fprintf(stdout, " number of independent variables = ? "); + fscanf(stdin, "%d", &indepDim); + fprintf(stdout, "\n"); + } } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - int i; - double r = 1.0/indepDim; - if (bv) - delete[] bv; - bv = new double[indepDim]; - for (i=0; i>= res; - trace_off(); - return res; +double tapingScalarFunction(int tag, double *indeps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + adouble ares = activeHelmholtz(indepDim, activeIndeps, bv); + double res = 0; + ares >>= res; + trace_off(); + return res; } #undef _SFUNC_HELMHOLTZ_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/sfunc_michalewitz.cpp b/ADOL-C/examples/additional_examples/timing/sfunc_michalewitz.cpp index 30a59ff81..cf015745e 100644 --- a/ADOL-C/examples/additional_examples/timing/sfunc_michalewitz.cpp +++ b/ADOL-C/examples/additional_examples/timing/sfunc_michalewitz.cpp @@ -5,38 +5,36 @@ Contents: function module containing Michalewitz' function Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SFUNC_MICHALEWITZ_C_ - /****************************************************************************/ /* INCLUDES */ #include #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "michalewitzexam.ctrl"; +const char *controlFileName = "michalewitzexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -45,83 +43,76 @@ int indepDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ #define Pi 3.141592654 -const double M = 10.0; - +const double M = 10.0; /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"MICHALEWITZ' FUNCTION (ADOL-C Example)\n\n"); - if (indepDim <= 0) { - fprintf(stdout," number of independent variables = ? "); - fscanf(stdin,"%d",&indepDim); - fprintf(stdout,"\n"); - } +void initProblemParameters(void) { + fprintf(stdout, "MICHALEWITZ' FUNCTION (ADOL-C Example)\n\n"); + if (indepDim <= 0) { + fprintf(stdout, " number of independent variables = ? "); + fscanf(stdin, "%d", &indepDim); + fprintf(stdout, "\n"); + } } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - int i; - for (i=0; i>= res; - trace_off(); - return res; +double tapingScalarFunction(int tag, double *indeps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + adouble ares = activeMicha(indepDim, activeIndeps); + double res = 0; + ares >>= res; + trace_off(); + return res; } #undef _SFUNC_MICHALEWITZ_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/sfunc_power.cpp b/ADOL-C/examples/additional_examples/timing/sfunc_power.cpp index be066fcee..d0e29b9c9 100644 --- a/ADOL-C/examples/additional_examples/timing/sfunc_power.cpp +++ b/ADOL-C/examples/additional_examples/timing/sfunc_power.cpp @@ -5,21 +5,21 @@ Contents: function module containing the power example Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SFUNC_POWER_C_ @@ -30,13 +30,12 @@ #include #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "powexam.ctrl"; +const char *controlFileName = "powexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -45,103 +44,90 @@ int indepDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ int exponent; -//static unsigned short int dx[3]; /* variable needed by erand48(.) */ - +// static unsigned short int dx[3]; /* variable needed by erand48(.) */ /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"COMPUTATION OF n-th POWER (ADOL-C Example)\n\n"); - indepDim = 1; - - fprintf(stdout," n = ? "); - fscanf(stdin,"%d",&exponent); - fprintf(stdout,"\n"); - - /* Init erand48(); */ - struct tm s; - time_t t; - time(&t); - s=*localtime(&t); - srand(s.tm_sec*s.tm_min); - /* dx[0]=rand(); - dx[1]=rand(); - dx[2]=rand();*/ +void initProblemParameters(void) { + fprintf(stdout, "COMPUTATION OF n-th POWER (ADOL-C Example)\n\n"); + indepDim = 1; + + fprintf(stdout, " n = ? "); + fscanf(stdin, "%d", &exponent); + fprintf(stdout, "\n"); + + /* Init erand48(); */ + struct tm s; + time_t t; + time(&t); + s = *localtime(&t); + srand(s.tm_sec * s.tm_min); + /* dx[0]=rand(); + dx[1]=rand(); + dx[2]=rand();*/ } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - indeps[0] = (double)rand(); -} - +void initIndependents(double *indeps) { indeps[0] = (double)rand(); } /****************************************************************************/ /* ORIGINAL SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The recursive determinant function */ -double power( double x, int n ) { - double z = 1; - if (n > 0) { - int nh =n/2; - z = power(x,nh); - z *= z; - if (2*nh != n) - z *= x; - return z; - } else - if (n == 0) - return z; - else - return 1.0/power(x,-n); +double power(double x, int n) { + double z = 1; + if (n > 0) { + int nh = n / 2; + z = power(x, nh); + z *= z; + if (2 * nh != n) + z *= x; + return z; + } else if (n == 0) + return z; + else + return 1.0 / power(x, -n); } /*--------------------------------------------------------------------------*/ /* The interface function */ -double originalScalarFunction( double* indeps ) { - return power(indeps[0],exponent); +double originalScalarFunction(double *indeps) { + return power(indeps[0], exponent); } - /****************************************************************************/ /* TAPING SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The recursive power function */ -adouble activePower( adouble x, int n) { - adouble z = 1; - if (n > 0) { - int nh =n/2; - z = activePower(x,nh); - z *= z; - if (2*nh != n) - z *= x; - return z; - } else - if (n == 0) - return z; - else - return 1.0/activePower(x,-n); +adouble activePower(adouble x, int n) { + adouble z = 1; + if (n > 0) { + int nh = n / 2; + z = activePower(x, nh); + z *= z; + if (2 * nh != n) + z *= x; + return z; + } else if (n == 0) + return z; + else + return 1.0 / activePower(x, -n); } /*--------------------------------------------------------------------------*/ /* The interface function */ -double tapingScalarFunction( int tag, double* indeps ) { - trace_on(tag); - adouble activeIndep; - activeIndep <<= *indeps; - adouble ares = activePower(activeIndep,exponent); - double res = 0; - ares >>= res; - trace_off(); - return res; +double tapingScalarFunction(int tag, double *indeps) { + trace_on(tag); + adouble activeIndep; + activeIndep <<= *indeps; + adouble ares = activePower(activeIndep, exponent); + double res = 0; + ares >>= res; + trace_off(); + return res; } #undef _SFUNC_POWER_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/sfunc_rosenbrock.cpp b/ADOL-C/examples/additional_examples/timing/sfunc_rosenbrock.cpp index 83a75922e..898bfbc5c 100644 --- a/ADOL-C/examples/additional_examples/timing/sfunc_rosenbrock.cpp +++ b/ADOL-C/examples/additional_examples/timing/sfunc_rosenbrock.cpp @@ -5,38 +5,36 @@ Contents: function module containing Rosenbrock's function Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SFUNC_ROSENBROCK_C_ - /****************************************************************************/ /* INCLUDES */ #include #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "rosenbrockexam.ctrl"; +const char *controlFileName = "rosenbrockexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -45,97 +43,84 @@ int indepDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ - /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"ROSENBROCKs FUNCTION (ADOL-C Example)\n\n"); - if (indepDim <= 0) { - fprintf(stdout," number of independent variables = ? "); - fscanf(stdin,"%d",&indepDim); - fprintf(stdout,"\n"); - } +void initProblemParameters(void) { + fprintf(stdout, "ROSENBROCKs FUNCTION (ADOL-C Example)\n\n"); + if (indepDim <= 0) { + fprintf(stdout, " number of independent variables = ? "); + fscanf(stdin, "%d", &indepDim); + fprintf(stdout, "\n"); + } } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - int i; - for (i=0; i>= res; - trace_off(); - return res; +double tapingScalarFunction(int tag, double *indeps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + adouble ares = activeRosenbrock(indepDim, activeIndeps); + double res = 0; + ares >>= res; + trace_off(); + return res; } #undef _SFUNC_ROSENBROCK_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/sfunc_speelpenning.cpp b/ADOL-C/examples/additional_examples/timing/sfunc_speelpenning.cpp index 3319b3f3f..9029fe23d 100644 --- a/ADOL-C/examples/additional_examples/timing/sfunc_speelpenning.cpp +++ b/ADOL-C/examples/additional_examples/timing/sfunc_speelpenning.cpp @@ -5,38 +5,36 @@ Contents: function module containing Speepennings product Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SFUNC_SPEELPENNING_C_ - /****************************************************************************/ /* INCLUDES */ #include #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "speelpenning.ctrl"; +const char *controlFileName = "speelpenning.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -45,81 +43,72 @@ int indepDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ - /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"SPEELPENNINGS PRODUCT Type 2 (ADOL-C Example)\n\n"); - if (indepDim <= 0) { - fprintf(stdout," number of independent variables = ? "); - fscanf(stdin,"%d",&indepDim); - fprintf(stdout,"\n"); - } +void initProblemParameters(void) { + fprintf(stdout, "SPEELPENNINGS PRODUCT Type 2 (ADOL-C Example)\n\n"); + if (indepDim <= 0) { + fprintf(stdout, " number of independent variables = ? "); + fscanf(stdin, "%d", &indepDim); + fprintf(stdout, "\n"); + } } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - int i; - for (i=0; i>= res; - trace_off(); - return res; +double tapingScalarFunction(int tag, double *indeps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + adouble ares = activeSpeelpenning(indepDim, activeIndeps); + double res = 0; + ares >>= res; + trace_off(); + return res; } #undef _SFUNC_SPEELPENNING_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/sgenmain.cpp b/ADOL-C/examples/additional_examples/timing/sgenmain.cpp index b314c0b34..7e37ac893 100644 --- a/ADOL-C/examples/additional_examples/timing/sgenmain.cpp +++ b/ADOL-C/examples/additional_examples/timing/sgenmain.cpp @@ -2,50 +2,48 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: sgenmain.cpp Revision: $Id$ - Contents: Scalar Generic Main File: + Contents: Scalar Generic Main File: for use with function modules containing several scalar - examples + examples (e.g. the determinant example in sfunc_determinant.cpp) Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; + + (1) const char* const controlFileName + (2) int indepDim; (3) void initProblemParameters( void ) (4) void initIndependents( double* indeps ) (5) double originalScalarFunction( double* indeps ) - (6) double tapingScalarFunction( int tag, double* indeps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + (6) double tapingScalarFunction( int tag, double* indeps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _SGENMAIN_C_ /****************************************************************************/ /* INCLUDES */ -#include #include "../clock/myclock.h" +#include #include #include - /****************************************************************************/ /* MACROS */ #define TIMEFORMAT " %12.6E units, %12.6E seconds\n" - /****************************************************************************/ /* EXTERNAL STUFF FROM FUNCTION MODULES*/ /*--------------------------------------------------------------------------*/ /* Control file name */ -const extern char* controlFileName; +const extern char *controlFileName; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -53,1079 +51,1073 @@ extern int indepDim; /*--------------------------------------------------------------------------*/ /* Init Problem Parameters */ -extern void initProblemParameters( void ); +extern void initProblemParameters(void); /*--------------------------------------------------------------------------*/ /* Initialize indeps */ -extern void initIndependents( double* indeps ); +extern void initIndependents(double *indeps); /*--------------------------------------------------------------------------*/ /* Original scalar function */ -extern double originalScalarFunction( double* indeps ); +extern double originalScalarFunction(double *indeps); /*--------------------------------------------------------------------------*/ /* Taping scalar function */ -extern double tapingScalarFunction( int tag, double* indeps ); - +extern double tapingScalarFunction(int tag, double *indeps); /****************************************************************************/ /* CONTROL STUFF */ enum controlParameter { - cpDimension, - cpAverageCount, - cpDegree, - cpVecCountFW, - cpVecCountRV, - cpVecCountTR, - cpZosFW, - cpFosFW, - cpHosFW, - cpFovFW, - cpHovFW, - cpFosRV, - cpHosRV, - cpFovRV, - cpHovRV, - cpFunction, - cpJacobian, - cpVecJac, - cpJacVec, - cpHessian, - cpHessVec, - cpLagHessVec, - cpTensor, - cpInvTensor, - cpCount + cpDimension, + cpAverageCount, + cpDegree, + cpVecCountFW, + cpVecCountRV, + cpVecCountTR, + cpZosFW, + cpFosFW, + cpHosFW, + cpFovFW, + cpHovFW, + cpFosRV, + cpHosRV, + cpFovRV, + cpHovRV, + cpFunction, + cpJacobian, + cpVecJac, + cpJacVec, + cpHessian, + cpHessVec, + cpLagHessVec, + cpTensor, + cpInvTensor, + cpCount }; - /****************************************************************************/ /* PROVIDE RANDOM INITs */ -//unsigned short int dx[3]; /* variable needed by erand48(.) */ - -void initRand ( void ) /* a function to initialize dx using actual time */ -{ struct tm s; - time_t t; - time(&t); - s=*localtime(&t); - srand(s.tm_sec*s.tm_min); - /* dx[0]=rand(); - dx[1]=rand(); - dx[2]=rand();*/ +// unsigned short int dx[3]; /* variable needed by erand48(.) */ + +void initRand(void) /* a function to initialize dx using actual time */ +{ + struct tm s; + time_t t; + time(&t); + s = *localtime(&t); + srand(s.tm_sec * s.tm_min); + /* dx[0]=rand(); + dx[1]=rand(); + dx[2]=rand();*/ } - /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i, j, k; - int tag = 1; /* tape tag */ - int taskCount = 0; - - int pFW, pRV, pTR, degree, keep; /* forward/reverse parameters */ - int evalCount; /* # of evaluations */ - - - /****************************************************************************/ - /* READ CONTROL PARAMETERS FROM FILE */ - int controlParameters[cpCount]; - FILE* controlFile; + int i, j, k; + int tag = 1; /* tape tag */ + int taskCount = 0; + + int pFW, pRV, pTR, degree, keep; /* forward/reverse parameters */ + int evalCount; /* # of evaluations */ + + /****************************************************************************/ + /* READ CONTROL PARAMETERS FROM FILE */ + int controlParameters[cpCount]; + FILE *controlFile; + + /*------------------------------------------------------------------------*/ + /* open file to read */ + if ((controlFile = fopen(controlFileName, "r")) == NULL) { + fprintf(stdout, "ERROR: Could not open control file %s\n", controlFileName); + exit(-1); + } + + /*------------------------------------------------------------------------*/ + /* read all values */ + for (i = 0; i < cpCount; i++) + fscanf(controlFile, "%d%*[^\n]", &controlParameters[i]); + + indepDim = controlParameters[cpDimension]; + pFW = controlParameters[cpVecCountFW]; + pRV = controlParameters[cpVecCountRV]; + pTR = controlParameters[cpVecCountTR]; + degree = controlParameters[cpDegree]; + evalCount = controlParameters[cpAverageCount]; + + /*------------------------------------------------------------------------*/ + /* close control file */ + fclose(controlFile); + + /****************************************************************************/ + /* VARIABLES & INITIALIZATION */ + + /*------------------------------------------------------------------------*/ + /* Initialize all problem parameters (including dimension) */ + initProblemParameters(); + + /*------------------------------------------------------------------------*/ + /* Initialize the independent variables */ + double *indeps = new double[indepDim]; + initIndependents(indeps); + + /*------------------------------------------------------------------------*/ + /* Check main parameters */ + if (evalCount <= 0) { + fprintf(stdout, " # of evaluations to average over = ? "); + fscanf(stdin, "%d", &evalCount); + fprintf(stdout, "\n"); + } + + if ((degree <= 1) && + (controlParameters[cpHosFW] || controlParameters[cpHovFW] || + controlParameters[cpHosRV] || controlParameters[cpHovRV] || + controlParameters[cpTensor])) { + fprintf(stdout, " degree = ? "); + fscanf(stdin, "%d", °ree); + fprintf(stdout, "\n"); + } + keep = degree + 1; + + if ((pFW < 1) && (controlParameters[cpFovFW] || controlParameters[cpHovFW])) { + fprintf(stdout, " # of vectors in vector forward mode = ? "); + fscanf(stdin, "%d", &pFW); + fprintf(stdout, "\n"); + } + + if ((pRV < 1) && (controlParameters[cpFovRV] || controlParameters[cpHovRV])) { + fprintf(stdout, " # of vectors in vector reverse mode = ? "); + fscanf(stdin, "%d", &pRV); + fprintf(stdout, "\n"); + } + + if ((pTR < 1) && (controlParameters[cpTensor])) { + fprintf(stdout, " # of vectors in tensor mode = ? "); + fscanf(stdin, "%d", &pTR); + fprintf(stdout, "\n"); + } + + /*------------------------------------------------------------------------*/ + /* Necessary variable */ + double depOrig = 0.0, depTape; /* function value */ + double ***XPPP, **XPP; + double ***YPPP, **YPP, *YP; + double ***ZPPP, **ZPP, *ZP; + double *UP, u; + double *VP; + double *WP; + double *JP; + short **nzPP; + int retVal = 0; /* return value */ + double t00, t01, t02, t03; /* time values */ + double **TPP; + double **SPP; + double **HPP; + int dim; + + /****************************************************************************/ + /* NORMALIZE TIMER */ + + /****************************************************************************/ + /* 0. ORIGINAL FUNCTION EVALUATION */ + /* ---> always */ + fprintf(stdout, "\nTASK %d: Original function evaluation\n", taskCount++); + + t00 = myclock(); + for (i = 0; i < evalCount; i++) + depOrig = originalScalarFunction(indeps); + t01 = myclock(); + + double timeUnit; + if (t01 - t00) { + timeUnit = 1.0 / (t01 - t00); + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, 1.0, (t01 - t00) / evalCount); + } else { + fprintf(stdout, " !!! zero timing !!!\n"); + fprintf(stdout, " set time unit to 1.0\n"); + timeUnit = 1; + } + + /****************************************************************************/ + /* 1. TAPING THE FUNCTION */ + /* ---> always */ + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: Taping the function\n", taskCount++); + + t00 = myclock(); + /* NOTE: taping will be performed ONCE only */ + depTape = tapingScalarFunction(tag, indeps); + t01 = myclock(); + + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit * evalCount, (t01 - t00)); + + /****************************************************************************/ + /* 2. ZOS_FORWARD */ + if (controlParameters[cpZosFW]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: forward(tag, m=1, n=%d, keep, X[n], Y[m])\n", + taskCount++, indepDim); + fprintf(stdout, " ---> zos_forward\n"); + + /*----------------------------------------------------------------------*/ + /* NO KEEP */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, 1, indepDim, 0, indeps, &depTape); + t01 = myclock(); - /*------------------------------------------------------------------------*/ - /* open file to read */ - if ((controlFile = fopen(controlFileName,"r")) == NULL) { - fprintf(stdout,"ERROR: Could not open control file %s\n", - controlFileName); - exit(-1); + fprintf(stdout, " NO KEEP"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* KEEP */ + t02 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, 1, indepDim, 1, indeps, &depTape); + t03 = myclock(); + + fprintf(stdout, " KEEP "); + fprintf(stdout, TIMEFORMAT, (t03 - t02) * timeUnit, + (t03 - t02) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpZosFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + fprintf(stdout, " Should be the same values:\n"); + fprintf(stdout, " (original) %12.8E =? %12.8E (forward from tape)\n", + depOrig, depTape); } - - /*------------------------------------------------------------------------*/ - /* read all values */ - for (i=0; i fos_forward\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[2]; + XPP[i][0] = indeps[i]; + XPP[i][1] = (double)rand(); } + YP = new double[2]; + + /*----------------------------------------------------------------------*/ + /* NO KEEP */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, 1, indepDim, 1, 0, XPP, YP); + t01 = myclock(); - if ((degree <= 1) && - (controlParameters[cpHosFW] || controlParameters[cpHovFW] || - controlParameters[cpHosRV] || controlParameters[cpHovRV] || - controlParameters[cpTensor])) { - fprintf(stdout," degree = ? "); - fscanf(stdin,"%d",°ree); - fprintf(stdout,"\n"); + fprintf(stdout, " NO KEEP"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* KEEP */ + t02 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, 1, indepDim, 1, 2, XPP, YP); + t03 = myclock(); + + fprintf(stdout, " KEEP "); + fprintf(stdout, TIMEFORMAT, (t03 - t02) * timeUnit, + (t03 - t02) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpFosFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + fprintf(stdout, " Should be the same values:\n"); + fprintf(stdout, " (original) %12.8E =? %12.8E (forward from tape)\n", + depOrig, YP[0]); } - keep = degree + 1; - if ((pFW < 1) && - (controlParameters[cpFovFW] || controlParameters[cpHovFW])) { - fprintf(stdout," # of vectors in vector forward mode = ? "); - fscanf(stdin,"%d",&pFW); - fprintf(stdout,"\n"); + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) + delete[] XPP[i]; + delete[] XPP; + delete[] YP; + } + + /****************************************************************************/ + /* 4. HOS_FORWARD */ + if (controlParameters[cpHosFW]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf( + stdout, + "\nTASK %d: forward(tag, m=1, n=%d, d=%d, keep, X[n][d+1], Y[d+1])\n", + taskCount++, indepDim, degree); + fprintf(stdout, " ---> hos_forward\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[1 + degree]; + XPP[i][0] = indeps[i]; + for (j = 1; j <= degree; j++) + XPP[i][j] = (double)rand(); } + YP = new double[1 + degree]; - if ((pRV < 1) && - (controlParameters[cpFovRV] || controlParameters[cpHovRV])) { - fprintf(stdout," # of vectors in vector reverse mode = ? "); - fscanf(stdin,"%d",&pRV); - fprintf(stdout,"\n"); + /*----------------------------------------------------------------------*/ + /* NO KEEP */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, 1, indepDim, degree, 0, XPP, YP); + t01 = myclock(); + + fprintf(stdout, " NO KEEP"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* KEEP */ + t02 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, 1, indepDim, degree, keep, XPP, YP); + t03 = myclock(); + + fprintf(stdout, " KEEP "); + fprintf(stdout, TIMEFORMAT, (t03 - t02) * timeUnit, + (t03 - t02) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpHosFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + fprintf(stdout, " Should be the same values:\n"); + fprintf(stdout, " (original) %12.8E =? %12.8E (forward from tape)\n", + depOrig, YP[0]); } - if ((pTR < 1) && - (controlParameters[cpTensor])) { - fprintf(stdout," # of vectors in tensor mode = ? "); - fscanf(stdin,"%d",&pTR); - fprintf(stdout,"\n"); + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) + delete[] XPP[i]; + delete[] XPP; + delete[] YP; + } + + /****************************************************************************/ + /* 5. FOV_FORWARD */ + if (controlParameters[cpFovFW]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: forward(tag, m=1, n=%d, p=%d, x[n], X[n][p], y[m], " + "Y[m][p])\n", + taskCount++, indepDim, pFW); + fprintf(stdout, " ---> fov_forward\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[pFW]; + for (j = 0; j < pFW; j++) + XPP[i][j] = (double)rand(); } + YP = new double[1]; + YPP = new double *[1]; + YPP[0] = new double[pFW]; - /*------------------------------------------------------------------------*/ - /* Necessary variable */ - double depOrig=0.0, depTape; /* function value */ - double ***XPPP, **XPP; - double ***YPPP, **YPP, *YP; - double ***ZPPP, **ZPP, *ZP; - double *UP, u; - double *VP; - double *WP; - double *JP; - short **nzPP; - int retVal=0; /* return value */ - double t00, t01, t02, t03; /* time values */ - double **TPP; - double **SPP; - double **HPP; - int dim; + /*----------------------------------------------------------------------*/ + /* always NO KEEP */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, 1, indepDim, pFW, indeps, XPP, YP, YPP); + t01 = myclock(); + fprintf(stdout, " (NO KEEP)"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* NORMALIZE TIMER */ + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpFovFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) + delete[] XPP[i]; + delete[] XPP; + delete[] YP; + delete[] YPP[0]; + delete[] YPP; + } + + /****************************************************************************/ + /* 6. HOV_FORWARD */ + if (controlParameters[cpHovFW]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: forward(tag, m=1, n=%d, d=%d, p=%d, x[n], X[n][p][d], " + "y[m], Y[m][p][d])\n", + taskCount++, indepDim, degree, pFW); + fprintf(stdout, " ---> hov_forward\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + XPPP = new double **[indepDim]; + for (i = 0; i < indepDim; i++) { + XPPP[i] = new double *[pFW]; + for (j = 0; j < pFW; j++) { + XPPP[i][j] = new double[degree]; + for (k = 0; k < degree; k++) + XPPP[i][j][k] = (double)rand(); + } + } + YP = new double[1]; + YPPP = new double **[1]; + YPPP[0] = new double *[pFW]; + for (j = 0; j < pFW; j++) + YPPP[0][j] = new double[degree]; + + /*----------------------------------------------------------------------*/ + /* always NO KEEP */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, 1, indepDim, degree, pFW, indeps, XPPP, YP, YPPP); + t01 = myclock(); + fprintf(stdout, " (NO KEEP)"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 0. ORIGINAL FUNCTION EVALUATION */ - /* ---> always */ - fprintf(stdout,"\nTASK %d: Original function evaluation\n", - taskCount++); + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpHovFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) { + for (j = 0; j < pFW; j++) + delete[] XPPP[i][j]; + delete[] XPPP[i]; + } + delete[] XPPP; + delete[] YP; + for (j = 0; j < pFW; j++) + delete[] YPPP[0][j]; + delete[] YPPP[0]; + delete[] YPPP; + } + + /****************************************************************************/ + /* 7. FOS_REVERSE */ + if (controlParameters[cpFosRV]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: reverse(tag, m=1, n=%d, d=0, u, Z[n])\n", + taskCount++, indepDim); + fprintf(stdout, " ---> fos_reverse\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + ZP = new double[indepDim]; + u = (double)rand(); + + /*----------------------------------------------------------------------*/ + /* Forward with keep*/ + forward(tag, 1, indepDim, 1, indeps, &depTape); + + /*----------------------------------------------------------------------*/ + /* Reverse */ t00 = myclock(); - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] ZP; + } + + /****************************************************************************/ + /* 8. HOS_REVERSE */ + if (controlParameters[cpHosRV]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: reverse(tag, m=1, n=%d, d=%d, u, Z[n][d+1])\n", + taskCount++, indepDim, degree); + fprintf(stdout, " ---> hos_reverse\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + ZPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) + ZPP[i] = new double[degree + 1]; + u = (double)rand(); + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[1 + degree]; + XPP[i][0] = indeps[i]; + for (j = 1; j <= degree; j++) + XPP[i][j] = (double)rand(); + } + YP = new double[1 + degree]; - /****************************************************************************/ - /* 1. TAPING THE FUNCTION */ - /* ---> always */ - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: Taping the function\n", - taskCount++); + /*----------------------------------------------------------------------*/ + /* Forward with keep*/ + forward(tag, 1, indepDim, degree, keep, XPP, YP); + /*----------------------------------------------------------------------*/ + /* Reverse */ t00 = myclock(); - /* NOTE: taping will be performed ONCE only */ - depTape = tapingScalarFunction(tag,indeps); + for (i = 0; i < evalCount; i++) + retVal = reverse(tag, 1, indepDim, degree, u, ZPP); t01 = myclock(); - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - fprintf(stdout," "); - fprintf(stdout,TIMEFORMAT,(t01-t00)*timeUnit*evalCount, - (t01-t00)); - - /****************************************************************************/ - /* 2. ZOS_FORWARD */ - if (controlParameters[cpZosFW]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forward(tag, m=1, n=%d, keep, X[n], Y[m])\n", - taskCount++,indepDim); - fprintf(stdout," ---> zos_forward\n"); - - /*----------------------------------------------------------------------*/ - /* NO KEEP */ - t00 = myclock(); - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - fprintf(stdout," Should be the same values:\n"); - fprintf(stdout," (original) %12.8E =? %12.8E (forward from tape)\n", - depOrig,depTape); - } + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpHosRV] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) + delete[] ZPP[i]; + delete[] ZPP; + for (i = 0; i < indepDim; i++) + delete[] XPP[i]; + delete[] XPP; + delete[] YP; + } + + /****************************************************************************/ + /* 9. FOV_REVERSE */ + if (controlParameters[cpFovRV]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: reverse(tag, m=1, n=%d, d=0, p=%d, U[p], Z[p][n])\n", + taskCount++, indepDim, pRV); + fprintf(stdout, " ---> fov_reverse\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + ZPP = new double *[pRV]; + for (i = 0; i < pRV; i++) + ZPP[i] = new double[indepDim]; + UP = new double[pRV]; + for (i = 0; i < pRV; i++) + UP[i] = (double)rand(); + + /*----------------------------------------------------------------------*/ + /* Forward with keep*/ + forward(tag, 1, indepDim, 1, indeps, &depTape); + + /*----------------------------------------------------------------------*/ + /* Reverse */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = reverse(tag, 1, indepDim, 0, pRV, UP, ZPP); + t01 = myclock(); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 3. FOS_FORWARD */ - if (controlParameters[cpFosFW]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forward(tag, m=1, n=%d, d=1, keep, X[n][d+1], Y[d+1])\n", - taskCount++,indepDim); - fprintf(stdout," ---> fos_forward\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - XPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - fprintf(stdout," Should be the same values:\n"); - fprintf(stdout," (original) %12.8E =? %12.8E (forward from tape)\n", - depOrig,YP[0]); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } - - /****************************************************************************/ - /* 4. HOS_FORWARD */ - if (controlParameters[cpHosFW]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forward(tag, m=1, n=%d, d=%d, keep, X[n][d+1], Y[d+1])\n", - taskCount++,indepDim,degree); - fprintf(stdout," ---> hos_forward\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - XPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - fprintf(stdout," Should be the same values:\n"); - fprintf(stdout," (original) %12.8E =? %12.8E (forward from tape)\n", - depOrig,YP[0]); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i hov_reverse\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + ZPPP = new double **[pRV]; + for (i = 0; i < pRV; i++) { + ZPPP[i] = new double *[indepDim]; + for (j = 0; j < indepDim; j++) + ZPPP[i][j] = new double[degree + 1]; } + UP = new double[pRV]; + for (i = 0; i < pRV; i++) + UP[i] = (double)rand(); + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[1 + degree]; + XPP[i][0] = indeps[i]; + for (j = 1; j <= degree; j++) + XPP[i][j] = (double)rand(); + } + YP = new double[1 + degree]; + nzPP = new short *[pRV]; + for (i = 0; i < pRV; i++) + nzPP[i] = new short[indepDim]; + /*----------------------------------------------------------------------*/ + /* Forward with keep*/ + forward(tag, 1, indepDim, degree, keep, XPP, YP); - /****************************************************************************/ - /* 5. FOV_FORWARD */ - if (controlParameters[cpFovFW]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forward(tag, m=1, n=%d, p=%d, x[n], X[n][p], y[m], Y[m][p])\n", - taskCount++,indepDim,pFW); - fprintf(stdout," ---> fov_forward\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - XPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i hov_forward\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - XPPP = new double**[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i fos_reverse\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - ZP = new double[indepDim]; - u = (double)rand(); - - /*----------------------------------------------------------------------*/ - /* Forward with keep*/ - forward(tag,1,indepDim,1,indeps,&depTape); - - /*----------------------------------------------------------------------*/ - /* Reverse */ - t00 = myclock(); - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] ZP; + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpHovRV] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < pRV; i++) { + for (j = 0; j < indepDim; j++) + delete[] ZPPP[i][j]; + delete[] ZPPP[i]; + delete[] nzPP[i]; + } + delete[] ZPPP; + delete[] nzPP; + delete[] UP; + for (i = 0; i < indepDim; i++) + delete[] XPP[i]; + delete[] XPP; + delete[] YP; + } + + /****************************************************************************/ + /* 11. FUNCTION */ + if (controlParameters[cpFunction]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: function(tag, m=1, n=%d, X[n], Y[m])\n", + taskCount++, indepDim); + + /*----------------------------------------------------------------------*/ + /* Function evaluation */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = function(tag, 1, indepDim, indeps, &depTape); + t01 = myclock(); - /****************************************************************************/ - /* 8. HOS_REVERSE */ - if (controlParameters[cpHosRV]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: reverse(tag, m=1, n=%d, d=%d, u, Z[n][d+1])\n", - taskCount++,indepDim,degree); - fprintf(stdout," ---> hos_reverse\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - ZPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + fprintf(stdout, " Should be the same values:\n"); + fprintf(stdout, " (original) %12.8E =? %12.8E (forward from tape)\n", + depOrig, depTape); } + } + /****************************************************************************/ + /* 12. JACOBIAN */ + if (controlParameters[cpJacobian]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: gradient(tag, n=%d, X[n], G[n])\n", taskCount++, + indepDim); - /****************************************************************************/ - /* 9. FOV_REVERSE */ - if (controlParameters[cpFovRV]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: reverse(tag, m=1, n=%d, d=0, p=%d, U[p], Z[p][n])\n", - taskCount++,indepDim,pRV); - fprintf(stdout," ---> fov_reverse\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - ZPP = new double*[pRV]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i hov_reverse\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - ZPPP = new double**[pRV]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] JP; + } + + /****************************************************************************/ + /* 13. VECJAC */ + if (controlParameters[cpVecJac]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: vec_jac(tag, m=1, n=%d, repeat, X[n], U[m], V[n])\n", + taskCount++, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + UP = new double[1]; + UP[0] = (double)rand(); + VP = new double[indepDim]; + + /*----------------------------------------------------------------------*/ + /* Evaluation without repeat */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = vec_jac(tag, 1, indepDim, 0, indeps, UP, VP); + t01 = myclock(); - /****************************************************************************/ - /* 11. FUNCTION */ - if (controlParameters[cpFunction]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: function(tag, m=1, n=%d, X[n], Y[m])\n", - taskCount++,indepDim); - - /*----------------------------------------------------------------------*/ - /* Function evaluation */ - t00 = myclock(); - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - fprintf(stdout," Should be the same values:\n"); - fprintf(stdout," (original) %12.8E =? %12.8E (forward from tape)\n", - depOrig,depTape); - } - } + fprintf(stdout, "(no repeat)"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + /*----------------------------------------------------------------------*/ + /* Evaluation with repeat */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = vec_jac(tag, 1, indepDim, 1, indeps, UP, VP); + t01 = myclock(); + + fprintf(stdout, " (repeat)"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 12. JACOBIAN */ - if (controlParameters[cpJacobian]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: gradient(tag, n=%d, X[n], G[n])\n", - taskCount++,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - JP = new double[indepDim]; - - /*----------------------------------------------------------------------*/ - /* Gradient evaluation */ - t00 = myclock(); - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] JP; + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpVecJac] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] UP; + delete[] VP; + } + + /****************************************************************************/ + /* 14. JACVEC */ + if (controlParameters[cpJacVec]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: jac_vec(tag, m=1, n=%d, X[n], V[n], U[m])\n", + taskCount++, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + UP = new double[1]; + VP = new double[indepDim]; + for (i = 0; i < indepDim; i++) + VP[i] = (double)rand(); + + /*----------------------------------------------------------------------*/ + /* Evaluation */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = jac_vec(tag, 1, indepDim, indeps, VP, UP); + t01 = myclock(); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 13. VECJAC */ - if (controlParameters[cpVecJac]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: vec_jac(tag, m=1, n=%d, repeat, X[n], U[m], V[n])\n", - taskCount++,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - UP = new double[1]; - UP[0] = (double)rand(); - VP = new double[indepDim]; - - /*----------------------------------------------------------------------*/ - /* Evaluation without repeat */ - t00 = myclock(); - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] UP; - delete[] VP; + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpJacVec] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] UP; + delete[] VP; + } + + /****************************************************************************/ + /* 15. HESSIAN */ + if (controlParameters[cpHessian]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: hessian(tag, n=%d, X[n], lower triangle of H[n][n])\n", + taskCount++, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + HPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) + HPP[i] = new double[indepDim]; + + /*----------------------------------------------------------------------*/ + /* Evaluation */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = hessian(tag, indepDim, indeps, HPP); + t01 = myclock(); - /****************************************************************************/ - /* 14. JACVEC */ - if (controlParameters[cpJacVec]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: jac_vec(tag, m=1, n=%d, X[n], V[n], U[m])\n", - taskCount++,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - UP = new double[1]; - VP = new double[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] UP; - delete[] VP; + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpHessian] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) + delete[] HPP[i]; + delete[] HPP; + } + + /****************************************************************************/ + /* 16. HESSVEC */ + if (controlParameters[cpHessVec]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: hess_vec(tag, n=%d, X[n], V[n], W[n])\n", + taskCount++, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + VP = new double[indepDim]; + for (i = 0; i < indepDim; i++) + VP[i] = (double)rand(); + WP = new double[indepDim]; + + /*----------------------------------------------------------------------*/ + /* Evaluation */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = hess_vec(tag, indepDim, indeps, VP, WP); + t01 = myclock(); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 15. HESSIAN */ - if (controlParameters[cpHessian]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: hessian(tag, n=%d, X[n], lower triangle of H[n][n])\n", - taskCount++,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - HPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] VP; + delete[] WP; + } + + /****************************************************************************/ + /* 17. LAGHESSVEC */ + if (controlParameters[cpLagHessVec]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf( + stdout, + "\nTASK %d: lagra_hess_vec(tag, m=1, n=%d, X[n], U[m], V[n], W[n])\n", + taskCount++, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + UP = new double[1]; + UP[0] = (double)rand(); + VP = new double[indepDim]; + for (i = 0; i < indepDim; i++) + VP[i] = (double)rand(); + WP = new double[indepDim]; + + /*----------------------------------------------------------------------*/ + /* Evaluation */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = lagra_hess_vec(tag, 1, indepDim, indeps, UP, VP, WP); + t01 = myclock(); - /****************************************************************************/ - /* 16. HESSVEC */ - if (controlParameters[cpHessVec]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: hess_vec(tag, n=%d, X[n], V[n], W[n])\n", - taskCount++,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - VP = new double[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] VP; - delete[] WP; - } + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpLagHessVec] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + } - /****************************************************************************/ - /* 17. LAGHESSVEC */ - if (controlParameters[cpLagHessVec]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: lagra_hess_vec(tag, m=1, n=%d, X[n], U[m], V[n], W[n])\n", - taskCount++,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - UP = new double[1]; - UP[0] = (double)rand(); - VP = new double[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] VP; - delete[] WP; - delete[] UP; + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] VP; + delete[] WP; + delete[] UP; + } + + /****************************************************************************/ + /* 18. TENSOR */ + if (controlParameters[cpTensor]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: tensor_eval(tag, m =1, n=%d, d=%d, p=%d, X[n], " + "tensor[m][dim], S[n][p])\n", + taskCount++, indepDim, degree, pTR); + fprintf(stdout, "\n dim = ((p+d) over d)\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + dim = binomi(pTR + degree, degree); + TPP = new double *[1]; + TPP[0] = new double[dim]; + SPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + SPP[i] = new double[pTR]; + for (j = 0; j < pTR; j++) + SPP[i][j] = (i == j) ? 1.0 : 0.0; } + /*----------------------------------------------------------------------*/ + /* tensor evaluation */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + tensor_eval(tag, 1, indepDim, degree, pTR, indeps, TPP, SPP); + t01 = myclock(); - /****************************************************************************/ - /* 18. TENSOR */ - if (controlParameters[cpTensor]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: tensor_eval(tag, m =1, n=%d, d=%d, p=%d, X[n], tensor[m][dim], S[n][p])\n", - taskCount++,indepDim,degree, pTR); - fprintf(stdout,"\n dim = ((p+d) over d)\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - dim = binomi(pTR+degree,degree); - TPP = new double*[1]; - TPP[0] = new double[dim]; - SPP = new double*[indepDim]; - for (i=0; i 1) {} - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] TPP[0]; - delete[] TPP; - for (i=0; i 1) { } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] TPP[0]; + delete[] TPP; + for (i = 0; i < indepDim; i++) + delete[] SPP[i]; + delete[] SPP; + } + + /****************************************************************************/ + /* 19. INVERSE TENSOR */ + if (controlParameters[cpInvTensor] && (1 == indepDim)) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: inverse_tensor_eval(tag, m=n=1, d=%d, p=%d, X[n], " + "tensor[m][dim], S[n][p])\n", + taskCount++, degree, pTR); + fprintf(stdout, "\n dim = ((p+d) over d)\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + dim = binomi(pTR + degree, degree); + TPP = new double *[1]; + TPP[0] = new double[dim]; + SPP = new double *[1]; + SPP[0] = new double[pTR]; + for (j = 0; j < pTR; j++) + SPP[0][j] = (0 == j) ? 1.0 : 0.0; + + /*----------------------------------------------------------------------*/ + /* tensor evaluation */ + t00 = myclock(); + for (i = 0; i < evalCount; i++) + inverse_tensor_eval(tag, 1, degree, pTR, indeps, TPP, SPP); + t01 = myclock(); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 19. INVERSE TENSOR */ - if (controlParameters[cpInvTensor] && (1==indepDim)) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: inverse_tensor_eval(tag, m=n=1, d=%d, p=%d, X[n], tensor[m][dim], S[n][p])\n", - taskCount++,degree, pTR); - fprintf(stdout,"\n dim = ((p+d) over d)\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - dim = binomi(pTR+degree,degree); - TPP = new double*[1]; - TPP[0] = new double[dim]; - SPP = new double*[1]; - SPP[0] = new double[pTR]; - for (j=0; j 1) {} - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] TPP[0]; - delete[] TPP; - delete[] SPP[0]; - delete[] SPP; + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpInvTensor] > 1) { } - return 1; + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] TPP[0]; + delete[] TPP; + delete[] SPP[0]; + delete[] SPP; + } + + return 1; } #undef _SGENMAIN_C_ - - diff --git a/ADOL-C/examples/additional_examples/timing/vfunc_gear.cpp b/ADOL-C/examples/additional_examples/timing/vfunc_gear.cpp index 2dd1bec5e..3320814e6 100644 --- a/ADOL-C/examples/additional_examples/timing/vfunc_gear.cpp +++ b/ADOL-C/examples/additional_examples/timing/vfunc_gear.cpp @@ -4,24 +4,24 @@ Revision: $Id$ Contents: Example of function module containing the machine tool example of gearing - + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indeps ) (6) void originalVectorFunction( double* indeps, double* deps ) - (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _VFUNC_GEAR_C_ @@ -30,16 +30,15 @@ #include #include -#include #include - +#include /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "gearexam.ctrl"; +const char *controlFileName = "gearexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -48,38 +47,35 @@ int depDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ -//static unsigned short int dx[3]; /* variable needed by erand48(.) */ - +// static unsigned short int dx[3]; /* variable needed by erand48(.) */ /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"GEAREXAM (ADOL-C Example)\n\n"); - - /* number of indeps & deps */ - indepDim = 3; - depDim = 3; - - /* Init erand48(); */ - struct tm s; - time_t t; - time(&t); - s=*localtime(&t); - srand(s.tm_sec*s.tm_min); - /* dx[0]=rand(); - dx[1]=rand(); - dx[2]=rand();*/ +void initProblemParameters(void) { + fprintf(stdout, "GEAREXAM (ADOL-C Example)\n\n"); + + /* number of indeps & deps */ + indepDim = 3; + depDim = 3; + + /* Init erand48(); */ + struct tm s; + time_t t; + time(&t); + s = *localtime(&t); + srand(s.tm_sec * s.tm_min); + /* dx[0]=rand(); + dx[1]=rand(); + dx[2]=rand();*/ } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - for (int i=0; i>= *iP++; - trace_off(); +void tapingVectorFunction(int tag, double *indeps, double *deps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *activeDeps = new adouble[depDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + activeGearFunction(activeIndeps, activeDeps); + aIP = activeDeps; + iP = deps; + for (i = 0; i < depDim; i++) + *aIP++ >>= *iP++; + trace_off(); } #undef _VFUNC_GEAR_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/vfunc_pargear.cpp b/ADOL-C/examples/additional_examples/timing/vfunc_pargear.cpp index baac862b0..5e0bfc3ee 100644 --- a/ADOL-C/examples/additional_examples/timing/vfunc_pargear.cpp +++ b/ADOL-C/examples/additional_examples/timing/vfunc_pargear.cpp @@ -4,37 +4,35 @@ Revision: $Id$ Contents: Example of function module containing the machine tool example of gearing (parametrized version) - + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indeps ) (6) void originalVectorFunction( double* indeps, double* deps ) - (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _VFUNC_PARGEAR_C_ - /****************************************************************************/ /* INCLUDES */ -#include #include "rotations.h" +#include #include -#include #include - +#include /****************************************************************************/ /* GLOBAL VARIABLES */ @@ -42,7 +40,7 @@ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "pargearexam.ctrl"; +const char *controlFileName = "pargearexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -55,109 +53,104 @@ int helMotDegree; int angMotDegree; int modRolDegree; - /*--------------------------------------------------------------------------*/ /* important machine tool parameters */ // example bet06-23 convex pinion flank -int konvex= 1; // konvexe oder konkave Flanke -int zz= 6; // Zaehnezahl - -double xmk= -17.50195; // Messerversatz -double ymk= 80.0; // MK-Versatz -double kopspw= 0.0; // Kopfspanwinkel -double flaspw= 0.0; // Flankenspanwinkel -double meschw= 0.0; // Messerschwenkwinkel -double flkrrd= 101.44158; // Spitzenradius, Flugkreisr. -double e= 0.0; // MK-Exzentrizitaet -double exzenw= 0.0; // Exzentrizitaetswinkel -double thetas= 0.0; // Messerkopfschwenkung -double thetan= 0.0; // Messerkopfneigung -double xmw= 24.63350; // MK-x -double ymw= -73.69500; // MK-y -double zmw= 96.15919; // MK-z -double thetaw=-314.52420; // Wiegenwinkel=Waelztrommelwinkel -double m= 0.0; // Erzeugungs-Achsversatz -double zwr= 0.0; // Verschiebung Werkradachse -double delta= 14.62090; // Kegelwinkel -double omega= 0.0; -double c= 0.0; -double r= 2.1; // Kopfradius -double rs= 2594.425; // Sphaerikradius -double ys= 876.147; // Sphaerik-Mitte-Y -double zs= -2442.015; // Sphaerik-Mitte-Z +int konvex = 1; // konvexe oder konkave Flanke +int zz = 6; // Zaehnezahl + +double xmk = -17.50195; // Messerversatz +double ymk = 80.0; // MK-Versatz +double kopspw = 0.0; // Kopfspanwinkel +double flaspw = 0.0; // Flankenspanwinkel +double meschw = 0.0; // Messerschwenkwinkel +double flkrrd = 101.44158; // Spitzenradius, Flugkreisr. +double e = 0.0; // MK-Exzentrizitaet +double exzenw = 0.0; // Exzentrizitaetswinkel +double thetas = 0.0; // Messerkopfschwenkung +double thetan = 0.0; // Messerkopfneigung +double xmw = 24.63350; // MK-x +double ymw = -73.69500; // MK-y +double zmw = 96.15919; // MK-z +double thetaw = -314.52420; // Wiegenwinkel=Waelztrommelwinkel +double m = 0.0; // Erzeugungs-Achsversatz +double zwr = 0.0; // Verschiebung Werkradachse +double delta = 14.62090; // Kegelwinkel +double omega = 0.0; +double c = 0.0; +double r = 2.1; // Kopfradius +double rs = 2594.425; // Sphaerikradius +double ys = 876.147; // Sphaerik-Mitte-Y +double zs = -2442.015; // Sphaerik-Mitte-Z /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ -//static unsigned short int dx[3]; /* variable needed by erand48(.) */ - +// static unsigned short int dx[3]; /* variable needed by erand48(.) */ /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"PARGEAREXAM (ADOL-C Example)\n\n"); - - /* number of indeps & deps */ - depDim = 3; - indepDim = 3; - - fprintf(stdout," Radial motion degree = ? [-1=no polynomial,0,...,6]"); - fscanf(stdin,"%d",&radMotDegree); - fprintf(stdout,"\n"); - if (radMotDegree>=0) - indepDim += radMotDegree + 1; - - fprintf(stdout," Vertical motion degree = ? "); - fscanf(stdin,"%d",&verMotDegree); - fprintf(stdout,"\n"); - if (verMotDegree>=0) - indepDim += verMotDegree + 1; - - fprintf(stdout," Horizontal motion degree = ? "); - fscanf(stdin,"%d",&horMotDegree); - fprintf(stdout,"\n"); - if (horMotDegree>=0) - indepDim += horMotDegree + 1; - - fprintf(stdout," Helical motion degree = ? "); - fscanf(stdin,"%d",&helMotDegree); - fprintf(stdout,"\n"); - if (helMotDegree>=0) - indepDim += helMotDegree + 1; - - fprintf(stdout," Angular motion degree = ? "); - fscanf(stdin,"%d",&angMotDegree); - fprintf(stdout,"\n"); - if (angMotDegree>=0) - indepDim += angMotDegree + 1; - - fprintf(stdout," Modified roll degree = ? "); - fscanf(stdin,"%d",&modRolDegree); - fprintf(stdout,"\n"); - if (modRolDegree>=0) - indepDim += modRolDegree + 1; - - /* Init erand48(); */ - struct tm s; - time_t t; - time(&t); - s=*localtime(&t); - srand(s.tm_sec*s.tm_min); - /* dx[0]=rand(); - dx[1]=rand(); - dx[2]=rand();*/ +void initProblemParameters(void) { + fprintf(stdout, "PARGEAREXAM (ADOL-C Example)\n\n"); + + /* number of indeps & deps */ + depDim = 3; + indepDim = 3; + + fprintf(stdout, " Radial motion degree = ? [-1=no polynomial,0,...,6]"); + fscanf(stdin, "%d", &radMotDegree); + fprintf(stdout, "\n"); + if (radMotDegree >= 0) + indepDim += radMotDegree + 1; + + fprintf(stdout, " Vertical motion degree = ? "); + fscanf(stdin, "%d", &verMotDegree); + fprintf(stdout, "\n"); + if (verMotDegree >= 0) + indepDim += verMotDegree + 1; + + fprintf(stdout, " Horizontal motion degree = ? "); + fscanf(stdin, "%d", &horMotDegree); + fprintf(stdout, "\n"); + if (horMotDegree >= 0) + indepDim += horMotDegree + 1; + + fprintf(stdout, " Helical motion degree = ? "); + fscanf(stdin, "%d", &helMotDegree); + fprintf(stdout, "\n"); + if (helMotDegree >= 0) + indepDim += helMotDegree + 1; + + fprintf(stdout, " Angular motion degree = ? "); + fscanf(stdin, "%d", &angMotDegree); + fprintf(stdout, "\n"); + if (angMotDegree >= 0) + indepDim += angMotDegree + 1; + + fprintf(stdout, " Modified roll degree = ? "); + fscanf(stdin, "%d", &modRolDegree); + fprintf(stdout, "\n"); + if (modRolDegree >= 0) + indepDim += modRolDegree + 1; + + /* Init erand48(); */ + struct tm s; + time_t t; + time(&t); + s = *localtime(&t); + srand(s.tm_sec * s.tm_min); + /* dx[0]=rand(); + dx[1]=rand(); + dx[2]=rand();*/ } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - for (int i=0; i (-xNeu) - f[1] += hgZmw; // FLB1-z-Achse zeigt nach rechts -> (yNeu) - f[2] += hgYmw; // FLB1-y-Achse zeigt aus der Wiege -> (zNeu) - - // Wiegenwinkel thetaW, entspricht dem wert t=0 - D3(f,hgThetaW); - - // ZUSATZBEWEGUNG Radial motion - if (radialMotionDegree >= 0) { - ah = 0.0; - for (i=radialMotionDegree; i>0; i--) { - ah += radialMotionCoeff[i]; - ah *= z[2]; - } - ah += radialMotionCoeff[0]; - f[1] += ah; // radiale Verschiebung des Messerkopfes + int radialMotionDegree, double *radialMotionCoeff, int verticalMotionDegree, + double *verticalMotionCoeff, int horizontalMotionDegree, + double *horizontalMotionCoeff, int helicalMotionDegree, + double *helicalMotionCoeff, int angularMotionDegree, + double *angularMotionCoeff, int modifiedRollDegree, + double *modifiedRollCoeff) { + int i; + double ah; // Hilfswert + + // Definition der Schneide + def_messer(z, f, hgR, hgRs, hgYs, hgZs); + + // Position der Schneide am Messerkopf + // (jetzt die Ber"ucksichtigung von hgKopSpW, hgFlaSpW, hgMeSchW) + D2T(f, hgMeSchW); // Messerschwenkwinkel Theta_M + D3T(f, hgFlaSpW); // Flankenspanwinkel Theta_F + D1(f, hgKopSpW); // Kopfspanwinkel Theta_K + // Position der Schneide am Messerkopf + f[0] += hgFlKrRd; // Flugkreisradius + f[1] -= hgXmk; // Messerversatz + + // Messerkopfrotation mit Parameter v + D3(f, z[1]); + + // Lage des Messerkopfs auf der Wiege + f[2] -= hgYmk; + + // Beruecksichtigung der Messerkopf-Exzentrizitaet + f[0] += hgE * cos(hgExzenW); + f[1] -= hgE * sin(hgExzenW); + + // Eindrehen in Orientierung der Wiege + ah = f[0]; + f[0] = f[1]; + f[1] = ah; + f[2] = -f[2]; + + // Beruecksichtigung von Messerkopf-Schwenkwinkel hgThetaS + // und der Messerkopfneigung hgThetaN + D3T(f, hgThetaS); // Einschwenken in die Neigungsachse + D1T(f, hgThetaN); // Neigung um x-Achse + D3(f, hgThetaS); // Rueckschwenken aus der Neigungsachse + + // Verschiebung + f[0] -= hgXmw; // FLB1-x-Achse zeigt nach oben -> (-xNeu) + f[1] += hgZmw; // FLB1-z-Achse zeigt nach rechts -> (yNeu) + f[2] += hgYmw; // FLB1-y-Achse zeigt aus der Wiege -> (zNeu) + + // Wiegenwinkel thetaW, entspricht dem wert t=0 + D3(f, hgThetaW); + + // ZUSATZBEWEGUNG Radial motion + if (radialMotionDegree >= 0) { + ah = 0.0; + for (i = radialMotionDegree; i > 0; i--) { + ah += radialMotionCoeff[i]; + ah *= z[2]; } - - // Wiegenbewegung mit Parameter t - D3(f,z[2]); - - // ZUSATZBEWEGUNG Vertical motion - if (verticalMotionDegree >= 0) { - ah = 0.0; - for (i=verticalMotionDegree; i>0; i--) { - ah += verticalMotionCoeff[i]; - ah *= z[2]; - } - ah += verticalMotionCoeff[0]; - f[0] += ah; // Achsversatz in positive x-Richtung + ah += radialMotionCoeff[0]; + f[1] += ah; // radiale Verschiebung des Messerkopfes + } + + // Wiegenbewegung mit Parameter t + D3(f, z[2]); + + // ZUSATZBEWEGUNG Vertical motion + if (verticalMotionDegree >= 0) { + ah = 0.0; + for (i = verticalMotionDegree; i > 0; i--) { + ah += verticalMotionCoeff[i]; + ah *= z[2]; } - - // originaler Achsversatz - f[0] += hgM; - - // ZUSATZBEWEGUNG Horizontal motion - if (horizontalMotionDegree >= 0) { - ah = 0.0; - for (i=horizontalMotionDegree; i>0; i--) { - ah += horizontalMotionCoeff[i]; - ah *= z[2]; - } - ah += horizontalMotionCoeff[0]; - f[1] += ah; // Achsversatz in positive y-Richtung + ah += verticalMotionCoeff[0]; + f[0] += ah; // Achsversatz in positive x-Richtung + } + + // originaler Achsversatz + f[0] += hgM; + + // ZUSATZBEWEGUNG Horizontal motion + if (horizontalMotionDegree >= 0) { + ah = 0.0; + for (i = horizontalMotionDegree; i > 0; i--) { + ah += horizontalMotionCoeff[i]; + ah *= z[2]; } - - // ZUSATZBEWEGUNG Helical motion - if (helicalMotionDegree >= 0) { - ah = 0.0; - for (i=helicalMotionDegree; i>0; i--) { - ah += helicalMotionCoeff[i]; - ah *= z[2]; - } - ah += helicalMotionCoeff[0]; - f[2] -= ah; // Tiefenposition in negative z-Richtung + ah += horizontalMotionCoeff[0]; + f[1] += ah; // Achsversatz in positive y-Richtung + } + + // ZUSATZBEWEGUNG Helical motion + if (helicalMotionDegree >= 0) { + ah = 0.0; + for (i = helicalMotionDegree; i > 0; i--) { + ah += helicalMotionCoeff[i]; + ah *= z[2]; } - - // Eindrehen in Orientierung des Werkrades - f[0] = -f[0]; - ah = f[1]; - f[1] = -f[2]; - f[2] = -ah; - - // ZUSATZBEWEGUNG Angular motion - if (angularMotionDegree >= 0) { - ah = 0.0; - for (i=angularMotionDegree; i>0; i--) { - ah += angularMotionCoeff[i]; - ah *= z[2]; - } - ah += angularMotionCoeff[0]; - D1(f,ah); // umgekehrte Drehung um die x-Achse + ah += helicalMotionCoeff[0]; + f[2] -= ah; // Tiefenposition in negative z-Richtung + } + + // Eindrehen in Orientierung des Werkrades + f[0] = -f[0]; + ah = f[1]; + f[1] = -f[2]; + f[2] = -ah; + + // ZUSATZBEWEGUNG Angular motion + if (angularMotionDegree >= 0) { + ah = 0.0; + for (i = angularMotionDegree; i > 0; i--) { + ah += angularMotionCoeff[i]; + ah *= z[2]; } - - // Teilkegeloeffnungswinkel delta - y-Achsen entgegengesetzt - D1(f,hgDelta); - - // neue Verschiebung der Werkradachse - f[2] += hgZwr; // z-Achse zeigt zu Spitze - - // ZUSATZBEWEGUNG Modified roll - if (modifiedRollDegree >= 0) { - ah = 0.0; - for (i=modifiedRollDegree; i>1; i--) { - ah += modifiedRollCoeff[i]; - ah *= z[2]; - } - if (modifiedRollDegree > 0) - ah += modifiedRollCoeff[1]; - ah += hgOmega; - ah *= z[2]; - ah += modifiedRollCoeff[0]; - } else { - ah = hgOmega; - ah *= z[2]; + ah += angularMotionCoeff[0]; + D1(f, ah); // umgekehrte Drehung um die x-Achse + } + + // Teilkegeloeffnungswinkel delta - y-Achsen entgegengesetzt + D1(f, hgDelta); + + // neue Verschiebung der Werkradachse + f[2] += hgZwr; // z-Achse zeigt zu Spitze + + // ZUSATZBEWEGUNG Modified roll + if (modifiedRollDegree >= 0) { + ah = 0.0; + for (i = modifiedRollDegree; i > 1; i--) { + ah += modifiedRollCoeff[i]; + ah *= z[2]; } - ah += hgC*z[1]; // c*v + omega * t - // gekoppelte Werkraddrehung in Abhaengigkeit von t und v - D3(f,ah); + if (modifiedRollDegree > 0) + ah += modifiedRollCoeff[1]; + ah += hgOmega; + ah *= z[2]; + ah += modifiedRollCoeff[0]; + } else { + ah = hgOmega; + ah *= z[2]; + } + ah += hgC * z[1]; // c*v + omega * t + // gekoppelte Werkraddrehung in Abhaengigkeit von t und v + D3(f, ah); } /*--------------------------------------------------------------------------*/ /* The interface function */ -void originalVectorFunction( double* indeps, double* deps ) { - int i = 3; - double * radMotCoeff = indeps+i; - i += radMotDegree; - double * verMotCoeff = indeps+i; - i += verMotDegree; - double * horMotCoeff = indeps+i; - i += horMotDegree; - double * helMotCoeff = indeps+i; - i += helMotDegree; - double * angMotCoeff = indeps+i; - i += angMotDegree; - double * modRolCoeff = indeps+i; - - gearFunction( - indeps, - deps, - // jetzt kommen die ganzen Parameter - xmk, // Messerversatz - ymk, // MK-Versatz - kopspw, // Kopfspanwinkel - flaspw, // Flankenspanwinkel - meschw, // Messerschwenkwinkel - flkrrd, // Flugkreisradius - e, // Exzentrizitaet - exzenw, // Exzentrizitaetswinkel - thetas, // Messerkopfschwenkung - thetan, // Messerkopfneigung - xmw, // MK-x - ymw, // MK-y - zmw, // MK-z - thetaw, // Wiegenwinkel - m, // Achsversatz - zwr, // Verschiebung Werkradachse - delta, // Teilkegeloeffnungswinkel - omega, // - c, - r, // Kopfradius - rs, // Sphaerikradius - ys, // Sphaerik-Mitte-Y - zs, // Sphaerik-Mitte-Z - // jetzt die Zusatzbewegungen - radMotDegree, - radMotCoeff, - verMotDegree, - verMotCoeff, - horMotDegree, - horMotCoeff, - helMotDegree, - helMotCoeff, - angMotDegree, - angMotCoeff, - modRolDegree, - modRolCoeff - ); +void originalVectorFunction(double *indeps, double *deps) { + int i = 3; + double *radMotCoeff = indeps + i; + i += radMotDegree; + double *verMotCoeff = indeps + i; + i += verMotDegree; + double *horMotCoeff = indeps + i; + i += horMotDegree; + double *helMotCoeff = indeps + i; + i += helMotDegree; + double *angMotCoeff = indeps + i; + i += angMotDegree; + double *modRolCoeff = indeps + i; + + gearFunction(indeps, deps, + // jetzt kommen die ganzen Parameter + xmk, // Messerversatz + ymk, // MK-Versatz + kopspw, // Kopfspanwinkel + flaspw, // Flankenspanwinkel + meschw, // Messerschwenkwinkel + flkrrd, // Flugkreisradius + e, // Exzentrizitaet + exzenw, // Exzentrizitaetswinkel + thetas, // Messerkopfschwenkung + thetan, // Messerkopfneigung + xmw, // MK-x + ymw, // MK-y + zmw, // MK-z + thetaw, // Wiegenwinkel + m, // Achsversatz + zwr, // Verschiebung Werkradachse + delta, // Teilkegeloeffnungswinkel + omega, // + c, + r, // Kopfradius + rs, // Sphaerikradius + ys, // Sphaerik-Mitte-Y + zs, // Sphaerik-Mitte-Z + // jetzt die Zusatzbewegungen + radMotDegree, radMotCoeff, verMotDegree, verMotCoeff, + horMotDegree, horMotCoeff, helMotDegree, helMotCoeff, + angMotDegree, angMotCoeff, modRolDegree, modRolCoeff); } - /****************************************************************************/ /* TAPING SCALAR FUNCTION */ - /*--------------------------------------------------------------------------*/ /* The model function */ /*--------------------------------------------------------------------------*/ // parametrized cutting edge -void def_messer( - adouble * z, - adouble * messer, - // jetzt kommen die Parameter - double hgR, // Kopfradius - double hgRs, // Sphaerikradius - double hgYs, // Sphaerik-Mitte-Y - double hgZs // Sphaerik-Mitte-Z +void def_messer(adouble *z, adouble *messer, + // jetzt kommen die Parameter + double hgR, // Kopfradius + double hgRs, // Sphaerikradius + double hgYs, // Sphaerik-Mitte-Y + double hgZs // Sphaerik-Mitte-Z ) { - double u0, uOri, phi0; - adouble h; - - phi0= asin((hgR+hgYs)/(hgR+hgRs)); - if (konvex==1) { - u0=hgRs*phi0; - uOri=1.0; - } else { - u0=hgRs*(phi0-Pi); - uOri=-1.0; - }; - - h= (z[0]-u0)/(uOri*hgRs); - messer[0]=hgZs+hgRs*cos(h); - messer[1]=0.0; - messer[2]=-hgYs-hgRs*sin(h); + double u0, uOri, phi0; + adouble h; + + phi0 = asin((hgR + hgYs) / (hgR + hgRs)); + if (konvex == 1) { + u0 = hgRs * phi0; + uOri = 1.0; + } else { + u0 = hgRs * (phi0 - Pi); + uOri = -1.0; + }; + + h = (z[0] - u0) / (uOri * hgRs); + messer[0] = hgZs + hgRs * cos(h); + messer[1] = 0.0; + messer[2] = -hgYs - hgRs * sin(h); } /*--------------------------------------------------------------------------*/ // the main function void activeGearFunction( - adouble* z, // (u,v,t) Parametrisierung der Bewegung der Messerschneide - adouble* f, // (x,y,z) Bewegte Messerschneide + adouble *z, // (u,v,t) Parametrisierung der Bewegung der Messerschneide + adouble *f, // (x,y,z) Bewegte Messerschneide // jetzt kommen die ganzen Parameter double hgXmk, // Messerversatz double hgYmk, // MK-Versatz @@ -495,244 +463,220 @@ void activeGearFunction( double hgDelta, // Teilkegeloeffnungswinkel double hgOmega, // double hgC, - double hgR, // Kopfradius - double hgRs, // Sphaerikradius - double hgYs, // Sphaerik-Mitte-Y - double hgZs, // Sphaerik-Mitte-Z + double hgR, // Kopfradius + double hgRs, // Sphaerikradius + double hgYs, // Sphaerik-Mitte-Y + double hgZs, // Sphaerik-Mitte-Z // jetzt die Zusatzbewegungen - int radialMotionDegree, - adouble* radialMotionCoeff, - int verticalMotionDegree, - adouble* verticalMotionCoeff, - int horizontalMotionDegree, - adouble* horizontalMotionCoeff, - int helicalMotionDegree, - adouble* helicalMotionCoeff, - int angularMotionDegree, - adouble* angularMotionCoeff, - int modifiedRollDegree, - adouble* modifiedRollCoeff -) { - int i; - adouble ah; - - // Definition der Schneide - def_messer(z,f,hgR,hgRs,hgYs,hgZs); - - // Position der Schneide am Messerkopf - // (jetzt die Ber"ucksichtigung von hgKopSpW, hgFlaSpW, hgMeSchW) - D2T(f,hgMeSchW); // Messerschwenkwinkel Theta_M - D3T(f,hgFlaSpW); // Flankenspanwinkel Theta_F - D1(f,hgKopSpW); // Kopfspanwinkel Theta_K - // Position der Schneide am Messerkopf - f[0] += hgFlKrRd; // Flugkreisradius - f[1] -= hgXmk; // Messerversatz - - // Messerkopfrotation mit Parameter v - D3(f,z[1]); - - // Lage des Messerkopfs auf der Wiege - f[2] -= hgYmk; - - // Beruecksichtigung der Messerkopf-Exzentrizitaet - f[0] += hgE * cos(hgExzenW); - f[1] -= hgE * sin(hgExzenW); - - // Eindrehen in Orientierung der Wiege - ah = f[0]; - f[0] = f[1]; - f[1] = ah; - f[2] = -f[2]; - - // Beruecksichtigung von Messerkopf-Schwenkwinkel hgThetaS - // und der Messerkopfneigung hgThetaN - D3T(f,hgThetaS); // Einschwenken in die Neigungsachse - D1T(f,hgThetaN); // Neigung um x-Achse - D3(f,hgThetaS); // Rueckschwenken aus der Neigungsachse - - // Verschiebung - f[0] -= hgXmw; // FLB1-x-Achse zeigt nach oben -> (-xNeu) - f[1] += hgZmw; // FLB1-z-Achse zeigt nach rechts -> (yNeu) - f[2] += hgYmw; // FLB1-y-Achse zeigt aus der Wiege -> (zNeu) - - // Wiegenwinkel thetaW, entspricht dem wert t=0 - D3(f,hgThetaW); - - // ZUSATZBEWEGUNG Radial motion - if (radialMotionDegree >= 0) { - ah = 0.0; - for (i=radialMotionDegree; i>0; i--) { - ah += radialMotionCoeff[i]; - ah *= z[2]; - } - ah += radialMotionCoeff[0]; - f[1] += ah; // radiale Verschiebung des Messerkopfes + int radialMotionDegree, adouble *radialMotionCoeff, + int verticalMotionDegree, adouble *verticalMotionCoeff, + int horizontalMotionDegree, adouble *horizontalMotionCoeff, + int helicalMotionDegree, adouble *helicalMotionCoeff, + int angularMotionDegree, adouble *angularMotionCoeff, + int modifiedRollDegree, adouble *modifiedRollCoeff) { + int i; + adouble ah; + + // Definition der Schneide + def_messer(z, f, hgR, hgRs, hgYs, hgZs); + + // Position der Schneide am Messerkopf + // (jetzt die Ber"ucksichtigung von hgKopSpW, hgFlaSpW, hgMeSchW) + D2T(f, hgMeSchW); // Messerschwenkwinkel Theta_M + D3T(f, hgFlaSpW); // Flankenspanwinkel Theta_F + D1(f, hgKopSpW); // Kopfspanwinkel Theta_K + // Position der Schneide am Messerkopf + f[0] += hgFlKrRd; // Flugkreisradius + f[1] -= hgXmk; // Messerversatz + + // Messerkopfrotation mit Parameter v + D3(f, z[1]); + + // Lage des Messerkopfs auf der Wiege + f[2] -= hgYmk; + + // Beruecksichtigung der Messerkopf-Exzentrizitaet + f[0] += hgE * cos(hgExzenW); + f[1] -= hgE * sin(hgExzenW); + + // Eindrehen in Orientierung der Wiege + ah = f[0]; + f[0] = f[1]; + f[1] = ah; + f[2] = -f[2]; + + // Beruecksichtigung von Messerkopf-Schwenkwinkel hgThetaS + // und der Messerkopfneigung hgThetaN + D3T(f, hgThetaS); // Einschwenken in die Neigungsachse + D1T(f, hgThetaN); // Neigung um x-Achse + D3(f, hgThetaS); // Rueckschwenken aus der Neigungsachse + + // Verschiebung + f[0] -= hgXmw; // FLB1-x-Achse zeigt nach oben -> (-xNeu) + f[1] += hgZmw; // FLB1-z-Achse zeigt nach rechts -> (yNeu) + f[2] += hgYmw; // FLB1-y-Achse zeigt aus der Wiege -> (zNeu) + + // Wiegenwinkel thetaW, entspricht dem wert t=0 + D3(f, hgThetaW); + + // ZUSATZBEWEGUNG Radial motion + if (radialMotionDegree >= 0) { + ah = 0.0; + for (i = radialMotionDegree; i > 0; i--) { + ah += radialMotionCoeff[i]; + ah *= z[2]; } - - // Wiegenbewegung mit Parameter t - D3(f,z[2]); - - // ZUSATZBEWEGUNG Vertical motion - if (verticalMotionDegree >= 0) { - ah = 0.0; - for (i=verticalMotionDegree; i>0; i--) { - ah += verticalMotionCoeff[i]; - ah *= z[2]; - } - ah += verticalMotionCoeff[0]; - f[0] += ah; // Achsversatz in positive x-Richtung + ah += radialMotionCoeff[0]; + f[1] += ah; // radiale Verschiebung des Messerkopfes + } + + // Wiegenbewegung mit Parameter t + D3(f, z[2]); + + // ZUSATZBEWEGUNG Vertical motion + if (verticalMotionDegree >= 0) { + ah = 0.0; + for (i = verticalMotionDegree; i > 0; i--) { + ah += verticalMotionCoeff[i]; + ah *= z[2]; } - - // originaler Achsversatz - f[0] += hgM; - - // ZUSATZBEWEGUNG Horizontal motion - if (horizontalMotionDegree >= 0) { - ah = 0.0; - for (i=horizontalMotionDegree; i>0; i--) { - ah += horizontalMotionCoeff[i]; - ah *= z[2]; - } - ah += horizontalMotionCoeff[0]; - f[1] += ah; // Achsversatz in positive y-Richtung + ah += verticalMotionCoeff[0]; + f[0] += ah; // Achsversatz in positive x-Richtung + } + + // originaler Achsversatz + f[0] += hgM; + + // ZUSATZBEWEGUNG Horizontal motion + if (horizontalMotionDegree >= 0) { + ah = 0.0; + for (i = horizontalMotionDegree; i > 0; i--) { + ah += horizontalMotionCoeff[i]; + ah *= z[2]; } - - // ZUSATZBEWEGUNG Helical motion - if (helicalMotionDegree >= 0) { - ah = 0.0; - for (i=helicalMotionDegree; i>0; i--) { - ah += helicalMotionCoeff[i]; - ah *= z[2]; - } - ah += helicalMotionCoeff[0]; - f[2] -= ah; // Tiefenposition in negative z-Richtung + ah += horizontalMotionCoeff[0]; + f[1] += ah; // Achsversatz in positive y-Richtung + } + + // ZUSATZBEWEGUNG Helical motion + if (helicalMotionDegree >= 0) { + ah = 0.0; + for (i = helicalMotionDegree; i > 0; i--) { + ah += helicalMotionCoeff[i]; + ah *= z[2]; } - - // Eindrehen in Orientierung des Werkrades - f[0] = -f[0]; - ah = f[1]; - f[1] = -f[2]; - f[2] = -ah; - - // ZUSATZBEWEGUNG Angular motion - if (angularMotionDegree >= 0) { - ah = 0.0; - for (i=angularMotionDegree; i>0; i--) { - ah += angularMotionCoeff[i]; - ah *= z[2]; - } - ah += angularMotionCoeff[0]; - D1(f,ah); // umgekehrte Drehung um die x-Achse + ah += helicalMotionCoeff[0]; + f[2] -= ah; // Tiefenposition in negative z-Richtung + } + + // Eindrehen in Orientierung des Werkrades + f[0] = -f[0]; + ah = f[1]; + f[1] = -f[2]; + f[2] = -ah; + + // ZUSATZBEWEGUNG Angular motion + if (angularMotionDegree >= 0) { + ah = 0.0; + for (i = angularMotionDegree; i > 0; i--) { + ah += angularMotionCoeff[i]; + ah *= z[2]; } - - // Teilkegeloeffnungswinkel delta - y-Achsen entgegengesetzt - D1(f,hgDelta); - - // neue Verschiebung der Werkradachse - f[2] += hgZwr; // z-Achse zeigt zu Spitze - - // ZUSATZBEWEGUNG Modified roll - if (modifiedRollDegree >= 0) { - ah = 0.0; - for (i=modifiedRollDegree; i>1; i--) { - ah += modifiedRollCoeff[i]; - ah *= z[2]; - } - if (modifiedRollDegree > 0) - ah += modifiedRollCoeff[1]; - ah += hgOmega; - ah *= z[2]; - ah += modifiedRollCoeff[0]; - } else { - ah = hgOmega; - ah *= z[2]; + ah += angularMotionCoeff[0]; + D1(f, ah); // umgekehrte Drehung um die x-Achse + } + + // Teilkegeloeffnungswinkel delta - y-Achsen entgegengesetzt + D1(f, hgDelta); + + // neue Verschiebung der Werkradachse + f[2] += hgZwr; // z-Achse zeigt zu Spitze + + // ZUSATZBEWEGUNG Modified roll + if (modifiedRollDegree >= 0) { + ah = 0.0; + for (i = modifiedRollDegree; i > 1; i--) { + ah += modifiedRollCoeff[i]; + ah *= z[2]; } - ah += hgC*z[1]; // c*v + omega * t - // gekoppelte Werkraddrehung in Abhaengigkeit von t und v - D3(f,ah); + if (modifiedRollDegree > 0) + ah += modifiedRollCoeff[1]; + ah += hgOmega; + ah *= z[2]; + ah += modifiedRollCoeff[0]; + } else { + ah = hgOmega; + ah *= z[2]; + } + ah += hgC * z[1]; // c*v + omega * t + // gekoppelte Werkraddrehung in Abhaengigkeit von t und v + D3(f, ah); } - /*--------------------------------------------------------------------------*/ /* The interface function */ -void tapingVectorFunction( int tag, double* indeps, double* deps ) { - int i; - trace_on(tag); - adouble* activeIndeps = new adouble[indepDim]; - adouble* activeDeps = new adouble[depDim]; - adouble* aIP = activeIndeps; - double* iP = indeps; - for (i=0; i>= *iP++; - trace_off(); - - delete [] activeDeps; - delete [] activeIndeps; +void tapingVectorFunction(int tag, double *indeps, double *deps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *activeDeps = new adouble[depDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + + i = 3; + adouble *activeRadMotCoeff = activeIndeps + i; + i += radMotDegree; + adouble *activeVerMotCoeff = activeIndeps + i; + i += verMotDegree; + adouble *activeHorMotCoeff = activeIndeps + i; + i += horMotDegree; + adouble *activeHelMotCoeff = activeIndeps + i; + i += helMotDegree; + adouble *activeAngMotCoeff = activeIndeps + i; + i += angMotDegree; + adouble *activeModRolCoeff = activeIndeps + i; + + activeGearFunction(activeIndeps, activeDeps, + // jetzt kommen die ganzen Parameter + xmk, // Messerversatz + ymk, // MK-Versatz + kopspw, // Kopfspanwinkel + flaspw, // Flankenspanwinkel + meschw, // Messerschwenkwinkel + flkrrd, // Flugkreisradius + e, // Exzentrizitaet + exzenw, // Exzentrizitaetswinkel + thetas, // Messerkopfschwenkung + thetan, // Messerkopfneigung + xmw, // MK-x + ymw, // MK-y + zmw, // MK-z + thetaw, // Wiegenwinkel + m, // Achsversatz + zwr, // Verschiebung Werkradachse + delta, // Teilkegeloeffnungswinkel + omega, // + c, + r, // Kopfradius + rs, // Sphaerikradius + ys, // Sphaerik-Mitte-Y + zs, // Sphaerik-Mitte-Z + // jetzt die Zusatzbewegungen + radMotDegree, activeRadMotCoeff, verMotDegree, + activeVerMotCoeff, horMotDegree, activeHorMotCoeff, + helMotDegree, activeHelMotCoeff, angMotDegree, + activeAngMotCoeff, modRolDegree, activeModRolCoeff); + + aIP = activeDeps; + iP = deps; + for (i = 0; i < depDim; i++) + *aIP++ >>= *iP++; + trace_off(); + + delete[] activeDeps; + delete[] activeIndeps; } #undef _VFUNC_GEAR_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/vfunc_shuttle.cpp b/ADOL-C/examples/additional_examples/timing/vfunc_shuttle.cpp index 15aec8526..a3332b5f4 100644 --- a/ADOL-C/examples/additional_examples/timing/vfunc_shuttle.cpp +++ b/ADOL-C/examples/additional_examples/timing/vfunc_shuttle.cpp @@ -3,42 +3,40 @@ File: vfunc_shuttle.cpp Revision: $Id$ Contents: Example of function module containing the shuttle example - (based on shuttlexam.c of version 1.7) - + (based on shuttlexam.c of version 1.7) + Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indeps ) (6) void originalVectorFunction( double* indeps, double* deps ) - (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _VFUNC_SHUTTLE_C_ - /****************************************************************************/ /* INCLUDES */ #include #include - /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "shuttlexam.ctrl"; +const char *controlFileName = "shuttlexam.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -50,160 +48,158 @@ int depDim; const double Pi = 3.141592654; const double ae = 20902900.0; const double mu = 0.14E+17; -const double a = 40.0; -const double S = 2690.0; -const double crtd = 180.0/Pi; -const double cl = 0.84-0.48*(38.0-a*crtd)/26.0; -const double C0 = 3.974960446019; +const double a = 40.0; +const double S = 2690.0; +const double crtd = 180.0 / Pi; +const double cl = 0.84 - 0.48 * (38.0 - a * crtd) / 26.0; +const double C0 = 3.974960446019; const double C1 = -0.01448947694635; const double C2 = -0.2156171551995e-4; const double C3 = -0.1089609507291e-7; -const double V0 = 0.0; +const double V0 = 0.0; const double ma = 5964.496499824; const double Om = .72921159e-4; - /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"SHUTTLEXAM (ADOL-C Example)\n\n"); +void initProblemParameters(void) { + fprintf(stdout, "SHUTTLEXAM (ADOL-C Example)\n\n"); - /* number of indeps & deps */ - indepDim = 14; - depDim = 7; + /* number of indeps & deps */ + indepDim = 14; + depDim = 7; } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - indeps[0] = 264039.328; /* H */ - indeps[1] = 177.718047; /* x */ - indeps[2] = 32.0417885; /* l */ - indeps[3] = 24317.0798; /* V */ - indeps[4] = -0.749986488; /* g */ - indeps[5] = 62.7883367; /* A */ - indeps[6] = 41.100771834; /* b */ - indeps[7] = -318; /* Hp */ - indeps[8] = 0.01; /* xp */ - indeps[9] = 0.1; /* lp */ - indeps[10] = -3.6; /* Vp */ - indeps[11] = 0.001; /* gp */ - indeps[12] = 0.1; /* Ap */ - indeps[13] = 0.06; /* bp */ +void initIndependents(double *indeps) { + indeps[0] = 264039.328; /* H */ + indeps[1] = 177.718047; /* x */ + indeps[2] = 32.0417885; /* l */ + indeps[3] = 24317.0798; /* V */ + indeps[4] = -0.749986488; /* g */ + indeps[5] = 62.7883367; /* A */ + indeps[6] = 41.100771834; /* b */ + indeps[7] = -318; /* Hp */ + indeps[8] = 0.01; /* xp */ + indeps[9] = 0.1; /* lp */ + indeps[10] = -3.6; /* Vp */ + indeps[11] = 0.001; /* gp */ + indeps[12] = 0.1; /* Ap */ + indeps[13] = 0.06; /* bp */ } - /****************************************************************************/ /* ORIGINAL SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The shuttle function */ -void shuttle( double* indeps, double* deps ) { - double r,gr,rho,L,cd,Z; - double sing,cosg,sinA,cosA,sinl,cosl,tanl; - - r = indeps[0]+ae; - gr = mu/(r*r); - rho= 0.002378*exp(-indeps[0]/23800.0); - L = 0.5*rho*cl*S*indeps[3]*indeps[3]; - cd = 0.78-0.58*(38.0-a*crtd)/26.0; - Z = .5*rho*cd*S*indeps[3]*indeps[3]; - // evaluate the dynamic equations ... - sinA = sin(indeps[5]); - cosA = cos(indeps[5]); - sing = sin(indeps[4]); - cosg = cos(indeps[4]); - sinl = sin(indeps[2]); - cosl = cos(indeps[2]); - tanl = sinl/cosl; - deps[0] = indeps[3]*sing-indeps[7]; - deps[1] = indeps[3]*cosg*sinA/(r*cosl)-indeps[8]; - deps[2] = indeps[3]*cosg*cosA/r-indeps[9]; - deps[3] = -Z/ma-gr*sing-Om*Om*r*cosl - *(sinl*cosA*cosg-cosl*sing)-indeps[10]; - deps[4] = L*cos(indeps[6])/(ma*indeps[3]) - +cosl/indeps[3]*(indeps[3]*indeps[3]/r-gr) - +2*Om*cosl*sinA - +Om*Om*r*cosl/indeps[3]*(sinl*cosA*sing+cosl*cosg) - -indeps[11]; - deps[5] = L*sin(indeps[6])/(ma*indeps[3]*cosg)+indeps[3]/r*cosg*sinA*tanl - -2*Om*(cosl*cosA*sing/cosg-sinl) - +Om*Om*r*cosl*sinl*sinA/(indeps[3]*cosg)-indeps[12]; - deps[6] = Z/ma - -(C0+(indeps[3]-V0)*(C1+(indeps[3]-V0)*(C2+(indeps[3]-V0)*C3))); +void shuttle(double *indeps, double *deps) { + double r, gr, rho, L, cd, Z; + double sing, cosg, sinA, cosA, sinl, cosl, tanl; + + r = indeps[0] + ae; + gr = mu / (r * r); + rho = 0.002378 * exp(-indeps[0] / 23800.0); + L = 0.5 * rho * cl * S * indeps[3] * indeps[3]; + cd = 0.78 - 0.58 * (38.0 - a * crtd) / 26.0; + Z = .5 * rho * cd * S * indeps[3] * indeps[3]; + // evaluate the dynamic equations ... + sinA = sin(indeps[5]); + cosA = cos(indeps[5]); + sing = sin(indeps[4]); + cosg = cos(indeps[4]); + sinl = sin(indeps[2]); + cosl = cos(indeps[2]); + tanl = sinl / cosl; + deps[0] = indeps[3] * sing - indeps[7]; + deps[1] = indeps[3] * cosg * sinA / (r * cosl) - indeps[8]; + deps[2] = indeps[3] * cosg * cosA / r - indeps[9]; + deps[3] = -Z / ma - gr * sing - + Om * Om * r * cosl * (sinl * cosA * cosg - cosl * sing) - + indeps[10]; + deps[4] = + L * cos(indeps[6]) / (ma * indeps[3]) + + cosl / indeps[3] * (indeps[3] * indeps[3] / r - gr) + + 2 * Om * cosl * sinA + + Om * Om * r * cosl / indeps[3] * (sinl * cosA * sing + cosl * cosg) - + indeps[11]; + deps[5] = L * sin(indeps[6]) / (ma * indeps[3] * cosg) + + indeps[3] / r * cosg * sinA * tanl - + 2 * Om * (cosl * cosA * sing / cosg - sinl) + + Om * Om * r * cosl * sinl * sinA / (indeps[3] * cosg) - indeps[12]; + deps[6] = Z / ma - + (C0 + (indeps[3] - V0) * + (C1 + (indeps[3] - V0) * (C2 + (indeps[3] - V0) * C3))); } /*--------------------------------------------------------------------------*/ /* The interface function */ -void originalVectorFunction( double* indeps, double* deps ) { - shuttle(indeps,deps); +void originalVectorFunction(double *indeps, double *deps) { + shuttle(indeps, deps); } - /****************************************************************************/ /* TAPING SCALAR FUNCTION */ /*--------------------------------------------------------------------------*/ /* The active shuttle function */ -void activeShuttle( adouble* indeps, adouble* deps ) { - adouble r,gr,rho,L,cd,Z; - adouble sing,cosg,sinA,cosA,sinl,cosl,tanl; - - r = indeps[0]+ae; - gr = mu/(r*r); - rho= 0.002378*exp(-indeps[0]/23800.0); - L = 0.5*rho*cl*S*indeps[3]*indeps[3]; - cd = 0.78-0.58*(38.0-a*crtd)/26.0; - Z = .5*rho*cd*S*indeps[3]*indeps[3]; - // evaluate the dynamic equations ... - sinA = sin(indeps[5]); - cosA = cos(indeps[5]); - sing = sin(indeps[4]); - cosg = cos(indeps[4]); - sinl = sin(indeps[2]); - cosl = cos(indeps[2]); - tanl = sinl/cosl; - deps[0] = indeps[3]*sing-indeps[7]; - deps[1] = indeps[3]*cosg*sinA/(r*cosl)-indeps[8]; - deps[2] = indeps[3]*cosg*cosA/r-indeps[9]; - deps[3] = -Z/ma-gr*sing-Om*Om*r*cosl - *(sinl*cosA*cosg-cosl*sing)-indeps[10]; - deps[4] = L*cos(indeps[6])/(ma*indeps[3]) - +cosl/indeps[3]*(indeps[3]*indeps[3]/r-gr) - +2*Om*cosl*sinA - +Om*Om*r*cosl/indeps[3]*(sinl*cosA*sing+cosl*cosg) - -indeps[11]; - deps[5] = L*sin(indeps[6])/(ma*indeps[3]*cosg)+indeps[3]/r*cosg*sinA*tanl - -2*Om*(cosl*cosA*sing/cosg-sinl) - +Om*Om*r*cosl*sinl*sinA/(indeps[3]*cosg)-indeps[12]; - deps[6] = Z/ma - -(C0+(indeps[3]-V0)*(C1+(indeps[3]-V0)*(C2+(indeps[3]-V0)*C3))); +void activeShuttle(adouble *indeps, adouble *deps) { + adouble r, gr, rho, L, cd, Z; + adouble sing, cosg, sinA, cosA, sinl, cosl, tanl; + + r = indeps[0] + ae; + gr = mu / (r * r); + rho = 0.002378 * exp(-indeps[0] / 23800.0); + L = 0.5 * rho * cl * S * indeps[3] * indeps[3]; + cd = 0.78 - 0.58 * (38.0 - a * crtd) / 26.0; + Z = .5 * rho * cd * S * indeps[3] * indeps[3]; + // evaluate the dynamic equations ... + sinA = sin(indeps[5]); + cosA = cos(indeps[5]); + sing = sin(indeps[4]); + cosg = cos(indeps[4]); + sinl = sin(indeps[2]); + cosl = cos(indeps[2]); + tanl = sinl / cosl; + deps[0] = indeps[3] * sing - indeps[7]; + deps[1] = indeps[3] * cosg * sinA / (r * cosl) - indeps[8]; + deps[2] = indeps[3] * cosg * cosA / r - indeps[9]; + deps[3] = -Z / ma - gr * sing - + Om * Om * r * cosl * (sinl * cosA * cosg - cosl * sing) - + indeps[10]; + deps[4] = + L * cos(indeps[6]) / (ma * indeps[3]) + + cosl / indeps[3] * (indeps[3] * indeps[3] / r - gr) + + 2 * Om * cosl * sinA + + Om * Om * r * cosl / indeps[3] * (sinl * cosA * sing + cosl * cosg) - + indeps[11]; + deps[5] = L * sin(indeps[6]) / (ma * indeps[3] * cosg) + + indeps[3] / r * cosg * sinA * tanl - + 2 * Om * (cosl * cosA * sing / cosg - sinl) + + Om * Om * r * cosl * sinl * sinA / (indeps[3] * cosg) - indeps[12]; + deps[6] = Z / ma - + (C0 + (indeps[3] - V0) * + (C1 + (indeps[3] - V0) * (C2 + (indeps[3] - V0) * C3))); } - /*--------------------------------------------------------------------------*/ /* The interface function */ -void tapingVectorFunction( int tag, double* indeps, double* deps ) { - int i; - trace_on(tag); - adouble* activeIndeps = new adouble[indepDim]; - adouble* activeDeps = new adouble[depDim]; - adouble* aIP = activeIndeps; - double* iP = indeps; - for (i=0; i>= *iP++; - trace_off(); +void tapingVectorFunction(int tag, double *indeps, double *deps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *activeDeps = new adouble[depDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + activeShuttle(activeIndeps, activeDeps); + aIP = activeDeps; + iP = deps; + for (i = 0; i < depDim; i++) + *aIP++ >>= *iP++; + trace_off(); } #undef _VFUNC_SHUTTLE_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/vfunc_simplevec.cpp b/ADOL-C/examples/additional_examples/timing/vfunc_simplevec.cpp index ff8bc301e..3589a3277 100644 --- a/ADOL-C/examples/additional_examples/timing/vfunc_simplevec.cpp +++ b/ADOL-C/examples/additional_examples/timing/vfunc_simplevec.cpp @@ -5,40 +5,38 @@ Contents: Example of function module containing a simple vector example Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indeps ) (6) void originalVectorFunction( double* indeps, double* deps ) - (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _VFUNC_SIMPLEVEC_C_ - /****************************************************************************/ /* INCLUDES */ #include -#include #include - +#include /****************************************************************************/ /* GLOBAL VARIABLES */ /*--------------------------------------------------------------------------*/ /* Control file name */ -const char* controlFileName = "simplevec.ctrl"; +const char *controlFileName = "simplevec.ctrl"; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -47,108 +45,98 @@ int depDim; /*--------------------------------------------------------------------------*/ /* Other problem dependent parameters */ -//static unsigned short int dx[3]; /* variable needed by erand48(.) */ - +// static unsigned short int dx[3]; /* variable needed by erand48(.) */ /****************************************************************************/ /* INIT PROBLEM PARAMETERS */ -void initProblemParameters( void ) { - fprintf(stdout,"A SIMPLE VECTOR FUNCTION (ADOL-C Example)\n\n"); - - /* number of indeps & deps */ - if (indepDim < 1) { - fprintf(stdout," # of independents = ? "); - fscanf(stdin,"%d",&indepDim); - fprintf(stdout,"\n"); - } - if (depDim < 1) { - fprintf(stdout," # of dependents = ? "); - fscanf(stdin,"%d",&depDim); - fprintf(stdout,"\n"); - } - - /* Init erand48(); */ - struct tm s; - time_t t; - time(&t); - s=*localtime(&t); - srand(s.tm_sec*s.tm_min); - /* dx[0]=rand(); - dx[1]=rand(); - dx[2]=rand();*/ +void initProblemParameters(void) { + fprintf(stdout, "A SIMPLE VECTOR FUNCTION (ADOL-C Example)\n\n"); + + /* number of indeps & deps */ + if (indepDim < 1) { + fprintf(stdout, " # of independents = ? "); + fscanf(stdin, "%d", &indepDim); + fprintf(stdout, "\n"); + } + if (depDim < 1) { + fprintf(stdout, " # of dependents = ? "); + fscanf(stdin, "%d", &depDim); + fprintf(stdout, "\n"); + } + + /* Init erand48(); */ + struct tm s; + time_t t; + time(&t); + s = *localtime(&t); + srand(s.tm_sec * s.tm_min); + /* dx[0]=rand(); + dx[1]=rand(); + dx[2]=rand();*/ } - /****************************************************************************/ /* INITIALIZE INDEPs */ -void initIndependents( double* indeps ) { - for (int i=0; i>= *iP++; - trace_off(); +void tapingVectorFunction(int tag, double *indeps, double *deps) { + int i; + trace_on(tag); + adouble *activeIndeps = new adouble[indepDim]; + adouble *activeDeps = new adouble[depDim]; + adouble *aIP = activeIndeps; + double *iP = indeps; + for (i = 0; i < indepDim; i++) + *aIP++ <<= *iP++; + activeSimplevec(indepDim, depDim, activeIndeps, activeDeps); + aIP = activeDeps; + iP = deps; + for (i = 0; i < depDim; i++) + *aIP++ >>= *iP++; + trace_off(); } - #undef _VFUNC_SIMPLEVEC_C_ - - - - - diff --git a/ADOL-C/examples/additional_examples/timing/vgenmain.cpp b/ADOL-C/examples/additional_examples/timing/vgenmain.cpp index 83948cb11..69f74ef92 100644 --- a/ADOL-C/examples/additional_examples/timing/vgenmain.cpp +++ b/ADOL-C/examples/additional_examples/timing/vgenmain.cpp @@ -2,52 +2,49 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: vgenmain.cpp Revision: $Id$ - Contents: Vector Generic Main File: + Contents: Vector Generic Main File: for use with function modules containing several vector - function examples + function examples (e.g. the sinple example in vfunc_simplevec.cpp) Each << function module >> contains: - - (1) const char* const controlFileName - (2) int indepDim; - (3) int depDim; + + (1) const char* const controlFileName + (2) int indepDim; + (3) int depDim; (4) void initProblemParameters( void ) (5) void initIndependents( double* indeps ) (6) void originalVectorFunction( double* indeps, double* deps ) - (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + (7) void tapingVectorFunction( int tag, double* indeps, double* deps ) + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #define _VGENMAIN_C_ - /****************************************************************************/ /* INCLUDES */ -#include #include "../clock/myclock.h" +#include #include #include - /****************************************************************************/ /* MACROS */ #define TIMEFORMAT " %12.6E units, %12.6E seconds\n" - /****************************************************************************/ /* EXTERNAL STUFF FROM FUNCTION MODULES*/ /*--------------------------------------------------------------------------*/ /* Control file name */ -const extern char* controlFileName; +const extern char *controlFileName; /*--------------------------------------------------------------------------*/ /* Dimensions */ @@ -56,1036 +53,1038 @@ extern int depDim; /*--------------------------------------------------------------------------*/ /* Init Problem Parameters */ -extern void initProblemParameters( void ); +extern void initProblemParameters(void); /*--------------------------------------------------------------------------*/ /* Initialize indeps */ -extern void initIndependents( double* indeps ); +extern void initIndependents(double *indeps); /*--------------------------------------------------------------------------*/ /* Original scalar function */ -extern void originalVectorFunction( double* indeps, double* deps ); +extern void originalVectorFunction(double *indeps, double *deps); /*--------------------------------------------------------------------------*/ /* Taping scalar function */ -extern void tapingVectorFunction( int tag, double* indeps, double* deps ); - +extern void tapingVectorFunction(int tag, double *indeps, double *deps); /****************************************************************************/ /* CONTROL STUFF */ enum controlParameter { - cpIndepDimension, - cpDepDimension, - cpAverageCount, - cpDegree, - cpVecCountFW, - cpVecCountRV, - cpVecCountTR, - cpZosFW, - cpFosFW, - cpHosFW, - cpFovFW, - cpHovFW, - cpFosRV, - cpHosRV, - cpFovRV, - cpHovRV, - cpFunction, - cpJacobian, - cpVecJac, - cpJacVec, - cpLagHessVec, - cpTensor, - cpInvTensor, - cpCount + cpIndepDimension, + cpDepDimension, + cpAverageCount, + cpDegree, + cpVecCountFW, + cpVecCountRV, + cpVecCountTR, + cpZosFW, + cpFosFW, + cpHosFW, + cpFovFW, + cpHovFW, + cpFosRV, + cpHosRV, + cpFovRV, + cpHovRV, + cpFunction, + cpJacobian, + cpVecJac, + cpJacVec, + cpLagHessVec, + cpTensor, + cpInvTensor, + cpCount }; - /****************************************************************************/ /* PROVIDE RANDOM INITs */ -//unsigned short int dx[3]; /* variable needed by erand48(.) */ - -void initRand ( void ) /* a function to initialize dx using actual time */ -{ struct tm s; - time_t t; - time(&t); - s=*localtime(&t); - srand(s.tm_sec*s.tm_min); - /* dx[0]=rand(); - dx[1]=rand(); - dx[2]=rand();*/ +// unsigned short int dx[3]; /* variable needed by erand48(.) */ + +void initRand(void) /* a function to initialize dx using actual time */ +{ + struct tm s; + time_t t; + time(&t); + s = *localtime(&t); + srand(s.tm_sec * s.tm_min); + /* dx[0]=rand(); + dx[1]=rand(); + dx[2]=rand();*/ } - /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i, j, k; - int tag = 1; /* tape tag */ - int taskCount = 0; - - int pFW, pRV, pTR, degree, keep; /* forward/reverse parameters */ - int evalCount; /* # of evaluations */ + int i, j, k; + int tag = 1; /* tape tag */ + int taskCount = 0; + + int pFW, pRV, pTR, degree, keep; /* forward/reverse parameters */ + int evalCount; /* # of evaluations */ + + /****************************************************************************/ + /* READ CONTROL PARAMETERS FROM FILE */ + int controlParameters[cpCount]; + FILE *controlFile; + + /*------------------------------------------------------------------------*/ + /* open file to read */ + if ((controlFile = fopen(controlFileName, "r")) == NULL) { + fprintf(stdout, "ERROR: Could not open control file %s\n", controlFileName); + exit(-1); + } + + /*------------------------------------------------------------------------*/ + /* read all values */ + for (i = 0; i < cpCount; i++) + fscanf(controlFile, "%d%*[^\n]", &controlParameters[i]); + + indepDim = controlParameters[cpIndepDimension]; + depDim = controlParameters[cpDepDimension]; + pFW = controlParameters[cpVecCountFW]; + pRV = controlParameters[cpVecCountRV]; + pTR = controlParameters[cpVecCountTR]; + degree = controlParameters[cpDegree]; + evalCount = controlParameters[cpAverageCount]; + + /*------------------------------------------------------------------------*/ + /* close control file */ + fclose(controlFile); + + /****************************************************************************/ + /* VARIABLES & INITIALIZATION */ + + /*------------------------------------------------------------------------*/ + /* Initialize all problem parameters (including dimension) */ + initProblemParameters(); + + /*------------------------------------------------------------------------*/ + /* Initialize the independent variables */ + double *indeps = new double[indepDim]; + double *deps = new double[depDim]; + initIndependents(indeps); + + /*------------------------------------------------------------------------*/ + /* Check main parameters */ + if (evalCount <= 0) { + fprintf(stdout, " # of evaluations to average over = ? "); + fscanf(stdin, "%d", &evalCount); + fprintf(stdout, "\n"); + } + + if ((degree <= 1) && + (controlParameters[cpHosFW] || controlParameters[cpHovFW] || + controlParameters[cpHosRV] || controlParameters[cpHovRV] || + controlParameters[cpTensor])) { + fprintf(stdout, " degree = ? "); + fscanf(stdin, "%d", °ree); + fprintf(stdout, "\n"); + } + keep = degree + 1; + + if ((pFW < 1) && (controlParameters[cpFovFW] || controlParameters[cpHovFW])) { + fprintf(stdout, " # of vectors in vector forward mode = ? "); + fscanf(stdin, "%d", &pFW); + fprintf(stdout, "\n"); + } + + if ((pRV < 1) && (controlParameters[cpFovRV] || controlParameters[cpHovRV])) { + fprintf(stdout, " # of vectors in vector reverse mode = ? "); + fscanf(stdin, "%d", &pRV); + fprintf(stdout, "\n"); + } + + if ((pTR < 1) && + (controlParameters[cpTensor] || controlParameters[cpInvTensor])) { + fprintf(stdout, " # of vectors in tensor mode = ? "); + fscanf(stdin, "%d", &pTR); + fprintf(stdout, "\n"); + } + + /*------------------------------------------------------------------------*/ + /* Necessary variable */ + double ***XPPP, **XPP; + double ***YPPP, **YPP, *YP; + double ***ZPPP, **ZPP, *ZP; + double **UPP, *UP; + double *VP; + double *WP; + double **JPP; + short **nzPP; + int retVal = 0; /* return value */ + double t00, t01, t02, t03; /* time values */ + double **TPP; + double **SPP; + int dim; + + /****************************************************************************/ + /* 0. ORIGINAL FUNCTION EVALUATION */ + /* ---> always */ + fprintf(stdout, "\nTASK %d: Original function evaluation\n", taskCount++); + + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + originalVectorFunction(indeps, deps); + t01 = myclock(); + + double timeUnit; + if (t01 - t00) { + timeUnit = 1.0 / (t01 - t00); + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, 1.0, (t01 - t00) / evalCount); + } else { + fprintf(stdout, " !!! zero timing !!!\n"); + fprintf(stdout, " set time unit to 1.0\n"); + timeUnit = 1; + } + + /****************************************************************************/ + /* 1. TAPING THE FUNCTION */ + /* ---> always */ + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: Taping the function\n", taskCount++); + + t00 = myclock(1); + /* NOTE: taping will be performed ONCE only */ + tapingVectorFunction(tag, indeps, deps); + t01 = myclock(); + + size_t tape_stats[STAT_SIZE]; + tapestats(tag, tape_stats); + + fprintf(stdout, "\n independents %zu\n", + tape_stats[NUM_INDEPENDENTS]); + fprintf(stdout, " dependents %zu\n", + tape_stats[NUM_DEPENDENTS]); + fprintf(stdout, " operations %zu\n", + tape_stats[NUM_OPERATIONS]); + fprintf(stdout, " operations buffer size %zu\n", + tape_stats[OP_BUFFER_SIZE]); + fprintf(stdout, " locations buffer size %zu\n", + tape_stats[LOC_BUFFER_SIZE]); + fprintf(stdout, " constants buffer size %zu\n", + tape_stats[VAL_BUFFER_SIZE]); + fprintf(stdout, " maxlive %zu\n", + tape_stats[NUM_MAX_LIVES]); + fprintf(stdout, " valstack size %zu\n\n", + tape_stats[TAY_STACK_SIZE]); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit * evalCount, (t01 - t00)); + + /****************************************************************************/ + /* 2. ZOS_FORWARD */ + if (controlParameters[cpZosFW]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: forward(tag, m=%d, n=%d, keep, X[n], Y[m])\n", + taskCount++, depDim, indepDim); + fprintf(stdout, " ---> zos_forward\n"); + + /*----------------------------------------------------------------------*/ + /* NO KEEP */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, depDim, indepDim, 0, indeps, deps); + t01 = myclock(); + fprintf(stdout, " NO KEEP"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* KEEP */ + t02 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, depDim, indepDim, 1, indeps, deps); + t03 = myclock(); + + fprintf(stdout, " KEEP "); + fprintf(stdout, TIMEFORMAT, (t03 - t02) * timeUnit, + (t03 - t02) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpZosFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + } + } + + /****************************************************************************/ + /* 3. FOS_FORWARD */ + if (controlParameters[cpFosFW]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: forward(tag, m=%d, n=%d, d=1, keep, X[n][d+1], " + "Y[m][d+1])\n", + taskCount++, depDim, indepDim); + fprintf(stdout, " ---> fos_forward\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[2]; + XPP[i][0] = indeps[i]; + XPP[i][1] = (double)rand(); + } + YPP = new double *[depDim]; + for (i = 0; i < depDim; i++) + YPP[i] = new double[2]; - /****************************************************************************/ - /* READ CONTROL PARAMETERS FROM FILE */ - int controlParameters[cpCount]; - FILE* controlFile; + /*----------------------------------------------------------------------*/ + /* NO KEEP */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, depDim, indepDim, 1, 0, XPP, YPP); + t01 = myclock(); - /*------------------------------------------------------------------------*/ - /* open file to read */ - if ((controlFile = fopen(controlFileName,"r")) == NULL) { - fprintf(stdout,"ERROR: Could not open control file %s\n", - controlFileName); - exit(-1); + fprintf(stdout, " NO KEEP"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* KEEP */ + t02 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, depDim, indepDim, 1, 2, XPP, YPP); + t03 = myclock(); + + fprintf(stdout, " KEEP "); + fprintf(stdout, TIMEFORMAT, (t03 - t02) * timeUnit, + (t03 - t02) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpFosFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } - /*------------------------------------------------------------------------*/ - /* read all values */ - for (i=0; i hos_forward\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[1 + degree]; + XPP[i][0] = indeps[i]; + for (j = 1; j <= degree; j++) + XPP[i][j] = (double)rand(); } + YPP = new double *[depDim]; + for (i = 0; i < depDim; i++) + YPP[i] = new double[1 + degree]; - if ((degree <= 1) && - (controlParameters[cpHosFW] || controlParameters[cpHovFW] || - controlParameters[cpHosRV] || controlParameters[cpHovRV] || - controlParameters[cpTensor])) { - fprintf(stdout," degree = ? "); - fscanf(stdin,"%d",°ree); - fprintf(stdout,"\n"); + /*----------------------------------------------------------------------*/ + /* NO KEEP */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, depDim, indepDim, degree, 0, XPP, YPP); + t01 = myclock(); + + fprintf(stdout, " NO KEEP"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* KEEP */ + t02 = myclock(); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, depDim, indepDim, degree, keep, XPP, YPP); + t03 = myclock(); + + fprintf(stdout, " KEEP "); + fprintf(stdout, TIMEFORMAT, (t03 - t02) * timeUnit, + (t03 - t02) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpHosFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } - keep = degree + 1; - if ((pFW < 1) && - (controlParameters[cpFovFW] || controlParameters[cpHovFW])) { - fprintf(stdout," # of vectors in vector forward mode = ? "); - fscanf(stdin,"%d",&pFW); - fprintf(stdout,"\n"); + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) + delete[] XPP[i]; + delete[] XPP; + for (i = 0; i < depDim; i++) + delete[] YPP[i]; + delete[] YPP; + } + + /****************************************************************************/ + /* 5. FOV_FORWARD */ + if (controlParameters[cpFovFW]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: forward(tag, m=%d, n=%d, p=%d, x[n], X[n][p], y[m], " + "Y[m][p])\n", + taskCount++, depDim, indepDim, pFW); + fprintf(stdout, " ---> fov_forward\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[pFW]; + for (j = 0; j < pFW; j++) + XPP[i][j] = (double)rand(); } + YP = new double[depDim]; + YPP = new double *[depDim]; + for (i = 0; i < depDim; i++) + YPP[i] = new double[pFW]; + + /*----------------------------------------------------------------------*/ + /* always NO KEEP */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = forward(tag, depDim, indepDim, pFW, indeps, XPP, YP, YPP); + t01 = myclock(); + + fprintf(stdout, " (NO KEEP)"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - if ((pRV < 1) && - (controlParameters[cpFovRV] || controlParameters[cpHovRV])) { - fprintf(stdout," # of vectors in vector reverse mode = ? "); - fscanf(stdin,"%d",&pRV); - fprintf(stdout,"\n"); + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpFovFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } - if ((pTR < 1) && - (controlParameters[cpTensor] || controlParameters[cpInvTensor])) { - fprintf(stdout," # of vectors in tensor mode = ? "); - fscanf(stdin,"%d",&pTR); - fprintf(stdout,"\n"); + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) + delete[] XPP[i]; + delete[] XPP; + delete[] YP; + for (i = 0; i < depDim; i++) + delete[] YPP[i]; + delete[] YPP; + } + + /****************************************************************************/ + /* 6. HOV_FORWARD */ + if (controlParameters[cpHovFW]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: forward(tag, m=%d, n=%d, d=%d, p=%d, x[n], X[n][p][d], " + "y[m], Y[m][p][d])\n", + taskCount++, depDim, indepDim, degree, pFW); + fprintf(stdout, " ---> hov_forward\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + XPPP = new double **[indepDim]; + for (i = 0; i < indepDim; i++) { + XPPP[i] = new double *[pFW]; + for (j = 0; j < pFW; j++) { + XPPP[i][j] = new double[degree]; + for (k = 0; k < degree; k++) + XPPP[i][j][k] = (double)rand(); + } + } + YP = new double[depDim]; + YPPP = new double **[depDim]; + for (i = 0; i < depDim; i++) { + YPPP[i] = new double *[pFW]; + for (j = 0; j < pFW; j++) + YPPP[i][j] = new double[degree]; } - /*------------------------------------------------------------------------*/ - /* Necessary variable */ - double ***XPPP, **XPP; - double ***YPPP, **YPP, *YP; - double ***ZPPP, **ZPP, *ZP; - double **UPP, *UP; - double *VP; - double *WP; - double **JPP; - short **nzPP; - int retVal=0; /* return value */ - double t00, t01, t02, t03; /* time values */ - double **TPP; - double **SPP; - int dim; - - - /****************************************************************************/ - /* 0. ORIGINAL FUNCTION EVALUATION */ - /* ---> always */ - fprintf(stdout,"\nTASK %d: Original function evaluation\n", - taskCount++); + /*----------------------------------------------------------------------*/ + /* always NO KEEP */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = + forward(tag, depDim, indepDim, degree, pFW, indeps, XPPP, YP, YPPP); + t01 = myclock(); + fprintf(stdout, " (NO KEEP)"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpHovFW] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + } + + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) { + for (j = 0; j < pFW; j++) + delete[] XPPP[i][j]; + delete[] XPPP[i]; + } + delete[] XPPP; + delete[] YP; + for (i = 0; i < depDim; i++) { + for (j = 0; j < pFW; j++) + delete[] YPPP[i][j]; + delete[] YPPP[i]; + } + delete[] YPPP; + } + + /****************************************************************************/ + /* 7. FOS_REVERSE */ + if (controlParameters[cpFosRV]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: reverse(tag, m=%d, n=%d, d=0, u[m], Z[n])\n", + taskCount++, depDim, indepDim); + fprintf(stdout, " ---> fos_reverse\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + ZP = new double[indepDim]; + UP = new double[depDim]; + for (i = 0; i < depDim; i++) + UP[i] = (double)rand(); + + /*----------------------------------------------------------------------*/ + /* Forward with keep*/ + forward(tag, depDim, indepDim, 1, indeps, deps); + + /*----------------------------------------------------------------------*/ + /* Reverse */ t00 = myclock(1); - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] ZP; + delete[] UP; + } + + /****************************************************************************/ + /* 8. HOS_REVERSE */ + if (controlParameters[cpHosRV]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: reverse(tag, m=%d, n=%d, d=%d, u[m], Z[n][d+1])\n", + taskCount++, depDim, indepDim, degree); + fprintf(stdout, " ---> hos_reverse\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + ZPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) + ZPP[i] = new double[degree + 1]; + UP = new double[depDim]; + for (i = 0; i < depDim; i++) + UP[i] = (double)rand(); + + XPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + XPP[i] = new double[1 + degree]; + XPP[i][0] = indeps[i]; + for (j = 1; j <= degree; j++) + XPP[i][j] = (double)rand(); + } + YPP = new double *[depDim]; + for (i = 0; i < depDim; i++) + YPP[i] = new double[1 + degree]; - /****************************************************************************/ - /* 1. TAPING THE FUNCTION */ - /* ---> always */ - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: Taping the function\n", - taskCount++); + /*----------------------------------------------------------------------*/ + /* Forward with keep*/ + forward(tag, depDim, indepDim, degree, keep, XPP, YPP); + /*----------------------------------------------------------------------*/ + /* Reverse */ t00 = myclock(1); - /* NOTE: taping will be performed ONCE only */ - tapingVectorFunction(tag,indeps,deps); + for (i = 0; i < evalCount; i++) + retVal = reverse(tag, depDim, indepDim, degree, UP, ZPP); t01 = myclock(); - size_t tape_stats[STAT_SIZE]; - tapestats(tag,tape_stats); - - fprintf(stdout,"\n independents %zu\n",tape_stats[NUM_INDEPENDENTS]); - fprintf(stdout," dependents %zu\n",tape_stats[NUM_DEPENDENTS]); - fprintf(stdout," operations %zu\n",tape_stats[NUM_OPERATIONS]); - fprintf(stdout," operations buffer size %zu\n",tape_stats[OP_BUFFER_SIZE]); - fprintf(stdout," locations buffer size %zu\n",tape_stats[LOC_BUFFER_SIZE]); - fprintf(stdout," constants buffer size %zu\n",tape_stats[VAL_BUFFER_SIZE]); - fprintf(stdout," maxlive %zu\n",tape_stats[NUM_MAX_LIVES]); - fprintf(stdout," valstack size %zu\n\n",tape_stats[TAY_STACK_SIZE]); - - fprintf(stdout," "); - fprintf(stdout,TIMEFORMAT,(t01-t00)*timeUnit*evalCount, - (t01-t00)); - - /****************************************************************************/ - /* 2. ZOS_FORWARD */ - if (controlParameters[cpZosFW]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forward(tag, m=%d, n=%d, keep, X[n], Y[m])\n", - taskCount++,depDim,indepDim); - fprintf(stdout," ---> zos_forward\n"); - - /*----------------------------------------------------------------------*/ - /* NO KEEP */ - t00 = myclock(1); - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - } + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpHosRV] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); + } - /****************************************************************************/ - /* 3. FOS_FORWARD */ - if (controlParameters[cpFosFW]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forward(tag, m=%d, n=%d, d=1, keep, X[n][d+1], Y[m][d+1])\n", - taskCount++,depDim,indepDim); - fprintf(stdout," ---> fos_forward\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - XPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i fov_reverse\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + ZPP = new double *[pRV]; + for (i = 0; i < pRV; i++) + ZPP[i] = new double[indepDim]; + UPP = new double *[pRV]; + for (i = 0; i < pRV; i++) { + UPP[i] = new double[depDim]; + for (j = 0; j < depDim; j++) + UPP[i][j] = (double)rand(); } + /*----------------------------------------------------------------------*/ + /* Forward with keep*/ + forward(tag, depDim, indepDim, 1, indeps, deps); - /****************************************************************************/ - /* 4. HOS_FORWARD */ - if (controlParameters[cpHosFW]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forward(tag, m=%d, n=%d, d=%d, keep, X[n][d+1], Y[m][d+1])\n", - taskCount++,depDim,indepDim,degree); - fprintf(stdout," ---> hos_forward\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - XPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i fov_forward\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - XPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < pRV; i++) + delete[] ZPP[i]; + delete[] ZPP; + for (i = 0; i < pRV; i++) + delete[] UPP[i]; + delete[] UPP; + } + + /****************************************************************************/ + /* 10. HOV_REVERSE */ + if (controlParameters[cpHovRV]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: reverse(tag, m=%d, n=%d, d=%d, p=%d, U[p][m], " + "Z[p][n][d+1], nz[p][n])\n", + taskCount++, depDim, indepDim, degree, pRV); + fprintf(stdout, " ---> hov_reverse\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + ZPPP = new double **[pRV]; + for (i = 0; i < pRV; i++) { + ZPPP[i] = new double *[indepDim]; + for (j = 0; j < indepDim; j++) + ZPPP[i][j] = new double[degree + 1]; + } + UPP = new double *[pRV]; + for (i = 0; i < pRV; i++) { + UPP[i] = new double[depDim]; + for (j = 0; j < depDim; j++) + UPP[i][j] = (double)rand(); + } - /****************************************************************************/ - /* 6. HOV_FORWARD */ - if (controlParameters[cpHovFW]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: forward(tag, m=%d, n=%d, d=%d, p=%d, x[n], X[n][p][d], y[m], Y[m][p][d])\n", - taskCount++,depDim,indepDim,degree,pFW); - fprintf(stdout," ---> hov_forward\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - XPPP = new double**[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i fos_reverse\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - ZP = new double[indepDim]; - UP = new double[depDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] ZP; - delete[] UP; - } + /*----------------------------------------------------------------------*/ + /* Reverse with nonzero pattern*/ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = reverse(tag, depDim, indepDim, degree, pRV, UPP, ZPPP, nzPP); + t01 = myclock(); + fprintf(stdout, " (NZ)"); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 8. HOS_REVERSE */ - if (controlParameters[cpHosRV]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: reverse(tag, m=%d, n=%d, d=%d, u[m], Z[n][d+1])\n", - taskCount++,depDim,indepDim,degree); - fprintf(stdout," ---> hos_reverse\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - ZPP = new double*[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } - - /****************************************************************************/ - /* 9. FOV_REVERSE */ - if (controlParameters[cpFovRV]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: reverse(tag, m=%d, n=%d, d=0, p=%d, U[p][m], Z[p][n])\n", - taskCount++,depDim,indepDim,pRV); - fprintf(stdout," ---> fov_reverse\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - ZPP = new double*[pRV]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i hov_reverse\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - ZPPP = new double**[pRV]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + } + + /****************************************************************************/ + /* 12. JACOBIAN */ + if (controlParameters[cpJacobian]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: jacobian(tag, m=%d, n=%d, X[n], J[m][n])\n", + taskCount++, depDim, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + JPP = new double *[depDim]; + for (i = 0; i < depDim; i++) + JPP[i] = new double[indepDim]; + + /*----------------------------------------------------------------------*/ + /* Gradient evaluation */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = jacobian(tag, depDim, indepDim, indeps, JPP); + t01 = myclock(); + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 11. FUNCTION */ - if (controlParameters[cpFunction]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: function(tag, m=%d, n=%d, X[n], Y[m])\n", - taskCount++,depDim,indepDim); - - /*----------------------------------------------------------------------*/ - /* Function evaluation */ - t00 = myclock(1); - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpJacobian] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < depDim; i++) + delete[] JPP[i]; + delete[] JPP; + } + + /****************************************************************************/ + /* 13. VECJAC */ + if (controlParameters[cpVecJac]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: vec_jac(tag, m=%d, n=%d, repeat, X[n], U[m], V[n])\n", + taskCount++, depDim, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + UP = new double[depDim]; + for (i = 0; i < depDim; i++) + UP[i] = (double)rand(); + VP = new double[indepDim]; + + /*----------------------------------------------------------------------*/ + /* Evaluation without repeat */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = vec_jac(tag, depDim, indepDim, 0, indeps, UP, VP); + t01 = myclock(); - /****************************************************************************/ - /* 12. JACOBIAN */ - if (controlParameters[cpJacobian]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: jacobian(tag, m=%d, n=%d, X[n], J[m][n])\n", - taskCount++,depDim,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - JPP = new double*[depDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] UP; - delete[] VP; + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpVecJac] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] UP; + delete[] VP; + } + + /****************************************************************************/ + /* 14. JACVEC */ + if (controlParameters[cpJacVec]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, "\nTASK %d: jac_vec(tag, m=%d, n=%d, X[n], V[n], U[m])\n", + taskCount++, depDim, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + UP = new double[depDim]; + VP = new double[indepDim]; + for (i = 0; i < indepDim; i++) + VP[i] = (double)rand(); + + /*----------------------------------------------------------------------*/ + /* Evaluation */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = jac_vec(tag, depDim, indepDim, indeps, VP, UP); + t01 = myclock(); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 14. JACVEC */ - if (controlParameters[cpJacVec]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: jac_vec(tag, m=%d, n=%d, X[n], V[n], U[m])\n", - taskCount++,depDim,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - UP = new double[depDim]; - VP = new double[indepDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] UP; - delete[] VP; + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpJacVec] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] UP; + delete[] VP; + } + + /****************************************************************************/ + /* 15. LAGHESSVEC */ + if (controlParameters[cpLagHessVec]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf( + stdout, + "\nTASK %d: lagra_hess_vec(tag, m=%d, n=%d, X[n], U[m], V[n], W[n])\n", + taskCount++, depDim, indepDim); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + UP = new double[depDim]; + for (i = 0; i < depDim; i++) + UP[i] = (double)rand(); + VP = new double[indepDim]; + for (i = 0; i < indepDim; i++) + VP[i] = (double)rand(); + WP = new double[indepDim]; + + /*----------------------------------------------------------------------*/ + /* Evaluation */ + t00 = myclock(1); + for (i = 0; i < evalCount; i++) + retVal = lagra_hess_vec(tag, depDim, indepDim, indeps, UP, VP, WP); + t01 = myclock(); + + fprintf(stdout, " "); + fprintf(stdout, TIMEFORMAT, (t01 - t00) * timeUnit, + (t01 - t00) / evalCount); - /****************************************************************************/ - /* 15. LAGHESSVEC */ - if (controlParameters[cpLagHessVec]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: lagra_hess_vec(tag, m=%d, n=%d, X[n], U[m], V[n], W[n])\n", - taskCount++,depDim,indepDim); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - UP = new double[depDim]; - for (i=0; i 1) { - fprintf(stdout,"\n Return value: %d\n",retVal); - } - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - delete[] VP; - delete[] WP; - delete[] UP; + /*----------------------------------------------------------------------*/ + /* Debug infos */ + if (controlParameters[cpLagHessVec] > 1) { + fprintf(stdout, "\n Return value: %d\n", retVal); } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + delete[] VP; + delete[] WP; + delete[] UP; + } + + /****************************************************************************/ + /* 16. TENSOR */ + if (controlParameters[cpTensor]) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: tensor_eval(tag, m =%d, n=%d, d=%d, p=%d, X[n], " + "tensor[m][dim], S[n][p])\n", + taskCount++, depDim, indepDim, degree, pTR); + fprintf(stdout, "\n dim = ((p+d) over d)\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + dim = binomi(pTR + degree, degree); + TPP = new double *[depDim]; + for (i = 0; i < depDim; i++) + TPP[i] = new double[dim]; + SPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + SPP[i] = new double[pTR]; + for (j = 0; j < pTR; j++) + SPP[i][j] = (i == j) ? 1.0 : 0.0; + } - /****************************************************************************/ - /* 16. TENSOR */ - if (controlParameters[cpTensor]) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: tensor_eval(tag, m =%d, n=%d, d=%d, p=%d, X[n], tensor[m][dim], S[n][p])\n", - taskCount++,depDim,indepDim,degree, pTR); - fprintf(stdout,"\n dim = ((p+d) over d)\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - dim = binomi(pTR+degree,degree); - TPP = new double*[depDim]; - for (i=0; i 1) {} - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { } + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < depDim; i++) + delete[] TPP[i]; + delete[] TPP; + for (i = 0; i < indepDim; i++) + delete[] SPP[i]; + delete[] SPP; + } + + /****************************************************************************/ + /* 17. INVERSE TENSOR */ + if (controlParameters[cpInvTensor] && (depDim == indepDim)) { + fprintf(stdout, "--------------------------------------------------------"); + fprintf(stdout, + "\nTASK %d: inverse_tensor_eval(tag, m=n=%d, d=%d, p=%d, X[n], " + "tensor[n][dim], S[n][p])\n", + taskCount++, indepDim, degree, pTR); + fprintf(stdout, "\n dim = ((p+d) over d)\n"); + + /*----------------------------------------------------------------------*/ + /* Allocation & initialisation of tensors */ + dim = binomi(pTR + degree, degree); + TPP = new double *[indepDim]; + for (i = 0; i < depDim; i++) + TPP[i] = new double[dim]; + SPP = new double *[indepDim]; + for (i = 0; i < indepDim; i++) { + SPP[i] = new double[pTR]; + for (j = 0; j < pTR; j++) + SPP[i][j] = (i == j) ? 1.0 : 0.0; + } - /****************************************************************************/ - /* 17. INVERSE TENSOR */ - if (controlParameters[cpInvTensor] && (depDim==indepDim)) { - fprintf(stdout,"--------------------------------------------------------"); - fprintf(stdout,"\nTASK %d: inverse_tensor_eval(tag, m=n=%d, d=%d, p=%d, X[n], tensor[n][dim], S[n][p])\n", - taskCount++,indepDim,degree, pTR); - fprintf(stdout,"\n dim = ((p+d) over d)\n"); - - /*----------------------------------------------------------------------*/ - /* Allocation & initialisation of tensors */ - dim = binomi(pTR+degree,degree); - TPP = new double*[indepDim]; - for (i=0; i 1) {} - - /*----------------------------------------------------------------------*/ - /* Free tensors */ - for (i=0; i 1) { } - return 1; + /*----------------------------------------------------------------------*/ + /* Free tensors */ + for (i = 0; i < indepDim; i++) + delete[] TPP[i]; + delete[] TPP; + for (i = 0; i < indepDim; i++) + delete[] SPP[i]; + delete[] SPP; + } + + return 1; } #undef _VGENMAIN_C_ - diff --git a/ADOL-C/examples/detexam.cpp b/ADOL-C/examples/detexam.cpp index cb5fb9af1..bfd586cb9 100644 --- a/ADOL-C/examples/detexam.cpp +++ b/ADOL-C/examples/detexam.cpp @@ -4,21 +4,21 @@ Revision: $Id$ Contents: computation of determinants, described in the manual - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include // use of active doubles -#include // use of basic forward/reverse +#include // use of active doubles +#include // use of basic forward/reverse // interfaces of ADOL-C -#include // use of taping +#include // use of taping #include using namespace std; @@ -26,89 +26,90 @@ using namespace std; /****************************************************************************/ /* ADOUBLE ROUTINE */ int n; -adouble **A; // A is an n x n matrix +adouble **A; // A is an n x n matrix adouble zero = 0; -adouble det(int k, int m) // k <= n is the order of the submatrix -{ if (m == 0) // its column indices - return 1.0; - else // are encoded in m - { - adouble *pt = A[k-1]; - adouble t = zero; - int p = 1; - int s; - if (k%2) - s = 1; - else - s = -1; - for(int i=0; i= p) { - if (m == p) { - if (s>0) - t += *pt; - else - t -= *pt; - } else { - if (s>0) - t += *pt*det(k-1, m-p); // recursive call to det - else - t -= *pt*det(k-1, m-p); // recursive call to det - } - s = -s; - } - ++pt; - p = p1; +adouble det(int k, int m) // k <= n is the order of the submatrix +{ + if (m == 0) // its column indices + return 1.0; + else // are encoded in m + { + adouble *pt = A[k - 1]; + adouble t = zero; + int p = 1; + int s; + if (k % 2) + s = 1; + else + s = -1; + for (int i = 0; i < n; i++) { + int p1 = 2 * p; + if (m % p1 >= p) { + if (m == p) { + if (s > 0) + t += *pt; + else + t -= *pt; + } else { + if (s > 0) + t += *pt * det(k - 1, m - p); // recursive call to det + else + t -= *pt * det(k - 1, m - p); // recursive call to det } - return t; + s = -s; + } + ++pt; + p = p1; } + return t; + } } /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i,j, m = 1; - int tag = 1; - int keep = 1; + int i, j, m = 1; + int tag = 1; + int keep = 1; - cout << "COMPUTATION OF DETERMINANTS (ADOL-C Documented Example)\n\n"; - cout << "order of matrix = ? \n"; // select matrix size - cin >> n; + cout << "COMPUTATION OF DETERMINANTS (ADOL-C Documented Example)\n\n"; + cout << "order of matrix = ? \n"; // select matrix size + cin >> n; - A = new adouble*[n]; - adouble ad; + A = new adouble *[n]; + adouble ad; - trace_on(tag,keep); // tag=1=keep - double detout = 0.0, diag = 1.0;// here keep the intermediates for - for (i=0; i>= detout; - printf("\n %f - %f = %f (should be 0)\n",detout,diag,detout-diag); - trace_off(); + trace_on(tag, keep); // tag=1=keep + double detout = 0.0, diag = 1.0; // here keep the intermediates for + for (i = 0; i < n; i++) // the subsequent call to reverse + { + m *= 2; + A[i] = new adouble[n]; + for (j = 0; j < n; j++) + A[i][j] <<= j / (1.0 + i); // make all elements of A independent + diag += A[i][i].value(); // value(adouble) converts to double + A[i][i] += 1.0; + } + ad = det(n, m - 1); // actual function call. + ad >>= detout; + printf("\n %f - %f = %f (should be 0)\n", detout, diag, detout - diag); + trace_off(); - double u[1]; - u[0] = 1.0; - double* B = new double[n*n]; + double u[1]; + u[0] = 1.0; + double *B = new double[n * n]; - reverse(tag,1,n*n,0,u,B); // call reverse to calculate the gradient + reverse(tag, 1, n * n, 0, u, B); // call reverse to calculate the gradient - cout << " \n first base? : "; - for (i=0; i #include #include -#include #include +#include -#include -#include #include +#include #include +#include #include using namespace std; -adouble findmaxindex(const size_t n, const advector& col, const size_t k) { - adouble idx = k; - for (size_t j = k + 1; j < n; j++ ) - condassign(idx,(fabs(col[j]) - fabs(col[idx])), adouble((double)j)); - return idx; +adouble findmaxindex(const size_t n, const advector &col, const size_t k) { + adouble idx = k; + for (size_t j = k + 1; j < n; j++) + condassign(idx, (fabs(col[j]) - fabs(col[idx])), adouble((double)j)); + return idx; } // Assuming A is stored row-wise in the vector -void lufactorize(const size_t n, advector& A, advector& p) { - adouble idx, tmp; +void lufactorize(const size_t n, advector &A, advector &p) { + adouble idx, tmp; + for (size_t j = 0; j < n; j++) + p[j] = j; + for (size_t k = 0; k < n; k++) { + advector column(n); for (size_t j = 0; j < n; j++) - p[j] = j; - for (size_t k = 0; k < n; k++) { - advector column(n); - for(size_t j = 0; j < n; j++) - condassign(column[j], adouble(double(j - k + 1)), A[j*n + k]); - idx = findmaxindex(n, column, k); - tmp = p[k]; - p[k] = p[idx]; - p[idx] = tmp; - for(size_t j = 0; j < n; j++) { - tmp = A[k*n + j]; - A[k*n + j] = A[idx*n + j]; - A[idx*n + j] = tmp; - } - tmp = 1.0/A[k*n + k]; - for (size_t i = k + 1; i < n; i++) { - A[i*n + k] *= tmp; - for (size_t j = k + 1; j < n; j++) { - A[i*n + j] -= A[i*n + k] * A[k*n+j]; - } - } + condassign(column[j], adouble(double(j - k + 1)), A[j * n + k]); + idx = findmaxindex(n, column, k); + tmp = p[k]; + p[k] = p[idx]; + p[idx] = tmp; + for (size_t j = 0; j < n; j++) { + tmp = A[k * n + j]; + A[k * n + j] = A[idx * n + j]; + A[idx * n + j] = tmp; } + tmp = 1.0 / A[k * n + k]; + for (size_t i = k + 1; i < n; i++) { + A[i * n + k] *= tmp; + for (size_t j = k + 1; j < n; j++) { + A[i * n + j] -= A[i * n + k] * A[k * n + j]; + } + } + } } -void Lsolve(const size_t n, const advector& A, const advector& p, advector& b, advector& x) { - for (size_t j = 0; j < n; j++) { - x[j] = b[p[j]]; - for (size_t k = j+1; k = i) - outf << setw(8) << A[i*n + j].value() << " "; - else - outf << setw(8) << 0.0 << " "; - outf << "\n"; - } +void printR(const size_t n, const advector &A, ostream &outf = std::cout) { + for (size_t i = 0; i < n; i++) { + for (size_t j = 0; j < n; j++) + if (j >= i) + outf << setw(8) << A[i * n + j].value() << " "; + else + outf << setw(8) << 0.0 << " "; + outf << "\n"; + } } -double norm2(const double *const v, const size_t n) -{ - size_t j; - double abs,scale,sum; - scale=0.0; - sum=0.0; - for (j=0; j> n; - - cout << "---------------------------------\nNow tracing:\n"; - rhs = new double[n*n + n]; - mat = rhs + n; - ans = new double[n]; - cout << "file name for matrix = ?\n"; - cin >> matrixname; - cout << "file name for rhs = ?\n"; - cin >> rhsname; - - - matf.open(matrixname.c_str()); - for (size_t i = 0; i < n*n; i++) - matf >> mat[i]; - matf.close(); - - rhsf.open(rhsname.c_str()); + int tag = 1; + int keep = 1; + int n; + string matrixname, rhsname; + ifstream matf, rhsf; + double *mat, *rhs, *ans, err, normx, normb; + + cout << "COMPUTATION OF LU-Factorization with pivoting (ADOL-C Documented " + "Example)\n\n"; + cout << "order of matrix = ? \n"; // select matrix size + cin >> n; + + cout << "---------------------------------\nNow tracing:\n"; + rhs = new double[n * n + n]; + mat = rhs + n; + ans = new double[n]; + cout << "file name for matrix = ?\n"; + cin >> matrixname; + cout << "file name for rhs = ?\n"; + cin >> rhsname; + + matf.open(matrixname.c_str()); + for (size_t i = 0; i < n * n; i++) + matf >> mat[i]; + matf.close(); + + rhsf.open(rhsname.c_str()); + for (size_t i = 0; i < n; i++) + rhsf >> rhs[i]; + rhsf.close(); + + { + trace_on(tag, keep); // tag=1=keep + advector A(n * n), b(n), x(n), p(n); for (size_t i = 0; i < n; i++) - rhsf >> rhs[i]; - rhsf.close(); - - { - trace_on(tag,keep); // tag=1=keep - advector A(n*n), b(n), x(n), p(n); - for(size_t i = 0; i < n; i++) - b[i] <<= rhs[i]; - for(size_t i = 0; i < n*n; i++) - A[i] <<= mat[i]; - lufactorize(n, A, p); - Lsolve(n, A, p, b, x); - Rsolve(n, A, x); - for(size_t i = 0; i < n; i++) - x[i] >>= ans[i]; - trace_off(); - } - - err = normresidue(mat, n, rhs, n, ans); - normb = norm2(rhs, n); - normx = norm2(ans, n); - cout << "Norm rhs = " << normb <<"\n"; - cout << "Norm solution = " << normx <<"\n"; - cout << "Norm of residue = " << err <<"\t relative error = " << err/normx << "\n"; - - cout << "---------------------------------\nNow computing from trace:\n"; - cout << "file name for matrix = ?\n"; - cin >> matrixname; - cout << "file name for rhs = ?\n"; - cin >> rhsname; - - - matf.open(matrixname.c_str()); - for (size_t i = 0; i < n*n; i++) - matf >> mat[i]; - matf.close(); - - rhsf.open(rhsname.c_str()); + b[i] <<= rhs[i]; + for (size_t i = 0; i < n * n; i++) + A[i] <<= mat[i]; + lufactorize(n, A, p); + Lsolve(n, A, p, b, x); + Rsolve(n, A, x); for (size_t i = 0; i < n; i++) - rhsf >> rhs[i]; - rhsf.close(); - - zos_forward(tag, n, n*n + n, keep, rhs, ans); - - err = normresidue(mat, n, rhs, n, ans); - normb = norm2(rhs, n); - normx = norm2(ans, n); - cout << "Norm rhs = " << normb <<"\n"; - cout << "Norm solution = " << normx <<"\n"; - cout << "Norm of residue = " << err <<"\t relative error = " << err/normx <<"\n"; - double *ansbar = new double[n]; - double *matcol = new double[n]; - double *rhsbar = new double[n*n+n]; - double *matbar = rhsbar + n; - double scprod = 0.0; - - memset(rhsbar, 0, (n*n+n)*sizeof(double)); - memset(ansbar, 0, n*sizeof(double)); - for (size_t k = 0; k < n; k++) { - cout << "computing gradient of element " << k + 1 << " of solution w.r.t. matrix elements and rhs\n"; + x[i] >>= ans[i]; + trace_off(); + } + + err = normresidue(mat, n, rhs, n, ans); + normb = norm2(rhs, n); + normx = norm2(ans, n); + cout << "Norm rhs = " << normb << "\n"; + cout << "Norm solution = " << normx << "\n"; + cout << "Norm of residue = " << err << "\t relative error = " << err / normx + << "\n"; + + cout << "---------------------------------\nNow computing from trace:\n"; + cout << "file name for matrix = ?\n"; + cin >> matrixname; + cout << "file name for rhs = ?\n"; + cin >> rhsname; + + matf.open(matrixname.c_str()); + for (size_t i = 0; i < n * n; i++) + matf >> mat[i]; + matf.close(); + + rhsf.open(rhsname.c_str()); + for (size_t i = 0; i < n; i++) + rhsf >> rhs[i]; + rhsf.close(); + + zos_forward(tag, n, n * n + n, keep, rhs, ans); + + err = normresidue(mat, n, rhs, n, ans); + normb = norm2(rhs, n); + normx = norm2(ans, n); + cout << "Norm rhs = " << normb << "\n"; + cout << "Norm solution = " << normx << "\n"; + cout << "Norm of residue = " << err << "\t relative error = " << err / normx + << "\n"; + double *ansbar = new double[n]; + double *matcol = new double[n]; + double *rhsbar = new double[n * n + n]; + double *matbar = rhsbar + n; + double scprod = 0.0; + + memset(rhsbar, 0, (n * n + n) * sizeof(double)); + memset(ansbar, 0, n * sizeof(double)); + for (size_t k = 0; k < n; k++) { + cout << "computing gradient of element " << k + 1 + << " of solution w.r.t. matrix elements and rhs\n"; ansbar[k] = 1.0; - fos_reverse(tag, n, n*n+n, ansbar, rhsbar); + fos_reverse(tag, n, n * n + n, ansbar, rhsbar); - for (size_t i = 0; i < n*n + n; i++) - cout << "bar[" << i << "] = " << rhsbar[i] << "\n"; + for (size_t i = 0; i < n * n + n; i++) + cout << "bar[" << i << "] = " << rhsbar[i] << "\n"; for (size_t j = 0; j < n; j++) { - for (size_t i = 0; i < n; i++) - matcol[i] = mat[i*n + j]; - scprod = scalar(rhsbar, matcol, n); - cout << "gradient w.r.t. rhs times column " << j + 1 << " of matrix = " << scprod << "\n"; + for (size_t i = 0; i < n; i++) + matcol[i] = mat[i * n + j]; + scprod = scalar(rhsbar, matcol, n); + cout << "gradient w.r.t. rhs times column " << j + 1 + << " of matrix = " << scprod << "\n"; } ansbar[k] = 0.0; - } - delete[] ansbar; - delete[] matcol; - delete[] rhsbar; + } + delete[] ansbar; + delete[] matcol; + delete[] rhsbar; - delete[] rhs; - delete[] ans; + delete[] rhs; + delete[] ans; } diff --git a/ADOL-C/examples/odexam.cpp b/ADOL-C/examples/odexam.cpp index d8ba4f46a..b7716094e 100644 --- a/ADOL-C/examples/odexam.cpp +++ b/ADOL-C/examples/odexam.cpp @@ -5,20 +5,20 @@ Contents: Nonlinear ordinary differential equation based on the Robertson test problem, described in the manual - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ +#include // use of ADOL-C allocation utilities #include // use of active double #include // use of "Easy To Use" ODE drivers -#include // use of ADOL-C allocation utilities #include // use of taping // NOTICE: If one wants to include all ADOL-C interfaces without @@ -33,63 +33,67 @@ using namespace std; /****************************************************************************/ /* ADOUBLE ROUTINE */ -void tracerhs(short int tag, double* py, double* pyprime) { - adouble y[3]; // we left the parameters passive - adouble yprime[3]; - - trace_on(tag); - y[0] <<= py[0]; y[1] <<= py[1]; y[2] <<= py[2]; // initialize and mark independents - yprime[0] = -sin(y[2]) + 1.0e8*y[2]*(1.0-1.0/y[0]); - yprime[1] = -10.0*y[0] + 3.0e7*y[2]*(1-y[1]); - yprime[2] = -yprime[0] - yprime[1]; - yprime[0] >>= pyprime[0]; yprime[1] >>= pyprime[1]; yprime[2] >>= pyprime[2]; // mark and pass dependents - trace_off(1); // write tape array onto a file +void tracerhs(short int tag, double *py, double *pyprime) { + adouble y[3]; // we left the parameters passive + adouble yprime[3]; + + trace_on(tag); + y[0] <<= py[0]; + y[1] <<= py[1]; + y[2] <<= py[2]; // initialize and mark independents + yprime[0] = -sin(y[2]) + 1.0e8 * y[2] * (1.0 - 1.0 / y[0]); + yprime[1] = -10.0 * y[0] + 3.0e7 * y[2] * (1 - y[1]); + yprime[2] = -yprime[0] - yprime[1]; + yprime[0] >>= pyprime[0]; + yprime[1] >>= pyprime[1]; + yprime[2] >>= pyprime[2]; // mark and pass dependents + trace_off(1); // write tape array onto a file } // end tracerhs /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i,j,deg; - int n = 3; - double py[3]; - double pyp[3]; - - cout << "MODIFIED ROBERTSON TEST PROBLEM (ADOL-C Documented Example)\n\n"; - cout << "degree of Taylor series =?\n"; - cin >> deg; - - short** nz = new short*[n]; - double **X; - double ***Z; - double ***B; - - X = myalloc2(n,deg+1); - Z = myalloc3(n,n,deg); - B = myalloc3(n,n,deg); - - for(i=0; i> deg; + + short **nz = new short *[n]; + double **X; + double ***Z; + double ***B; + + X = myalloc2(n, deg + 1); + Z = myalloc3(n, n, deg); + B = myalloc3(n, n, deg); + + for (i = 0; i < n; i++) { + py[i] = (i == 0) ? 1.0 : 0.0; // Initialize the base point + X[i][0] = py[i]; // and the Taylor coefficient; + nz[i] = new short[n]; // set up sparsity array + } // end for + + tracerhs(1, py, pyp); // trace RHS with tag = 1 + + forode(1, n, deg, X); // compute deg coefficients + reverse(1, n, n, deg - 1, Z, nz); // U defaults to the identity + accode(n, deg - 1, Z, B, nz); + + cout << "nonzero pattern:\n"; + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) + cout << nz[i][j] << "\t"; cout << "\n"; - cout << " 4 = transcend , 3 = rational , 2 = polynomial ," - << " 1 = linear , 0 = zero \n"; - cout << " negative number k indicate that entries of all" - << " B_j with j < -k vanish \n"; + } // end for + cout << "\n"; + cout << " 4 = transcend , 3 = rational , 2 = polynomial ," + << " 1 = linear , 0 = zero \n"; + cout << " negative number k indicate that entries of all" + << " B_j with j < -k vanish \n"; - return 1; + return 1; } // end main diff --git a/ADOL-C/examples/powexam.cpp b/ADOL-C/examples/powexam.cpp index 288826c2b..76bb3083f 100644 --- a/ADOL-C/examples/powexam.cpp +++ b/ADOL-C/examples/powexam.cpp @@ -4,18 +4,18 @@ Revision: $Id$ Contents: computation of n-th power, described in the manual - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include /* use of ALL ADOL-C interfaces */ +#include /* use of ALL ADOL-C interfaces */ #include using namespace std; @@ -23,68 +23,69 @@ using namespace std; /****************************************************************************/ /* ADOUBLE ROUTINE */ adouble power(adouble x, int n) { - adouble z = 1; + adouble z = 1; - if (n>0) /* Recursion and branches */ - { int nh = n/2; /* that do not depend on */ - z = power(x,nh); /* adoubles are fine !!!! */ - z *= z; - if (2*nh != n) - z *= x; - return z; - } /* end if */ - else { - if (n==0) /* The local adouble z dies */ - return z; /* as it goes out of scope. */ - else - return 1/power(x,-n); - } /* end else */ + if (n > 0) /* Recursion and branches */ + { + int nh = n / 2; /* that do not depend on */ + z = power(x, nh); /* adoubles are fine !!!! */ + z *= z; + if (2 * nh != n) + z *= x; + return z; + } /* end if */ + else { + if (n == 0) /* The local adouble z dies */ + return z; /* as it goes out of scope. */ + else + return 1 / power(x, -n); + } /* end else */ } /* end power */ /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i,tag = 1; - int n; + int i, tag = 1; + int n; - cout << "COMPUTATION OF N-TH POWER (ADOL-C Documented Example)\n\n"; - cout << "monomial degree=? \n"; /* input the desired degree */ - cin >> n; - /* allocations and initializations */ - double** X; - double** Y; - X = myalloc2(1,n+4); - Y = myalloc2(1,n+4); - X[0][0] = 0.5; /* function value = 0. coefficient */ - X[0][1] = 1.0; /* first derivative = 1. coefficient */ - for(i=0; i> n; + /* allocations and initializations */ + double **X; + double **Y; + X = myalloc2(1, n + 4); + Y = myalloc2(1, n + 4); + X[0][0] = 0.5; /* function value = 0. coefficient */ + X[0][1] = 1.0; /* first derivative = 1. coefficient */ + for (i = 0; i < n + 2; i++) + X[0][i + 2] = 0; /* further coefficients */ + double **Z; /* used for checking consistency */ + Z = myalloc2(1, n + 2); /* between forward and reverse */ - adouble y,x; /* declare active variables */ - /* beginning of active section */ - trace_on(tag); /* tag = 1 and keep = 0 */ - x <<= X[0][0]; /* only one independent var */ - y = power(x,n); /* actual function call */ - y >>= Y[0][0]; /* only one dependent adouble */ - trace_off(); /* no global adouble has died */ - /* end of active section */ - double u[1]; /* weighting vector */ - u[0]=1; /* for reverse call */ - for(i=0; i>= Y[0][0]; /* only one dependent adouble */ + trace_off(); /* no global adouble has died */ + /* end of active section */ + double u[1]; /* weighting vector */ + u[0] = 1; /* for reverse call */ + for (i = 0; i < n + 2; i++) /* note that keep = i+1 in call */ + { + forward(tag, 1, 1, i, i + 1, X, Y); /* evaluate the i-the derivative */ + if (i == 0) + cout << Y[0][i] << " - " << y.value() << " = " << Y[0][i] - y.value() + << " (should be 0)\n"; + else { + Z[0][i] = Z[0][i - 1] / i; /* scale derivative to Taylorcoeff. */ + cout << Y[0][i] << " - " << Z[0][i] << " = " << Y[0][i] - Z[0][i] + << " (should be 0)\n"; + } + reverse(tag, 1, 1, i, u, Z); /* evaluate the (i+1)-st deriv. */ + } /* end for */ - return 1; + return 1; } /* end main */ - diff --git a/ADOL-C/examples/speelpenning.cpp b/ADOL-C/examples/speelpenning.cpp index 230c62ad1..11ea6b743 100644 --- a/ADOL-C/examples/speelpenning.cpp +++ b/ADOL-C/examples/speelpenning.cpp @@ -4,21 +4,21 @@ Revision: $Id$ Contents: speelpennings example, described in the manual - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include // use of active doubles -#include // use of "Easy to Use" drivers +#include // use of active doubles +#include // use of "Easy to Use" drivers // gradient(.) and hessian(.) -#include // use of taping +#include // use of taping #include using namespace std; @@ -29,55 +29,54 @@ using namespace std; /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int n,i,j; - size_t tape_stats[STAT_SIZE]; + int n, i, j; + size_t tape_stats[STAT_SIZE]; - cout << "SPEELPENNINGS PRODUCT (ADOL-C Documented Example)\n\n"; - cout << "number of independent variables = ? \n"; - cin >> n; + cout << "SPEELPENNINGS PRODUCT (ADOL-C Documented Example)\n\n"; + cout << "number of independent variables = ? \n"; + cin >> n; - double *xp = new double[n]; - double yp = 0.0; - adouble *x = new adouble[n]; - adouble y = 1; + double *xp = new double[n]; + double yp = 0.0; + adouble *x = new adouble[n]; + adouble y = 1; - for(i=0; i>= yp; - delete[] x; - trace_off(1); + trace_on(1); // tag = 1, keep = 0 by default + for (i = 0; i < n; i++) { + x[i] <<= xp[i]; // or x <<= xp outside the loop + y *= x[i]; + } // end for + y >>= yp; + delete[] x; + trace_off(1); - tapestats(1,tape_stats); // reading of tape statistics - cout<<"maxlive "<j) // lower half of hessian - errh += fabs(H[i][j]-g[i]/xp[j]); - } // end for + double **H = (double **)malloc(n * sizeof(double *)); + for (i = 0; i < n; i++) + H[i] = (double *)malloc((i + 1) * sizeof(double)); + hessian(1, n, xp, H); // H equals (n-1)g since g is + double errg = 0; // homogeneous of degree n-1. + double errh = 0; + for (i = 0; i < n; i++) + errg += fabs(g[i] - yp / xp[i]); // vanishes analytically. + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i > j) // lower half of hessian + errh += fabs(H[i][j] - g[i] / xp[j]); } // end for - cout << yp-1/(1.0+n) << " error in function \n"; - cout << errg <<" error in gradient \n"; - cout << errh <<" consistency check \n"; + } // end for + cout << yp - 1 / (1.0 + n) << " error in function \n"; + cout << errg << " error in gradient \n"; + cout << errh << " consistency check \n"; - return 0; + return 0; } // end main - diff --git a/ADOL-C/examples/traceless_higher_order.cpp b/ADOL-C/examples/traceless_higher_order.cpp index b11d514a0..bf0f07893 100644 --- a/ADOL-C/examples/traceless_higher_order.cpp +++ b/ADOL-C/examples/traceless_higher_order.cpp @@ -7,125 +7,117 @@ described in the manual Copyright (c) Andrea Walther, Andreas Kowarz, Benjamin Jurgelucks - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - ----------------------------------------------------------------------------*/ +---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ #define ADOLC_TRACELESS_HIGHER_ORDER -//#include -//typedef adhotl::adouble adouble; -#include +// #include +// typedef adhotl::adouble adouble; #include - +#include #include typedef adtl_hov::adouble adouble; - - - using namespace std; -adouble poly (adouble* z){ +adouble poly(adouble *z) { adouble y; - y =exp(z[0])*log(pow(z[0],2.0)); + y = exp(z[0]) * log(pow(z[0], 2.0)); return y; } -double poly (double* z){ +double poly(double *z) { double y; - y = exp(z[0])*log(pow(z[0],2.0)); + y = exp(z[0]) * log(pow(z[0], 2.0)); return y; } -adouble higher_order(adouble* z) -{ - double a=1.0; +adouble higher_order(adouble *z) { + double a = 1.0; adouble y; - y=z[0]*exp(a*z[0]); + y = z[0] * exp(a * z[0]); return y; } -double higher_order(double* z) -{ - double a=1.0; - double y; - y=z[0]*exp(a*z[0]); +double higher_order(double *z) { + double a = 1.0; + double y; + y = z[0] * exp(a * z[0]); return y; } -double higher_order_analytic(double* z, int n) -{ - double a=1.0; - double y; - y=exp(a*z[0])*(n*pow(a,n-1)+pow(a,n)*z[0]); +double higher_order_analytic(double *z, int n) { + double a = 1.0; + double y; + y = exp(a * z[0]) * (n * pow(a, n - 1) + pow(a, n) * z[0]); return y; } -int factorial(int n) -{ - return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; -} - +int factorial(int n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; } -int main(){ - int d=12, n=3; +int main() { + int d = 12, n = 3; cout << "Degree of derivative (precise up to degree 12): "; cin >> d; cout << endl; - + double one[1]; - one[0]=1; - - //number of Taylor coefficients y_i + one[0] = 1; + + // number of Taylor coefficients y_i adtl_hov::setDegree(d); - - adouble* z = new adouble[n]; + + adouble *z = new adouble[n]; adouble y; - double* dz = new double[n]; + double *dz = new double[n]; double dy; - - //initialization of independent variables - for(int i=0; i typedef adtl::adouble adouble; - int main(int argc, char *argv[]) { - adouble x[3], y[3]; - - for (int i=0; i<3;++i) // Initialize x_i - x[i] = i + 1.0; - - cout << endl << "Compute transform from Cartesian to spherical polar coordinates" << endl << endl; - - // derivative of y with respect to x0 - double one=1.0; - x[0].setADValue(&one); - - y[0] = sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]); - y[1] = atan(sqrt(x[0]*x[0]+x[1]*x[1])/x[2]); - y[2] = atan(x[1]/x[0]); - - cout << "cartesian coordinates: " << endl; - cout << "x[0] = " << x[0].getValue() << " x[1] = " << x[1].getValue() - << " x[2] = " << x[2].getValue() << endl << endl; - cout << "cpherical polar coordinates: " << endl; - cout << "y[0] = " << y[0].getValue() << " y[1] = " << y[1].getValue() - << " y[2] = " << y[2].getValue() << endl < #include -template -class my_function : public func_ad { +template class my_function : public func_ad { public: - int operator() (int n, T *x, int m, T *y) - { - y[0] = sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]); - y[1] = atan(sqrt(x[0]*x[0]+x[1]*x[1])/x[2]); - y[2] = atan(x[1]/x[0]); - return 1; - } + int operator()(int n, T *x, int m, T *y) { + y[0] = sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); + y[1] = atan(sqrt(x[0] * x[0] + x[1] * x[1]) / x[2]); + y[2] = atan(x[1] / x[0]); + return 1; + } }; - int main(int argc, char *argv[]) { - const int m=3, n=3; - adtl::setNumDir(n); - - my_function fun; - my_function fun_indo; - adtl::adouble x[n], y[m]; - - for (int i=0; i fun; + my_function fun_indo; + adtl::adouble x[n], y[m]; + + for (int i = 0; i < n; ++i) // Initialize x_i + { + x[i] = i + 1.0; + for (int j = 0; j < m; ++j) + if (i == j) + x[i].setADValue(j, 1); + } + + cout.precision(15); + cout << endl + << "Transform from Cartesian to spherical polar coordinates" << endl + << endl; + + cout << "cartesian coordinates: " << endl; + cout << "x[0] = " << x[0].getValue() << " x[1] = " << x[1].getValue() + << " x[2] = " << x[2].getValue() << endl + << endl; + + fun(3, x, 3, y); + + cout << "cpherical polar coordinates: " << endl; + cout << "y[0] = " << y[0].getValue() << " y[1] = " << y[1].getValue() + << " y[2] = " << y[2].getValue() << endl + << endl; + + // "use" the derivative + cout << "derivatives:" << endl; + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) + cout << y[i].getADValue(j) << " "; cout << endl; - - double* basepoints = new double[n]; - for(int i = 0; i + #include /****************************************************************************/ /* Now the C THINGS */ @@ -23,68 +23,55 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* MEMORY MANAGEMENT UTILITIES */ -ADOLC_DLL_EXPORT char* populate_dpp(double ***const pointer, char *const memory, +ADOLC_DLL_EXPORT char *populate_dpp(double ***const pointer, char *const memory, int n, int m); -ADOLC_DLL_EXPORT char* populate_dppp(double ****const pointer, char *const memory, - int n, int m, int p); -ADOLC_DLL_EXPORT char* populate_dppp_nodata(double ****const pointer, char *const memory, - int n, int m); -ADOLC_DLL_EXPORT double *myalloc1(size_t); -ADOLC_DLL_EXPORT double **myalloc2(size_t, size_t); -ADOLC_DLL_EXPORT double ***myalloc3(size_t, size_t, size_t); - -ADOLC_DLL_EXPORT void myfree1(double *); -ADOLC_DLL_EXPORT void myfree2(double **); +ADOLC_DLL_EXPORT char *populate_dppp(double ****const pointer, + char *const memory, int n, int m, int p); +ADOLC_DLL_EXPORT char *populate_dppp_nodata(double ****const pointer, + char *const memory, int n, int m); +ADOLC_DLL_EXPORT double *myalloc1(size_t); +ADOLC_DLL_EXPORT double **myalloc2(size_t, size_t); +ADOLC_DLL_EXPORT double ***myalloc3(size_t, size_t, size_t); + +ADOLC_DLL_EXPORT void myfree1(double *); +ADOLC_DLL_EXPORT void myfree2(double **); ADOLC_DLL_EXPORT void myfree3(double ***); /*--------------------------------------------------------------------------*/ /* SPECIAL IDENTITY REPRESENTATION */ -ADOLC_DLL_EXPORT double **myallocI2(int); -ADOLC_DLL_EXPORT void myfreeI2(int, double**); - -ADOLC_DLL_EXPORT unsigned int * myalloc1_uint(int); +ADOLC_DLL_EXPORT double **myallocI2(int); +ADOLC_DLL_EXPORT void myfreeI2(int, double **); -ADOLC_DLL_EXPORT unsigned long int * myalloc1_ulong(int); -ADOLC_DLL_EXPORT unsigned long int ** myalloc2_ulong(int, int); +ADOLC_DLL_EXPORT unsigned int *myalloc1_uint(int); +ADOLC_DLL_EXPORT unsigned long int *myalloc1_ulong(int); +ADOLC_DLL_EXPORT unsigned long int **myalloc2_ulong(int, int); /****************************************************************************/ /* INTEGER VARIANT FOR BIT PATTERN PROPAGATION */ -ADOLC_DLL_EXPORT void myfree1_uint(unsigned int*); +ADOLC_DLL_EXPORT void myfree1_uint(unsigned int *); ADOLC_DLL_EXPORT void myfree1_ulong(unsigned long int *); ADOLC_DLL_EXPORT void myfree2_ulong(unsigned long int **); END_C_DECLS -/****************************************************************************/ -/* Now the C++ THINGS */ -#if defined(__cplusplus) + /****************************************************************************/ + /* Now the C++ THINGS */ + #if defined(__cplusplus) /*--------------------------------------------------------------------------*/ /* MEMORY MANAGEMENT UTILITIES */ -inline double * myalloc(int n) { - return myalloc1(n); -} -inline double ** myalloc(int m, int n) { - return myalloc2(m,n); -} -inline double *** myalloc(int m, int n, int p) { - return myalloc3(m,n,p); -} - -inline void myfree(double *A) { - myfree1(A); -} -inline void myfree(double **A) { - myfree2(A); -} -inline void myfree(double ***A) { - myfree3(A); -} +inline double *myalloc(int n) { return myalloc1(n); } +inline double **myalloc(int m, int n) { return myalloc2(m, n); } +inline double ***myalloc(int m, int n, int p) { return myalloc3(m, n, p); } -#endif +inline void myfree(double *A) { myfree1(A); } +inline void myfree(double **A) { myfree2(A); } +inline void myfree(double ***A) { myfree3(A); } + + #endif /****************************************************************************/ #endif diff --git a/ADOL-C/include/adolc/adolc.h b/ADOL-C/include/adolc/adolc.h index f65a9cce5..cbf67d65f 100644 --- a/ADOL-C/include/adolc/adolc.h +++ b/ADOL-C/include/adolc/adolc.h @@ -3,72 +3,72 @@ File: adolc.h Revision: $Id$ Contents: Provides all C/C++ interfaces of ADOL-C. - NOTICE: ALL C/C++ headers will be included DEPENDING ON - whether the source code is plain C or C/C++ code. - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + NOTICE: ALL C/C++ headers will be included DEPENDING ON + whether the source code is plain C or C/C++ code. + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_ADOLC_H) -#define ADOLC_ADOLC_H 1 + #define ADOLC_ADOLC_H 1 -#include + #include -/****************************************************************************/ -/* Now the pure C++ THINGS */ -#if defined(__cplusplus) -/*--------------------------------------------------------------------------*/ -/* Operator overloading things (active doubles & vectors) */ -# include -# include -# include -# include -# include -# include -#endif + /****************************************************************************/ + /* Now the pure C++ THINGS */ + #if defined(__cplusplus) + /*--------------------------------------------------------------------------*/ + /* Operator overloading things (active doubles & vectors) */ + #include + #include + #include + #include + #include + #include + #endif -/****************************************************************************/ -/* Now the C/C++ THINGS */ + /****************************************************************************/ + /* Now the C/C++ THINGS */ -/*--------------------------------------------------------------------------*/ -/* interfaces to basic forward/reverse routines */ -#include + /*--------------------------------------------------------------------------*/ + /* interfaces to basic forward/reverse routines */ + #include -/*--------------------------------------------------------------------------*/ -/* interfaces to "Easy To Use" driver routines for ... */ -#include /* optimization & nonlinear equations */ -#include /* higher order tensors & inverse/implicit functions */ -#include /* ordinary differential equations */ -#include /* piecewise smooth functions */ + /*--------------------------------------------------------------------------*/ + /* interfaces to "Easy To Use" driver routines for ... */ + #include /* optimization & nonlinear equations */ + #include /* ordinary differential equations */ + #include /* piecewise smooth functions */ + #include /* higher order tensors & inverse/implicit functions */ -/*--------------------------------------------------------------------------*/ -/* interfaces to TAPEDOC package */ -#include + /*--------------------------------------------------------------------------*/ + /* interfaces to TAPEDOC package */ + #include -/*--------------------------------------------------------------------------*/ -/* interfaces to SPARSE package */ -#if defined(SPARSE_DRIVERS) -#include -#include -#endif + /*--------------------------------------------------------------------------*/ + /* interfaces to SPARSE package */ + #if defined(SPARSE_DRIVERS) + #include + #include + #endif -/*--------------------------------------------------------------------------*/ -/* parameters */ -#include + /*--------------------------------------------------------------------------*/ + /* parameters */ + #include -/*--------------------------------------------------------------------------*/ -/* tape and value stack utilities */ -#include + /*--------------------------------------------------------------------------*/ + /* tape and value stack utilities */ + #include -/*--------------------------------------------------------------------------*/ -/* allocation utilities */ -#include + /*--------------------------------------------------------------------------*/ + /* allocation utilities */ + #include /****************************************************************************/ #endif diff --git a/ADOL-C/include/adolc/adolc_fatalerror.h b/ADOL-C/include/adolc/adolc_fatalerror.h index bb4a41e34..5c7c6e7e2 100644 --- a/ADOL-C/include/adolc/adolc_fatalerror.h +++ b/ADOL-C/include/adolc/adolc_fatalerror.h @@ -7,9 +7,9 @@ Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #ifndef ADOLC_FATALERROR_H @@ -17,25 +17,26 @@ #ifdef __cplusplus -#ifndef SWIG -#include -#include -#endif + #ifndef SWIG + #include + #include + #endif class FatalError : public std::exception { protected: - static const int MAX_MSG_SIZE = 4*1024; - char msg[MAX_MSG_SIZE]; + static const int MAX_MSG_SIZE = 4 * 1024; + char msg[MAX_MSG_SIZE]; public: - explicit FatalError(int errorcode, const char* what, const char* function, const char* file, int line) { - // need to use C-style functions that do not use exceptions themselves - snprintf(this->msg, MAX_MSG_SIZE, "errorcode=%d function=%s file=%s line=%d what=%s", errorcode, function, file, line, what); - } - - virtual const char* what() const throw() { - return msg; - } + explicit FatalError(int errorcode, const char *what, const char *function, + const char *file, int line) { + // need to use C-style functions that do not use exceptions themselves + snprintf(this->msg, MAX_MSG_SIZE, + "errorcode=%d function=%s file=%s line=%d what=%s", errorcode, + function, file, line, what); + } + + virtual const char *what() const throw() { return msg; } }; #endif diff --git a/ADOL-C/include/adolc/adolc_openmp.h b/ADOL-C/include/adolc/adolc_openmp.h index 6195cd708..d8def4ce9 100644 --- a/ADOL-C/include/adolc/adolc_openmp.h +++ b/ADOL-C/include/adolc/adolc_openmp.h @@ -5,24 +5,24 @@ Contents: header file for openmp parallel differentiation Copyright (c) Andreas Kowarz - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #if !defined(ADOLC_ADOLC_OPENMP_H) -#define ADOLC_ADOLC_OPENMP_H 1 + #define ADOLC_ADOLC_OPENMP_H 1 -#if !defined(__cplusplus) -#warning ADOLC_OPENMP IS ONLY USEFUL WHEN COMPILED WITH C++ !!! -#else + #if !defined(__cplusplus) + #warning ADOLC_OPENMP IS ONLY USEFUL WHEN COMPILED WITH C++ !!! + #else -#if !defined(_OPENMP) -#error OPENMP NOT ENABLED AT COMPILE TIME !!! -#else + #if !defined(_OPENMP) + #error OPENMP NOT ENABLED AT COMPILE TIME !!! + #else -#include + #include extern void beginParallel(); extern void endParallel(); @@ -30,34 +30,29 @@ extern void endParallel(); extern int ADOLC_parallel_doCopy; typedef struct ADOLC_OpenMP { - inline ADOLC_OpenMP() {} - inline ADOLC_OpenMP(const ADOLC_OpenMP &arg) { - ADOLC_parallel_doCopy = 1; - beginParallel(); - } - inline ~ADOLC_OpenMP() { - endParallel(); - } + inline ADOLC_OpenMP() {} + inline ADOLC_OpenMP(const ADOLC_OpenMP &arg) { + ADOLC_parallel_doCopy = 1; + beginParallel(); + } + inline ~ADOLC_OpenMP() { endParallel(); } } ADOLC_OpenMP; typedef struct ADOLC_OpenMP_NC { - inline ADOLC_OpenMP_NC() {} - inline ADOLC_OpenMP_NC(const ADOLC_OpenMP_NC &arg) { - ADOLC_parallel_doCopy = 0; - beginParallel(); - } - inline ~ADOLC_OpenMP_NC() { - endParallel(); - } + inline ADOLC_OpenMP_NC() {} + inline ADOLC_OpenMP_NC(const ADOLC_OpenMP_NC &arg) { + ADOLC_parallel_doCopy = 0; + beginParallel(); + } + inline ~ADOLC_OpenMP_NC() { endParallel(); } } ADOLC_OpenMP_NC; extern ADOLC_OpenMP ADOLC_OpenMP_Handler; extern ADOLC_OpenMP_NC ADOLC_OpenMP_Handler_NC; -#define ADOLC_OPENMP firstprivate(ADOLC_OpenMP_Handler) -#define ADOLC_OPENMP_NC firstprivate(ADOLC_OpenMP_Handler_NC) - -#endif /* _OPENMP */ -#endif /* __cplusplus */ -#endif /* ADOLC_ADOLC_OPENMP_H */ + #define ADOLC_OPENMP firstprivate(ADOLC_OpenMP_Handler) + #define ADOLC_OPENMP_NC firstprivate(ADOLC_OpenMP_Handler_NC) + #endif /* _OPENMP */ + #endif /* __cplusplus */ +#endif /* ADOLC_ADOLC_OPENMP_H */ diff --git a/ADOL-C/include/adolc/adolc_sparse.h b/ADOL-C/include/adolc/adolc_sparse.h index 4dc61cb89..39cb3f3c7 100644 --- a/ADOL-C/include/adolc/adolc_sparse.h +++ b/ADOL-C/include/adolc/adolc_sparse.h @@ -3,14 +3,14 @@ File: adolc_sparse.h Revision: $Id$ Contents: Provides C/C++ interfaces of ADOL-C sprase drivers. - + Copyright (c) Andrea Walther This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ -#include #include +#include diff --git a/ADOL-C/include/adolc/adouble.h b/ADOL-C/include/adolc/adouble.h index 8858b9a25..413050af4 100644 --- a/ADOL-C/include/adolc/adouble.h +++ b/ADOL-C/include/adolc/adouble.h @@ -13,35 +13,35 @@ Benjamin Letschert Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #if !defined(ADOLC_ADOUBLE_H) -#define ADOLC_ADOUBLE_H 1 + #define ADOLC_ADOUBLE_H 1 -/****************************************************************************/ -/* THIS FILE IS C++ */ -#ifdef __cplusplus + /****************************************************************************/ + /* THIS FILE IS C++ */ + #ifdef __cplusplus -#include -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include + #include -#if !defined(SWIGPRE) -using std::cout; -using std::cin; + #if !defined(SWIGPRE) using std::cerr; -using std::ostream; +using std::cin; +using std::cout; using std::istream; using std::logic_error; -#endif +using std::ostream; + #endif -#include + #include /* NOTICE: There are automatic includes at the end of this file! */ @@ -55,202 +55,203 @@ class badouble; class pdouble; /*--------------------------------------------------------------------------*/ -void ADOLC_DLL_EXPORT condassign( double &res, const double &cond, - const double &arg1, const double &arg2 ); -void ADOLC_DLL_EXPORT condassign( double &res, const double &cond, - const double &arg ); +void ADOLC_DLL_EXPORT condassign(double &res, const double &cond, + const double &arg1, const double &arg2); +void ADOLC_DLL_EXPORT condassign(double &res, const double &cond, + const double &arg); -void ADOLC_DLL_EXPORT condeqassign( double &res, const double &cond, - const double &arg1, const double &arg2 ); -void ADOLC_DLL_EXPORT condeqassign( double &res, const double &cond, - const double &arg ); +void ADOLC_DLL_EXPORT condeqassign(double &res, const double &cond, + const double &arg1, const double &arg2); +void ADOLC_DLL_EXPORT condeqassign(double &res, const double &cond, + const double &arg); /****************************************************************************/ /* CLASS BADOUBLE */ /** - The class badouble contains the basic definitions for - the arithmetic operations, comparisons, etc. - This is a basic class from which the adub and adouble are - derived. Notice that the constructors/destructors for + The class badouble contains the basic definitions for + the arithmetic operations, comparisons, etc. + This is a basic class from which the adub and adouble are + derived. Notice that the constructors/destructors for the class badouble are of the trivial variety. This is the main difference among badoubles, adubs, and adoubles. */ class ADOLC_DLL_EXPORT badouble { - friend ADOLC_DLL_EXPORT class pdouble; + friend ADOLC_DLL_EXPORT class pdouble; + protected: - locint location; - badouble( void ) {}; - // Copy constructor: - // must be public when using gcc >= 3.4 and gcc <= 4.3.0 - // (see GCC 3.4 Release Series - Changes, New Features, and Fixes) - // so we make it protected for newer compilers again. - badouble( const badouble& a ) {}; /* ctor */ - explicit badouble( locint lo ) { - location = lo; - isInit = true; - }; - - bool isInit; // marker if the badouble is properly initialized + locint location; + badouble(void) {}; + // Copy constructor: + // must be public when using gcc >= 3.4 and gcc <= 4.3.0 + // (see GCC 3.4 Release Series - Changes, New Features, and Fixes) + // so we make it protected for newer compilers again. + badouble(const badouble &a) {}; /* ctor */ + explicit badouble(locint lo) { + location = lo; + isInit = true; + }; + + bool isInit; // marker if the badouble is properly initialized public: - - ~badouble(); - - /*--------------------------------------------------------------------------*/ - inline locint loc( void ) const; /* Helpful stuff */ - - /*------------------------------------------------------------------------*/ - badouble& operator >>= ( double& ); /* Assignments */ - badouble& operator <<= ( double ); - void declareIndependent (); - void declareDependent (); - badouble& operator = ( double ); - badouble& operator = ( const badouble& ); - badouble& operator = ( const adub& ); - double getValue() const; - inline double value() const { - return getValue(); - } - explicit operator double(); - explicit operator double const&() const; - explicit operator double&&(); - void setValue ( const double ); - /* badouble& operator = ( const adouble& ); - !!! olvo 991210: was the same as badouble-assignment */ - - /*--------------------------------------------------------------------------*/ - friend ADOLC_DLL_EXPORT std::ostream& operator << ( std::ostream&, const badouble& ); /* IO friends */ - friend ADOLC_DLL_EXPORT std::istream& operator >> ( std::istream&, const badouble& ); - - /*------------------------------------------------------------------------*/ - badouble& operator += ( double ); /* Operation + Assignment */ - badouble& operator += ( const badouble& ); - badouble& operator -= ( double y ); - badouble& operator -= ( const badouble& ); - badouble& operator *= ( double ); - badouble& operator *= ( const badouble& ); - badouble& operator /= ( double ); - badouble& operator /= ( const badouble& ); - /* olvo 991122 n2l: new special op_codes */ - badouble& operator += ( const adub& ); - badouble& operator -= ( const adub& ); - - /*--------------------------------------------------------------------------*/ - badouble& operator = (const pdouble&); - badouble& operator += (const pdouble&); - badouble& operator -= (const pdouble&); - badouble& operator *= (const pdouble&); - inline badouble& operator /= (const pdouble&); + ~badouble(); + + /*--------------------------------------------------------------------------*/ + inline locint loc(void) const; /* Helpful stuff */ + + /*------------------------------------------------------------------------*/ + badouble &operator>>=(double &); /* Assignments */ + badouble &operator<<=(double); + void declareIndependent(); + void declareDependent(); + badouble &operator=(double); + badouble &operator=(const badouble &); + badouble &operator=(const adub &); + double getValue() const; + inline double value() const { return getValue(); } + explicit operator double(); + explicit operator double const &() const; + explicit operator double &&(); + void setValue(const double); + /* badouble& operator = ( const adouble& ); + !!! olvo 991210: was the same as badouble-assignment */ + + /*--------------------------------------------------------------------------*/ + friend ADOLC_DLL_EXPORT std::ostream & + operator<<(std::ostream &, const badouble &); /* IO friends */ + friend ADOLC_DLL_EXPORT std::istream &operator>>(std::istream &, + const badouble &); + + /*------------------------------------------------------------------------*/ + badouble &operator+=(double); /* Operation + Assignment */ + badouble &operator+=(const badouble &); + badouble &operator-=(double y); + badouble &operator-=(const badouble &); + badouble &operator*=(double); + badouble &operator*=(const badouble &); + badouble &operator/=(double); + badouble &operator/=(const badouble &); + /* olvo 991122 n2l: new special op_codes */ + badouble &operator+=(const adub &); + badouble &operator-=(const adub &); + + /*--------------------------------------------------------------------------*/ + badouble &operator=(const pdouble &); + badouble &operator+=(const pdouble &); + badouble &operator-=(const pdouble &); + badouble &operator*=(const pdouble &); + inline badouble &operator/=(const pdouble &); /*--------------------------------------------------------------------------*/ /* Comparison (friends) */ -#if !defined(ADOLC_ADVANCED_BRANCHING) - inline friend bool operator != ( const badouble&, const badouble& ); - inline friend bool operator == ( const badouble&, const badouble& ); - inline friend bool operator <= ( const badouble&, const badouble& ); - inline friend bool operator >= ( const badouble&, const badouble& ); - inline friend bool operator > ( const badouble&, const badouble& ); - inline friend bool operator < ( const badouble&, const badouble& ); -#endif - inline friend bool operator != ( double, const badouble& ); - friend ADOLC_DLL_EXPORT bool operator != ( const badouble&, double ); - inline friend bool operator == ( double, const badouble& ); - friend ADOLC_DLL_EXPORT bool operator == ( const badouble&, double ); - inline friend bool operator <= ( double, const badouble& ); - friend ADOLC_DLL_EXPORT bool operator <= ( const badouble&, double ); - inline friend bool operator >= ( double, const badouble& ); - friend ADOLC_DLL_EXPORT bool operator >= ( const badouble&, double ); - inline friend bool operator > ( double, const badouble& ); - friend ADOLC_DLL_EXPORT bool operator > ( const badouble&, double ); - inline friend bool operator < ( double, const badouble& ); - friend ADOLC_DLL_EXPORT bool operator < ( const badouble&, double ); - + #if !defined(ADOLC_ADVANCED_BRANCHING) + inline friend bool operator!=(const badouble &, const badouble &); + inline friend bool operator==(const badouble &, const badouble &); + inline friend bool operator<=(const badouble &, const badouble &); + inline friend bool operator>=(const badouble &, const badouble &); + inline friend bool operator>(const badouble &, const badouble &); + inline friend bool operator<(const badouble &, const badouble &); + #endif + inline friend bool operator!=(double, const badouble &); + friend ADOLC_DLL_EXPORT bool operator!=(const badouble &, double); + inline friend bool operator==(double, const badouble &); + friend ADOLC_DLL_EXPORT bool operator==(const badouble &, double); + inline friend bool operator<=(double, const badouble &); + friend ADOLC_DLL_EXPORT bool operator<=(const badouble &, double); + inline friend bool operator>=(double, const badouble &); + friend ADOLC_DLL_EXPORT bool operator>=(const badouble &, double); + inline friend bool operator>(double, const badouble &); + friend ADOLC_DLL_EXPORT bool operator>(const badouble &, double); + inline friend bool operator<(double, const badouble &); + friend ADOLC_DLL_EXPORT bool operator<(const badouble &, double); /*--------------------------------------------------------------------------*/ /* Functions friends with both badouble and adub */ -#define _IN_CLASS_ 1 -#define _IN_BADOUBLE_ 1 -#include -#undef _IN_BADOUBLE_ -#undef _IN_CLASS_ - - /*--------------------------------------------------------------------------*/ - /* special operators (friends) */ - friend ADOLC_DLL_EXPORT adouble atan2 ( const badouble&, const badouble& ); - /* uses condassign internally */ - friend ADOLC_DLL_EXPORT adouble pow ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adouble pow ( double, const badouble& ); - /* User defined version of logarithm to test extend_quad macro */ - friend ADOLC_DLL_EXPORT adouble myquad( const badouble& ); - - /*--------------------------------------------------------------------------*/ - /* Conditionals */ - friend ADOLC_DLL_EXPORT void condassign( adouble &res, const badouble &cond, - const badouble &arg1, const badouble &arg2 ); - friend ADOLC_DLL_EXPORT void condassign( adouble &res, const badouble &cond, - const badouble &arg ); - friend ADOLC_DLL_EXPORT void condeqassign( adouble &res, const badouble &cond, - const badouble &arg1, const badouble &arg2 ); - friend ADOLC_DLL_EXPORT void condeqassign( adouble &res, const badouble &cond, - const badouble &arg ); - -#define _IN_CLASS_ 1 -#define _IN_BADOUBLE_ 1 -#include -#undef _IN_BADOUBLE_ -#undef _IN_CLASS_ - + #define _IN_CLASS_ 1 + #define _IN_BADOUBLE_ 1 + #include + #undef _IN_BADOUBLE_ + #undef _IN_CLASS_ + + /*--------------------------------------------------------------------------*/ + /* special operators (friends) */ + friend ADOLC_DLL_EXPORT adouble atan2(const badouble &, const badouble &); + /* uses condassign internally */ + friend ADOLC_DLL_EXPORT adouble pow(const badouble &, const badouble &); + friend ADOLC_DLL_EXPORT adouble pow(double, const badouble &); + /* User defined version of logarithm to test extend_quad macro */ + friend ADOLC_DLL_EXPORT adouble myquad(const badouble &); + + /*--------------------------------------------------------------------------*/ + /* Conditionals */ + friend ADOLC_DLL_EXPORT void condassign(adouble &res, const badouble &cond, + const badouble &arg1, + const badouble &arg2); + friend ADOLC_DLL_EXPORT void condassign(adouble &res, const badouble &cond, + const badouble &arg); + friend ADOLC_DLL_EXPORT void condeqassign(adouble &res, const badouble &cond, + const badouble &arg1, + const badouble &arg2); + friend ADOLC_DLL_EXPORT void condeqassign(adouble &res, const badouble &cond, + const badouble &arg); + + #define _IN_CLASS_ 1 + #define _IN_BADOUBLE_ 1 + #include + #undef _IN_BADOUBLE_ + #undef _IN_CLASS_ }; - - -/****************************************************************************/ -/* CLASS ADUB */ - -/* - The class Adub - ---- Basically used as a temporary result. The address for an - adub is usually generated within an operation. That address - is "freed" when the adub goes out of scope (at destruction time). - ---- operates just like a badouble, but it has a destructor defined for it. -*/ -#if !defined(SWIGPRE) + /****************************************************************************/ + /* CLASS ADUB + */ + + /* + The class Adub + ---- Basically used as a temporary result. The address for an + adub is usually generated within an operation. That address + is "freed" when the adub goes out of scope (at destruction time). + ---- operates just like a badouble, but it has a destructor defined for + it. + */ + #if !defined(SWIGPRE) /* s = adolc_vec_dot(x,y,size); <=> s = _2 */ -ADOLC_DLL_EXPORT adub adolc_vec_dot(const adouble*const, const adouble*const, locint); -#endif +ADOLC_DLL_EXPORT adub adolc_vec_dot(const adouble *const, const adouble *const, + locint); + #endif -class ADOLC_DLL_EXPORT adub:public badouble { - friend ADOLC_DLL_EXPORT class adouble; - friend ADOLC_DLL_EXPORT class advector; - friend ADOLC_DLL_EXPORT class adubref; - friend ADOLC_DLL_EXPORT class pdouble; +class ADOLC_DLL_EXPORT adub : public badouble { + friend ADOLC_DLL_EXPORT class adouble; + friend ADOLC_DLL_EXPORT class advector; + friend ADOLC_DLL_EXPORT class adubref; + friend ADOLC_DLL_EXPORT class pdouble; protected: - /* this is the only logically legal constructor, which can be called by - * friend classes and functions - */ - adub( locint lo ) : badouble(lo) {} + /* this is the only logically legal constructor, which can be called by + * friend classes and functions + */ + adub(locint lo) : badouble(lo) {} public: /*--------------------------------------------------------------------------*/ -#if !defined(SWIGPRE) - /* s = adolc_vec_dot(x,y,size); <=> s = _2 */ - friend adub adolc_vec_dot(const adouble*const, const adouble*const, locint); -#endif + #if !defined(SWIGPRE) + /* s = adolc_vec_dot(x,y,size); <=> s = _2 */ + friend adub adolc_vec_dot(const adouble *const, const adouble *const, locint); + #endif /* Functions friends with both badouble and adub */ -#define _IN_CLASS_ 1 -#define _IN_ADUB_ 1 -#include -#undef _IN_ADUB_ -#undef _IN_CLASS_ + #define _IN_CLASS_ 1 + #define _IN_ADUB_ 1 + #include + #undef _IN_ADUB_ + #undef _IN_CLASS_ /*--------------------------------------------------------------------------*/ /* Parameter dependent functions (friends) */ -#define _IN_CLASS_ 1 -#define _IN_ADUB_ 1 -#include -#undef _IN_ADUB_ -#undef _IN_CLASS_ + #define _IN_CLASS_ 1 + #define _IN_ADUB_ 1 + #include + #undef _IN_ADUB_ + #undef _IN_CLASS_ }; BEGIN_C_DECLS @@ -265,169 +266,159 @@ END_C_DECLS ---At construction, it is given a new address, and at destruction, that address is freed. */ -class ADOLC_DLL_EXPORT adouble:public badouble { - friend ADOLC_DLL_EXPORT class advector; - friend ADOLC_DLL_EXPORT class pdouble; +class ADOLC_DLL_EXPORT adouble : public badouble { + friend ADOLC_DLL_EXPORT class advector; + friend ADOLC_DLL_EXPORT class pdouble; + protected: - void initInternal(void); // Init for late initialization + void initInternal(void); // Init for late initialization public: - adouble( const adub& ); - adouble( const adouble& ); - adouble( void ); - adouble( double ); + adouble(const adub &); + adouble(const adouble &); + adouble(void); + adouble(double); /* adub prevents postfix operators to occur on the left side of an assignment which would not work */ -#if !defined(SWIGPRE) - adub operator++( int ); - adub operator--( int ); -#else - adub* operator++( int ); - adub* operator--( int ); -#endif - badouble& operator++( void ); - badouble& operator--( void ); - /* inline double value(); */ - - adouble& operator = ( double ); - adouble& operator = ( const badouble& ); - adouble& operator = ( const adouble& ); - adouble& operator = ( const adub& ); - adouble& operator = (const pdouble&); - - inline locint loc(void) const; - -#if defined(ADOLC_DEFAULT_CONTIG_LOC) - void *operator new[](size_t sz) { - void *p = ::new char[sz]; - size_t n = (sz - sizeof(size_t))/sizeof(adouble); - ensureContiguousLocations(n); - return p; - } - void operator delete[](void* p) { - ::delete[] (char*)p; - } -#endif + #if !defined(SWIGPRE) + adub operator++(int); + adub operator--(int); + #else + adub *operator++(int); + adub *operator--(int); + #endif + badouble &operator++(void); + badouble &operator--(void); + /* inline double value(); */ + + adouble &operator=(double); + adouble &operator=(const badouble &); + adouble &operator=(const adouble &); + adouble &operator=(const adub &); + adouble &operator=(const pdouble &); + + inline locint loc(void) const; + + #if defined(ADOLC_DEFAULT_CONTIG_LOC) + void *operator new[](size_t sz) { + void *p = ::new char[sz]; + size_t n = (sz - sizeof(size_t)) / sizeof(adouble); + ensureContiguousLocations(n); + return p; + } + void operator delete[](void *p) { ::delete[] (char *)p; } + #endif }; -#endif /* __cplusplus */ + #endif /* __cplusplus */ -#include -#include + #include + #include -#ifdef __cplusplus + #ifdef __cplusplus /****************************************************************************/ /* INLINE DEFINITIONS */ /*--------------------------------------------------------------------------*/ -inline locint badouble::loc( void ) const { - return location; -} +inline locint badouble::loc(void) const { return location; } -inline locint adouble::loc( void ) const { - const_cast(this)->initInternal(); - return location; +inline locint adouble::loc(void) const { + const_cast(this)->initInternal(); + return location; } -/*--------------------------------------------------------------------------*/ -/* Comparison */ + /*--------------------------------------------------------------------------*/ + /* Comparison */ -#if !defined(ADOLC_ADVANCED_BRANCHING) -inline bool operator != ( const badouble& u, const badouble& v ) { - return (u-v != 0); + #if !defined(ADOLC_ADVANCED_BRANCHING) +inline bool operator!=(const badouble &u, const badouble &v) { + return (u - v != 0); } -inline bool operator == ( const badouble& u, const badouble& v ) { - return (u-v == 0); +inline bool operator==(const badouble &u, const badouble &v) { + return (u - v == 0); } -inline bool operator <= ( const badouble& u, const badouble& v ) { - return (u-v <= 0); +inline bool operator<=(const badouble &u, const badouble &v) { + return (u - v <= 0); } -inline bool operator >= ( const badouble& u, const badouble& v ) { - return (u-v >= 0); +inline bool operator>=(const badouble &u, const badouble &v) { + return (u - v >= 0); } -inline bool operator > ( const badouble& u, const badouble& v ) { - return (u-v > 0); +inline bool operator>(const badouble &u, const badouble &v) { + return (u - v > 0); } -inline bool operator < ( const badouble& u, const badouble& v ) { - return (u-v < 0); +inline bool operator<(const badouble &u, const badouble &v) { + return (u - v < 0); } -#endif + #endif -inline bool operator != ( double coval, const badouble& v) { - if (coval) - return (-coval+v != 0); - else - return (v != 0); +inline bool operator!=(double coval, const badouble &v) { + if (coval) + return (-coval + v != 0); + else + return (v != 0); } -inline bool operator == ( double coval, const badouble& v) { - if (coval) - return (-coval+v == 0); - else - return (v == 0); +inline bool operator==(double coval, const badouble &v) { + if (coval) + return (-coval + v == 0); + else + return (v == 0); } -inline bool operator <= ( double coval, const badouble& v ) { - if (coval) - return (-coval+v >= 0); - else - return (v >= 0); +inline bool operator<=(double coval, const badouble &v) { + if (coval) + return (-coval + v >= 0); + else + return (v >= 0); } -inline bool operator >= ( double coval, const badouble& v ) { - if (coval) - return (-coval+v <= 0); - else - return (v <= 0); +inline bool operator>=(double coval, const badouble &v) { + if (coval) + return (-coval + v <= 0); + else + return (v <= 0); } -inline bool operator > ( double coval, const badouble& v ) { - if (coval) - return (-coval+v < 0); - else - return (v < 0); +inline bool operator>(double coval, const badouble &v) { + if (coval) + return (-coval + v < 0); + else + return (v < 0); } -inline bool operator < ( double coval, const badouble& v ) { - if (coval) - return (-coval+v > 0); - else - return (v > 0); +inline bool operator<(double coval, const badouble &v) { + if (coval) + return (-coval + v > 0); + else + return (v > 0); } -#if !defined(SWIGPRE) + #if !defined(SWIGPRE) /*--------------------------------------------------------------------------*/ /* Adding a floating point from an adouble */ -inline adub operator + ( const badouble& x , double coval ) { - return coval + x; -} +inline adub operator+(const badouble &x, double coval) { return coval + x; } /* Subtract a floating point from an adouble */ -inline adub operator - ( const badouble& x , double coval ) { - return (-coval) + x; -} +inline adub operator-(const badouble &x, double coval) { return (-coval) + x; } /*--------------------------------------------------------------------------*/ /* Multiply an adouble by a floating point */ -inline adub operator * (const badouble& x, double coval) { - return coval * x; -} +inline adub operator*(const badouble &x, double coval) { return coval * x; } /*--------------------------------------------------------------------------*/ /* Divide an adouble by a floating point */ -inline adub operator / (const badouble& x, double coval) { - return (1.0/coval) * x; +inline adub operator/(const badouble &x, double coval) { + return (1.0 / coval) * x; } -#endif - + #endif -inline badouble& badouble::operator /= (const pdouble& p) { - *this *= recipr(p); - return *this; +inline badouble &badouble::operator/=(const pdouble &p) { + *this *= recipr(p); + return *this; } /* numeric_limits specialization @@ -435,67 +426,83 @@ inline badouble& badouble::operator /= (const pdouble& p) { * All methods return double instead of adouble, because these values * never depend on the independent variables. */ -template<> -struct std::numeric_limits -{ - static constexpr bool is_specialized = true; - - static constexpr double - min() noexcept { return std::numeric_limits::min(); } - - static constexpr double - max() noexcept { return std::numeric_limits::max(); } - - static constexpr double - lowest() noexcept { return std::numeric_limits::lowest(); } - - static constexpr int digits = std::numeric_limits::digits; - static constexpr int digits10 = std::numeric_limits::digits10; - static constexpr int max_digits10 = std::numeric_limits::max_digits10; - static constexpr bool is_signed = std::numeric_limits::is_signed; - static constexpr bool is_integer = std::numeric_limits::is_integer; - static constexpr bool is_exact = std::numeric_limits::is_exact; - static constexpr int radix = std::numeric_limits::radix; - - static constexpr double - epsilon() noexcept { return std::numeric_limits::epsilon(); } - - static constexpr double - round_error() noexcept { return std::numeric_limits::round_error(); } - - static constexpr int min_exponent = std::numeric_limits::min_exponent; - static constexpr int min_exponent10 = std::numeric_limits::min_exponent10; - static constexpr int max_exponent = std::numeric_limits::max_exponent; - static constexpr int max_exponent10 = std::numeric_limits::max_exponent10; - - static constexpr bool has_infinity = std::numeric_limits::has_infinity; - static constexpr bool has_quiet_NaN = std::numeric_limits::has_quiet_NaN; - static constexpr bool has_signaling_NaN = std::numeric_limits::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = std::numeric_limits::has_denorm; - static constexpr bool has_denorm_loss = std::numeric_limits::has_denorm_loss; - - static constexpr double - infinity() noexcept { return std::numeric_limits::infinity(); } - - static constexpr double - quiet_NaN() noexcept { return std::numeric_limits::quiet_NaN(); } - - static constexpr double - signaling_NaN() noexcept { return std::numeric_limits::signaling_NaN(); } - - static constexpr double - denorm_min() noexcept { return std::numeric_limits::denorm_min(); } - - static constexpr bool is_iec559 = std::numeric_limits::is_iec559; - static constexpr bool is_bounded = std::numeric_limits::is_bounded; - static constexpr bool is_modulo = std::numeric_limits::is_modulo; - - static constexpr bool traps = std::numeric_limits::traps; - static constexpr bool tinyness_before = std::numeric_limits::tinyness_before; - static constexpr float_round_style round_style = std::numeric_limits::round_style; +template <> struct std::numeric_limits { + static constexpr bool is_specialized = true; + + static constexpr double min() noexcept { + return std::numeric_limits::min(); + } + + static constexpr double max() noexcept { + return std::numeric_limits::max(); + } + + static constexpr double lowest() noexcept { + return std::numeric_limits::lowest(); + } + + static constexpr int digits = std::numeric_limits::digits; + static constexpr int digits10 = std::numeric_limits::digits10; + static constexpr int max_digits10 = std::numeric_limits::max_digits10; + static constexpr bool is_signed = std::numeric_limits::is_signed; + static constexpr bool is_integer = std::numeric_limits::is_integer; + static constexpr bool is_exact = std::numeric_limits::is_exact; + static constexpr int radix = std::numeric_limits::radix; + + static constexpr double epsilon() noexcept { + return std::numeric_limits::epsilon(); + } + + static constexpr double round_error() noexcept { + return std::numeric_limits::round_error(); + } + + static constexpr int min_exponent = std::numeric_limits::min_exponent; + static constexpr int min_exponent10 = + std::numeric_limits::min_exponent10; + static constexpr int max_exponent = std::numeric_limits::max_exponent; + static constexpr int max_exponent10 = + std::numeric_limits::max_exponent10; + + static constexpr bool has_infinity = + std::numeric_limits::has_infinity; + static constexpr bool has_quiet_NaN = + std::numeric_limits::has_quiet_NaN; + static constexpr bool has_signaling_NaN = + std::numeric_limits::has_signaling_NaN; + static constexpr float_denorm_style has_denorm = + std::numeric_limits::has_denorm; + static constexpr bool has_denorm_loss = + std::numeric_limits::has_denorm_loss; + + static constexpr double infinity() noexcept { + return std::numeric_limits::infinity(); + } + + static constexpr double quiet_NaN() noexcept { + return std::numeric_limits::quiet_NaN(); + } + + static constexpr double signaling_NaN() noexcept { + return std::numeric_limits::signaling_NaN(); + } + + static constexpr double denorm_min() noexcept { + return std::numeric_limits::denorm_min(); + } + + static constexpr bool is_iec559 = std::numeric_limits::is_iec559; + static constexpr bool is_bounded = std::numeric_limits::is_bounded; + static constexpr bool is_modulo = std::numeric_limits::is_modulo; + + static constexpr bool traps = std::numeric_limits::traps; + static constexpr bool tinyness_before = + std::numeric_limits::tinyness_before; + static constexpr float_round_style round_style = + std::numeric_limits::round_style; }; -/****************************************************************************/ -/* THAT'S ALL*/ -#endif /* __cplusplus */ -#endif /* ADOLC_ADOUBLE_H */ + /****************************************************************************/ + /* THAT'S ALL*/ + #endif /* __cplusplus */ +#endif /* ADOLC_ADOUBLE_H */ diff --git a/ADOL-C/include/adolc/adoublecuda.h b/ADOL-C/include/adolc/adoublecuda.h index 32acc2313..3e9cea519 100644 --- a/ADOL-C/include/adolc/adoublecuda.h +++ b/ADOL-C/include/adolc/adoublecuda.h @@ -8,1029 +8,977 @@ Copyright (c) Alina Koniaeva, Andrea Walther This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #if !defined(ADOLC_ADOUBLECUDA_H) -#define ADOLC_ADOUBLECUDA_H 1 + #define ADOLC_ADOUBLECUDA_H 1 -#include -#include -#include + #include + #include + #include using std::cout; -using std::ostream; using std::istream; +using std::ostream; -#include -#include + #include + #include namespace adtlc { - -#if defined(NUMBER_DIRECTIONS) + #if defined(NUMBER_DIRECTIONS) __managed__ size_t ADOLC_numDir = NUMBER_DIRECTIONS; -# if defined(DYNAMIC_DIRECTIONS) -# define ADVAL_DECL *adval -# define ADVAL_TYPE_ADV const double* adv -# else -# define ADVAL_DECL adval[NUMBER_DIRECTIONS] -# define ADVAL_TYPE_ADV const double adv[NUMBER_DIRECTIONS] -# endif -# define ADVAL_TYPE double* -# define FOR_I_EQ_0_LT_NUMDIR for (size_t i = 0; i < ADOLC_numDir; i++) -# define ADVAL_I adval[i] -# define ADV_I adv[i] -# define V_I v[i] -#else -# define ADVAL_DECL adval -# define ADVAL adval -# define ADVAL_TYPE_ADV double adv -# define ADVAL_TYPE double -# define FOR_I_EQ_0_LT_NUMDIR -# define ADVAL_I adval -# define ADV_I adv -# define V_I v -#endif - - -#define ADOLC_MATH_NSP std - -inline __device__ double makeNaN() { - return CUDART_NAN; -} - -inline __device__ double makeInf() { - return CUDART_INF; -} - - -#define CUDADEV __device__ inline -#define CUDAHOST __host__ inline -#define CUDAHOSTDEV __host__ __device__ inline + #if defined(DYNAMIC_DIRECTIONS) + #define ADVAL_DECL *adval + #define ADVAL_TYPE_ADV const double *adv + #else + #define ADVAL_DECL adval[NUMBER_DIRECTIONS] + #define ADVAL_TYPE_ADV const double adv[NUMBER_DIRECTIONS] + #endif + #define ADVAL_TYPE double * + #define FOR_I_EQ_0_LT_NUMDIR for (size_t i = 0; i < ADOLC_numDir; i++) + #define ADVAL_I adval[i] + #define ADV_I adv[i] + #define V_I v[i] + #else + #define ADVAL_DECL adval + #define ADVAL adval + #define ADVAL_TYPE_ADV double adv + #define ADVAL_TYPE double + #define FOR_I_EQ_0_LT_NUMDIR + #define ADVAL_I adval + #define ADV_I adv + #define V_I v + #endif + + #define ADOLC_MATH_NSP std + +inline __device__ double makeNaN() { return CUDART_NAN; } + +inline __device__ double makeInf() { return CUDART_INF; } + + #define CUDADEV __device__ inline + #define CUDAHOST __host__ inline + #define CUDAHOSTDEV __host__ __device__ inline class adouble { public: - // ctors - CUDADEV adouble(); - CUDADEV adouble(const double v); - CUDADEV adouble(const double v, ADVAL_TYPE_ADV); - CUDADEV adouble(const adouble& a); -#if defined(DYNAMIC_DIRECTIONS) - CUDADEV ~adouble(); -#endif - /******************* temporary results ******************************/ - // sign - CUDADEV adouble operator - () const; - CUDADEV adouble operator + () const; - - // addition - CUDADEV adouble operator + (const double v) const; - CUDADEV adouble operator + (const adouble& a) const; - CUDADEV friend - adouble operator + (const double v, const adouble& a); - - // subtraction - CUDADEV adouble operator - (const double v) const; - CUDADEV adouble operator - (const adouble& a) const; - CUDADEV friend - adouble operator - (const double v, const adouble& a); - - // multiplication - CUDADEV adouble operator * (const double v) const; - CUDADEV adouble operator * (const adouble& a) const; - CUDADEV friend - adouble operator * (const double v, const adouble& a); - - // division - CUDADEV adouble operator / (const double v) const; - CUDADEV adouble operator / (const adouble& a) const; - CUDADEV friend - adouble operator / (const double v, const adouble& a); - - // inc/dec - CUDADEV adouble operator ++ (); - CUDADEV adouble operator ++ (int); - CUDADEV adouble operator -- (); - CUDADEV adouble operator -- (int); - - // functions - CUDADEV friend adouble tan(const adouble &a); - CUDADEV friend adouble exp(const adouble &a); - CUDADEV friend adouble log(const adouble &a); - CUDADEV friend adouble sqrt(const adouble &a); - CUDADEV friend adouble sin(const adouble &a); - CUDADEV friend adouble cos(const adouble &a); - CUDADEV friend adouble asin(const adouble &a); - CUDADEV friend adouble acos(const adouble &a); - CUDADEV friend adouble atan(const adouble &a); - - CUDADEV friend adouble atan2(const adouble &a, const adouble &b); - CUDADEV friend adouble pow(const adouble &a, double v); - CUDADEV friend adouble pow(const adouble &a, const adouble &b); - CUDADEV friend adouble pow(double v, const adouble &a); - CUDADEV friend adouble log10(const adouble &a); - - CUDADEV friend adouble sinh (const adouble &a); - CUDADEV friend adouble cosh (const adouble &a); - CUDADEV friend adouble tanh (const adouble &a); - CUDADEV friend adouble asinh (const adouble &a); - CUDADEV friend adouble acosh (const adouble &a); - CUDADEV friend adouble atanh (const adouble &a); - CUDADEV friend adouble fabs (const adouble &a); - CUDADEV friend adouble ceil (const adouble &a); - CUDADEV friend adouble floor (const adouble &a); - CUDADEV friend adouble fmax (const adouble &a, const adouble &b); - CUDADEV friend adouble fmax (double v, const adouble &a); - CUDADEV friend adouble fmax (const adouble &a, double v); - CUDADEV friend adouble fmin (const adouble &a, const adouble &b); - CUDADEV friend adouble fmin (double v, const adouble &a); - CUDADEV friend adouble fmin (const adouble &a, double v); - CUDADEV friend adouble ldexp (const adouble &a, const adouble &b); - CUDADEV friend adouble ldexp (const adouble &a, const double v); - CUDADEV friend adouble ldexp (const double v, const adouble &a); - CUDADEV friend double frexp (const adouble &a, int* v); - CUDADEV friend adouble erf (const adouble &a); - CUDADEV friend adouble erfc (const adouble &a); - - - /******************* nontemporary results ***************************/ - // assignment - CUDADEV void operator = (const double v); - CUDADEV void operator = (const adouble& a); - - // addition - CUDADEV void operator += (const double v); - CUDADEV void operator += (const adouble& a); - - // subtraction - CUDADEV void operator -= (const double v); - CUDADEV void operator -= (const adouble& a); - - // multiplication - CUDADEV void operator *= (const double v); - CUDADEV void operator *= (const adouble& a); - - // division - CUDADEV void operator /= (const double v); - CUDADEV void operator /= (const adouble& a); - - // not - CUDADEV int operator ! () const; - - // comparison - CUDADEV int operator != (const adouble&) const; - CUDADEV int operator != (const double) const; - CUDADEV friend int operator != (const double, const adouble&); - - CUDADEV int operator == (const adouble&) const; - CUDADEV int operator == (const double) const; - CUDADEV friend int operator == (const double, const adouble&); - - CUDADEV int operator <= (const adouble&) const; - CUDADEV int operator <= (const double) const; - CUDADEV friend int operator <= (const double, const adouble&); - - CUDADEV int operator >= (const adouble&) const; - CUDADEV int operator >= (const double) const; - CUDADEV friend int operator >= (const double, const adouble&); - - CUDADEV int operator > (const adouble&) const; - CUDADEV int operator > (const double) const; - CUDADEV friend int operator > (const double, const adouble&); - - CUDADEV int operator < (const adouble&) const; - CUDADEV int operator < (const double) const; - CUDADEV friend int operator < (const double, const adouble&); - - /******************* getter / setter ********************************/ - CUDAHOSTDEV double getValue() const; - CUDAHOSTDEV void setValue(const double v); - CUDAHOSTDEV ADVAL_TYPE getADValue() const; - CUDAHOSTDEV void setADValue(ADVAL_TYPE v); -#if defined(NUMBER_DIRECTIONS) - CUDAHOSTDEV double getADValue(const unsigned int p) const; - CUDAHOSTDEV void setADValue(const unsigned int p, const double v); -#endif - - /******************* i/o operations *********************************/ - CUDAHOST friend ostream& operator << ( ostream&, const adouble& ); - CUDAHOST friend istream& operator >> ( istream&, adouble& ); + // ctors + CUDADEV adouble(); + CUDADEV adouble(const double v); + CUDADEV adouble(const double v, ADVAL_TYPE_ADV); + CUDADEV adouble(const adouble &a); + #if defined(DYNAMIC_DIRECTIONS) + CUDADEV ~adouble(); + #endif + /******************* temporary results ******************************/ + // sign + CUDADEV adouble operator-() const; + CUDADEV adouble operator+() const; + + // addition + CUDADEV adouble operator+(const double v) const; + CUDADEV adouble operator+(const adouble &a) const; + CUDADEV friend adouble operator+(const double v, const adouble &a); + + // subtraction + CUDADEV adouble operator-(const double v) const; + CUDADEV adouble operator-(const adouble &a) const; + CUDADEV friend adouble operator-(const double v, const adouble &a); + + // multiplication + CUDADEV adouble operator*(const double v) const; + CUDADEV adouble operator*(const adouble &a) const; + CUDADEV friend adouble operator*(const double v, const adouble &a); + + // division + CUDADEV adouble operator/(const double v) const; + CUDADEV adouble operator/(const adouble &a) const; + CUDADEV friend adouble operator/(const double v, const adouble &a); + + // inc/dec + CUDADEV adouble operator++(); + CUDADEV adouble operator++(int); + CUDADEV adouble operator--(); + CUDADEV adouble operator--(int); + + // functions + CUDADEV friend adouble tan(const adouble &a); + CUDADEV friend adouble exp(const adouble &a); + CUDADEV friend adouble log(const adouble &a); + CUDADEV friend adouble sqrt(const adouble &a); + CUDADEV friend adouble sin(const adouble &a); + CUDADEV friend adouble cos(const adouble &a); + CUDADEV friend adouble asin(const adouble &a); + CUDADEV friend adouble acos(const adouble &a); + CUDADEV friend adouble atan(const adouble &a); + + CUDADEV friend adouble atan2(const adouble &a, const adouble &b); + CUDADEV friend adouble pow(const adouble &a, double v); + CUDADEV friend adouble pow(const adouble &a, const adouble &b); + CUDADEV friend adouble pow(double v, const adouble &a); + CUDADEV friend adouble log10(const adouble &a); + + CUDADEV friend adouble sinh(const adouble &a); + CUDADEV friend adouble cosh(const adouble &a); + CUDADEV friend adouble tanh(const adouble &a); + CUDADEV friend adouble asinh(const adouble &a); + CUDADEV friend adouble acosh(const adouble &a); + CUDADEV friend adouble atanh(const adouble &a); + CUDADEV friend adouble fabs(const adouble &a); + CUDADEV friend adouble ceil(const adouble &a); + CUDADEV friend adouble floor(const adouble &a); + CUDADEV friend adouble fmax(const adouble &a, const adouble &b); + CUDADEV friend adouble fmax(double v, const adouble &a); + CUDADEV friend adouble fmax(const adouble &a, double v); + CUDADEV friend adouble fmin(const adouble &a, const adouble &b); + CUDADEV friend adouble fmin(double v, const adouble &a); + CUDADEV friend adouble fmin(const adouble &a, double v); + CUDADEV friend adouble ldexp(const adouble &a, const adouble &b); + CUDADEV friend adouble ldexp(const adouble &a, const double v); + CUDADEV friend adouble ldexp(const double v, const adouble &a); + CUDADEV friend double frexp(const adouble &a, int *v); + CUDADEV friend adouble erf(const adouble &a); + CUDADEV friend adouble erfc(const adouble &a); + + /******************* nontemporary results ***************************/ + // assignment + CUDADEV void operator=(const double v); + CUDADEV void operator=(const adouble &a); + + // addition + CUDADEV void operator+=(const double v); + CUDADEV void operator+=(const adouble &a); + + // subtraction + CUDADEV void operator-=(const double v); + CUDADEV void operator-=(const adouble &a); + + // multiplication + CUDADEV void operator*=(const double v); + CUDADEV void operator*=(const adouble &a); + + // division + CUDADEV void operator/=(const double v); + CUDADEV void operator/=(const adouble &a); + + // not + CUDADEV int operator!() const; + + // comparison + CUDADEV int operator!=(const adouble &) const; + CUDADEV int operator!=(const double) const; + CUDADEV friend int operator!=(const double, const adouble &); + + CUDADEV int operator==(const adouble &) const; + CUDADEV int operator==(const double) const; + CUDADEV friend int operator==(const double, const adouble &); + + CUDADEV int operator<=(const adouble &) const; + CUDADEV int operator<=(const double) const; + CUDADEV friend int operator<=(const double, const adouble &); + + CUDADEV int operator>=(const adouble &) const; + CUDADEV int operator>=(const double) const; + CUDADEV friend int operator>=(const double, const adouble &); + + CUDADEV int operator>(const adouble &) const; + CUDADEV int operator>(const double) const; + CUDADEV friend int operator>(const double, const adouble &); + + CUDADEV int operator<(const adouble &) const; + CUDADEV int operator<(const double) const; + CUDADEV friend int operator<(const double, const adouble &); + + /******************* getter / setter ********************************/ + CUDAHOSTDEV double getValue() const; + CUDAHOSTDEV void setValue(const double v); + CUDAHOSTDEV ADVAL_TYPE getADValue() const; + CUDAHOSTDEV void setADValue(ADVAL_TYPE v); + #if defined(NUMBER_DIRECTIONS) + CUDAHOSTDEV double getADValue(const unsigned int p) const; + CUDAHOSTDEV void setADValue(const unsigned int p, const double v); + #endif + + /******************* i/o operations *********************************/ + CUDAHOST friend ostream &operator<<(ostream &, const adouble &); + CUDAHOST friend istream &operator>>(istream &, adouble &); private: - // internal variables - double val; - double ADVAL_DECL; + // internal variables + double val; + double ADVAL_DECL; }; - + /******************************* ctors ************************************/ CUDADEV adouble::adouble() { -#if defined(DYNAMIC_DIRECTIONS) - adval = new double[ADOLC_numDir]; -#endif + #if defined(DYNAMIC_DIRECTIONS) + adval = new double[ADOLC_numDir]; + #endif } CUDADEV adouble::adouble(const double v) : val(v) { -#if defined(DYNAMIC_DIRECTIONS) - adval = new double[ADOLC_numDir]; -#endif - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I = 0.0; + #if defined(DYNAMIC_DIRECTIONS) + adval = new double[ADOLC_numDir]; + #endif + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = 0.0; } CUDADEV adouble::adouble(const double v, ADVAL_TYPE_ADV) : val(v) { -#if defined(DYNAMIC_DIRECTIONS) - adval = new double[ADOLC_numDir]; -#endif - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=ADV_I; + #if defined(DYNAMIC_DIRECTIONS) + adval = new double[ADOLC_numDir]; + #endif + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = ADV_I; } -CUDADEV adouble::adouble(const adouble& a) : val(a.val) { -#if defined(DYNAMIC_DIRECTIONS) - adval = new double[ADOLC_numDir]; -#endif - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=a.ADVAL_I; +CUDADEV adouble::adouble(const adouble &a) : val(a.val) { + #if defined(DYNAMIC_DIRECTIONS) + adval = new double[ADOLC_numDir]; + #endif + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = a.ADVAL_I; } -/******************************* dtors ************************************/ -#if defined(DYNAMIC_DIRECTIONS) -CUDADEV adouble::~adouble() { - delete[] adval; -} -#endif + /******************************* dtors ************************************/ + #if defined(DYNAMIC_DIRECTIONS) +CUDADEV adouble::~adouble() { delete[] adval; } + #endif /************************* temporary results ******************************/ // sign -CUDADEV adouble adouble::operator - () const { - adouble tmp; - tmp.val=-val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=-ADVAL_I; - return tmp; +CUDADEV adouble adouble::operator-() const { + adouble tmp; + tmp.val = -val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = -ADVAL_I; + return tmp; } -CUDADEV adouble adouble::operator + () const { - return *this; -} +CUDADEV adouble adouble::operator+() const { return *this; } // addition -CUDADEV adouble adouble::operator + (const double v) const { - return adouble(val+v, adval); +CUDADEV adouble adouble::operator+(const double v) const { + return adouble(val + v, adval); } -CUDADEV adouble adouble::operator + (const adouble& a) const { - adouble tmp; - tmp.val=val+a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I+a.ADVAL_I; - return tmp; +CUDADEV adouble adouble::operator+(const adouble &a) const { + adouble tmp; + tmp.val = val + a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I + a.ADVAL_I; + return tmp; } -CUDADEV adouble operator + (const double v, const adouble& a) { - return adouble(v+a.val, a.adval); +CUDADEV adouble operator+(const double v, const adouble &a) { + return adouble(v + a.val, a.adval); } // subtraction -CUDADEV adouble adouble::operator - (const double v) const { - return adouble(val-v, adval); +CUDADEV adouble adouble::operator-(const double v) const { + return adouble(val - v, adval); } -CUDADEV adouble adouble::operator - (const adouble& a) const { - adouble tmp; - tmp.val=val-a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I-a.ADVAL_I; - return tmp; +CUDADEV adouble adouble::operator-(const adouble &a) const { + adouble tmp; + tmp.val = val - a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I - a.ADVAL_I; + return tmp; } -CUDADEV adouble operator - (const double v, const adouble& a) { - adouble tmp; - tmp.val=v-a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=-a.ADVAL_I; - return tmp; +CUDADEV adouble operator-(const double v, const adouble &a) { + adouble tmp; + tmp.val = v - a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = -a.ADVAL_I; + return tmp; } // multiplication -CUDADEV adouble adouble::operator * (const double v) const { - adouble tmp; - tmp.val=val*v; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I*v; - return tmp; +CUDADEV adouble adouble::operator*(const double v) const { + adouble tmp; + tmp.val = val * v; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I * v; + return tmp; } -CUDADEV adouble adouble::operator * (const adouble& a) const { - adouble tmp; - tmp.val=val*a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I*a.val+val*a.ADVAL_I; - return tmp; +CUDADEV adouble adouble::operator*(const adouble &a) const { + adouble tmp; + tmp.val = val * a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I * a.val + val * a.ADVAL_I; + return tmp; } -CUDADEV adouble operator * (const double v, const adouble& a) { - adouble tmp; - tmp.val=v*a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=v*a.ADVAL_I; - return tmp; +CUDADEV adouble operator*(const double v, const adouble &a) { + adouble tmp; + tmp.val = v * a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = v * a.ADVAL_I; + return tmp; } // division -CUDADEV adouble adouble::operator / (const double v) const { - adouble tmp; - tmp.val=val/v; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I/v; - return tmp; +CUDADEV adouble adouble::operator/(const double v) const { + adouble tmp; + tmp.val = val / v; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I / v; + return tmp; } -CUDADEV adouble adouble::operator / (const adouble& a) const { - adouble tmp; - tmp.val=val/a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=(ADVAL_I*a.val-val*a.ADVAL_I)/(a.val*a.val); - return tmp; +CUDADEV adouble adouble::operator/(const adouble &a) const { + adouble tmp; + tmp.val = val / a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = (ADVAL_I * a.val - val * a.ADVAL_I) / (a.val * a.val); + return tmp; } -CUDADEV adouble operator / (const double v, const adouble& a) { - adouble tmp; - tmp.val=v/a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=(-v*a.ADVAL_I)/(a.val*a.val); - return tmp; +CUDADEV adouble operator/(const double v, const adouble &a) { + adouble tmp; + tmp.val = v / a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = (-v * a.ADVAL_I) / (a.val * a.val); + return tmp; } // inc/dec -CUDADEV adouble adouble::operator ++ () { - ++val; - return *this; +CUDADEV adouble adouble::operator++() { + ++val; + return *this; } -CUDADEV adouble adouble::operator ++ (int) { - adouble tmp; - tmp.val=val++; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I; - return tmp; +CUDADEV adouble adouble::operator++(int) { + adouble tmp; + tmp.val = val++; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I; + return tmp; } -CUDADEV adouble adouble::operator -- () { - --val; - return *this; +CUDADEV adouble adouble::operator--() { + --val; + return *this; } -CUDADEV adouble adouble::operator -- (int) { - adouble tmp; - tmp.val=val--; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I; - return tmp; +CUDADEV adouble adouble::operator--(int) { + adouble tmp; + tmp.val = val--; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I; + return tmp; } // functions -CUDADEV adouble tan(const adouble& a) { - adouble tmp; - double tmp2; - tmp.val=ADOLC_MATH_NSP::tan(a.val); - tmp2=ADOLC_MATH_NSP::cos(a.val); - tmp2*=tmp2; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; +CUDADEV adouble tan(const adouble &a) { + adouble tmp; + double tmp2; + tmp.val = ADOLC_MATH_NSP::tan(a.val); + tmp2 = ADOLC_MATH_NSP::cos(a.val); + tmp2 *= tmp2; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; } CUDADEV adouble exp(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::exp(a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=tmp.val*a.ADVAL_I; - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::exp(a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = tmp.val * a.ADVAL_I; + return tmp; } CUDADEV adouble log(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::log(a.val); - FOR_I_EQ_0_LT_NUMDIR - if (a.val>0) tmp.ADVAL_I=a.ADVAL_I/a.val; - else if (a.val==0 && a.ADVAL_I != 0.0) { - int sign = (a.ADVAL_I < 0) ? -1 : 1; - tmp.ADVAL_I=sign* makeInf(); - } else tmp.ADVAL_I=makeNaN(); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::log(a.val); + FOR_I_EQ_0_LT_NUMDIR + if (a.val > 0) + tmp.ADVAL_I = a.ADVAL_I / a.val; + else if (a.val == 0 && a.ADVAL_I != 0.0) { + int sign = (a.ADVAL_I < 0) ? -1 : 1; + tmp.ADVAL_I = sign * makeInf(); + } else + tmp.ADVAL_I = makeNaN(); + return tmp; } CUDADEV adouble sqrt(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::sqrt(a.val); - FOR_I_EQ_0_LT_NUMDIR - if (a.val>0) tmp.ADVAL_I=a.ADVAL_I/(tmp.val*2); - else if (a.val==0.0 && a.ADVAL_I != 0.0) { - int sign = (a.ADVAL_I < 0) ? -1 : 1; - tmp.ADVAL_I=sign * makeInf(); - } - else tmp.ADVAL_I=makeNaN(); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::sqrt(a.val); + FOR_I_EQ_0_LT_NUMDIR + if (a.val > 0) + tmp.ADVAL_I = a.ADVAL_I / (tmp.val * 2); + else if (a.val == 0.0 && a.ADVAL_I != 0.0) { + int sign = (a.ADVAL_I < 0) ? -1 : 1; + tmp.ADVAL_I = sign * makeInf(); + } else + tmp.ADVAL_I = makeNaN(); + return tmp; } CUDADEV adouble sin(const adouble &a) { - adouble tmp; - double tmp2; - tmp.val=ADOLC_MATH_NSP::sin(a.val); - tmp2=ADOLC_MATH_NSP::cos(a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; + adouble tmp; + double tmp2; + tmp.val = ADOLC_MATH_NSP::sin(a.val); + tmp2 = ADOLC_MATH_NSP::cos(a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } CUDADEV adouble cos(const adouble &a) { - adouble tmp; - double tmp2; - tmp.val=ADOLC_MATH_NSP::cos(a.val); - tmp2=-ADOLC_MATH_NSP::sin(a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; + adouble tmp; + double tmp2; + tmp.val = ADOLC_MATH_NSP::cos(a.val); + tmp2 = -ADOLC_MATH_NSP::sin(a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } CUDADEV adouble asin(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::asin(a.val); - double tmp2=ADOLC_MATH_NSP::sqrt(1-a.val*a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::asin(a.val); + double tmp2 = ADOLC_MATH_NSP::sqrt(1 - a.val * a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; } CUDADEV adouble acos(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::acos(a.val); - double tmp2=-ADOLC_MATH_NSP::sqrt(1-a.val*a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::acos(a.val); + double tmp2 = -ADOLC_MATH_NSP::sqrt(1 - a.val * a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; } CUDADEV adouble atan(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::atan(a.val); - double tmp2=1+a.val*a.val; - tmp2=1/tmp2; - if (tmp2!=0) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*tmp2; - else - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::atan(a.val); + double tmp2 = 1 + a.val * a.val; + tmp2 = 1 / tmp2; + if (tmp2 != 0) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * tmp2; + else FOR_I_EQ_0_LT_NUMDIR tmp.ADVAL_I = 0.0; + return tmp; } CUDADEV adouble atan2(const adouble &a, const adouble &b) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::atan2(a.val, b.val); - double tmp2=a.val*a.val; - double tmp3=b.val*b.val; - double tmp4=tmp3/(tmp2+tmp3); - if (tmp4!=0) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=(a.ADVAL_I*b.val-a.val*b.ADVAL_I)/tmp3*tmp4; - else - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::atan2(a.val, b.val); + double tmp2 = a.val * a.val; + double tmp3 = b.val * b.val; + double tmp4 = tmp3 / (tmp2 + tmp3); + if (tmp4 != 0) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = (a.ADVAL_I * b.val - a.val * b.ADVAL_I) / tmp3 * tmp4; + else FOR_I_EQ_0_LT_NUMDIR tmp.ADVAL_I = 0.0; + return tmp; } CUDADEV adouble pow(const adouble &a, double v) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::pow(a.val, v); - double tmp2=v*ADOLC_MATH_NSP::pow(a.val, v-1); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::pow(a.val, v); + double tmp2 = v * ADOLC_MATH_NSP::pow(a.val, v - 1); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } CUDADEV adouble pow(const adouble &a, const adouble &b) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::pow(a.val, b.val); - double tmp2=b.val*ADOLC_MATH_NSP::pow(a.val, b.val-1); - double tmp3=ADOLC_MATH_NSP::log(a.val)*tmp.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I+tmp3*b.ADVAL_I; - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::pow(a.val, b.val); + double tmp2 = b.val * ADOLC_MATH_NSP::pow(a.val, b.val - 1); + double tmp3 = ADOLC_MATH_NSP::log(a.val) * tmp.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I + tmp3 * b.ADVAL_I; + return tmp; } CUDADEV adouble pow(double v, const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::pow(v, a.val); - double tmp2=tmp.val*ADOLC_MATH_NSP::log(v); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::pow(v, a.val); + double tmp2 = tmp.val * ADOLC_MATH_NSP::log(v); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } CUDADEV adouble log10(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::log10(a.val); - double tmp2=ADOLC_MATH_NSP::log((double)10)*a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -CUDADEV adouble sinh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::sinh(a.val); - double tmp2=ADOLC_MATH_NSP::cosh(a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*tmp2; - return tmp; -} - -CUDADEV adouble cosh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::cosh(a.val); - double tmp2=ADOLC_MATH_NSP::sinh(a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*tmp2; - return tmp; -} - -CUDADEV adouble tanh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::tanh(a.val); - double tmp2=ADOLC_MATH_NSP::cosh(a.val); - tmp2*=tmp2; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -CUDADEV adouble asinh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::asinh(a.val); - double tmp2=ADOLC_MATH_NSP::sqrt(a.val*a.val+1); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -CUDADEV adouble acosh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::acosh(a.val); - double tmp2=ADOLC_MATH_NSP::sqrt(a.val*a.val-1); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -CUDADEV adouble atanh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::atanh(a.val); - double tmp2=1-a.val*a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -CUDADEV adouble fabs (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::fabs(a.val); - int as=0; - if (a.val>0) as=1; - if (a.val<0) as=-1; - if (as!=0) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*as; - else - FOR_I_EQ_0_LT_NUMDIR { - as=0; - if (a.ADVAL_I>0) as=1; - if (a.ADVAL_I<0) as=-1; - tmp.ADVAL_I=a.ADVAL_I*as; - } - return tmp; -} - -CUDADEV adouble ceil (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::ceil(a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; - return tmp; -} - -CUDADEV adouble floor (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::floor(a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; - return tmp; -} - -CUDADEV adouble fmax (const adouble &a, const adouble &b) { - adouble tmp; - double tmp2=a.val-b.val; - if (tmp2<0) { - tmp.val=b.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=b.ADVAL_I; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::log10(a.val); + double tmp2 = ADOLC_MATH_NSP::log((double)10) * a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +CUDADEV adouble sinh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::sinh(a.val); + double tmp2 = ADOLC_MATH_NSP::cosh(a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * tmp2; + return tmp; +} + +CUDADEV adouble cosh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::cosh(a.val); + double tmp2 = ADOLC_MATH_NSP::sinh(a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * tmp2; + return tmp; +} + +CUDADEV adouble tanh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::tanh(a.val); + double tmp2 = ADOLC_MATH_NSP::cosh(a.val); + tmp2 *= tmp2; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +CUDADEV adouble asinh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::asinh(a.val); + double tmp2 = ADOLC_MATH_NSP::sqrt(a.val * a.val + 1); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +CUDADEV adouble acosh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::acosh(a.val); + double tmp2 = ADOLC_MATH_NSP::sqrt(a.val * a.val - 1); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +CUDADEV adouble atanh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::atanh(a.val); + double tmp2 = 1 - a.val * a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +CUDADEV adouble fabs(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::fabs(a.val); + int as = 0; + if (a.val > 0) + as = 1; + if (a.val < 0) + as = -1; + if (as != 0) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * as; + else FOR_I_EQ_0_LT_NUMDIR { + as = 0; + if (a.ADVAL_I > 0) + as = 1; + if (a.ADVAL_I < 0) + as = -1; + tmp.ADVAL_I = a.ADVAL_I * as; + } + return tmp; +} + +CUDADEV adouble ceil(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::ceil(a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = 0.0; + return tmp; +} + +CUDADEV adouble floor(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::floor(a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = 0.0; + return tmp; +} + +CUDADEV adouble fmax(const adouble &a, const adouble &b) { + adouble tmp; + double tmp2 = a.val - b.val; + if (tmp2 < 0) { + tmp.val = b.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = b.ADVAL_I; + } else { + tmp.val = a.val; + if (tmp2 > 0) { + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; } else { - tmp.val=a.val; - if (tmp2>0) { - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - } else { - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I 0) { + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = 0.0; } else { - tmp.val=v; - if (tmp2>0) { - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; - } else { - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I>0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - } -} -return tmp; -} - -CUDADEV adouble fmax (const adouble &a, double v) { - adouble tmp; - double tmp2=a.val-v; - if (tmp2<0) { - tmp.val=v; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; + FOR_I_EQ_0_LT_NUMDIR { + if (a.ADVAL_I > 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } + } + } + return tmp; +} + +CUDADEV adouble fmax(const adouble &a, double v) { + adouble tmp; + double tmp2 = a.val - v; + if (tmp2 < 0) { + tmp.val = v; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = 0.0; + } else { + tmp.val = a.val; + if (tmp2 > 0) { + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; } else { - tmp.val=a.val; - if (tmp2>0) { - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - } else { - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I>0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - } -} -return tmp; -} - -CUDADEV adouble fmin (const adouble &a, const adouble &b) { - adouble tmp; - double tmp2=a.val-b.val; - if (tmp2<0) { - tmp.val=a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; + FOR_I_EQ_0_LT_NUMDIR { + if (a.ADVAL_I > 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } + } + } + return tmp; +} + +CUDADEV adouble fmin(const adouble &a, const adouble &b) { + adouble tmp; + double tmp2 = a.val - b.val; + if (tmp2 < 0) { + tmp.val = a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; + } else { + tmp.val = b.val; + if (tmp2 > 0) { + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = b.ADVAL_I; } else { - tmp.val=b.val; - if (tmp2>0) { - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=b.ADVAL_I; - } else { - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I 0) { + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; } else { - tmp.val=a.val; - if (tmp2>0) { - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - } else { - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I<0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - } -} -return tmp; -} - -CUDADEV adouble fmin (const adouble &a, double v) { - adouble tmp; - double tmp2=a.val-v; - if (tmp2<0) { - tmp.val=a.val; - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; + FOR_I_EQ_0_LT_NUMDIR { + if (a.ADVAL_I < 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } + } + } + return tmp; +} + +CUDADEV adouble fmin(const adouble &a, double v) { + adouble tmp; + double tmp2 = a.val - v; + if (tmp2 < 0) { + tmp.val = a.val; + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; + } else { + tmp.val = v; + if (tmp2 > 0) { + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = 0.0; } else { - tmp.val=v; - if (tmp2>0) { - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; - } else { - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I<0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - } -} -return tmp; + FOR_I_EQ_0_LT_NUMDIR { + if (a.ADVAL_I < 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } + } + } + return tmp; } -CUDADEV adouble ldexp (const adouble &a, const adouble &b) { - return a*pow(2.,b); +CUDADEV adouble ldexp(const adouble &a, const adouble &b) { + return a * pow(2., b); } -CUDADEV adouble ldexp (const adouble &a, const double v) { - return a*ADOLC_MATH_NSP::pow(2.,v); +CUDADEV adouble ldexp(const adouble &a, const double v) { + return a * ADOLC_MATH_NSP::pow(2., v); } -CUDADEV adouble ldexp (const double v, const adouble &a) { - return v*pow(2.,a); +CUDADEV adouble ldexp(const double v, const adouble &a) { + return v * pow(2., a); } -CUDADEV double frexp (const adouble &a, int* v) { - return ADOLC_MATH_NSP::frexp(a.val, v); +CUDADEV double frexp(const adouble &a, int *v) { + return ADOLC_MATH_NSP::frexp(a.val, v); } -CUDADEV adouble erf (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::erf(a.val); - double tmp2 = 2.0 / - ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * - ADOLC_MATH_NSP_ERF::exp(-a.val*a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; +CUDADEV adouble erf(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::erf(a.val); + double tmp2 = 2.0 / ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * + ADOLC_MATH_NSP_ERF::exp(-a.val * a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } -CUDADEV adouble erfc (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::erfc(a.val); - double tmp2 = -2.0 / - ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * - ADOLC_MATH_NSP_ERF::exp(-a.val*a.val); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; +CUDADEV adouble erfc(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::erfc(a.val); + double tmp2 = -2.0 / ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * + ADOLC_MATH_NSP_ERF::exp(-a.val * a.val); + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } /******************* nontemporary results *********************************/ -CUDADEV void adouble::operator = (const double v) { - val=v; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=0.0; +CUDADEV void adouble::operator=(const double v) { + val = v; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = 0.0; } -CUDADEV void adouble::operator = (const adouble& a) { - val=a.val; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=a.ADVAL_I; +CUDADEV void adouble::operator=(const adouble &a) { + val = a.val; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = a.ADVAL_I; } -CUDADEV void adouble::operator += (const double v) { - val+=v; -} +CUDADEV void adouble::operator+=(const double v) { val += v; } -CUDADEV void adouble::operator += (const adouble& a) { - val=val+a.val; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I+=a.ADVAL_I; +CUDADEV void adouble::operator+=(const adouble &a) { + val = val + a.val; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I += a.ADVAL_I; } -CUDADEV void adouble::operator -= (const double v) { - val-=v; -} +CUDADEV void adouble::operator-=(const double v) { val -= v; } -CUDADEV void adouble::operator -= (const adouble& a) { - val=val-a.val; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I-=a.ADVAL_I; +CUDADEV void adouble::operator-=(const adouble &a) { + val = val - a.val; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I -= a.ADVAL_I; } -CUDADEV void adouble::operator *= (const double v) { - val=val*v; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I*=v; +CUDADEV void adouble::operator*=(const double v) { + val = val * v; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I *= v; } -CUDADEV void adouble::operator *= (const adouble& a) { - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=ADVAL_I*a.val+val*a.ADVAL_I; - val*=a.val; +CUDADEV void adouble::operator*=(const adouble &a) { + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = ADVAL_I * a.val + val * a.ADVAL_I; + val *= a.val; } -CUDADEV void adouble::operator /= (const double v) { - val/=v; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I/=v; +CUDADEV void adouble::operator/=(const double v) { + val /= v; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I /= v; } -CUDADEV void adouble::operator /= (const adouble& a) { - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=(ADVAL_I*a.val-val*a.ADVAL_I)/(a.val*a.val); - val=val/a.val; +CUDADEV void adouble::operator/=(const adouble &a) { + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = (ADVAL_I * a.val - val * a.ADVAL_I) / (a.val * a.val); + val = val / a.val; } // not -CUDADEV int adouble::operator ! () const { - return val==0.0; -} +CUDADEV int adouble::operator!() const { return val == 0.0; } // comparison -CUDADEV int adouble::operator != (const adouble &a) const { - return val!=a.val; -} +CUDADEV int adouble::operator!=(const adouble &a) const { return val != a.val; } -CUDADEV int adouble::operator != (const double v) const { - return val!=v; -} +CUDADEV int adouble::operator!=(const double v) const { return val != v; } -CUDADEV int operator != (const double v, const adouble &a) { - return v!=a.val; -} +CUDADEV int operator!=(const double v, const adouble &a) { return v != a.val; } -CUDADEV int adouble::operator == (const adouble &a) const { - return val==a.val; -} +CUDADEV int adouble::operator==(const adouble &a) const { return val == a.val; } -CUDADEV int adouble::operator == (const double v) const { - return val==v; -} +CUDADEV int adouble::operator==(const double v) const { return val == v; } -CUDADEV int operator == (const double v, const adouble &a) { - return v==a.val; -} +CUDADEV int operator==(const double v, const adouble &a) { return v == a.val; } -CUDADEV int adouble::operator <= (const adouble &a) const { - return val<=a.val; -} +CUDADEV int adouble::operator<=(const adouble &a) const { return val <= a.val; } -CUDADEV int adouble::operator <= (const double v) const { - return val<=v; -} +CUDADEV int adouble::operator<=(const double v) const { return val <= v; } -CUDADEV int operator <= (const double v, const adouble &a) { - return v<=a.val; -} +CUDADEV int operator<=(const double v, const adouble &a) { return v <= a.val; } -CUDADEV int adouble::operator >= (const adouble &a) const { - return val>=a.val; -} +CUDADEV int adouble::operator>=(const adouble &a) const { return val >= a.val; } -CUDADEV int adouble::operator >= (const double v) const { - return val>=v; -} +CUDADEV int adouble::operator>=(const double v) const { return val >= v; } -CUDADEV int operator >= (const double v, const adouble &a) { - return v>=a.val; -} +CUDADEV int operator>=(const double v, const adouble &a) { return v >= a.val; } -CUDADEV int adouble::operator > (const adouble &a) const { - return val>a.val; -} +CUDADEV int adouble::operator>(const adouble &a) const { return val > a.val; } -CUDADEV int adouble::operator > (const double v) const { - return val>v; -} +CUDADEV int adouble::operator>(const double v) const { return val > v; } -CUDADEV int operator > (const double v, const adouble &a) { - return v>a.val; -} +CUDADEV int operator>(const double v, const adouble &a) { return v > a.val; } -CUDADEV int adouble::operator < (const adouble &a) const { - return val=ADOLC_numDir) { - locp = ADOLC_numDir -1; - } - return adval[locp]; + unsigned int locp = p; + if (locp >= ADOLC_numDir) { + locp = ADOLC_numDir - 1; + } + return adval[locp]; } CUDAHOSTDEV void adouble::setADValue(const unsigned int p, const double v) { - unsigned int locp = p; - if (locp>=ADOLC_numDir) { - locp = ADOLC_numDir - 1; - } - adval[locp]=v; + unsigned int locp = p; + if (locp >= ADOLC_numDir) { + locp = ADOLC_numDir - 1; + } + adval[locp] = v; } -# endif + #endif -#if defined(NUMBER_DIRECTIONS) + #if defined(NUMBER_DIRECTIONS) void setNumDir(const unsigned int p) { -#if !defined(DYNAMIC_DIRECTIONS) - if (p>NUMBER_DIRECTIONS) ADOLC_numDir=NUMBER_DIRECTIONS; - else ADOLC_numDir=p; -#else + #if !defined(DYNAMIC_DIRECTIONS) + if (p > NUMBER_DIRECTIONS) + ADOLC_numDir = NUMBER_DIRECTIONS; + else ADOLC_numDir = p; -#endif + #else + ADOLC_numDir = p; + #endif } -#endif + #endif /******************* i/o operations ***************************************/ -CUDAHOST ostream& operator << ( ostream& out, const adouble& a) { - out << "Value: " << a.val; -#if !defined(NUMBER_DIRECTIONS) - out << " ADValue: "; -#else - out << " ADValues (" << ADOLC_numDir << "): "; -#endif - FOR_I_EQ_0_LT_NUMDIR - out << a.ADVAL_I << " "; - out << "(a)"; - return out; -} - -CUDAHOST istream& operator >> ( istream& in, adouble& a) { - char c; - do { - in >> c; - } while (c!=':' && !in.eof()); - in >> a.val; -#if !defined(NUMBER_DIRECTIONS) - do in >> c; - while (c!=':' && !in.eof()); -#else -unsigned int num; -do in >> c; -while (c!='(' && !in.eof()); -in >> num; -if (num>NUMBER_DIRECTIONS) { +CUDAHOST ostream &operator<<(ostream &out, const adouble &a) { + out << "Value: " << a.val; + #if !defined(NUMBER_DIRECTIONS) + out << " ADValue: "; + #else + out << " ADValues (" << ADOLC_numDir << "): "; + #endif + FOR_I_EQ_0_LT_NUMDIR + out << a.ADVAL_I << " "; + out << "(a)"; + return out; +} + +CUDAHOST istream &operator>>(istream &in, adouble &a) { + char c; + do { + in >> c; + } while (c != ':' && !in.eof()); + in >> a.val; + #if !defined(NUMBER_DIRECTIONS) + do + in >> c; + while (c != ':' && !in.eof()); + #else + unsigned int num; + do + in >> c; + while (c != '(' && !in.eof()); + in >> num; + if (num > NUMBER_DIRECTIONS) { cout << "ADOL-C error: to many directions in input\n"; exit(-1); -} -do in >> c; -while (c!=')' && !in.eof()); -#endif - FOR_I_EQ_0_LT_NUMDIR - in >> a.ADVAL_I; - do in >> c; - while (c!=')' && !in.eof()); - return in; -} -} + } + do + in >> c; + while (c != ')' && !in.eof()); + #endif + FOR_I_EQ_0_LT_NUMDIR + in >> a.ADVAL_I; + do + in >> c; + while (c != ')' && !in.eof()); + return in; +} +} // namespace adtlc /****************************************************************************/ -/* end traceless gpu implementation first order derivatives */ +/* end traceless gpu implementation first order derivatives */ /****************************************************************************/ #endif diff --git a/ADOL-C/include/adolc/adtl.h b/ADOL-C/include/adolc/adtl.h index 88865abb3..7fe2aac73 100644 --- a/ADOL-C/include/adolc/adtl.h +++ b/ADOL-C/include/adolc/adtl.h @@ -17,19 +17,19 @@ #ifndef ADOLC_ADTL_H #define ADOLC_ADTL_H -#include #include #include +#include #include #if USE_BOOST_POOL -#include + #include #endif -using std::ostream; using std::istream; using std::list; using std::logic_error; +using std::ostream; namespace adtl { @@ -41,193 +41,190 @@ class adouble; class refcounter { private: - ADOLC_DLL_EXPIMP static size_t refcnt; - ADOLC_DLL_EXPORT friend void setNumDir(const size_t p); - friend class adouble; + ADOLC_DLL_EXPIMP static size_t refcnt; + ADOLC_DLL_EXPORT friend void setNumDir(const size_t p); + friend class adouble; + public: - refcounter() { ++refcnt; } - ~refcounter() { --refcnt; } - inline static size_t getNumLiveVar() {return refcnt;} + refcounter() { ++refcnt; } + ~refcounter() { --refcnt; } + inline static size_t getNumLiveVar() { return refcnt; } }; #endif - -//class func_ad { -//public: -// virtual int operator() (int n, adouble *x, int m, adouble *y) = 0; -//}; +// class func_ad { +// public: +// virtual int operator() (int n, adouble *x, int m, adouble *y) = 0; +// }; class adouble { public: - inline adouble(); - inline adouble(const double v); - inline adouble(const double v, const double* adv); - inline adouble(const adouble& a); - inline ~adouble(); - - // sign - inline adouble operator - () const; - inline adouble operator + () const; - - // addition - inline adouble operator + (const double v) const; - inline adouble operator + (const adouble& a) const; - inline friend - adouble operator + (const double v, const adouble& a); - - // subtraction - inline adouble operator - (const double v) const; - inline adouble operator - (const adouble& a) const; - inline friend - adouble operator - (const double v, const adouble& a); - - // multiplication - inline adouble operator * (const double v) const; - inline adouble operator * (const adouble& a) const; - inline friend - adouble operator * (const double v, const adouble& a); - - // division - inline adouble operator / (const double v) const; - inline adouble operator / (const adouble& a) const; - inline friend - adouble operator / (const double v, const adouble& a); - - // inc/dec - inline adouble operator ++ (); - inline adouble operator ++ (int); - inline adouble operator -- (); - inline adouble operator -- (int); - - // functions - inline friend adouble tan(const adouble &a); - inline friend adouble exp(const adouble &a); - inline friend adouble log(const adouble &a); - inline friend adouble sqrt(const adouble &a); - inline friend adouble cbrt(const adouble &a); - inline friend adouble sin(const adouble &a); - inline friend adouble cos(const adouble &a); - inline friend adouble asin(const adouble &a); - inline friend adouble acos(const adouble &a); - inline friend adouble atan(const adouble &a); - - inline friend adouble atan2(const adouble &a, const adouble &b); - inline friend adouble pow(const adouble &a, double v); - inline friend adouble pow(const adouble &a, const adouble &b); - inline friend adouble pow(double v, const adouble &a); - inline friend adouble log10(const adouble &a); - - inline friend adouble sinh (const adouble &a); - inline friend adouble cosh (const adouble &a); - inline friend adouble tanh (const adouble &a); - inline friend adouble asinh (const adouble &a); - inline friend adouble acosh (const adouble &a); - inline friend adouble atanh (const adouble &a); - inline friend adouble fabs (const adouble &a); - inline friend adouble ceil (const adouble &a); - inline friend adouble floor (const adouble &a); - inline friend adouble fmax (const adouble &a, const adouble &b); - inline friend adouble fmax (double v, const adouble &a); - inline friend adouble fmax (const adouble &a, double v); - inline friend adouble fmin (const adouble &a, const adouble &b); - inline friend adouble fmin (double v, const adouble &a); - inline friend adouble fmin (const adouble &a, double v); - inline friend adouble ldexp (const adouble &a, const adouble &b); - inline friend adouble ldexp (const adouble &a, const double v); - inline friend adouble ldexp (const double v, const adouble &a); - inline friend double frexp (const adouble &a, int* v); - inline friend adouble erf (const adouble &a); - inline friend adouble erfc (const adouble &a); - - inline friend void condassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ); - inline friend void condassign( adouble &res, const adouble &cond, - const adouble &arg ); - inline friend void condeqassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ); - inline friend void condeqassign( adouble &res, const adouble &cond, - const adouble &arg ); - - /******************* nontemporary results ***************************/ - // assignment - inline adouble& operator = (const double v); - inline adouble& operator = (const adouble& a); - - // addition - inline adouble& operator += (const double v); - inline adouble& operator += (const adouble& a); - - // subtraction - inline adouble& operator -= (const double v); - inline adouble& operator -= (const adouble& a); - - // multiplication - inline adouble& operator *= (const double v); - inline adouble& operator *= (const adouble& a); - - // division - inline adouble& operator /= (const double v); - inline adouble& operator /= (const adouble& a); - - // not - inline bool operator ! () const; - - // comparison - inline bool operator != (const adouble&) const; - inline bool operator != (const double) const; - inline friend bool operator != (const double, const adouble&); - - inline bool operator == (const adouble&) const; - inline bool operator == (const double) const; - inline friend bool operator == (const double, const adouble&); - - inline bool operator <= (const adouble&) const; - inline bool operator <= (const double) const; - inline friend bool operator <= (const double, const adouble&); - - inline bool operator >= (const adouble&) const; - inline bool operator >= (const double) const; - inline friend bool operator >= (const double, const adouble&); - - inline bool operator > (const adouble&) const; - inline bool operator > (const double) const; - inline friend bool operator > (const double, const adouble&); - - inline bool operator < (const adouble&) const; - inline bool operator < (const double) const; - inline friend bool operator < (const double, const adouble&); - - /******************* getter / setter ********************************/ - inline double getValue() const; - inline void setValue(const double v); - inline const double* const getADValue() const; - inline void setADValue(const double* v); - - inline double getADValue(const unsigned int p) const; - inline void setADValue(const unsigned int p, const double v); - inline explicit operator double const&() const; - inline explicit operator double&&(); - inline explicit operator double(); + inline adouble(); + inline adouble(const double v); + inline adouble(const double v, const double *adv); + inline adouble(const adouble &a); + inline ~adouble(); + + // sign + inline adouble operator-() const; + inline adouble operator+() const; + + // addition + inline adouble operator+(const double v) const; + inline adouble operator+(const adouble &a) const; + inline friend adouble operator+(const double v, const adouble &a); + + // subtraction + inline adouble operator-(const double v) const; + inline adouble operator-(const adouble &a) const; + inline friend adouble operator-(const double v, const adouble &a); + + // multiplication + inline adouble operator*(const double v) const; + inline adouble operator*(const adouble &a) const; + inline friend adouble operator*(const double v, const adouble &a); + + // division + inline adouble operator/(const double v) const; + inline adouble operator/(const adouble &a) const; + inline friend adouble operator/(const double v, const adouble &a); + + // inc/dec + inline adouble operator++(); + inline adouble operator++(int); + inline adouble operator--(); + inline adouble operator--(int); + + // functions + inline friend adouble tan(const adouble &a); + inline friend adouble exp(const adouble &a); + inline friend adouble log(const adouble &a); + inline friend adouble sqrt(const adouble &a); + inline friend adouble cbrt(const adouble &a); + inline friend adouble sin(const adouble &a); + inline friend adouble cos(const adouble &a); + inline friend adouble asin(const adouble &a); + inline friend adouble acos(const adouble &a); + inline friend adouble atan(const adouble &a); + + inline friend adouble atan2(const adouble &a, const adouble &b); + inline friend adouble pow(const adouble &a, double v); + inline friend adouble pow(const adouble &a, const adouble &b); + inline friend adouble pow(double v, const adouble &a); + inline friend adouble log10(const adouble &a); + + inline friend adouble sinh(const adouble &a); + inline friend adouble cosh(const adouble &a); + inline friend adouble tanh(const adouble &a); + inline friend adouble asinh(const adouble &a); + inline friend adouble acosh(const adouble &a); + inline friend adouble atanh(const adouble &a); + inline friend adouble fabs(const adouble &a); + inline friend adouble ceil(const adouble &a); + inline friend adouble floor(const adouble &a); + inline friend adouble fmax(const adouble &a, const adouble &b); + inline friend adouble fmax(double v, const adouble &a); + inline friend adouble fmax(const adouble &a, double v); + inline friend adouble fmin(const adouble &a, const adouble &b); + inline friend adouble fmin(double v, const adouble &a); + inline friend adouble fmin(const adouble &a, double v); + inline friend adouble ldexp(const adouble &a, const adouble &b); + inline friend adouble ldexp(const adouble &a, const double v); + inline friend adouble ldexp(const double v, const adouble &a); + inline friend double frexp(const adouble &a, int *v); + inline friend adouble erf(const adouble &a); + inline friend adouble erfc(const adouble &a); + + inline friend void condassign(adouble &res, const adouble &cond, + const adouble &arg1, const adouble &arg2); + inline friend void condassign(adouble &res, const adouble &cond, + const adouble &arg); + inline friend void condeqassign(adouble &res, const adouble &cond, + const adouble &arg1, const adouble &arg2); + inline friend void condeqassign(adouble &res, const adouble &cond, + const adouble &arg); + + /******************* nontemporary results ***************************/ + // assignment + inline adouble &operator=(const double v); + inline adouble &operator=(const adouble &a); + + // addition + inline adouble &operator+=(const double v); + inline adouble &operator+=(const adouble &a); + + // subtraction + inline adouble &operator-=(const double v); + inline adouble &operator-=(const adouble &a); + + // multiplication + inline adouble &operator*=(const double v); + inline adouble &operator*=(const adouble &a); + + // division + inline adouble &operator/=(const double v); + inline adouble &operator/=(const adouble &a); + + // not + inline bool operator!() const; + + // comparison + inline bool operator!=(const adouble &) const; + inline bool operator!=(const double) const; + inline friend bool operator!=(const double, const adouble &); + + inline bool operator==(const adouble &) const; + inline bool operator==(const double) const; + inline friend bool operator==(const double, const adouble &); + + inline bool operator<=(const adouble &) const; + inline bool operator<=(const double) const; + inline friend bool operator<=(const double, const adouble &); + + inline bool operator>=(const adouble &) const; + inline bool operator>=(const double) const; + inline friend bool operator>=(const double, const adouble &); + + inline bool operator>(const adouble &) const; + inline bool operator>(const double) const; + inline friend bool operator>(const double, const adouble &); + + inline bool operator<(const adouble &) const; + inline bool operator<(const double) const; + inline friend bool operator<(const double, const adouble &); + + /******************* getter / setter ********************************/ + inline double getValue() const; + inline void setValue(const double v); + inline const double *const getADValue() const; + inline void setADValue(const double *v); + + inline double getADValue(const unsigned int p) const; + inline void setADValue(const unsigned int p, const double v); + inline explicit operator double const &() const; + inline explicit operator double &&(); + inline explicit operator double(); public: - /******************* i/o operations *********************************/ - ADOLC_DLL_EXPORT friend ostream& operator << ( ostream&, const adouble& ); - ADOLC_DLL_EXPORT friend istream& operator >> ( istream&, adouble& ); + /******************* i/o operations *********************************/ + ADOLC_DLL_EXPORT friend ostream &operator<<(ostream &, const adouble &); + ADOLC_DLL_EXPORT friend istream &operator>>(istream &, adouble &); private: #if USE_BOOST_POOL - ADOLC_DLL_EXPIMP static boost::pool* advalpool; + ADOLC_DLL_EXPIMP static boost::pool + *advalpool; #endif - double *adval; + double *adval; #ifdef USE_ADTL_REFCOUNTING - refcounter __rcnt; + refcounter __rcnt; #endif - ADOLC_DLL_EXPIMP static size_t numDir; - inline friend void setNumDir(const size_t p); - inline friend size_t getNumDir(); + ADOLC_DLL_EXPIMP static size_t numDir; + inline friend void setNumDir(const size_t p); + inline friend size_t getNumDir(); }; -} +} // namespace adtl #include #include @@ -238,866 +235,863 @@ namespace adtl { inline void setNumDir(const size_t p) { #ifdef USE_ADTL_REFCOUNTING if (refcounter::refcnt > 0) { - fprintf(DIAG_OUT, "ADOL-C Warning: Traceless: Setting numDir will not change the number of\n directional derivative in existing adoubles and may lead to erroneous results\n or memory corruption\n Number of currently existing adoubles = %zu\n", refcounter::refcnt); + fprintf(DIAG_OUT, + "ADOL-C Warning: Traceless: Setting numDir will not change the " + "number of\n directional derivative in existing adoubles and may " + "lead to erroneous results\n or memory corruption\n Number of " + "currently existing adoubles = %zu\n", + refcounter::refcnt); } #endif - if (p < 1) { - fprintf(DIAG_OUT, "ADOL-C Error: Traceless: p < 1 not possible\n"); - abort(); - } - adouble::numDir = p; + if (p < 1) { + fprintf(DIAG_OUT, "ADOL-C Error: Traceless: p < 1 not possible\n"); + abort(); + } + adouble::numDir = p; #if USE_BOOST_POOL - if (adouble::advalpool != NULL) { - delete adouble::advalpool; - adouble::advalpool = NULL; - } - adouble::advalpool = new boost::pool((adouble::numDir+1)*sizeof(double)); + if (adouble::advalpool != NULL) { + delete adouble::advalpool; + adouble::advalpool = NULL; + } + adouble::advalpool = + new boost::pool( + (adouble::numDir + 1) * sizeof(double)); #endif } -inline size_t getNumDir() {return adouble::numDir;} +inline size_t getNumDir() { return adouble::numDir; } inline double makeNaN() { - return ADOLC_MATH_NSP::numeric_limits::quiet_NaN(); + return ADOLC_MATH_NSP::numeric_limits::quiet_NaN(); } inline double makeInf() { - return ADOLC_MATH_NSP::numeric_limits::infinity(); + return ADOLC_MATH_NSP::numeric_limits::infinity(); } -#define FOR_I_EQ_0_LTEQ_NUMDIR for (size_t _i=0; _i <= adouble::numDir; ++_i) -#define FOR_I_EQ_1_LTEQ_NUMDIR for (size_t _i=1; _i <= adouble::numDir; ++_i) -#define ADVAL_I adval[_i] -#define PRIMAL_VALUE adval[0] +#define FOR_I_EQ_0_LTEQ_NUMDIR for (size_t _i = 0; _i <= adouble::numDir; ++_i) +#define FOR_I_EQ_1_LTEQ_NUMDIR for (size_t _i = 1; _i <= adouble::numDir; ++_i) +#define ADVAL_I adval[_i] +#define PRIMAL_VALUE adval[0] /******************************* ctors ************************************/ inline adouble::adouble() : adval(NULL) { #if USE_BOOST_POOL - adval = reinterpret_cast(advalpool->malloc()); + adval = reinterpret_cast(advalpool->malloc()); #else - adval = new double[adouble::numDir+1]; + adval = new double[adouble::numDir + 1]; #endif - PRIMAL_VALUE = 0.; + PRIMAL_VALUE = 0.; } inline adouble::adouble(const double v) : adval(NULL) { #if USE_BOOST_POOL - adval = reinterpret_cast(advalpool->malloc()); + adval = reinterpret_cast(advalpool->malloc()); #else - adval = new double[adouble::numDir+1]; + adval = new double[adouble::numDir + 1]; #endif - PRIMAL_VALUE = v; - FOR_I_EQ_1_LTEQ_NUMDIR - ADVAL_I = 0.0; + PRIMAL_VALUE = v; + FOR_I_EQ_1_LTEQ_NUMDIR + ADVAL_I = 0.0; } -inline adouble::adouble(const double v, const double* adv) : adval(NULL) { +inline adouble::adouble(const double v, const double *adv) : adval(NULL) { #if USE_BOOST_POOL - adval = reinterpret_cast(advalpool->malloc()); + adval = reinterpret_cast(advalpool->malloc()); #else - adval = new double[adouble::numDir+1]; + adval = new double[adouble::numDir + 1]; #endif - PRIMAL_VALUE = v; - FOR_I_EQ_1_LTEQ_NUMDIR - ADVAL_I=adv[_i-1]; + PRIMAL_VALUE = v; + FOR_I_EQ_1_LTEQ_NUMDIR + ADVAL_I = adv[_i - 1]; } -inline adouble::adouble(const adouble& a) : adval(NULL) { +inline adouble::adouble(const adouble &a) : adval(NULL) { #if USE_BOOST_POOL - adval = reinterpret_cast(advalpool->malloc()); + adval = reinterpret_cast(advalpool->malloc()); #else - adval = new double[adouble::numDir+1]; + adval = new double[adouble::numDir + 1]; #endif - FOR_I_EQ_0_LTEQ_NUMDIR - ADVAL_I=a.ADVAL_I; + FOR_I_EQ_0_LTEQ_NUMDIR + ADVAL_I = a.ADVAL_I; } /******************************* dtors ************************************/ inline adouble::~adouble() { - if (adval != NULL) + if (adval != NULL) #if USE_BOOST_POOL - advalpool->free(adval); + advalpool->free(adval); #else - delete[] adval; + delete[] adval; #endif } /************************* temporary results ******************************/ // sign -inline adouble adouble::operator - () const { - adouble tmp; - FOR_I_EQ_0_LTEQ_NUMDIR - tmp.ADVAL_I=-ADVAL_I; - return tmp; +inline adouble adouble::operator-() const { + adouble tmp; + FOR_I_EQ_0_LTEQ_NUMDIR + tmp.ADVAL_I = -ADVAL_I; + return tmp; } -inline adouble adouble::operator + () const { - return *this; -} +inline adouble adouble::operator+() const { return *this; } // addition -inline adouble adouble::operator + (const double v) const { - adouble tmp(PRIMAL_VALUE+v, adval+1); - return tmp; +inline adouble adouble::operator+(const double v) const { + adouble tmp(PRIMAL_VALUE + v, adval + 1); + return tmp; } -inline adouble adouble::operator + (const adouble& a) const { - adouble tmp; - FOR_I_EQ_0_LTEQ_NUMDIR - tmp.ADVAL_I=ADVAL_I+a.ADVAL_I; - return tmp; +inline adouble adouble::operator+(const adouble &a) const { + adouble tmp; + FOR_I_EQ_0_LTEQ_NUMDIR + tmp.ADVAL_I = ADVAL_I + a.ADVAL_I; + return tmp; } -inline adouble operator + (const double v, const adouble& a) { - adouble tmp(v+a.PRIMAL_VALUE, a.adval+1); - return tmp; +inline adouble operator+(const double v, const adouble &a) { + adouble tmp(v + a.PRIMAL_VALUE, a.adval + 1); + return tmp; } // subtraction -inline adouble adouble::operator - (const double v) const { - adouble tmp(PRIMAL_VALUE-v, adval+1); - return tmp; +inline adouble adouble::operator-(const double v) const { + adouble tmp(PRIMAL_VALUE - v, adval + 1); + return tmp; } -inline adouble adouble::operator - (const adouble& a) const { - adouble tmp; - FOR_I_EQ_0_LTEQ_NUMDIR - tmp.ADVAL_I=ADVAL_I-a.ADVAL_I; - return tmp; +inline adouble adouble::operator-(const adouble &a) const { + adouble tmp; + FOR_I_EQ_0_LTEQ_NUMDIR + tmp.ADVAL_I = ADVAL_I - a.ADVAL_I; + return tmp; } -inline adouble operator - (const double v, const adouble& a) { - adouble tmp; - tmp.PRIMAL_VALUE=v-a.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=-a.ADVAL_I; - return tmp; +inline adouble operator-(const double v, const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = v - a.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = -a.ADVAL_I; + return tmp; } // multiplication -inline adouble adouble::operator * (const double v) const { - adouble tmp; - FOR_I_EQ_0_LTEQ_NUMDIR - tmp.ADVAL_I=ADVAL_I*v; - return tmp; +inline adouble adouble::operator*(const double v) const { + adouble tmp; + FOR_I_EQ_0_LTEQ_NUMDIR + tmp.ADVAL_I = ADVAL_I * v; + return tmp; } -inline adouble adouble::operator * (const adouble& a) const { - adouble tmp; - tmp.PRIMAL_VALUE=PRIMAL_VALUE*a.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=ADVAL_I*a.PRIMAL_VALUE+PRIMAL_VALUE*a.ADVAL_I; - return tmp; +inline adouble adouble::operator*(const adouble &a) const { + adouble tmp; + tmp.PRIMAL_VALUE = PRIMAL_VALUE * a.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = ADVAL_I * a.PRIMAL_VALUE + PRIMAL_VALUE * a.ADVAL_I; + return tmp; } -inline adouble operator * (const double v, const adouble& a) { - adouble tmp; - FOR_I_EQ_0_LTEQ_NUMDIR - tmp.ADVAL_I=v*a.ADVAL_I; - return tmp; +inline adouble operator*(const double v, const adouble &a) { + adouble tmp; + FOR_I_EQ_0_LTEQ_NUMDIR + tmp.ADVAL_I = v * a.ADVAL_I; + return tmp; } // division -inline adouble adouble::operator / (const double v) const { - adouble tmp; - FOR_I_EQ_0_LTEQ_NUMDIR - tmp.ADVAL_I=ADVAL_I/v; - return tmp; +inline adouble adouble::operator/(const double v) const { + adouble tmp; + FOR_I_EQ_0_LTEQ_NUMDIR + tmp.ADVAL_I = ADVAL_I / v; + return tmp; } -inline adouble adouble::operator / (const adouble& a) const { - adouble tmp; - tmp.PRIMAL_VALUE=PRIMAL_VALUE/a.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=(ADVAL_I*a.PRIMAL_VALUE-PRIMAL_VALUE*a.ADVAL_I)/(a.PRIMAL_VALUE*a.PRIMAL_VALUE); - return tmp; +inline adouble adouble::operator/(const adouble &a) const { + adouble tmp; + tmp.PRIMAL_VALUE = PRIMAL_VALUE / a.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = (ADVAL_I * a.PRIMAL_VALUE - PRIMAL_VALUE * a.ADVAL_I) / + (a.PRIMAL_VALUE * a.PRIMAL_VALUE); + return tmp; } -inline adouble operator / (const double v, const adouble& a) { - adouble tmp; - tmp.PRIMAL_VALUE=v/a.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=(-v*a.ADVAL_I)/(a.PRIMAL_VALUE*a.PRIMAL_VALUE); - return tmp; +inline adouble operator/(const double v, const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = v / a.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = (-v * a.ADVAL_I) / (a.PRIMAL_VALUE * a.PRIMAL_VALUE); + return tmp; } // inc/dec -inline adouble adouble::operator ++ () { - ++PRIMAL_VALUE; - return *this; +inline adouble adouble::operator++() { + ++PRIMAL_VALUE; + return *this; } -inline adouble adouble::operator ++ (int) { - adouble tmp; - tmp.PRIMAL_VALUE=PRIMAL_VALUE++; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=ADVAL_I; - return tmp; +inline adouble adouble::operator++(int) { + adouble tmp; + tmp.PRIMAL_VALUE = PRIMAL_VALUE++; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = ADVAL_I; + return tmp; } -inline adouble adouble::operator -- () { - --PRIMAL_VALUE; - return *this; +inline adouble adouble::operator--() { + --PRIMAL_VALUE; + return *this; } -inline adouble adouble::operator -- (int) { - adouble tmp; - tmp.PRIMAL_VALUE=PRIMAL_VALUE--; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=ADVAL_I; - return tmp; +inline adouble adouble::operator--(int) { + adouble tmp; + tmp.PRIMAL_VALUE = PRIMAL_VALUE--; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = ADVAL_I; + return tmp; } // functions -inline adouble tan(const adouble& a) { - adouble tmp; - double tmp2; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::tan(a.PRIMAL_VALUE); - tmp2=ADOLC_MATH_NSP::cos(a.PRIMAL_VALUE); - tmp2*=tmp2; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; +inline adouble tan(const adouble &a) { + adouble tmp; + double tmp2; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::tan(a.PRIMAL_VALUE); + tmp2 = ADOLC_MATH_NSP::cos(a.PRIMAL_VALUE); + tmp2 *= tmp2; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; } inline adouble exp(const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::exp(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=tmp.PRIMAL_VALUE*a.ADVAL_I; - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::exp(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = tmp.PRIMAL_VALUE * a.ADVAL_I; + return tmp; } inline adouble log(const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::log(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - if (a.PRIMAL_VALUE>0) tmp.ADVAL_I=a.ADVAL_I/a.PRIMAL_VALUE; - else if (a.PRIMAL_VALUE==0 && a.ADVAL_I != 0.0) { - int sign = (a.ADVAL_I < 0) ? -1 : 1; - tmp.ADVAL_I=sign*makeInf(); - } else tmp.ADVAL_I=makeNaN(); - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::log(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + if (a.PRIMAL_VALUE > 0) + tmp.ADVAL_I = a.ADVAL_I / a.PRIMAL_VALUE; + else if (a.PRIMAL_VALUE == 0 && a.ADVAL_I != 0.0) { + int sign = (a.ADVAL_I < 0) ? -1 : 1; + tmp.ADVAL_I = sign * makeInf(); + } else + tmp.ADVAL_I = makeNaN(); + return tmp; } inline adouble sqrt(const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::sqrt(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - if (a.PRIMAL_VALUE>0) tmp.ADVAL_I=a.ADVAL_I/(tmp.PRIMAL_VALUE*2); - else if (a.PRIMAL_VALUE==0.0 && a.ADVAL_I != 0.0) { - int sign = (a.ADVAL_I < 0) ? -1 : 1; - tmp.ADVAL_I=sign * makeInf(); - } else tmp.ADVAL_I=makeNaN(); - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::sqrt(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + if (a.PRIMAL_VALUE > 0) + tmp.ADVAL_I = a.ADVAL_I / (tmp.PRIMAL_VALUE * 2); + else if (a.PRIMAL_VALUE == 0.0 && a.ADVAL_I != 0.0) { + int sign = (a.ADVAL_I < 0) ? -1 : 1; + tmp.ADVAL_I = sign * makeInf(); + } else + tmp.ADVAL_I = makeNaN(); + return tmp; } inline adouble cbrt(const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::cbrt(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - if (a.PRIMAL_VALUE!=0.0) - tmp.ADVAL_I=a.ADVAL_I/(tmp.PRIMAL_VALUE*tmp.PRIMAL_VALUE*3); - else if (a.PRIMAL_VALUE==0.0 && a.ADVAL_I != 0.0) { - int sign = (a.ADVAL_I < 0) ? -1 : 1; - tmp.ADVAL_I=sign * makeInf(); - } else tmp.ADVAL_I=makeNaN(); - return tmp; -} - + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::cbrt(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + if (a.PRIMAL_VALUE != 0.0) + tmp.ADVAL_I = a.ADVAL_I / (tmp.PRIMAL_VALUE * tmp.PRIMAL_VALUE * 3); + else if (a.PRIMAL_VALUE == 0.0 && a.ADVAL_I != 0.0) { + int sign = (a.ADVAL_I < 0) ? -1 : 1; + tmp.ADVAL_I = sign * makeInf(); + } else + tmp.ADVAL_I = makeNaN(); + return tmp; +} + inline adouble sin(const adouble &a) { - adouble tmp; - double tmp2; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::sin(a.PRIMAL_VALUE); - tmp2=ADOLC_MATH_NSP::cos(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; + adouble tmp; + double tmp2; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::sin(a.PRIMAL_VALUE); + tmp2 = ADOLC_MATH_NSP::cos(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } inline adouble cos(const adouble &a) { - adouble tmp; - double tmp2; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::cos(a.PRIMAL_VALUE); - tmp2=-ADOLC_MATH_NSP::sin(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; + adouble tmp; + double tmp2; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::cos(a.PRIMAL_VALUE); + tmp2 = -ADOLC_MATH_NSP::sin(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } inline adouble asin(const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::asin(a.PRIMAL_VALUE); - double tmp2=ADOLC_MATH_NSP::sqrt(1-a.PRIMAL_VALUE*a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::asin(a.PRIMAL_VALUE); + double tmp2 = ADOLC_MATH_NSP::sqrt(1 - a.PRIMAL_VALUE * a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; } inline adouble acos(const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::acos(a.PRIMAL_VALUE); - double tmp2=-ADOLC_MATH_NSP::sqrt(1-a.PRIMAL_VALUE*a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::acos(a.PRIMAL_VALUE); + double tmp2 = -ADOLC_MATH_NSP::sqrt(1 - a.PRIMAL_VALUE * a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; } inline adouble atan(const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::atan(a.PRIMAL_VALUE); - double tmp2=1+a.PRIMAL_VALUE*a.PRIMAL_VALUE; - tmp2=1/tmp2; - if (tmp2!=0) - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*tmp2; - else - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=0.0; - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::atan(a.PRIMAL_VALUE); + double tmp2 = 1 + a.PRIMAL_VALUE * a.PRIMAL_VALUE; + tmp2 = 1 / tmp2; + if (tmp2 != 0) + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * tmp2; + else FOR_I_EQ_1_LTEQ_NUMDIR tmp.ADVAL_I = 0.0; + return tmp; } inline adouble atan2(const adouble &a, const adouble &b) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::atan2(a.PRIMAL_VALUE, b.PRIMAL_VALUE); - double tmp2=a.PRIMAL_VALUE*a.PRIMAL_VALUE; - double tmp3=b.PRIMAL_VALUE*b.PRIMAL_VALUE; - double tmp4=tmp3/(tmp2+tmp3); - if (tmp4!=0) - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=(a.ADVAL_I*b.PRIMAL_VALUE-a.PRIMAL_VALUE*b.ADVAL_I)/tmp3*tmp4; - else - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=0.0; - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::atan2(a.PRIMAL_VALUE, b.PRIMAL_VALUE); + double tmp2 = a.PRIMAL_VALUE * a.PRIMAL_VALUE; + double tmp3 = b.PRIMAL_VALUE * b.PRIMAL_VALUE; + double tmp4 = tmp3 / (tmp2 + tmp3); + if (tmp4 != 0) + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = + (a.ADVAL_I * b.PRIMAL_VALUE - a.PRIMAL_VALUE * b.ADVAL_I) / tmp3 * tmp4; + else FOR_I_EQ_1_LTEQ_NUMDIR tmp.ADVAL_I = 0.0; + return tmp; } inline adouble pow(const adouble &a, double v) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::pow(a.PRIMAL_VALUE, v); - double tmp2=v*ADOLC_MATH_NSP::pow(a.PRIMAL_VALUE, v-1); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::pow(a.PRIMAL_VALUE, v); + double tmp2 = v * ADOLC_MATH_NSP::pow(a.PRIMAL_VALUE, v - 1); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } inline adouble pow(const adouble &a, const adouble &b) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::pow(a.PRIMAL_VALUE, b.PRIMAL_VALUE); - double tmp2=b.PRIMAL_VALUE*ADOLC_MATH_NSP::pow(a.PRIMAL_VALUE, b.PRIMAL_VALUE-1); - double tmp3=ADOLC_MATH_NSP::log(a.PRIMAL_VALUE)*tmp.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I+tmp3*b.ADVAL_I; - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::pow(a.PRIMAL_VALUE, b.PRIMAL_VALUE); + double tmp2 = + b.PRIMAL_VALUE * ADOLC_MATH_NSP::pow(a.PRIMAL_VALUE, b.PRIMAL_VALUE - 1); + double tmp3 = ADOLC_MATH_NSP::log(a.PRIMAL_VALUE) * tmp.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I + tmp3 * b.ADVAL_I; + return tmp; } inline adouble pow(double v, const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::pow(v, a.PRIMAL_VALUE); - double tmp2=tmp.PRIMAL_VALUE*ADOLC_MATH_NSP::log(v); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::pow(v, a.PRIMAL_VALUE); + double tmp2 = tmp.PRIMAL_VALUE * ADOLC_MATH_NSP::log(v); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } inline adouble log10(const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::log10(a.PRIMAL_VALUE); - double tmp2=ADOLC_MATH_NSP::log((double)10)*a.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -inline adouble sinh (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::sinh(a.PRIMAL_VALUE); - double tmp2=ADOLC_MATH_NSP::cosh(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*tmp2; - return tmp; -} - -inline adouble cosh (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::cosh(a.PRIMAL_VALUE); - double tmp2=ADOLC_MATH_NSP::sinh(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*tmp2; - return tmp; -} - -inline adouble tanh (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::tanh(a.PRIMAL_VALUE); - double tmp2=ADOLC_MATH_NSP::cosh(a.PRIMAL_VALUE); - tmp2*=tmp2; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -inline adouble asinh (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP_ERF::asinh(a.PRIMAL_VALUE); - double tmp2=ADOLC_MATH_NSP::sqrt(a.PRIMAL_VALUE*a.PRIMAL_VALUE+1); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -inline adouble acosh (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP_ERF::acosh(a.PRIMAL_VALUE); - double tmp2=ADOLC_MATH_NSP::sqrt(a.PRIMAL_VALUE*a.PRIMAL_VALUE-1); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -inline adouble atanh (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP_ERF::atanh(a.PRIMAL_VALUE); - double tmp2=1-a.PRIMAL_VALUE*a.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - return tmp; -} - -inline adouble fabs (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::fabs(a.PRIMAL_VALUE); - int as=0; - if (a.PRIMAL_VALUE>0) as=1; - if (a.PRIMAL_VALUE<0) as=-1; - if (as!=0) - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*as; - else - FOR_I_EQ_1_LTEQ_NUMDIR { - as=0; - if (a.ADVAL_I>0) as=1; - if (a.ADVAL_I<0) as=-1; - tmp.ADVAL_I=a.ADVAL_I*as; - } - return tmp; -} - -inline adouble ceil (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::ceil(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=0.0; - return tmp; -} - -inline adouble floor (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP::floor(a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=0.0; - return tmp; -} - -inline adouble fmax (const adouble &a, const adouble &b) { - adouble tmp; - double tmp2=a.PRIMAL_VALUE-b.PRIMAL_VALUE; - if (tmp2<0) { - tmp.PRIMAL_VALUE=b.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=b.ADVAL_I; + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::log10(a.PRIMAL_VALUE); + double tmp2 = ADOLC_MATH_NSP::log((double)10) * a.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +inline adouble sinh(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::sinh(a.PRIMAL_VALUE); + double tmp2 = ADOLC_MATH_NSP::cosh(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * tmp2; + return tmp; +} + +inline adouble cosh(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::cosh(a.PRIMAL_VALUE); + double tmp2 = ADOLC_MATH_NSP::sinh(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * tmp2; + return tmp; +} + +inline adouble tanh(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::tanh(a.PRIMAL_VALUE); + double tmp2 = ADOLC_MATH_NSP::cosh(a.PRIMAL_VALUE); + tmp2 *= tmp2; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +inline adouble asinh(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP_ERF::asinh(a.PRIMAL_VALUE); + double tmp2 = ADOLC_MATH_NSP::sqrt(a.PRIMAL_VALUE * a.PRIMAL_VALUE + 1); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +inline adouble acosh(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP_ERF::acosh(a.PRIMAL_VALUE); + double tmp2 = ADOLC_MATH_NSP::sqrt(a.PRIMAL_VALUE * a.PRIMAL_VALUE - 1); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +inline adouble atanh(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP_ERF::atanh(a.PRIMAL_VALUE); + double tmp2 = 1 - a.PRIMAL_VALUE * a.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I / tmp2; + return tmp; +} + +inline adouble fabs(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::fabs(a.PRIMAL_VALUE); + int as = 0; + if (a.PRIMAL_VALUE > 0) + as = 1; + if (a.PRIMAL_VALUE < 0) + as = -1; + if (as != 0) + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * as; + else FOR_I_EQ_1_LTEQ_NUMDIR { + as = 0; + if (a.ADVAL_I > 0) + as = 1; + if (a.ADVAL_I < 0) + as = -1; + tmp.ADVAL_I = a.ADVAL_I * as; + } + return tmp; +} + +inline adouble ceil(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::ceil(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = 0.0; + return tmp; +} + +inline adouble floor(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP::floor(a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = 0.0; + return tmp; +} + +inline adouble fmax(const adouble &a, const adouble &b) { + adouble tmp; + double tmp2 = a.PRIMAL_VALUE - b.PRIMAL_VALUE; + if (tmp2 < 0) { + tmp.PRIMAL_VALUE = b.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = b.ADVAL_I; + } else { + tmp.PRIMAL_VALUE = a.PRIMAL_VALUE; + if (tmp2 > 0) { + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; } else { - tmp.PRIMAL_VALUE=a.PRIMAL_VALUE; - if (tmp2>0) { - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - } else { - FOR_I_EQ_1_LTEQ_NUMDIR - { - if (a.ADVAL_I 0) { + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = 0.0; } else { - tmp.PRIMAL_VALUE=v; - if (tmp2>0) { - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=0.0; - } else { - FOR_I_EQ_1_LTEQ_NUMDIR - { - if (a.ADVAL_I>0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - } + FOR_I_EQ_1_LTEQ_NUMDIR { + if (a.ADVAL_I > 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } } - return tmp; + } + return tmp; } -inline adouble fmax (const adouble &a, double v) { - adouble tmp; - double tmp2=a.PRIMAL_VALUE-v; - if (tmp2<0) { - tmp.PRIMAL_VALUE=v; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=0.0; +inline adouble fmax(const adouble &a, double v) { + adouble tmp; + double tmp2 = a.PRIMAL_VALUE - v; + if (tmp2 < 0) { + tmp.PRIMAL_VALUE = v; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = 0.0; + } else { + tmp.PRIMAL_VALUE = a.PRIMAL_VALUE; + if (tmp2 > 0) { + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; } else { - tmp.PRIMAL_VALUE=a.PRIMAL_VALUE; - if (tmp2>0) { - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - } else { - FOR_I_EQ_1_LTEQ_NUMDIR - { - if (a.ADVAL_I>0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - } + FOR_I_EQ_1_LTEQ_NUMDIR { + if (a.ADVAL_I > 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } } - return tmp; + } + return tmp; } -inline adouble fmin (const adouble &a, const adouble &b) { - adouble tmp; - double tmp2=a.PRIMAL_VALUE-b.PRIMAL_VALUE; - if (tmp2<0) { - tmp.PRIMAL_VALUE=a.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; +inline adouble fmin(const adouble &a, const adouble &b) { + adouble tmp; + double tmp2 = a.PRIMAL_VALUE - b.PRIMAL_VALUE; + if (tmp2 < 0) { + tmp.PRIMAL_VALUE = a.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; + } else { + tmp.PRIMAL_VALUE = b.PRIMAL_VALUE; + if (tmp2 > 0) { + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = b.ADVAL_I; } else { - tmp.PRIMAL_VALUE=b.PRIMAL_VALUE; - if (tmp2>0) { - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=b.ADVAL_I; - } else { - FOR_I_EQ_1_LTEQ_NUMDIR - { - if (a.ADVAL_I 0) { + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; } else { - tmp.PRIMAL_VALUE=a.PRIMAL_VALUE; - if (tmp2>0) { - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - } else { - FOR_I_EQ_1_LTEQ_NUMDIR - { - if (a.ADVAL_I<0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - } + FOR_I_EQ_1_LTEQ_NUMDIR { + if (a.ADVAL_I < 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } } - return tmp; + } + return tmp; } -inline adouble fmin (const adouble &a, double v) { - adouble tmp; - double tmp2=a.PRIMAL_VALUE-v; - if (tmp2<0) { - tmp.PRIMAL_VALUE=a.PRIMAL_VALUE; - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; +inline adouble fmin(const adouble &a, double v) { + adouble tmp; + double tmp2 = a.PRIMAL_VALUE - v; + if (tmp2 < 0) { + tmp.PRIMAL_VALUE = a.PRIMAL_VALUE; + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; + } else { + tmp.PRIMAL_VALUE = v; + if (tmp2 > 0) { + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = 0.0; } else { - tmp.PRIMAL_VALUE=v; - if (tmp2>0) { - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=0.0; - } else { - FOR_I_EQ_1_LTEQ_NUMDIR - { - if (a.ADVAL_I<0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - } + FOR_I_EQ_1_LTEQ_NUMDIR { + if (a.ADVAL_I < 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } } - return tmp; + } + return tmp; } -inline adouble ldexp (const adouble &a, const adouble &b) { - adouble tmp = a*pow(2.,b); - return tmp; +inline adouble ldexp(const adouble &a, const adouble &b) { + adouble tmp = a * pow(2., b); + return tmp; } -inline adouble ldexp (const adouble &a, const double v) { - return a*ADOLC_MATH_NSP::pow(2.,v); +inline adouble ldexp(const adouble &a, const double v) { + return a * ADOLC_MATH_NSP::pow(2., v); } -inline adouble ldexp (const double v, const adouble &a) { - adouble tmp = v*pow(2.,a); - return tmp; +inline adouble ldexp(const double v, const adouble &a) { + adouble tmp = v * pow(2., a); + return tmp; } -inline double frexp (const adouble &a, int* v) { - return ADOLC_MATH_NSP::frexp(a.PRIMAL_VALUE, v); +inline double frexp(const adouble &a, int *v) { + return ADOLC_MATH_NSP::frexp(a.PRIMAL_VALUE, v); } -inline adouble erf (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP_ERF::erf(a.PRIMAL_VALUE); - double tmp2 = 2.0 / - ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * - ADOLC_MATH_NSP_ERF::exp(-a.PRIMAL_VALUE*a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; +inline adouble erf(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP_ERF::erf(a.PRIMAL_VALUE); + double tmp2 = 2.0 / ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * + ADOLC_MATH_NSP_ERF::exp(-a.PRIMAL_VALUE * a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } -inline adouble erfc (const adouble &a) { - adouble tmp; - tmp.PRIMAL_VALUE=ADOLC_MATH_NSP_ERF::erfc(a.PRIMAL_VALUE); - double tmp2 = -2.0 / - ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * - ADOLC_MATH_NSP_ERF::exp(-a.PRIMAL_VALUE*a.PRIMAL_VALUE); - FOR_I_EQ_1_LTEQ_NUMDIR - tmp.ADVAL_I=tmp2*a.ADVAL_I; - return tmp; +inline adouble erfc(const adouble &a) { + adouble tmp; + tmp.PRIMAL_VALUE = ADOLC_MATH_NSP_ERF::erfc(a.PRIMAL_VALUE); + double tmp2 = -2.0 / ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * + ADOLC_MATH_NSP_ERF::exp(-a.PRIMAL_VALUE * a.PRIMAL_VALUE); + FOR_I_EQ_1_LTEQ_NUMDIR + tmp.ADVAL_I = tmp2 * a.ADVAL_I; + return tmp; } -inline void condassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ) { - if (cond.getValue() > 0) - res = arg1; - else - res = arg2; +inline void condassign(adouble &res, const adouble &cond, const adouble &arg1, + const adouble &arg2) { + if (cond.getValue() > 0) + res = arg1; + else + res = arg2; } -inline void condassign( adouble &res, const adouble &cond, - const adouble &arg ) { - if (cond.getValue() > 0) - res = arg; +inline void condassign(adouble &res, const adouble &cond, const adouble &arg) { + if (cond.getValue() > 0) + res = arg; } -inline void condeqassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ) { - if (cond.getValue() >= 0) - res = arg1; - else - res = arg2; +inline void condeqassign(adouble &res, const adouble &cond, const adouble &arg1, + const adouble &arg2) { + if (cond.getValue() >= 0) + res = arg1; + else + res = arg2; } -inline void condeqassign( adouble &res, const adouble &cond, - const adouble &arg ) { - if (cond.getValue() >= 0) - res = arg; +inline void condeqassign(adouble &res, const adouble &cond, + const adouble &arg) { + if (cond.getValue() >= 0) + res = arg; } - - /******************* nontemporary results *********************************/ -inline adouble& adouble::operator = (const double v) { - PRIMAL_VALUE=v; - FOR_I_EQ_1_LTEQ_NUMDIR - ADVAL_I=0.0; - return *this; +inline adouble &adouble::operator=(const double v) { + PRIMAL_VALUE = v; + FOR_I_EQ_1_LTEQ_NUMDIR + ADVAL_I = 0.0; + return *this; } -inline adouble& adouble::operator = (const adouble& a) { - FOR_I_EQ_0_LTEQ_NUMDIR - ADVAL_I=a.ADVAL_I; - return *this; +inline adouble &adouble::operator=(const adouble &a) { + FOR_I_EQ_0_LTEQ_NUMDIR + ADVAL_I = a.ADVAL_I; + return *this; } -inline adouble& adouble::operator += (const double v) { - PRIMAL_VALUE+=v; - return *this; +inline adouble &adouble::operator+=(const double v) { + PRIMAL_VALUE += v; + return *this; } -inline adouble& adouble::operator += (const adouble& a) { - FOR_I_EQ_0_LTEQ_NUMDIR - ADVAL_I+=a.ADVAL_I; - return *this; +inline adouble &adouble::operator+=(const adouble &a) { + FOR_I_EQ_0_LTEQ_NUMDIR + ADVAL_I += a.ADVAL_I; + return *this; } -inline adouble& adouble::operator -= (const double v) { - PRIMAL_VALUE-=v; - return *this; +inline adouble &adouble::operator-=(const double v) { + PRIMAL_VALUE -= v; + return *this; } -inline adouble& adouble::operator -= (const adouble& a) { - FOR_I_EQ_0_LTEQ_NUMDIR - ADVAL_I-=a.ADVAL_I; - return *this; +inline adouble &adouble::operator-=(const adouble &a) { + FOR_I_EQ_0_LTEQ_NUMDIR + ADVAL_I -= a.ADVAL_I; + return *this; } -inline adouble& adouble::operator *= (const double v) { - FOR_I_EQ_0_LTEQ_NUMDIR - ADVAL_I*=v; - return *this; +inline adouble &adouble::operator*=(const double v) { + FOR_I_EQ_0_LTEQ_NUMDIR + ADVAL_I *= v; + return *this; } -inline adouble& adouble::operator *= (const adouble& a) { - FOR_I_EQ_1_LTEQ_NUMDIR - ADVAL_I=ADVAL_I*a.PRIMAL_VALUE+PRIMAL_VALUE*a.ADVAL_I; - PRIMAL_VALUE*=a.PRIMAL_VALUE; - return *this; +inline adouble &adouble::operator*=(const adouble &a) { + FOR_I_EQ_1_LTEQ_NUMDIR + ADVAL_I = ADVAL_I * a.PRIMAL_VALUE + PRIMAL_VALUE * a.ADVAL_I; + PRIMAL_VALUE *= a.PRIMAL_VALUE; + return *this; } -inline adouble& adouble::operator /= (const double v) { - FOR_I_EQ_0_LTEQ_NUMDIR - ADVAL_I/=v; - return *this; +inline adouble &adouble::operator/=(const double v) { + FOR_I_EQ_0_LTEQ_NUMDIR + ADVAL_I /= v; + return *this; } -inline adouble& adouble::operator /= (const adouble& a) { - FOR_I_EQ_1_LTEQ_NUMDIR - ADVAL_I=(ADVAL_I*a.PRIMAL_VALUE-PRIMAL_VALUE*a.ADVAL_I)/(a.PRIMAL_VALUE*a.PRIMAL_VALUE); - PRIMAL_VALUE=PRIMAL_VALUE/a.PRIMAL_VALUE; - return *this; +inline adouble &adouble::operator/=(const adouble &a) { + FOR_I_EQ_1_LTEQ_NUMDIR + ADVAL_I = (ADVAL_I * a.PRIMAL_VALUE - PRIMAL_VALUE * a.ADVAL_I) / + (a.PRIMAL_VALUE * a.PRIMAL_VALUE); + PRIMAL_VALUE = PRIMAL_VALUE / a.PRIMAL_VALUE; + return *this; } // not -inline bool adouble::operator ! () const { - return PRIMAL_VALUE==0.0; -} +inline bool adouble::operator!() const { return PRIMAL_VALUE == 0.0; } // comparison -inline bool adouble::operator != (const adouble &a) const { - return PRIMAL_VALUE!=a.PRIMAL_VALUE; +inline bool adouble::operator!=(const adouble &a) const { + return PRIMAL_VALUE != a.PRIMAL_VALUE; } -inline bool adouble::operator != (const double v) const { - return PRIMAL_VALUE!=v; +inline bool adouble::operator!=(const double v) const { + return PRIMAL_VALUE != v; } -inline bool operator != (const double v, const adouble &a) { - return v!=a.PRIMAL_VALUE; +inline bool operator!=(const double v, const adouble &a) { + return v != a.PRIMAL_VALUE; } -inline bool adouble::operator == (const adouble &a) const { - return PRIMAL_VALUE==a.PRIMAL_VALUE; +inline bool adouble::operator==(const adouble &a) const { + return PRIMAL_VALUE == a.PRIMAL_VALUE; } -inline bool adouble::operator == (const double v) const { - return PRIMAL_VALUE==v; +inline bool adouble::operator==(const double v) const { + return PRIMAL_VALUE == v; } -inline bool operator == (const double v, const adouble &a) { - return v==a.PRIMAL_VALUE; +inline bool operator==(const double v, const adouble &a) { + return v == a.PRIMAL_VALUE; } -inline bool adouble::operator <= (const adouble &a) const { - return PRIMAL_VALUE<=a.PRIMAL_VALUE; +inline bool adouble::operator<=(const adouble &a) const { + return PRIMAL_VALUE <= a.PRIMAL_VALUE; } -inline bool adouble::operator <= (const double v) const { - return PRIMAL_VALUE<=v; +inline bool adouble::operator<=(const double v) const { + return PRIMAL_VALUE <= v; } -inline bool operator <= (const double v, const adouble &a) { - return v<=a.PRIMAL_VALUE; +inline bool operator<=(const double v, const adouble &a) { + return v <= a.PRIMAL_VALUE; } -inline bool adouble::operator >= (const adouble &a) const { - return PRIMAL_VALUE>=a.PRIMAL_VALUE; +inline bool adouble::operator>=(const adouble &a) const { + return PRIMAL_VALUE >= a.PRIMAL_VALUE; } -inline bool adouble::operator >= (const double v) const { - return PRIMAL_VALUE>=v; +inline bool adouble::operator>=(const double v) const { + return PRIMAL_VALUE >= v; } -inline bool operator >= (const double v, const adouble &a) { - return v>=a.PRIMAL_VALUE; +inline bool operator>=(const double v, const adouble &a) { + return v >= a.PRIMAL_VALUE; } -inline bool adouble::operator > (const adouble &a) const { - return PRIMAL_VALUE>a.PRIMAL_VALUE; +inline bool adouble::operator>(const adouble &a) const { + return PRIMAL_VALUE > a.PRIMAL_VALUE; } -inline bool adouble::operator > (const double v) const { - return PRIMAL_VALUE>v; +inline bool adouble::operator>(const double v) const { + return PRIMAL_VALUE > v; } -inline bool operator > (const double v, const adouble &a) { - return v>a.PRIMAL_VALUE; +inline bool operator>(const double v, const adouble &a) { + return v > a.PRIMAL_VALUE; } -inline bool adouble::operator < (const adouble &a) const { - return PRIMAL_VALUE=adouble::numDir) - { - fprintf(DIAG_OUT, "Derivative array accessed out of bounds"\ - " while \"getADValue(...)\"!!!\n"); - throw logic_error("incorrect function call, errorcode=-1"); - } - return adval[p+1]; + if (p >= adouble::numDir) { + fprintf(DIAG_OUT, "Derivative array accessed out of bounds" + " while \"getADValue(...)\"!!!\n"); + throw logic_error("incorrect function call, errorcode=-1"); + } + return adval[p + 1]; } inline void adouble::setADValue(const unsigned int p, const double v) { - if (p>=adouble::numDir) - { - fprintf(DIAG_OUT, "Derivative array accessed out of bounds"\ - " while \"setADValue(...)\"!!!\n"); - throw logic_error("incorrect function call, errorcode=-1"); - } - adval[p+1]=v; + if (p >= adouble::numDir) { + fprintf(DIAG_OUT, "Derivative array accessed out of bounds" + " while \"setADValue(...)\"!!!\n"); + throw logic_error("incorrect function call, errorcode=-1"); + } + adval[p + 1] = v; } -} +} // namespace adtl #endif diff --git a/ADOL-C/include/adolc/adtl_hov.h b/ADOL-C/include/adolc/adtl_hov.h index b416bdb2f..d430893f9 100644 --- a/ADOL-C/include/adolc/adtl_hov.h +++ b/ADOL-C/include/adolc/adtl_hov.h @@ -17,17 +17,16 @@ #ifndef ADOLC_ADTL_HOV_H #define ADOLC_ADTL_HOV_H -#include +#include //for myalloc2 #include #include +#include #include -#include //for myalloc2 - -using std::ostream; using std::istream; using std::list; using std::logic_error; +using std::ostream; namespace adtl_hov { @@ -35,11 +34,11 @@ double makeNaN(); double makeInf(); enum Mode { - ADTL_ZOS = 0x1, - ADTL_FOV = 0x3, - ADTL_INDO = 0x5, - ADTL_FOV_INDO = 0x7, - ADTL_HOV = 0x9 // = BIN(1 0 0 1) + ADTL_ZOS = 0x1, + ADTL_FOV = 0x3, + ADTL_INDO = 0x5, + ADTL_FOV_INDO = 0x7, + ADTL_HOV = 0x9 // = BIN(1 0 0 1) }; // Mode @@ -49,220 +48,221 @@ class adouble; class refcounter { private: - ADOLC_DLL_EXPIMP static size_t refcnt; - ADOLC_DLL_EXPORT friend void setNumDir(const size_t p); - ADOLC_DLL_EXPORT friend void setDegree(const size_t p); - ADOLC_DLL_EXPORT friend void setMode(enum Mode newmode); - friend class adouble; + ADOLC_DLL_EXPIMP static size_t refcnt; + ADOLC_DLL_EXPORT friend void setNumDir(const size_t p); + ADOLC_DLL_EXPORT friend void setDegree(const size_t p); + ADOLC_DLL_EXPORT friend void setMode(enum Mode newmode); + friend class adouble; + public: - refcounter() { ++refcnt; } - ~refcounter() { --refcnt; } - inline static size_t getNumLiveVar() {return refcnt;} + refcounter() { ++refcnt; } + ~refcounter() { --refcnt; } + inline static size_t getNumLiveVar() { return refcnt; } }; #endif class func_ad { public: - virtual int operator() (int n, adouble *x, int m, adouble *y) = 0; + virtual int operator()(int n, adouble *x, int m, adouble *y) = 0; }; class adouble { public: - inline adouble(); - inline adouble(const double v); - inline adouble(const double v, const double* adv); - inline adouble(const double v, const double** hov); - inline adouble(const adouble& a); - inline ~adouble(); - - // sign - inline adouble operator - () const; - inline adouble operator + () const; - - // addition - inline adouble operator + (const double v) const; - inline adouble operator + (const adouble& a) const; - inline friend - adouble operator + (const double v, const adouble& a); - - // subtraction - inline adouble operator - (const double v) const; - inline adouble operator - (const adouble& a) const; - inline friend - adouble operator - (const double v, const adouble& a); - - // multiplication - inline adouble operator * (const double v) const; - inline adouble operator * (const adouble& a) const; - inline friend - adouble operator * (const double v, const adouble& a); - - // division - inline adouble operator / (const double v) const; - inline adouble operator / (const adouble& a) const; - inline friend - adouble operator / (const double v, const adouble& a); - - // inc/dec - inline adouble operator ++ (); - inline adouble operator ++ (int); - inline adouble operator -- (); - inline adouble operator -- (int); - - // functions - inline friend adouble tan(const adouble &a); - inline friend adouble exp(const adouble &a); - inline friend adouble log(const adouble &a); - inline friend adouble sqrt(const adouble &a); - inline friend adouble cbrt(const adouble &a); - inline friend adouble sin(const adouble &a); - inline friend adouble cos(const adouble &a); - inline friend adouble asin(const adouble &a); - inline friend adouble acos(const adouble &a); - inline friend adouble atan(const adouble &a); - - inline friend adouble atan2(const adouble &a, const adouble &b); - inline friend adouble pow(const adouble &a, double v); - inline friend adouble pow(const adouble &a, const adouble &b); - inline friend adouble pow(double v, const adouble &a); - inline friend adouble log10(const adouble &a); - - inline friend adouble sinh (const adouble &a); - inline friend adouble cosh (const adouble &a); - inline friend adouble tanh (const adouble &a); - inline friend adouble asinh (const adouble &a); - inline friend adouble acosh (const adouble &a); - inline friend adouble atanh (const adouble &a); - inline friend adouble fabs (const adouble &a); - inline friend adouble ceil (const adouble &a); - inline friend adouble floor (const adouble &a); - inline friend adouble fmax (const adouble &a, const adouble &b); - inline friend adouble fmax (double v, const adouble &a); - inline friend adouble fmax (const adouble &a, double v); - inline friend adouble fmin (const adouble &a, const adouble &b); - inline friend adouble fmin (double v, const adouble &a); - inline friend adouble fmin (const adouble &a, double v); - inline friend adouble ldexp (const adouble &a, const adouble &b); - inline friend adouble ldexp (const adouble &a, const double v); - inline friend adouble ldexp (const double v, const adouble &a); - inline friend double frexp (const adouble &a, int* v); - inline friend adouble erf (const adouble &a); - inline friend adouble erfc (const adouble &a); - - inline friend void condassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ); - inline friend void condassign( adouble &res, const adouble &cond, - const adouble &arg ); - inline friend void condeqassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ); - inline friend void condeqassign( adouble &res, const adouble &cond, - const adouble &arg ); - - /******************* nontemporary results ***************************/ - // assignment - inline adouble& operator = (const double v); - inline adouble& operator = (const adouble& a); - - // addition - inline adouble& operator += (const double v); - inline adouble& operator += (const adouble& a); - - // subtraction - inline adouble& operator -= (const double v); - inline adouble& operator -= (const adouble& a); - - // multiplication - inline adouble& operator *= (const double v); - inline adouble& operator *= (const adouble& a); - - // division - inline adouble& operator /= (const double v); - inline adouble& operator /= (const adouble& a); - - // not - inline int operator ! () const; - - // comparison - inline int operator != (const adouble&) const; - inline int operator != (const double) const; - inline friend int operator != (const double, const adouble&); - - inline int operator == (const adouble&) const; - inline int operator == (const double) const; - inline friend int operator == (const double, const adouble&); - - inline int operator <= (const adouble&) const; - inline int operator <= (const double) const; - inline friend int operator <= (const double, const adouble&); - - inline int operator >= (const adouble&) const; - inline int operator >= (const double) const; - inline friend int operator >= (const double, const adouble&); - - inline int operator > (const adouble&) const; - inline int operator > (const double) const; - inline friend int operator > (const double, const adouble&); - - inline int operator < (const adouble&) const; - inline int operator < (const double) const; - inline friend int operator < (const double, const adouble&); - - /******************* getter / setter ********************************/ - inline double getValue() const; - inline void setValue(const double v); - inline const double* const getADValue() const; - inline void setADValue(const double* v); - - inline double getADValue(const unsigned int p) const; - inline void setADValue(const unsigned int p, const double v); - - double* getOneADValue(int i) const; - - void setOneADValue(int i, double* v); - - - inline explicit operator double const&(); - inline explicit operator double&&(); - inline explicit operator double(); + inline adouble(); + inline adouble(const double v); + inline adouble(const double v, const double *adv); + inline adouble(const double v, const double **hov); + inline adouble(const adouble &a); + inline ~adouble(); + + // sign + inline adouble operator-() const; + inline adouble operator+() const; + + // addition + inline adouble operator+(const double v) const; + inline adouble operator+(const adouble &a) const; + inline friend adouble operator+(const double v, const adouble &a); + + // subtraction + inline adouble operator-(const double v) const; + inline adouble operator-(const adouble &a) const; + inline friend adouble operator-(const double v, const adouble &a); + + // multiplication + inline adouble operator*(const double v) const; + inline adouble operator*(const adouble &a) const; + inline friend adouble operator*(const double v, const adouble &a); + + // division + inline adouble operator/(const double v) const; + inline adouble operator/(const adouble &a) const; + inline friend adouble operator/(const double v, const adouble &a); + + // inc/dec + inline adouble operator++(); + inline adouble operator++(int); + inline adouble operator--(); + inline adouble operator--(int); + + // functions + inline friend adouble tan(const adouble &a); + inline friend adouble exp(const adouble &a); + inline friend adouble log(const adouble &a); + inline friend adouble sqrt(const adouble &a); + inline friend adouble cbrt(const adouble &a); + inline friend adouble sin(const adouble &a); + inline friend adouble cos(const adouble &a); + inline friend adouble asin(const adouble &a); + inline friend adouble acos(const adouble &a); + inline friend adouble atan(const adouble &a); + + inline friend adouble atan2(const adouble &a, const adouble &b); + inline friend adouble pow(const adouble &a, double v); + inline friend adouble pow(const adouble &a, const adouble &b); + inline friend adouble pow(double v, const adouble &a); + inline friend adouble log10(const adouble &a); + + inline friend adouble sinh(const adouble &a); + inline friend adouble cosh(const adouble &a); + inline friend adouble tanh(const adouble &a); + inline friend adouble asinh(const adouble &a); + inline friend adouble acosh(const adouble &a); + inline friend adouble atanh(const adouble &a); + inline friend adouble fabs(const adouble &a); + inline friend adouble ceil(const adouble &a); + inline friend adouble floor(const adouble &a); + inline friend adouble fmax(const adouble &a, const adouble &b); + inline friend adouble fmax(double v, const adouble &a); + inline friend adouble fmax(const adouble &a, double v); + inline friend adouble fmin(const adouble &a, const adouble &b); + inline friend adouble fmin(double v, const adouble &a); + inline friend adouble fmin(const adouble &a, double v); + inline friend adouble ldexp(const adouble &a, const adouble &b); + inline friend adouble ldexp(const adouble &a, const double v); + inline friend adouble ldexp(const double v, const adouble &a); + inline friend double frexp(const adouble &a, int *v); + inline friend adouble erf(const adouble &a); + inline friend adouble erfc(const adouble &a); + + inline friend void condassign(adouble &res, const adouble &cond, + const adouble &arg1, const adouble &arg2); + inline friend void condassign(adouble &res, const adouble &cond, + const adouble &arg); + inline friend void condeqassign(adouble &res, const adouble &cond, + const adouble &arg1, const adouble &arg2); + inline friend void condeqassign(adouble &res, const adouble &cond, + const adouble &arg); + + /******************* nontemporary results ***************************/ + // assignment + inline adouble &operator=(const double v); + inline adouble &operator=(const adouble &a); + + // addition + inline adouble &operator+=(const double v); + inline adouble &operator+=(const adouble &a); + + // subtraction + inline adouble &operator-=(const double v); + inline adouble &operator-=(const adouble &a); + + // multiplication + inline adouble &operator*=(const double v); + inline adouble &operator*=(const adouble &a); + + // division + inline adouble &operator/=(const double v); + inline adouble &operator/=(const adouble &a); + + // not + inline int operator!() const; + + // comparison + inline int operator!=(const adouble &) const; + inline int operator!=(const double) const; + inline friend int operator!=(const double, const adouble &); + + inline int operator==(const adouble &) const; + inline int operator==(const double) const; + inline friend int operator==(const double, const adouble &); + + inline int operator<=(const adouble &) const; + inline int operator<=(const double) const; + inline friend int operator<=(const double, const adouble &); + + inline int operator>=(const adouble &) const; + inline int operator>=(const double) const; + inline friend int operator>=(const double, const adouble &); + + inline int operator>(const adouble &) const; + inline int operator>(const double) const; + inline friend int operator>(const double, const adouble &); + + inline int operator<(const adouble &) const; + inline int operator<(const double) const; + inline friend int operator<(const double, const adouble &); + + /******************* getter / setter ********************************/ + inline double getValue() const; + inline void setValue(const double v); + inline const double *const getADValue() const; + inline void setADValue(const double *v); + + inline double getADValue(const unsigned int p) const; + inline void setADValue(const unsigned int p, const double v); + + double *getOneADValue(int i) const; + + void setOneADValue(int i, double *v); + + inline explicit operator double const &(); + inline explicit operator double &&(); + inline explicit operator double(); protected: - inline const list& get_pattern() const; - inline void add_to_pattern(const list& v); - inline size_t get_pattern_size() const; - inline void delete_pattern(); + inline const list &get_pattern() const; + inline void add_to_pattern(const list &v); + inline size_t get_pattern_size() const; + inline void delete_pattern(); public: - ADOLC_DLL_EXPORT friend int ADOLC_Init_sparse_pattern(adouble *a, int n,unsigned int start_cnt); - ADOLC_DLL_EXPORT friend int ADOLC_get_sparse_pattern(const adouble *const b, int m, unsigned int **&pat); - ADOLC_DLL_EXPORT friend int ADOLC_get_sparse_jacobian( func_ad *const func, int n, int m, int repeat, double* basepoints, int *nnz, unsigned int **rind, unsigned int **cind, double **values); + ADOLC_DLL_EXPORT friend int ADOLC_Init_sparse_pattern(adouble *a, int n, + unsigned int start_cnt); + ADOLC_DLL_EXPORT friend int + ADOLC_get_sparse_pattern(const adouble *const b, int m, unsigned int **&pat); + ADOLC_DLL_EXPORT friend int + ADOLC_get_sparse_jacobian(func_ad *const func, int n, int m, int repeat, + double *basepoints, int *nnz, unsigned int **rind, + unsigned int **cind, double **values); #if 0 ADOLC_DLL_EXPORT friend int ADOLC_get_sparse_jacobian(int n, int m, adouble *x, int *nnz, unsigned int *rind, unsigned int *cind, double *values); #endif - /******************* i/o operations *********************************/ - ADOLC_DLL_EXPORT friend ostream& operator << ( ostream&, const adouble& ); - ADOLC_DLL_EXPORT friend istream& operator >> ( istream&, adouble& ); + /******************* i/o operations *********************************/ + ADOLC_DLL_EXPORT friend ostream &operator<<(ostream &, const adouble &); + ADOLC_DLL_EXPORT friend istream &operator>>(istream &, adouble &); private: - double val; - double *adval; - double **ho_deriv; - list pattern; + double val; + double *adval; + double **ho_deriv; + list pattern; #ifdef USE_ADTL_REFCOUNTING - refcounter __rcnt; + refcounter __rcnt; #endif - inline static bool _do_val(); - inline static bool _do_adval(); - inline static bool _do_hoval(); - inline static bool _do_indo(); - ADOLC_DLL_EXPIMP static size_t numDir; - ADOLC_DLL_EXPIMP static size_t degree; - ADOLC_DLL_EXPIMP static enum Mode forward_mode; - inline friend void setNumDir(const size_t p); - inline friend void setDegree(const size_t p); - inline friend void setMode(enum Mode newmode); + inline static bool _do_val(); + inline static bool _do_adval(); + inline static bool _do_hoval(); + inline static bool _do_indo(); + ADOLC_DLL_EXPIMP static size_t numDir; + ADOLC_DLL_EXPIMP static size_t degree; + ADOLC_DLL_EXPIMP static enum Mode forward_mode; + inline friend void setNumDir(const size_t p); + inline friend void setDegree(const size_t p); + inline friend void setMode(enum Mode newmode); }; -} +} // namespace adtl_hov #include #include @@ -271,45 +271,45 @@ class adouble { namespace adtl_hov { enum ModeMask { - ADTL_Z_MASK = 0x1, - ADTL_F_MASK = 0x2, - ADTL_I_MASK = 0x4, - ADTL_H_MASK = 0x8 + ADTL_Z_MASK = 0x1, + ADTL_F_MASK = 0x2, + ADTL_I_MASK = 0x4, + ADTL_H_MASK = 0x8 }; #if defined(HAVE_BUILTIN_EXPECT) && HAVE_BUILTIN_EXPECT -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) #endif #ifndef likely -#define likely(x) (x) + #define likely(x) (x) #endif #ifndef unlikely -#define unlikely(x) (x) + #define unlikely(x) (x) #endif inline bool adouble::_do_val() { -return true; -// return ((forward_mode & ADTL_Z_MASK) == ADTL_Z_MASK); + return true; + // return ((forward_mode & ADTL_Z_MASK) == ADTL_Z_MASK); } #define do_val() likely(adouble::_do_val()) #define no_do_val() unlikely(!adouble::_do_val()) inline bool adouble::_do_adval() { -return true; -// return ((forward_mode & ADTL_F_MASK) == ADTL_F_MASK); + return true; + // return ((forward_mode & ADTL_F_MASK) == ADTL_F_MASK); } #define do_adval() likely(adouble::_do_adval()) #define no_do_adval() unlikely(!adouble::_do_adval()) inline bool adouble::_do_indo() { -return true; -// return ((forward_mode & ADTL_I_MASK) == ADTL_I_MASK); + return true; + // return ((forward_mode & ADTL_I_MASK) == ADTL_I_MASK); } -inline bool adouble::_do_hoval(){ -return true; -// return ((forward_mode & ADTL_H_MASK) == ADTL_H_MASK); +inline bool adouble::_do_hoval() { + return true; + // return ((forward_mode & ADTL_H_MASK) == ADTL_H_MASK); } #define do_indo() unlikely(adouble::_do_indo()) @@ -318,159 +318,174 @@ return true; inline void setNumDir(const size_t p) { #ifdef USE_ADTL_REFCOUNTING - if (refcounter::refcnt > 0) { - fprintf(DIAG_OUT, "ADOL-C Warning: Traceless: Setting numDir will not change the number of\n directional derivative in existing adoubles and may lead to erroneous results\n or memory corruption\n Number of currently existing adoubles = %zu\n", refcounter::refcnt); - } + if (refcounter::refcnt > 0) { + fprintf(DIAG_OUT, + "ADOL-C Warning: Traceless: Setting numDir will not change the " + "number of\n directional derivative in existing adoubles and may " + "lead to erroneous results\n or memory corruption\n Number of " + "currently existing adoubles = %zu\n", + refcounter::refcnt); + } #endif - if (p < 1) { - fprintf(DIAG_OUT, "ADOL-C Error: Traceless: You are being a moron now.\n"); - abort(); - } - adouble::numDir = p; + if (p < 1) { + fprintf(DIAG_OUT, "ADOL-C Error: Traceless: You are being a moron now.\n"); + abort(); + } + adouble::numDir = p; } inline void setDegree(const size_t p) { - if (p < 1) { - fprintf(DIAG_OUT, "ADOL-C Error: Traceless: p < 1 not possible.\n"); - abort(); - } - adouble::degree = p; + if (p < 1) { + fprintf(DIAG_OUT, "ADOL-C Error: Traceless: p < 1 not possible.\n"); + abort(); + } + adouble::degree = p; } inline void setMode(enum Mode newmode) { #ifdef USE_ADTL_REFCOUNTING if (refcounter::refcnt > 0) { - fprintf(DIAG_OUT, "ADOL-C Warning: Traceless: Setting mode will the change the mode of\n computation in previously computed variables and may lead to erroneous results\n or memory corruption\n Number of currently existing adoubles = %zu\n", refcounter::refcnt); + fprintf(DIAG_OUT, + "ADOL-C Warning: Traceless: Setting mode will the change the mode " + "of\n computation in previously computed variables and may lead to " + "erroneous results\n or memory corruption\n Number of currently " + "existing adoubles = %zu\n", + refcounter::refcnt); } #else - fprintf(DIAG_OUT, "ADOL-C Warning: Traceless: Setting mode will the change the mode of\n computation in previously computed variables and may lead to erroneous results\n or memory corruption\n"); + fprintf(DIAG_OUT, + "ADOL-C Warning: Traceless: Setting mode will the change the mode " + "of\n computation in previously computed variables and may lead to " + "erroneous results\n or memory corruption\n"); #endif - adouble::forward_mode = newmode; + adouble::forward_mode = newmode; } inline double makeNaN() { - return ADOLC_MATH_NSP::numeric_limits::quiet_NaN(); + return ADOLC_MATH_NSP::numeric_limits::quiet_NaN(); } inline double makeInf() { - return ADOLC_MATH_NSP::numeric_limits::infinity(); + return ADOLC_MATH_NSP::numeric_limits::infinity(); } -#define FOR_I_EQ_0_LT_NUMDIR for (int _i=0; _i < adouble::numDir; ++_i) -#define FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR for (int _j=0; _j < adouble::degree; ++_j) for (int _i=0; _i < adouble::numDir; ++_i) -#define FOR_I_EQ_0_LT_NUMDIR_FOR_J_EQ_0_LT_DEGREE for (int _i=0; _i < adouble::numDir; ++_i) for (int _j=0; _j < adouble::degree; ++_j) -#define ADVAL_I adval[_i] -#define ADV_I adv[_i] -#define V_I v[_i] -#define HO_DER_I_J ho_deriv[_j][_i] +#define FOR_I_EQ_0_LT_NUMDIR for (int _i = 0; _i < adouble::numDir; ++_i) +#define FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR \ + for (int _j = 0; _j < adouble::degree; ++_j) \ + for (int _i = 0; _i < adouble::numDir; ++_i) +#define FOR_I_EQ_0_LT_NUMDIR_FOR_J_EQ_0_LT_DEGREE \ + for (int _i = 0; _i < adouble::numDir; ++_i) \ + for (int _j = 0; _j < adouble::degree; ++_j) +#define ADVAL_I adval[_i] +#define ADV_I adv[_i] +#define V_I v[_i] +#define HO_DER_I_J ho_deriv[_j][_i] /******************************* ctors ************************************/ inline adouble::adouble() : val(0), adval(NULL) { - if (do_adval()) - adval = new double[adouble::numDir]; - - // ho_deriv= new double[adouble::degree][ adouble::numDir]; - //double** ho_deriv= new double*[adouble::degree]; -// std::cout << " do_hoval() is : "<< do_hoval() << std::endl; - if(do_hoval()) // ADTL_HOV -// std::cout << "constructing adtl: degree: " << adouble::degree << " numDir: " << adouble::numDir << std::endl; -{ - ho_deriv = myalloc2( adouble::degree, adouble::numDir); -} -/* - for(int i=0;i< adouble::degree;i++) - ho_deriv[i]=new double[adouble::numDir]; - -*/ + if (do_adval()) + adval = new double[adouble::numDir]; + + // ho_deriv= new double[adouble::degree][ adouble::numDir]; + // double** ho_deriv= new double*[adouble::degree]; + // std::cout << " do_hoval() is : "<< do_hoval() << std::endl; + if (do_hoval()) // ADTL_HOV + // std::cout << "constructing adtl: degree: " << adouble::degree + // << " numDir: " << adouble::numDir << std::endl; + { + ho_deriv = myalloc2(adouble::degree, adouble::numDir); + } + /* + for(int i=0;i< adouble::degree;i++) + ho_deriv[i]=new double[adouble::numDir]; - if (do_indo()) { - if (!pattern.empty()) - pattern.clear(); - } + */ + if (do_indo()) { + if (!pattern.empty()) + pattern.clear(); + } } inline adouble::adouble(const double v) : val(v), adval(NULL) { - if (do_adval()) { - adval = new double[adouble::numDir]; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I = 0.0; - } - if(do_hoval()) // ADTL_HOV - { - ho_deriv = myalloc2( adouble::degree, adouble::numDir); - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - HO_DER_I_J=0.0; - } - if (do_indo()) { - if (!pattern.empty()) - pattern.clear(); - } + if (do_adval()) { + adval = new double[adouble::numDir]; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = 0.0; + } + if (do_hoval()) // ADTL_HOV + { + ho_deriv = myalloc2(adouble::degree, adouble::numDir); + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + HO_DER_I_J = 0.0; + } + if (do_indo()) { + if (!pattern.empty()) + pattern.clear(); + } } -inline adouble::adouble(const double v, const double* adv) : val(v), adval(NULL) { - if (do_adval()) { - adval = new double[adouble::numDir]; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=ADV_I; - } - if(do_hoval()) // ADTL_HOV - { - fprintf(DIAG_OUT, "Dimension mismatch.\n"); - abort(); - } - +inline adouble::adouble(const double v, const double *adv) + : val(v), adval(NULL) { + if (do_adval()) { + adval = new double[adouble::numDir]; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = ADV_I; + } + if (do_hoval()) // ADTL_HOV + { + fprintf(DIAG_OUT, "Dimension mismatch.\n"); + abort(); + } - if (do_indo()) { - if (!pattern.empty()) - pattern.clear(); - } + if (do_indo()) { + if (!pattern.empty()) + pattern.clear(); + } } -inline adouble::adouble(const double v, const double** hov) : val(v), ho_deriv(NULL) { - if(do_hoval()) // ADTL_HOV - { - ho_deriv = myalloc2( adouble::degree, adouble::numDir); - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - HO_DER_I_J=hov[_j][_i]; - } - if (do_adval()) { - fprintf(DIAG_OUT, "Dimension mismatch.\n"); - abort(); - } - +inline adouble::adouble(const double v, const double **hov) + : val(v), ho_deriv(NULL) { + if (do_hoval()) // ADTL_HOV + { + ho_deriv = myalloc2(adouble::degree, adouble::numDir); + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + HO_DER_I_J = hov[_j][_i]; + } + if (do_adval()) { + fprintf(DIAG_OUT, "Dimension mismatch.\n"); + abort(); + } - if (do_indo()) { - if (!pattern.empty()) - pattern.clear(); - } + if (do_indo()) { + if (!pattern.empty()) + pattern.clear(); + } } +inline adouble::adouble(const adouble &a) : val(a.val), adval(NULL) { + if (do_adval()) { + adval = new double[adouble::numDir]; + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = a.ADVAL_I; + } + if (do_hoval()) // ADTL_HOV + { + ho_deriv = myalloc2(adouble::degree, adouble::numDir); + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + HO_DER_I_J = a.HO_DER_I_J; + } + if (do_indo()) { + if (!pattern.empty()) + pattern.clear(); - -inline adouble::adouble(const adouble& a) : val(a.val), adval(NULL) { - if (do_adval()) { - adval = new double[adouble::numDir]; - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=a.ADVAL_I; - } - if(do_hoval()) // ADTL_HOV - { - ho_deriv = myalloc2( adouble::degree, adouble::numDir); - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - HO_DER_I_J=a.HO_DER_I_J; - } - if (do_indo()) { - if (!pattern.empty()) - pattern.clear(); - - add_to_pattern(a.get_pattern()); - } + add_to_pattern(a.get_pattern()); + } } /******************************* dtors ************************************/ inline adouble::~adouble() { - if (adval != NULL) - delete[] adval; + if (adval != NULL) + delete[] adval; // if(ho_deriv!=NULL) // delete[][] ho_deriv; #if 0 @@ -481,2027 +496,2109 @@ inline adouble::~adouble() { /************************* temporary results ******************************/ // sign -inline adouble adouble::operator - () const { - adouble tmp; - if (do_val()) - tmp.val=-val; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=-ADVAL_I; - if(do_hoval()) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - tmp.HO_DER_I_J=-HO_DER_I_J; - } - if (do_indo()) - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator-() const { + adouble tmp; + if (do_val()) + tmp.val = -val; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = -ADVAL_I; + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + tmp.HO_DER_I_J = -HO_DER_I_J; + } + if (do_indo()) + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator + () const { - return *this; -} +inline adouble adouble::operator+() const { return *this; } // addition -inline adouble adouble::operator + (const double v) const { - adouble tmp(val+v, adval); - if (do_indo()) - tmp.add_to_pattern( get_pattern() ) ; - return tmp; -} - -inline adouble adouble::operator + (const adouble& a) const { - adouble tmp; - if (do_val()) - tmp.val=val+a.val; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I+a.ADVAL_I; - if(do_hoval()) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - tmp.HO_DER_I_J=HO_DER_I_J+a.HO_DER_I_J; - } - if (do_indo()) { - tmp.add_to_pattern( get_pattern() ); - tmp.add_to_pattern( a.get_pattern() ); - } - return tmp; +inline adouble adouble::operator+(const double v) const { + adouble tmp(val + v, adval); + if (do_indo()) + tmp.add_to_pattern(get_pattern()); + return tmp; +} + +inline adouble adouble::operator+(const adouble &a) const { + adouble tmp; + if (do_val()) + tmp.val = val + a.val; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I + a.ADVAL_I; + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + tmp.HO_DER_I_J = HO_DER_I_J + a.HO_DER_I_J; + } + if (do_indo()) { + tmp.add_to_pattern(get_pattern()); + tmp.add_to_pattern(a.get_pattern()); + } + return tmp; } -inline adouble operator + (const double v, const adouble& a) { - adouble tmp; - if (do_val()) - { - adouble tmp(v+a.val, a.adval); - } - if( do_hoval() ) // ADTL_HOV //how can this not be declared? it works fine in the method above - { // why was "a." necessary here and not after the next line? - std::cout << "Not implemented. " << std::endl; - throw std::exception(); - //adouble tmp(v+a.val,a.ho_deriv); //TODO: does not exist yet - } - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble operator+(const double v, const adouble &a) { + adouble tmp; + if (do_val()) { + adouble tmp(v + a.val, a.adval); + } + if (do_hoval()) // ADTL_HOV //how can this not be declared? it works fine in + // the method above + { // why was "a." necessary here and not after the next line? + std::cout << "Not implemented. " << std::endl; + throw std::exception(); + // adouble tmp(v+a.val,a.ho_deriv); //TODO: does not exist yet + } + if (do_indo()) + tmp.add_to_pattern(a.get_pattern()); + return tmp; } // subtraction -inline adouble adouble::operator - (const double v) const { - adouble tmp; - if (do_val()) - { - adouble tmp(val-v, adval); - } - if( do_hoval() ) // ADTL_HOV //how can this not be declared? it works fine in the method above - { // why was "a." necessary here and not after the next line? - std::cout << "Not implemented. " << std::endl; - throw std::exception(); - //adouble tmp(val-v, adval,ho_deriv); //TODO: does not exist yet - } - //adouble tmp(val-v, adval); moved up - if (do_indo()) - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator-(const double v) const { + adouble tmp; + if (do_val()) { + adouble tmp(val - v, adval); + } + if (do_hoval()) // ADTL_HOV //how can this not be declared? it works fine in + // the method above + { // why was "a." necessary here and not after the next line? + std::cout << "Not implemented. " << std::endl; + throw std::exception(); + // adouble tmp(val-v, adval,ho_deriv); //TODO: does not exist yet + } + // adouble tmp(val-v, adval); moved up + if (do_indo()) + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator - (const adouble& a) const { - adouble tmp; - if (do_val()) - tmp.val=val-a.val; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I-a.ADVAL_I; - if (do_indo()) { - tmp.add_to_pattern( get_pattern() ); - tmp.add_to_pattern( a.get_pattern() ); - } - if( do_hoval() ) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - tmp.HO_DER_I_J=HO_DER_I_J-a.HO_DER_I_J; - //adouble tmp(val-v, adval,ho_deriv); //TODO: does not exist yet - } - return tmp; +inline adouble adouble::operator-(const adouble &a) const { + adouble tmp; + if (do_val()) + tmp.val = val - a.val; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I - a.ADVAL_I; + if (do_indo()) { + tmp.add_to_pattern(get_pattern()); + tmp.add_to_pattern(a.get_pattern()); + } + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + tmp.HO_DER_I_J = HO_DER_I_J - a.HO_DER_I_J; + // adouble tmp(val-v, adval,ho_deriv); //TODO: does not exist yet + } + return tmp; } -inline adouble operator - (const double v, const adouble& a) { - adouble tmp; - if (do_val()) - tmp.val=v-a.val; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=-a.ADVAL_I; - - if( do_hoval() ) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - tmp.HO_DER_I_J=-a.HO_DER_I_J; - } - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble operator-(const double v, const adouble &a) { + adouble tmp; + if (do_val()) + tmp.val = v - a.val; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = -a.ADVAL_I; + + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + tmp.HO_DER_I_J = -a.HO_DER_I_J; + } + if (do_indo()) + tmp.add_to_pattern(a.get_pattern()); + return tmp; } // multiplication -inline adouble adouble::operator * (const double v) const { - adouble tmp; - if (do_val()) - tmp.val=val*v; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=ADVAL_I*v; - if( do_hoval() ) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - tmp.HO_DER_I_J=v*HO_DER_I_J; - } - if (do_indo()) - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator*(const double v) const { + adouble tmp; + if (do_val()) + tmp.val = val * v; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = ADVAL_I * v; + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + tmp.HO_DER_I_J = v * HO_DER_I_J; + } + if (do_indo()) + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator * (const adouble& a) const { - adouble tmp; - if (unlikely(!adouble::_do_val() && adouble::_do_adval())) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - if (do_val()) - tmp.val=val*a.val; - if( do_hoval() ) // ADTL_HOV - { - int i; - double sum=0.0; - for(int l=0;l0) tmp.ADVAL_I=a.ADVAL_I/a.val; - else if (a.val==0 && a.ADVAL_I != 0.0) { - int sign = (a.ADVAL_I < 0) ? -1 : 1; - tmp.ADVAL_I=sign*makeInf(); - } else tmp.ADVAL_I=makeNaN(); - } + adouble tmp; + if (unlikely(!adouble::_do_val() && adouble::_do_adval())) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (do_val()) + tmp.val = ADOLC_MATH_NSP::log(a.val); + if (likely(adouble::_do_adval() && adouble::_do_val())) { + FOR_I_EQ_0_LT_NUMDIR + if (a.val > 0) + tmp.ADVAL_I = a.ADVAL_I / a.val; + else if (a.val == 0 && a.ADVAL_I != 0.0) { + int sign = (a.ADVAL_I < 0) ? -1 : 1; + tmp.ADVAL_I = sign * makeInf(); + } else + tmp.ADVAL_I = makeNaN(); + } - if( do_hoval() ) // ADTL_HOV - { - int i; - double sum=0.0; - for(int l=0;l0) tmp.ADVAL_I=a.ADVAL_I/(tmp.val*2); - else if (a.val==0.0 && a.ADVAL_I != 0.0) { - int sign = (a.ADVAL_I < 0) ? -1 : 1; - tmp.ADVAL_I=sign * makeInf(); - } else tmp.ADVAL_I=makeNaN(); - } + adouble tmp; + if (unlikely(!adouble::_do_val() && adouble::_do_adval())) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (do_val()) + tmp.val = ADOLC_MATH_NSP::sqrt(a.val); + if (likely(adouble::_do_adval() && adouble::_do_val())) { + FOR_I_EQ_0_LT_NUMDIR + if (a.val > 0) + tmp.ADVAL_I = a.ADVAL_I / (tmp.val * 2); + else if (a.val == 0.0 && a.ADVAL_I != 0.0) { + int sign = (a.ADVAL_I < 0) ? -1 : 1; + tmp.ADVAL_I = sign * makeInf(); + } else + tmp.ADVAL_I = makeNaN(); + } - if( do_hoval() ) // ADTL_HOV - { - int i; - double sum=0.0; - for(int l=0;l 0) + as = 1; + if (a.val < 0) + as = -1; + if (as != 0) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I * as; + else FOR_I_EQ_0_LT_NUMDIR { + as = 0; + if (a.ADVAL_I > 0) + as = 1; + if (a.ADVAL_I < 0) + as = -1; + tmp.ADVAL_I = a.ADVAL_I * as; } - if( do_hoval() ) // ADTL_HOV + } + if (do_hoval()) // ADTL_HOV + { + // find leading Taylor coefficient + + // TODO: do not forget to check the function value. it is the zero-th taylor + // coefficient + + int i, m; + double sum; + int *leading_sgn = (int *)alloca(sizeof(int) * adouble::degree); + for (int l = 0; l < adouble::numDir; l++) // Init { - //TODO - std::cout <<"error: higher order derivatives for asinh have not been implemented yet!!!"< 0 && (!found)) { + leading_sgn[l] = 1; + found = true; + break; + // found leading coefficient for this direction. it is positive. + // no need to do any further for this direction + } + if (tmp.ho_deriv[k][l] < 0 && (!found)) { + // found leading coefficient for this direction. it is negative. + found = true; + leading_sgn[l] = -1; + break; + } + /* + if(tmp.ho_deriv[k][l]=0 && (!found)) + { + //not the leading Taylor coefficient + //continue searching + } + */ + } + found = false; } - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - return tmp; -} -inline adouble acosh (const adouble &a) { - adouble tmp; - if (unlikely(!adouble::_do_val() && adouble::_do_adval())) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - if (do_val()) - tmp.val=ADOLC_MATH_NSP_ERF::acosh(a.val); - if (likely(adouble::_do_adval() && adouble::_do_val())) { - double tmp2=ADOLC_MATH_NSP::sqrt(a.val*a.val-1); - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I/tmp2; - } - if( do_hoval() ) // ADTL_HOV - { - //TODO - std::cout <<"error: higher order derivatives for acosh have not been implemented yet!!!"<0) as=1; - if (a.val<0) as=-1; - if (as!=0) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I*as; - else - FOR_I_EQ_0_LT_NUMDIR { - as=0; - if (a.ADVAL_I>0) as=1; - if (a.ADVAL_I<0) as=-1; - tmp.ADVAL_I=a.ADVAL_I*as; - } - } - if( do_hoval() ) // ADTL_HOV - { - //find leading Taylor coefficient - - // TODO: do not forget to check the function value. it is the zero-th taylor coefficient - - int i,m; - double sum; - int* leading_sgn = (int*)alloca(sizeof(int) * adouble::degree); - for(int l=0;l0 && (!found)) - { - leading_sgn[l]=1; - found = true; - break; - //found leading coefficient for this direction. it is positive. - // no need to do any further for this direction - } - if (tmp.ho_deriv[k][l]<0 && (!found)) - { - //found leading coefficient for this direction. it is negative. - found = true; - leading_sgn[l]=-1; - break; - } - /* - if(tmp.ho_deriv[k][l]=0 && (!found)) - { - //not the leading Taylor coefficient - //continue searching - } - */ - } - found = false; - } - - //assume we found all leading Taylor coefficients - - for(int l=0;l 0) { + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; + if (do_indo()) + tmp.add_to_pattern(a.get_pattern()); } else { - if (do_val()) - tmp.val=a.val; - if (tmp2>0) { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - } else { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I 0) { + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = 0.0; } else { - if (do_val()) - tmp.val=v; - if (tmp2>0) { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; - } else { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I>0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - } - } - if( do_hoval() ) // ADTL_HOV - { - //TODO - std::cout <<"error: higher order derivatives for fmax have not been implemented yet!!!"< 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } + if (do_indo()) + tmp.add_to_pattern(a.get_pattern()); } - return tmp; + } + if (do_hoval()) // ADTL_HOV + { + // TODO + std::cout << "error: higher order derivatives for fmax have not been " + "implemented yet!!!" + << std::endl; + exit(1); + } + return tmp; } -inline adouble fmax (const adouble &a, double v) { - adouble tmp; - if (unlikely(!adouble::_do_val() && (adouble::_do_adval() || adouble::_do_indo()))) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - double tmp2=a.val-v; - if (tmp2<0) { - if (do_val()) - tmp.val=v; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; +inline adouble fmax(const adouble &a, double v) { + adouble tmp; + if (unlikely(!adouble::_do_val() && + (adouble::_do_adval() || adouble::_do_indo()))) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + double tmp2 = a.val - v; + if (tmp2 < 0) { + if (do_val()) + tmp.val = v; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = 0.0; + } else { + if (do_val()) + tmp.val = a.val; + if (tmp2 > 0) { + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; + if (do_indo()) + tmp.add_to_pattern(a.get_pattern()); } else { - if (do_val()) - tmp.val=a.val; - if (tmp2>0) { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - } else { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I>0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - } - } - if( do_hoval() ) // ADTL_HOV - { - //TODO - std::cout <<"error: higher order derivatives for fmax have not been implemented yet!!!"< 0) + tmp.ADVAL_I = a.ADVAL_I; + else + tmp.ADVAL_I = 0.0; + } + if (do_indo()) + tmp.add_to_pattern(a.get_pattern()); } - return tmp; + } + if (do_hoval()) // ADTL_HOV + { + // TODO + std::cout << "error: higher order derivatives for fmax have not been " + "implemented yet!!!" + << std::endl; + exit(1); + } + return tmp; } -inline adouble fmin (const adouble &a, const adouble &b) { - adouble tmp; - if (unlikely(!adouble::_do_val() && (adouble::_do_adval() || adouble::_do_indo()))) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - double tmp2=a.val-b.val; - if (tmp2<0) { - if (do_val()) - tmp.val=a.val; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); +inline adouble fmin(const adouble &a, const adouble &b) { + adouble tmp; + if (unlikely(!adouble::_do_val() && + (adouble::_do_adval() || adouble::_do_indo()))) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + double tmp2 = a.val - b.val; + if (tmp2 < 0) { + if (do_val()) + tmp.val = a.val; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; + if (do_indo()) + tmp.add_to_pattern(a.get_pattern()); + } else { + if (do_val()) + tmp.val = b.val; + if (tmp2 > 0) { + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = b.ADVAL_I; + if (do_indo()) + tmp.add_to_pattern(b.get_pattern()); } else { - if (do_val()) - tmp.val=b.val; - if (tmp2>0) { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=b.ADVAL_I; - if (do_indo()) - tmp.add_to_pattern( b.get_pattern() ); - } else { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I 0) { + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = a.ADVAL_I; + if (do_indo()) + tmp.add_to_pattern(a.get_pattern()); } else { - if (do_val()) - tmp.val=a.val; - if (tmp2>0) { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=a.ADVAL_I; - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - } else { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I<0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - } - } - if( do_hoval() ) // ADTL_HOV - { - //TODO - std::cout <<"error: higher order derivatives for fmin have not been implemented yet!!!"< 0) { + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + tmp.ADVAL_I = 0.0; } else { - if (do_val()) - tmp.val=v; - if (tmp2>0) { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - tmp.ADVAL_I=0.0; - } else { - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - { - if (a.ADVAL_I<0) tmp.ADVAL_I=a.ADVAL_I; - else tmp.ADVAL_I=0.0; - } - if (do_indo()) - tmp.add_to_pattern( a.get_pattern() ); - } - } - if( do_hoval() ) // ADTL_HOV - { - //TODO - std::cout <<"error: higher order derivatives for fmin have not been implemented yet!!!"< 0) - res = arg1; - else - res = arg2; - } +inline void condassign(adouble &res, const adouble &cond, const adouble &arg1, + const adouble &arg2) { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (do_val()) { + if (cond.getValue() > 0) + res = arg1; + else + res = arg2; + } } -inline void condassign( adouble &res, const adouble &cond, - const adouble &arg ) { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - if (do_val()) { - if (cond.getValue() > 0) - res = arg; - } +inline void condassign(adouble &res, const adouble &cond, const adouble &arg) { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (do_val()) { + if (cond.getValue() > 0) + res = arg; + } } -inline void condeqassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ) { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - if (do_val()) { - if (cond.getValue() >= 0) - res = arg1; - else - res = arg2; - } +inline void condeqassign(adouble &res, const adouble &cond, const adouble &arg1, + const adouble &arg2) { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (do_val()) { + if (cond.getValue() >= 0) + res = arg1; + else + res = arg2; + } } -inline void condeqassign( adouble &res, const adouble &cond, - const adouble &arg ) { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - if (do_val()) { - if (cond.getValue() >= 0) - res = arg; - } +inline void condeqassign(adouble &res, const adouble &cond, + const adouble &arg) { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (do_val()) { + if (cond.getValue() >= 0) + res = arg; + } } - - /******************* nontemporary results *********************************/ -inline adouble& adouble::operator = (const double v) { - if (do_val()) - val=v; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=0.0; - - if( do_hoval() ) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - HO_DER_I_J=0.0; - } +inline adouble &adouble::operator=(const double v) { + if (do_val()) + val = v; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = 0.0; + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + HO_DER_I_J = 0.0; + } - if (do_indo()) - if (!pattern.empty()) pattern.clear(); - return *this; + if (do_indo()) + if (!pattern.empty()) + pattern.clear(); + return *this; } -inline adouble& adouble::operator = (const adouble& a) { - if (do_val()) - val=a.val; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=a.ADVAL_I; +inline adouble &adouble::operator=(const adouble &a) { + if (do_val()) + val = a.val; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = a.ADVAL_I; - if( do_hoval() ) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - HO_DER_I_J=a.HO_DER_I_J; - } + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + HO_DER_I_J = a.HO_DER_I_J; + } - if (do_indo()) { - if (!pattern.empty()) pattern.clear(); - add_to_pattern( a.get_pattern() ); - } - return *this; + if (do_indo()) { + if (!pattern.empty()) + pattern.clear(); + add_to_pattern(a.get_pattern()); + } + return *this; } -inline adouble& adouble::operator += (const double v) { - if (do_val()) - val+=v; - return *this; +inline adouble &adouble::operator+=(const double v) { + if (do_val()) + val += v; + return *this; } -inline adouble& adouble::operator += (const adouble& a) { - if (do_val()) - val=val+a.val; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I+=a.ADVAL_I; +inline adouble &adouble::operator+=(const adouble &a) { + if (do_val()) + val = val + a.val; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I += a.ADVAL_I; - if( do_hoval() ) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - HO_DER_I_J+=a.HO_DER_I_J; - } + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + HO_DER_I_J += a.HO_DER_I_J; + } - if (do_indo()) - add_to_pattern( a.get_pattern() ); - return *this; + if (do_indo()) + add_to_pattern(a.get_pattern()); + return *this; } -inline adouble& adouble::operator -= (const double v) { - if (do_val()) - val-=v; - return *this; +inline adouble &adouble::operator-=(const double v) { + if (do_val()) + val -= v; + return *this; } -inline adouble& adouble::operator -= (const adouble& a) { - if (do_val()) - val=val-a.val; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I-=a.ADVAL_I; +inline adouble &adouble::operator-=(const adouble &a) { + if (do_val()) + val = val - a.val; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I -= a.ADVAL_I; - if( do_hoval() ) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - HO_DER_I_J-=a.HO_DER_I_J; - } + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + HO_DER_I_J -= a.HO_DER_I_J; + } - if (do_indo()) - add_to_pattern( a.get_pattern() ) ; - return *this; + if (do_indo()) + add_to_pattern(a.get_pattern()); + return *this; } -inline adouble& adouble::operator *= (const double v) { - if (do_val()) - val=val*v; - if (do_adval()) - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I*=v; - if( do_hoval() ) // ADTL_HOV - { - FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR - HO_DER_I_J*=v; - } - return *this; +inline adouble &adouble::operator*=(const double v) { + if (do_val()) + val = val * v; + if (do_adval()) + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I *= v; + if (do_hoval()) // ADTL_HOV + { + FOR_J_EQ_0_LT_DEGREE_FOR_I_EQ_0_LT_NUMDIR + HO_DER_I_J *= v; + } + return *this; } -inline adouble& adouble::operator *= (const adouble& a) { - if (unlikely(!adouble::_do_val() && adouble::_do_adval())) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); +inline adouble &adouble::operator*=(const adouble &a) { + if (unlikely(!adouble::_do_val() && adouble::_do_adval())) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (likely(adouble::_do_adval() && adouble::_do_val())) + FOR_I_EQ_0_LT_NUMDIR + ADVAL_I = ADVAL_I * a.val + val * a.ADVAL_I; + if (do_val()) + val *= a.val; + + adouble tmp; + tmp.val = val * a.val; + + if (do_hoval()) // ADTL_HOV + { + int i, m; + double sum; + double sum1 = 0.0, sum2 = 0.0; + for (int l = 0; l < adouble::numDir; l++) { + for (int k = 0; k < degree; k++) { + sum = val * a.ho_deriv[k][l] + ho_deriv[k][l] * a.val; + i = k - 1; + for (int j = 0; j < k; j++) + sum += ho_deriv[j][l] * a.ho_deriv[i - j][l]; + tmp.ho_deriv[k][l] = sum; + sum = 0.0; + } + val = tmp.val; + for (int k = 0; k < degree; k++) + ho_deriv[k][l] = tmp.ho_deriv[k][l]; } - if (likely(adouble::_do_adval() && adouble::_do_val())) - FOR_I_EQ_0_LT_NUMDIR - ADVAL_I=ADVAL_I*a.val+val*a.ADVAL_I; - if (do_val()) - val*=a.val; + } - adouble tmp; - tmp.val=val*a.val; - - if( do_hoval() ) // ADTL_HOV - { - int i,m; - double sum; - double sum1=0.0, sum2=0.0; - for(int l=0;l= (const adouble &a) const { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - return val>=a.val; +inline int adouble::operator>=(const adouble &a) const { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + return val >= a.val; } -inline int adouble::operator >= (const double v) const { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - return val>=v; +inline int adouble::operator>=(const double v) const { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + return val >= v; } -inline int operator >= (const double v, const adouble &a) { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - return v>=a.val; +inline int operator>=(const double v, const adouble &a) { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + return v >= a.val; } -inline int adouble::operator > (const adouble &a) const { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - return val>a.val; +inline int adouble::operator>(const adouble &a) const { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + return val > a.val; } -inline int adouble::operator > (const double v) const { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - return val>v; +inline int adouble::operator>(const double v) const { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + return val > v; } -inline int operator > (const double v, const adouble &a) { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - return v>a.val; +inline int operator>(const double v, const adouble &a) { + if (no_do_val()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + return v > a.val; } -inline int adouble::operator < (const adouble &a) const { - if (no_do_val()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - return val=adouble::numDir) - { - fprintf(DIAG_OUT, "Derivative array accessed out of bounds"\ - " while \"getADValue(...)\"!!!\n"); - throw logic_error("incorrect function call, errorcode=-1"); - } - return adval[p]; + if (no_do_adval()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (p >= adouble::numDir) { + fprintf(DIAG_OUT, "Derivative array accessed out of bounds" + " while \"getADValue(...)\"!!!\n"); + throw logic_error("incorrect function call, errorcode=-1"); + } + return adval[p]; } inline void adouble::setADValue(const unsigned int p, const double v) { - if (no_do_adval()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - if (p>=adouble::numDir) - { - fprintf(DIAG_OUT, "Derivative array accessed out of bounds"\ - " while \"setADValue(...)\"!!!\n"); - throw logic_error("incorrect function call, errorcode=-1"); - } - adval[p]=v; + if (no_do_adval()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (p >= adouble::numDir) { + fprintf(DIAG_OUT, "Derivative array accessed out of bounds" + " while \"setADValue(...)\"!!!\n"); + throw logic_error("incorrect function call, errorcode=-1"); + } + adval[p] = v; } -double* adouble::getOneADValue(int i) const{ - std::cout << " getOneADValue : i= "<< i<< std::endl; - return ho_deriv[i];} +double *adouble::getOneADValue(int i) const { + std::cout << " getOneADValue : i= " << i << std::endl; + return ho_deriv[i]; +} -void adouble::setOneADValue(int i, double* v){ - ho_deriv[i]=v;} +void adouble::setOneADValue(int i, double *v) { ho_deriv[i] = v; } -inline const list& adouble::get_pattern() const { - if (no_do_indo()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - return pattern; +inline const list &adouble::get_pattern() const { + if (no_do_indo()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + return pattern; } inline void adouble::delete_pattern() { - if (no_do_indo()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - if ( !pattern.empty() ) - pattern.clear(); + if (no_do_indo()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (!pattern.empty()) + pattern.clear(); } -inline void adouble::add_to_pattern(const list& v) { - if (no_do_indo()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - if (likely( pattern != v)) { - if( !v.empty() ){ - list cv = v; - //pattern.splice(pattern.end(), cv); - pattern.merge(cv); - //if (pattern.size() > refcounter::refcnt) { - //pattern.sort(); - pattern.unique(); - //} - } +inline void adouble::add_to_pattern(const list &v) { + if (no_do_indo()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + if (likely(pattern != v)) { + if (!v.empty()) { + list cv = v; + // pattern.splice(pattern.end(), cv); + pattern.merge(cv); + // if (pattern.size() > refcounter::refcnt) { + // pattern.sort(); + pattern.unique(); + //} } + } } inline size_t adouble::get_pattern_size() const { - if (no_do_indo()) { - fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call setMode(enum Mode mode)\n"); - throw logic_error("incorrect function call, errorcode=1"); - } - size_t s=0; - if( !pattern.empty() ) - s = pattern.size(); - return s; + if (no_do_indo()) { + fprintf(DIAG_OUT, "ADOL-C error: Traceless: Incorrect mode, call " + "setMode(enum Mode mode)\n"); + throw logic_error("incorrect function call, errorcode=1"); + } + size_t s = 0; + if (!pattern.empty()) + s = pattern.size(); + return s; } -} +} // namespace adtl_hov #endif diff --git a/ADOL-C/include/adolc/adtl_indo.h b/ADOL-C/include/adolc/adtl_indo.h index f9444268b..d5c00a937 100644 --- a/ADOL-C/include/adolc/adtl_indo.h +++ b/ADOL-C/include/adolc/adtl_indo.h @@ -17,32 +17,37 @@ #ifndef ADOLC_ADTL_INDO_H #define ADOLC_ADTL_INDO_H -#include #include #include +#include #include - #include -using std::ostream; using std::istream; using std::list; using std::logic_error; +using std::ostream; -template -class func_ad { +template class func_ad { public: - virtual int operator() (int n, T *x, int m, T *y) = 0; + virtual int operator()(int n, T *x, int m, T *y) = 0; }; -namespace adtl_indo{ +namespace adtl_indo { class adouble; -ADOLC_DLL_EXPORT int ADOLC_Init_sparse_pattern(adouble *a, int n,unsigned int start_cnt); -ADOLC_DLL_EXPORT int ADOLC_get_sparse_pattern(const adouble *const b, int m, unsigned int **&pat); -} - -ADOLC_DLL_EXPORT int ADOLC_get_sparse_jacobian( func_ad *const func, func_ad *const func_indo, int n, int m, int repeat, double* basepoints, int *nnz, unsigned int **rind, unsigned int **cind, double **values); +ADOLC_DLL_EXPORT int ADOLC_Init_sparse_pattern(adouble *a, int n, + unsigned int start_cnt); +ADOLC_DLL_EXPORT int ADOLC_get_sparse_pattern(const adouble *const b, int m, + unsigned int **&pat); +} // namespace adtl_indo + +ADOLC_DLL_EXPORT int +ADOLC_get_sparse_jacobian(func_ad *const func, + func_ad *const func_indo, int n, + int m, int repeat, double *basepoints, int *nnz, + unsigned int **rind, unsigned int **cind, + double **values); namespace adtl_indo { @@ -51,171 +56,169 @@ double makeInf(); class adouble { public: - inline adouble(); - inline adouble(const double v); - inline adouble(const double v, const double* adv); - inline adouble(const adouble& a); - inline ~adouble(); - - // sign - inline adouble operator - () const; - inline adouble operator + () const; - - // addition - inline adouble operator + (const double v) const; - inline adouble operator + (const adouble& a) const; - inline friend - adouble operator + (const double v, const adouble& a); - - // subtraction - inline adouble operator - (const double v) const; - inline adouble operator - (const adouble& a) const; - inline friend - adouble operator - (const double v, const adouble& a); - - // multiplication - inline adouble operator * (const double v) const; - inline adouble operator * (const adouble& a) const; - inline friend - adouble operator * (const double v, const adouble& a); - - // division - inline adouble operator / (const double v) const; - inline adouble operator / (const adouble& a) const; - inline friend - adouble operator / (const double v, const adouble& a); - - // inc/dec - inline adouble operator ++ (); - inline adouble operator ++ (int); - inline adouble operator -- (); - inline adouble operator -- (int); - - // functions - inline friend adouble tan(const adouble &a); - inline friend adouble exp(const adouble &a); - inline friend adouble log(const adouble &a); - inline friend adouble sqrt(const adouble &a); - inline friend adouble cbrt(const adouble &a); - inline friend adouble sin(const adouble &a); - inline friend adouble cos(const adouble &a); - inline friend adouble asin(const adouble &a); - inline friend adouble acos(const adouble &a); - inline friend adouble atan(const adouble &a); - - inline friend adouble atan2(const adouble &a, const adouble &b); - inline friend adouble pow(const adouble &a, double v); - inline friend adouble pow(const adouble &a, const adouble &b); - inline friend adouble pow(double v, const adouble &a); - inline friend adouble log10(const adouble &a); - - inline friend adouble sinh (const adouble &a); - inline friend adouble cosh (const adouble &a); - inline friend adouble tanh (const adouble &a); - inline friend adouble asinh (const adouble &a); - inline friend adouble acosh (const adouble &a); - inline friend adouble atanh (const adouble &a); - inline friend adouble fabs (const adouble &a); - inline friend adouble ceil (const adouble &a); - inline friend adouble floor (const adouble &a); - inline friend adouble fmax (const adouble &a, const adouble &b); - inline friend adouble fmax (double v, const adouble &a); - inline friend adouble fmax (const adouble &a, double v); - inline friend adouble fmin (const adouble &a, const adouble &b); - inline friend adouble fmin (double v, const adouble &a); - inline friend adouble fmin (const adouble &a, double v); - inline friend adouble ldexp (const adouble &a, const adouble &b); - inline friend adouble ldexp (const adouble &a, const double v); - inline friend adouble ldexp (const double v, const adouble &a); - inline friend double frexp (const adouble &a, int* v); - inline friend adouble erf (const adouble &a); - inline friend adouble erfc (const adouble &a); - - inline friend void condassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ); - inline friend void condassign( adouble &res, const adouble &cond, - const adouble &arg ); - inline friend void condeqassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ); - inline friend void condeqassign( adouble &res, const adouble &cond, - const adouble &arg ); - - /******************* nontemporary results ***************************/ - // assignment - inline adouble& operator = (const double v); - inline adouble& operator = (const adouble& a); - - // addition - inline adouble& operator += (const double v); - inline adouble& operator += (const adouble& a); - - // subtraction - inline adouble& operator -= (const double v); - inline adouble& operator -= (const adouble& a); - - // multiplication - inline adouble& operator *= (const double v); - inline adouble& operator *= (const adouble& a); - - // division - inline adouble& operator /= (const double v); - inline adouble& operator /= (const adouble& a); - - // not - inline int operator ! () const; - - // comparison - inline int operator != (const adouble&) const; - inline int operator != (const double) const; - inline friend int operator != (const double, const adouble&); - - inline int operator == (const adouble&) const; - inline int operator == (const double) const; - inline friend int operator == (const double, const adouble&); - - inline int operator <= (const adouble&) const; - inline int operator <= (const double) const; - inline friend int operator <= (const double, const adouble&); - - inline int operator >= (const adouble&) const; - inline int operator >= (const double) const; - inline friend int operator >= (const double, const adouble&); - - inline int operator > (const adouble&) const; - inline int operator > (const double) const; - inline friend int operator > (const double, const adouble&); - - inline int operator < (const adouble&) const; - inline int operator < (const double) const; - inline friend int operator < (const double, const adouble&); - - /******************* getter / setter ********************************/ - inline double getValue() const; - inline void setValue(const double v); - - inline explicit operator double const&() const; - inline explicit operator double&&(); - inline explicit operator double(); + inline adouble(); + inline adouble(const double v); + inline adouble(const double v, const double *adv); + inline adouble(const adouble &a); + inline ~adouble(); + + // sign + inline adouble operator-() const; + inline adouble operator+() const; + + // addition + inline adouble operator+(const double v) const; + inline adouble operator+(const adouble &a) const; + inline friend adouble operator+(const double v, const adouble &a); + + // subtraction + inline adouble operator-(const double v) const; + inline adouble operator-(const adouble &a) const; + inline friend adouble operator-(const double v, const adouble &a); + + // multiplication + inline adouble operator*(const double v) const; + inline adouble operator*(const adouble &a) const; + inline friend adouble operator*(const double v, const adouble &a); + + // division + inline adouble operator/(const double v) const; + inline adouble operator/(const adouble &a) const; + inline friend adouble operator/(const double v, const adouble &a); + + // inc/dec + inline adouble operator++(); + inline adouble operator++(int); + inline adouble operator--(); + inline adouble operator--(int); + + // functions + inline friend adouble tan(const adouble &a); + inline friend adouble exp(const adouble &a); + inline friend adouble log(const adouble &a); + inline friend adouble sqrt(const adouble &a); + inline friend adouble cbrt(const adouble &a); + inline friend adouble sin(const adouble &a); + inline friend adouble cos(const adouble &a); + inline friend adouble asin(const adouble &a); + inline friend adouble acos(const adouble &a); + inline friend adouble atan(const adouble &a); + + inline friend adouble atan2(const adouble &a, const adouble &b); + inline friend adouble pow(const adouble &a, double v); + inline friend adouble pow(const adouble &a, const adouble &b); + inline friend adouble pow(double v, const adouble &a); + inline friend adouble log10(const adouble &a); + + inline friend adouble sinh(const adouble &a); + inline friend adouble cosh(const adouble &a); + inline friend adouble tanh(const adouble &a); + inline friend adouble asinh(const adouble &a); + inline friend adouble acosh(const adouble &a); + inline friend adouble atanh(const adouble &a); + inline friend adouble fabs(const adouble &a); + inline friend adouble ceil(const adouble &a); + inline friend adouble floor(const adouble &a); + inline friend adouble fmax(const adouble &a, const adouble &b); + inline friend adouble fmax(double v, const adouble &a); + inline friend adouble fmax(const adouble &a, double v); + inline friend adouble fmin(const adouble &a, const adouble &b); + inline friend adouble fmin(double v, const adouble &a); + inline friend adouble fmin(const adouble &a, double v); + inline friend adouble ldexp(const adouble &a, const adouble &b); + inline friend adouble ldexp(const adouble &a, const double v); + inline friend adouble ldexp(const double v, const adouble &a); + inline friend double frexp(const adouble &a, int *v); + inline friend adouble erf(const adouble &a); + inline friend adouble erfc(const adouble &a); + + inline friend void condassign(adouble &res, const adouble &cond, + const adouble &arg1, const adouble &arg2); + inline friend void condassign(adouble &res, const adouble &cond, + const adouble &arg); + inline friend void condeqassign(adouble &res, const adouble &cond, + const adouble &arg1, const adouble &arg2); + inline friend void condeqassign(adouble &res, const adouble &cond, + const adouble &arg); + + /******************* nontemporary results ***************************/ + // assignment + inline adouble &operator=(const double v); + inline adouble &operator=(const adouble &a); + + // addition + inline adouble &operator+=(const double v); + inline adouble &operator+=(const adouble &a); + + // subtraction + inline adouble &operator-=(const double v); + inline adouble &operator-=(const adouble &a); + + // multiplication + inline adouble &operator*=(const double v); + inline adouble &operator*=(const adouble &a); + + // division + inline adouble &operator/=(const double v); + inline adouble &operator/=(const adouble &a); + + // not + inline int operator!() const; + + // comparison + inline int operator!=(const adouble &) const; + inline int operator!=(const double) const; + inline friend int operator!=(const double, const adouble &); + + inline int operator==(const adouble &) const; + inline int operator==(const double) const; + inline friend int operator==(const double, const adouble &); + + inline int operator<=(const adouble &) const; + inline int operator<=(const double) const; + inline friend int operator<=(const double, const adouble &); + + inline int operator>=(const adouble &) const; + inline int operator>=(const double) const; + inline friend int operator>=(const double, const adouble &); + + inline int operator>(const adouble &) const; + inline int operator>(const double) const; + inline friend int operator>(const double, const adouble &); + + inline int operator<(const adouble &) const; + inline int operator<(const double) const; + inline friend int operator<(const double, const adouble &); + + /******************* getter / setter ********************************/ + inline double getValue() const; + inline void setValue(const double v); + + inline explicit operator double const &() const; + inline explicit operator double &&(); + inline explicit operator double(); protected: - inline const list& get_pattern() const; - inline void add_to_pattern(const list& v); - inline size_t get_pattern_size() const; - inline void delete_pattern(); + inline const list &get_pattern() const; + inline void add_to_pattern(const list &v); + inline size_t get_pattern_size() const; + inline void delete_pattern(); public: - friend int ADOLC_Init_sparse_pattern(adouble *a, int n,unsigned int start_cnt); - friend int ADOLC_get_sparse_pattern(const adouble *const b, int m, unsigned int **&pat); - /******************* i/o operations *********************************/ - ADOLC_DLL_EXPORT friend ostream& operator << ( ostream&, const adouble& ); - ADOLC_DLL_EXPORT friend istream& operator >> ( istream&, adouble& ); + friend int ADOLC_Init_sparse_pattern(adouble *a, int n, + unsigned int start_cnt); + friend int ADOLC_get_sparse_pattern(const adouble *const b, int m, + unsigned int **&pat); + /******************* i/o operations *********************************/ + ADOLC_DLL_EXPORT friend ostream &operator<<(ostream &, const adouble &); + ADOLC_DLL_EXPORT friend istream &operator>>(istream &, adouble &); private: - double val; - list pattern; + double val; + list pattern; }; -} +} // namespace adtl_indo #include #include @@ -224,46 +227,46 @@ class adouble { namespace adtl_indo { #if defined(HAVE_BUILTIN_EXPECT) && HAVE_BUILTIN_EXPECT -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) #endif #ifndef likely -#define likely(x) (x) + #define likely(x) (x) #endif #ifndef unlikely -#define unlikely(x) (x) + #define unlikely(x) (x) #endif inline double makeNaN() { - return ADOLC_MATH_NSP::numeric_limits::quiet_NaN(); + return ADOLC_MATH_NSP::numeric_limits::quiet_NaN(); } inline double makeInf() { - return ADOLC_MATH_NSP::numeric_limits::infinity(); + return ADOLC_MATH_NSP::numeric_limits::infinity(); } /******************************* ctors ************************************/ inline adouble::adouble() : val(0) { - if (!pattern.empty()) - pattern.clear(); + if (!pattern.empty()) + pattern.clear(); } inline adouble::adouble(const double v) : val(v) { - if (!pattern.empty()) - pattern.clear(); + if (!pattern.empty()) + pattern.clear(); } -inline adouble::adouble(const double v, const double* adv) : val(v) { - if (!pattern.empty()) - pattern.clear(); +inline adouble::adouble(const double v, const double *adv) : val(v) { + if (!pattern.empty()) + pattern.clear(); } -inline adouble::adouble(const adouble& a) : val(a.val) { - if (!pattern.empty()) - pattern.clear(); +inline adouble::adouble(const adouble &a) : val(a.val) { + if (!pattern.empty()) + pattern.clear(); - add_to_pattern(a.get_pattern()); + add_to_pattern(a.get_pattern()); } /******************************* dtors ************************************/ @@ -276,646 +279,593 @@ inline adouble::~adouble() { /************************* temporary results ******************************/ // sign -inline adouble adouble::operator - () const { - adouble tmp; - tmp.val=-val; - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator-() const { + adouble tmp; + tmp.val = -val; + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator + () const { - return *this; -} +inline adouble adouble::operator+() const { return *this; } // addition -inline adouble adouble::operator + (const double v) const { - adouble tmp(val+v); - tmp.add_to_pattern( get_pattern() ) ; - return tmp; +inline adouble adouble::operator+(const double v) const { + adouble tmp(val + v); + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator + (const adouble& a) const { - adouble tmp; - tmp.val=val+a.val; - tmp.add_to_pattern( get_pattern() ); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble adouble::operator+(const adouble &a) const { + adouble tmp; + tmp.val = val + a.val; + tmp.add_to_pattern(get_pattern()); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble operator + (const double v, const adouble& a) { - adouble tmp(v+a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble operator+(const double v, const adouble &a) { + adouble tmp(v + a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } // subtraction -inline adouble adouble::operator - (const double v) const { - adouble tmp(val-v); - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator-(const double v) const { + adouble tmp(val - v); + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator - (const adouble& a) const { - adouble tmp; - tmp.val=val-a.val; - tmp.add_to_pattern( get_pattern() ); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble adouble::operator-(const adouble &a) const { + adouble tmp; + tmp.val = val - a.val; + tmp.add_to_pattern(get_pattern()); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble operator - (const double v, const adouble& a) { - adouble tmp; - tmp.val=v-a.val; - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble operator-(const double v, const adouble &a) { + adouble tmp; + tmp.val = v - a.val; + tmp.add_to_pattern(a.get_pattern()); + return tmp; } // multiplication -inline adouble adouble::operator * (const double v) const { - adouble tmp; - tmp.val=val*v; - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator*(const double v) const { + adouble tmp; + tmp.val = val * v; + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator * (const adouble& a) const { - adouble tmp; - tmp.val=val*a.val; - tmp.add_to_pattern( get_pattern() ); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble adouble::operator*(const adouble &a) const { + adouble tmp; + tmp.val = val * a.val; + tmp.add_to_pattern(get_pattern()); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble operator * (const double v, const adouble& a) { - adouble tmp; - tmp.val=v*a.val; - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble operator*(const double v, const adouble &a) { + adouble tmp; + tmp.val = v * a.val; + tmp.add_to_pattern(a.get_pattern()); + return tmp; } // division -inline adouble adouble::operator / (const double v) const { - adouble tmp; - tmp.val=val/v; - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator/(const double v) const { + adouble tmp; + tmp.val = val / v; + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator / (const adouble& a) const { - adouble tmp; - tmp.val=val/a.val; - tmp.add_to_pattern( get_pattern() ); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble adouble::operator/(const adouble &a) const { + adouble tmp; + tmp.val = val / a.val; + tmp.add_to_pattern(get_pattern()); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble operator / (const double v, const adouble& a) { - adouble tmp; - tmp.val=v/a.val; - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble operator/(const double v, const adouble &a) { + adouble tmp; + tmp.val = v / a.val; + tmp.add_to_pattern(a.get_pattern()); + return tmp; } // inc/dec -inline adouble adouble::operator ++ () { - ++val; - return *this; +inline adouble adouble::operator++() { + ++val; + return *this; } -inline adouble adouble::operator ++ (int) { - adouble tmp; - tmp.val=val++; - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator++(int) { + adouble tmp; + tmp.val = val++; + tmp.add_to_pattern(get_pattern()); + return tmp; } -inline adouble adouble::operator -- () { - --val; - return *this; +inline adouble adouble::operator--() { + --val; + return *this; } -inline adouble adouble::operator -- (int) { - adouble tmp; - tmp.val=val--; - tmp.add_to_pattern( get_pattern() ); - return tmp; +inline adouble adouble::operator--(int) { + adouble tmp; + tmp.val = val--; + tmp.add_to_pattern(get_pattern()); + return tmp; } // functions -inline adouble tan(const adouble& a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::tan(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble tan(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::tan(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble exp(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::exp(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::exp(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble log(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::log(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::log(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble sqrt(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::sqrt(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::sqrt(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble cbrt(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::cbrt(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::cbrt(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } - - inline adouble sin(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::sin(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble sin(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::sin(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble cos(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::cos(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::cos(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble asin(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::asin(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::asin(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble acos(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::acos(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::acos(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble atan(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::atan(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::atan(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble atan2(const adouble &a, const adouble &b) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::atan2(a.val, b.val); - tmp.add_to_pattern( a.get_pattern() ); - tmp.add_to_pattern( b.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::atan2(a.val, b.val); + tmp.add_to_pattern(a.get_pattern()); + tmp.add_to_pattern(b.get_pattern()); + return tmp; } inline adouble pow(const adouble &a, double v) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::pow(a.val, v); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::pow(a.val, v); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble pow(const adouble &a, const adouble &b) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::pow(a.val, b.val); - tmp.add_to_pattern( a.get_pattern() ); - tmp.add_to_pattern( b.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::pow(a.val, b.val); + tmp.add_to_pattern(a.get_pattern()); + tmp.add_to_pattern(b.get_pattern()); + return tmp; } inline adouble pow(double v, const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::pow(v, a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::pow(v, a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } inline adouble log10(const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::log10(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; + adouble tmp; + tmp.val = ADOLC_MATH_NSP::log10(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble sinh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::sinh(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble sinh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::sinh(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble cosh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::cosh(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble cosh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::cosh(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble tanh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::tanh(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble tanh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::tanh(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble asinh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::asinh(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble asinh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::asinh(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble acosh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::acosh(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble acosh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::acosh(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble atanh (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::atanh(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble atanh(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::atanh(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble fabs (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::fabs(a.val); - tmp.add_to_pattern( a.get_pattern() ); - return tmp; +inline adouble fabs(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::fabs(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble ceil (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::ceil(a.val); - return tmp; +inline adouble ceil(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::ceil(a.val); + return tmp; } -inline adouble floor (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP::floor(a.val); - return tmp; +inline adouble floor(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP::floor(a.val); + return tmp; } -inline adouble fmax (const adouble &a, const adouble &b) { - adouble tmp; - double tmp2=a.val-b.val; - if (tmp2<0) { - tmp.val=b.val; - tmp.add_to_pattern( b.get_pattern() ); +inline adouble fmax(const adouble &a, const adouble &b) { + adouble tmp; + double tmp2 = a.val - b.val; + if (tmp2 < 0) { + tmp.val = b.val; + tmp.add_to_pattern(b.get_pattern()); + } else { + tmp.val = a.val; + if (tmp2 > 0) { + tmp.add_to_pattern(a.get_pattern()); } else { - tmp.val=a.val; - if (tmp2>0) { - tmp.add_to_pattern( a.get_pattern() ); - } else { - tmp.add_to_pattern( a.get_pattern() ); - tmp.add_to_pattern( b.get_pattern() ); - } + tmp.add_to_pattern(a.get_pattern()); + tmp.add_to_pattern(b.get_pattern()); } - return tmp; -} - -inline adouble fmax (double v, const adouble &a) { - adouble tmp; - double tmp2=v-a.val; - if (tmp2<0) { - tmp.val=a.val; - tmp.add_to_pattern( a.get_pattern() ); + } + return tmp; +} + +inline adouble fmax(double v, const adouble &a) { + adouble tmp; + double tmp2 = v - a.val; + if (tmp2 < 0) { + tmp.val = a.val; + tmp.add_to_pattern(a.get_pattern()); + } else { + tmp.val = v; + if (tmp2 > 0) { } else { - tmp.val=v; - if (tmp2>0) { - } else { - tmp.add_to_pattern( a.get_pattern() ); - } + tmp.add_to_pattern(a.get_pattern()); } - return tmp; -} - -inline adouble fmax (const adouble &a, double v) { - adouble tmp; - double tmp2=a.val-v; - if (tmp2<0) { - tmp.val=v; + } + return tmp; +} + +inline adouble fmax(const adouble &a, double v) { + adouble tmp; + double tmp2 = a.val - v; + if (tmp2 < 0) { + tmp.val = v; + } else { + tmp.val = a.val; + tmp.add_to_pattern(a.get_pattern()); + } + return tmp; +} + +inline adouble fmin(const adouble &a, const adouble &b) { + adouble tmp; + double tmp2 = a.val - b.val; + if (tmp2 < 0) { + tmp.val = a.val; + tmp.add_to_pattern(a.get_pattern()); + } else { + tmp.val = b.val; + if (tmp2 > 0) { + tmp.add_to_pattern(b.get_pattern()); } else { - tmp.val=a.val; - tmp.add_to_pattern( a.get_pattern() ); + tmp.add_to_pattern(a.get_pattern()); + tmp.add_to_pattern(b.get_pattern()); } - return tmp; -} - -inline adouble fmin (const adouble &a, const adouble &b) { - adouble tmp; - double tmp2=a.val-b.val; - if (tmp2<0) { - tmp.val=a.val; - tmp.add_to_pattern( a.get_pattern() ); - } else { - tmp.val=b.val; - if (tmp2>0) { - tmp.add_to_pattern( b.get_pattern() ); - } else { - tmp.add_to_pattern( a.get_pattern() ); - tmp.add_to_pattern( b.get_pattern() ); - } - } - return tmp; -} - -inline adouble fmin (double v, const adouble &a) { - adouble tmp; - double tmp2=v-a.val; - if (tmp2<0) { - tmp.val=v; - } else { - tmp.val=a.val; - tmp.add_to_pattern( a.get_pattern() ); - } - return tmp; -} - -inline adouble fmin (const adouble &a, double v) { - adouble tmp; - double tmp2=a.val-v; - if (tmp2<0) { - tmp.val=a.val; - tmp.add_to_pattern( a.get_pattern() ); + } + return tmp; +} + +inline adouble fmin(double v, const adouble &a) { + adouble tmp; + double tmp2 = v - a.val; + if (tmp2 < 0) { + tmp.val = v; + } else { + tmp.val = a.val; + tmp.add_to_pattern(a.get_pattern()); + } + return tmp; +} + +inline adouble fmin(const adouble &a, double v) { + adouble tmp; + double tmp2 = a.val - v; + if (tmp2 < 0) { + tmp.val = a.val; + tmp.add_to_pattern(a.get_pattern()); + } else { + tmp.val = v; + if (tmp2 > 0) { } else { - tmp.val=v; - if (tmp2>0) { - } else { - tmp.add_to_pattern( a.get_pattern() ); - } + tmp.add_to_pattern(a.get_pattern()); } - return tmp; + } + return tmp; } -inline adouble ldexp (const adouble &a, const adouble &b) { - adouble tmp = a*pow(2.,b); - tmp.add_to_pattern( a.get_pattern() ) ; - tmp.add_to_pattern( b.get_pattern() ) ; - return tmp; +inline adouble ldexp(const adouble &a, const adouble &b) { + adouble tmp = a * pow(2., b); + tmp.add_to_pattern(a.get_pattern()); + tmp.add_to_pattern(b.get_pattern()); + return tmp; } -inline adouble ldexp (const adouble &a, const double v) { - return a*ADOLC_MATH_NSP::pow(2.,v); +inline adouble ldexp(const adouble &a, const double v) { + return a * ADOLC_MATH_NSP::pow(2., v); } -inline adouble ldexp (const double v, const adouble &a) { - adouble tmp = v*pow(2.,a); - tmp.add_to_pattern( a.get_pattern() ) ; - return tmp; +inline adouble ldexp(const double v, const adouble &a) { + adouble tmp = v * pow(2., a); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline double frexp (const adouble &a, int* v) { - return ADOLC_MATH_NSP::frexp(a.val, v); +inline double frexp(const adouble &a, int *v) { + return ADOLC_MATH_NSP::frexp(a.val, v); } -inline adouble erf (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::erf(a.val); - tmp.add_to_pattern( a.get_pattern() ) ; - return tmp; +inline adouble erf(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::erf(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline adouble erfc (const adouble &a) { - adouble tmp; - tmp.val=ADOLC_MATH_NSP_ERF::erfc(a.val); - tmp.add_to_pattern( a.get_pattern() ) ; - return tmp; +inline adouble erfc(const adouble &a) { + adouble tmp; + tmp.val = ADOLC_MATH_NSP_ERF::erfc(a.val); + tmp.add_to_pattern(a.get_pattern()); + return tmp; } -inline void condassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ) { - if (cond.getValue() > 0) - res = arg1; - else - res = arg2; +inline void condassign(adouble &res, const adouble &cond, const adouble &arg1, + const adouble &arg2) { + if (cond.getValue() > 0) + res = arg1; + else + res = arg2; } -inline void condassign( adouble &res, const adouble &cond, - const adouble &arg ) { - if (cond.getValue() > 0) - res = arg; +inline void condassign(adouble &res, const adouble &cond, const adouble &arg) { + if (cond.getValue() > 0) + res = arg; } -inline void condeqassign( adouble &res, const adouble &cond, - const adouble &arg1, const adouble &arg2 ) { - if (cond.getValue() >= 0) - res = arg1; - else - res = arg2; +inline void condeqassign(adouble &res, const adouble &cond, const adouble &arg1, + const adouble &arg2) { + if (cond.getValue() >= 0) + res = arg1; + else + res = arg2; } -inline void condeqassign( adouble &res, const adouble &cond, - const adouble &arg ) { - if (cond.getValue() >= 0) - res = arg; +inline void condeqassign(adouble &res, const adouble &cond, + const adouble &arg) { + if (cond.getValue() >= 0) + res = arg; } - - /******************* nontemporary results *********************************/ -inline adouble& adouble::operator = (const double v) { - val=v; - if (!pattern.empty()) pattern.clear(); - return *this; +inline adouble &adouble::operator=(const double v) { + val = v; + if (!pattern.empty()) + pattern.clear(); + return *this; } -inline adouble& adouble::operator = (const adouble& a) { - val=a.val; - if (!pattern.empty()) pattern.clear(); - add_to_pattern( a.get_pattern() ); - return *this; +inline adouble &adouble::operator=(const adouble &a) { + val = a.val; + if (!pattern.empty()) + pattern.clear(); + add_to_pattern(a.get_pattern()); + return *this; } -inline adouble& adouble::operator += (const double v) { - val+=v; - return *this; +inline adouble &adouble::operator+=(const double v) { + val += v; + return *this; } -inline adouble& adouble::operator += (const adouble& a) { - val=val+a.val; - add_to_pattern( a.get_pattern() ); - return *this; +inline adouble &adouble::operator+=(const adouble &a) { + val = val + a.val; + add_to_pattern(a.get_pattern()); + return *this; } -inline adouble& adouble::operator -= (const double v) { - val-=v; - return *this; +inline adouble &adouble::operator-=(const double v) { + val -= v; + return *this; } -inline adouble& adouble::operator -= (const adouble& a) { - val=val-a.val; - add_to_pattern( a.get_pattern() ) ; - return *this; +inline adouble &adouble::operator-=(const adouble &a) { + val = val - a.val; + add_to_pattern(a.get_pattern()); + return *this; } -inline adouble& adouble::operator *= (const double v) { - val=val*v; - return *this; +inline adouble &adouble::operator*=(const double v) { + val = val * v; + return *this; } -inline adouble& adouble::operator *= (const adouble& a) { - val*=a.val; - add_to_pattern( a.get_pattern() ) ; - return *this; +inline adouble &adouble::operator*=(const adouble &a) { + val *= a.val; + add_to_pattern(a.get_pattern()); + return *this; } -inline adouble& adouble::operator /= (const double v) { - val/=v; - return *this; +inline adouble &adouble::operator/=(const double v) { + val /= v; + return *this; } -inline adouble& adouble::operator /= (const adouble& a) { - val=val/a.val; - add_to_pattern( a.get_pattern() ) ; - return *this; +inline adouble &adouble::operator/=(const adouble &a) { + val = val / a.val; + add_to_pattern(a.get_pattern()); + return *this; } // not -inline int adouble::operator ! () const { - return val==0.0; -} +inline int adouble::operator!() const { return val == 0.0; } // comparison -inline int adouble::operator != (const adouble &a) const { - return val!=a.val; -} +inline int adouble::operator!=(const adouble &a) const { return val != a.val; } -inline int adouble::operator != (const double v) const { - return val!=v; -} +inline int adouble::operator!=(const double v) const { return val != v; } -inline int operator != (const double v, const adouble &a) { - return v!=a.val; -} +inline int operator!=(const double v, const adouble &a) { return v != a.val; } -inline int adouble::operator == (const adouble &a) const { - return val==a.val; -} +inline int adouble::operator==(const adouble &a) const { return val == a.val; } -inline int adouble::operator == (const double v) const { - return val==v; -} +inline int adouble::operator==(const double v) const { return val == v; } -inline int operator == (const double v, const adouble &a) { - return v==a.val; -} +inline int operator==(const double v, const adouble &a) { return v == a.val; } -inline int adouble::operator <= (const adouble &a) const { - return val<=a.val; -} +inline int adouble::operator<=(const adouble &a) const { return val <= a.val; } -inline int adouble::operator <= (const double v) const { - return val<=v; -} +inline int adouble::operator<=(const double v) const { return val <= v; } -inline int operator <= (const double v, const adouble &a) { - return v<=a.val; -} +inline int operator<=(const double v, const adouble &a) { return v <= a.val; } -inline int adouble::operator >= (const adouble &a) const { - return val>=a.val; -} +inline int adouble::operator>=(const adouble &a) const { return val >= a.val; } -inline int adouble::operator >= (const double v) const { - return val>=v; -} +inline int adouble::operator>=(const double v) const { return val >= v; } -inline int operator >= (const double v, const adouble &a) { - return v>=a.val; -} +inline int operator>=(const double v, const adouble &a) { return v >= a.val; } -inline int adouble::operator > (const adouble &a) const { - return val>a.val; -} +inline int adouble::operator>(const adouble &a) const { return val > a.val; } -inline int adouble::operator > (const double v) const { - return val>v; -} +inline int adouble::operator>(const double v) const { return val > v; } -inline int operator > (const double v, const adouble &a) { - return v>a.val; -} +inline int operator>(const double v, const adouble &a) { return v > a.val; } -inline int adouble::operator < (const adouble &a) const { - return val& adouble::get_pattern() const { - return pattern; +inline const list &adouble::get_pattern() const { + return pattern; } inline void adouble::delete_pattern() { - if ( !pattern.empty() ) - pattern.clear(); -} - -inline void adouble::add_to_pattern(const list& v) { - if (likely( pattern != v)) { - if( !v.empty() ){ - list cv = v; - //pattern.splice(pattern.end(), cv); - pattern.merge(cv); - //if (pattern.size() > refcounter::refcnt) { - //pattern.sort(); - pattern.unique(); - //} - } + if (!pattern.empty()) + pattern.clear(); +} + +inline void adouble::add_to_pattern(const list &v) { + if (likely(pattern != v)) { + if (!v.empty()) { + list cv = v; + // pattern.splice(pattern.end(), cv); + pattern.merge(cv); + // if (pattern.size() > refcounter::refcnt) { + // pattern.sort(); + pattern.unique(); + //} } + } } inline size_t adouble::get_pattern_size() const { - size_t s=0; - if( !pattern.empty() ) - s = pattern.size(); - return s; + size_t s = 0; + if (!pattern.empty()) + s = pattern.size(); + return s; } -} +} // namespace adtl_indo #endif diff --git a/ADOL-C/include/adolc/adutils.h b/ADOL-C/include/adolc/adutils.h index a0da3827d..366487c4d 100644 --- a/ADOL-C/include/adolc/adutils.h +++ b/ADOL-C/include/adolc/adutils.h @@ -3,21 +3,20 @@ File: adutils.h Revision: $Id$ Contents: Provides all C/C++ interfaces of ADOL-C. - NOTICE: This file is kept for compatibility reasons only. + NOTICE: This file is kept for compatibility reasons only. The new header adolc.h is included. - + Copyright (c) Andreas Kowarz - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_ADUTILS_H) -#define ADOLC_ADUTILS_H 1 + #define ADOLC_ADUTILS_H 1 -#include + #include #endif - diff --git a/ADOL-C/include/adolc/adutilsc.h b/ADOL-C/include/adolc/adutilsc.h index 63af5c906..de277a598 100644 --- a/ADOL-C/include/adolc/adutilsc.h +++ b/ADOL-C/include/adolc/adutilsc.h @@ -3,21 +3,21 @@ File: adutilsc.h Revision: $Id$ Contents: Provides all C/C++ interfaces of ADOL-C. - NOTICE: This file is kept for compatibility reasons only. + NOTICE: This file is kept for compatibility reasons only. The new header adolc.h is included. - + Copyright (c) Andreas Kowarz - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_ADUTILSC_H) -#define ADOLC_ADUTILSC_H 1 + #define ADOLC_ADUTILSC_H 1 -#include + #include #endif diff --git a/ADOL-C/include/adolc/advector.h b/ADOL-C/include/adolc/advector.h index 99df6f82d..d0d6b7dad 100644 --- a/ADOL-C/include/adolc/advector.h +++ b/ADOL-C/include/adolc/advector.h @@ -8,170 +8,185 @@ Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ---------------------------------------------------------------------------*/ #if !defined(ADOLC_ADVECTOR_H) -#define ADOLC_ADVECTOR_H 1 + #define ADOLC_ADVECTOR_H 1 -/****************************************************************************/ -/* THIS FILE IS C++ */ -#ifdef __cplusplus -#include + /****************************************************************************/ + /* THIS FILE IS C++ */ + #ifdef __cplusplus + #include -/****************************************************************************/ -/* THIS IS ONLY FOR TAPED VERSION */ -#if !defined(TAPELESS) + /****************************************************************************/ + /* THIS IS ONLY FOR TAPED VERSION + */ + #if !defined(TAPELESS) class advector; class adubref; class ADOLC_DLL_EXPORT adubref { - /* This class is supposed to be used only when an advector subscript - * occurs as an lvalue somewhere. What we need to do is read the location - * of the referenced adouble out of store[location] and perform - * operations with this refloc. This means that the tape needs new - * opcodes (ref_assign_* /ref_eq_* / ref_{incr,decr}_a) for each of - * these operations, most of the code will simply be copied from - * adouble class, since the operation is really the same except for - * the part where the refloc is read from store[location]. - * Reverse mode is also straightforward the same way. - * - * Convert to a new adub as soon as used as rvalue, this is why adubref - * is not a child of badouble, since it should never occur as rvalue. - */ - friend ADOLC_DLL_EXPORT class adub; - friend ADOLC_DLL_EXPORT class advector; - friend ADOLC_DLL_EXPORT class pdouble; + /* This class is supposed to be used only when an advector subscript + * occurs as an lvalue somewhere. What we need to do is read the location + * of the referenced adouble out of store[location] and perform + * operations with this refloc. This means that the tape needs new + * opcodes (ref_assign_* /ref_eq_* / ref_{incr,decr}_a) for each of + * these operations, most of the code will simply be copied from + * adouble class, since the operation is really the same except for + * the part where the refloc is read from store[location]. + * Reverse mode is also straightforward the same way. + * + * Convert to a new adub as soon as used as rvalue, this is why adubref + * is not a child of badouble, since it should never occur as rvalue. + */ + friend ADOLC_DLL_EXPORT class adub; + friend ADOLC_DLL_EXPORT class advector; + friend ADOLC_DLL_EXPORT class pdouble; + protected: - locint location; - locint refloc; - explicit adubref( locint lo, locint ref ); - explicit adubref( void ) { - fprintf(DIAG_OUT,"ADOL-C error: illegal default construction of adubref" - " variable\n"); - exit(-2); - } - explicit adubref( double ) { - fprintf(DIAG_OUT,"ADOL-C error: illegal construction of adubref" - " variable from double\n"); - exit(-2); - } - explicit adubref( const badouble& ) { - fprintf(DIAG_OUT,"ADOL-C error: illegal construction of adubref" - " variable from badouble\n"); - exit(-2); - } - explicit adubref( const adub& ) { - fprintf(DIAG_OUT,"ADOL-C error: illegal construction of adubref" - " variable from adub\n"); - exit(-2); - } - adubref( const adubref& ) { - fprintf(DIAG_OUT,"ADOL-C error: illegal copy construction of adubref" - " variable\n"); - exit(-2); - } - bool isInit; // marker if the badouble is properly initialized + locint location; + locint refloc; + explicit adubref(locint lo, locint ref); + explicit adubref(void) { + fprintf(DIAG_OUT, "ADOL-C error: illegal default construction of adubref" + " variable\n"); + exit(-2); + } + explicit adubref(double) { + fprintf(DIAG_OUT, "ADOL-C error: illegal construction of adubref" + " variable from double\n"); + exit(-2); + } + explicit adubref(const badouble &) { + fprintf(DIAG_OUT, "ADOL-C error: illegal construction of adubref" + " variable from badouble\n"); + exit(-2); + } + explicit adubref(const adub &) { + fprintf(DIAG_OUT, "ADOL-C error: illegal construction of adubref" + " variable from adub\n"); + exit(-2); + } + adubref(const adubref &) { + fprintf(DIAG_OUT, "ADOL-C error: illegal copy construction of adubref" + " variable\n"); + exit(-2); + } + bool isInit; // marker if the badouble is properly initialized public: - /* adub prevents postfix operators to occur on the left - side of an assignment which would not work */ -#if !defined(SWIGPRE) - adub operator++( int ); - adub operator--( int ); -#else - adub* operator++( int ); - adub* operator--( int ); -#endif - adubref& operator++( void ); - adubref& operator--( void ); - adubref& operator = ( double ); - adubref& operator = ( const badouble& ); - adubref& operator = ( const adubref& ); - adubref& operator = ( const pdouble& ); - adubref& operator += ( double ); - adubref& operator += ( const badouble& ); - adubref& operator += ( const pdouble& ); - adubref& operator -= ( double x ); - adubref& operator -= ( const badouble& ); - adubref& operator -= ( const pdouble& ); - adubref& operator *= ( double x ); - adubref& operator *= ( const badouble& ); - adubref& operator *= ( const pdouble& ); - inline adubref& operator /= ( double x ); - inline adubref& operator /= ( const badouble& ); - inline adubref& operator /= ( const pdouble&); - - adubref& operator <<= ( double ); - void declareIndependent(); - adubref& operator >>= ( double& ); - void declareDependent(); - operator adub() const; -#if !defined(SWIGPRE) - explicit operator adubref*() const; -#endif - friend ADOLC_DLL_EXPORT void condassign(adubref&, const badouble&, const badouble&, const badouble&); - friend ADOLC_DLL_EXPORT void condassign(adubref&, const badouble&, const badouble&); - friend ADOLC_DLL_EXPORT void condeqassign(adubref&, const badouble&, const badouble&, const badouble&); - friend ADOLC_DLL_EXPORT void condeqassign(adubref&, const badouble&, const badouble&); - ~adubref(); + /* adub prevents postfix operators to occur on the left + side of an assignment which would not work */ + #if !defined(SWIGPRE) + adub operator++(int); + adub operator--(int); + #else + adub *operator++(int); + adub *operator--(int); + #endif + adubref &operator++(void); + adubref &operator--(void); + adubref &operator=(double); + adubref &operator=(const badouble &); + adubref &operator=(const adubref &); + adubref &operator=(const pdouble &); + adubref &operator+=(double); + adubref &operator+=(const badouble &); + adubref &operator+=(const pdouble &); + adubref &operator-=(double x); + adubref &operator-=(const badouble &); + adubref &operator-=(const pdouble &); + adubref &operator*=(double x); + adubref &operator*=(const badouble &); + adubref &operator*=(const pdouble &); + inline adubref &operator/=(double x); + inline adubref &operator/=(const badouble &); + inline adubref &operator/=(const pdouble &); + + adubref &operator<<=(double); + void declareIndependent(); + adubref &operator>>=(double &); + void declareDependent(); + operator adub() const; + #if !defined(SWIGPRE) + explicit operator adubref *() const; + #endif + friend ADOLC_DLL_EXPORT void condassign(adubref &, const badouble &, + const badouble &, const badouble &); + friend ADOLC_DLL_EXPORT void condassign(adubref &, const badouble &, + const badouble &); + friend ADOLC_DLL_EXPORT void condeqassign(adubref &, const badouble &, + const badouble &, const badouble &); + friend ADOLC_DLL_EXPORT void condeqassign(adubref &, const badouble &, + const badouble &); + ~adubref(); }; /* adolc_vec_copy(dest,src,size); */ -void ADOLC_DLL_EXPORT adolc_vec_copy(adouble *const, const adouble*const, locint); +void ADOLC_DLL_EXPORT adolc_vec_copy(adouble *const, const adouble *const, + locint); /* adolc_vec_axpy(res,a,x,y,size); <=> res = a*x + y */ -void ADOLC_DLL_EXPORT adolc_vec_axpy(adouble *const, const badouble&, const adouble*const, const adouble*const, locint); +void ADOLC_DLL_EXPORT adolc_vec_axpy(adouble *const, const badouble &, + const adouble *const, const adouble *const, + locint); class advector { private: - struct ADOLC_DLL_EXPORT blocker { - blocker() {} - blocker(size_t n); - ~blocker() {} - } blk; - std::vector data; - ADOLC_DLL_EXPORT bool nondecreasing() const; + struct ADOLC_DLL_EXPORT blocker { + blocker() {} + blocker(size_t n); + ~blocker() {} + } blk; + std::vector data; + ADOLC_DLL_EXPORT bool nondecreasing() const; + public: - ADOLC_DLL_EXPORT advector() : blk(), data() {} - ADOLC_DLL_EXPORT explicit advector(size_t n) : blk(n), data(n) {} - ADOLC_DLL_EXPORT ~advector() {} - ADOLC_DLL_EXPORT advector(const advector& x) : blk(x.size()), data(x.size()) { adolc_vec_copy(data.data(),x.data.data(),x.size()); } - // in the above copy we are sure of contiguous locations - // but not so in the one below - ADOLC_DLL_EXPORT advector(const std::vector& v) : blk(v.size()), data(v) {} - ADOLC_DLL_EXPORT size_t size() const { return data.size(); } - ADOLC_DLL_EXPORT operator const std::vector&() const { return data; } - ADOLC_DLL_EXPORT operator std::vector&() { return data; } - ADOLC_DLL_EXPORT operator adouble*() { return data.data(); } -#if !defined(SWIGPRE) - ADOLC_DLL_EXPORT adub operator[](const badouble& index) const; - ADOLC_DLL_EXPORT adubref operator[](const badouble& index); -#else - ADOLC_DLL_EXPORT adub* operator[](const badouble& index) const; - ADOLC_DLL_EXPORT adubref* operator[](const badouble& index); -#endif - ADOLC_DLL_EXPORT adouble& operator[](size_t i) { return data[i]; } - ADOLC_DLL_EXPORT const adouble& operator[](size_t i) const { return data[i]; } - ADOLC_DLL_EXPORT adouble lookupindex(const badouble& x, const badouble& y) const; + ADOLC_DLL_EXPORT advector() : blk(), data() {} + ADOLC_DLL_EXPORT explicit advector(size_t n) : blk(n), data(n) {} + ADOLC_DLL_EXPORT ~advector() {} + ADOLC_DLL_EXPORT advector(const advector &x) : blk(x.size()), data(x.size()) { + adolc_vec_copy(data.data(), x.data.data(), x.size()); + } + // in the above copy we are sure of contiguous locations + // but not so in the one below + ADOLC_DLL_EXPORT advector(const std::vector &v) + : blk(v.size()), data(v) {} + ADOLC_DLL_EXPORT size_t size() const { return data.size(); } + ADOLC_DLL_EXPORT operator const std::vector &() const { + return data; + } + ADOLC_DLL_EXPORT operator std::vector &() { return data; } + ADOLC_DLL_EXPORT operator adouble *() { return data.data(); } + #if !defined(SWIGPRE) + ADOLC_DLL_EXPORT adub operator[](const badouble &index) const; + ADOLC_DLL_EXPORT adubref operator[](const badouble &index); + #else + ADOLC_DLL_EXPORT adub *operator[](const badouble &index) const; + ADOLC_DLL_EXPORT adubref *operator[](const badouble &index); + #endif + ADOLC_DLL_EXPORT adouble &operator[](size_t i) { return data[i]; } + ADOLC_DLL_EXPORT const adouble &operator[](size_t i) const { return data[i]; } + ADOLC_DLL_EXPORT adouble lookupindex(const badouble &x, + const badouble &y) const; }; -inline adubref& adubref::operator /= (double y) { - *this *= (1.0/y); - return *this; +inline adubref &adubref::operator/=(double y) { + *this *= (1.0 / y); + return *this; } - -inline adubref& adubref::operator /= (const badouble& y) { - *this *= (1.0/y); - return *this; +inline adubref &adubref::operator/=(const badouble &y) { + *this *= (1.0 / y); + return *this; } -inline adubref& adubref::operator /= (const pdouble& p) { - *this *= recipr(p); - return *this; +inline adubref &adubref::operator/=(const pdouble &p) { + *this *= recipr(p); + return *this; } -#endif /* TAPELESS */ -#endif /* __cplusplus */ -#endif /* ADOLC_ADVECTOR_H */ + #endif /* TAPELESS */ + #endif /* __cplusplus */ +#endif /* ADOLC_ADVECTOR_H */ diff --git a/ADOL-C/include/adolc/checkpointing.h b/ADOL-C/include/adolc/checkpointing.h index ed9526879..ad0225fed 100644 --- a/ADOL-C/include/adolc/checkpointing.h +++ b/ADOL-C/include/adolc/checkpointing.h @@ -3,64 +3,64 @@ File: checkpointing.h Revision: $Id$ Contents: Provides all checkointing interfaces. - + Copyright (c) Andreas Kowarz - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_CHECKPOINTING_H) -#define ADOLC_CHECKPOINTING_H 1 + #define ADOLC_CHECKPOINTING_H 1 -#include -#include + #include + #include -#if defined(__cplusplus) + #if defined(__cplusplus) /****************************************************************************/ /* This is all C++ */ -typedef int (*ADOLC_TimeStepFuncion) (int n, adouble *x); -typedef int (*ADOLC_TimeStepFuncion_double) (int n, double *x); -typedef void *(*ADOLC_saveFct) (); -typedef void (*ADOLC_restoreFct) (void *); +typedef int (*ADOLC_TimeStepFuncion)(int n, adouble *x); +typedef int (*ADOLC_TimeStepFuncion_double)(int n, double *x); +typedef void *(*ADOLC_saveFct)(); +typedef void (*ADOLC_restoreFct)(void *); typedef struct CpInfos { - ADOLC_TimeStepFuncion function; - ADOLC_TimeStepFuncion_double function_double; - ADOLC_saveFct saveNonAdoubles; - ADOLC_restoreFct restoreNonAdoubles; - int steps; - int checkpoints; - int tapeNumber; /* tape number to be used for checkpointing */ - int retaping; /* != 0 forces retaping before every reverse step */ - - int n; /* number of variables in input and output (n=m) */ - adouble *adp_x; /* input of the first step */ - adouble *adp_y; /* output of the last step; will be set by ADOLC */ - - /* these are internal checkpointing variables => do not use */ - int check; - int capo; - int fine; - int info; - int currentCP; - double *dp_internal_for; - double *dp_internal_rev; - double **dpp_internal_rev; - locint index; /* please do not change */ - char modeForward; - char modeReverse; - char *allmem; /* this is dummy to get externfcts and checkpointing both use buffer_temp without a problem */ -} -CpInfos; + ADOLC_TimeStepFuncion function; + ADOLC_TimeStepFuncion_double function_double; + ADOLC_saveFct saveNonAdoubles; + ADOLC_restoreFct restoreNonAdoubles; + int steps; + int checkpoints; + int tapeNumber; /* tape number to be used for checkpointing */ + int retaping; /* != 0 forces retaping before every reverse step */ + + int n; /* number of variables in input and output (n=m) */ + adouble *adp_x; /* input of the first step */ + adouble *adp_y; /* output of the last step; will be set by ADOLC */ + + /* these are internal checkpointing variables => do not use */ + int check; + int capo; + int fine; + int info; + int currentCP; + double *dp_internal_for; + double *dp_internal_rev; + double **dpp_internal_rev; + locint index; /* please do not change */ + char modeForward; + char modeReverse; + char *allmem; /* this is dummy to get externfcts and checkpointing both use + buffer_temp without a problem */ +} CpInfos; ADOLC_DLL_EXPORT CpInfos *reg_timestep_fct(ADOLC_TimeStepFuncion timeStepFunction); -ADOLC_DLL_EXPORT int checkpointing (CpInfos *cpInfos); +ADOLC_DLL_EXPORT int checkpointing(CpInfos *cpInfos); /* if tape with one program and use the tapes with another program call this * function within the latter */ @@ -68,79 +68,68 @@ ADOLC_DLL_EXPORT void reinit_checkpointing(); class CP_Context { public: - inline CP_Context(ADOLC_TimeStepFuncion tsf); - inline ~CP_Context() {} - - inline void setDoubleFct(ADOLC_TimeStepFuncion_double tsf); - inline void setSaveFct(ADOLC_saveFct sf); - inline void setRestoreFct(ADOLC_restoreFct rf); - inline void setNumberOfSteps(int number); - inline void setNumberOfCheckpoints(int number); - inline void setTapeNumber(int tapeNumber); - inline void setDimensionXY(int n); - inline void setInput(adouble *x); - inline void setOutput(adouble *y); - inline void setAlwaysRetaping(bool state); - - inline int checkpointing(); + inline CP_Context(ADOLC_TimeStepFuncion tsf); + inline ~CP_Context() {} + + inline void setDoubleFct(ADOLC_TimeStepFuncion_double tsf); + inline void setSaveFct(ADOLC_saveFct sf); + inline void setRestoreFct(ADOLC_restoreFct rf); + inline void setNumberOfSteps(int number); + inline void setNumberOfCheckpoints(int number); + inline void setTapeNumber(int tapeNumber); + inline void setDimensionXY(int n); + inline void setInput(adouble *x); + inline void setOutput(adouble *y); + inline void setAlwaysRetaping(bool state); + + inline int checkpointing(); private: - inline CP_Context() {} + inline CP_Context() {} - CpInfos *cpInfos; + CpInfos *cpInfos; }; CP_Context::CP_Context(ADOLC_TimeStepFuncion tsf) { - cpInfos = reg_timestep_fct(tsf); + cpInfos = reg_timestep_fct(tsf); } void CP_Context::setDoubleFct(ADOLC_TimeStepFuncion_double tsf) { - cpInfos->function_double = tsf; + cpInfos->function_double = tsf; } -void CP_Context::setSaveFct(ADOLC_saveFct sf) { - cpInfos->saveNonAdoubles = sf; -} +void CP_Context::setSaveFct(ADOLC_saveFct sf) { cpInfos->saveNonAdoubles = sf; } void CP_Context::setRestoreFct(ADOLC_restoreFct rf) { - cpInfos->restoreNonAdoubles = rf; + cpInfos->restoreNonAdoubles = rf; } -void CP_Context::setNumberOfSteps(int number) { - cpInfos->steps = number; -} +void CP_Context::setNumberOfSteps(int number) { cpInfos->steps = number; } void CP_Context::setNumberOfCheckpoints(int number) { - cpInfos->checkpoints = number; + cpInfos->checkpoints = number; } void CP_Context::setTapeNumber(int tapeNumber) { - cpInfos->tapeNumber = tapeNumber; + cpInfos->tapeNumber = tapeNumber; } -void CP_Context::setDimensionXY(int n) { - cpInfos->n = n; -} +void CP_Context::setDimensionXY(int n) { cpInfos->n = n; } -void CP_Context::setInput(adouble *x) { - cpInfos->adp_x = x; -} +void CP_Context::setInput(adouble *x) { cpInfos->adp_x = x; } -void CP_Context::setOutput(adouble *y) { - cpInfos->adp_y = y; -} +void CP_Context::setOutput(adouble *y) { cpInfos->adp_y = y; } void CP_Context::setAlwaysRetaping(bool state) { - if (state) cpInfos->retaping = 1; - else cpInfos->retaping = 0; + if (state) + cpInfos->retaping = 1; + else + cpInfos->retaping = 0; } -int CP_Context::checkpointing() { - return ::checkpointing(cpInfos); -} +int CP_Context::checkpointing() { return ::checkpointing(cpInfos); } -#endif /* CPLUSPLUS */ + #endif /* CPLUSPLUS */ /****************************************************************************/ #endif /* ADOLC_CHECKPOINTING_H */ - diff --git a/ADOL-C/include/adolc/convolut.h b/ADOL-C/include/adolc/convolut.h index d4e4432c3..fd6e05294 100644 --- a/ADOL-C/include/adolc/convolut.h +++ b/ADOL-C/include/adolc/convolut.h @@ -3,20 +3,20 @@ File: convolut.h Revision: $Id$ Contents: Convolution routines (used by ho_rev.mc) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ #if !defined(ADOLC_CONVOLUT_H) -#define ADOLC_CONVOLUT_H 1 + #define ADOLC_CONVOLUT_H 1 -#include + #include BEGIN_C_DECLS @@ -25,56 +25,52 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* Evaluates convolution of a and b to c */ -void conv( int dim, revreal *a, revreal *b, revreal *c ); -void conv0( int dim, revreal *a, revreal *b, revreal *c ); +void conv(int dim, revreal *a, revreal *b, revreal *c); +void conv0(int dim, revreal *a, revreal *b, revreal *c); /****************************************************************************/ /* INCREMENTAL CONVOLUTION */ /*--------------------------------------------------------------------------*/ /* Increments truncated convolution of a and b to c */ -void inconv ( int dim, revreal *a, revreal *b, revreal* c ); +void inconv(int dim, revreal *a, revreal *b, revreal *c); /*--------------------------------------------------------------------------*/ /* Increments truncated convolution of a and b to c and sets a to zero */ -void inconv0( int dim, revreal *a, revreal *b, revreal* c ); -void inconv1( int dim, revreal *a, revreal *b, revreal* c ); - +void inconv0(int dim, revreal *a, revreal *b, revreal *c); +void inconv1(int dim, revreal *a, revreal *b, revreal *c); /****************************************************************************/ /* DECREMENTAL CONVOLUTION */ /*--------------------------------------------------------------------------*/ /* Decrements truncated convolution of a and b to c */ -void deconv ( int dim, revreal* a, revreal *b, revreal* c ); +void deconv(int dim, revreal *a, revreal *b, revreal *c); /*--------------------------------------------------------------------------*/ /* Decrements truncated convolution of a and b to c and sets a to zero */ -void deconv0( int dim, revreal* a, revreal *b, revreal* c ); -void deconv1( int dim, revreal* a, revreal *b, revreal* c ); - +void deconv0(int dim, revreal *a, revreal *b, revreal *c); +void deconv1(int dim, revreal *a, revreal *b, revreal *c); /****************************************************************************/ /* OTHER USEFUL ROUTINES */ /*--------------------------------------------------------------------------*/ -void divide(int dim, revreal* a, revreal *b, revreal* c); +void divide(int dim, revreal *a, revreal *b, revreal *c); /*--------------------------------------------------------------------------*/ -void recipr(int dim, double a, revreal *b, revreal* c); - +void recipr(int dim, double a, revreal *b, revreal *c); /****************************************************************************/ /* ZEROING */ /*--------------------------------------------------------------------------*/ /* Set a to zero */ -void zeroset(int dim, double* a); +void zeroset(int dim, double *a); /*--------------------------------------------------------------------------*/ /* Copies a to tmp and initializes a to zero */ -void copyAndZeroset( int dim, revreal *a, revreal* tmp); - +void copyAndZeroset(int dim, revreal *a, revreal *tmp); /****************************************************************************/ END_C_DECLS diff --git a/ADOL-C/include/adolc/drivers/drivers.h b/ADOL-C/include/adolc/drivers/drivers.h index 80c668e72..72a72dd2a 100644 --- a/ADOL-C/include/adolc/drivers/drivers.h +++ b/ADOL-C/include/adolc/drivers/drivers.h @@ -3,21 +3,21 @@ File: drivers/drivers.h Revision: $Id$ Contents: Easy to use drivers for optimization and nonlinear equations - (with C and C++ callable interfaces including Fortran + (with C and C++ callable interfaces including Fortran callable versions). - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_DRIVERS_DRIVERS_H) -#define ADOLC_DRIVERS_DRIVERS_H 1 + #define ADOLC_DRIVERS_DRIVERS_H 1 -#include + #include BEGIN_C_DECLS @@ -27,78 +27,84 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* function */ /* function(tag, m, n, x[n], y[m]) */ -ADOLC_DLL_EXPORT int function(short,int,int,const double*,double*); -ADOLC_DLL_EXPORT fint function_(fint*,fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int function(short, int, int, const double *, double *); +ADOLC_DLL_EXPORT fint function_(fint *, fint *, fint *, fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* gradient */ /* gradient(tag, n, x[n], g[n]) */ -ADOLC_DLL_EXPORT int gradient(short,int,const double*,double*); -ADOLC_DLL_EXPORT fint gradient_(fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int gradient(short, int, const double *, double *); +ADOLC_DLL_EXPORT fint gradient_(fint *, fint *, fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* jacobian */ /* jacobian(tag, m, n, x[n], J[m][n]) */ -ADOLC_DLL_EXPORT int jacobian(short,int,int,const double*,double**); -ADOLC_DLL_EXPORT fint jacobian_(fint*,fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int jacobian(short, int, int, const double *, double **); +ADOLC_DLL_EXPORT fint jacobian_(fint *, fint *, fint *, fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* large_jacobian */ /* large_jacobian(tag, m, n, k, x[n], y[m], J[m][n]) */ -ADOLC_DLL_EXPORT int large_jacobian(short,int,int,int,double*,double*,double**); -ADOLC_DLL_EXPORT fint large_jacobian_(fint*,fint*,fint*,fint*,fdouble*,fdouble*,fdouble*); - +ADOLC_DLL_EXPORT int large_jacobian(short, int, int, int, double *, double *, + double **); +ADOLC_DLL_EXPORT fint large_jacobian_(fint *, fint *, fint *, fint *, fdouble *, + fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* vector_jacobian */ /* vec_jac(tag, m, n, repeat, x[n], u[m], v[n]) */ -ADOLC_DLL_EXPORT int vec_jac(short,int,int,int,const double*,double*,double*); -ADOLC_DLL_EXPORT fint vec_jac_(fint*,fint*,fint*,fint*, - fdouble*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int vec_jac(short, int, int, int, const double *, double *, + double *); +ADOLC_DLL_EXPORT fint vec_jac_(fint *, fint *, fint *, fint *, fdouble *, + fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* jacobian_vector */ /* jac_vec(tag, m, n, x[n], v[n], u[m]); */ -ADOLC_DLL_EXPORT int jac_vec(short,int,int,const double*,const double*,double*); -ADOLC_DLL_EXPORT fint jac_vec_(fint*,fint*,fint*,fdouble*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int jac_vec(short, int, int, const double *, const double *, + double *); +ADOLC_DLL_EXPORT fint jac_vec_(fint *, fint *, fint *, fdouble *, fdouble *, + fdouble *); /*--------------------------------------------------------------------------*/ /* hessian */ /* hessian(tag, n, x[n], lower triangle of H[n][n]) */ /* uses Hessian-vector product */ -ADOLC_DLL_EXPORT int hessian(short,int,const double*,double**); -ADOLC_DLL_EXPORT fint hessian_(fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int hessian(short, int, const double *, double **); +ADOLC_DLL_EXPORT fint hessian_(fint *, fint *, fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* hessian2 */ /* hessian2(tag, n, x[n], lower triangle of H[n][n]) */ /* uses Hessian-matrix product */ -ADOLC_DLL_EXPORT int hessian2(short,int,double*,double**); -ADOLC_DLL_EXPORT fint hessian2_(fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int hessian2(short, int, double *, double **); +ADOLC_DLL_EXPORT fint hessian2_(fint *, fint *, fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* hessian_vector */ /* hess_vec(tag, n, x[n], v[n], w[n]) */ -ADOLC_DLL_EXPORT int hess_vec(short,int,const double*,const double*,double*); -ADOLC_DLL_EXPORT fint hess_vec_(fint*,fint*,fdouble*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int hess_vec(short, int, const double *, const double *, + double *); +ADOLC_DLL_EXPORT fint hess_vec_(fint *, fint *, fdouble *, fdouble *, + fdouble *); /*--------------------------------------------------------------------------*/ /* hessian_matrix */ /* hess_mat(tag, n, q, x[n], V[n][q], W[n][q]) */ -ADOLC_DLL_EXPORT int hess_mat(short,int,int,const double*, const double* const*,double**); -ADOLC_DLL_EXPORT fint hess_mat_(fint*,fint*,fint*, - fdouble*,fdouble**,fdouble**); +ADOLC_DLL_EXPORT int hess_mat(short, int, int, const double *, + const double *const *, double **); +ADOLC_DLL_EXPORT fint hess_mat_(fint *, fint *, fint *, fdouble *, fdouble **, + fdouble **); /*--------------------------------------------------------------------------*/ /* lagrange_hessian_vector */ /* lagra_hess_vec(tag, m, n, x[n], v[n], u[m], w[n]) */ -ADOLC_DLL_EXPORT int lagra_hess_vec(short,int,int,const double*, - const double*,const double*,double*); -ADOLC_DLL_EXPORT fint lagra_hess_vec_(fint*,fint*,fint*, - fdouble*,fdouble*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT int lagra_hess_vec(short, int, int, const double *, + const double *, const double *, double *); +ADOLC_DLL_EXPORT fint lagra_hess_vec_(fint *, fint *, fint *, fdouble *, + fdouble *, fdouble *, fdouble *); END_C_DECLS /****************************************************************************/ #endif - diff --git a/ADOL-C/include/adolc/drivers/odedrivers.h b/ADOL-C/include/adolc/drivers/odedrivers.h index e5aa5d894..1219d2bde 100644 --- a/ADOL-C/include/adolc/drivers/odedrivers.h +++ b/ADOL-C/include/adolc/drivers/odedrivers.h @@ -3,22 +3,22 @@ File: drivers/odedrivers.h Revision: $Id$ Contents: Easy to use drivers for ordinary differential equations (ODE) - (with C and C++ callable interfaces including Fortran + (with C and C++ callable interfaces including Fortran callable versions). - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_DRIVERS_ODEDRIVERS_H) -#define ADOLC_DRIVERS_ODEDRIVERS_H 1 + #define ADOLC_DRIVERS_ODEDRIVERS_H 1 -#include -#include + #include + #include BEGIN_C_DECLS @@ -28,21 +28,23 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* forodec */ /* forodec(tag, n, tau, dold, dnew, X[n][d+1]) */ -ADOLC_DLL_EXPORT int forodec(short,int,double,int,int,double**); -ADOLC_DLL_EXPORT fint forodec_(fint*,fint*,fdouble*,fint*,fint*,fdouble*); +ADOLC_DLL_EXPORT int forodec(short, int, double, int, int, double **); +ADOLC_DLL_EXPORT fint forodec_(fint *, fint *, fdouble *, fint *, fint *, + fdouble *); /*--------------------------------------------------------------------------*/ /* accodec */ /* accodec(n, tau, d, Z[n][n][d+1], B[n][n][d+1], nz[n][n]) */ -ADOLC_DLL_EXPORT void accodec(int,double,int,double***,double***,short**); -ADOLC_DLL_EXPORT fint accodec_(fint*,fdouble*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT void accodec(int, double, int, double ***, double ***, + short **); +ADOLC_DLL_EXPORT fint accodec_(fint *, fdouble *, fint *, fdouble *, fdouble *); END_C_DECLS -/****************************************************************************/ -/****************************************************************************/ -/* Now the C++ THINGS */ -#if defined(__cplusplus) + /****************************************************************************/ + /****************************************************************************/ + /* Now the C++ THINGS */ + #if defined(__cplusplus) /****************************************************************************/ /* DRIVERS FOR ODEs, overloaded calls */ @@ -50,15 +52,14 @@ END_C_DECLS /*--------------------------------------------------------------------------*/ /* forode */ /* forode(tag, n, tau, dold, dnew, X[n][d+1]) */ -inline int forode( - short tag, // tape identifier - int n, // space dimension - double tau, // scaling - int dold, // previous degree defaults to zero - int dnew, // New degree of consistency - double **X) // Taylor series +inline int forode(short tag, // tape identifier + int n, // space dimension + double tau, // scaling + int dold, // previous degree defaults to zero + int dnew, // New degree of consistency + double **X) // Taylor series { - return forodec(tag,n,tau,dold,dnew,X); + return forodec(tag, n, tau, dold, dnew, X); } /*--------------------------------------------------------------------------*/ @@ -66,8 +67,8 @@ inline int forode( /* the scaling tau defaults to 1 */ /* */ /* forode(tag, n, dold, dnew, X[n][d+1]) */ -inline int forode(short tag, int n, int dold, int dnew, double** X) { - return forodec(tag,n,1.0,dold,dnew,X); +inline int forode(short tag, int n, int dold, int dnew, double **X) { + return forodec(tag, n, 1.0, dold, dnew, X); } /*--------------------------------------------------------------------------*/ @@ -75,8 +76,8 @@ inline int forode(short tag, int n, int dold, int dnew, double** X) { /* previous order defaults to 0 */ /* */ /* forode(tag, n, tau, dnew, X[n][d+1]) */ -inline int forode( short tag, int n, double tau, int deg, double **X) { - return forodec(tag,n,tau,0,deg, X); +inline int forode(short tag, int n, double tau, int deg, double **X) { + return forodec(tag, n, tau, 0, deg, X); } /*--------------------------------------------------------------------------*/ @@ -84,22 +85,21 @@ inline int forode( short tag, int n, double tau, int deg, double **X) { /* both tau and dold default */ /* */ /* forode(tag, n, dnew, X[n][d+1]) */ -inline int forode(short tag, int n, int deg, double** X) { - return forode(tag,n,1.0,0,deg,X); +inline int forode(short tag, int n, int deg, double **X) { + return forode(tag, n, 1.0, 0, deg, X); } /*--------------------------------------------------------------------------*/ /* accode */ /* accode(n, tau, d, Z[n][n][d+1], B[n][n][d+1], nz[n][n]) */ -inline void accode( - int n, // space dimension - double tau, // scaling defaults to 1.0 - int deg, // highest degree - double ***A, // input tensor of "partial" Jacobians - double ***B, // output tensor of "total" Jacobians - short **nonzero = 0) // optional sparsity characterization +inline void accode(int n, // space dimension + double tau, // scaling defaults to 1.0 + int deg, // highest degree + double ***A, // input tensor of "partial" Jacobians + double ***B, // output tensor of "total" Jacobians + short **nonzero = 0) // optional sparsity characterization { - accodec(n,tau,deg,A,B,nonzero); + accodec(n, tau, deg, A, B, nonzero); } /*--------------------------------------------------------------------------*/ @@ -107,18 +107,16 @@ inline void accode( /* scaling defaults to 1 */ /* */ /* accode(n, d, Z[n][n][d+1], B[n][n][d+1], nz[n][n]) */ -inline void accode( - int n, // space dimension - int deg, // highest degree - double ***A, // input tensor of "partial" Jacobians - double ***B, // output tensor of "total" Jacobians - short **nonzero = 0) // optional sparsity characterization +inline void accode(int n, // space dimension + int deg, // highest degree + double ***A, // input tensor of "partial" Jacobians + double ***B, // output tensor of "total" Jacobians + short **nonzero = 0) // optional sparsity characterization { - accodec(n,1.0,deg,A,B,nonzero); + accodec(n, 1.0, deg, A, B, nonzero); } -#endif + #endif /****************************************************************************/ #endif - diff --git a/ADOL-C/include/adolc/drivers/psdrivers.h b/ADOL-C/include/adolc/drivers/psdrivers.h index 08ffe3e0b..9e70428d6 100644 --- a/ADOL-C/include/adolc/drivers/psdrivers.h +++ b/ADOL-C/include/adolc/drivers/psdrivers.h @@ -3,22 +3,21 @@ File: drivers/psdrivers.h Revision: $Id$ Contents: Easy to use drivers for piecewise smooth functions - (with C and C++ callable interfaces including Fortran + (with C and C++ callable interfaces including Fortran callable versions). Copyright (c) Andrea Walther, Sabrina Fiege This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_DRIVERS_PSDRIVERS_H) -#define ADOLC_DRIVERS_PSDRIVERS_H 1 - -#include -#include + #define ADOLC_DRIVERS_PSDRIVERS_H 1 + #include + #include BEGIN_C_DECLS @@ -28,42 +27,43 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* directional_active_gradient_ */ /* */ -ADOLC_DLL_EXPORT fint directional_active_gradient_(fint,fint,double*,double*,double*,double**,short*); +ADOLC_DLL_EXPORT fint directional_active_gradient_(fint, fint, double *, + double *, double *, + double **, short *); /*--------------------------------------------------------------------------*/ /* directional_active_gradient */ /* */ -ADOLC_DLL_EXPORT int directional_active_gradient( - short tag, /* trace identifier */ - int n, /* number of independents */ - double* x, /* value of independents */ - double* d, /* direction */ - double* g, /* directional active gradient */ - short *sigma_g /* sigma of g */ - ); - +ADOLC_DLL_EXPORT int +directional_active_gradient(short tag, /* trace identifier */ + int n, /* number of independents */ + double *x, /* value of independents */ + double *d, /* direction */ + double *g, /* directional active gradient */ + short *sigma_g /* sigma of g */ +); /*--------------------------------------------------------------------------*/ /* abs_normal */ /* */ -ADOLC_DLL_EXPORT fint abs_normal_(fint*,fint*,fint*,fint*,fdouble*,fdouble*,fdouble*,fdouble*,fdouble*,fdouble*,fdouble*,fdouble*,fdouble*); -ADOLC_DLL_EXPORT int abs_normal(short tag, /* tape identifier */ - int m, /* number od dependents */ - int n, /* number of independents */ - int swchk, /* number of switches (check) */ - double *x, /* base point */ - double *y, /* function value */ - double *z, /* switching variables */ - double *cz, /* first constant */ - double *cy, /* second constant */ - double **Y, /* m times n */ - double **J, /* m times s */ - double **Z, /* s times n */ - double **L); /* s times s (lowtri) */ - +ADOLC_DLL_EXPORT fint abs_normal_(fint *, fint *, fint *, fint *, fdouble *, + fdouble *, fdouble *, fdouble *, fdouble *, + fdouble *, fdouble *, fdouble *, fdouble *); +ADOLC_DLL_EXPORT int abs_normal(short tag, /* tape identifier */ + int m, /* number od dependents */ + int n, /* number of independents */ + int swchk, /* number of switches (check) */ + double *x, /* base point */ + double *y, /* function value */ + double *z, /* switching variables */ + double *cz, /* first constant */ + double *cy, /* second constant */ + double **Y, /* m times n */ + double **J, /* m times s */ + double **Z, /* s times n */ + double **L); /* s times s (lowtri) */ END_C_DECLS /****************************************************************************/ #endif - diff --git a/ADOL-C/include/adolc/drivers/taylor.h b/ADOL-C/include/adolc/drivers/taylor.h index 206c36e46..f7ee384aa 100644 --- a/ADOL-C/include/adolc/drivers/taylor.h +++ b/ADOL-C/include/adolc/drivers/taylor.h @@ -4,18 +4,18 @@ Revision: $Id$ Contents: Easy to use drivers for the evaluation of higher order derivative tensors and inverse/impicit function differentiation - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Olaf Vogel This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_DRIVERS_TAYLOR_H) -#define ADOLC_DRIVERS_TAYLOR_H 1 + #define ADOLC_DRIVERS_TAYLOR_H 1 -#include + #include BEGIN_C_DECLS @@ -25,20 +25,20 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* tensor_eval(tag,m,n,d,p,x[n],tensor[m][dim],S[n][p]) with dim = ((p+d) over d) */ -ADOLC_DLL_EXPORT int tensor_eval -(short tag, int m, int n, int d, int p, - double *x, double **tensor, double **S); +ADOLC_DLL_EXPORT int tensor_eval(short tag, int m, int n, int d, int p, + double *x, double **tensor, double **S); /*--------------------------------------------------------------------------*/ /* inverse_tensor_eval(tag,n,d,p,x,tensor[n][dim],S[n][p]) with dim = ((p+d) over d) */ -ADOLC_DLL_EXPORT int inverse_tensor_eval -(short tag, int n, int d, int p, double *x, double **tensor, double **S); +ADOLC_DLL_EXPORT int inverse_tensor_eval(short tag, int n, int d, int p, + double *x, double **tensor, + double **S); /*--------------------------------------------------------------------------*/ /* inverse_Taylor_prop(tag,n,d,Y[n][d+1],X[n][d+1]) */ -ADOLC_DLL_EXPORT int inverse_Taylor_prop -(short tag, int n, int d, double** Y, double** X); +ADOLC_DLL_EXPORT int inverse_Taylor_prop(short tag, int n, int d, double **Y, + double **X); /****************************************************************************/ /* ACCESS TO TENSOR VALUES */ @@ -46,20 +46,20 @@ ADOLC_DLL_EXPORT int inverse_Taylor_prop /*--------------------------------------------------------------------------*/ /* tensor_value(d,m,y[m],tensori[m][dim],multi[d]) with dim = ((p+d) over d) */ -ADOLC_DLL_EXPORT void tensor_value -(int d, int m, double *y, double **tensor, int *multi); +ADOLC_DLL_EXPORT void tensor_value(int d, int m, double *y, double **tensor, + int *multi); /*--------------------------------------------------------------------------*/ /* void** tensorsetup(m,p,d,tensorig) */ -ADOLC_DLL_EXPORT void** tensorsetup(int m, int p, int d, double** tensorig); +ADOLC_DLL_EXPORT void **tensorsetup(int m, int p, int d, double **tensorig); /*--------------------------------------------------------------------------*/ /* void freetensor(m,p,d,tensor) */ -ADOLC_DLL_EXPORT void freetensor(int m, int p, int d, double** tensor); +ADOLC_DLL_EXPORT void freetensor(int m, int p, int d, double **tensor); /*--------------------------------------------------------------------------*/ /* int tensor_address(d, im[d]) */ -ADOLC_DLL_EXPORT int tensor_address(int d, int* im); +ADOLC_DLL_EXPORT int tensor_address(int d, int *im); /****************************************************************************/ /* UTILS */ @@ -70,10 +70,8 @@ ADOLC_DLL_EXPORT long binomi(int a, int b); /*--------------------------------------------------------------------------*/ /* jac_solv(tag,n,x,b,mode) */ -ADOLC_DLL_EXPORT int jac_solv -(unsigned short tag, int n, const double* x, double* b, - unsigned short mode); - +ADOLC_DLL_EXPORT int jac_solv(unsigned short tag, int n, const double *x, + double *b, unsigned short mode); END_C_DECLS diff --git a/ADOL-C/include/adolc/edfclasses.h b/ADOL-C/include/adolc/edfclasses.h index 2165bd2f7..152923393 100644 --- a/ADOL-C/include/adolc/edfclasses.h +++ b/ADOL-C/include/adolc/edfclasses.h @@ -14,69 +14,96 @@ ----------------------------------------------------------------------------*/ #if !defined(ADOLC_EDFCLASSES_H) -#define ADOLC_EDFCLASSES_H 1 + #define ADOLC_EDFCLASSES_H 1 -#include -#include + #include + #include class EDFobject { protected: - ext_diff_fct *edf; - void init_edf(EDFobject *ebase); + ext_diff_fct *edf; + void init_edf(EDFobject *ebase); + public: - EDFobject() { init_edf(this); } - virtual ~EDFobject() { edf_zero(edf); } - virtual int function(int n, double *x, int m, double *y) = 0; - virtual int zos_forward(int n, double *x, int m, double *y) = 0; - virtual int fos_forward(int n, double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y) = 0; - virtual int fov_forward(int n, double *dp_x, int p, double **dpp_X, int m, double *dp_y, double **dpp_Y) = 0; - virtual int fos_reverse(int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y) = 0; - virtual int fov_reverse(int m, int p, double **dpp_U, int n, double **dpp_Z, double *dp_x, double *dp_y) = 0; - int call(int n, adouble *xa, int m, adouble *ya) { - return call_ext_fct(edf,n,xa,m,ya); - } - int call(int n, advector& x, int m, advector& y) { - return call(n,x.operator adouble*(),m,y.operator adouble*()); - } + EDFobject() { init_edf(this); } + virtual ~EDFobject() { edf_zero(edf); } + virtual int function(int n, double *x, int m, double *y) = 0; + virtual int zos_forward(int n, double *x, int m, double *y) = 0; + virtual int fos_forward(int n, double *dp_x, double *dp_X, int m, + double *dp_y, double *dp_Y) = 0; + virtual int fov_forward(int n, double *dp_x, int p, double **dpp_X, int m, + double *dp_y, double **dpp_Y) = 0; + virtual int fos_reverse(int m, double *dp_U, int n, double *dp_Z, + double *dp_x, double *dp_y) = 0; + virtual int fov_reverse(int m, int p, double **dpp_U, int n, double **dpp_Z, + double *dp_x, double *dp_y) = 0; + int call(int n, adouble *xa, int m, adouble *ya) { + return call_ext_fct(edf, n, xa, m, ya); + } + int call(int n, advector &x, int m, advector &y) { + return call(n, x.operator adouble *(), m, y.operator adouble *()); + } }; class EDFobject_iArr { protected: - ext_diff_fct *edf; - void init_edf(EDFobject_iArr *ebase); + ext_diff_fct *edf; + void init_edf(EDFobject_iArr *ebase); + public: - EDFobject_iArr() { init_edf(this); } - virtual ~EDFobject_iArr() { edf_zero(edf); } - virtual int function(int iArrLength, int *iArr, int n, double *x, int m, double *y) = 0; - virtual int zos_forward(int iArrLength, int *iArr, int n, double *x, int m, double *y) = 0; - virtual int fos_forward(int iArrLength, int *iArr, int n, double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y) = 0; - virtual int fov_forward(int iArrLength, int *iArr, int n, double *dp_x, int p, double **dpp_X, int m, double *dp_y, double **dpp_Y) = 0; - virtual int fos_reverse(int iArrLength, int *iArr, int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y) = 0; - virtual int fov_reverse(int iArrLength, int *iArr, int m, int p, double **dpp_U, int n, double **dpp_Z, double *dp_x, double *dp_y) = 0; - int call(int iArrLength, int *iArr, int n, adouble *xa, int m, adouble *ya) { - return call_ext_fct(edf,iArrLength,iArr,n,xa,m,ya); - } - int call(int iArrLength,int* iArr,int n, advector& x, int m, advector& y) { - return call(iArrLength,iArr,n,x.operator adouble*(),m,y.operator adouble*()); - } + EDFobject_iArr() { init_edf(this); } + virtual ~EDFobject_iArr() { edf_zero(edf); } + virtual int function(int iArrLength, int *iArr, int n, double *x, int m, + double *y) = 0; + virtual int zos_forward(int iArrLength, int *iArr, int n, double *x, int m, + double *y) = 0; + virtual int fos_forward(int iArrLength, int *iArr, int n, double *dp_x, + double *dp_X, int m, double *dp_y, double *dp_Y) = 0; + virtual int fov_forward(int iArrLength, int *iArr, int n, double *dp_x, int p, + double **dpp_X, int m, double *dp_y, + double **dpp_Y) = 0; + virtual int fos_reverse(int iArrLength, int *iArr, int m, double *dp_U, int n, + double *dp_Z, double *dp_x, double *dp_y) = 0; + virtual int fov_reverse(int iArrLength, int *iArr, int m, int p, + double **dpp_U, int n, double **dpp_Z, double *dp_x, + double *dp_y) = 0; + int call(int iArrLength, int *iArr, int n, adouble *xa, int m, adouble *ya) { + return call_ext_fct(edf, iArrLength, iArr, n, xa, m, ya); + } + int call(int iArrLength, int *iArr, int n, advector &x, int m, advector &y) { + return call(iArrLength, iArr, n, x.operator adouble *(), m, + y.operator adouble *()); + } }; class EDFobject_v2 { protected: - ext_diff_fct_v2 *edf; - void init_edf(EDFobject_v2 *ebase); + ext_diff_fct_v2 *edf; + void init_edf(EDFobject_v2 *ebase); + public: - EDFobject_v2() { init_edf(this); } - virtual ~EDFobject_v2() { edf_zero(edf); } - virtual int function(int iArrLen, int *iArr, int nin, int nout, int *insz, double **x, int *outsz, double **y, void* ctx) = 0; - virtual int zos_forward(int iArrLen, int *iArr, int nin, int nout, int *insz, double **x, int *outsz, double **y, void* ctx) = 0; - virtual int fos_forward(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, double **xp, int *outsz, double **y, double **yp, void *ctx) = 0; - virtual int fov_forward(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, int ndir, double ***Xp, int *outsz, double **y, double ***Yp, void* ctx) = 0; - virtual int fos_reverse(int iArrLen, int* iArr, int nout, int nin, int *outsz, double **up, int *insz, double **zp, double **x, double **y, void *ctx) = 0; - virtual int fov_reverse(int iArrLen, int* iArr, int nout, int nin, int *outsz, int dir, double ***Up, int *insz, double ***Zp, double **x, double **y, void* ctx) = 0; - int call(int iArrLen, int* iArr, int nin, int nout, int *insz, adouble **x, int *outsz, adouble **y) { - return call_ext_fct(edf,iArrLen,iArr,nin,nout,insz,x,outsz,y); - } + EDFobject_v2() { init_edf(this); } + virtual ~EDFobject_v2() { edf_zero(edf); } + virtual int function(int iArrLen, int *iArr, int nin, int nout, int *insz, + double **x, int *outsz, double **y, void *ctx) = 0; + virtual int zos_forward(int iArrLen, int *iArr, int nin, int nout, int *insz, + double **x, int *outsz, double **y, void *ctx) = 0; + virtual int fos_forward(int iArrLen, int *iArr, int nin, int nout, int *insz, + double **x, double **xp, int *outsz, double **y, + double **yp, void *ctx) = 0; + virtual int fov_forward(int iArrLen, int *iArr, int nin, int nout, int *insz, + double **x, int ndir, double ***Xp, int *outsz, + double **y, double ***Yp, void *ctx) = 0; + virtual int fos_reverse(int iArrLen, int *iArr, int nout, int nin, int *outsz, + double **up, int *insz, double **zp, double **x, + double **y, void *ctx) = 0; + virtual int fov_reverse(int iArrLen, int *iArr, int nout, int nin, int *outsz, + int dir, double ***Up, int *insz, double ***Zp, + double **x, double **y, void *ctx) = 0; + int call(int iArrLen, int *iArr, int nin, int nout, int *insz, adouble **x, + int *outsz, adouble **y) { + return call_ext_fct(edf, iArrLen, iArr, nin, nout, insz, x, outsz, y); + } }; #endif diff --git a/ADOL-C/include/adolc/externfcts.h b/ADOL-C/include/adolc/externfcts.h index 35b9594f8..08918d543 100644 --- a/ADOL-C/include/adolc/externfcts.h +++ b/ADOL-C/include/adolc/externfcts.h @@ -4,186 +4,232 @@ Revision: $Id$ Contents: public functions and data types for extern (differentiated) functions. - + Copyright (c) Andreas Kowarz, Jean Utke This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_EXTERNFCTS_H) -#define ADOLC_EXTERNFCTS_H 1 + #define ADOLC_EXTERNFCTS_H 1 -#include -#include + #include + #include BEGIN_C_DECLS -typedef int (ADOLC_ext_fct) (int n, double *x, int m, double *y); -typedef int (ADOLC_ext_fct_fos_forward) (int n, double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y); -typedef int (ADOLC_ext_fct_fov_forward) (int n, double *dp_x, int p, double **dpp_X, int m, double *dp_y, double **dpp_Y); -typedef int (ADOLC_ext_fct_hos_forward) (int n, double *dp_x, int d, double **dpp_X, int m, double *dp_y, double **dpp_Y); -typedef int (ADOLC_ext_fct_hov_forward) (int n, double *dp_x, int d, int p, double ***dppp_X, int m, double *dp_y, double ***dppp_Y); -typedef int (ADOLC_ext_fct_fos_reverse) (int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y); -typedef int (ADOLC_ext_fct_fov_reverse) (int m, int p, double **dpp_U, int n, double **dpp_Z, double *dp_x, double *dp_y); -typedef int (ADOLC_ext_fct_hos_reverse) (int m, double *dp_U, int n, int d, double **dpp_Z); -// dpp_x: {x_{0,0}, x{0,1}, ..., x_{0,keep}}, {x1,0, ..., x_1,keep}, ...} ; n Taylor polynomials of degree keep (i.e., array of size n * (keep+1)) -typedef int (ADOLC_ext_fct_hos_ti_reverse) (int m, double **dp_U, int n, int d, double **dpp_Z, double **dpp_x, double **dpp_y); -typedef int (ADOLC_ext_fct_hov_reverse) (int m, int p, double **dpp_U, int n, int d, double ***dppp_Z, short **spp_nz); +typedef int(ADOLC_ext_fct)(int n, double *x, int m, double *y); +typedef int(ADOLC_ext_fct_fos_forward)(int n, double *dp_x, double *dp_X, int m, + double *dp_y, double *dp_Y); +typedef int(ADOLC_ext_fct_fov_forward)(int n, double *dp_x, int p, + double **dpp_X, int m, double *dp_y, + double **dpp_Y); +typedef int(ADOLC_ext_fct_hos_forward)(int n, double *dp_x, int d, + double **dpp_X, int m, double *dp_y, + double **dpp_Y); +typedef int(ADOLC_ext_fct_hov_forward)(int n, double *dp_x, int d, int p, + double ***dppp_X, int m, double *dp_y, + double ***dppp_Y); +typedef int(ADOLC_ext_fct_fos_reverse)(int m, double *dp_U, int n, double *dp_Z, + double *dp_x, double *dp_y); +typedef int(ADOLC_ext_fct_fov_reverse)(int m, int p, double **dpp_U, int n, + double **dpp_Z, double *dp_x, + double *dp_y); +typedef int(ADOLC_ext_fct_hos_reverse)(int m, double *dp_U, int n, int d, + double **dpp_Z); +// dpp_x: {x_{0,0}, x{0,1}, ..., x_{0,keep}}, {x1,0, ..., x_1,keep}, ...} ; n +// Taylor polynomials of degree keep (i.e., array of size n * (keep+1)) +typedef int(ADOLC_ext_fct_hos_ti_reverse)(int m, double **dp_U, int n, int d, + double **dpp_Z, double **dpp_x, + double **dpp_y); +typedef int(ADOLC_ext_fct_hov_reverse)(int m, int p, double **dpp_U, int n, + int d, double ***dppp_Z, short **spp_nz); /** - * we add a second set of function pointers with a signature expanded by a an integer array iArr - * and a parameter iArrLength motivated by externalizing sparse solvers where the sparsity format - * may be triples (i,j,A[i][j]) and a number of nonzero entries nz where all these integers are to - * be packed into iArr. Doing this will still allow the integers to be stored in the locint part - * of the tape. - * The alternative to doing this is the introduction of a separate stack to contain the extra data - * but this would break the self-containment of the tape. + * we add a second set of function pointers with a signature expanded by a an + * integer array iArr and a parameter iArrLength motivated by externalizing + * sparse solvers where the sparsity format may be triples (i,j,A[i][j]) and a + * number of nonzero entries nz where all these integers are to be packed into + * iArr. Doing this will still allow the integers to be stored in the locint + * part of the tape. The alternative to doing this is the introduction of a + * separate stack to contain the extra data but this would break the + * self-containment of the tape. */ -typedef int (ADOLC_ext_fct_iArr) (int iArrLength, int *iArr, int n, double *x, int m, double *y); -typedef int (ADOLC_ext_fct_iArr_fos_forward) (int iArrLength, int *iArr, int n, double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y); -typedef int (ADOLC_ext_fct_iArr_fov_forward) (int iArrLength, int *iArr, int n, double *dp_x, int p, double **dpp_X, int m, double *dp_y, double **dpp_Y); -typedef int (ADOLC_ext_fct_iArr_hos_forward) (int iArrLength, int *iArr, int n, double *dp_x, int d, double **dpp_X, int m, double *dp_y, double **dpp_Y); -typedef int (ADOLC_ext_fct_iArr_hov_forward) (int iArrLength, int *iArr, int n, double *dp_x, int d, int p, double ***dppp_X, int m, double *dp_y, double ***dppp_Y); -typedef int (ADOLC_ext_fct_iArr_fos_reverse) (int iArrLength, int *iArr, int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y); -typedef int (ADOLC_ext_fct_iArr_fov_reverse) (int iArrLength, int *iArr, int m, int p, double **dpp_U, int n, double **dpp_Z, double *dp_x, double *dp_y); -typedef int (ADOLC_ext_fct_iArr_hos_reverse) (int iArrLength, int *iArr, int m, double *dp_U, int n, int d, double **dpp_Z); -typedef int (ADOLC_ext_fct_iArr_hov_reverse) (int iArrLength, int *iArr, int m, int p, double **dpp_U, int n, int d, double ***dppp_Z, short **spp_nz); - +typedef int(ADOLC_ext_fct_iArr)(int iArrLength, int *iArr, int n, double *x, + int m, double *y); +typedef int(ADOLC_ext_fct_iArr_fos_forward)(int iArrLength, int *iArr, int n, + double *dp_x, double *dp_X, int m, + double *dp_y, double *dp_Y); +typedef int(ADOLC_ext_fct_iArr_fov_forward)(int iArrLength, int *iArr, int n, + double *dp_x, int p, double **dpp_X, + int m, double *dp_y, + double **dpp_Y); +typedef int(ADOLC_ext_fct_iArr_hos_forward)(int iArrLength, int *iArr, int n, + double *dp_x, int d, double **dpp_X, + int m, double *dp_y, + double **dpp_Y); +typedef int(ADOLC_ext_fct_iArr_hov_forward)(int iArrLength, int *iArr, int n, + double *dp_x, int d, int p, + double ***dppp_X, int m, + double *dp_y, double ***dppp_Y); +typedef int(ADOLC_ext_fct_iArr_fos_reverse)(int iArrLength, int *iArr, int m, + double *dp_U, int n, double *dp_Z, + double *dp_x, double *dp_y); +typedef int(ADOLC_ext_fct_iArr_fov_reverse)(int iArrLength, int *iArr, int m, + int p, double **dpp_U, int n, + double **dpp_Z, double *dp_x, + double *dp_y); +typedef int(ADOLC_ext_fct_iArr_hos_reverse)(int iArrLength, int *iArr, int m, + double *dp_U, int n, int d, + double **dpp_Z); +typedef int(ADOLC_ext_fct_iArr_hov_reverse)(int iArrLength, int *iArr, int m, + int p, double **dpp_U, int n, int d, + double ***dppp_Z, short **spp_nz); /** - * A variable of this type has to be instantiated by reg_ext_fct (see below) and a pointer to it is - * returned. Within reg_ext_fct the memberse function and index are properly set. - * is likely to be wrong in this case. Use pointers instead. + * A variable of this type has to be instantiated by reg_ext_fct (see below) and + * a pointer to it is returned. Within reg_ext_fct the memberse function and + * index are properly set. is likely to be wrong in this case. Use pointers + * instead. */ typedef struct ext_diff_fct { /** * DO NOT touch - the function pointer is set through reg_ext_fct */ - ADOLC_ext_fct *function; + ADOLC_ext_fct *function; ADOLC_ext_fct_iArr *function_iArr; /** * DO NOT touch - the index is set through reg_ext_fct */ - locint index; + locint index; - /** - * below are function pointers used for call back from the corresponding ADOL-C trace interpreters; - * these function pointers are initialized to 0 by reg_ext_fct; - * the user needs to set eplicitly the function pointers for the trace interpreters called in the - * application driver + /** + * below are function pointers used for call back from the corresponding + * ADOL-C trace interpreters; these function pointers are initialized to 0 by + * reg_ext_fct; the user needs to set eplicitly the function pointers for the + * trace interpreters called in the application driver */ /** - * this points to a method implementing a forward execution of the externally differentiated function dp_y=f(dp_x); - * the pointer would typically be set to the same function pointer supplied in the call to reg_ext_fct, - * i.e. zos_forward would be equal to function (above) - * but there are cases when it makes sense for this to be different as illustrated - * in examples/additional_examples/ext_diff_func/ext_diff_func.cpp + * this points to a method implementing a forward execution of the externally + * differentiated function dp_y=f(dp_x); the pointer would typically be set to + * the same function pointer supplied in the call to reg_ext_fct, i.e. + * zos_forward would be equal to function (above) but there are cases when it + * makes sense for this to be different as illustrated in + * examples/additional_examples/ext_diff_func/ext_diff_func.cpp */ ADOLC_ext_fct *zos_forward; ADOLC_ext_fct_iArr *zos_forward_iArr; /** - * this points to a method implementing a forward execution of the externally differentiated function dp_y=f(dp_x) - * and computing the projection dp_Y=Jacobian*dp_x - * see also the explanation of the dp_X/Y members below. + * this points to a method implementing a forward execution of the externally + * differentiated function dp_y=f(dp_x) and computing the projection + * dp_Y=Jacobian*dp_x see also the explanation of the dp_X/Y members below. */ ADOLC_ext_fct_fos_forward *fos_forward; ADOLC_ext_fct_iArr_fos_forward *fos_forward_iArr; /** - * this points to a method implementing a forward execution of the externally differentiated function dp_y=f(dp_x) - * and computing the projection dpp_Y=Jacobian*dpp_x - * see also the explanation of the dpp_X/Y members below. + * this points to a method implementing a forward execution of the externally + * differentiated function dp_y=f(dp_x) and computing the projection + * dpp_Y=Jacobian*dpp_x see also the explanation of the dpp_X/Y members + * below. */ ADOLC_ext_fct_fov_forward *fov_forward; ADOLC_ext_fct_iArr_fov_forward *fov_forward_iArr; - /** - * higher order scalar forward for external functions is currently not implemented in uni5_for.c + /** + * higher order scalar forward for external functions is currently not + * implemented in uni5_for.c */ - ADOLC_ext_fct_hos_forward *hos_forward; + ADOLC_ext_fct_hos_forward *hos_forward; ADOLC_ext_fct_iArr_hos_forward *hos_forward_iArr; - /** - * higher order vector forward for external functions is currently not implemented in uni5_for.c + /** + * higher order vector forward for external functions is currently not + * implemented in uni5_for.c */ ADOLC_ext_fct_hov_forward *hov_forward; ADOLC_ext_fct_iArr_hov_forward *hov_forward_iArr; /** - * this points to a method computing the projection dp_Z=transpose(dp_U) * Jacobian - * see also the explanation of the dp_U/Z members below. + * this points to a method computing the projection dp_Z=transpose(dp_U) * + * Jacobian see also the explanation of the dp_U/Z members below. */ - ADOLC_ext_fct_fos_reverse *fos_reverse; + ADOLC_ext_fct_fos_reverse *fos_reverse; ADOLC_ext_fct_iArr_fos_reverse *fos_reverse_iArr; /** - * this points to a method computing the projection dpp_Z=transpose(dpp_U) * Jacobian - * see also the explanation of the dpp_U/Z members below. + * this points to a method computing the projection dpp_Z=transpose(dpp_U) * + * Jacobian see also the explanation of the dpp_U/Z members below. */ - ADOLC_ext_fct_fov_reverse *fov_reverse; + ADOLC_ext_fct_fov_reverse *fov_reverse; ADOLC_ext_fct_iArr_fov_reverse *fov_reverse_iArr; - /** - * higher order scalar reverse for external functions is currently not implemented in ho_rev.c + /** + * higher order scalar reverse for external functions is currently not + * implemented in ho_rev.c */ - ADOLC_ext_fct_hos_reverse *hos_reverse; + ADOLC_ext_fct_hos_reverse *hos_reverse; ADOLC_ext_fct_iArr_hos_reverse *hos_reverse_iArr; ADOLC_ext_fct_hos_ti_reverse *hos_ti_reverse; - /** - * higher order vector reverse for external functions is currently not implemented in ho_rev.c + /** + * higher order vector reverse for external functions is currently not + * implemented in ho_rev.c */ - ADOLC_ext_fct_hov_reverse *hov_reverse; + ADOLC_ext_fct_hov_reverse *hov_reverse; ADOLC_ext_fct_iArr_hov_reverse *hov_reverse_iArr; - /** - * The names of the variables below correspond to the formal parameters names in the call back - * functions above; + * The names of the variables below correspond to the formal parameters names + * in the call back functions above; */ - - /** + + /** * function and all _forward calls: function argument, dimension [n] - */ - double *dp_x; + */ + double *dp_x; - /** + /** * fos_forward: tangent direction, dimension [n] - */ - double *dp_X; + */ + double *dp_X; /** * fov_forward: seed matrix for p directions, dimensions [n][p] - * hos_forward: argument Taylor polynomial coefficients up to order d. dimensions [n][d] + * hos_forward: argument Taylor polynomial coefficients up to order d. + * dimensions [n][d] */ double **dpp_X; - + /** - * hov_forward: argument Taylor polynomial coefficients up to order d in p directions. dimensions [n][p][d] + * hov_forward: argument Taylor polynomial coefficients up to order d in p + * directions. dimensions [n][p][d] */ - double ***dppp_X; + double ***dppp_X; /** * function and all _forward calls: function result, dimension [m] */ - double *dp_y; + double *dp_y; /** * fos_forward: Jacobian projection, dimension [m] */ - double *dp_Y; + double *dp_Y; /** * fov_forward: Jacobian projection in p directions, dimension [m][p] - * hos_forward: result Taylor polynomial coefficients up to order d. dimensions [m][d] + * hos_forward: result Taylor polynomial coefficients up to order d. + * dimensions [m][d] */ - double **dpp_Y; + double **dpp_Y; /** - * hov_forward: result Taylor polynomial coefficients up to order d in p directions. dimensions [m][p][d] + * hov_forward: result Taylor polynomial coefficients up to order d in p + * directions. dimensions [m][p][d] */ double ***dppp_Y; @@ -191,30 +237,33 @@ typedef struct ext_diff_fct { * fos_reverse and hos_reverse: weight vector, dimension [m] */ double *dp_U; - + /** * fov_reverse and hov_reverse: p weight vectors, dimensions [p][m] */ - double **dpp_U; + double **dpp_U; - /** + /** * fos_reverse: Jacobian projection, dimension [n] */ - double *dp_Z; + double *dp_Z; - /** + /** * fov_reverse: Jacobian projection for p weight vectors, dimensions [p][n] - * hos_reverse: adjoint Taylor polynomial coefficients up to order d, dimensions [n][d+1] + * hos_reverse: adjoint Taylor polynomial coefficients up to order d, + * dimensions [n][d+1] */ - double **dpp_Z; + double **dpp_Z; /** - * hov_reverse: adjoint Taylor polynomial coefficients up to order d for p weight vectors, dimension [p][n][d+1] + * hov_reverse: adjoint Taylor polynomial coefficients up to order d for p + * weight vectors, dimension [p][n][d+1] */ - double ***dppp_Z; + double ***dppp_Z; - /** - * hov_reverse: non-zero pattern of dppp_Z, dimension [p][n], see also the hov_reverse ADOL-C driver + /** + * hov_reverse: non-zero pattern of dppp_Z, dimension [p][n], see also the + * hov_reverse ADOL-C driver */ short **spp_nz; @@ -254,50 +303,46 @@ typedef struct ext_diff_fct { * This is an all-memory pointer for allocating and deallocating * all other pointers can point to memory within here. */ - char* allmem; + char *allmem; /** * This is a reference to an object for the C++ object-oriented * implementation of the external function ** do not touch ** */ - void* obj; + void *obj; /** - * This flag indicates that user allocates memory and internally no + * This flag indicates that user allocates memory and internally no * memory should be allocated */ char user_allocated_mem; -} -ext_diff_fct; +} ext_diff_fct; END_C_DECLS -#include + #include -#if defined(__cplusplus) + #if defined(__cplusplus) /****************************************************************************/ /* This is all C++ */ ADOLC_DLL_EXPORT ext_diff_fct *reg_ext_fct(ADOLC_ext_fct ext_fct); ADOLC_DLL_EXPORT ext_diff_fct *reg_ext_fct(ADOLC_ext_fct_iArr ext_fct); -ADOLC_DLL_EXPORT int call_ext_fct (ext_diff_fct *edfct, - int n, adouble *xa, - int m, adouble *ya); -ADOLC_DLL_EXPORT int call_ext_fct (ext_diff_fct *edfct, - int iArrLength, int* iArr, - int n, adouble *xa, - int m, adouble *ya); +ADOLC_DLL_EXPORT int call_ext_fct(ext_diff_fct *edfct, int n, adouble *xa, + int m, adouble *ya); +ADOLC_DLL_EXPORT int call_ext_fct(ext_diff_fct *edfct, int iArrLength, + int *iArr, int n, adouble *xa, int m, + adouble *ya); /** * zeros out the edf pointers and sets bools to defaults */ ADOLC_DLL_EXPORT void edf_zero(ext_diff_fct *edfct); -#include + #include -#endif /* __CPLUSPLUS */ + #endif /* __CPLUSPLUS */ /****************************************************************************/ #endif /* ADOLC_EXTERNFCTS_H */ - diff --git a/ADOL-C/include/adolc/externfcts2.h b/ADOL-C/include/adolc/externfcts2.h index 46593676b..58e314405 100644 --- a/ADOL-C/include/adolc/externfcts2.h +++ b/ADOL-C/include/adolc/externfcts2.h @@ -14,25 +14,46 @@ ----------------------------------------------------------------------------*/ #if !defined(ADOLC_EXTERNFCTS2_H) -#define ADOLC_EXTERNFCTS2_H 1 + #define ADOLC_EXTERNFCTS2_H 1 -#include -#include + #include + #include BEGIN_C_DECLS -typedef int (ADOLC_ext_fct_v2) (int iArrLen, int *iArr, int nin, int nout, int *insz, double **x, int *outsz, double **y, void* ctx); -typedef int (ADOLC_ext_fct_v2_fos_forward)(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, double **xp, int *outsz, double **y, double **yp, void *ctx); -typedef int (ADOLC_ext_fct_v2_fov_forward)(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, int ndir, double ***Xp, int *outsz, double **y, double ***Yp, void* ctx); -typedef int (ADOLC_ext_fct_v2_fos_reverse)(int iArrLen, int* iArr, int nout, int nin, int *outsz, double **up, int *insz, double **zp, double **x, double **y, void *ctx); -typedef int (ADOLC_ext_fct_v2_fov_reverse)(int iArrLen, int* iArr, int nout, int nin, int *outsz, int dir, double ***Up, int *insz, double ***Zp, double **x, double **y, void* ctx); +typedef int(ADOLC_ext_fct_v2)(int iArrLen, int *iArr, int nin, int nout, + int *insz, double **x, int *outsz, double **y, + void *ctx); +typedef int(ADOLC_ext_fct_v2_fos_forward)(int iArrLen, int *iArr, int nin, + int nout, int *insz, double **x, + double **xp, int *outsz, double **y, + double **yp, void *ctx); +typedef int(ADOLC_ext_fct_v2_fov_forward)(int iArrLen, int *iArr, int nin, + int nout, int *insz, double **x, + int ndir, double ***Xp, int *outsz, + double **y, double ***Yp, void *ctx); +typedef int(ADOLC_ext_fct_v2_fos_reverse)(int iArrLen, int *iArr, int nout, + int nin, int *outsz, double **up, + int *insz, double **zp, double **x, + double **y, void *ctx); +typedef int(ADOLC_ext_fct_v2_fov_reverse)(int iArrLen, int *iArr, int nout, + int nin, int *outsz, int dir, + double ***Up, int *insz, double ***Zp, + double **x, double **y, void *ctx); /* The following two aren't implemented */ -typedef int (ADOLC_ext_fct_v2_hos_forward)(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, int degree, double ***Xp, int *outsz, double **y, double ***Yp, void* ctx); -typedef int (ADOLC_ext_fct_v2_hov_forward)(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, int degree, int ndir, double ****Xp, int *outsz, double **y, double ****Yp, void *ctx); +typedef int(ADOLC_ext_fct_v2_hos_forward)(int iArrLen, int *iArr, int nin, + int nout, int *insz, double **x, + int degree, double ***Xp, int *outsz, + double **y, double ***Yp, void *ctx); +typedef int(ADOLC_ext_fct_v2_hov_forward)(int iArrLen, int *iArr, int nin, + int nout, int *insz, double **x, + int degree, int ndir, double ****Xp, + int *outsz, double **y, double ****Yp, + void *ctx); typedef struct ext_diff_fct_v2 { - /** + /** * DO NOT touch - the function pointer is set through reg_ext_fct */ ADOLC_ext_fct_v2 *function; @@ -42,54 +63,56 @@ typedef struct ext_diff_fct_v2 { locint index; /** - * below are function pointers used for call back from the corresponding ADOL-C trace interpreters; - * these function pointers are initialized to 0 by reg_ext_fct; - * the user needs to set eplicitly the function pointers for the trace interpreters called in the - * application driver + * below are function pointers used for call back from the corresponding + * ADOL-C trace interpreters; these function pointers are initialized to 0 by + * reg_ext_fct; the user needs to set eplicitly the function pointers for the + * trace interpreters called in the application driver */ /** - * this points to a method implementing a forward execution of the externally differentiated function y=f(x); - * the pointer would typically be set to the same function pointer supplied in the call to reg_ext_fct, - * i.e. zos_forward would be equal to function (above) - * but there are cases when it makes sense for this to be different as illustrated - * in examples/additional_examples/ext_diff_func/ext_diff_func.cpp + * this points to a method implementing a forward execution of the externally + * differentiated function y=f(x); the pointer would typically be set to the + * same function pointer supplied in the call to reg_ext_fct, i.e. zos_forward + * would be equal to function (above) but there are cases when it makes sense + * for this to be different as illustrated in + * examples/additional_examples/ext_diff_func/ext_diff_func.cpp */ ADOLC_ext_fct_v2 *zos_forward; /** - * this points to a method implementing a forward execution of the externally differentiated function y=f(x) - * and computing the projection yp=Jacobian*xp + * this points to a method implementing a forward execution of the externally + * differentiated function y=f(x) and computing the projection yp=Jacobian*xp * see also the explanation of the xp,yp members below. */ ADOLC_ext_fct_v2_fos_forward *fos_forward; /** - * this points to a method implementing a forward execution of the externally differentiated function y=f(x) - * and computing the projection Yp=Jacobian*Xp + * this points to a method implementing a forward execution of the externally + * differentiated function y=f(x) and computing the projection Yp=Jacobian*Xp * see also the explanation of the Xp/Yp members below. */ ADOLC_ext_fct_v2_fov_forward *fov_forward; - /** - * this points to a method computing the projection zp=transpose(zp) * Jacobian - * see also the explanation of the up/zp members below. + /** + * this points to a method computing the projection zp=transpose(zp) * + * Jacobian see also the explanation of the up/zp members below. */ ADOLC_ext_fct_v2_fos_reverse *fos_reverse; /** - * this points to a method computing the projection Zp=transpose(Up) * Jacobian - * see also the explanation of the Up/Zp members below. + * this points to a method computing the projection Zp=transpose(Up) * + * Jacobian see also the explanation of the Up/Zp members below. */ ADOLC_ext_fct_v2_fov_reverse *fov_reverse; /** - * The names of the variables below correspond to the formal parameters names in the call back - * functions above; + * The names of the variables below correspond to the formal parameters names + * in the call back functions above; */ /** - * function and all _forward calls: function argument, dimension nin*insz[0..nin] + * function and all _forward calls: function argument, dimension + * nin*insz[0..nin] */ double **x; @@ -99,12 +122,14 @@ typedef struct ext_diff_fct_v2 { double **xp; /** - * fov_forward: seed matrix for p directions, dimensions nin*insz[0..nin]*p (p=nin*insz[0..nin]) + * fov_forward: seed matrix for p directions, dimensions nin*insz[0..nin]*p + * (p=nin*insz[0..nin]) */ double ***Xp; /** - * function and all _forward calls: function result, dimension nout*outsz[0..nout] + * function and all _forward calls: function result, dimension + * nout*outsz[0..nout] */ double **y; @@ -114,7 +139,8 @@ typedef struct ext_diff_fct_v2 { double **yp; /** - * fov_forward: Jacobian projection in p directions, dimension nout*outsz[0..nout]*p (p=nin*insz[0..nin]) + * fov_forward: Jacobian projection in p directions, dimension + * nout*outsz[0..nout]*p (p=nin*insz[0..nin]) */ double ***Yp; @@ -124,7 +150,8 @@ typedef struct ext_diff_fct_v2 { double **up; /** - * fov_reverse and hov_reverse: q weight vectors, dimensions (q=nout*outsz[0..nout]) q*nout*outsz[0..nout] + * fov_reverse and hov_reverse: q weight vectors, dimensions + * (q=nout*outsz[0..nout]) q*nout*outsz[0..nout] */ double ***Up; @@ -134,7 +161,8 @@ typedef struct ext_diff_fct_v2 { double **zp; /** - * fov_reverse: Jacobian projection for q weight vectors, dimensions (q=nout*outsz[0..nout]) q*nin*insz[0..nin] + * fov_reverse: Jacobian projection for q weight vectors, dimensions + * (q=nout*outsz[0..nout]) q*nin*insz[0..nin] */ double ***Zp; @@ -168,40 +196,37 @@ typedef struct ext_diff_fct_v2 { * This is a opaque context pointer that the user may set and use * in his implementation of the above functions */ - void* context; + void *context; /** * This is an all-memory pointer for allocating and deallocating * all other pointers can point to memory within here. */ - char* allmem; + char *allmem; /** * This is a reference to an object for the C++ object-oriented * implementation of the external function ** do not touch ** */ - void* obj; + void *obj; /** - * This flag indicates that user allocates memory and internally no + * This flag indicates that user allocates memory and internally no * memory should be allocated */ char user_allocated_mem; -} -ext_diff_fct_v2; +} ext_diff_fct_v2; END_C_DECLS -#if defined(__cplusplus) + #if defined(__cplusplus) ADOLC_DLL_EXPORT ext_diff_fct_v2 *reg_ext_fct(ADOLC_ext_fct_v2 ext_fct); -ADOLC_DLL_EXPORT int call_ext_fct (ext_diff_fct_v2 *edfct, - int iArrLen, int* iArr, - int nin, int nout, - int *insz, adouble **x, - int *outsz, adouble **y); +ADOLC_DLL_EXPORT int call_ext_fct(ext_diff_fct_v2 *edfct, int iArrLen, + int *iArr, int nin, int nout, int *insz, + adouble **x, int *outsz, adouble **y); ADOLC_DLL_EXPORT void edf_zero(ext_diff_fct_v2 *edfct); inline void edf_set_opaque_context(ext_diff_fct_v2 *edfct, void *ctx) { - edfct->context = ctx; + edfct->context = ctx; } -#endif + #endif #endif diff --git a/ADOL-C/include/adolc/fixpoint.h b/ADOL-C/include/adolc/fixpoint.h index 5b4de5099..c3f21f8fb 100644 --- a/ADOL-C/include/adolc/fixpoint.h +++ b/ADOL-C/include/adolc/fixpoint.h @@ -14,26 +14,19 @@ ----------------------------------------------------------------------------*/ #if !defined(ADOLC_FIXPOINT_H) -#define ADOLC_FIXPOINT_H 1 + #define ADOLC_FIXPOINT_H 1 -#include + #include BEGIN_C_DECLS -ADOLC_DLL_EXPORT int fp_iteration(int sub_tape_num, - int (*double_F)(double *, double *, double *, int, int), - int (*adouble_F)(adouble *, adouble *, adouble *, int, int), - double (*norm)(double *, int), - double (*norm_deriv)(double *, int), - double epsilon, - double epsilon_deriv, - int N_max, - int N_max_deriv, - adouble *x_0, - adouble *u, - adouble *x_fix, - int dim_x, - int dim_u); +ADOLC_DLL_EXPORT int +fp_iteration(int sub_tape_num, + int (*double_F)(double *, double *, double *, int, int), + int (*adouble_F)(adouble *, adouble *, adouble *, int, int), + double (*norm)(double *, int), double (*norm_deriv)(double *, int), + double epsilon, double epsilon_deriv, int N_max, int N_max_deriv, + adouble *x_0, adouble *u, adouble *x_fix, int dim_x, int dim_u); END_C_DECLS diff --git a/ADOL-C/include/adolc/fortutils.h b/ADOL-C/include/adolc/fortutils.h index e0b28d97c..6ff877c81 100644 --- a/ADOL-C/include/adolc/fortutils.h +++ b/ADOL-C/include/adolc/fortutils.h @@ -3,33 +3,33 @@ File: fortutils.h Revision: $Id$ Contents: Internal tools to handle Fortran arrays - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_FORTUTILS_H) -#define ADOLC_FORTUTILS_H 1 + #define ADOLC_FORTUTILS_H 1 -#include + #include /****************************************************************************/ /* Now the C THINGS */ BEGIN_C_DECLS -ADOLC_DLL_EXPORT void spread1(int m, fdouble* x, double* X); -ADOLC_DLL_EXPORT void pack1(int m, double* X, fdouble* x); +ADOLC_DLL_EXPORT void spread1(int m, fdouble *x, double *X); +ADOLC_DLL_EXPORT void pack1(int m, double *X, fdouble *x); -ADOLC_DLL_EXPORT void spread2(int m, int n, fdouble* x, double** X); -ADOLC_DLL_EXPORT void pack2(int m, int n, double** X, fdouble* x); +ADOLC_DLL_EXPORT void spread2(int m, int n, fdouble *x, double **X); +ADOLC_DLL_EXPORT void pack2(int m, int n, double **X, fdouble *x); -ADOLC_DLL_EXPORT void spread3(int m, int n, int p, fdouble* x, double*** X); -ADOLC_DLL_EXPORT void pack3(int m, int n, int p, double*** X, fdouble* x); +ADOLC_DLL_EXPORT void spread3(int m, int n, int p, fdouble *x, double ***X); +ADOLC_DLL_EXPORT void pack3(int m, int n, int p, double ***X, fdouble *x); END_C_DECLS diff --git a/ADOL-C/include/adolc/interfaces.h b/ADOL-C/include/adolc/interfaces.h index 57817ffb2..f3b11f35d 100644 --- a/ADOL-C/include/adolc/interfaces.h +++ b/ADOL-C/include/adolc/interfaces.h @@ -4,7 +4,7 @@ Revision: $Id$ Contents: Declaration of the standard interfaces to ADOL-C forward and reverse calls (C++, C and Fortran callable C functions). - + Functions prototyped here are defined in the files uni5_for.c for zos_forward.c @@ -14,19 +14,19 @@ hov_forward.c hov_wk_forward.c fo_rev.c for - fos_reverse.c - fov_reverse.c + fos_reverse.c + fov_reverse.c ho_rev.c for hos_reverse.c hos_ov_reverse.c - hov_reverse.c + hov_reverse.c hos_ti_reverse.c - hov_ti_reverse.c + hov_ti_reverse.c interfacesC.C interfacesf.c - + ADOL-C Abbreviations : - zos : zero-order-scalar mode + zos : zero-order-scalar mode fos : first-order-scalar mode hos : higher-order-scalar mode fov : first-order-vector mode @@ -34,29 +34,29 @@ wk : with keep ov : over vector (forward) ti : Taylor input - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_INTERFACES_H) -#define ADOLC_INTERFACES_H 1 + #define ADOLC_INTERFACES_H 1 -#include + #include -#if defined(SPARSE) -#include -#include -#endif + #if defined(SPARSE) + #include + #include + #endif -/****************************************************************************/ -/****************************************************************************/ -/* Now the C++ THINGS */ -#if defined(__cplusplus) + /****************************************************************************/ + /****************************************************************************/ + /* Now the C++ THINGS */ + #if defined(__cplusplus) /****************************************************************************/ /* FORWARD MODE, overloaded calls */ @@ -65,39 +65,39 @@ /* General scalar call. For d=0 or d=1 done by specialized code */ /* */ /* forward(tag, m, n, d, keep, X[n][d+1], Y[m][d+1]) : hos || fos || zos */ -ADOLC_DLL_EXPORT int forward(short, int, int, int, int, double**, double**); +ADOLC_DLL_EXPORT int forward(short, int, int, int, int, double **, double **); /*--------------------------------------------------------------------------*/ /* Y can be one dimensional if m=1. d=0 or d=1 done by specialized code */ /* */ /* forward(tag, m, n, d, keep, X[n][d+1], Y[d+1]) : hos || fos || zos */ -ADOLC_DLL_EXPORT int forward(short, int, int, int, int, double**, double*); +ADOLC_DLL_EXPORT int forward(short, int, int, int, int, double **, double *); /*--------------------------------------------------------------------------*/ /* X and Y can be one dimensional if d = 0; done by specialized code */ /* */ /* forward(tag, m, n, d, keep, X[n], Y[m]) : zos */ -ADOLC_DLL_EXPORT int forward(short, int, int, int, int, double*, double*); +ADOLC_DLL_EXPORT int forward(short, int, int, int, int, double *, double *); /*--------------------------------------------------------------------------*/ /* X and Y can be one dimensional if d omitted; done by specialized code */ /* */ /* forward(tag, m, n, keep, X[n], Y[m]) : zos */ -ADOLC_DLL_EXPORT int forward(short, int, int, int, double*, double*); +ADOLC_DLL_EXPORT int forward(short, int, int, int, double *, double *); /*--------------------------------------------------------------------------*/ /* General vector call */ /* */ /* forward(tag, m, n, d, p, x[n], X[n][p][d], y[m], Y[m][p][d]) : hov */ -ADOLC_DLL_EXPORT int forward(short, int, int, int, int, double*, double***, - double*, double***); +ADOLC_DLL_EXPORT int forward(short, int, int, int, int, double *, double ***, + double *, double ***); /*--------------------------------------------------------------------------*/ /* d = 1 may be omitted. General vector call, done by specialized code */ /* */ /* forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]) : fov */ -ADOLC_DLL_EXPORT int forward( - short, int, int, int, double*, double**, double*, double**); +ADOLC_DLL_EXPORT int forward(short, int, int, int, double *, double **, + double *, double **); /****************************************************************************/ /* REVERSE MODE, overloaded calls */ @@ -106,53 +106,53 @@ ADOLC_DLL_EXPORT int forward( /* General call */ /* */ /* reverse(tag, m, n, d, u[m], Z[n][d+1]) : hos */ -ADOLC_DLL_EXPORT int reverse(short, int, int, int, double*, double**); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, double *, double **); /*--------------------------------------------------------------------------*/ /* u can be a scalar if m=1 */ /* */ /* reverse(tag, m, n, d, u, Z[n][d+1]) : hos */ -ADOLC_DLL_EXPORT int reverse(short, int, int, int, double, double**); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, double, double **); /*--------------------------------------------------------------------------*/ /* Z can be vector if d = 0; done by specialized code */ /* */ /* reverse(tag, m, n, d, u[m], Z[n]) : fos */ -ADOLC_DLL_EXPORT int reverse(short, int, int, int, double*, double*); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, double *, double *); /*--------------------------------------------------------------------------*/ /* u can be a scalar if m=1 and d=0; done by specialized code */ /* */ /* reverse(tag, m, n, d, u, Z[n]) : fos */ -ADOLC_DLL_EXPORT int reverse(short, int, int, int, double, double*); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, double, double *); /*--------------------------------------------------------------------------*/ /* General vector call */ /* */ /* reverse(tag, m, n, d, q, U[q][m], Z[q][n][d+1], nz[q][n]) : hov */ -ADOLC_DLL_EXPORT int reverse( - short, int, int, int, int, double**, double***, short** =0); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, int, double **, double ***, + short ** = 0); /*--------------------------------------------------------------------------*/ /* U can be a vector if m=1 */ /* */ /* reverse(tag, m, n, d, q, U[q], Z[q][n][d+1], nz[q][n]) : hov */ -ADOLC_DLL_EXPORT int reverse( - short, int, int, int, int, double*, double***, short** = 0); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, int, double *, double ***, + short ** = 0); /*--------------------------------------------------------------------------*/ /* */ /* If d=0 then Z may be a matrix, no nz; done by specialized code */ /* */ /* reverse(tag, m, n, d, q, U[q][m], Z[q][n]) : fov */ -ADOLC_DLL_EXPORT int reverse(short, int, int, int, int, double**, double**); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, int, double **, double **); /*--------------------------------------------------------------------------*/ /* */ /* d=0 may be omitted, Z is a matrix, no nz; done by specialized code */ /* */ /* reverse(tag, m, n, q, U[q][m], Z[q][n]) : fov */ -ADOLC_DLL_EXPORT int reverse(short, int, int, int, double**, double**); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, double **, double **); /*--------------------------------------------------------------------------*/ /* */ @@ -160,16 +160,16 @@ ADOLC_DLL_EXPORT int reverse(short, int, int, int, double**, double**); /* Done by specialized code */ /* */ /* reverse(tag, m, n, d, q, U[q], Z[q][n]) : fov */ -ADOLC_DLL_EXPORT int reverse(short, int, int, int, int, double*, double**); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, int, double *, double **); /*--------------------------------------------------------------------------*/ /* */ /* If q and U are omitted they default to m and I so that as above */ /* */ /* reverse(tag, m, n, d, Z[q][n][d+1], nz[q][n]) : hov */ -ADOLC_DLL_EXPORT int reverse(short, int, int, int, double***, short** =0); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, double ***, short ** = 0); -#endif + #endif /****************************************************************************/ /****************************************************************************/ @@ -183,100 +183,105 @@ BEGIN_C_DECLS /* ZOS */ /* zos_forward(tag, m, n, keep, x[n], y[m]) */ /* (defined in uni5_for.c) */ -ADOLC_DLL_EXPORT int zos_forward(short,int,int,int,const double*,double*); +ADOLC_DLL_EXPORT int zos_forward(short, int, int, int, const double *, + double *); /* zos_forward_nk(tag, m, n, x[n], y[m]) */ /* (no keep, defined in uni5_for.c, but not supported in ADOL-C 1.8) */ -ADOLC_DLL_EXPORT int zos_forward_nk(short,int,int,const double*,double*); +ADOLC_DLL_EXPORT int zos_forward_nk(short, int, int, const double *, double *); /* zos_forward_partx(tag, m, n, ndim[n], x[n][d], y[m]) */ /* (based on zos_forward) */ -ADOLC_DLL_EXPORT int zos_forward_partx(short,int,int,int*,double**,double*); +ADOLC_DLL_EXPORT int zos_forward_partx(short, int, int, int *, double **, + double *); /*--------------------------------------------------------------------------*/ /* FOS */ /* fos_forward(tag, m, n, keep, x[n], X[n], y[m], Y[m]) */ /* (defined in uni5_for.c) */ -ADOLC_DLL_EXPORT int fos_forward( - short,int,int,int,const double*,const double*,double*,double*); +ADOLC_DLL_EXPORT int fos_forward(short, int, int, int, const double *, + const double *, double *, double *); /* fos_forward_nk(tag,m,n,x[n],X[n],y[m],Y[m]) */ /* (no keep, defined in uni5_for.c, but not supported in ADOL-C 1.8) */ -ADOLC_DLL_EXPORT int fos_forward_nk( - short,int,int,const double*,const double*,double*,double*); +ADOLC_DLL_EXPORT int fos_forward_nk(short, int, int, const double *, + const double *, double *, double *); /* fos_forward_partx(tag, m, n, ndim[n], x[n][][2], y[m][2]) */ /* (based on fos_forward) */ -ADOLC_DLL_EXPORT int fos_forward_partx( - short,int,int,int*,double***,double**); +ADOLC_DLL_EXPORT int fos_forward_partx(short, int, int, int *, double ***, + double **); /*--------------------------------------------------------------------------*/ /* HOS */ /* hos_forward(tag, m, n, d, keep, x[n], X[n][d], y[m], Y[m][d]) */ /* (defined in uni5_for.c) */ -ADOLC_DLL_EXPORT int hos_forward( - short,int,int,int,int,const double*,double**,double*,double**); +ADOLC_DLL_EXPORT int hos_forward(short, int, int, int, int, const double *, + double **, double *, double **); /* hos_forward_nk(tag, m, n, d, x[n], X[n][d], y[m], Y[m][d]) */ /* (no keep, defined in uni5_for.c, but not supported in ADOL-C 1.8) */ -ADOLC_DLL_EXPORT int hos_forward_nk( - short,int,int,int,const double*,double**,double*,double**); +ADOLC_DLL_EXPORT int hos_forward_nk(short, int, int, int, const double *, + double **, double *, double **); /* hos_forward_partx(tag, m, n, ndim[n], d, X[n][d+1], Y[m][d+1]) */ /* (defined in forward_partx.c) */ -ADOLC_DLL_EXPORT int hos_forward_partx( - short,int,int,int*,int,double***,double**); +ADOLC_DLL_EXPORT int hos_forward_partx(short, int, int, int *, int, double ***, + double **); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint hos_forward_( - fint*,fint*,fint*,fint*,fint*,fdouble*,fdouble*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint hos_forward_(fint *, fint *, fint *, fint *, fint *, + fdouble *, fdouble *, fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* FOV */ /* fov_forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]) */ /* (defined in uni5_for.c) */ -ADOLC_DLL_EXPORT int fov_forward( - short, int,int,int,const double*,double**,double*,double**); -ADOLC_DLL_EXPORT int fov_offset_forward( - short, int,int,int,int,const double*,double**,double*,double**); +ADOLC_DLL_EXPORT int fov_forward(short, int, int, int, const double *, + double **, double *, double **); +ADOLC_DLL_EXPORT int fov_offset_forward(short, int, int, int, int, + const double *, double **, double *, + double **); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint fov_forward_( - fint*,fint*,fint*,fint*,fdouble*,fdouble*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint fov_forward_(fint *, fint *, fint *, fint *, fdouble *, + fdouble *, fdouble *, fdouble *); /* fov_forward_partx(tag, m, n, ndim[n], p, */ /* x[n][], X[n][][p],y[m], Y[m][p]) */ -ADOLC_DLL_EXPORT int fov_forward_partx( - short, int, int, int*, int, double**, double***, double*, double**); +ADOLC_DLL_EXPORT int fov_forward_partx(short, int, int, int *, int, double **, + double ***, double *, double **); /*--------------------------------------------------------------------------*/ /* HOV */ /* hov_forward(tag, m, n, d, p, x[n], X[n][p][d], y[m], Y[m][p][d]) */ /* (defined in uni5_for.c) */ -ADOLC_DLL_EXPORT int hov_forward( - short,int,int,int,int,const double*,double***,double*,double***); +ADOLC_DLL_EXPORT int hov_forward(short, int, int, int, int, const double *, + double ***, double *, double ***); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint hov_forward_( - fint*,fint*,fint*,fint*,fint*,fdouble*,fdouble*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint hov_forward_(fint *, fint *, fint *, fint *, fint *, + fdouble *, fdouble *, fdouble *, fdouble *); /* hov_forward_partx(tag, m, n, ndim[n], d, p, */ /* x[n][], X[n][][p][d], y[m], Y[m][p][d]) */ -ADOLC_DLL_EXPORT int hov_forward_partx( - short, int, int, int*, int, int, - double**, double****, double*, double***); +ADOLC_DLL_EXPORT int hov_forward_partx(short, int, int, int *, int, int, + double **, double ****, double *, + double ***); /*--------------------------------------------------------------------------*/ /* HOV_WK */ /* hov_wk_forward(tag, m, n, d, keep, p, x[n], X[n][p][d], y[m], Y[m][p][d]) */ /* (defined in uni5_for.c) */ -ADOLC_DLL_EXPORT int hov_wk_forward( - short,int,int,int,int,int,const double*,double***,double*,double***); +ADOLC_DLL_EXPORT int hov_wk_forward(short, int, int, int, int, int, + const double *, double ***, double *, + double ***); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint hov_wk_forward_( - fint*,fint*,fint*,fint*,fint*,fint*,fdouble*,fdouble*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint hov_wk_forward_(fint *, fint *, fint *, fint *, fint *, + fint *, fdouble *, fdouble *, fdouble *, + fdouble *); /****************************************************************************/ /* BIT PATTERN UTILITIES */ @@ -284,16 +289,17 @@ ADOLC_DLL_EXPORT fint hov_wk_forward_( /* INT_FOR, SAFE */ /* int_forward_safe(tag, m, n, p, X[n][p], Y[m][p]) */ -ADOLC_DLL_EXPORT int int_forward_safe -(short, int, int, int, unsigned long int**, unsigned long int**); - +ADOLC_DLL_EXPORT int int_forward_safe(short, int, int, int, + unsigned long int **, + unsigned long int **); /*--------------------------------------------------------------------------*/ /* INT_FOR, TIGHT */ /* int_forward_tight(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]) */ -ADOLC_DLL_EXPORT int int_forward_tight -(short, int, int, int, const double*, unsigned long int**, double*, unsigned long int**); +ADOLC_DLL_EXPORT int int_forward_tight(short, int, int, int, const double *, + unsigned long int **, double *, + unsigned long int **); /****************************************************************************/ /* INDEX DOMAIN UTILITIES */ @@ -301,16 +307,15 @@ ADOLC_DLL_EXPORT int int_forward_tight /* INDOPRO, SAFE */ /* indopro_forward_safe(tag, m, n, p, x[n], *Y[m]) */ -ADOLC_DLL_EXPORT int indopro_forward_safe -(short, int, int, const double*, unsigned int**); - +ADOLC_DLL_EXPORT int indopro_forward_safe(short, int, int, const double *, + unsigned int **); /*--------------------------------------------------------------------------*/ /* INDOPRO, TIGHT */ /* indopro_forward_tight(tag, m, n, x[n], *Y[m]) */ -ADOLC_DLL_EXPORT int indopro_forward_tight -(short, int, int, const double*, unsigned int**); +ADOLC_DLL_EXPORT int indopro_forward_tight(short, int, int, const double *, + unsigned int **); /****************************************************************************/ /* NONLINEAR INDEX DOMAIN UTILITIES */ @@ -318,30 +323,28 @@ ADOLC_DLL_EXPORT int indopro_forward_tight /* INDOPRO, SAFE */ /* nonl_ind_forward_safe(tag, m, n, p, x[n], *Y[m]) */ -ADOLC_DLL_EXPORT int nonl_ind_forward_safe -(short, int, int, const double*, unsigned int**); - +ADOLC_DLL_EXPORT int nonl_ind_forward_safe(short, int, int, const double *, + unsigned int **); /*--------------------------------------------------------------------------*/ /* INDOPRO, TIGHT */ /* nonl_ind_forward_tight(tag, m, n, x[n], *Y[m]) */ -ADOLC_DLL_EXPORT int nonl_ind_forward_tight -(short, int, int, const double*, unsigned int**); +ADOLC_DLL_EXPORT int nonl_ind_forward_tight(short, int, int, const double *, + unsigned int **); /*--------------------------------------------------------------------------*/ /* INDOPRO, SAFE */ -/* nonl_ind_old_forward_safe(tag, m, n, p, x[n], *Y[m]) */ - -ADOLC_DLL_EXPORT int nonl_ind_old_forward_safe -(short, int, int, const double*, unsigned int**); +/* nonl_ind_old_forward_safe(tag, m, n, p, x[n], *Y[m]) */ +ADOLC_DLL_EXPORT int nonl_ind_old_forward_safe(short, int, int, const double *, + unsigned int **); /*--------------------------------------------------------------------------*/ /* INDOPRO, TIGHT */ -/* nonl_ind_old_forward_tight(tag, m, n, x[n], *Y[m]) */ +/* nonl_ind_old_forward_tight(tag, m, n, x[n], *Y[m]) */ -ADOLC_DLL_EXPORT int nonl_ind_old_forward_tight -(short, int, int, const double*, unsigned int**); +ADOLC_DLL_EXPORT int nonl_ind_old_forward_tight(short, int, int, const double *, + unsigned int **); /****************************************************************************/ /* REVERSE MODE */ @@ -350,70 +353,75 @@ ADOLC_DLL_EXPORT int nonl_ind_old_forward_tight /* FOS */ /* fos_reverse(tag, m, n, u[m], z[n]) */ /* (defined in fo_rev.c) */ -ADOLC_DLL_EXPORT int fos_reverse(short,int,int,double*,double*); +ADOLC_DLL_EXPORT int fos_reverse(short, int, int, double *, double *); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint fos_reverse_(fint*,fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint fos_reverse_(fint *, fint *, fint *, fdouble *, + fdouble *); /*--------------------------------------------------------------------------*/ /* HOS */ /* hos_reverse(tag, m, n, d, u[m], Z[n][d+1]) */ /* (defined in ho_rev.c) */ -ADOLC_DLL_EXPORT int hos_reverse(short,int,int,int,const double*,double**); +ADOLC_DLL_EXPORT int hos_reverse(short, int, int, int, const double *, + double **); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint hos_reverse_(fint*,fint*,fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint hos_reverse_(fint *, fint *, fint *, fint *, fdouble *, + fdouble *); /*--------------------------------------------------------------------------*/ /* HOS_TI */ /* hos_ti_reverse(tag, m, n, d, U[m][d+1], Z[n][d+1]) */ /* (defined in ho_rev.c) */ -ADOLC_DLL_EXPORT int hos_ti_reverse(short,int,int,int,double**,double**); +ADOLC_DLL_EXPORT int hos_ti_reverse(short, int, int, int, double **, double **); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint hos_ti_reverse_( - fint*,fint*,fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint hos_ti_reverse_(fint *, fint *, fint *, fint *, fdouble *, + fdouble *); /*--------------------------------------------------------------------------*/ /* HOS_OV */ /* hos_ov_reverse(tag, m, n, d, p, U[m][d+1], Z[p][n][d+1]) */ /* (defined in ho_rev.c) */ -ADOLC_DLL_EXPORT int hos_ov_reverse(short,int,int,int,int,double**,double***); +ADOLC_DLL_EXPORT int hos_ov_reverse(short, int, int, int, int, double **, + double ***); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint hos_ov_reverse_( - fint*,fint*,fint*,fint*,fint*,fdouble*,fdouble***); +ADOLC_DLL_EXPORT fint hos_ov_reverse_(fint *, fint *, fint *, fint *, fint *, + fdouble *, fdouble ***); /*--------------------------------------------------------------------------*/ /* FOV */ /* fov_reverse(tag, m, n, p, U[p][m], Z[p][n]) */ /* (defined in fo_rev.c) */ -ADOLC_DLL_EXPORT int fov_reverse(short,int,int,int,double**,double**); +ADOLC_DLL_EXPORT int fov_reverse(short, int, int, int, double **, double **); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint fov_reverse_(fint*,fint*,fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint fov_reverse_(fint *, fint *, fint *, fint *, fdouble *, + fdouble *); /*--------------------------------------------------------------------------*/ /* HOV */ /* hov_reverse(tag, m, n, d, p, U[p][m], Z[p][n][d+1], nz[p][n]) */ /* (defined in ho_rev.c) */ -ADOLC_DLL_EXPORT int hov_reverse( - short,int,int,int,int,double**,double***,short**); +ADOLC_DLL_EXPORT int hov_reverse(short, int, int, int, int, double **, + double ***, short **); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint hov_reverse_( - fint*,fint*,fint*,fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint hov_reverse_(fint *, fint *, fint *, fint *, fint *, + fdouble *, fdouble *); /*--------------------------------------------------------------------------*/ /* HOV_TI */ /* hov_ti_reverse(tag, m, n, d, p, U[p][m][d+1], Z[p][n][d+1], nz[p][n]) */ /* (defined in ho_rev.c) */ -ADOLC_DLL_EXPORT int hov_ti_reverse( - short,int,int,int,int,double***,double***,short**); +ADOLC_DLL_EXPORT int hov_ti_reverse(short, int, int, int, int, double ***, + double ***, short **); /* now pack the arrays into vectors for Fortran calling */ -ADOLC_DLL_EXPORT fint hov_ti_reverse_( - fint*,fint*,fint*,fint*,fint*,fdouble*,fdouble*); +ADOLC_DLL_EXPORT fint hov_ti_reverse_(fint *, fint *, fint *, fint *, fint *, + fdouble *, fdouble *); /****************************************************************************/ /* BIT PATTERN UTILITIES */ @@ -421,31 +429,44 @@ ADOLC_DLL_EXPORT fint hov_ti_reverse_( /* INT_REV, TIGHT */ /* int_reverse_tight(tag, m, n, q, U[q][m], Z[q][n]) */ -ADOLC_DLL_EXPORT int int_reverse_tight -(short, int, int, int, unsigned long int**, unsigned long int**); - +ADOLC_DLL_EXPORT int int_reverse_tight(short, int, int, int, + unsigned long int **, + unsigned long int **); /*--------------------------------------------------------------------------*/ /* INT_REV, SAFE */ /* int_reverse_safe(tag, m, n, q, U[q][m], Z[q][n]) */ -ADOLC_DLL_EXPORT int int_reverse_safe -(short, int, int, int, unsigned long int**, unsigned long int**); +ADOLC_DLL_EXPORT int int_reverse_safe(short, int, int, int, + unsigned long int **, + unsigned long int **); /*--------------------------------------------------------------------------*/ ADOLC_DLL_EXPORT int get_num_switches(short); -ADOLC_DLL_EXPORT int zos_pl_forward(short,int,int,int,const double*,double*,double*); -ADOLC_DLL_EXPORT short firstsign(int, double*, double*); -ADOLC_DLL_EXPORT short ext_firstsign(double,double,int,double*,double*); -ADOLC_DLL_EXPORT short ext_firstsign2(double,int,double*,double*); -ADOLC_DLL_EXPORT int fos_pl_forward(short,int,int,const double*,double*,double*,double*,double*,double*); -ADOLC_DLL_EXPORT int fov_pl_forward(short,int,int,int,const double*,double**,double*,double**,double*,double**,short*); -ADOLC_DLL_EXPORT int fos_pl_sig_forward(short,int,int,const double*,double*,int,short*,short*,double*,double*,double*,double*,short*); -ADOLC_DLL_EXPORT int fov_pl_sig_forward(short,int,int,int,const double*,double**,int,short*,short*,double*,double**,double*,double**,short*); -ADOLC_DLL_EXPORT int indopro_forward_absnormal(short,int,int,int,const double*,unsigned int**); -/*--------------------------------------------------------------------------*/ -ADOLC_DLL_EXPORT int fos_pl_reverse(short,int,int,int,int,double*); -ADOLC_DLL_EXPORT int fos_pl_sig_reverse(short,int,int,int,short*,double*,double*); +ADOLC_DLL_EXPORT int zos_pl_forward(short, int, int, int, const double *, + double *, double *); +ADOLC_DLL_EXPORT short firstsign(int, double *, double *); +ADOLC_DLL_EXPORT short ext_firstsign(double, double, int, double *, double *); +ADOLC_DLL_EXPORT short ext_firstsign2(double, int, double *, double *); +ADOLC_DLL_EXPORT int fos_pl_forward(short, int, int, const double *, double *, + double *, double *, double *, double *); +ADOLC_DLL_EXPORT int fov_pl_forward(short, int, int, int, const double *, + double **, double *, double **, double *, + double **, short *); +ADOLC_DLL_EXPORT int fos_pl_sig_forward(short, int, int, const double *, + double *, int, short *, short *, + double *, double *, double *, double *, + short *); +ADOLC_DLL_EXPORT int fov_pl_sig_forward(short, int, int, int, const double *, + double **, int, short *, short *, + double *, double **, double *, + double **, short *); +ADOLC_DLL_EXPORT int indopro_forward_absnormal(short, int, int, int, + const double *, unsigned int **); +/*--------------------------------------------------------------------------*/ +ADOLC_DLL_EXPORT int fos_pl_reverse(short, int, int, int, int, double *); +ADOLC_DLL_EXPORT int fos_pl_sig_reverse(short, int, int, int, short *, double *, + double *); END_C_DECLS diff --git a/ADOL-C/include/adolc/internal/adubfunc.h b/ADOL-C/include/adolc/internal/adubfunc.h index 6650892ee..74734ee55 100644 --- a/ADOL-C/include/adolc/internal/adubfunc.h +++ b/ADOL-C/include/adolc/internal/adubfunc.h @@ -3,92 +3,92 @@ File: adubfunc.h Revision: $Id$ Contents: operators and functions returning temporaries - + Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ #if defined(_IN_CLASS_) && _IN_CLASS_ -#if defined(_IN_BADOUBLE_) || defined(_IN_ADUB_) - /*--------------------------------------------------------------------------*/ - /* Comparison (friends) */ -#if defined(ADOLC_ADVANCED_BRANCHING) && !defined(SWIGPRE) - friend ADOLC_DLL_EXPORT adub operator != ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator == ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator <= ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator >= ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator > ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator < ( const badouble&, const badouble& ); -#endif + #if defined(_IN_BADOUBLE_) || defined(_IN_ADUB_) + /*--------------------------------------------------------------------------*/ + /* Comparison (friends) */ + #if defined(ADOLC_ADVANCED_BRANCHING) && !defined(SWIGPRE) +friend ADOLC_DLL_EXPORT adub operator!=(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator==(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator<=(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator>=(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator>(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator<(const badouble &, const badouble &); + #endif -#if !defined(SWIGPRE) - /*--------------------------------------------------------------------------*/ - /* sign operators (friends) */ - friend ADOLC_DLL_EXPORT adub operator + ( const badouble& x ); - friend ADOLC_DLL_EXPORT adub operator - ( const badouble& x ); + #if !defined(SWIGPRE) +/*--------------------------------------------------------------------------*/ +/* sign operators (friends) */ +friend ADOLC_DLL_EXPORT adub operator+(const badouble &x); +friend ADOLC_DLL_EXPORT adub operator-(const badouble &x); - /*--------------------------------------------------------------------------*/ - /* binary operators (friends) */ - friend ADOLC_DLL_EXPORT adub operator + ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator + ( double, const badouble& ); - inline friend adub operator + ( const badouble&, double ); - friend ADOLC_DLL_EXPORT adub operator - ( const badouble&, const badouble& ); - inline friend adub operator - ( const badouble&, double ); - friend ADOLC_DLL_EXPORT adub operator - ( double, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator * ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator * ( double, const badouble& ); - inline friend adub operator * ( const badouble&, double ); - inline friend adub operator / ( const badouble&, double ); - friend ADOLC_DLL_EXPORT adub operator / ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator / ( double, const badouble& ); +/*--------------------------------------------------------------------------*/ +/* binary operators (friends) */ +friend ADOLC_DLL_EXPORT adub operator+(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator+(double, const badouble &); +inline friend adub operator+(const badouble &, double); +friend ADOLC_DLL_EXPORT adub operator-(const badouble &, const badouble &); +inline friend adub operator-(const badouble &, double); +friend ADOLC_DLL_EXPORT adub operator-(double, const badouble &); +friend ADOLC_DLL_EXPORT adub operator*(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator*(double, const badouble &); +inline friend adub operator*(const badouble &, double); +inline friend adub operator/(const badouble &, double); +friend ADOLC_DLL_EXPORT adub operator/(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator/(double, const badouble &); - /*--------------------------------------------------------------------------*/ - /* unary operators (friends) */ - friend ADOLC_DLL_EXPORT adub exp ( const badouble& ); - friend ADOLC_DLL_EXPORT adub log ( const badouble& ); - friend ADOLC_DLL_EXPORT adub sqrt ( const badouble& ); - friend ADOLC_DLL_EXPORT adub cbrt ( const badouble& ); - friend ADOLC_DLL_EXPORT adub sin ( const badouble& ); - friend ADOLC_DLL_EXPORT adub cos ( const badouble& ); - friend ADOLC_DLL_EXPORT adub tan ( const badouble& ); - friend ADOLC_DLL_EXPORT adub asin ( const badouble& ); - friend ADOLC_DLL_EXPORT adub acos ( const badouble& ); - friend ADOLC_DLL_EXPORT adub atan ( const badouble& ); +/*--------------------------------------------------------------------------*/ +/* unary operators (friends) */ +friend ADOLC_DLL_EXPORT adub exp(const badouble &); +friend ADOLC_DLL_EXPORT adub log(const badouble &); +friend ADOLC_DLL_EXPORT adub sqrt(const badouble &); +friend ADOLC_DLL_EXPORT adub cbrt(const badouble &); +friend ADOLC_DLL_EXPORT adub sin(const badouble &); +friend ADOLC_DLL_EXPORT adub cos(const badouble &); +friend ADOLC_DLL_EXPORT adub tan(const badouble &); +friend ADOLC_DLL_EXPORT adub asin(const badouble &); +friend ADOLC_DLL_EXPORT adub acos(const badouble &); +friend ADOLC_DLL_EXPORT adub atan(const badouble &); - /*--------------------------------------------------------------------------*/ - /* special operators (friends) */ - /* no internal use of condassign: */ - friend ADOLC_DLL_EXPORT adub pow ( const badouble&, double ); - friend ADOLC_DLL_EXPORT adub log10 ( const badouble& ); +/*--------------------------------------------------------------------------*/ +/* special operators (friends) */ +/* no internal use of condassign: */ +friend ADOLC_DLL_EXPORT adub pow(const badouble &, double); +friend ADOLC_DLL_EXPORT adub log10(const badouble &); - /* Additional ANSI C standard Math functions Added by DWJ on 8/6/90 */ - friend ADOLC_DLL_EXPORT adub sinh ( const badouble& ); - friend ADOLC_DLL_EXPORT adub cosh ( const badouble& ); - friend ADOLC_DLL_EXPORT adub tanh ( const badouble& ); - friend ADOLC_DLL_EXPORT adub asinh ( const badouble& ); - friend ADOLC_DLL_EXPORT adub acosh ( const badouble& ); - friend ADOLC_DLL_EXPORT adub atanh ( const badouble& ); - friend ADOLC_DLL_EXPORT adub erf ( const badouble& ); - friend ADOLC_DLL_EXPORT adub erfc ( const badouble& ); +/* Additional ANSI C standard Math functions Added by DWJ on 8/6/90 */ +friend ADOLC_DLL_EXPORT adub sinh(const badouble &); +friend ADOLC_DLL_EXPORT adub cosh(const badouble &); +friend ADOLC_DLL_EXPORT adub tanh(const badouble &); +friend ADOLC_DLL_EXPORT adub asinh(const badouble &); +friend ADOLC_DLL_EXPORT adub acosh(const badouble &); +friend ADOLC_DLL_EXPORT adub atanh(const badouble &); +friend ADOLC_DLL_EXPORT adub erf(const badouble &); +friend ADOLC_DLL_EXPORT adub erfc(const badouble &); - friend ADOLC_DLL_EXPORT adub fabs ( const badouble& ); - friend ADOLC_DLL_EXPORT adub ceil ( const badouble& ); - friend ADOLC_DLL_EXPORT adub floor ( const badouble& ); +friend ADOLC_DLL_EXPORT adub fabs(const badouble &); +friend ADOLC_DLL_EXPORT adub ceil(const badouble &); +friend ADOLC_DLL_EXPORT adub floor(const badouble &); - friend ADOLC_DLL_EXPORT adub fmax ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub fmax ( double, const badouble& ); - friend ADOLC_DLL_EXPORT adub fmax ( const badouble&, double ); - friend ADOLC_DLL_EXPORT adub fmin ( const badouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub fmin ( double, const badouble& ); - friend ADOLC_DLL_EXPORT adub fmin ( const badouble&, double ); +friend ADOLC_DLL_EXPORT adub fmax(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub fmax(double, const badouble &); +friend ADOLC_DLL_EXPORT adub fmax(const badouble &, double); +friend ADOLC_DLL_EXPORT adub fmin(const badouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub fmin(double, const badouble &); +friend ADOLC_DLL_EXPORT adub fmin(const badouble &, double); - friend ADOLC_DLL_EXPORT adub ldexp ( const badouble&, int ); - friend ADOLC_DLL_EXPORT adub frexp ( const badouble&, int* ); +friend ADOLC_DLL_EXPORT adub ldexp(const badouble &, int); +friend ADOLC_DLL_EXPORT adub frexp(const badouble &, int *); /*--------------------------------------------------------------------------*/ -#endif -#endif + #endif + #endif #endif diff --git a/ADOL-C/include/adolc/internal/common.h b/ADOL-C/include/adolc/internal/common.h index 06532c859..f8640bf44 100644 --- a/ADOL-C/include/adolc/internal/common.h +++ b/ADOL-C/include/adolc/internal/common.h @@ -2,118 +2,137 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: common.h Revision: $Id$ - Contents: Common (global) ADOL-C header - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Contents: Common (global) ADOL-C header + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_COMMON_H) -#define ADOLC_COMMON_H 1 - -#include -/*--------------------------------------------------------------------------*/ -/* standard includes */ -#if !defined(__cplusplus) -# include -# include -#else -# include -# include -#endif + #define ADOLC_COMMON_H 1 + + #include + /*--------------------------------------------------------------------------*/ + /* standard includes */ + #if !defined(__cplusplus) + #include + #include + #else + #include + #include + #endif /*--------------------------------------------------------------------------*/ /* type definitions */ - typedef unsigned int uint; - -/*--------------------------------------------------------------------------*/ -/* OpenMP includes */ -#if defined(_OPENMP) -#include -#endif - -/*--------------------------------------------------------------------------*/ -/* system dependent configuration */ -#if defined(ADOLC_INTERNAL) -# if HAVE_CONFIG_H -# include "config.h" - -/* malloc/calloc/realloc replacements */ -# undef ADOLC_NO_MALLOC -# undef ADOLC_NO_REALLOC -# if !defined(HAVE_MALLOC) -# define ADOLC_NO_MALLOC 1 -# else -# if (HAVE_MALLOC == 0) -# define ADOLC_NO_MALLOC 1 -# endif /* HAVE_MALLOC == 0 */ -# endif /* HAVE_MALLOC */ -# if !defined(HAVE_REALLOC) -# define ADOLC_NO_REALLOC 1 -# else -# if (HAVE_REALLOC == 0) -# define ADOLC_NO_REALLOC 1 -# endif /* HAVE_REALLOC == 0 */ -# endif /* HAVE_REALLOC */ - -# if defined(ADOLC_NO_MALLOC) -# include "rpl_malloc.h" -# define malloc rpl_malloc -# define calloc rpl_calloc -# endif /* ADOLC_NO_MALLOC */ -# if defined(ADOLC_NO_REALLOC) -# include "rpl_malloc.h" -# define realloc rpl_realloc -# endif /* ADOLC_NO_REALLOC */ - -# ifndef HAVE_TRUNC -# define trunc(x) ( (x<0) ? ceil(x) : floor(x) ) -# endif - -# endif /* HAVE_CONFIG_H */ -#endif /* ADOLC_INTERNAL */ +typedef unsigned int uint; + + /*--------------------------------------------------------------------------*/ + /* OpenMP includes */ + #if defined(_OPENMP) + #include + #endif + + /*--------------------------------------------------------------------------*/ + /* system dependent configuration */ + #if defined(ADOLC_INTERNAL) + #if HAVE_CONFIG_H + #include "config.h" + + /* malloc/calloc/realloc replacements */ + #undef ADOLC_NO_MALLOC + #undef ADOLC_NO_REALLOC + #if !defined(HAVE_MALLOC) + #define ADOLC_NO_MALLOC 1 + #else + #if (HAVE_MALLOC == 0) + #define ADOLC_NO_MALLOC 1 + #endif /* HAVE_MALLOC == 0 */ + #endif /* HAVE_MALLOC */ + #if !defined(HAVE_REALLOC) + #define ADOLC_NO_REALLOC 1 + #else + #if (HAVE_REALLOC == 0) + #define ADOLC_NO_REALLOC 1 + #endif /* HAVE_REALLOC == 0 */ + #endif /* HAVE_REALLOC */ + + #if defined(ADOLC_NO_MALLOC) + #include "rpl_malloc.h" + #define malloc rpl_malloc + #define calloc rpl_calloc + #endif /* ADOLC_NO_MALLOC */ + #if defined(ADOLC_NO_REALLOC) + #include "rpl_malloc.h" + #define realloc rpl_realloc + #endif /* ADOLC_NO_REALLOC */ + + #ifndef HAVE_TRUNC + #define trunc(x) ((x < 0) ? ceil(x) : floor(x)) + #endif + + #endif /* HAVE_CONFIG_H */ + #endif /* ADOLC_INTERNAL */ + + /*--------------------------------------------------------------------------*/ + /* user parameters and settings */ + #include + #include + + /*--------------------------------------------------------------------------*/ + /* windows dll exports/imports */ + #if defined(ADOLC_DLL) + #define ADOLC_DLL_EXPORT __declspec(dllexport) + #define ADOLC_DLL_EXPIMP __declspec(dllexport) + #elif defined(_MSC_VER) + #define ADOLC_DLL_EXPORT + #define ADOLC_DLL_EXPIMP __declspec(dllimport) + #else + #define ADOLC_DLL_EXPORT + #define ADOLC_DLL_EXPIMP + #endif + + /*--------------------------------------------------------------------------*/ + /* further helpful macros */ + #if defined(__cplusplus) + #define BEGIN_C_DECLS extern "C" { + #define END_C_DECLS } + #else + #define BEGIN_C_DECLS + #define END_C_DECLS + #endif + + #define MAXDEC(a, b) \ + do { \ + revreal __r = (b); \ + if (__r > (a)) \ + (a) = __r; \ + } while (0) + #define MAXDECI(a, b) \ + do { \ + int __r = (b); \ + if (__r > (a)) \ + (a) = __r; \ + } while (0) + #define MINDECR(a, b) \ + do { \ + revreal __r = (b); \ + if (__r < (a)) \ + (a) = __r; \ + } while (0) + #define MINDEC(a, b) \ + do { \ + int __r = (b); \ + if (__r < (a)) \ + (a) = __r; \ + } while (0) + + #define MAX_ADOLC(a, b) ((a) < (b) ? (b) : (a)) + #define MIN_ADOLC(a, b) ((a) > (b) ? (b) : (a)) /*--------------------------------------------------------------------------*/ -/* user parameters and settings */ -#include -#include - -/*--------------------------------------------------------------------------*/ -/* windows dll exports/imports */ -#if defined(ADOLC_DLL) -# define ADOLC_DLL_EXPORT __declspec(dllexport) -# define ADOLC_DLL_EXPIMP __declspec(dllexport) -#elif defined(_MSC_VER) -# define ADOLC_DLL_EXPORT -# define ADOLC_DLL_EXPIMP __declspec(dllimport) -#else -# define ADOLC_DLL_EXPORT -# define ADOLC_DLL_EXPIMP -#endif - -/*--------------------------------------------------------------------------*/ -/* further helpful macros */ -#if defined(__cplusplus) -# define BEGIN_C_DECLS extern "C" { -# define END_C_DECLS } -#else -# define BEGIN_C_DECLS -# define END_C_DECLS #endif - -#define MAXDEC(a,b) do { revreal __r = (b); if ( __r > (a) ) (a) = __r; } while (0) -#define MAXDECI(a,b) do { int __r = (b); if ( __r > (a) ) (a) = __r; } while (0) -#define MINDECR(a,b) do { revreal __r = (b); if ( __r < (a) ) (a) = __r; } while (0) -#define MINDEC(a,b) do { int __r = (b); if ( __r < (a) ) (a) = __r; } while (0) - -#define MAX_ADOLC(a,b) ( (a)<(b)? (b):(a) ) -#define MIN_ADOLC(a,b) ( (a)>(b)? (b):(a) ) - -/*--------------------------------------------------------------------------*/ -#endif - diff --git a/ADOL-C/include/adolc/internal/paramfunc.h b/ADOL-C/include/adolc/internal/paramfunc.h index 40cc84f2d..39849505b 100644 --- a/ADOL-C/include/adolc/internal/paramfunc.h +++ b/ADOL-C/include/adolc/internal/paramfunc.h @@ -3,118 +3,118 @@ File: paramfunc.h Revision: $Id$ Contents: operators for parameter dependent functions - + Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ #if defined(_IN_CLASS_) && _IN_CLASS_ -#if defined(_IN_BADOUBLE_) || defined(_IN_ADUB_) || defined(_IN_PDOUBLE_) + #if defined(_IN_BADOUBLE_) || defined(_IN_ADUB_) || defined(_IN_PDOUBLE_) -#if defined(ADOLC_ADVANCED_BRANCHING) && !defined(SWIGPRE) - inline friend adub operator != ( const pdouble&, const badouble&); - friend ADOLC_DLL_EXPORT adub operator != ( const badouble&, const pdouble&); - inline friend adub operator == ( const pdouble&, const badouble&); - friend ADOLC_DLL_EXPORT adub operator == ( const badouble&, const pdouble&); - inline friend adub operator <= ( const pdouble&, const badouble&); - friend ADOLC_DLL_EXPORT adub operator <= ( const badouble&, const pdouble&); - inline friend adub operator >= ( const pdouble&, const badouble&); - friend ADOLC_DLL_EXPORT adub operator >= ( const badouble&, const pdouble&); - inline friend adub operator > ( const pdouble&, const badouble&); - friend ADOLC_DLL_EXPORT adub operator > ( const badouble&, const pdouble&); - inline friend adub operator < ( const pdouble&, const badouble&); - friend ADOLC_DLL_EXPORT adub operator < ( const badouble&, const pdouble&); -#else -#if defined(_IN_BADOUBLE_) || defined(_IN_PDOUBLE_) - inline friend int operator != ( const pdouble&, const badouble&); - inline friend int operator != ( const badouble&, const pdouble&); - inline friend int operator == ( const pdouble&, const badouble&); - inline friend int operator == ( const badouble&, const pdouble&); - inline friend int operator <= ( const pdouble&, const badouble&); - inline friend int operator <= ( const badouble&, const pdouble&); - inline friend int operator >= ( const pdouble&, const badouble&); - inline friend int operator >= ( const badouble&, const pdouble&); - inline friend int operator > ( const pdouble&, const badouble&); - inline friend int operator > ( const badouble&, const pdouble&); - inline friend int operator < ( const pdouble&, const badouble&); - inline friend int operator < ( const badouble&, const pdouble&); -#endif -#endif + #if defined(ADOLC_ADVANCED_BRANCHING) && !defined(SWIGPRE) +inline friend adub operator!=(const pdouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator!=(const badouble &, const pdouble &); +inline friend adub operator==(const pdouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator==(const badouble &, const pdouble &); +inline friend adub operator<=(const pdouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator<=(const badouble &, const pdouble &); +inline friend adub operator>=(const pdouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator>=(const badouble &, const pdouble &); +inline friend adub operator>(const pdouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator>(const badouble &, const pdouble &); +inline friend adub operator<(const pdouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator<(const badouble &, const pdouble &); + #else + #if defined(_IN_BADOUBLE_) || defined(_IN_PDOUBLE_) +inline friend int operator!=(const pdouble &, const badouble &); +inline friend int operator!=(const badouble &, const pdouble &); +inline friend int operator==(const pdouble &, const badouble &); +inline friend int operator==(const badouble &, const pdouble &); +inline friend int operator<=(const pdouble &, const badouble &); +inline friend int operator<=(const badouble &, const pdouble &); +inline friend int operator>=(const pdouble &, const badouble &); +inline friend int operator>=(const badouble &, const pdouble &); +inline friend int operator>(const pdouble &, const badouble &); +inline friend int operator>(const badouble &, const pdouble &); +inline friend int operator<(const pdouble &, const badouble &); +inline friend int operator<(const badouble &, const pdouble &); + #endif + #endif -#if !defined(SWIGPRE) - inline friend adub operator + ( const pdouble&, const badouble&); - inline friend adub operator + ( const pdouble&, double); - inline friend adub operator + ( double, const pdouble&); - friend ADOLC_DLL_EXPORT adub operator + ( const badouble&, const pdouble&); - friend ADOLC_DLL_EXPORT adub operator - ( const pdouble&); - friend ADOLC_DLL_EXPORT adub operator - ( const badouble&, const pdouble&); - inline friend adub operator - ( const pdouble&, double ); - inline friend adub operator - ( double, const pdouble& ); - inline friend adub operator - ( const pdouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub operator * ( const badouble&, const pdouble&); - inline friend adub operator * ( const pdouble&, const badouble& ); - inline friend adub operator * ( const pdouble&, double ); - inline friend adub operator * ( double, const pdouble& ); - friend ADOLC_DLL_EXPORT adub recipr( const pdouble& ); - inline friend adub operator / ( const badouble&, const pdouble& ); - inline friend adub operator / ( double, const pdouble& ); - inline friend adub operator / ( const pdouble&, double ); - friend ADOLC_DLL_EXPORT adub operator / ( const pdouble&, const badouble& ); - friend ADOLC_DLL_EXPORT adub pow ( const badouble&, const pdouble& ); - inline friend adub fmax ( const pdouble&, const badouble& ); - inline friend adub fmax ( const badouble&, const pdouble& ); - inline friend adub fmin ( const pdouble&, const badouble& ); - inline friend adub fmin ( const badouble&, const pdouble& ); - /*--------------------------------------------------------------------------*/ - /* unary operators (friends) */ - inline friend ADOLC_DLL_EXPORT adub exp ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub log ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub sqrt ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub cbrt ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub sin ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub cos ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub tan ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub asin ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub acos ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub atan ( const pdouble& ); + #if !defined(SWIGPRE) +inline friend adub operator+(const pdouble &, const badouble &); +inline friend adub operator+(const pdouble &, double); +inline friend adub operator+(double, const pdouble &); +friend ADOLC_DLL_EXPORT adub operator+(const badouble &, const pdouble &); +friend ADOLC_DLL_EXPORT adub operator-(const pdouble &); +friend ADOLC_DLL_EXPORT adub operator-(const badouble &, const pdouble &); +inline friend adub operator-(const pdouble &, double); +inline friend adub operator-(double, const pdouble &); +inline friend adub operator-(const pdouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub operator*(const badouble &, const pdouble &); +inline friend adub operator*(const pdouble &, const badouble &); +inline friend adub operator*(const pdouble &, double); +inline friend adub operator*(double, const pdouble &); +friend ADOLC_DLL_EXPORT adub recipr(const pdouble &); +inline friend adub operator/(const badouble &, const pdouble &); +inline friend adub operator/(double, const pdouble &); +inline friend adub operator/(const pdouble &, double); +friend ADOLC_DLL_EXPORT adub operator/(const pdouble &, const badouble &); +friend ADOLC_DLL_EXPORT adub pow(const badouble &, const pdouble &); +inline friend adub fmax(const pdouble &, const badouble &); +inline friend adub fmax(const badouble &, const pdouble &); +inline friend adub fmin(const pdouble &, const badouble &); +inline friend adub fmin(const badouble &, const pdouble &); +/*--------------------------------------------------------------------------*/ +/* unary operators (friends) */ +inline friend ADOLC_DLL_EXPORT adub exp(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub log(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub sqrt(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub cbrt(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub sin(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub cos(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub tan(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub asin(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub acos(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub atan(const pdouble &); - /*--------------------------------------------------------------------------*/ - /* special operators (friends) */ - /* no internal use of condassign: */ - inline friend ADOLC_DLL_EXPORT adub pow ( const pdouble&, double ); - inline friend ADOLC_DLL_EXPORT adub log10 ( const pdouble& ); +/*--------------------------------------------------------------------------*/ +/* special operators (friends) */ +/* no internal use of condassign: */ +inline friend ADOLC_DLL_EXPORT adub pow(const pdouble &, double); +inline friend ADOLC_DLL_EXPORT adub log10(const pdouble &); - /* Additional ANSI C standard Math functions Added by DWJ on 8/6/90 */ - inline friend ADOLC_DLL_EXPORT adub sinh ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub cosh ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub tanh ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub asinh ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub acosh ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub atanh ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub erf ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub erfc ( const pdouble& ); +/* Additional ANSI C standard Math functions Added by DWJ on 8/6/90 */ +inline friend ADOLC_DLL_EXPORT adub sinh(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub cosh(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub tanh(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub asinh(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub acosh(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub atanh(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub erf(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub erfc(const pdouble &); - inline friend ADOLC_DLL_EXPORT adub fabs ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub ceil ( const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub floor ( const pdouble& ); +inline friend ADOLC_DLL_EXPORT adub fabs(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub ceil(const pdouble &); +inline friend ADOLC_DLL_EXPORT adub floor(const pdouble &); - inline friend ADOLC_DLL_EXPORT adub fmax ( const pdouble&, const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub fmax ( double, const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub fmax ( const pdouble&, double ); - inline friend ADOLC_DLL_EXPORT adub fmin ( const pdouble&, const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub fmin ( double, const pdouble& ); - inline friend ADOLC_DLL_EXPORT adub fmin ( const pdouble&, double ); +inline friend ADOLC_DLL_EXPORT adub fmax(const pdouble &, const pdouble &); +inline friend ADOLC_DLL_EXPORT adub fmax(double, const pdouble &); +inline friend ADOLC_DLL_EXPORT adub fmax(const pdouble &, double); +inline friend ADOLC_DLL_EXPORT adub fmin(const pdouble &, const pdouble &); +inline friend ADOLC_DLL_EXPORT adub fmin(double, const pdouble &); +inline friend ADOLC_DLL_EXPORT adub fmin(const pdouble &, double); - inline friend ADOLC_DLL_EXPORT adub ldexp ( const pdouble&, int ); - inline friend ADOLC_DLL_EXPORT adub frexp ( const pdouble&, int* ); +inline friend ADOLC_DLL_EXPORT adub ldexp(const pdouble &, int); +inline friend ADOLC_DLL_EXPORT adub frexp(const pdouble &, int *); /*--------------------------------------------------------------------------*/ -#endif - friend ADOLC_DLL_EXPORT adouble pow ( const pdouble&, const badouble& ); -#endif + #endif +friend ADOLC_DLL_EXPORT adouble pow(const pdouble &, const badouble &); + #endif #endif diff --git a/ADOL-C/include/adolc/internal/usrparms.h b/ADOL-C/include/adolc/internal/usrparms.h index b57774db2..14b00551f 100644 --- a/ADOL-C/include/adolc/internal/usrparms.h +++ b/ADOL-C/include/adolc/internal/usrparms.h @@ -6,66 +6,66 @@ These parameters might affect the performance of the ADOL-C system; they are intended to be tweaked by users and local maintenance personal. - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_USRPARMS_H) -#define ADOLC_USRPARMS_H 1 + #define ADOLC_USRPARMS_H 1 -/*--------------------------------------------------------------------------*/ -/* Buffer sizes */ -#define OBUFSIZE 524288 /* 16384 or 65536 */ -#define LBUFSIZE 524288 /* 16384 or 65536 */ -#define VBUFSIZE 524288 /* 16384 or 65536 */ + /*--------------------------------------------------------------------------*/ + /* Buffer sizes */ + #define OBUFSIZE 524288 /* 16384 or 65536 */ + #define LBUFSIZE 524288 /* 16384 or 65536 */ + #define VBUFSIZE 524288 /* 16384 or 65536 */ -/*--------------------------------------------------------------------------*/ -/* Buffer size for temporary Taylor store */ -#define TBUFSIZE 524288 /* 16384 or 65536 */ + /*--------------------------------------------------------------------------*/ + /* Buffer size for temporary Taylor store */ + #define TBUFSIZE 524288 /* 16384 or 65536 */ -/*--------------------------------------------------------------------------*/ -/* Number of temporary Taylor stores*/ -#define TBUFNUM 32 + /*--------------------------------------------------------------------------*/ + /* Number of temporary Taylor stores*/ + #define TBUFNUM 32 -/*--------------------------------------------------------------------------*/ -/* Data types used by Fortran callable versions of functions */ -#define fint long -#define fdouble double + /*--------------------------------------------------------------------------*/ + /* Data types used by Fortran callable versions of functions */ + #define fint long + #define fdouble double -/*--------------------------------------------------------------------------*/ -/* Definition of inf and NaN */ -#define inf_num 1.0 /* don't undefine these; on non-IEEE machines */ -#define inf_den 0.0 /* change the values to get small fractions */ -#define non_num 0.0 /* (inf_num/inf_den) and (non_num/non_den) */ -#define non_den 0.0 /* respectively, see the documentation */ -#define ADOLC_EPS 10E-20 /* for test on zero */ + /*--------------------------------------------------------------------------*/ + /* Definition of inf and NaN */ + #define inf_num 1.0 /* don't undefine these; on non-IEEE machines */ + #define inf_den 0.0 /* change the values to get small fractions */ + #define non_num 0.0 /* (inf_num/inf_den) and (non_num/non_den) */ + #define non_den 0.0 /* respectively, see the documentation */ + #define ADOLC_EPS 10E-20 /* for test on zero */ -/****************************************************************************/ -/* Standard output used for diagnostics by ADOL-C, */ -/* e.g. stdout or stderr or whatever file identifier */ -#define DIAG_OUT stderr + /****************************************************************************/ + /* Standard output used for diagnostics by ADOL-C, */ + /* e.g. stdout or stderr or whatever file identifier */ + #define DIAG_OUT stderr -/****************************************************************************/ -/* Tells ADOL-C which name space offers the mathematical functions */ -#define ADOLC_MATH_NSP std -/* For error function with gcc compiler */ -#define ADOLC_MATH_NSP_ERF + /****************************************************************************/ + /* Tells ADOL-C which name space offers the mathematical functions */ + #define ADOLC_MATH_NSP std + /* For error function with gcc compiler */ + #define ADOLC_MATH_NSP_ERF -/*--------------------------------------------------------------------------*/ -/* Constants used by the checkpointing part (revolve) */ -#define ADOLC_CHECKUP 1000 -#define ADOLC_REPSUP 1000 + /*--------------------------------------------------------------------------*/ + /* Constants used by the checkpointing part (revolve) */ + #define ADOLC_CHECKUP 1000 + #define ADOLC_REPSUP 1000 -/*--------------------------------------------------------------------------*/ -/* Maximal size (Bytes) of a block to be written with fwrite or read with */ -/* fread --- power of 2 > 8 preferable ;-) --- */ -#define ADOLC_IO_CHUNK_SIZE 1073741824 + /*--------------------------------------------------------------------------*/ + /* Maximal size (Bytes) of a block to be written with fwrite or read with */ + /* fread --- power of 2 > 8 preferable ;-) --- */ + #define ADOLC_IO_CHUNK_SIZE 1073741824 /*--------------------------------------------------------------------------*/ #endif diff --git a/ADOL-C/include/adolc/lie/drivers.h b/ADOL-C/include/adolc/lie/drivers.h index fb0f5f28a..89fa1f42b 100644 --- a/ADOL-C/include/adolc/lie/drivers.h +++ b/ADOL-C/include/adolc/lie/drivers.h @@ -3,50 +3,53 @@ File: lie/drivers.h Revision: $Id$ Contents: functions for computation of Lie derivatives - + Copyright (c) Siquian Wang, Klaus Röbenack, Jan Winkler, Mirko Franke This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_LIE_DRIVER_H) -#define ADOLC_LIE_DRIVER_H - -#include "adolc/internal/common.h" + #define ADOLC_LIE_DRIVER_H + #include "adolc/internal/common.h" -/* C++ declarations available only when compiling with C++ */ -#if defined(__cplusplus) - -ADOLC_DLL_EXPORT int lie_scalar(short, short, short, double*, short, double*); -ADOLC_DLL_EXPORT int lie_scalar(short, short, short, short, double*, short, double**); -ADOLC_DLL_EXPORT int lie_gradient(short, short, short, double*, short, double**); -ADOLC_DLL_EXPORT int lie_gradient(short, short, short, short, double*, short, double***); - -#endif + /* C++ declarations available only when compiling with C++ */ + #if defined(__cplusplus) +ADOLC_DLL_EXPORT int lie_scalar(short, short, short, double *, short, double *); +ADOLC_DLL_EXPORT int lie_scalar(short, short, short, short, double *, short, + double **); +ADOLC_DLL_EXPORT int lie_gradient(short, short, short, double *, short, + double **); +ADOLC_DLL_EXPORT int lie_gradient(short, short, short, short, double *, short, + double ***); + #endif -/* C-declarations */ -#if defined (__cplusplus) + /* C-declarations */ + #if defined(__cplusplus) extern "C" { -#endif - -ADOLC_DLL_EXPORT int lie_scalarc(short, short, short, double*, short, double*); -ADOLC_DLL_EXPORT int lie_scalarcv(short, short, short, short, double*, short, double**); -ADOLC_DLL_EXPORT int lie_gradientc(short, short, short, double*, short, double**); -ADOLC_DLL_EXPORT int lie_gradientcv(short, short, short, short, double*, short, double***); -ADOLC_DLL_EXPORT int lie_covector(short, short, short, double*, short, double**); -ADOLC_DLL_EXPORT int lie_bracket(short, short, short, double*, short, double**); - -#if defined (__cplusplus) + #endif + +ADOLC_DLL_EXPORT int lie_scalarc(short, short, short, double *, short, + double *); +ADOLC_DLL_EXPORT int lie_scalarcv(short, short, short, short, double *, short, + double **); +ADOLC_DLL_EXPORT int lie_gradientc(short, short, short, double *, short, + double **); +ADOLC_DLL_EXPORT int lie_gradientcv(short, short, short, short, double *, short, + double ***); +ADOLC_DLL_EXPORT int lie_covector(short, short, short, double *, short, + double **); +ADOLC_DLL_EXPORT int lie_bracket(short, short, short, double *, short, + double **); + + #if defined(__cplusplus) } -#endif - - + #endif #endif - diff --git a/ADOL-C/include/adolc/medipacksupport.h b/ADOL-C/include/adolc/medipacksupport.h index 066b84ab0..0858707f8 100644 --- a/ADOL-C/include/adolc/medipacksupport.h +++ b/ADOL-C/include/adolc/medipacksupport.h @@ -12,20 +12,22 @@ ----------------------------------------------------------------------------*/ #if !defined(ADOLC_MEDISUPPORTADOLC_H) -#define ADOLC_MEDISUPPORTADOLC_H 1 + #define ADOLC_MEDISUPPORTADOLC_H 1 -#include "adouble.h" + #include "adouble.h" -#include -#include -#include -#include + #include + #include + #include + #include -void mediAddHandle(medi::HandleBase* h); +void mediAddHandle(medi::HandleBase *h); void mediInitStatic(); void mediFinalizeStatic(); -struct AdolcTool final : public medi::ADToolImplCommon { +struct AdolcTool final + : public medi::ADToolImplCommon { typedef adouble Type; typedef void AdjointType; typedef double ModifiedType; @@ -38,10 +40,12 @@ struct AdolcTool final : public medi::ADToolImplCommon MediType; - static MediType* MPI_TYPE; + static MediType *MPI_TYPE; static medi::AMPI_Datatype MPI_INT_TYPE; - static medi::OperatorHelper> operatorHelper; + static medi::OperatorHelper< + medi::FunctionHelper> + operatorHelper; static void initTypes() { // create the mpi type for ADOL-c @@ -61,12 +65,10 @@ struct AdolcTool final : public medi::ADToolImplCommon(primalMpiType, adjointMpiType) {} - + AdolcTool(MPI_Datatype primalMpiType, MPI_Datatype adjointMpiType) + : medi::ADToolImplCommon(primalMpiType, adjointMpiType) {} - inline bool isActiveType() const { - return true; - } - - inline bool isHandleRequired() const { - return isTaping(); - } + inline bool isActiveType() const { return true; } - inline bool isOldPrimalsRequired() const { - return true; - } + inline bool isHandleRequired() const { return isTaping(); } - inline void startAssembly(medi::HandleBase* h) const { - MEDI_UNUSED(h); + inline bool isOldPrimalsRequired() const { return true; } - } + inline void startAssembly(medi::HandleBase *h) const { MEDI_UNUSED(h); } - inline void addToolAction(medi::HandleBase* h) const { - if(NULL != h) { + inline void addToolAction(medi::HandleBase *h) const { + if (NULL != h) { mediAddHandle(h); } } - inline void stopAssembly(medi::HandleBase* h) const { - MEDI_UNUSED(h); - } + inline void stopAssembly(medi::HandleBase *h) const { MEDI_UNUSED(h); } medi::AMPI_Op convertOperator(medi::AMPI_Op op) const { return operatorHelper.convertOperator(op); } - - inline void createPrimalTypeBuffer(PrimalType* &buf, size_t size) const { + inline void createPrimalTypeBuffer(PrimalType *&buf, size_t size) const { buf = new PrimalType[size]; } - inline void createIndexTypeBuffer(IndexType* &buf, size_t size) const { + inline void createIndexTypeBuffer(IndexType *&buf, size_t size) const { buf = new IndexType[size]; } - inline void deletePrimalTypeBuffer(PrimalType* &buf) const { - if(NULL != buf) { - delete [] buf; + inline void deletePrimalTypeBuffer(PrimalType *&buf) const { + if (NULL != buf) { + delete[] buf; buf = NULL; } } - inline void deleteIndexTypeBuffer(IndexType* &buf) const { - if(NULL != buf) { - delete [] buf; + inline void deleteIndexTypeBuffer(IndexType *&buf) const { + if (NULL != buf) { + delete[] buf; buf = NULL; } } - static inline int getIndex(const Type& value) { - return value.loc(); - } + static inline int getIndex(const Type &value) { return value.loc(); } - static inline void clearIndex(Type& value) { + static inline void clearIndex(Type &value) { // do nothing } - static inline PrimalType getValue(const Type& value) { - return value.value(); - } + static inline PrimalType getValue(const Type &value) { return value.value(); } - static inline void setIntoModifyBuffer(ModifiedType& modValue, const Type& value) { + static inline void setIntoModifyBuffer(ModifiedType &modValue, + const Type &value) { modValue = value.value(); } - static inline void getFromModifyBuffer(const ModifiedType& modValue, Type& value) { + static inline void getFromModifyBuffer(const ModifiedType &modValue, + Type &value) { value.setValue(modValue); } - static void createIndex(Type& value, IndexType& index) { + static void createIndex(Type &value, IndexType &index) { MEDI_UNUSED(value); MEDI_UNUSED(index); // do nothing indices are created in registerValue } - static inline void registerValue(Type& value, PrimalType& oldPrimal, IndexType& index) { + static inline void registerValue(Type &value, PrimalType &oldPrimal, + IndexType &index) { MEDI_UNUSED(oldPrimal); // do nothing value should have an index index = value.loc(); } - static PrimalType getPrimalFromMod(const ModifiedType& modValue) { + static PrimalType getPrimalFromMod(const ModifiedType &modValue) { return modValue; } - static void setPrimalToMod(ModifiedType& modValue, const PrimalType& value) { + static void setPrimalToMod(ModifiedType &modValue, const PrimalType &value) { modValue = value; } - static void modifyDependency(ModifiedType& inval, ModifiedType& inoutval) { + static void modifyDependency(ModifiedType &inval, ModifiedType &inoutval) { MEDI_UNUSED(inval); MEDI_UNUSED(inoutval); diff --git a/ADOL-C/include/adolc/param.h b/ADOL-C/include/adolc/param.h index 27a19768c..547635ed1 100644 --- a/ADOL-C/include/adolc/param.h +++ b/ADOL-C/include/adolc/param.h @@ -3,214 +3,198 @@ File: param.h Revision: $Id$ Contents: class for parameter dependent functions - + Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ #if !defined(ADOLC_PARAM_H) -#define ADOLC_PARAM_H 1 -#if defined(__cplusplus) + #define ADOLC_PARAM_H 1 + #if defined(__cplusplus) -#include -#include + #include + #include -#if !defined(SWIGPRE) + #if !defined(SWIGPRE) using std::logic_error; -#endif + #endif class pdouble; -#if !defined(SWIGPRE) + #if !defined(SWIGPRE) ADOLC_DLL_EXPORT pdouble mkparam(double pval); ADOLC_DLL_EXPORT pdouble getparam(locint index); -#endif + #endif ADOLC_DLL_EXPORT locint mkparam_idx(double pval); class ADOLC_DLL_EXPORT pdouble { - friend ADOLC_DLL_EXPORT class badouble; - friend ADOLC_DLL_EXPORT class adub; - friend ADOLC_DLL_EXPORT class adouble; - friend ADOLC_DLL_EXPORT class adubref; -protected: - double _val; - locint _idx; - pdouble(const pdouble&) { - fprintf(DIAG_OUT,"ADOL-C error: illegal copy construction of pdouble" - " variable\n ... pdouble objects must never be copied\n"); - throw logic_error("illegal constructor call, errorcode=-2"); - } - pdouble(void) { - fprintf(DIAG_OUT,"ADOL-C error: illegal default construction of pdouble" - " variable\n"); - throw logic_error("illegal constructor call, errorcode=-2"); - } - pdouble(double pval); - pdouble(locint index); -public: -#if !defined(SWIGPRE) - friend pdouble mkparam(double pval); - friend pdouble getparam(locint index); - explicit operator pdouble*() const; -#endif - friend locint mkparam_idx(double pval); - operator adub() const; + friend ADOLC_DLL_EXPORT class badouble; + friend ADOLC_DLL_EXPORT class adub; + friend ADOLC_DLL_EXPORT class adouble; + friend ADOLC_DLL_EXPORT class adubref; -#define _IN_CLASS_ 1 -#define _IN_PDOUBLE_ 1 -#include -#undef _IN_PDOUBLE_ -#undef _IN_CLASS_ +protected: + double _val; + locint _idx; + pdouble(const pdouble &) { + fprintf(DIAG_OUT, + "ADOL-C error: illegal copy construction of pdouble" + " variable\n ... pdouble objects must never be copied\n"); + throw logic_error("illegal constructor call, errorcode=-2"); + } + pdouble(void) { + fprintf(DIAG_OUT, "ADOL-C error: illegal default construction of pdouble" + " variable\n"); + throw logic_error("illegal constructor call, errorcode=-2"); + } + pdouble(double pval); + pdouble(locint index); - ~pdouble() {} +public: + #if !defined(SWIGPRE) + friend pdouble mkparam(double pval); + friend pdouble getparam(locint index); + explicit operator pdouble *() const; + #endif + friend locint mkparam_idx(double pval); + operator adub() const; + + #define _IN_CLASS_ 1 + #define _IN_PDOUBLE_ 1 + #include + #undef _IN_PDOUBLE_ + #undef _IN_CLASS_ + + ~pdouble() {} }; -#ifdef ADOLC_ADVANCED_BRANCHING -inline adub operator != ( const pdouble& a, const badouble& b) -{ return (b != a); } -inline adub operator == ( const pdouble& a, const badouble& b) -{ return (b == a); } -inline adub operator <= ( const pdouble& a, const badouble& b) -{ return (b >= a); } -inline adub operator >= ( const pdouble& a, const badouble& b) -{ return (b <= a); } -inline adub operator > ( const pdouble& a, const badouble& b) -{ return (b < a); } -inline adub operator < ( const pdouble& a, const badouble& b) -{ return (b > a); } -#else -inline int operator != ( const badouble& a, const pdouble& b) -{ return ((a - b) != 0); } -inline int operator == ( const badouble& a, const pdouble& b) -{ return ((a - b) == 0); } -inline int operator <= ( const badouble& a, const pdouble& b) -{ return ((a - b) <= 0); } -inline int operator >= ( const badouble& a, const pdouble& b) -{ return ((a - b) >= 0); } -inline int operator > ( const badouble& a, const pdouble& b) -{ return ((a - b) > 0); } -inline int operator < ( const badouble& a, const pdouble& b) -{ return ((a - b) < 0); } -inline int operator != ( const pdouble& a, const badouble& b) -{ return (b != a); } -inline int operator == ( const pdouble& a, const badouble& b) -{ return (b == a); } -inline int operator <= ( const pdouble& a, const badouble& b) -{ return (b >= a); } -inline int operator >= ( const pdouble& a, const badouble& b) -{ return (b <= a); } -inline int operator > ( const pdouble& a, const badouble& b) -{ return (b < a); } -inline int operator < ( const pdouble& a, const badouble& b) -{ return (b > a); } -#endif + #ifdef ADOLC_ADVANCED_BRANCHING +inline adub operator!=(const pdouble &a, const badouble &b) { return (b != a); } +inline adub operator==(const pdouble &a, const badouble &b) { return (b == a); } +inline adub operator<=(const pdouble &a, const badouble &b) { return (b >= a); } +inline adub operator>=(const pdouble &a, const badouble &b) { return (b <= a); } +inline adub operator>(const pdouble &a, const badouble &b) { return (b < a); } +inline adub operator<(const pdouble &a, const badouble &b) { return (b > a); } + #else +inline int operator!=(const badouble &a, const pdouble &b) { + return ((a - b) != 0); +} +inline int operator==(const badouble &a, const pdouble &b) { + return ((a - b) == 0); +} +inline int operator<=(const badouble &a, const pdouble &b) { + return ((a - b) <= 0); +} +inline int operator>=(const badouble &a, const pdouble &b) { + return ((a - b) >= 0); +} +inline int operator>(const badouble &a, const pdouble &b) { + return ((a - b) > 0); +} +inline int operator<(const badouble &a, const pdouble &b) { + return ((a - b) < 0); +} +inline int operator!=(const pdouble &a, const badouble &b) { return (b != a); } +inline int operator==(const pdouble &a, const badouble &b) { return (b == a); } +inline int operator<=(const pdouble &a, const badouble &b) { return (b >= a); } +inline int operator>=(const pdouble &a, const badouble &b) { return (b <= a); } +inline int operator>(const pdouble &a, const badouble &b) { return (b < a); } +inline int operator<(const pdouble &a, const badouble &b) { return (b > a); } + #endif -#if !defined(SWIGPRE) -inline adub operator + ( const pdouble& a, const badouble& b) -{ return (b + a); } + #if !defined(SWIGPRE) +inline adub operator+(const pdouble &a, const badouble &b) { return (b + a); } -inline adub operator + ( const pdouble& a, double b) -{ return (b + adub(a)); } +inline adub operator+(const pdouble &a, double b) { return (b + adub(a)); } -inline adub operator + ( double a, const pdouble& b) -{ return (a + adub(b)); } +inline adub operator+(double a, const pdouble &b) { return (a + adub(b)); } -inline adub operator - ( const pdouble& a, const badouble& b) -{ return ((-b) + a); } +inline adub operator-(const pdouble &a, const badouble &b) { + return ((-b) + a); +} -inline adub operator - ( const pdouble& a, double b) -{ return (adub(a) - b); } +inline adub operator-(const pdouble &a, double b) { return (adub(a) - b); } -inline adub operator - ( double a, const pdouble& b) -{ return (a + (-b)); } +inline adub operator-(double a, const pdouble &b) { return (a + (-b)); } -inline adub operator * ( const pdouble& a, const badouble& b) -{ return (b*a); } +inline adub operator*(const pdouble &a, const badouble &b) { return (b * a); } -inline adub operator * ( const pdouble& a, double b) -{ return (b * adub(a)); } +inline adub operator*(const pdouble &a, double b) { return (b * adub(a)); } -inline adub operator * ( double a, const pdouble& b) -{ return (a * adub(b)); } +inline adub operator*(double a, const pdouble &b) { return (a * adub(b)); } -inline adub operator / ( const badouble& a, const pdouble& b) -{ return (a*recipr(b)); } +inline adub operator/(const badouble &a, const pdouble &b) { + return (a * recipr(b)); +} -inline adub operator / ( double a, const pdouble& b) -{ return (a*recipr(b)); } +inline adub operator/(double a, const pdouble &b) { return (a * recipr(b)); } -inline adub operator / ( const pdouble& a, double b) -{ return (adub(a)/b); } +inline adub operator/(const pdouble &a, double b) { return (adub(a) / b); } -inline adub fmax ( const badouble& y, const pdouble& d ) { - return (-fmin(-d,-y)); +inline adub fmax(const badouble &y, const pdouble &d) { + return (-fmin(-d, -y)); } -inline adub fmax ( const pdouble& a, const badouble& b) -{ return fmax(b,a); } +inline adub fmax(const pdouble &a, const badouble &b) { return fmax(b, a); } -inline adub fmin ( const pdouble& a, const badouble& b) -{ return fmin(b,a); } +inline adub fmin(const pdouble &a, const badouble &b) { return fmin(b, a); } -inline adub fmin( const badouble& a, const pdouble& b) -{ return fmin(a,adub(b)); } +inline adub fmin(const badouble &a, const pdouble &b) { + return fmin(a, adub(b)); +} /* unary operators (friends) */ -inline adub exp ( const pdouble& p) { return exp(adub(p)); } -inline adub log ( const pdouble& p) { return log(adub(p)); } -inline adub sqrt ( const pdouble& p) { return sqrt(adub(p)); } -inline adub cbrt ( const pdouble& p) { return cbrt(adub(p)); } -inline adub sin ( const pdouble& p) { return sin(adub(p)); } -inline adub cos ( const pdouble& p) { return cos(adub(p)); } -inline adub tan ( const pdouble& p) { return tan(adub(p)); } -inline adub asin ( const pdouble& p) { return asin(adub(p)); } -inline adub acos ( const pdouble& p) { return acos(adub(p)); } -inline adub atan ( const pdouble& p) { return atan(adub(p)); } +inline adub exp(const pdouble &p) { return exp(adub(p)); } +inline adub log(const pdouble &p) { return log(adub(p)); } +inline adub sqrt(const pdouble &p) { return sqrt(adub(p)); } +inline adub cbrt(const pdouble &p) { return cbrt(adub(p)); } +inline adub sin(const pdouble &p) { return sin(adub(p)); } +inline adub cos(const pdouble &p) { return cos(adub(p)); } +inline adub tan(const pdouble &p) { return tan(adub(p)); } +inline adub asin(const pdouble &p) { return asin(adub(p)); } +inline adub acos(const pdouble &p) { return acos(adub(p)); } +inline adub atan(const pdouble &p) { return atan(adub(p)); } /*--------------------------------------------------------------------------*/ /* special operators (friends) */ /* no internal use of condassign: */ -inline adub pow ( const pdouble& p, double q) { return pow(adub(p),q); } -inline adub log10 ( const pdouble& p) { return log10(adub(p)); } +inline adub pow(const pdouble &p, double q) { return pow(adub(p), q); } +inline adub log10(const pdouble &p) { return log10(adub(p)); } /* Additional ANSI C standard Math functions Added by DWJ on 8/6/90 */ -inline adub sinh ( const pdouble& p) { return sinh(adub(p)); } -inline adub cosh ( const pdouble& p) { return cosh(adub(p)); } -inline adub tanh ( const pdouble& p) { return tanh(adub(p)); } -inline adub asinh ( const pdouble& p) { return asinh(adub(p)); } -inline adub acosh ( const pdouble& p) { return acosh(adub(p)); } -inline adub atanh ( const pdouble& p) { return atanh(adub(p)); } -inline adub erf ( const pdouble& p) { return erf(adub(p)); } -inline adub erfc ( const pdouble& p) { return erfc(adub(p)); } -inline adub fabs ( const pdouble& p) { return fabs(adub(p)); } -inline adub ceil ( const pdouble& p) { return ceil(adub(p)); } -inline adub floor ( const pdouble& p) { return floor(adub(p)); } - -inline adub fmax ( const pdouble& p, const pdouble& q) -{ return fmax(adub(p),adub(q)); } -inline adub fmax ( double p, const pdouble& q) -{ return fmax(p,adub(q)); } -inline adub fmax ( const pdouble& p, double q) -{ return fmax(adub(p),q); } -inline adub fmin ( const pdouble& p, const pdouble& q) -{ return fmin(adub(p),adub(q)); } -inline adub fmin ( double p, const pdouble& q) -{ return fmin(p,adub(q)); } -inline adub fmin ( const pdouble& p, double q) -{ return fmin(adub(p),q); } - -inline adub ldexp ( const pdouble& p, int n) -{ return ldexp(adub(p),n); } -inline adub frexp ( const pdouble& p, int* n) -{ return frexp(adub(p),n); } -#endif +inline adub sinh(const pdouble &p) { return sinh(adub(p)); } +inline adub cosh(const pdouble &p) { return cosh(adub(p)); } +inline adub tanh(const pdouble &p) { return tanh(adub(p)); } +inline adub asinh(const pdouble &p) { return asinh(adub(p)); } +inline adub acosh(const pdouble &p) { return acosh(adub(p)); } +inline adub atanh(const pdouble &p) { return atanh(adub(p)); } +inline adub erf(const pdouble &p) { return erf(adub(p)); } +inline adub erfc(const pdouble &p) { return erfc(adub(p)); } +inline adub fabs(const pdouble &p) { return fabs(adub(p)); } +inline adub ceil(const pdouble &p) { return ceil(adub(p)); } +inline adub floor(const pdouble &p) { return floor(adub(p)); } + +inline adub fmax(const pdouble &p, const pdouble &q) { + return fmax(adub(p), adub(q)); +} +inline adub fmax(double p, const pdouble &q) { return fmax(p, adub(q)); } +inline adub fmax(const pdouble &p, double q) { return fmax(adub(p), q); } +inline adub fmin(const pdouble &p, const pdouble &q) { + return fmin(adub(p), adub(q)); +} +inline adub fmin(double p, const pdouble &q) { return fmin(p, adub(q)); } +inline adub fmin(const pdouble &p, double q) { return fmin(adub(p), q); } -/*--------------------------------------------------------------------------*/ -#endif +inline adub ldexp(const pdouble &p, int n) { return ldexp(adub(p), n); } +inline adub frexp(const pdouble &p, int *n) { return frexp(adub(p), n); } + #endif + + /*--------------------------------------------------------------------------*/ + #endif BEGIN_C_DECLS @@ -224,7 +208,8 @@ ADOLC_DLL_EXPORT size_t get_num_param(short tag); /* the taylor stack, so next reverse call will fail, if not preceded by a */ /* forward call after setting the parameters. */ /****************************************************************************/ -ADOLC_DLL_EXPORT void set_param_vec(short tag, size_t numparam, revreal* paramvec); +ADOLC_DLL_EXPORT void set_param_vec(short tag, size_t numparam, + revreal *paramvec); END_C_DECLS #endif diff --git a/ADOL-C/include/adolc/revolve.h b/ADOL-C/include/adolc/revolve.h index 5c57210e7..e8d8b4283 100644 --- a/ADOL-C/include/adolc/revolve.h +++ b/ADOL-C/include/adolc/revolve.h @@ -5,56 +5,56 @@ Contents: optimal binomial checkpointing adapted for ADOL-C Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ #if !defined(ADOLC_REVOLVE_H) -#define ADOLC_REVOLVE_H 1 + #define ADOLC_REVOLVE_H 1 -#include + #include BEGIN_C_DECLS typedef struct { - int advances; - int takeshots; - int commands; - int turn; - int reps; - int range; - int ch[ADOLC_CHECKUP]; - int oldsnaps; - int oldfine; + int advances; + int takeshots; + int commands; + int turn; + int reps; + int range; + int ch[ADOLC_CHECKUP]; + int oldsnaps; + int oldfine; } revolve_nums; -#ifndef _OPENMP - extern revolve_nums revolve_numbers; -#else -#include - extern revolve_nums *revolve_numbers; -#endif + #ifndef _OPENMP +extern revolve_nums revolve_numbers; + #else + #include +extern revolve_nums *revolve_numbers; + #endif enum revolve_action { - revolve_advance, - revolve_takeshot, - revolve_restore, - revolve_firsturn, - revolve_youturn, - revolve_terminate, - revolve_error + revolve_advance, + revolve_takeshot, + revolve_restore, + revolve_firsturn, + revolve_youturn, + revolve_terminate, + revolve_error }; int maxrange(int ss, int tt); -int adjustsize(int* steps, int* snaps, int* reps); +int adjustsize(int *steps, int *snaps, int *reps); -enum revolve_action revolve(int* check,int* capo,int* fine,int snaps,int* info); +enum revolve_action revolve(int *check, int *capo, int *fine, int snaps, + int *info); END_C_DECLS #endif /* ADOLC_REVOLVE_H */ - diff --git a/ADOL-C/include/adolc/sparse/sparse_fo_rev.h b/ADOL-C/include/adolc/sparse/sparse_fo_rev.h index ee4eb1a34..ab7b9319c 100644 --- a/ADOL-C/include/adolc/sparse/sparse_fo_rev.h +++ b/ADOL-C/include/adolc/sparse/sparse_fo_rev.h @@ -2,22 +2,23 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: sparse/sparse_fo_rev.h Revision: $Id$ - Contents: This file contains some "Easy To Use" interfaces of the sparse package. - - + Contents: This file contains some "Easy To Use" interfaces of the sparse +package. + + Copyright (c) Andrea Walther, Christo Mitev This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ -#if !defined (ADOLC_SPARSE_SPARSE_H) -#define ADOLC_SPARSE_SPARSE_H 1 +#if !defined(ADOLC_SPARSE_SPARSE_H) + #define ADOLC_SPARSE_SPARSE_H 1 -#include + #include -#if defined(__cplusplus) + #if defined(__cplusplus) /****************************************************************************/ /* FORWARD MODE, overloaded calls */ /* */ @@ -35,18 +36,17 @@ /* */ /* forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p], mode) : intfov */ -ADOLC_DLL_EXPORT int forward -(short, int, int, int, double*, unsigned long int**, - double*, unsigned long int**, char =0); +ADOLC_DLL_EXPORT int forward(short, int, int, int, double *, + unsigned long int **, double *, + unsigned long int **, char = 0); /*--------------------------------------------------------------------------*/ /* Bit pattern propagation call, d = 1, safe version (no x[] and y[]) */ /* */ /* forward(tag, m, n, p, X[n][p], Y[m][p], mode) : intfov */ -ADOLC_DLL_EXPORT int forward -(short, int, int, int, unsigned long int**, unsigned long int**, char =0); - +ADOLC_DLL_EXPORT int forward(short, int, int, int, unsigned long int **, + unsigned long int **, char = 0); /****************************************************************************/ /* REVERSE MODE, overloaded calls */ @@ -66,10 +66,10 @@ ADOLC_DLL_EXPORT int forward /* */ /* reverse(tag, m, n, q, U[q][m], Z[q][n], mode) : intfov */ -ADOLC_DLL_EXPORT int reverse -(short, int, int, int, unsigned long int**, unsigned long int**, char =0); +ADOLC_DLL_EXPORT int reverse(short, int, int, int, unsigned long int **, + unsigned long int **, char = 0); -#endif + #endif /****************************************************************************/ diff --git a/ADOL-C/include/adolc/sparse/sparsedrivers.h b/ADOL-C/include/adolc/sparse/sparsedrivers.h index 50af4fa73..07b1b8474 100644 --- a/ADOL-C/include/adolc/sparse/sparsedrivers.h +++ b/ADOL-C/include/adolc/sparse/sparsedrivers.h @@ -2,29 +2,25 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: sparse/sparsedrivers.h Revision: $Id$ - Contents: This file contains some "Easy To Use" interfaces of the sparse package. - + Contents: This file contains some "Easy To Use" interfaces of the sparse +package. + Copyright (c) Andrea Walther This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - -----------------------------------------------------------------------------*/ -#if !defined (ADOLC_SPARSE_SPARSE_H) -#define ADOLC_SPARSE_SPARSE_H 1 - -#include +----------------------------------------------------------------------------*/ +#if !defined(ADOLC_SPARSE_SPARSE_H) + #define ADOLC_SPARSE_SPARSE_H 1 + #include BEGIN_C_DECLS - - /****************************************************************************/ - /*--------------------------------------------------------------------------*/ /* jacobian pattern */ /* jac_pat(tag, m, n, argument, */ @@ -32,32 +28,31 @@ BEGIN_C_DECLS /* options[3]) */ /* */ -ADOLC_DLL_EXPORT int jac_pat -(short,int,int,const double*,unsigned int**,int*); +ADOLC_DLL_EXPORT int jac_pat(short, int, int, const double *, unsigned int **, + int *); /*--------------------------------------------------------------------------*/ /* abs-normal jacobian pattern */ /* absnormal_jac_pat(tag, m, n, s, argument, */ /* crs[] [ crs[][0] = non-zero independent blocks per row ]) */ /* */ -ADOLC_DLL_EXPORT int absnormal_jac_pat -(short,int,int,int,const double*,unsigned int**); +ADOLC_DLL_EXPORT int absnormal_jac_pat(short, int, int, int, const double *, + unsigned int **); /*--------------------------------------------------------------------------*/ /* seed matrix for sparse jacobian */ /* generate_seed_jac(m, n, crs, &seed, &p, option); */ -ADOLC_DLL_EXPORT void generate_seed_jac -(int, int, unsigned int**, double***, int*, int); +ADOLC_DLL_EXPORT void generate_seed_jac(int, int, unsigned int **, double ***, + int *, int); /*--------------------------------------------------------------------------*/ /* sparse jacobian */ /* int sparse_jac(tag, m, n, repeat, x, &nnz, &row_ind, &col_ind, &values, */ /* options[3]); */ -ADOLC_DLL_EXPORT int sparse_jac -(short, int , int, int, const double*, int *, - unsigned int **, unsigned int **, double **,int*); - +ADOLC_DLL_EXPORT int sparse_jac(short, int, int, int, const double *, int *, + unsigned int **, unsigned int **, double **, + int *); /*--------------------------------------------------------------------------*/ /* hessian pattern */ @@ -66,47 +61,45 @@ ADOLC_DLL_EXPORT int sparse_jac /* crs[i][ crs[i][0] = non-zero entries per row ] */ /* */ -ADOLC_DLL_EXPORT int hess_pat(short,int,const double*,unsigned int**, int); +ADOLC_DLL_EXPORT int hess_pat(short, int, const double *, unsigned int **, int); /*--------------------------------------------------------------------------*/ /* seed matrix for sparse hessian */ /* generate_seed_hess(n, crs, &seed, &p, option); */ -ADOLC_DLL_EXPORT void generate_seed_hess -(int, unsigned int**, double***, int*, int); +ADOLC_DLL_EXPORT void generate_seed_hess(int, unsigned int **, double ***, + int *, int); /*--------------------------------------------------------------------------*/ /* sparse hessian */ /* int sparse_hess(tag, n, repeat, x, &nnz, &row_ind, &col_ind, &values, */ /* options[2]); */ -ADOLC_DLL_EXPORT int sparse_hess -(short, int , int, const double*, int *, - unsigned int **, unsigned int **, double **,int*); +ADOLC_DLL_EXPORT int sparse_hess(short, int, int, const double *, int *, + unsigned int **, unsigned int **, double **, + int *); -ADOLC_DLL_EXPORT void set_HP( - short tag, /* tape identification */ - int indep, /* number of independent variables */ - unsigned int ** HP); +ADOLC_DLL_EXPORT void set_HP(short tag, /* tape identification */ + int indep, /* number of independent variables */ + unsigned int **HP); -ADOLC_DLL_EXPORT void get_HP( - short tag, /* tape identification */ - int indep, /* number of independent variables */ - unsigned int *** HP); +ADOLC_DLL_EXPORT void get_HP(short tag, /* tape identification */ + int indep, /* number of independent variables */ + unsigned int ***HP); /*--------------------------------------------------------------------------*/ /* JACOBIAN BLOCK PATTERN */ /* Max. number of unsigned ints to store the seed / jacobian matrix strips. - Reduce this value to x if your system happens to run out of memory. + Reduce this value to x if your system happens to run out of memory. x < 10 makes no sense. x = 50 or 100 is better - x stays for ( x * sizeof(unsigned long int) * 8 ) + x stays for ( x * sizeof(unsigned long int) * 8 ) (block) variables at once */ -#define PQ_STRIPMINE_MAX 30 + #define PQ_STRIPMINE_MAX 30 -ADOLC_DLL_EXPORT int bit_vector_propagation -(short, int, int, const double*, unsigned int**, int*); +ADOLC_DLL_EXPORT int bit_vector_propagation(short, int, int, const double *, + unsigned int **, int *); /****************************************************************************/ END_C_DECLS diff --git a/ADOL-C/include/adolc/tapedoc/tapedoc.h b/ADOL-C/include/adolc/tapedoc/tapedoc.h index c87de6141..4e92d2031 100644 --- a/ADOL-C/include/adolc/tapedoc/tapedoc.h +++ b/ADOL-C/include/adolc/tapedoc/tapedoc.h @@ -3,20 +3,20 @@ File: tapedoc/tapedoc.h Revision: $Id$ Contents: Contains declaration of tapedoc driver. - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_TAPEDOC_TAPEDOC_H) -#define ADOLC_TAPEDOC_TAPEDOC_H 1 + #define ADOLC_TAPEDOC_TAPEDOC_H 1 -#include + #include BEGIN_C_DECLS @@ -24,8 +24,7 @@ BEGIN_C_DECLS /* tape_doc */ /* tape_doc(tag, m, n, x[n], y[m]) */ -ADOLC_DLL_EXPORT void tape_doc(short, int, int, const double*, double*); - +ADOLC_DLL_EXPORT void tape_doc(short, int, int, const double *, double *); /****************************************************************************/ /* THAT'S ALL */ diff --git a/ADOL-C/include/adolc/taping.h b/ADOL-C/include/adolc/taping.h index e1172abc1..dc1e83c46 100644 --- a/ADOL-C/include/adolc/taping.h +++ b/ADOL-C/include/adolc/taping.h @@ -5,51 +5,48 @@ Contents: all C functions directly accessing at least one of the four tapes (operations, locations, constants, value stack) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_TAPING_H) -#define ADOLC_TAPING_H 1 + #define ADOLC_TAPING_H 1 -#include + #include BEGIN_C_DECLS enum StatEntries { - NUM_INDEPENDENTS, /* # of independent variables */ - NUM_DEPENDENTS, /* # of dependent variables */ - NUM_MAX_LIVES, /* max # of live variables */ - TAY_STACK_SIZE, /* # of values in the taylor (value) stack */ - OP_BUFFER_SIZE, /* # of operations per buffer == OBUFSIZE (usrparms.h) */ - NUM_OPERATIONS, /* overall # of operations */ - OP_FILE_ACCESS, /* operations file written or not */ - NUM_LOCATIONS, /* overall # of locations */ - LOC_FILE_ACCESS, /* locations file written or not */ - NUM_VALUES, /* overall # of values */ - VAL_FILE_ACCESS, /* values file written or not */ - LOC_BUFFER_SIZE, /* # of locations per buffer == LBUFSIZE (usrparms.h) */ - VAL_BUFFER_SIZE, /* # of values per buffer == CBUFSIZE (usrparms.h) */ - TAY_BUFFER_SIZE, /* # of taylors per buffer <= TBUFSIZE (usrparms.h) */ - NUM_EQ_PROD, /* # of eq_*_prod for sparsity pattern */ - NO_MIN_MAX, /* no use of min_op, deferred to abs_op for piecewise stuff */ - NUM_SWITCHES, /* # of abs calls that can switch branch */ - NUM_PARAM, /* no of parameters (doubles) interchangeable without retaping */ - STAT_SIZE /* represents the size of the stats vector */ + NUM_INDEPENDENTS, /* # of independent variables */ + NUM_DEPENDENTS, /* # of dependent variables */ + NUM_MAX_LIVES, /* max # of live variables */ + TAY_STACK_SIZE, /* # of values in the taylor (value) stack */ + OP_BUFFER_SIZE, /* # of operations per buffer == OBUFSIZE (usrparms.h) */ + NUM_OPERATIONS, /* overall # of operations */ + OP_FILE_ACCESS, /* operations file written or not */ + NUM_LOCATIONS, /* overall # of locations */ + LOC_FILE_ACCESS, /* locations file written or not */ + NUM_VALUES, /* overall # of values */ + VAL_FILE_ACCESS, /* values file written or not */ + LOC_BUFFER_SIZE, /* # of locations per buffer == LBUFSIZE (usrparms.h) */ + VAL_BUFFER_SIZE, /* # of values per buffer == CBUFSIZE (usrparms.h) */ + TAY_BUFFER_SIZE, /* # of taylors per buffer <= TBUFSIZE (usrparms.h) */ + NUM_EQ_PROD, /* # of eq_*_prod for sparsity pattern */ + NO_MIN_MAX, /* no use of min_op, deferred to abs_op for piecewise stuff */ + NUM_SWITCHES, /* # of abs calls that can switch branch */ + NUM_PARAM, /* no of parameters (doubles) interchangeable without retaping */ + STAT_SIZE /* represents the size of the stats vector */ }; -enum TapeRemovalType { - ADOLC_REMOVE_FROM_CORE, - ADOLC_REMOVE_COMPLETELY -}; +enum TapeRemovalType { ADOLC_REMOVE_FROM_CORE, ADOLC_REMOVE_COMPLETELY }; enum LocationMgrType { - ADOLC_LOCATION_BLOCKS, /* can allocate contiguous location blocks */ - ADOLC_LOCATION_SINGLETONS /* only singleton locations, no blocks */ + ADOLC_LOCATION_BLOCKS, /* can allocate contiguous location blocks */ + ADOLC_LOCATION_SINGLETONS /* only singleton locations, no blocks */ }; ADOLC_DLL_EXPORT void skip_tracefile_cleanup(short tnum); @@ -74,13 +71,15 @@ ADOLC_DLL_EXPORT void disableBranchSwitchWarnings(); ADOLC_DLL_EXPORT void enableMinMaxUsingAbs(); ADOLC_DLL_EXPORT void disableMinMaxUsingAbs(); /* - * free location block sorting/consolidation upon calls to ensureContiguousLocations - * happens when the ratio between allocated and used locations exceeds gcTriggerRatio or - * the allocated locations exceed gcTriggerMaxSize + * free location block sorting/consolidation upon calls to + * ensureContiguousLocations happens when the ratio between allocated and used + * locations exceeds gcTriggerRatio or the allocated locations exceed + * gcTriggerMaxSize */ ADOLC_DLL_EXPORT void setStoreManagerType(unsigned char loctypes); -ADOLC_DLL_EXPORT void setStoreManagerControl(double gcTriggerRatio, size_t gcTriggerMaxSize); +ADOLC_DLL_EXPORT void setStoreManagerControl(double gcTriggerRatio, + size_t gcTriggerMaxSize); END_C_DECLS @@ -88,17 +87,17 @@ END_C_DECLS * Normally, theKeeper would take care of the initialization and finalization * of ADOL-C. However, some compilers do not include the keeper code when * linking. "initADOLC" should be called right after main(...), in this case. - * "initADOLC" will not initialize memory, but is only necessary to reference + * "initADOLC" will not initialize memory, but is only necessary to reference * "theKeeper", such that this static instance is used at least once. :-( */ ADOLC_DLL_EXPORT void initADOLC(); -#if defined(__cplusplus) + #if defined(__cplusplus) /* Initialization for the taping process. Creates buffers for this tape, sets * files names, and calls appropriate setup routines. * This functions return value is different from zero if a tape with with ID - * tnum is available only in core. The old tape gets overwritten by the new + * tnum is available only in core. The old tape gets overwritten by the new * one in this case. */ ADOLC_DLL_EXPORT int trace_on(short tnum, int keepTaylors = 0); @@ -109,8 +108,8 @@ ADOLC_DLL_EXPORT int trace_on(short tnum, int keepTaylors = 0); * tbs - size of the taylor buffer (number of elements) * trace_on is the last point in time we want to allow the change of buffer * sizes for a given tape */ -ADOLC_DLL_EXPORT int trace_on(short tnum, int keepTaylors, - uint obs, uint lbs, uint vbs, uint tbs, int skipFileCleanup=0); +ADOLC_DLL_EXPORT int trace_on(short tnum, int keepTaylors, uint obs, uint lbs, + uint vbs, uint tbs, int skipFileCleanup = 0); /* Stop Tracing. Cleans up, and turns off trace_flag. Flag not equal zero * enforces writing of the three main tape files (op+loc+val). */ @@ -118,9 +117,9 @@ ADOLC_DLL_EXPORT void trace_off(int flag = 0); ADOLC_DLL_EXPORT bool isTaping(); -#include -ADOLC_DLL_EXPORT void cachedTraceTags(std::vector& result); + #include +ADOLC_DLL_EXPORT void cachedTraceTags(std::vector &result); -#endif + #endif #endif /* ADOLC_TAPING_H */ diff --git a/ADOL-C/src/adalloc.c b/ADOL-C/src/adalloc.c index 49d1b6b58..375b9a6ff 100644 --- a/ADOL-C/src/adalloc.c +++ b/ADOL-C/src/adalloc.c @@ -2,197 +2,210 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: adalloc.c Revision: $Id$ - Contents: C allocation of arrays of doubles in several dimensions - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Contents: C allocation of arrays of doubles in several dimensions + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#include #include "dvlparms.h" +#include #if !defined(ADOLC_NO_MALLOC) -# define ADOLC_CALLOC(n,m) calloc(n,m) + #define ADOLC_CALLOC(n, m) calloc(n, m) #else -# define ADOLC_CALLOC(n,m) rpl_calloc(n,m) + #define ADOLC_CALLOC(n, m) rpl_calloc(n, m) +#endif +#if !defined(ADOLC_NO_MALLOC) + #define ADOLC_MALLOC(n, m) calloc(n, m) +#else + #define ADOLC_MALLOC(n, m) rpl_calloc(n, m) #endif -# if !defined(ADOLC_NO_MALLOC) -# define ADOLC_MALLOC(n,m) calloc(n,m) -# else -# define ADOLC_MALLOC(n,m) rpl_calloc(n,m) -# endif BEGIN_C_DECLS -extern void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line); +extern void adolc_exit(int errorcode, const char *what, const char *function, + const char *file, int line); /****************************************************************************/ /* MEMORY MANAGEMENT UTILITIES */ /*--------------------------------------------------------------------------*/ -char* populate_dpp(double ***const pointer, char *const memory, - int n, int m) { - char* tmp; - double **tmp1; double *tmp2; - int i,j; - tmp = (char*) memory; - tmp1 = (double**)memory; - *pointer = tmp1; - tmp = (char*)(tmp1+n); - tmp2 = (double*)tmp; - for (i=0;i0) { - A=(double*)ADOLC_MALLOC(m,sizeof(double)); - if (A == NULL) { - fprintf(DIAG_OUT,"ADOL-C error: myalloc1 cannot allocate %zd bytes\n", - (size_t)(m*sizeof(double))); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } +double *myalloc1(size_t m) { + double *A = NULL; + if (m > 0) { + A = (double *)ADOLC_MALLOC(m, sizeof(double)); + if (A == NULL) { + fprintf(DIAG_OUT, "ADOL-C error: myalloc1 cannot allocate %zd bytes\n", + (size_t)(m * sizeof(double))); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); } - return A; + } + return A; } /*--------------------------------------------------------------------------*/ -double** myalloc2(size_t m, size_t n) { - double **A=NULL; - if (m>0 && n>0) { - int i; - char *Adum = (char*)ADOLC_MALLOC(m*n*sizeof(double)+m*sizeof(double*),sizeof(char)); - if (Adum == NULL) { - fprintf(DIAG_OUT,"ADOL-C error: myalloc2 cannot allocate %zd bytes\n", - (size_t)(m*n*sizeof(double)+m*sizeof(double*))); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - populate_dpp(&A,Adum,m,n); +double **myalloc2(size_t m, size_t n) { + double **A = NULL; + if (m > 0 && n > 0) { + int i; + char *Adum = (char *)ADOLC_MALLOC( + m * n * sizeof(double) + m * sizeof(double *), sizeof(char)); + if (Adum == NULL) { + fprintf(DIAG_OUT, "ADOL-C error: myalloc2 cannot allocate %zd bytes\n", + (size_t)(m * n * sizeof(double) + m * sizeof(double *))); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); } - return A; + populate_dpp(&A, Adum, m, n); + } + return A; } /*--------------------------------------------------------------------------*/ -double*** myalloc3(size_t m, size_t n, size_t p) { /* This function allocates 3-tensors contiguously */ - double ***A = NULL; - if (m>0 && n>0 && p > 0) { - int i,j; - char *Adum = (char*) ADOLC_MALLOC(m*n*p*sizeof(double)+m*n*sizeof(double*)+m*sizeof(double**),sizeof(char)); - if (Adum == NULL) { - fprintf(DIAG_OUT,"ADOL-C error: myalloc3 cannot allocate %zd bytes\n", - (size_t)(m*n*p*sizeof(double)+m*n*sizeof(double*)+m*sizeof(double**))); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - populate_dppp(&A,Adum,m,n,p); +double *** +myalloc3(size_t m, size_t n, + size_t p) { /* This function allocates 3-tensors contiguously */ + double ***A = NULL; + if (m > 0 && n > 0 && p > 0) { + int i, j; + char *Adum = (char *)ADOLC_MALLOC(m * n * p * sizeof(double) + + m * n * sizeof(double *) + + m * sizeof(double **), + sizeof(char)); + if (Adum == NULL) { + fprintf(DIAG_OUT, "ADOL-C error: myalloc3 cannot allocate %zd bytes\n", + (size_t)(m * n * p * sizeof(double) + m * n * sizeof(double *) + + m * sizeof(double **))); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); } - return A; + populate_dppp(&A, Adum, m, n, p); + } + return A; } /*--------------------------------------------------------------------------*/ -void myfree1(double *A) { - if (A) free((char*) A); +void myfree1(double *A) { + if (A) + free((char *)A); } /*--------------------------------------------------------------------------*/ -void myfree2(double **A) { - if (A) free((char*) A); +void myfree2(double **A) { + if (A) + free((char *)A); } /*--------------------------------------------------------------------------*/ void myfree3(double ***A) { - if (A) free((char*) A); + if (A) + free((char *)A); } - /****************************************************************************/ /* SPECIAL IDENTITY REPRESENTATION */ /*--------------------------------------------------------------------------*/ -double **myallocI2(int n) { - double *Idum = (double*)ADOLC_MALLOC((2*n-1),sizeof(double)); - double **I = (double**)malloc(n*sizeof(double*)); - int i; - if (Idum == NULL) { - fprintf(DIAG_OUT,"ADOL-C error: myallocI2 cannot allocate %i bytes\n", - (int)((2*n-1)*sizeof(double))); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - if (I == NULL) { - fprintf(DIAG_OUT,"ADOL-C error: myallocI2 cannot allocate %i bytes\n", - (int)(n*sizeof(double*))); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - Idum += (n - 1); - I[0] = Idum; - *Idum = 1.0; - /* 20020628 olvo n3l: Initialization to 0 */ - for (i=1; i -#include "oplate.h" -#include "dvlparms.h" using namespace std; @@ -32,27 +32,25 @@ using namespace std; /* HELPFUL FUNCTIONS */ /*--------------------------------------------------------------------------*/ -void condassign( double &res, const double &cond, - const double &arg1, const double &arg2 ) { - res = cond > 0 ? arg1 : arg2; +void condassign(double &res, const double &cond, const double &arg1, + const double &arg2) { + res = cond > 0 ? arg1 : arg2; } /*--------------------------------------------------------------------------*/ -void condassign( double &res, const double &cond, - const double &arg) { - res = cond > 0 ? arg : res; +void condassign(double &res, const double &cond, const double &arg) { + res = cond > 0 ? arg : res; } /*--------------------------------------------------------------------------*/ -void condeqassign( double &res, const double &cond, - const double &arg1, const double &arg2 ) { - res = cond >= 0 ? arg1 : arg2; +void condeqassign(double &res, const double &cond, const double &arg1, + const double &arg2) { + res = cond >= 0 ? arg1 : arg2; } /*--------------------------------------------------------------------------*/ -void condeqassign( double &res, const double &cond, - const double &arg) { - res = cond >= 0 ? arg : res; +void condeqassign(double &res, const double &cond, const double &arg) { + res = cond >= 0 ? arg : res; } /*--------------------------------------------------------------------------*/ /* The remaining routines define the badouble, adub and adouble routines. */ @@ -70,27 +68,27 @@ void adouble::initInternal(void) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; -#if defined(ADOLC_ADOUBLE_STDCZERO) - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { -#endif - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); -#if defined(ADOLC_TRACK_ACTIVITY) - } -#endif + #if defined(ADOLC_ADOUBLE_STDCZERO) + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + #if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { + #endif + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + #if defined(ADOLC_TRACK_ACTIVITY) + } + #endif } ADOLC_GLOBAL_TAPE_VARS.store[location] = 0.; -#if defined(ADOLC_TRACK_ACTIVITY) + #if defined(ADOLC_TRACK_ACTIVITY) ADOLC_GLOBAL_TAPE_VARS.actStore[location] = false; -#endif -#endif + #endif + #endif isInit = true; } #else @@ -99,178 +97,179 @@ void adouble::initInternal(void) {} /*--------------------------------------------------------------------------*/ adouble::adouble() { - location = next_loc(); - isInit = true; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + location = next_loc(); + isInit = true; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; #if defined(ADOLC_ADOUBLE_STDCZERO) - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { -#endif - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(location); // = res + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + #if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { + #endif + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + #if defined(ADOLC_TRACK_ACTIVITY) + } + #endif + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); -#if defined(ADOLC_TRACK_ACTIVITY) - } -#endif - } - - ADOLC_GLOBAL_TAPE_VARS.store[location] = 0.; -#if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[location] = false; -#endif + ADOLC_GLOBAL_TAPE_VARS.store[location] = 0.; + #if defined(ADOLC_TRACK_ACTIVITY) + ADOLC_GLOBAL_TAPE_VARS.actStore[location] = false; + #endif #endif } /*--------------------------------------------------------------------------*/ -adouble::adouble( double coval ) { - location = next_loc(); - isInit = true; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; +adouble::adouble(double coval) { + location = next_loc(); + isInit = true; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { #endif - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(location); // = res - } else - if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(location); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - } + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(location); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(location); // = res + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[location] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[location] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[location] = false; + ADOLC_GLOBAL_TAPE_VARS.actStore[location] = false; #endif } /*--------------------------------------------------------------------------*/ -adouble::adouble( const adouble& a ) { - location = next_loc(); - isInit = true; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - +adouble::adouble(const adouble &a) { + location = next_loc(); + isInit = true; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[a.location]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[a.location]) { #endif - put_op(assign_a); - ADOLC_PUT_LOCINT(a.location); // = arg - ADOLC_PUT_LOCINT(location); // = res + put_op(assign_a); + ADOLC_PUT_LOCINT(a.location); // = arg + ADOLC_PUT_LOCINT(location); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); #if defined(ADOLC_TRACK_ACTIVITY) - } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[a.location]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(location); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(location); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[a.location]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(location); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(location); // = res + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval + } - } - } -#endif + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + } } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[location] = ADOLC_GLOBAL_TAPE_VARS.store[a.location]; + ADOLC_GLOBAL_TAPE_VARS.store[location] = + ADOLC_GLOBAL_TAPE_VARS.store[a.location]; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[location] = ADOLC_GLOBAL_TAPE_VARS.actStore[a.location]; + ADOLC_GLOBAL_TAPE_VARS.actStore[location] = + ADOLC_GLOBAL_TAPE_VARS.actStore[a.location]; #endif } /*--------------------------------------------------------------------------*/ -adouble::adouble( const adub& a ) { - location = next_loc(); - isInit = true; - locint a_loc = a.loc(); - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - int upd = 0; - /* 981020 olvo skip upd_resloc(..) if no tracing performed */ - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) - upd = upd_resloc_check(a_loc,loc()); - if (upd) { /* olvo 980708 new n2l & 980921 changed interface */ - free_loc(location); - location = a_loc; - const_cast(a).isInit = false; - } else { - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(loc(),a_loc); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]) { +adouble::adouble(const adub &a) { + location = next_loc(); + isInit = true; + locint a_loc = a.loc(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + int upd = 0; + /* 981020 olvo skip upd_resloc(..) if no tracing performed */ + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) + upd = upd_resloc_check(a_loc, loc()); + if (upd) { /* olvo 980708 new n2l & 980921 changed interface */ + free_loc(location); + location = a_loc; + const_cast(a).isInit = false; + } else { + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(loc(),a_loc); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]) { #endif - put_op(assign_a); - ADOLC_PUT_LOCINT(a_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res + put_op(assign_a); + ADOLC_PUT_LOCINT(a_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(location); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(location); // = res } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(location); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(location); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } - } -#endif + put_op(assign_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; -#if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]; + } #endif } + ADOLC_GLOBAL_TAPE_VARS.store[loc()] = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; +#if defined(ADOLC_TRACK_ACTIVITY) + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]; +#endif + } } /****************************************************************************/ @@ -279,9 +278,9 @@ adouble::adouble( const adub& a ) { /*--------------------------------------------------------------------------*/ badouble::~badouble() { #ifdef adolc_overwrite - if (isInit) { - free_loc(location); - } + if (isInit) { + free_loc(location); + } #endif } @@ -290,33 +289,33 @@ badouble::~badouble() { /*--------------------------------------------------------------------------*/ double badouble::getValue() const { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - return ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + return ADOLC_GLOBAL_TAPE_VARS.store[loc()]; } -badouble::operator double const&() const { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - return ADOLC_GLOBAL_TAPE_VARS.store[loc()]; +badouble::operator double const &() const { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + return ADOLC_GLOBAL_TAPE_VARS.store[loc()]; } -badouble::operator double&&() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - return (double&&)ADOLC_GLOBAL_TAPE_VARS.store[loc()]; +badouble::operator double &&() { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + return (double &&)ADOLC_GLOBAL_TAPE_VARS.store[loc()]; } badouble::operator double() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - return ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + return ADOLC_GLOBAL_TAPE_VARS.store[loc()]; } -void badouble::setValue( const double x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - ADOLC_GLOBAL_TAPE_VARS.store[loc()]=x; +void badouble::setValue(const double x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] = x; } /****************************************************************************/ @@ -324,357 +323,363 @@ void badouble::setValue( const double x ) { /*--------------------------------------------------------------------------*/ /* Assign an adouble variable a constant value. */ -badouble& badouble::operator = ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { +badouble &badouble::operator=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(loc()); // = res - } else - if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(loc()); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval - } + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(loc()); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(loc()); // = res + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = false; + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = false; #endif - return *this; + return *this; } /*--------------------------------------------------------------------------*/ /* Assign an adouble variable a constant value. */ -adouble& adouble::operator = ( double coval ) { - this->loc(); // call for late init - (*this).badouble::operator=(coval); - return (*this); +adouble &adouble::operator=(double coval) { + this->loc(); // call for late init + (*this).badouble::operator=(coval); + return (*this); } /*--------------------------------------------------------------------------*/ /* Assign an adouble variable to an independent value. */ -badouble& badouble::operator <<= ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - ADOLC_CURRENT_TAPE_INFOS.numInds++; +badouble &badouble::operator<<=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + ADOLC_CURRENT_TAPE_INFOS.numInds++; - put_op(assign_ind); - ADOLC_PUT_LOCINT(loc()); // = res + put_op(assign_ind); + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true; #endif - return *this; + return *this; } void badouble::declareIndependent() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - ADOLC_CURRENT_TAPE_INFOS.numInds++; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + ADOLC_CURRENT_TAPE_INFOS.numInds++; - put_op(assign_ind); - ADOLC_PUT_LOCINT(loc()); // = res + put_op(assign_ind); + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + } #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true; #endif } /*--------------------------------------------------------------------------*/ /* Assign a float variable from a dependent adouble value. */ -badouble& badouble::operator >>= ( double& coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ! ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { - fprintf(DIAG_OUT, "ADOL-C warning: marking an inactive variable (constant) as dependent.\n"); - locint tmploc = loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } -#endif - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - ADOLC_CURRENT_TAPE_INFOS.numDeps++; - - put_op(assign_dep); - ADOLC_PUT_LOCINT(loc()); // = res +badouble &badouble::operator>>=(double &coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; +#if defined(ADOLC_TRACK_ACTIVITY) + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + fprintf(DIAG_OUT, "ADOL-C warning: marking an inactive variable (constant) " + "as dependent.\n"); + locint tmploc = loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); } - coval = double (ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - return *this; + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } +#endif + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + ADOLC_CURRENT_TAPE_INFOS.numDeps++; + + put_op(assign_dep); + ADOLC_PUT_LOCINT(loc()); // = res + } + + coval = double(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + return *this; } void badouble::declareDependent() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ! ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { - fprintf(DIAG_OUT, "ADOL-C warning: marking an inactive variable (constant) as dependent.\n"); - locint tmploc = loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; +#if defined(ADOLC_TRACK_ACTIVITY) + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + fprintf(DIAG_OUT, "ADOL-C warning: marking an inactive variable (constant) " + "as dependent.\n"); + locint tmploc = loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } #endif - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - ADOLC_CURRENT_TAPE_INFOS.numDeps++; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + ADOLC_CURRENT_TAPE_INFOS.numDeps++; - put_op(assign_dep); - ADOLC_PUT_LOCINT(loc()); // = res - } + put_op(assign_dep); + ADOLC_PUT_LOCINT(loc()); // = res + } } /*--------------------------------------------------------------------------*/ /* Assign an Badouble variable an Badouble value. */ -badouble& badouble::operator = ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint x_loc = x.loc(); - if (loc()!=x_loc) - /* test this to avoid for x=x statements adjoint(x)=0 in reverse mode */ - { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(loc(),x.loc()); +badouble &badouble::operator=(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint x_loc = x.loc(); + if (loc() != x_loc) + /* test this to avoid for x=x statements adjoint(x)=0 in reverse mode */ + { + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(loc(),x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { #endif - put_op(assign_a); - ADOLC_PUT_LOCINT(x_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res + put_op(assign_a); + ADOLC_PUT_LOCINT(x_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(location); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(location); // = res } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(location); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(location); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } - } -#endif + put_op(assign_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); } + } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()]=ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]; + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]; #endif - } - return *this; + } + return *this; } /*--------------------------------------------------------------------------*/ /* Assign an Badouble variable an Badouble value. */ -adouble& adouble::operator = ( const badouble& x ) { - this->loc(); // call for late init - (*this).badouble::operator=(x); - return (*this); +adouble &adouble::operator=(const badouble &x) { + this->loc(); // call for late init + (*this).badouble::operator=(x); + return (*this); } /*--------------------------------------------------------------------------*/ /* Assign an adouble variable an adouble value. */ -adouble& adouble::operator = ( const adouble& x ) { - this->loc(); // call for late init - x.loc(); // cal for late init - (*this).badouble::operator=(x); - return (*this); +adouble &adouble::operator=(const adouble &x) { + this->loc(); // call for late init + x.loc(); // cal for late init + (*this).badouble::operator=(x); + return (*this); } /*--------------------------------------------------------------------------*/ /* Assign an adouble an adub */ /* olvo 980517 new version griewank */ -badouble& badouble::operator = ( const adub& a ) { - locint a_loc = a.loc(); - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - int upd = 0; - /* 981020 olvo skip upd_resloc(..) if no tracing performed */ - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) -#if defined(ADOLC_TRACK_ACTIVITY) - upd = upd_resloc_check(a_loc,loc()); +badouble &badouble::operator=(const adub &a) { + locint a_loc = a.loc(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + int upd = 0; + /* 981020 olvo skip upd_resloc(..) if no tracing performed */ + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) +#if defined(ADOLC_TRACK_ACTIVITY) + upd = upd_resloc_check(a_loc, loc()); #else - upd = upd_resloc(a_loc,loc()); + upd = upd_resloc(a_loc, loc()); #endif - if (upd) { /* olvo 980708 new n2l & 980921 changed interface */ + if (upd) { /* olvo 980708 new n2l & 980921 changed interface */ #if defined(ADOLC_TRACK_ACTIVITY) - free_loc(location); - location = a_loc; - const_cast(a).isInit = false; + free_loc(location); + location = a_loc; + const_cast(a).isInit = false; #else - revreal tempVal = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_OVERWRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()],&ADOLC_GLOBAL_TAPE_VARS.store[a_loc]); - ADOLC_GLOBAL_TAPE_VARS.store[loc()] = tempVal; + revreal tempVal = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_OVERWRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()], + &ADOLC_GLOBAL_TAPE_VARS.store[a_loc]); + ADOLC_GLOBAL_TAPE_VARS.store[loc()] = tempVal; #endif - } else { - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(loc(),a_loc); + } else { + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(loc(),a_loc); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]) { #endif - put_op(assign_a); - ADOLC_PUT_LOCINT(a_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res + put_op(assign_a); + ADOLC_PUT_LOCINT(a_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(location); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(location); // = res } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[location]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(location); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(location); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } - } -#endif + put_op(assign_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; -#if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]; + } #endif } + ADOLC_GLOBAL_TAPE_VARS.store[loc()] = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; +#if defined(ADOLC_TRACK_ACTIVITY) + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]; +#endif + } - return *this; + return *this; } /*--------------------------------------------------------------------------*/ /* Assign an adouble an adub */ /* olvo 980517 new version griewank */ -adouble& adouble::operator = ( const adub& a ) { - this->loc(); // call for late init - (*this).badouble::operator=(a); - return (*this); +adouble &adouble::operator=(const adub &a) { + this->loc(); // call for late init + (*this).badouble::operator=(a); + return (*this); } - /****************************************************************************/ /* INPUT / OUTPUT */ /*--------------------------------------------------------------------------*/ /* Output an adouble value !!! No tracing of this action */ -std::ostream& operator << ( std::ostream& out, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - return out << ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] << "(a)" ; +std::ostream &operator<<(std::ostream &out, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + return out << ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] << "(a)"; } /*--------------------------------------------------------------------------*/ /* Input adouble value */ -std::istream& operator >> ( std::istream& in, const badouble& y ) { - double coval; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - in >> coval; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_d(y.loc(),coval); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { -#endif - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(y.loc()); // = res - } else - if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(y.loc()); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(y.loc()); // = res - ADOLC_PUT_VAL(coval); // = coval - } +std::istream &operator>>(std::istream &in, const badouble &y) { + double coval; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + in >> coval; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_d(y.loc(),coval); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { +#endif + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(y.loc()); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(y.loc()); // = res + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(y.loc()); // = res + ADOLC_PUT_VAL(coval); // = coval + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] = false; + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] = false; #endif - return in; + return in; } /****************************************************************************/ @@ -682,181 +687,187 @@ std::istream& operator >> ( std::istream& in, const badouble& y ) { /*--------------------------------------------------------------------------*/ /* Postfix increment */ -adub adouble::operator++( int ) { - locint locat = next_loc(); - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; +adub adouble::operator++(int) { + locint locat = next_loc(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(locat,loc()); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(locat,loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(assign_a); - ADOLC_PUT_LOCINT(loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res + put_op(assign_a); + ADOLC_PUT_LOCINT(loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval - } + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); // = res + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat]=ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]; #endif - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_incr_decr_a(incr_a,loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_incr_decr_a(incr_a,loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(incr_a); - ADOLC_PUT_LOCINT(loc()); // = res + put_op(incr_a); + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()]++; - return locat; + ADOLC_GLOBAL_TAPE_VARS.store[loc()]++; + return locat; } /*--------------------------------------------------------------------------*/ /* Postfix decrement */ -adub adouble::operator--( int ) { - locint locat = next_loc(); - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; +adub adouble::operator--(int) { + locint locat = next_loc(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(locat,loc()); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(locat,loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(assign_a); - ADOLC_PUT_LOCINT(loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res + put_op(assign_a); + ADOLC_PUT_LOCINT(loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval - } + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); // = res + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat]=ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]; #endif - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_incr_decr_a(decr_a,loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_incr_decr_a(decr_a,loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(decr_a); - ADOLC_PUT_LOCINT(loc()); // = res + put_op(decr_a); + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()]--; - return locat; + ADOLC_GLOBAL_TAPE_VARS.store[loc()]--; + return locat; } /*--------------------------------------------------------------------------*/ /* Prefix increment */ -badouble& adouble::operator++() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_incr_decr_a(incr_a,loc()); +badouble &adouble::operator++() { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_incr_decr_a(incr_a,loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(incr_a); - ADOLC_PUT_LOCINT(loc()); // = res + put_op(incr_a); + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()]++; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[loc()]++; + return *this; } /*--------------------------------------------------------------------------*/ /* Prefix decrement */ -badouble& adouble::operator--() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_incr_decr_a(decr_a,loc()); +badouble &adouble::operator--() { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_incr_decr_a(decr_a,loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(decr_a); - ADOLC_PUT_LOCINT(loc()); // = res + put_op(decr_a); + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()]--; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[loc()]--; + return *this; } /****************************************************************************/ @@ -864,657 +875,681 @@ badouble& adouble::operator--() { /*--------------------------------------------------------------------------*/ /* Adding a floating point to an adouble */ -badouble& badouble::operator += ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_plus_d,loc(),coval); +badouble &badouble::operator+=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_plus_d,loc(),coval); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(eq_plus_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval + put_op(eq_plus_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] += coval; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] += coval; + return *this; } - /*--------------------------------------------------------------------------*/ /* Subtracting a floating point from an adouble */ -badouble& badouble::operator -= ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_min_d,loc(),coval); +badouble &badouble::operator-=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_min_d,loc(),coval); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(eq_min_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval + put_op(eq_min_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= coval; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= coval; + return *this; } /*--------------------------------------------------------------------------*/ /* Add an adouble to another adouble */ -badouble& badouble::operator += ( const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint y_loc = y.loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_a_same_arg(eq_plus_a,loc(),y.loc()); +badouble &badouble::operator+=(const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint y_loc = y.loc(); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_a_same_arg(eq_plus_a,loc(),y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc] && ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc] && + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(eq_plus_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res + put_op(eq_plus_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (coval) { - put_op(plus_d_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); - } else { - put_op(assign_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (coval) { + put_op(plus_d_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); + } else { + put_op(assign_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + } - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; - if (coval) { - put_op(eq_plus_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + if (coval) { + put_op(eq_plus_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] += ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] += ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]); + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]); #endif - return *this; + return *this; } /*--------------------------------------------------------------------------*/ /* olvo 991122 new version for y += x1 * x2; */ -badouble& badouble::operator += ( const adub& a ) { - locint a_loc = a.loc(); - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - int upd = 0; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) -#endif - { - upd = upd_resloc_inc_prod(a_loc,loc(),eq_plus_prod); - } - if (upd) { - /* kk 20170720 Activity Tracking: This case only happens if both - lhs and rhs have true in actStore, since previous operation - that created rhs is mult_a_a and we checked lhs above. - So no change is needed */ - ADOLC_GLOBAL_TAPE_VARS.store[loc()] += ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_DELETE_SCAYLOR(&ADOLC_GLOBAL_TAPE_VARS.store[a_loc]); - --ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - ++ADOLC_CURRENT_TAPE_INFOS.num_eq_prod; - } else { - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(loc(),a_loc); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc] && ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { +badouble &badouble::operator+=(const adub &a) { + locint a_loc = a.loc(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + int upd = 0; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) +#endif + { + upd = upd_resloc_inc_prod(a_loc, loc(), eq_plus_prod); + } + if (upd) { + /* kk 20170720 Activity Tracking: This case only happens if both + lhs and rhs have true in actStore, since previous operation + that created rhs is mult_a_a and we checked lhs above. + So no change is needed */ + ADOLC_GLOBAL_TAPE_VARS.store[loc()] += ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_DELETE_SCAYLOR(&ADOLC_GLOBAL_TAPE_VARS.store[a_loc]); + --ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + ++ADOLC_CURRENT_TAPE_INFOS.num_eq_prod; + } else { + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(loc(),a_loc); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc] && + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(eq_plus_a); - ADOLC_PUT_LOCINT(a_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res + put_op(eq_plus_a); + ADOLC_PUT_LOCINT(a_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (coval) { - put_op(plus_d_a); - ADOLC_PUT_LOCINT(a_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); - } else { - put_op(assign_a); - ADOLC_PUT_LOCINT(a_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; - if (coval) { - put_op(eq_plus_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } - } -#endif + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (coval) { + put_op(plus_d_a); + ADOLC_PUT_LOCINT(a_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); + } else { + put_op(assign_a); + ADOLC_PUT_LOCINT(a_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] += ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; -#if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; + if (coval) { + put_op(eq_plus_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + } + } #endif } + ADOLC_GLOBAL_TAPE_VARS.store[loc()] += ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; +#if defined(ADOLC_TRACK_ACTIVITY) + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]); +#endif + } - return *this; + return *this; } /*--------------------------------------------------------------------------*/ /* Subtract an adouble from another adouble */ -badouble& badouble::operator -= ( const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint y_loc = y.loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_a_same_arg(eq_min_a,loc(),y.loc()); +badouble &badouble::operator-=(const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint y_loc = y.loc(); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_a_same_arg(eq_min_a,loc(),y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc] && ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc] && + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(eq_min_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res + put_op(eq_min_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (coval) { - put_op(min_d_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); - } else { - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (coval) { + put_op(min_d_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); + } else { + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + } - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; - if (coval) { - put_op(eq_min_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + if (coval) { + put_op(eq_min_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]); + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]); #endif - return *this; + return *this; } /*--------------------------------------------------------------------------*/ /* olvo 991122 new version for y -= x1 * x2; */ -badouble& badouble::operator -= ( const adub& a ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint a_loc = a.loc(); - int upd = 0; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) -#endif - { - upd = upd_resloc_inc_prod(a_loc,loc(),eq_min_prod); - } - if (upd) { - /* kk 20170720 Activity Tracking: This case only happens if both - lhs and rhs have true in actStore, since previous operation - that created rhs is mult_a_a and we checked lhs above. - So no change is needed */ - ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_DELETE_SCAYLOR(&ADOLC_GLOBAL_TAPE_VARS.store[a_loc]); - --ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - ++ADOLC_CURRENT_TAPE_INFOS.num_eq_prod; - } else { - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(loc(),a_loc); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc] && ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { +badouble &badouble::operator-=(const adub &a) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint a_loc = a.loc(); + int upd = 0; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) +#endif + { + upd = upd_resloc_inc_prod(a_loc, loc(), eq_min_prod); + } + if (upd) { + /* kk 20170720 Activity Tracking: This case only happens if both + lhs and rhs have true in actStore, since previous operation + that created rhs is mult_a_a and we checked lhs above. + So no change is needed */ + ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_DELETE_SCAYLOR(&ADOLC_GLOBAL_TAPE_VARS.store[a_loc]); + --ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + ++ADOLC_CURRENT_TAPE_INFOS.num_eq_prod; + } else { + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(loc(),a_loc); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc] && + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(eq_min_a); - ADOLC_PUT_LOCINT(a_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res + put_op(eq_min_a); + ADOLC_PUT_LOCINT(a_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (coval) { - put_op(min_d_a); - ADOLC_PUT_LOCINT(a_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); - } else { - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(a_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; - if (coval) { - put_op(eq_min_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } - } -#endif + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (coval) { + put_op(min_d_a); + ADOLC_PUT_LOCINT(a_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); + } else { + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(a_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; -#if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; + if (coval) { + put_op(eq_min_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + } + } #endif } + ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= ADOLC_GLOBAL_TAPE_VARS.store[a_loc]; +#if defined(ADOLC_TRACK_ACTIVITY) + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[a_loc]); +#endif + } - return *this; + return *this; } /*--------------------------------------------------------------------------*/ /* Multiply an adouble by a floating point */ -badouble& badouble::operator *= ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_mult_d,loc(),coval); +badouble &badouble::operator*=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_mult_d,loc(),coval); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(eq_mult_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval + put_op(eq_mult_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] *= coval; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] *= coval; + return *this; } /*--------------------------------------------------------------------------*/ /* Multiply one adouble by another adouble*/ -badouble& badouble::operator *= ( const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint y_loc = y.loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_a_same_arg(eq_mult_a,loc(),y.loc()); +badouble &badouble::operator*=(const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint y_loc = y.loc(); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_a_same_arg(eq_mult_a,loc(),y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc] && ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc] && + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { #endif - put_op(eq_mult_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res + put_op(eq_mult_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; - if (coval == -1.0) { - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - } else if (coval == 1.0) { - put_op(pos_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - } else { - put_op(mult_d_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); - } + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[loc()]; + if (coval == -1.0) { + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + } else if (coval == 1.0) { + put_op(pos_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + } else { + put_op(mult_d_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; - put_op(eq_mult_d); - ADOLC_PUT_LOCINT(loc()); // = res - ADOLC_PUT_VAL(coval); // = coval + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + put_op(eq_mult_d); + ADOLC_PUT_LOCINT(loc()); // = res + ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } -#endif + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[loc()] *= ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + ADOLC_GLOBAL_TAPE_VARS.store[loc()] *= ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]); + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y_loc]); #endif - return *this; + return *this; } /*--------------------------------------------------------------------------*/ -badouble& badouble::operator /= (double y) { - *this = *this/y; - return *this; +badouble &badouble::operator/=(double y) { + *this = *this / y; + return *this; } /*--------------------------------------------------------------------------*/ -badouble& badouble::operator /= (const badouble& y) { - *this = *this * (1.0/y); - return *this; +badouble &badouble::operator/=(const badouble &y) { + *this = *this * (1.0 / y); + return *this; } /****************************************************************************/ /* COMPARISON */ /*--------------------------------------------------------------------------*/ /* The Not Equal Operator (!=) */ -bool operator != ( const badouble& v, double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (coval) - return (-coval+v != 0); - else { - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { +bool operator!=(const badouble &v, double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (coval) + return (-coval + v != 0); + else { + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { #endif - put_op(ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] ? neq_zero : eq_zero); - ADOLC_PUT_LOCINT(v.loc()); + put_op(ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] ? neq_zero : eq_zero); + ADOLC_PUT_LOCINT(v.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - } + } #endif - } - return (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] != 0); } + return (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] != 0); + } } /*--------------------------------------------------------------------------*/ /* The Equal Operator (==) */ -bool operator == ( const badouble& v, double coval) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (coval) - return (-coval+v == 0); - else { - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { +bool operator==(const badouble &v, double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (coval) + return (-coval + v == 0); + else { + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { #endif - put_op(ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] ? neq_zero : eq_zero); - ADOLC_PUT_LOCINT(v.loc()); + put_op(ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] ? neq_zero : eq_zero); + ADOLC_PUT_LOCINT(v.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - } + } #endif - } - return (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] == 0); } + return (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] == 0); + } } /*--------------------------------------------------------------------------*/ /* The Less than or Equal Operator (<=) */ -bool operator <= ( const badouble& v, double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (coval) - return (-coval+v <= 0); - else { - bool b = (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] <= 0); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { +bool operator<=(const badouble &v, double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (coval) + return (-coval + v <= 0); + else { + bool b = (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] <= 0); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { #endif - put_op(b ? le_zero : gt_zero); - ADOLC_PUT_LOCINT(v.loc()); + put_op(b ? le_zero : gt_zero); + ADOLC_PUT_LOCINT(v.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - } + } #endif - } - return b; } + return b; + } } /*--------------------------------------------------------------------------*/ /* The Greater than or Equal Operator (>=) */ -bool operator >= ( const badouble& v, double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (coval) - return (-coval+v >= 0); - else { - bool b = (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] >= 0); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { +bool operator>=(const badouble &v, double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (coval) + return (-coval + v >= 0); + else { + bool b = (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] >= 0); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { #endif - put_op(b ? ge_zero : lt_zero); - ADOLC_PUT_LOCINT(v.loc()); + put_op(b ? ge_zero : lt_zero); + ADOLC_PUT_LOCINT(v.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - } + } #endif - } - return b; } + return b; + } } /*--------------------------------------------------------------------------*/ /* The Greater than Operator (>) */ -bool operator > ( const badouble& v, double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (coval) - return (-coval+v > 0); - else { - bool b = (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] > 0); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { +bool operator>(const badouble &v, double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (coval) + return (-coval + v > 0); + else { + bool b = (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] > 0); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { #endif - put_op(b ? gt_zero : le_zero); - ADOLC_PUT_LOCINT(v.loc()); + put_op(b ? gt_zero : le_zero); + ADOLC_PUT_LOCINT(v.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - } + } #endif - } - return b; } + return b; + } } /*--------------------------------------------------------------------------*/ /* The Less than Operator (<) */ -bool operator < ( const badouble& v, double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (coval) - return (-coval+v < 0); - else { - bool b = (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] < 0); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { +bool operator<(const badouble &v, double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (coval) + return (-coval + v < 0); + else { + bool b = (ADOLC_GLOBAL_TAPE_VARS.store[v.loc()] < 0); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[v.loc()]) { #endif - put_op(b ? lt_zero : ge_zero); - ADOLC_PUT_LOCINT(v.loc()); + put_op(b ? lt_zero : ge_zero); + ADOLC_PUT_LOCINT(v.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - } + } #endif - } - return b; } + return b; + } } - /****************************************************************************/ /* SIGN OPERATORS */ /*--------------------------------------------------------------------------*/ /* olvo 980709 modified positive sign operator ??? possibly there is a better way */ -adub operator + ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; +adub operator+(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_pos_sign_a(locat,x.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_pos_sign_a(locat,x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(pos_sign_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res + put_op(pos_sign_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* olvo 980709 modified negative sign operator */ -adub operator - ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; +adub operator-(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_neg_sign_a(locat,x.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_neg_sign_a(locat,x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (- coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (- coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(- coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (-coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (-coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(-coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = - coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = -coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - return locat; + return locat; } - /****************************************************************************/ /* BINARY OPERATORS */ @@ -1523,723 +1558,756 @@ adub operator - ( const badouble& x ) { /*--------------------------------------------------------------------------*/ /* Adding two adoubles */ -adub operator + ( const badouble& x, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()] + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_two_a_rec(plus_a_a,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { -#endif - put_op(plus_a_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { - put_op(plus_d_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - if (coval) { - put_op(plus_d_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); - } else { - put_op(pos_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } +adub operator+(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()] + + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_two_a_rec(plus_a_a,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { +#endif + put_op(plus_a_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + put_op(plus_d_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + if (coval) { + put_op(plus_d_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); + } else { + put_op(pos_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* Adding a adouble and a floating point */ -adub operator + ( double coval, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = coval + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; +adub operator+(double coval, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = coval + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { #endif - /* olvo 980708 test coval to be zero */ - if (coval) { - put_op(plus_d_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval - } else { - put_op(pos_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } + /* olvo 980708 test coval to be zero */ + if (coval) { + put_op(plus_d_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval + } else { + put_op(pos_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]; #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* Subtraction of two adoubles */ -adub operator - ( const badouble& x, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()] - ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_two_a_rec(min_a_a,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { -#endif - put_op(min_a_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { - double coval = - ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - put_op(plus_d_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - if (coval) { - put_op(min_d_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); - } else { - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } +adub operator-(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()] - + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_two_a_rec(min_a_a,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { +#endif + put_op(min_a_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + double coval = -ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + put_op(plus_d_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + if (coval) { + put_op(min_d_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); + } else { + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); #endif - return locat; + return locat; } - /*--------------------------------------------------------------------------*/ /* Subtract an adouble from a floating point */ -adub operator - ( double coval, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = coval - ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; +adub operator-(double coval, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = coval - ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(min_d_a,locat,coval,y.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(min_d_a,locat,coval,y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { #endif - /* olvo 980708 test coval to be zero */ - if (coval) { - put_op(min_d_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval - } else { - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } + /* olvo 980708 test coval to be zero */ + if (coval) { + put_op(min_d_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval + } else { + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]; #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* Multiply two adoubles */ -adub operator * ( const badouble& x, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()] * ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_two_a_rec(mult_a_a,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { -#endif - put_op(mult_a_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - put_op(mult_d_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - if (coval == -1.0) { - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } else if (coval == 1.0) { - put_op(pos_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } else { - put_op(mult_d_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } +adub operator*(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()] * + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_two_a_rec(mult_a_a,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { +#endif + put_op(mult_a_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + put_op(mult_d_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + if (coval == -1.0) { + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } else if (coval == 1.0) { + put_op(pos_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } else { + put_op(mult_d_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* Multiply an adouble by a floating point */ /* olvo 980709 modified */ -adub operator * ( double coval, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = coval * ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; +adub operator*(double coval, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = coval * ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_pos_sign_a(locat,y.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_pos_sign_a(locat,y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { #endif - if ( coval == 1.0 ) { - put_op(pos_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } else if ( coval == -1.0 ) { - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } else { - put_op(mult_d_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } + if (coval == 1.0) { + put_op(pos_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } else if (coval == -1.0) { + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } else { + put_op(mult_d_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]; #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* Divide an adouble by another adouble */ -adub operator / ( const badouble& x, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()] / ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; +adub operator/(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()] / + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_two_a_rec(div_a_a,locat,x.loc(),y.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_two_a_rec(div_a_a,locat,x.loc(),y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { #endif - put_op(div_a_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { - double coval = 1.0/ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - if (coval == -1.0) { - put_op(neg_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } else if (coval == 1.0) { - put_op(pos_sign_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - } else { - put_op(mult_d_a); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - put_op(div_d_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); + put_op(div_a_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + double coval = 1.0 / ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + if (coval == -1.0) { + put_op(neg_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } else if (coval == 1.0) { + put_op(pos_sign_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + } else { + put_op(mult_d_a); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + put_op(div_d_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* Division floating point - adouble */ -adub operator / ( double coval, const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = coval / ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(div_d_a,locat,coval,y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { -#endif - put_op(div_d_a); - ADOLC_PUT_LOCINT(y.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub operator/(double coval, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = coval / ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(div_d_a,locat,coval,y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { +#endif + put_op(div_d_a); + ADOLC_PUT_LOCINT(y.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]; #endif - return locat; + return locat; } - /****************************************************************************/ /* SINGLE OPERATIONS */ /*--------------------------------------------------------------------------*/ /* Compute exponential of adouble */ -adub exp ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP::exp(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); +adub exp(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_MATH_NSP::exp(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_single_op(exp_op,locat,x.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_single_op(exp_op,locat,x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(exp_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res + put_op(exp_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Compute logarithm of adouble */ -adub log ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP::log(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); +adub log(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_MATH_NSP::log(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_single_op(log_op,locat,x.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_single_op(log_op,locat,x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(log_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res + put_op(log_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Compute sqrt of adouble */ -adub sqrt ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP::sqrt(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); +adub sqrt(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_MATH_NSP::sqrt(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_single_op(sqrt_op,locat,x.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_single_op(sqrt_op,locat,x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(sqrt_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res + put_op(sqrt_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Compute cbrt of adouble */ -adub cbrt ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP::cbrt(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); +adub cbrt(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_MATH_NSP::cbrt(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(cbrt_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res + put_op(cbrt_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /****************************************************************************/ @@ -2249,435 +2317,459 @@ adub cbrt ( const badouble& x ) { /* Compute sin of adouble !!! Sin and Cos are always evaluated together */ -adub sin ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval1 = ADOLC_MATH_NSP::sin(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - double coval2 = ADOLC_MATH_NSP::cos(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); +adub sin(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval1 = ADOLC_MATH_NSP::sin(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + double coval2 = ADOLC_MATH_NSP::cos(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - adouble y; + adouble y; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(sin_op,locat,x.loc(),y.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(sin_op,locat,x.loc(),y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(sin_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res + put_op(sin_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += 2; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) { /* olvo 980921 changed order */ - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += 2; + if (ADOLC_CURRENT_TAPE_INFOS + .keepTaylors) { /* olvo 980921 changed order */ + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } #if defined(ADOLC_TRACK_ACTIVITY) - } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval1 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval1 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval1); - } + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval1 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval1 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval1); + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(y.loc()); - } else if (coval1 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(y.loc()); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(y.loc()); - ADOLC_PUT_VAL(coval2); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(y.loc()); + } else if (coval1 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(y.loc()); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(y.loc()); + ADOLC_PUT_VAL(coval2); + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval1; - ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval1; + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Compute cos of adouble */ -adub cos ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval1 = ADOLC_MATH_NSP::cos(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - double coval2 = ADOLC_MATH_NSP::sin(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); +adub cos(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval1 = ADOLC_MATH_NSP::cos(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + double coval2 = ADOLC_MATH_NSP::sin(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - adouble y; + adouble y; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(cos_op, locat,x.loc(),y.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(cos_op, locat,x.loc(),y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(cos_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res + put_op(cos_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += 2; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) { /* olvo 980921 changed order */ - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += 2; + if (ADOLC_CURRENT_TAPE_INFOS + .keepTaylors) { /* olvo 980921 changed order */ + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } #if defined(ADOLC_TRACK_ACTIVITY) - } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval1 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval1 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval1); - } + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval1 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval1 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval1); + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(y.loc()); - } else if (coval1 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(y.loc()); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(y.loc()); - ADOLC_PUT_VAL(coval2); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(y.loc()); + } else if (coval1 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(y.loc()); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(y.loc()); + ADOLC_PUT_VAL(coval2); + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]); } -#endif } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval1; - ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval1; + ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Compute tan of adouble */ -adub tan ( const badouble& x ) { - return sin(x) / cos(x); -} +adub tan(const badouble &x) { return sin(x) / cos(x); } /*--------------------------------------------------------------------------*/ /* Asin value -- really a quadrature */ -adub asin ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP::asin(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - - adouble y = 1.0 / sqrt(1.0 - x*x); +adub asin(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_MATH_NSP::asin(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + + adouble y = 1.0 / sqrt(1.0 - x * x); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(asin_op,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS + .actStore[x.loc()]) { // y will have same activity as x and can be + // considered as second input here +#endif + put_op(asin_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); + } - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(asin_op,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { // y will have same activity as x and can be considered as second input here -#endif - put_op(asin_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } -#endif + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Acos value -- really a quadrature */ -adub acos ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP::acos(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - - adouble y = -1.0 / sqrt(1.0 - x*x); - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(acos_op,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { // y will have same activity as x and can be considered as second input here -#endif - put_op(acos_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub acos(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_MATH_NSP::acos(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + + adouble y = -1.0 / sqrt(1.0 - x * x); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(acos_op,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS + .actStore[x.loc()]) { // y will have same activity as x and can be + // considered as second input here +#endif + put_op(acos_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Atan value -- really a quadrature */ -adub atan ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP::atan(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - - adouble y = 1.0 / (1.0 + x*x); - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(atan_op,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { // y will have same activity as x and can be considered as second input here -#endif - put_op(atan_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub atan(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_MATH_NSP::atan(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + + adouble y = 1.0 / (1.0 + x * x); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(atan_op,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS + .actStore[x.loc()]) { // y will have same activity as x and can be + // considered as second input here +#endif + put_op(atan_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ -adouble atan2( const badouble& y, const badouble& x) { - adouble a1, a2, ret, sy; - const double pihalf = ADOLC_MATH_NSP::asin(1.0); - /* y+0.0 is a hack since condassign is currently not defined for - badoubles */ - condassign( sy, y, (adouble)1.0 , (adouble)-1.0 ); - condassign( a1, x, atan(y/x), atan(y/x)+sy*2*pihalf); - condassign( a2, fabs(y), sy*pihalf-atan(x/y), (adouble) 0.0 ); - condassign( ret, fabs(x) - fabs(y), a1, a2 ); - return ret; +adouble atan2(const badouble &y, const badouble &x) { + adouble a1, a2, ret, sy; + const double pihalf = ADOLC_MATH_NSP::asin(1.0); + /* y+0.0 is a hack since condassign is currently not defined for + badoubles */ + condassign(sy, y, (adouble)1.0, (adouble)-1.0); + condassign(a1, x, atan(y / x), atan(y / x) + sy * 2 * pihalf); + condassign(a2, fabs(y), sy * pihalf - atan(x / y), (adouble)0.0); + condassign(ret, fabs(x) - fabs(y), a1, a2); + return ret; } /*--------------------------------------------------------------------------*/ /* power value -- adouble ^ floating point */ -adub pow ( const badouble& x, double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval2 = ADOLC_MATH_NSP::pow(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()],coval); - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(pow_op,locat,cocval,x.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { -#endif - put_op(pow_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval2 == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval2 == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval2); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub pow(const badouble &x, double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval2 = + ADOLC_MATH_NSP::pow(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()], coval); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(pow_op,locat,cocval,x.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { +#endif + put_op(pow_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval2 == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval2 == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval2); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval2; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* power value --- floating point ^ adouble */ -adouble pow ( double coval, const badouble& y ) { - adouble ret; +adouble pow(double coval, const badouble &y) { + adouble ret; - if (coval <= 0) { - fprintf(DIAG_OUT,"\nADOL-C message: exponent at zero/negative constant basis deactivated\n"); - } + if (coval <= 0) { + fprintf(DIAG_OUT, "\nADOL-C message: exponent at zero/negative constant " + "basis deactivated\n"); + } - condassign (ret, (adouble) coval, exp(y*ADOLC_MATH_NSP::log(coval)), - (adouble) ADOLC_MATH_NSP::pow(coval,y.getValue()) ); + condassign(ret, (adouble)coval, exp(y * ADOLC_MATH_NSP::log(coval)), + (adouble)ADOLC_MATH_NSP::pow(coval, y.getValue())); - return ret; + return ret; } /*--------------------------------------------------------------------------*/ /* power value --- adouble ^ adouble */ -adouble pow ( const badouble& x, const badouble& y) { - adouble a1, a2, ret; - double vx = x.getValue(); - double vy = y.getValue(); - - if (!(vx > 0)) { - if (vx < 0 || vy >= 0) - fprintf(DIAG_OUT,"\nADOL-C message: exponent of zero/negative basis deactivated\n"); - else - fprintf(DIAG_OUT,"\nADOL-C message: negative exponent and zero basis deactivated\n"); - } - condassign(a1, -y, (adouble) ADOLC_MATH_NSP::pow(vx,vy), pow(x,vy)); - condassign(a2, fabs(x), pow(x, vy), a1); - condassign(ret, x, exp(y*log(x)),a2); +adouble pow(const badouble &x, const badouble &y) { + adouble a1, a2, ret; + double vx = x.getValue(); + double vy = y.getValue(); + + if (!(vx > 0)) { + if (vx < 0 || vy >= 0) + fprintf( + DIAG_OUT, + "\nADOL-C message: exponent of zero/negative basis deactivated\n"); + else + fprintf( + DIAG_OUT, + "\nADOL-C message: negative exponent and zero basis deactivated\n"); + } + condassign(a1, -y, (adouble)ADOLC_MATH_NSP::pow(vx, vy), pow(x, vy)); + condassign(a2, fabs(x), pow(x, vy), a1); + condassign(ret, x, exp(y * log(x)), a2); - return ret; + return ret; } /*--------------------------------------------------------------------------*/ /* log base 10 of an adouble */ -adub log10 ( const badouble& x ) { - return log(x) / ADOLC_MATH_NSP::log(10.0); -} +adub log10(const badouble &x) { return log(x) / ADOLC_MATH_NSP::log(10.0); } /*--------------------------------------------------------------------------*/ /* Hyperbolic Sine of an adouble */ /* 981119 olvo changed as J.M. Aparicio suggested */ -adub sinh ( const badouble& x ) { - if (x.getValue() < 0.0) { - adouble temp = exp(x); - return 0.5*(temp - 1.0/temp); - } else { - adouble temp = exp(-x); - return 0.5*(1.0/temp - temp); - } +adub sinh(const badouble &x) { + if (x.getValue() < 0.0) { + adouble temp = exp(x); + return 0.5 * (temp - 1.0 / temp); + } else { + adouble temp = exp(-x); + return 0.5 * (1.0 / temp - temp); + } } /*--------------------------------------------------------------------------*/ /* Hyperbolic Cosine of an adouble */ /* 981119 olvo changed as J.M. Aparicio suggested */ -adub cosh ( const badouble& x ) { - adouble temp = (x.getValue() < 0.0) ? exp(x) : exp(-x); - return 0.5*(temp + 1.0/temp); +adub cosh(const badouble &x) { + adouble temp = (x.getValue() < 0.0) ? exp(x) : exp(-x); + return 0.5 * (temp + 1.0 / temp); } /*--------------------------------------------------------------------------*/ @@ -2685,1143 +2777,1204 @@ adub cosh ( const badouble& x ) { Hyperbolic Tangent of an adouble value. */ /* 981119 olvo changed as J.M. Aparicio suggested */ -adub tanh ( const badouble& x ) { - if (x.getValue() < 0.0) { - adouble temp = exp(2.0*x); - return (temp - 1.0)/(temp + 1.0); - } else { - adouble temp = exp((-2.0)*x); - return (1.0 - temp)/(temp + 1.0); - } +adub tanh(const badouble &x) { + if (x.getValue() < 0.0) { + adouble temp = exp(2.0 * x); + return (temp - 1.0) / (temp + 1.0); + } else { + adouble temp = exp((-2.0) * x); + return (1.0 - temp) / (temp + 1.0); + } } /*--------------------------------------------------------------------------*/ /* Ceiling function (NOTE: This function is nondifferentiable) */ -adub ceil ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat=next_loc(); +adub ceil(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); - double coval = ADOLC_MATH_NSP::ceil(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + double coval = ADOLC_MATH_NSP::ceil(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(ceil_op,locat,coval,x.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(ceil_op,locat,coval,x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(ceil_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval + put_op(ceil_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* Floor function (NOTE: This function is nondifferentiable) */ -adub floor ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat=next_loc(); +adub floor(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); - double coval = - ADOLC_MATH_NSP::floor(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + double coval = ADOLC_MATH_NSP::floor(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(floor_op,locat,coval,x.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(floor_op,locat,coval,x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { #endif - put_op(floor_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval + put_op(floor_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); #if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* Asinh value -- really a quadrature */ -adub asinh ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP_ERF::asinh(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - - adouble y = 1.0 / sqrt(1.0 + x*x); - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(asinh_op,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { // y will have same activity as x and can be considered as second input here -#endif - put_op(asinh_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub asinh(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = + ADOLC_MATH_NSP_ERF::asinh(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + + adouble y = 1.0 / sqrt(1.0 + x * x); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(asinh_op,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS + .actStore[x.loc()]) { // y will have same activity as x and can be + // considered as second input here +#endif + put_op(asinh_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Acosh value -- really a quadrature */ -adub acosh ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP_ERF::acosh(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - - adouble y = 1.0 / sqrt(x*x-1.0); - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(acosh_op,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { // y will have same activity as x and can be considered as second input here -#endif - put_op(acosh_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub acosh(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = + ADOLC_MATH_NSP_ERF::acosh(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + + adouble y = 1.0 / sqrt(x * x - 1.0); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(acosh_op,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS + .actStore[x.loc()]) { // y will have same activity as x and can be + // considered as second input here +#endif + put_op(acosh_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Atanh value -- really a quadrature */ -adub atanh ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP_ERF::atanh(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - - adouble y = 1.0 / (1.0 - x*x); - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(atanh_op,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { // y will have same activity as x and can be considered as second input here -#endif - put_op(atanh_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub atanh(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = + ADOLC_MATH_NSP_ERF::atanh(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + + adouble y = 1.0 / (1.0 - x * x); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(atanh_op,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS + .actStore[x.loc()]) { // y will have same activity as x and can be + // considered as second input here +#endif + put_op(atanh_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* The error function erf */ -adub erf( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP_ERF::erf(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - - adouble y = 2.0 / - ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0))*exp(-x*x); - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(erf_op,locat,x.loc(),y.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { // y will have same activity as x and can be considered as second input here -#endif - put_op(erf_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub erf(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = ADOLC_MATH_NSP_ERF::erf(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + + adouble y = + 2.0 / ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * exp(-x * x); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(erf_op,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS + .actStore[x.loc()]) { // y will have same activity as x and can be + // considered as second input here +#endif + put_op(erf_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; -#if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; -} - -adub erfc( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - double coval = ADOLC_MATH_NSP_ERF::erfc(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - - adouble y = -2.0 / - ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0))*exp(-x*x); + } - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_quad(erfc_op,locat,x.loc(),y.loc()); + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { // y will have same activity as x and can be considered as second input here + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - put_op(erfc_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (coval == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(coval); - } + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; +} - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub erfc(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + double coval = + ADOLC_MATH_NSP_ERF::erfc(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + + adouble y = + -2.0 / ADOLC_MATH_NSP_ERF::sqrt(ADOLC_MATH_NSP::acos(-1.0)) * exp(-x * x); + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_quad(erfc_op,locat,x.loc(),y.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS + .actStore[x.loc()]) { // y will have same activity as x and can be + // considered as second input here +#endif + put_op(erfc_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (coval == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(coval); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = coval; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } /*--------------------------------------------------------------------------*/ /* Fabs Function (NOTE: This function is also nondifferentiable at x=0) */ -adub fabs ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); - - double coval = 1.0; - double temp = ADOLC_MATH_NSP::fabs(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); - if (temp != ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]) - coval = 0.0; - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { /* write_args_d_a(abs_val,locat,coval,x.loc()); */ -#if defined(ADOLC_TRACK_ACTIVITY) - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { -#endif - put_op(abs_val); - ADOLC_PUT_LOCINT(x.loc()); /* arg */ - ADOLC_PUT_LOCINT(locat); /* res */ - ADOLC_PUT_VAL(coval); /* coval */ - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) - ++ADOLC_CURRENT_TAPE_INFOS.numSwitches; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +adub fabs(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); + + double coval = 1.0; + double temp = ADOLC_MATH_NSP::fabs(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]); + if (temp != ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]) + coval = 0.0; + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { /* write_args_d_a(abs_val,locat,coval,x.loc()); */ +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { +#endif + put_op(abs_val); + ADOLC_PUT_LOCINT(x.loc()); /* arg */ + ADOLC_PUT_LOCINT(locat); /* res */ + ADOLC_PUT_VAL(coval); /* coval */ + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) + ++ADOLC_CURRENT_TAPE_INFOS.numSwitches; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(temp); } -#endif + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = temp; +#endif + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = temp; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]; #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /* max and min functions (changed : 11/15/95) */ -adub fmin ( const badouble& x, const badouble& y ) { /* olvo 980702 tested: return 0.5*fabs(x+y-fabs(x-y)); */ - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) - return ((x + y - fabs(x - y))/2.0); +adub fmin(const badouble &x, + const badouble + &y) { /* olvo 980702 tested: return 0.5*fabs(x+y-fabs(x-y)); */ + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) + return ((x + y - fabs(x - y)) / 2.0); #if defined(ADOLC_TRACK_ACTIVITY) if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - if ( ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] && ! ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] ) { - locint tmploc = x.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } - if ( ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && ! ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] ) { - locint tmploc = y.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } - } -#endif - - locint locat = next_loc(); - double coval, temp; - - if (ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] < ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]) { - coval = 0.0; - temp = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - } else { - coval = 1.0; - temp = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - } + if (ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] && + !ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + locint tmploc = x.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_min_op(x.loc(),y.loc(),locat,0.0); -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()] ) { + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] && + !ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { + locint tmploc = y.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } + } #endif - put_op(min_op); - ADOLC_PUT_LOCINT(x.loc()); // = arg1 - ADOLC_PUT_LOCINT(y.loc()); // = arg2 - ADOLC_PUT_LOCINT(locat); // = res - ADOLC_PUT_VAL(coval); // = coval - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(locat); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(locat); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(locat); - ADOLC_PUT_VAL(temp); - } + locint locat = next_loc(); + double coval, temp; - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } -#endif + if (ADOLC_GLOBAL_TAPE_VARS.store[y.loc()] < + ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]) { + coval = 0.0; + temp = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + } else { + coval = 1.0; + temp = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + } + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_min_op(x.loc(),y.loc(),locat,0.0); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]) { +#endif + put_op(min_op); + ADOLC_PUT_LOCINT(x.loc()); // = arg1 + ADOLC_PUT_LOCINT(y.loc()); // = arg2 + ADOLC_PUT_LOCINT(locat); // = res + ADOLC_PUT_VAL(coval); // = coval + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else if (ADOLC_GLOBAL_TAPE_VARS.actStore[locat]) { + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(locat); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(locat); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(locat); + ADOLC_PUT_VAL(temp); + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); } +#endif + } - ADOLC_GLOBAL_TAPE_VARS.store[locat]=temp; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = temp; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = + (ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] || + ADOLC_GLOBAL_TAPE_VARS.actStore[y.loc()]); #endif - return locat; + return locat; } /*--------------------------------------------------------------------------*/ /*21.8.96*/ -adub fmin ( double d, const badouble& y ) { - adouble x = d; - return (fmin (x,y)); +adub fmin(double d, const badouble &y) { + adouble x = d; + return (fmin(x, y)); } /*--------------------------------------------------------------------------*/ -adub fmin ( const badouble& x, double d ) { - adouble y = d; - return (fmin (x,y)); +adub fmin(const badouble &x, double d) { + adouble y = d; + return (fmin(x, y)); } /*--------------------------------------------------------------------------*/ -adub fmax ( const badouble& x, const badouble& y ) { - return (-fmin(-x,-y)); -} +adub fmax(const badouble &x, const badouble &y) { return (-fmin(-x, -y)); } /*--------------------------------------------------------------------------*/ /*21.8.96*/ -adub fmax ( double d, const badouble& y ) { - adouble x = d; - return (-fmin(-x,-y)); +adub fmax(double d, const badouble &y) { + adouble x = d; + return (-fmin(-x, -y)); } /*--------------------------------------------------------------------------*/ -adub fmax ( const badouble& x, double d ) { - adouble y = d; - return (-fmin(-x,-y)); +adub fmax(const badouble &x, double d) { + adouble y = d; + return (-fmin(-x, -y)); } /*--------------------------------------------------------------------------*/ /* Ldexp Function */ -adub ldexp ( const badouble& x, int exp ) { - return x*ldexp(1.0,exp); -} +adub ldexp(const badouble &x, int exp) { return x * ldexp(1.0, exp); } /*--------------------------------------------------------------------------*/ /* frexp Function */ -adub frexp ( const badouble& x, int* n) { - double v = frexp(x.value(), n); - adouble r = x - v; - adouble z = r - double(*n); - if (z == 0) { - return (x - double(*n)); - } else { - fprintf(stderr,"ADOL-C warning: std::frexp() returned inconsistent results\n"); - return (r - double(*n)); - } +adub frexp(const badouble &x, int *n) { + double v = frexp(x.value(), n); + adouble r = x - v; + adouble z = r - double(*n); + if (z == 0) { + return (x - double(*n)); + } else { + fprintf(stderr, + "ADOL-C warning: std::frexp() returned inconsistent results\n"); + return (r - double(*n)); + } } /*--------------------------------------------------------------------------*/ /* Macro for user defined quadratures, example myquad is below.*/ /* the forward sweep tests if the tape is executed exactly at */ /* the same argument point otherwise it stops with a returnval */ -#define extend_quad(func,integrand)\ -adouble func ( const badouble& arg )\ -{ adouble temp; \ - adouble val; \ - integrand; \ - ADOLC_OPENMP_THREAD_NUMBER; \ - ADOLC_OPENMP_GET_THREAD_NUMBER; \ - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) \ - { put_op(gen_quad); \ - ADOLC_PUT_LOCINT(arg.loc()); \ - ADOLC_PUT_LOCINT(val.loc()); \ - ADOLC_PUT_LOCINT(temp.loc()); \ - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; \ - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) \ - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[temp.loc()]); \ - } \ - ADOLC_GLOBAL_TAPE_VARS.store[temp.loc()]=func(ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]); \ - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) \ - { ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]); \ - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[temp.loc()]); \ - } \ - return temp; } - -double myquad(double& x) { - double res; - res = ADOLC_MATH_NSP::log(x); - return res; +#define extend_quad(func, integrand) \ + adouble func(const badouble &arg) { \ + adouble temp; \ + adouble val; \ + integrand; \ + ADOLC_OPENMP_THREAD_NUMBER; \ + ADOLC_OPENMP_GET_THREAD_NUMBER; \ + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { \ + put_op(gen_quad); \ + ADOLC_PUT_LOCINT(arg.loc()); \ + ADOLC_PUT_LOCINT(val.loc()); \ + ADOLC_PUT_LOCINT(temp.loc()); \ + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; \ + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) \ + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[temp.loc()]); \ + } \ + ADOLC_GLOBAL_TAPE_VARS.store[temp.loc()] = \ + func(ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]); \ + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { \ + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]); \ + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[temp.loc()]); \ + } \ + return temp; \ + } + +double myquad(double &x) { + double res; + res = ADOLC_MATH_NSP::log(x); + return res; } /* This defines the natural logarithm as a quadrature */ -extend_quad(myquad,val = 1/arg) - +extend_quad(myquad, val = 1 / arg) /****************************************************************************/ /* CONDITIONALS */ /*--------------------------------------------------------------------------*/ #if defined(ADOLC_ADVANCED_BRANCHING) -adub operator != (const badouble& x, const badouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - double res = (double)(xval != yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(neq_a_a); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y.loc()); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; -} -/*--------------------------------------------------------------------------*/ -adub operator == (const badouble& x, const badouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - double res = (double)(xval == yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(eq_a_a); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y.loc()); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; -} -/*--------------------------------------------------------------------------*/ -adub operator <= (const badouble& x, const badouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - double res = (double)(xval <= yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(le_a_a); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y.loc()); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; -} -/*--------------------------------------------------------------------------*/ -adub operator >= (const badouble& x, const badouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - double res = (double)(xval >= yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(ge_a_a); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y.loc()); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; -} -/*--------------------------------------------------------------------------*/ -adub operator > (const badouble& x, const badouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - double res = (double)(xval > yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(gt_a_a); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y.loc()); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; -} -/*--------------------------------------------------------------------------*/ -adub operator < (const badouble& x, const badouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; - double res = (double)(xval < yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(lt_a_a); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y.loc()); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; -} -#endif -/*--------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------*/ -void condassign( adouble &res, const badouble &cond, - const badouble &arg1, const badouble &arg2 ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_condassign(res.loc(),cond.loc(),arg1.loc(), - // arg2.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()] ) { - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[arg1.loc()] ) { - locint tmploc = arg1.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + adub + operator!=(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + double res = (double)(xval != yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(neq_a_a); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y.loc()); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; +} +/*--------------------------------------------------------------------------*/ +adub operator==(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + double res = (double)(xval == yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(eq_a_a); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y.loc()); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; +} +/*--------------------------------------------------------------------------*/ +adub operator<=(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + double res = (double)(xval <= yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(le_a_a); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y.loc()); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; +} +/*--------------------------------------------------------------------------*/ +adub operator>=(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + double res = (double)(xval >= yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(ge_a_a); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y.loc()); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; +} +/*--------------------------------------------------------------------------*/ +adub operator>(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + double res = (double)(xval > yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(gt_a_a); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y.loc()); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; +} +/*--------------------------------------------------------------------------*/ +adub operator<(const badouble &x, const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = ADOLC_GLOBAL_TAPE_VARS.store[y.loc()]; + double res = (double)(xval < yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(lt_a_a); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y.loc()); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; +} +#endif +/*--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------*/ +void condassign(adouble &res, const badouble &cond, const badouble &arg1, + const badouble &arg2) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: + // write_condassign(res.loc(),cond.loc(),arg1.loc(), + // arg2.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]) { + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[arg1.loc()]) { + locint tmploc = arg1.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); } - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[arg2.loc()] ) { - locint tmploc = arg2.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[arg2.loc()]) { + locint tmploc = arg2.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); } -#endif - put_op(cond_assign); - ADOLC_PUT_LOCINT(cond.loc()); // = arg - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); - ADOLC_PUT_LOCINT(arg1.loc()); // = arg1 - ADOLC_PUT_LOCINT(arg2.loc()); // = arg2 - ADOLC_PUT_LOCINT(res.loc()); // = res ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } +#endif + put_op(cond_assign); + ADOLC_PUT_LOCINT(cond.loc()); // = arg + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); + ADOLC_PUT_LOCINT(arg1.loc()); // = arg1 + ADOLC_PUT_LOCINT(arg2.loc()); // = arg2 + ADOLC_PUT_LOCINT(res.loc()); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); #if defined(ADOLC_TRACK_ACTIVITY) + } else { + locint x_loc; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + x_loc = arg1.loc(); + else + x_loc = arg2.loc(); + + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { + put_op(assign_a); + ADOLC_PUT_LOCINT(x_loc); // = arg + ADOLC_PUT_LOCINT(res.loc()); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); } else { - locint x_loc; - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - x_loc = arg1.loc(); - else - x_loc = arg2.loc(); - - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { - put_op(assign_a); - ADOLC_PUT_LOCINT(x_loc); // = arg - ADOLC_PUT_LOCINT(res.loc()); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + if (ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(res.loc()); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(res.loc()); // = res } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(res.loc()); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(res.loc()); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(res.loc()); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); - } + put_op(assign_d); + ADOLC_PUT_LOCINT(res.loc()); // = res + ADOLC_PUT_VAL(coval); // = coval } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + } } -#endif } +#endif + } + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; + else + ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; +#if defined(ADOLC_TRACK_ACTIVITY) + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]) { if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[arg1.loc()]; else - ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ! ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()] ) { - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[arg1.loc()]; - else - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[arg2.loc()]; - } else - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]; -#endif -} - -/*--------------------------------------------------------------------------*/ -void condassign( adouble &res, const badouble &cond, const badouble &arg ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_condassign2(res.loc(),cond.loc(),arg.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()] ) { - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[arg.loc()] ) { - locint tmploc = arg.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[arg2.loc()]; + } else + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]; +#endif +} - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); +/*--------------------------------------------------------------------------*/ +void condassign(adouble &res, const badouble &cond, const badouble &arg) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: + // write_condassign2(res.loc(),cond.loc(),arg.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]) { + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[arg.loc()]) { + locint tmploc = arg.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); } -#endif - put_op(cond_assign_s); - ADOLC_PUT_LOCINT(cond.loc()); // = arg - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); - ADOLC_PUT_LOCINT(arg.loc()); // = arg1 - ADOLC_PUT_LOCINT(res.loc()); // = res ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); -#if defined(ADOLC_TRACK_ACTIVITY) - } else { - locint x_loc; - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) { - x_loc = arg.loc(); - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { - put_op(assign_a); - ADOLC_PUT_LOCINT(x_loc); // = arg - ADOLC_PUT_LOCINT(res.loc()); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); - } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(res.loc()); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(res.loc()); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(res.loc()); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); - } - } - } + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); } #endif - } + put_op(cond_assign_s); + ADOLC_PUT_LOCINT(cond.loc()); // = arg + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); + ADOLC_PUT_LOCINT(arg.loc()); // = arg1 + ADOLC_PUT_LOCINT(res.loc()); // = res - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ! ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()] ) { - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[arg.loc()]; - } else - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]; -#endif -} -/*--------------------------------------------------------------------------*/ -void condeqassign( adouble &res, const badouble &cond, - const badouble &arg1, const badouble &arg2 ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_condassign(res.loc(),cond.loc(),arg1.loc(), - // arg2.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()] ) { - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[arg1.loc()] ) { - locint tmploc = arg1.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); +#if defined(ADOLC_TRACK_ACTIVITY) + } else { + locint x_loc; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) { + x_loc = arg.loc(); + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { + put_op(assign_a); + ADOLC_PUT_LOCINT(x_loc); // = arg + ADOLC_PUT_LOCINT(res.loc()); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(res.loc()); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(res.loc()); // = res } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); + put_op(assign_d); + ADOLC_PUT_LOCINT(res.loc()); // = res + ADOLC_PUT_VAL(coval); // = coval } ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + } } - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[arg2.loc()] ) { - locint tmploc = arg2.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } + } + } +#endif + } - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; +#if defined(ADOLC_TRACK_ACTIVITY) + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[arg.loc()]; + } else + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]; #endif - put_op(cond_eq_assign); - ADOLC_PUT_LOCINT(cond.loc()); // = arg - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); - ADOLC_PUT_LOCINT(arg1.loc()); // = arg1 - ADOLC_PUT_LOCINT(arg2.loc()); // = arg2 - ADOLC_PUT_LOCINT(res.loc()); // = res +} +/*--------------------------------------------------------------------------*/ +void condeqassign(adouble &res, const badouble &cond, const badouble &arg1, + const badouble &arg2) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: + // write_condassign(res.loc(),cond.loc(),arg1.loc(), + // arg2.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]) { + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[arg1.loc()]) { + locint tmploc = arg1.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[arg2.loc()]) { + locint tmploc = arg2.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } +#endif + put_op(cond_eq_assign); + ADOLC_PUT_LOCINT(cond.loc()); // = arg + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); + ADOLC_PUT_LOCINT(arg1.loc()); // = arg1 + ADOLC_PUT_LOCINT(arg2.loc()); // = arg2 + ADOLC_PUT_LOCINT(res.loc()); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); #if defined(ADOLC_TRACK_ACTIVITY) + } else { + locint x_loc; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + x_loc = arg1.loc(); + else + x_loc = arg2.loc(); + + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { + put_op(assign_a); + ADOLC_PUT_LOCINT(x_loc); // = arg + ADOLC_PUT_LOCINT(res.loc()); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); } else { - locint x_loc; - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - x_loc = arg1.loc(); - else - x_loc = arg2.loc(); - - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { - put_op(assign_a); - ADOLC_PUT_LOCINT(x_loc); // = arg - ADOLC_PUT_LOCINT(res.loc()); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + if (ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(res.loc()); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(res.loc()); // = res } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(res.loc()); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(res.loc()); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(res.loc()); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); - } + put_op(assign_d); + ADOLC_PUT_LOCINT(res.loc()); // = res + ADOLC_PUT_VAL(coval); // = coval } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + } } -#endif } +#endif + } - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] >= 0) - ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] >= 0) + ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; + else + ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; +#if defined(ADOLC_TRACK_ACTIVITY) + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[arg1.loc()]; else - ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ! ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()] ) { - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[arg1.loc()]; - else - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[arg2.loc()]; - } else - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]; -#endif -} - -/*--------------------------------------------------------------------------*/ -void condeqassign( adouble &res, const badouble &cond, const badouble &arg ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_condassign2(res.loc(),cond.loc(),arg.loc()); -#if defined(ADOLC_TRACK_ACTIVITY) - if ( ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()] ) { - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[arg.loc()] ) { - locint tmploc = arg.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[arg2.loc()]; + } else + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]; +#endif +} - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); +/*--------------------------------------------------------------------------*/ +void condeqassign(adouble &res, const badouble &cond, const badouble &arg) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: + // write_condassign2(res.loc(),cond.loc(),arg.loc()); +#if defined(ADOLC_TRACK_ACTIVITY) + if (ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]) { + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[arg.loc()]) { + locint tmploc = arg.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); } -#endif - put_op(cond_eq_assign_s); - ADOLC_PUT_LOCINT(cond.loc()); // = arg - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); - ADOLC_PUT_LOCINT(arg.loc()); // = arg1 - ADOLC_PUT_LOCINT(res.loc()); // = res ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); + } +#endif + put_op(cond_eq_assign_s); + ADOLC_PUT_LOCINT(cond.loc()); // = arg + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); + ADOLC_PUT_LOCINT(arg.loc()); // = arg1 + ADOLC_PUT_LOCINT(res.loc()); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); #if defined(ADOLC_TRACK_ACTIVITY) - } else { - locint x_loc; - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) { - x_loc = arg.loc(); - if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { - put_op(assign_a); - ADOLC_PUT_LOCINT(x_loc); // = arg - ADOLC_PUT_LOCINT(res.loc()); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); - } else { - if (ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()]) { - double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; - if (coval == 0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(res.loc()); // = res - } else if (coval == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(res.loc()); // = res - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(res.loc()); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); - } - } + } else { + locint x_loc; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) { + x_loc = arg.loc(); + if (ADOLC_GLOBAL_TAPE_VARS.actStore[x_loc]) { + put_op(assign_a); + ADOLC_PUT_LOCINT(x_loc); // = arg + ADOLC_PUT_LOCINT(res.loc()); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); + } else { + if (ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()]) { + double coval = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; + if (coval == 0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(res.loc()); // = res + } else if (coval == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(res.loc()); // = res + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(res.loc()); // = res + ADOLC_PUT_VAL(coval); // = coval + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.loc()]); } + } } -#endif } +#endif + } - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] >= 0) - ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] >= 0) + ADOLC_GLOBAL_TAPE_VARS.store[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; #if defined(ADOLC_TRACK_ACTIVITY) - if ( ! ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()] ) { - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[arg.loc()]; - } else - ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]; + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]) { + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[arg.loc()]; + } else + ADOLC_GLOBAL_TAPE_VARS.actStore[res.loc()] = + ADOLC_GLOBAL_TAPE_VARS.actStore[cond.loc()]; #endif } diff --git a/ADOL-C/src/adouble_tl.cpp b/ADOL-C/src/adouble_tl.cpp index 6ace5d49a..d6dd8cfa9 100644 --- a/ADOL-C/src/adouble_tl.cpp +++ b/ADOL-C/src/adouble_tl.cpp @@ -8,8 +8,8 @@ The first purpose is to actual compute the function, just as the same code written for double precision (single precision - complex - interval) arithmetic would. The second purpose is - to compute directional derivatives in forward mode of - automatic differentiation. + to compute directional derivatives in forward mode of + automatic differentiation. Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel, @@ -21,62 +21,65 @@ ----------------------------------------------------------------------------*/ +#include "dvlparms.h" #include #include #include #include -#include "dvlparms.h" using std::cout; -extern "C" void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line); +extern "C" void adolc_exit(int errorcode, const char *what, + const char *function, const char *file, int line); namespace adtl { - size_t adouble::numDir = 1; #ifdef USE_ADTL_REFCOUNTING size_t refcounter::refcnt = 0; #endif - #if USE_BOOST_POOL -boost::pool* adouble::advalpool = new -boost::pool((adouble::numDir+1) * sizeof(double), 32, 10000); +boost::pool *adouble::advalpool = + new boost::pool( + (adouble::numDir + 1) * sizeof(double), 32, 10000); #endif /******************* i/o operations ***************************************/ -ostream& operator << ( ostream& out, const adouble& a) { - out << "Value: " << a.PRIMAL_VALUE; - out << " ADValues (" << adouble::numDir << "): "; - FOR_I_EQ_1_LTEQ_NUMDIR - out << a.ADVAL_I << " "; - out << "(a)"; - return out; +ostream &operator<<(ostream &out, const adouble &a) { + out << "Value: " << a.PRIMAL_VALUE; + out << " ADValues (" << adouble::numDir << "): "; + FOR_I_EQ_1_LTEQ_NUMDIR + out << a.ADVAL_I << " "; + out << "(a)"; + return out; } -istream& operator >> ( istream& in, adouble& a) { - char c; - do in >> c; - while (c!=':' && !in.eof()); - in >> a.PRIMAL_VALUE; - unsigned int num; - do in >> c; - while (c!='(' && !in.eof()); - in >> num; - if (num>adouble::numDir) - { - cout << "ADOL-C error: to many directions in input\n"; - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - do in >> c; - while (c!=':' && !in.eof()); - FOR_I_EQ_1_LTEQ_NUMDIR - in >> a.ADVAL_I; - do in >> c; - while (c!=')' && !in.eof()); - return in; +istream &operator>>(istream &in, adouble &a) { + char c; + do + in >> c; + while (c != ':' && !in.eof()); + in >> a.PRIMAL_VALUE; + unsigned int num; + do + in >> c; + while (c != '(' && !in.eof()); + in >> num; + if (num > adouble::numDir) { + cout << "ADOL-C error: to many directions in input\n"; + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + do + in >> c; + while (c != ':' && !in.eof()); + FOR_I_EQ_1_LTEQ_NUMDIR + in >> a.ADVAL_I; + do + in >> c; + while (c != ')' && !in.eof()); + return in; } -} +} // namespace adtl diff --git a/ADOL-C/src/adouble_tl_hov.cpp b/ADOL-C/src/adouble_tl_hov.cpp index b3e6c0ae6..e6dd17eaa 100644 --- a/ADOL-C/src/adouble_tl_hov.cpp +++ b/ADOL-C/src/adouble_tl_hov.cpp @@ -8,8 +8,8 @@ The first purpose is to actual compute the function, just as the same code written for double precision (single precision - complex - interval) arithmetic would. The second purpose is - to compute directional derivatives in forward mode of - automatic differentiation. + to compute directional derivatives in forward mode of + automatic differentiation. Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel, @@ -21,19 +21,19 @@ ----------------------------------------------------------------------------*/ +#include "dvlparms.h" #include #include #include #include -#include "dvlparms.h" using std::cout; -extern "C" void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line); +extern "C" void adolc_exit(int errorcode, const char *what, + const char *function, const char *file, int line); namespace adtl_hov { - size_t adouble::numDir = 1; size_t adouble::degree = 1; @@ -41,44 +41,46 @@ size_t adouble::degree = 1; size_t refcounter::refcnt = 0; #endif - /* #if USE_BOOST_POOL boost::pool* adouble::advalpool = new -boost::pool((adouble::numDir+1) * sizeof(double), 32, 10000); -#endif +boost::pool((adouble::numDir+1) * +sizeof(double), 32, 10000); #endif */ /******************* i/o operations ***************************************/ -ostream& operator << ( ostream& out, const adouble& a) { - out << "Value: " << a.val; - out << " ADValues (" << adouble::numDir << "): "; - FOR_I_EQ_0_LT_NUMDIR - out << a.ADVAL_I << " "; - out << "(a)"; - return out; +ostream &operator<<(ostream &out, const adouble &a) { + out << "Value: " << a.val; + out << " ADValues (" << adouble::numDir << "): "; + FOR_I_EQ_0_LT_NUMDIR + out << a.ADVAL_I << " "; + out << "(a)"; + return out; } -istream& operator >> ( istream& in, adouble& a) { - char c; - do in >> c; - while (c!=':' && !in.eof()); - in >> a.val; - unsigned int num; - do in >> c; - while (c!='(' && !in.eof()); - in >> num; - if (num>adouble::numDir) - { - cout << "ADOL-C error: to many directions in input\n"; - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - do in >> c; - while (c!=':' && !in.eof()); - FOR_I_EQ_0_LT_NUMDIR - in >> a.ADVAL_I; - do in >> c; - while (c!=')' && !in.eof()); - return in; +istream &operator>>(istream &in, adouble &a) { + char c; + do + in >> c; + while (c != ':' && !in.eof()); + in >> a.val; + unsigned int num; + do + in >> c; + while (c != '(' && !in.eof()); + in >> num; + if (num > adouble::numDir) { + cout << "ADOL-C error: to many directions in input\n"; + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + do + in >> c; + while (c != ':' && !in.eof()); + FOR_I_EQ_0_LT_NUMDIR + in >> a.ADVAL_I; + do + in >> c; + while (c != ')' && !in.eof()); + return in; } -} +} // namespace adtl_hov diff --git a/ADOL-C/src/adouble_tl_indo.cpp b/ADOL-C/src/adouble_tl_indo.cpp index 51dd170fe..c09341e4a 100644 --- a/ADOL-C/src/adouble_tl_indo.cpp +++ b/ADOL-C/src/adouble_tl_indo.cpp @@ -2,7 +2,8 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: adouble_tl_indo.cpp Revision: $Id$ - Contents: adouble_tl.cpp contains that definitions of procedures used for sparse patterns. + Contents: adouble_tl.cpp contains that definitions of procedures used for +sparse patterns. Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel, @@ -14,57 +15,60 @@ ----------------------------------------------------------------------------*/ +#include "dvlparms.h" #include #include #include #include -#include "dvlparms.h" using std::cout; -extern "C" void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line); +extern "C" void adolc_exit(int errorcode, const char *what, + const char *function, const char *file, int line); namespace adtl_indo { /******************* i/o operations ***************************************/ -ostream& operator << ( ostream& out, const adouble& a) { - out << a.val; - return out; +ostream &operator<<(ostream &out, const adouble &a) { + out << a.val; + return out; } -istream& operator >> ( istream& in, adouble& a) { - in >> a.val; - return in; +istream &operator>>(istream &in, adouble &a) { + in >> a.val; + return in; } /**************** ADOLC_TRACELESS_SPARSE_PATTERN ****************************/ int ADOLC_Init_sparse_pattern(adouble *a, int n, unsigned int start_cnt) { - for(unsigned int i=0; i < n; i++) { - a[i].delete_pattern(); - a[i].pattern.push_back( i+start_cnt ); - } - return 3; + for (unsigned int i = 0; i < n; i++) { + a[i].delete_pattern(); + a[i].pattern.push_back(i + start_cnt); + } + return 3; } -int ADOLC_get_sparse_pattern(const adouble *const b, int m, unsigned int **&pat) { - pat = (unsigned int**) malloc(m*sizeof(unsigned int*)); - for( int i=0; i < m ; i++){ - //const_cast(b[i]).pattern.sort(); - //const_cast(b[i]).pattern.unique(); - if ( b[i].get_pattern_size() > 0 ) { - pat[i] = (unsigned int*) malloc(sizeof(unsigned int) * (b[i].get_pattern_size() +1) ); - pat[i][0] = b[i].get_pattern_size(); - const list& tmp_set = b[i].get_pattern(); - list::const_iterator it; - unsigned int l=1; - for(it = tmp_set.begin() ; it != tmp_set.end() ; it++,l++) - pat[i][l] = *it; - } else { - pat[i] = (unsigned int*) malloc(sizeof(unsigned int)); - pat[i][0] =0; - } +int ADOLC_get_sparse_pattern(const adouble *const b, int m, + unsigned int **&pat) { + pat = (unsigned int **)malloc(m * sizeof(unsigned int *)); + for (int i = 0; i < m; i++) { + // const_cast(b[i]).pattern.sort(); + // const_cast(b[i]).pattern.unique(); + if (b[i].get_pattern_size() > 0) { + pat[i] = (unsigned int *)malloc(sizeof(unsigned int) * + (b[i].get_pattern_size() + 1)); + pat[i][0] = b[i].get_pattern_size(); + const list &tmp_set = b[i].get_pattern(); + list::const_iterator it; + unsigned int l = 1; + for (it = tmp_set.begin(); it != tmp_set.end(); it++, l++) + pat[i][l] = *it; + } else { + pat[i] = (unsigned int *)malloc(sizeof(unsigned int)); + pat[i][0] = 0; } - return 3; + } + return 3; } -} +} // namespace adtl_indo diff --git a/ADOL-C/src/advector.cpp b/ADOL-C/src/advector.cpp index 701755b41..48ef8065d 100644 --- a/ADOL-C/src/advector.cpp +++ b/ADOL-C/src/advector.cpp @@ -8,593 +8,636 @@ Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ---------------------------------------------------------------------------*/ -#include #include +#include +#include "dvlparms.h" +#include "oplate.h" #include "taping_p.h" #include -#include "oplate.h" -#include "dvlparms.h" using std::vector; -adubref::adubref( locint lo, locint ref ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - location = lo; - refloc = (size_t)trunc(fabs(ADOLC_GLOBAL_TAPE_VARS.store[location])); - if (ref != refloc) { - fprintf(DIAG_OUT,"ADOL-C error: strange construction of an active" - " vector subscript reference\n(passed ref = %d, stored refloc = %d)\n",ref,refloc); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); - } - isInit = true; +adubref::adubref(locint lo, locint ref) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + location = lo; + refloc = (size_t)trunc(fabs(ADOLC_GLOBAL_TAPE_VARS.store[location])); + if (ref != refloc) { + fprintf( + DIAG_OUT, + "ADOL-C error: strange construction of an active" + " vector subscript reference\n(passed ref = %d, stored refloc = %d)\n", + ref, refloc); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + } + isInit = true; } adubref::~adubref() { #ifdef adolc_overwrite - if (isInit) - free_loc(location); + if (isInit) + free_loc(location); #endif } -adubref::operator adubref*() const { - locint locat = location; - locint refl = refloc; - const_cast(*this).isInit = false; - adubref *retp = new adubref(locat,refl); - return retp; +adubref::operator adubref *() const { + locint locat = location; + locint refl = refloc; + const_cast(*this).isInit = false; + adubref *retp = new adubref(locat, refl); + return retp; } adubref::operator adub() const { - locint locat = next_loc(); - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(locat,location); - put_op(ref_copyout); - ADOLC_PUT_LOCINT(location); // = arg - ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } + locint locat = next_loc(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(locat,location); + put_op(ref_copyout); + ADOLC_PUT_LOCINT(location); // = arg + ADOLC_PUT_LOCINT(locat); // = res + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } - ADOLC_GLOBAL_TAPE_VARS.store[locat]=ADOLC_GLOBAL_TAPE_VARS.store[refloc]; - return locat; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[refloc]; + return locat; } -adub adubref::operator++( int ) { - locint locat = next_loc(); - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; +adub adubref::operator++(int) { + locint locat = next_loc(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(locat,location); - put_op(ref_copyout); - ADOLC_PUT_LOCINT(location); // = arg - ADOLC_PUT_LOCINT(locat); // = res + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(locat,location); + put_op(ref_copyout); + ADOLC_PUT_LOCINT(location); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } - ADOLC_GLOBAL_TAPE_VARS.store[locat]=ADOLC_GLOBAL_TAPE_VARS.store[refloc]; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[refloc]; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_incr_decr_a(incr_a,location); - put_op(ref_incr_a); - ADOLC_PUT_LOCINT(location); // = res + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_incr_decr_a(incr_a,location); + put_op(ref_incr_a); + ADOLC_PUT_LOCINT(location); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc]++; - return locat; + ADOLC_GLOBAL_TAPE_VARS.store[refloc]++; + return locat; } -adub adubref::operator--( int ) { - locint locat = next_loc(); - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; +adub adubref::operator--(int) { + locint locat = next_loc(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(locat,location); - put_op(ref_copyout); - ADOLC_PUT_LOCINT(location); // = arg - ADOLC_PUT_LOCINT(locat); // = res + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(locat,location); + put_op(ref_copyout); + ADOLC_PUT_LOCINT(location); // = arg + ADOLC_PUT_LOCINT(locat); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } - ADOLC_GLOBAL_TAPE_VARS.store[locat]=ADOLC_GLOBAL_TAPE_VARS.store[refloc]; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[refloc]; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_incr_decr_a(incr_a,location); - put_op(ref_decr_a); - ADOLC_PUT_LOCINT(location); // = res + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_incr_decr_a(incr_a,location); + put_op(ref_decr_a); + ADOLC_PUT_LOCINT(location); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc]--; - return locat; + ADOLC_GLOBAL_TAPE_VARS.store[refloc]--; + return locat; } -adubref& adubref::operator++() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_incr_decr_a(incr_a,location); - put_op(ref_incr_a); - ADOLC_PUT_LOCINT(location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } +adubref &adubref::operator++() { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_incr_decr_a(incr_a,location); + put_op(ref_incr_a); + ADOLC_PUT_LOCINT(location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc]++; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc]++; + return *this; } -adubref& adubref::operator--() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_incr_decr_a(incr_a,location); - put_op(ref_decr_a); - ADOLC_PUT_LOCINT(location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } +adubref &adubref::operator--() { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_incr_decr_a(incr_a,location); + put_op(ref_decr_a); + ADOLC_PUT_LOCINT(location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc]--; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc]--; + return *this; } -adubref& adubref::operator = ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - if (coval == 0) { - put_op(ref_assign_d_zero); - ADOLC_PUT_LOCINT(location); // = res - } else - if (coval == 1.0) { - put_op(ref_assign_d_one); - ADOLC_PUT_LOCINT(location); // = res - } else { - put_op(ref_assign_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); +adubref &adubref::operator=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + if (coval == 0) { + put_op(ref_assign_d_zero); + ADOLC_PUT_LOCINT(location); // = res + } else if (coval == 1.0) { + put_op(ref_assign_d_one); + ADOLC_PUT_LOCINT(location); // = res + } else { + put_op(ref_assign_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] = coval; - return *this; + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[refloc] = coval; + return *this; } -adubref& adubref::operator = ( const badouble& x ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint x_loc = x.loc(); - if (location!=x_loc) - /* test this to avoid for x=x statements adjoint(x)=0 in reverse mode */ - { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_assign_a(location,x.location); - put_op(ref_assign_a); - ADOLC_PUT_LOCINT(x_loc); // = arg - ADOLC_PUT_LOCINT(location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } - - ADOLC_GLOBAL_TAPE_VARS.store[refloc]=ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; +adubref &adubref::operator=(const badouble &x) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint x_loc = x.loc(); + if (location != x_loc) + /* test this to avoid for x=x statements adjoint(x)=0 in reverse mode */ + { + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_assign_a(location,x.location); + put_op(ref_assign_a); + ADOLC_PUT_LOCINT(x_loc); // = arg + ADOLC_PUT_LOCINT(location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); } - return *this; + + ADOLC_GLOBAL_TAPE_VARS.store[refloc] = ADOLC_GLOBAL_TAPE_VARS.store[x_loc]; + } + return *this; } -adubref& adubref::operator = ( const adubref& x ) { - *this = adub(x); - return *this; +adubref &adubref::operator=(const adubref &x) { + *this = adub(x); + return *this; } -adubref& adubref::operator <<= ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - ADOLC_CURRENT_TAPE_INFOS.numInds++; +adubref &adubref::operator<<=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + ADOLC_CURRENT_TAPE_INFOS.numInds++; - put_op(ref_assign_ind); - ADOLC_PUT_LOCINT(location); // = res + put_op(ref_assign_ind); + ADOLC_PUT_LOCINT(location); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] = coval; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc] = coval; + return *this; } void adubref::declareIndependent() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - ADOLC_CURRENT_TAPE_INFOS.numInds++; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + ADOLC_CURRENT_TAPE_INFOS.numInds++; - put_op(ref_assign_ind); - ADOLC_PUT_LOCINT(location); // = res + put_op(ref_assign_ind); + ADOLC_PUT_LOCINT(location); // = res - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + } } -adubref& adubref::operator >>= (double& coval) { - adub(*this) >>= coval; - return *this; +adubref &adubref::operator>>=(double &coval) { + adub(*this) >>= coval; + return *this; } -void adubref::declareDependent() { - adub(*this).declareDependent(); -} +void adubref::declareDependent() { adub(*this).declareDependent(); } -adubref& adubref::operator += ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_plus_d,location,coval); - put_op(ref_eq_plus_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } +adubref &adubref::operator+=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_plus_d,location,coval); + put_op(ref_eq_plus_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] += coval; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc] += coval; + return *this; } -adubref& adubref::operator += ( const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint y_loc = y.loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_a_same_arg(eq_plus_a,location,y.location); - put_op(ref_eq_plus_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } +adubref &adubref::operator+=(const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint y_loc = y.loc(); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_a_same_arg(eq_plus_a,location,y.location); + put_op(ref_eq_plus_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] += ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc] += ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + return *this; } -adubref& adubref::operator -= ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_min_d,location,coval); - put_op(ref_eq_min_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } +adubref &adubref::operator-=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_min_d,location,coval); + put_op(ref_eq_min_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] -= coval; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc] -= coval; + return *this; } -adubref& adubref::operator -= ( const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint y_loc = y.loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_a_same_arg(eq_min_a,location,y.location); - put_op(ref_eq_min_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } +adubref &adubref::operator-=(const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint y_loc = y.loc(); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_a_same_arg(eq_min_a,location,y.location); + put_op(ref_eq_min_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] -= ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc] -= ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + return *this; } -adubref& adubref::operator *= ( double coval ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_mult_d,location,coval); - put_op(ref_eq_mult_d); - ADOLC_PUT_LOCINT(location); // = res - ADOLC_PUT_VAL(coval); // = coval - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } +adubref &adubref::operator*=(double coval) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_mult_d,location,coval); + put_op(ref_eq_mult_d); + ADOLC_PUT_LOCINT(location); // = res + ADOLC_PUT_VAL(coval); // = coval + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] *= coval; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc] *= coval; + return *this; } -adubref& adubref::operator *= ( const badouble& y ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint y_loc = y.loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_a_same_arg(eq_mult_a,location,y.location); - put_op(ref_eq_mult_a); - ADOLC_PUT_LOCINT(y_loc); // = arg - ADOLC_PUT_LOCINT(location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } +adubref &adubref::operator*=(const badouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint y_loc = y.loc(); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_a_same_arg(eq_mult_a,location,y.location); + put_op(ref_eq_mult_a); + ADOLC_PUT_LOCINT(y_loc); // = arg + ADOLC_PUT_LOCINT(location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] *= ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; - return *this; + ADOLC_GLOBAL_TAPE_VARS.store[refloc] *= ADOLC_GLOBAL_TAPE_VARS.store[y_loc]; + return *this; } -void condassign( adubref& res, const badouble &cond, - const badouble &arg1, const badouble &arg2 ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_condassign(res.location,cond.location,arg1.location, - // arg2.location); - put_op(ref_cond_assign); - ADOLC_PUT_LOCINT(cond.loc()); // = arg - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); - ADOLC_PUT_LOCINT(arg1.loc()); // = arg1 - ADOLC_PUT_LOCINT(arg2.loc()); // = arg2 - ADOLC_PUT_LOCINT(res.location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.refloc]); - } +void condassign(adubref &res, const badouble &cond, const badouble &arg1, + const badouble &arg2) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: + // write_condassign(res.location,cond.location,arg1.location, + // arg2.location); + put_op(ref_cond_assign); + ADOLC_PUT_LOCINT(cond.loc()); // = arg + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); + ADOLC_PUT_LOCINT(arg1.loc()); // = arg1 + ADOLC_PUT_LOCINT(arg2.loc()); // = arg2 + ADOLC_PUT_LOCINT(res.location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.refloc]); + } - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; - else - ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = + ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; + else + ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = + ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; } -void condassign( adubref& res, const badouble &cond, const badouble &arg ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_condassign2(res.location,cond.location,arg.location); - put_op(ref_cond_assign_s); - ADOLC_PUT_LOCINT(cond.loc()); // = arg - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); - ADOLC_PUT_LOCINT(arg.loc()); // = arg1 - ADOLC_PUT_LOCINT(res.location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.refloc]); - } +void condassign(adubref &res, const badouble &cond, const badouble &arg) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: + // write_condassign2(res.location,cond.location,arg.location); + put_op(ref_cond_assign_s); + ADOLC_PUT_LOCINT(cond.loc()); // = arg + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); + ADOLC_PUT_LOCINT(arg.loc()); // = arg1 + ADOLC_PUT_LOCINT(res.location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.refloc]); + } - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) - ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] > 0) + ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = + ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; } -void condeqassign( adubref& res, const badouble &cond, - const badouble &arg1, const badouble &arg2 ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_condassign(res.location,cond.location,arg1.location, - // arg2.location); - put_op(ref_cond_eq_assign); - ADOLC_PUT_LOCINT(cond.loc()); // = arg - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); - ADOLC_PUT_LOCINT(arg1.loc()); // = arg1 - ADOLC_PUT_LOCINT(arg2.loc()); // = arg2 - ADOLC_PUT_LOCINT(res.location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.refloc]); - } +void condeqassign(adubref &res, const badouble &cond, const badouble &arg1, + const badouble &arg2) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: + // write_condassign(res.location,cond.location,arg1.location, + // arg2.location); + put_op(ref_cond_eq_assign); + ADOLC_PUT_LOCINT(cond.loc()); // = arg + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); + ADOLC_PUT_LOCINT(arg1.loc()); // = arg1 + ADOLC_PUT_LOCINT(arg2.loc()); // = arg2 + ADOLC_PUT_LOCINT(res.location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.refloc]); + } - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] >= 0) - ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; - else - ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] >= 0) + ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = + ADOLC_GLOBAL_TAPE_VARS.store[arg1.loc()]; + else + ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = + ADOLC_GLOBAL_TAPE_VARS.store[arg2.loc()]; } -void condeqassign( adubref& res, const badouble &cond, const badouble &arg ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_condassign2(res.location,cond.location,arg.location); - put_op(ref_cond_eq_assign_s); - ADOLC_PUT_LOCINT(cond.loc()); // = arg - ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); - ADOLC_PUT_LOCINT(arg.loc()); // = arg1 - ADOLC_PUT_LOCINT(res.location); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.refloc]); - } +void condeqassign(adubref &res, const badouble &cond, const badouble &arg) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: + // write_condassign2(res.location,cond.location,arg.location); + put_op(ref_cond_eq_assign_s); + ADOLC_PUT_LOCINT(cond.loc()); // = arg + ADOLC_PUT_VAL(ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()]); + ADOLC_PUT_LOCINT(arg.loc()); // = arg1 + ADOLC_PUT_LOCINT(res.location); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[res.refloc]); + } - if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] >= 0) - ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; + if (ADOLC_GLOBAL_TAPE_VARS.store[cond.loc()] >= 0) + ADOLC_GLOBAL_TAPE_VARS.store[res.refloc] = + ADOLC_GLOBAL_TAPE_VARS.store[arg.loc()]; } -advector::blocker::blocker(size_t n) { - ensureContiguousLocations(n); -} +advector::blocker::blocker(size_t n) { ensureContiguousLocations(n); } bool advector::nondecreasing() const { - bool ret = true; - double last = - ADOLC_MATH_NSP::numeric_limits::infinity(); - vector::const_iterator iter = data.begin(); - for ( ; iter != data.end() && ret ; iter++) { - ret = ret && ( iter->value() >= last ); - last = iter->value(); - } - return ret; + bool ret = true; + double last = -ADOLC_MATH_NSP::numeric_limits::infinity(); + vector::const_iterator iter = data.begin(); + for (; iter != data.end() && ret; iter++) { + ret = ret && (iter->value() >= last); + last = iter->value(); + } + return ret; } -adub advector::operator[](const badouble& index) const { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - size_t idx = (size_t)trunc(fabs(ADOLC_GLOBAL_TAPE_VARS.store[index.loc()])); - locint locat = next_loc(); - size_t n = data.size(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(subscript); - ADOLC_PUT_LOCINT(index.loc()); - ADOLC_PUT_VAL(n); - ADOLC_PUT_LOCINT(data[0].loc()); - ADOLC_PUT_LOCINT(locat); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } +adub advector::operator[](const badouble &index) const { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + size_t idx = (size_t)trunc(fabs(ADOLC_GLOBAL_TAPE_VARS.store[index.loc()])); + locint locat = next_loc(); + size_t n = data.size(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(subscript); + ADOLC_PUT_LOCINT(index.loc()); + ADOLC_PUT_VAL(n); + ADOLC_PUT_LOCINT(data[0].loc()); + ADOLC_PUT_LOCINT(locat); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } - if (idx >= n) - fprintf(DIAG_OUT, "ADOL-C warning: index out of bounds while subscripting n=%zu, idx=%zu\n", n, idx); + if (idx >= n) + fprintf(DIAG_OUT, + "ADOL-C warning: index out of bounds while subscripting n=%zu, " + "idx=%zu\n", + n, idx); - ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[data[idx].loc()]; - return locat; + ADOLC_GLOBAL_TAPE_VARS.store[locat] = + ADOLC_GLOBAL_TAPE_VARS.store[data[idx].loc()]; + return locat; } -adubref advector::operator[](const badouble& index) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - size_t idx = (size_t) trunc(fabs(ADOLC_GLOBAL_TAPE_VARS.store[index.loc()])); - locint locat = next_loc(); - size_t n = data.size(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(subscript_ref); - ADOLC_PUT_LOCINT(index.loc()); - ADOLC_PUT_VAL(n); - ADOLC_PUT_LOCINT(data[0].loc()); - ADOLC_PUT_LOCINT(locat); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } +adubref advector::operator[](const badouble &index) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + size_t idx = (size_t)trunc(fabs(ADOLC_GLOBAL_TAPE_VARS.store[index.loc()])); + locint locat = next_loc(); + size_t n = data.size(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(subscript_ref); + ADOLC_PUT_LOCINT(index.loc()); + ADOLC_PUT_VAL(n); + ADOLC_PUT_LOCINT(data[0].loc()); + ADOLC_PUT_LOCINT(locat); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } - if (idx >= n) - fprintf(DIAG_OUT, "ADOL-C warning: index out of bounds while subscripting (ref) n=%zu, idx=%zu\n", n, idx); + if (idx >= n) + fprintf(DIAG_OUT, + "ADOL-C warning: index out of bounds while subscripting (ref) " + "n=%zu, idx=%zu\n", + n, idx); - ADOLC_GLOBAL_TAPE_VARS.store[locat] = data[idx].loc(); - return adubref(locat,data[idx].loc()); + ADOLC_GLOBAL_TAPE_VARS.store[locat] = data[idx].loc(); + return adubref(locat, data[idx].loc()); } -adouble advector::lookupindex(const badouble& x, const badouble& y) const { - if (!nondecreasing()) { - fprintf(DIAG_OUT, "ADOL-C error: can only call lookup index if advector ist nondecreasing\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); - } - if (y.value() < 0) { - fprintf(DIAG_OUT, "ADOL-C error: index lookup needs a nonnegative denominator\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); - } - adouble r = 0; - size_t n = data.size(); - for (size_t i = 0; i < n; i++) - condassign(r, x - data[i]*y, (adouble) (i+1)); - return r; +adouble advector::lookupindex(const badouble &x, const badouble &y) const { + if (!nondecreasing()) { + fprintf(DIAG_OUT, "ADOL-C error: can only call lookup index if advector " + "ist nondecreasing\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + } + if (y.value() < 0) { + fprintf(DIAG_OUT, + "ADOL-C error: index lookup needs a nonnegative denominator\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + } + adouble r = 0; + size_t n = data.size(); + for (size_t i = 0; i < n; i++) + condassign(r, x - data[i] * y, (adouble)(i + 1)); + return r; } void adolc_vec_copy(adouble *const dest, const adouble *const src, locint n) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (dest[n-1].loc() - dest[0].loc()!=(unsigned)n-1 || src[n-1].loc()-src[0].loc()!=(unsigned)n-1) fail(ADOLC_VEC_LOCATIONGAP); + if (dest[n - 1].loc() - dest[0].loc() != (unsigned)n - 1 || + src[n - 1].loc() - src[0].loc() != (unsigned)n - 1) + fail(ADOLC_VEC_LOCATIONGAP); if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(vec_copy); - ADOLC_PUT_LOCINT(src[0].loc()); - ADOLC_PUT_LOCINT(n); - ADOLC_PUT_LOCINT(dest[0].loc()); - for (locint i=0; i -#include #include +#include -#include "taping_p.h" -#include "oplate.h" #include "adolc/adouble.h" +#include "oplate.h" +#include "taping_p.h" #ifdef ADOLC_AMPI_SUPPORT -#include "ampi/ampi.h" -#include "ampi/adTool/support.h" -#include "ampi/tape/support.h" -#include "ampi/libCommon/modified.h" -#include "ampisupportAdolc.h" + #include "ampi/adTool/support.h" + #include "ampi/ampi.h" + #include "ampi/libCommon/modified.h" + #include "ampi/tape/support.h" + #include "ampisupportAdolc.h" MPI_Comm ADTOOL_AMPI_COMM_WORLD_SHADOW; -int AMPI_Init_NT(int* argc, - char*** argv) { +int AMPI_Init_NT(int *argc, char ***argv) { int rc; - rc=MPI_Init(argc, - argv); + rc = MPI_Init(argc, argv); ADTOOL_AMPI_setupTypes(); ADOLC_TLM_init(); - ourADTOOL_AMPI_FPCollection.pushBcastInfo_fp=&ADTOOL_AMPI_pushBcastInfo; - ourADTOOL_AMPI_FPCollection.popBcastInfo_fp=&ADTOOL_AMPI_popBcastInfo; - ourADTOOL_AMPI_FPCollection.pushDoubleArray_fp=&ADTOOL_AMPI_pushDoubleArray; - ourADTOOL_AMPI_FPCollection.popDoubleArray_fp=&ADTOOL_AMPI_popDoubleArray; - ourADTOOL_AMPI_FPCollection.pushReduceInfo_fp=&ADTOOL_AMPI_pushReduceInfo; - ourADTOOL_AMPI_FPCollection.popReduceCountAndType_fp=&ADTOOL_AMPI_popReduceCountAndType; - ourADTOOL_AMPI_FPCollection.popReduceInfo_fp=&ADTOOL_AMPI_popReduceInfo; - ourADTOOL_AMPI_FPCollection.pushSRinfo_fp=&ADTOOL_AMPI_pushSRinfo; - ourADTOOL_AMPI_FPCollection.popSRinfo_fp=&ADTOOL_AMPI_popSRinfo; - ourADTOOL_AMPI_FPCollection.pushGSinfo_fp=&ADTOOL_AMPI_pushGSinfo; - ourADTOOL_AMPI_FPCollection.popGScommSizeForRootOrNull_fp=&ADTOOL_AMPI_popGScommSizeForRootOrNull; - ourADTOOL_AMPI_FPCollection.popGSinfo_fp=&ADTOOL_AMPI_popGSinfo; - ourADTOOL_AMPI_FPCollection.pushGSVinfo_fp=&ADTOOL_AMPI_pushGSVinfo; - ourADTOOL_AMPI_FPCollection.popGSVinfo_fp=&ADTOOL_AMPI_popGSVinfo; - ourADTOOL_AMPI_FPCollection.push_CallCode_fp=&ADTOOL_AMPI_push_CallCode; - ourADTOOL_AMPI_FPCollection.push_CallCodeReserve_fp=&ADTOOL_AMPI_push_CallCodeReserve; - ourADTOOL_AMPI_FPCollection.pop_CallCode_fp=&ADTOOL_AMPI_pop_CallCode; - ourADTOOL_AMPI_FPCollection.push_AMPI_Request_fp=&ADTOOL_AMPI_push_AMPI_Request; - ourADTOOL_AMPI_FPCollection.pop_AMPI_Request_fp=&ADTOOL_AMPI_pop_AMPI_Request; - ourADTOOL_AMPI_FPCollection.push_request_fp=&ADTOOL_AMPI_push_request; - ourADTOOL_AMPI_FPCollection.pop_request_fp=&ADTOOL_AMPI_pop_request; - ourADTOOL_AMPI_FPCollection.push_comm_fp=&ADTOOL_AMPI_push_comm; - ourADTOOL_AMPI_FPCollection.pop_comm_fp=&ADTOOL_AMPI_pop_comm; - ourADTOOL_AMPI_FPCollection.rawData_fp=&ADTOOL_AMPI_rawData; - ourADTOOL_AMPI_FPCollection.rawDataV_fp=&ADTOOL_AMPI_rawDataV; - ourADTOOL_AMPI_FPCollection.packDType_fp=&ADTOOL_AMPI_packDType; - ourADTOOL_AMPI_FPCollection.unpackDType_fp=&ADTOOL_AMPI_unpackDType; - ourADTOOL_AMPI_FPCollection.writeData_fp=&ADTOOL_AMPI_writeData; - ourADTOOL_AMPI_FPCollection.writeDataV_fp=&ADTOOL_AMPI_writeDataV; - ourADTOOL_AMPI_FPCollection.rawAdjointData_fp=&ADTOOL_AMPI_rawAdjointData; - ourADTOOL_AMPI_FPCollection.Turn_fp=&ADTOOL_AMPI_Turn; - ourADTOOL_AMPI_FPCollection.mapBufForAdjoint_fp=&ADTOOL_AMPI_mapBufForAdjoint; - ourADTOOL_AMPI_FPCollection.setBufForAdjoint_fp=&ADTOOL_AMPI_setBufForAdjoint; - ourADTOOL_AMPI_FPCollection.getAdjointCount_fp=&ADTOOL_AMPI_getAdjointCount; - ourADTOOL_AMPI_FPCollection.setAdjointCount_fp=&ADTOOL_AMPI_setAdjointCount; - ourADTOOL_AMPI_FPCollection.setAdjointCountAndTempBuf_fp=&ADTOOL_AMPI_setAdjointCountAndTempBuf; - ourADTOOL_AMPI_FPCollection.allocateTempBuf_fp=&ADTOOL_AMPI_allocateTempBuf; - ourADTOOL_AMPI_FPCollection.releaseAdjointTempBuf_fp=&ADTOOL_AMPI_releaseAdjointTempBuf; - ourADTOOL_AMPI_FPCollection.incrementAdjoint_fp=&ADTOOL_AMPI_incrementAdjoint; - ourADTOOL_AMPI_FPCollection.multiplyAdjoint_fp=&ADTOOL_AMPI_multiplyAdjoint; - ourADTOOL_AMPI_FPCollection.divideAdjoint_fp=&ADTOOL_AMPI_divideAdjoint; - ourADTOOL_AMPI_FPCollection.equalAdjoints_fp=&ADTOOL_AMPI_equalAdjoints; - ourADTOOL_AMPI_FPCollection.nullifyAdjoint_fp=&ADTOOL_AMPI_nullifyAdjoint; - ourADTOOL_AMPI_FPCollection.setupTypes_fp=&ADTOOL_AMPI_setupTypes; - ourADTOOL_AMPI_FPCollection.cleanupTypes_fp=&ADTOOL_AMPI_cleanupTypes; - ourADTOOL_AMPI_FPCollection.FW_rawType_fp=&ADTOOL_AMPI_FW_rawType; - ourADTOOL_AMPI_FPCollection.BW_rawType_fp=&ADTOOL_AMPI_BW_rawType; - ourADTOOL_AMPI_FPCollection.isActiveType_fp=&ADTOOL_AMPI_isActiveType; - ourADTOOL_AMPI_FPCollection.allocateTempActiveBuf_fp=&ADTOOL_AMPI_allocateTempActiveBuf; - ourADTOOL_AMPI_FPCollection.releaseTempActiveBuf_fp=&ADTOOL_AMPI_releaseTempActiveBuf; - ourADTOOL_AMPI_FPCollection.copyActiveBuf_fp=&ADTOOL_AMPI_copyActiveBuf; + ourADTOOL_AMPI_FPCollection.pushBcastInfo_fp = &ADTOOL_AMPI_pushBcastInfo; + ourADTOOL_AMPI_FPCollection.popBcastInfo_fp = &ADTOOL_AMPI_popBcastInfo; + ourADTOOL_AMPI_FPCollection.pushDoubleArray_fp = &ADTOOL_AMPI_pushDoubleArray; + ourADTOOL_AMPI_FPCollection.popDoubleArray_fp = &ADTOOL_AMPI_popDoubleArray; + ourADTOOL_AMPI_FPCollection.pushReduceInfo_fp = &ADTOOL_AMPI_pushReduceInfo; + ourADTOOL_AMPI_FPCollection.popReduceCountAndType_fp = + &ADTOOL_AMPI_popReduceCountAndType; + ourADTOOL_AMPI_FPCollection.popReduceInfo_fp = &ADTOOL_AMPI_popReduceInfo; + ourADTOOL_AMPI_FPCollection.pushSRinfo_fp = &ADTOOL_AMPI_pushSRinfo; + ourADTOOL_AMPI_FPCollection.popSRinfo_fp = &ADTOOL_AMPI_popSRinfo; + ourADTOOL_AMPI_FPCollection.pushGSinfo_fp = &ADTOOL_AMPI_pushGSinfo; + ourADTOOL_AMPI_FPCollection.popGScommSizeForRootOrNull_fp = + &ADTOOL_AMPI_popGScommSizeForRootOrNull; + ourADTOOL_AMPI_FPCollection.popGSinfo_fp = &ADTOOL_AMPI_popGSinfo; + ourADTOOL_AMPI_FPCollection.pushGSVinfo_fp = &ADTOOL_AMPI_pushGSVinfo; + ourADTOOL_AMPI_FPCollection.popGSVinfo_fp = &ADTOOL_AMPI_popGSVinfo; + ourADTOOL_AMPI_FPCollection.push_CallCode_fp = &ADTOOL_AMPI_push_CallCode; + ourADTOOL_AMPI_FPCollection.push_CallCodeReserve_fp = + &ADTOOL_AMPI_push_CallCodeReserve; + ourADTOOL_AMPI_FPCollection.pop_CallCode_fp = &ADTOOL_AMPI_pop_CallCode; + ourADTOOL_AMPI_FPCollection.push_AMPI_Request_fp = + &ADTOOL_AMPI_push_AMPI_Request; + ourADTOOL_AMPI_FPCollection.pop_AMPI_Request_fp = + &ADTOOL_AMPI_pop_AMPI_Request; + ourADTOOL_AMPI_FPCollection.push_request_fp = &ADTOOL_AMPI_push_request; + ourADTOOL_AMPI_FPCollection.pop_request_fp = &ADTOOL_AMPI_pop_request; + ourADTOOL_AMPI_FPCollection.push_comm_fp = &ADTOOL_AMPI_push_comm; + ourADTOOL_AMPI_FPCollection.pop_comm_fp = &ADTOOL_AMPI_pop_comm; + ourADTOOL_AMPI_FPCollection.rawData_fp = &ADTOOL_AMPI_rawData; + ourADTOOL_AMPI_FPCollection.rawDataV_fp = &ADTOOL_AMPI_rawDataV; + ourADTOOL_AMPI_FPCollection.packDType_fp = &ADTOOL_AMPI_packDType; + ourADTOOL_AMPI_FPCollection.unpackDType_fp = &ADTOOL_AMPI_unpackDType; + ourADTOOL_AMPI_FPCollection.writeData_fp = &ADTOOL_AMPI_writeData; + ourADTOOL_AMPI_FPCollection.writeDataV_fp = &ADTOOL_AMPI_writeDataV; + ourADTOOL_AMPI_FPCollection.rawAdjointData_fp = &ADTOOL_AMPI_rawAdjointData; + ourADTOOL_AMPI_FPCollection.Turn_fp = &ADTOOL_AMPI_Turn; + ourADTOOL_AMPI_FPCollection.mapBufForAdjoint_fp = + &ADTOOL_AMPI_mapBufForAdjoint; + ourADTOOL_AMPI_FPCollection.setBufForAdjoint_fp = + &ADTOOL_AMPI_setBufForAdjoint; + ourADTOOL_AMPI_FPCollection.getAdjointCount_fp = &ADTOOL_AMPI_getAdjointCount; + ourADTOOL_AMPI_FPCollection.setAdjointCount_fp = &ADTOOL_AMPI_setAdjointCount; + ourADTOOL_AMPI_FPCollection.setAdjointCountAndTempBuf_fp = + &ADTOOL_AMPI_setAdjointCountAndTempBuf; + ourADTOOL_AMPI_FPCollection.allocateTempBuf_fp = &ADTOOL_AMPI_allocateTempBuf; + ourADTOOL_AMPI_FPCollection.releaseAdjointTempBuf_fp = + &ADTOOL_AMPI_releaseAdjointTempBuf; + ourADTOOL_AMPI_FPCollection.incrementAdjoint_fp = + &ADTOOL_AMPI_incrementAdjoint; + ourADTOOL_AMPI_FPCollection.multiplyAdjoint_fp = &ADTOOL_AMPI_multiplyAdjoint; + ourADTOOL_AMPI_FPCollection.divideAdjoint_fp = &ADTOOL_AMPI_divideAdjoint; + ourADTOOL_AMPI_FPCollection.equalAdjoints_fp = &ADTOOL_AMPI_equalAdjoints; + ourADTOOL_AMPI_FPCollection.nullifyAdjoint_fp = &ADTOOL_AMPI_nullifyAdjoint; + ourADTOOL_AMPI_FPCollection.setupTypes_fp = &ADTOOL_AMPI_setupTypes; + ourADTOOL_AMPI_FPCollection.cleanupTypes_fp = &ADTOOL_AMPI_cleanupTypes; + ourADTOOL_AMPI_FPCollection.FW_rawType_fp = &ADTOOL_AMPI_FW_rawType; + ourADTOOL_AMPI_FPCollection.BW_rawType_fp = &ADTOOL_AMPI_BW_rawType; + ourADTOOL_AMPI_FPCollection.isActiveType_fp = &ADTOOL_AMPI_isActiveType; + ourADTOOL_AMPI_FPCollection.allocateTempActiveBuf_fp = + &ADTOOL_AMPI_allocateTempActiveBuf; + ourADTOOL_AMPI_FPCollection.releaseTempActiveBuf_fp = + &ADTOOL_AMPI_releaseTempActiveBuf; + ourADTOOL_AMPI_FPCollection.copyActiveBuf_fp = &ADTOOL_AMPI_copyActiveBuf; return rc; } -locint startLocAssertContiguous(adouble* adoubleBuffer, int count) { - locint start=0; - if (count>0) { - start=adoubleBuffer->loc(); - assert(start+count-1==(adoubleBuffer+count-1)->loc()); // buf must have consecutive ascending locations +locint startLocAssertContiguous(adouble *adoubleBuffer, int count) { + locint start = 0; + if (count > 0) { + start = adoubleBuffer->loc(); + assert(start + count - 1 == + (adoubleBuffer + count - 1) + ->loc()); // buf must have consecutive ascending locations } return start; -} +} -void ADTOOL_AMPI_pushBcastInfo(void* buf, - int count, - MPI_Datatype datatype, - int root, - MPI_Comm comm) { +void ADTOOL_AMPI_pushBcastInfo(void *buf, int count, MPI_Datatype datatype, + int root, MPI_Comm comm) { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { int i, dt_idx = derivedTypeIdx(datatype); int activeVarCount, bitCountToFirstActive, bitCountToLastActive; if (isDerivedType(dt_idx)) { - derivedTypeData* dtdata = getDTypeData(); - activeVarCount = dtdata->num_actives[dt_idx]*count; - bitCountToFirstActive = dtdata->first_active_blocks[dt_idx];; - bitCountToLastActive = (count-1)*dtdata->extents[dt_idx] - + dtdata->last_active_blocks[dt_idx] - + sizeof(adouble)*(dtdata->last_active_block_lengths[dt_idx]-1); - } - else { - activeVarCount = count; - bitCountToFirstActive = 0; - bitCountToLastActive = (count-1)*sizeof(adouble); + derivedTypeData *dtdata = getDTypeData(); + activeVarCount = dtdata->num_actives[dt_idx] * count; + bitCountToFirstActive = dtdata->first_active_blocks[dt_idx]; + ; + bitCountToLastActive = + (count - 1) * dtdata->extents[dt_idx] + + dtdata->last_active_blocks[dt_idx] + + sizeof(adouble) * (dtdata->last_active_block_lengths[dt_idx] - 1); + } else { + activeVarCount = count; + bitCountToFirstActive = 0; + bitCountToLastActive = (count - 1) * sizeof(adouble); } - if (count>0) { + if (count > 0) { assert(buf); - locint start=((adouble*)((char*)buf+bitCountToFirstActive))->loc(); - locint end=((adouble*)((char*)buf+bitCountToLastActive))->loc(); - assert(start+activeVarCount-1==end); // buf must have consecutive ascending locations + locint start = ((adouble *)((char *)buf + bitCountToFirstActive))->loc(); + locint end = ((adouble *)((char *)buf + bitCountToLastActive))->loc(); + assert(start + activeVarCount - 1 == + end); // buf must have consecutive ascending locations ADOLC_PUT_LOCINT(start); - } - else { + } else { ADOLC_PUT_LOCINT(0); // have to put something } TAPE_AMPI_push_int(count); @@ -136,60 +146,49 @@ void ADTOOL_AMPI_pushBcastInfo(void* buf, } } -void ADTOOL_AMPI_popBcastInfo(void** buf, - int* count, - MPI_Datatype* datatype, - int* root, - MPI_Comm* comm, - void **idx) { +void ADTOOL_AMPI_popBcastInfo(void **buf, int *count, MPI_Datatype *datatype, + int *root, MPI_Comm *comm, void **idx) { TAPE_AMPI_pop_MPI_Comm(comm); TAPE_AMPI_pop_int(root); TAPE_AMPI_pop_MPI_Datatype(datatype); TAPE_AMPI_pop_int(count); - *buf=(void*)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); + *buf = (void *)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); } -void ADTOOL_AMPI_pushDoubleArray(void* buf, - int count) { +void ADTOOL_AMPI_pushDoubleArray(void *buf, int count) { int i; if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - for (i=0;i=0;i--) { + for (i = *count - 1; i >= 0; i--) { TAPE_AMPI_pop_double(&(buf[i])); } } -void ADTOOL_AMPI_pushReduceInfo(void* sbuf, - void* rbuf, - void* resultData, - int pushResultData, /* push resultData if true */ - int count, - MPI_Datatype datatype, - MPI_Op op, - int root, - MPI_Comm comm) { +void ADTOOL_AMPI_pushReduceInfo( + void *sbuf, void *rbuf, void *resultData, + int pushResultData, /* push resultData if true */ + int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - if (count>0) { + if (count > 0) { assert(rbuf); - ADOLC_PUT_LOCINT(startLocAssertContiguous((adouble*)rbuf,count)); - ADOLC_PUT_LOCINT(startLocAssertContiguous((adouble*)sbuf,count)); - } - else { + ADOLC_PUT_LOCINT(startLocAssertContiguous((adouble *)rbuf, count)); + ADOLC_PUT_LOCINT(startLocAssertContiguous((adouble *)sbuf, count)); + } else { ADOLC_PUT_LOCINT(0); ADOLC_PUT_LOCINT(0); } TAPE_AMPI_push_int(count); TAPE_AMPI_push_int(pushResultData); - ADTOOL_AMPI_pushDoubleArray(sbuf,count); - if (pushResultData) ADTOOL_AMPI_pushDoubleArray(resultData,count); + ADTOOL_AMPI_pushDoubleArray(sbuf, count); + if (pushResultData) + ADTOOL_AMPI_pushDoubleArray(resultData, count); TAPE_AMPI_push_int(pushResultData); TAPE_AMPI_push_MPI_Op(op); TAPE_AMPI_push_int(root); @@ -199,61 +198,55 @@ void ADTOOL_AMPI_pushReduceInfo(void* sbuf, } } -void ADTOOL_AMPI_popReduceCountAndType(int* count, - MPI_Datatype* datatype) { +void ADTOOL_AMPI_popReduceCountAndType(int *count, MPI_Datatype *datatype) { TAPE_AMPI_pop_int(count); TAPE_AMPI_pop_MPI_Datatype(datatype); } -void ADTOOL_AMPI_popReduceInfo(void** sbuf, - void** rbuf, - void** prevData, - void** resultData, - int* count, - MPI_Op* op, - int* root, - MPI_Comm* comm, - void **idx) { +void ADTOOL_AMPI_popReduceInfo(void **sbuf, void **rbuf, void **prevData, + void **resultData, int *count, MPI_Op *op, + int *root, MPI_Comm *comm, void **idx) { int popResultData; TAPE_AMPI_pop_MPI_Comm(comm); TAPE_AMPI_pop_int(root); TAPE_AMPI_pop_MPI_Op(op); TAPE_AMPI_pop_int(&popResultData); - if (popResultData) ADTOOL_AMPI_popDoubleArray((double*)(*resultData),count); - ADTOOL_AMPI_popDoubleArray((double*)(*prevData),count); + if (popResultData) + ADTOOL_AMPI_popDoubleArray((double *)(*resultData), count); + ADTOOL_AMPI_popDoubleArray((double *)(*prevData), count); TAPE_AMPI_pop_int(&popResultData); TAPE_AMPI_pop_int(count); - *sbuf=(void*)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); - *rbuf=(void*)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); + *sbuf = (void *)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); + *rbuf = (void *)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); } -void ADTOOL_AMPI_pushSRinfo(void* buf, - int count, - MPI_Datatype datatype, - int endPoint, - int tag, - enum AMPI_PairedWith_E pairedWith, - MPI_Comm comm) { +void ADTOOL_AMPI_pushSRinfo(void *buf, int count, MPI_Datatype datatype, + int endPoint, int tag, + enum AMPI_PairedWith_E pairedWith, MPI_Comm comm) { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { int i, dt_idx = derivedTypeIdx(datatype); int activeVarCount, bitCountToFirstActive, bitCountToLastActive; if (isDerivedType(dt_idx)) { - derivedTypeData* dtdata = getDTypeData(); - activeVarCount = dtdata->num_actives[dt_idx]*count; + derivedTypeData *dtdata = getDTypeData(); + activeVarCount = dtdata->num_actives[dt_idx] * count; bitCountToFirstActive = dtdata->first_active_blocks[dt_idx]; - bitCountToLastActive = (count-1)*dtdata->extents[dt_idx] - + dtdata->last_active_blocks[dt_idx] - + sizeof(adouble)*(dtdata->last_active_block_lengths[dt_idx]-1); + bitCountToLastActive = + (count - 1) * dtdata->extents[dt_idx] + + dtdata->last_active_blocks[dt_idx] + + sizeof(adouble) * (dtdata->last_active_block_lengths[dt_idx] - 1); + } else { + activeVarCount = count; + bitCountToFirstActive = 0; + bitCountToLastActive = (count - 1) * sizeof(adouble); } - else { activeVarCount = count; bitCountToFirstActive = 0; bitCountToLastActive = (count-1)*sizeof(adouble); } - if (count>0) { + if (count > 0) { assert(buf); - locint start=((adouble*)((char*)buf+bitCountToFirstActive))->loc(); - locint end=((adouble*)((char*)buf+bitCountToLastActive))->loc(); - assert(start+activeVarCount-1==end); // buf must have consecutive ascending locations + locint start = ((adouble *)((char *)buf + bitCountToFirstActive))->loc(); + locint end = ((adouble *)((char *)buf + bitCountToLastActive))->loc(); + assert(start + activeVarCount - 1 == + end); // buf must have consecutive ascending locations ADOLC_PUT_LOCINT(start); - } - else { + } else { ADOLC_PUT_LOCINT(0); // have to put something } TAPE_AMPI_push_int(count); @@ -265,48 +258,37 @@ void ADTOOL_AMPI_pushSRinfo(void* buf, } } -void ADTOOL_AMPI_popSRinfo(void** buf, - int* count, - MPI_Datatype* datatype, - int* endPoint, - int* tag, - AMPI_PairedWith_E* pairedWith, - MPI_Comm* comm, - void **idx) { +void ADTOOL_AMPI_popSRinfo(void **buf, int *count, MPI_Datatype *datatype, + int *endPoint, int *tag, + AMPI_PairedWith_E *pairedWith, MPI_Comm *comm, + void **idx) { TAPE_AMPI_pop_MPI_Comm(comm); - TAPE_AMPI_pop_int((int*)pairedWith); + TAPE_AMPI_pop_int((int *)pairedWith); TAPE_AMPI_pop_int(tag); TAPE_AMPI_pop_int(endPoint); TAPE_AMPI_pop_MPI_Datatype(datatype); TAPE_AMPI_pop_int(count); - *buf=(void*)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); + *buf = (void *)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); } -void ADTOOL_AMPI_pushGSinfo(int commSizeForRootOrNull, - void *rbuf, - int rcnt, - MPI_Datatype rtype, - void *buf, - int count, - MPI_Datatype type, - int root, - MPI_Comm comm) { +void ADTOOL_AMPI_pushGSinfo(int commSizeForRootOrNull, void *rbuf, int rcnt, + MPI_Datatype rtype, void *buf, int count, + MPI_Datatype type, int root, MPI_Comm comm) { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { int i; - TAPE_AMPI_push_int(commSizeForRootOrNull); // counter at the beginning - if(commSizeForRootOrNull>0) { + TAPE_AMPI_push_int(commSizeForRootOrNull); // counter at the beginning + if (commSizeForRootOrNull > 0) { TAPE_AMPI_push_int(rcnt); assert(rbuf); - ADOLC_PUT_LOCINT(startLocAssertContiguous((adouble*)rbuf,rcnt)); + ADOLC_PUT_LOCINT(startLocAssertContiguous((adouble *)rbuf, rcnt)); TAPE_AMPI_push_MPI_Datatype(rtype); } - locint start=0; // have to put something regardless - if (buf!=MPI_IN_PLACE && count>0) { + locint start = 0; // have to put something regardless + if (buf != MPI_IN_PLACE && count > 0) { assert(buf); - start=startLocAssertContiguous((adouble*)buf,count); - } - else { - count=0; + start = startLocAssertContiguous((adouble *)buf, count); + } else { + count = 0; } ADOLC_PUT_LOCINT(start); TAPE_AMPI_push_int(count); @@ -321,77 +303,69 @@ void ADTOOL_AMPI_popGScommSizeForRootOrNull(int *commSizeForRootOrNull) { TAPE_AMPI_pop_int(commSizeForRootOrNull); } -void ADTOOL_AMPI_popGSinfo(int commSizeForRootOrNull, - void **rbuf, - int *rcnt, - MPI_Datatype *rtype, - void **buf, - int *count, - MPI_Datatype *type, - int *root, - MPI_Comm *comm) { +void ADTOOL_AMPI_popGSinfo(int commSizeForRootOrNull, void **rbuf, int *rcnt, + MPI_Datatype *rtype, void **buf, int *count, + MPI_Datatype *type, int *root, MPI_Comm *comm) { int i; TAPE_AMPI_pop_MPI_Comm(comm); TAPE_AMPI_pop_int(root); TAPE_AMPI_pop_MPI_Datatype(type); TAPE_AMPI_pop_int(count); - locint bufLoc=get_locint_r(); - if (*count==0) { - if (commSizeForRootOrNull) *buf=MPI_IN_PLACE; - else *buf=0; - } - else *buf=(void*)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[bufLoc])); - if (commSizeForRootOrNull>0) { + locint bufLoc = get_locint_r(); + if (*count == 0) { + if (commSizeForRootOrNull) + *buf = MPI_IN_PLACE; + else + *buf = 0; + } else + *buf = (void *)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[bufLoc])); + if (commSizeForRootOrNull > 0) { TAPE_AMPI_pop_MPI_Datatype(rtype); - *rbuf=(void*)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); + *rbuf = (void *)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); TAPE_AMPI_pop_int(rcnt); - } - else { + } else { // at least initialize to something nonrandom - // because we know we always have valid addresses passed in here + // because we know we always have valid addresses passed in here // NOTE JU: may not be true for source transformation... - *rbuf=0; - *rcnt=0; + *rbuf = 0; + *rcnt = 0; } TAPE_AMPI_pop_int(&commSizeForRootOrNull); } -void ADTOOL_AMPI_pushGSVinfo(int commSizeForRootOrNull, - void *rbuf, - int *rcnts, - int *displs, - MPI_Datatype rtype, - void *buf, - int count, - MPI_Datatype type, - int root, - MPI_Comm comm) { +void ADTOOL_AMPI_pushGSVinfo(int commSizeForRootOrNull, void *rbuf, int *rcnts, + int *displs, MPI_Datatype rtype, void *buf, + int count, MPI_Datatype type, int root, + MPI_Comm comm) { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { int i; - int minDispls=INT_MAX,endOffsetMax=0; - TAPE_AMPI_push_int(commSizeForRootOrNull); // counter at the beginning - for (i=0;i0) { - if (minDispls>displs[i]) minDispls=displs[i]; - if (endOffsetMax 0) { + if (minDispls > displs[i]) + minDispls = displs[i]; + if (endOffsetMax < displs[i] + rcnts[i]) + endOffsetMax = displs[i] + rcnts[i]; } - if (endOffsetMax==0) minDispls=0; + if (endOffsetMax == 0) + minDispls = 0; } - if (commSizeForRootOrNull>0) { - assert(minDispls==0); // don't want to make assumptions about memory layout for nonzero displacements + if (commSizeForRootOrNull > 0) { + assert(minDispls == 0); // don't want to make assumptions about memory + // layout for nonzero displacements assert(rbuf); - ADOLC_PUT_LOCINT(startLocAssertContiguous((adouble*)rbuf,endOffsetMax)); + ADOLC_PUT_LOCINT(startLocAssertContiguous((adouble *)rbuf, endOffsetMax)); TAPE_AMPI_push_MPI_Datatype(rtype); } - locint start=0; // have to put something regardless - if (count>0 && buf!=MPI_IN_PLACE) { + locint start = 0; // have to put something regardless + if (count > 0 && buf != MPI_IN_PLACE) { assert(buf); - start=startLocAssertContiguous((adouble*)buf,count); - } - else { - count=0; + start = startLocAssertContiguous((adouble *)buf, count); + } else { + count = 0; } ADOLC_PUT_LOCINT(start); TAPE_AMPI_push_int(count); @@ -402,38 +376,33 @@ void ADTOOL_AMPI_pushGSVinfo(int commSizeForRootOrNull, } } -void ADTOOL_AMPI_popGSVinfo(int commSizeForRootOrNull, - void **rbuf, - int *rcnts, - int *displs, - MPI_Datatype *rtype, - void **buf, - int *count, - MPI_Datatype *type, - int *root, - MPI_Comm *comm) { +void ADTOOL_AMPI_popGSVinfo(int commSizeForRootOrNull, void **rbuf, int *rcnts, + int *displs, MPI_Datatype *rtype, void **buf, + int *count, MPI_Datatype *type, int *root, + MPI_Comm *comm) { int i; TAPE_AMPI_pop_MPI_Comm(comm); TAPE_AMPI_pop_int(root); TAPE_AMPI_pop_MPI_Datatype(type); TAPE_AMPI_pop_int(count); - locint bufLoc=get_locint_r(); - if (*count==0) { - if (commSizeForRootOrNull) *buf=MPI_IN_PLACE; - else *buf=0; - } - else *buf=(void*)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[bufLoc])); - if (commSizeForRootOrNull>0) { + locint bufLoc = get_locint_r(); + if (*count == 0) { + if (commSizeForRootOrNull) + *buf = MPI_IN_PLACE; + else + *buf = 0; + } else + *buf = (void *)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[bufLoc])); + if (commSizeForRootOrNull > 0) { TAPE_AMPI_pop_MPI_Datatype(rtype); - *rbuf=(void*)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); - } - else { + *rbuf = (void *)(&(ADOLC_CURRENT_TAPE_INFOS.rp_A[get_locint_r()])); + } else { // at least initialize to something nonrandom - // because we know we always have valid addresses passed in here + // because we know we always have valid addresses passed in here // NOTE JU: may not be true for source transformation... - *rbuf=0; + *rbuf = 0; } - for (i=commSizeForRootOrNull-1;i>=0;--i) { + for (i = commSizeForRootOrNull - 1; i >= 0; --i) { TAPE_AMPI_pop_int(&(displs[i])); TAPE_AMPI_pop_int(&(rcnts[i])); } @@ -442,103 +411,96 @@ void ADTOOL_AMPI_popGSVinfo(int commSizeForRootOrNull, void ADTOOL_AMPI_push_CallCode(enum AMPI_CallCode_E thisCall) { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - switch(thisCall) { - case AMPI_WAIT: - put_op(ampi_wait); - break; - case AMPI_BARRIER: - put_op(ampi_barrier); - break; - case AMPI_SEND: - put_op(ampi_send); - break; - case AMPI_RECV: - put_op(ampi_recv); - break; - case AMPI_ISEND: - put_op(ampi_isend); - break; - case AMPI_IRECV: - put_op(ampi_irecv); - break; - case AMPI_BCAST: - put_op(ampi_bcast); - break; - case AMPI_REDUCE: - put_op(ampi_reduce); - break; - case AMPI_ALLREDUCE: - put_op(ampi_allreduce); - break; - case AMPI_GATHER: - put_op(ampi_gather); - break; - case AMPI_SCATTER: - put_op(ampi_scatter); - break; - case AMPI_ALLGATHER: - put_op(ampi_allgather); - break; - default: - assert(0); - break; + switch (thisCall) { + case AMPI_WAIT: + put_op(ampi_wait); + break; + case AMPI_BARRIER: + put_op(ampi_barrier); + break; + case AMPI_SEND: + put_op(ampi_send); + break; + case AMPI_RECV: + put_op(ampi_recv); + break; + case AMPI_ISEND: + put_op(ampi_isend); + break; + case AMPI_IRECV: + put_op(ampi_irecv); + break; + case AMPI_BCAST: + put_op(ampi_bcast); + break; + case AMPI_REDUCE: + put_op(ampi_reduce); + break; + case AMPI_ALLREDUCE: + put_op(ampi_allreduce); + break; + case AMPI_GATHER: + put_op(ampi_gather); + break; + case AMPI_SCATTER: + put_op(ampi_scatter); + break; + case AMPI_ALLGATHER: + put_op(ampi_allgather); + break; + default: + assert(0); + break; } } } -void ADTOOL_AMPI_push_CallCodeReserve(enum AMPI_CallCode_E thisCall, unsigned int numlocations) { +void ADTOOL_AMPI_push_CallCodeReserve(enum AMPI_CallCode_E thisCall, + unsigned int numlocations) { if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - switch(thisCall) { - case AMPI_GATHERV: - put_op_reserve(ampi_gatherv, numlocations); - break; - case AMPI_SCATTERV: - put_op_reserve(ampi_scatterv, numlocations); - break; - case AMPI_ALLGATHERV: - put_op_reserve(ampi_allgatherv, numlocations); - break; - default: - assert(0); - break; + switch (thisCall) { + case AMPI_GATHERV: + put_op_reserve(ampi_gatherv, numlocations); + break; + case AMPI_SCATTERV: + put_op_reserve(ampi_scatterv, numlocations); + break; + case AMPI_ALLGATHERV: + put_op_reserve(ampi_allgatherv, numlocations); + break; + default: + assert(0); + break; } } } -void ADTOOL_AMPI_pop_CallCode(enum AMPI_CallCode_E *thisCall) { - assert(0); -} +void ADTOOL_AMPI_pop_CallCode(enum AMPI_CallCode_E *thisCall) { assert(0); } -void ADTOOL_AMPI_push_AMPI_Request(struct AMPI_Request_S *ampiRequest) { - ADTOOL_AMPI_pushSRinfo(ampiRequest->buf, - ampiRequest->count, - ampiRequest->datatype, - ampiRequest->endPoint, - ampiRequest->tag, - ampiRequest->pairedWith, - ampiRequest->comm); +void ADTOOL_AMPI_push_AMPI_Request(struct AMPI_Request_S *ampiRequest) { + ADTOOL_AMPI_pushSRinfo(ampiRequest->buf, ampiRequest->count, + ampiRequest->datatype, ampiRequest->endPoint, + ampiRequest->tag, ampiRequest->pairedWith, + ampiRequest->comm); if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { TAPE_AMPI_push_MPI_Request(ampiRequest->tracedRequest); TAPE_AMPI_push_int(ampiRequest->origin); } } -void ADTOOL_AMPI_pop_AMPI_Request(struct AMPI_Request_S *ampiRequest) { - TAPE_AMPI_pop_int((int*)&(ampiRequest->origin)); +void ADTOOL_AMPI_pop_AMPI_Request(struct AMPI_Request_S *ampiRequest) { + TAPE_AMPI_pop_int((int *)&(ampiRequest->origin)); TAPE_AMPI_pop_MPI_Request(&(ampiRequest->tracedRequest)); - ADTOOL_AMPI_popSRinfo(&(ampiRequest->adjointBuf), - &(ampiRequest->count), - &(ampiRequest->datatype), - &(ampiRequest->endPoint), - &(ampiRequest->tag), - &(ampiRequest->pairedWith), - &(ampiRequest->comm), - &(ampiRequest->idx)); + ADTOOL_AMPI_popSRinfo(&(ampiRequest->adjointBuf), &(ampiRequest->count), + &(ampiRequest->datatype), &(ampiRequest->endPoint), + &(ampiRequest->tag), &(ampiRequest->pairedWith), + &(ampiRequest->comm), &(ampiRequest->idx)); } -void ADTOOL_AMPI_push_request(MPI_Request request) { - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) TAPE_AMPI_push_MPI_Request(request); -} +void ADTOOL_AMPI_push_request(MPI_Request request) { + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) + TAPE_AMPI_push_MPI_Request(request); +} MPI_Request ADTOOL_AMPI_pop_request() { MPI_Request r; @@ -547,7 +509,8 @@ MPI_Request ADTOOL_AMPI_pop_request() { } void ADTOOL_AMPI_push_comm(MPI_Comm comm) { - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) TAPE_AMPI_push_MPI_Comm(comm); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) + TAPE_AMPI_push_MPI_Comm(comm); } MPI_Comm ADTOOL_AMPI_pop_comm() { @@ -556,586 +519,460 @@ MPI_Comm ADTOOL_AMPI_pop_comm() { return c; } -void * ADTOOL_AMPI_rawData(void* activeData, int *size) { - void *ret=0; - if (*size>0) { - adouble* adouble_p=(adouble*)activeData; - ret=(void*)(&(ADOLC_GLOBAL_TAPE_VARS.store[adouble_p->loc()])); +void *ADTOOL_AMPI_rawData(void *activeData, int *size) { + void *ret = 0; + if (*size > 0) { + adouble *adouble_p = (adouble *)activeData; + ret = (void *)(&(ADOLC_GLOBAL_TAPE_VARS.store[adouble_p->loc()])); } return ret; } -void * ADTOOL_AMPI_rawDataV(void* activeData, int commSize, int *counts, int *displs) { - void *ret=NULL; - int nonNullCount=0; - int minDispls=INT_MAX; - for (int i=0; i< commSize; ++i) { - if (counts[i]>nonNullCount) nonNullCount=counts[i]; - if (minDispls>displs[i]) minDispls=displs[i]; +void *ADTOOL_AMPI_rawDataV(void *activeData, int commSize, int *counts, + int *displs) { + void *ret = NULL; + int nonNullCount = 0; + int minDispls = INT_MAX; + for (int i = 0; i < commSize; ++i) { + if (counts[i] > nonNullCount) + nonNullCount = counts[i]; + if (minDispls > displs[i]) + minDispls = displs[i]; } - if (nonNullCount>0) { - assert(minDispls==0); - adouble* adouble_p=(adouble*)activeData; - ret=(void*)(&(ADOLC_GLOBAL_TAPE_VARS.store[adouble_p->loc()])); + if (nonNullCount > 0) { + assert(minDispls == 0); + adouble *adouble_p = (adouble *)activeData; + ret = (void *)(&(ADOLC_GLOBAL_TAPE_VARS.store[adouble_p->loc()])); } return ret; } -void * ADTOOL_AMPI_packDType(void* indata, void* outdata, int count, int idx) { - if (!isDerivedType(idx)) return indata; /* not derived type, or only passive elements */ +void *ADTOOL_AMPI_packDType(void *indata, void *outdata, int count, int idx) { + if (!isDerivedType(idx)) + return indata; /* not derived type, or only passive elements */ int i, j, s, in_offset, out_offset, dt_idx; MPI_Aint p_extent, extent; MPI_Datatype datatype; - derivedTypeData* dtdata = getDTypeData(); + derivedTypeData *dtdata = getDTypeData(); char *out_addr, *in_addr; p_extent = dtdata->p_extents[idx]; extent = dtdata->extents[idx]; - for (j=0;jcounts[idx];i++) { + for (j = 0; j < count; j++) { + in_offset = j * extent; + out_offset = j * p_extent; + for (i = 0; i < dtdata->counts[idx]; i++) { datatype = dtdata->arrays_of_types[idx][i]; - if (datatype==MPI_UB || datatype==MPI_LB) assert(0); + if (datatype == MPI_UB || datatype == MPI_LB) + assert(0); dt_idx = derivedTypeIdx(datatype); - out_addr = (char*)outdata + out_offset + (int)dtdata->arrays_of_p_displacements[idx][i]; - in_addr = (char*)indata + in_offset + (int)dtdata->arrays_of_displacements[idx][i]; - if (ADTOOL_AMPI_isActiveType(datatype)==AMPI_ACTIVE) { - memcpy(out_addr, - ADTOOL_AMPI_rawData((void*)in_addr,&dtdata->arrays_of_blocklengths[idx][i]), - sizeof(revreal)*dtdata->arrays_of_blocklengths[idx][i]); - } - else if (isDerivedType(dt_idx)) { - ADTOOL_AMPI_packDType(in_addr, - out_addr, - dtdata->arrays_of_blocklengths[idx][i], - dt_idx); - } - else { - if (datatype==MPI_DOUBLE) s = (int)sizeof(double); - else if (datatype==MPI_INT) s = (int)sizeof(int); - else if (datatype==MPI_FLOAT) s = (int)sizeof(float); - else if (datatype==MPI_CHAR) s = (int)sizeof(char); - else assert(0); - memcpy(out_addr, - in_addr, - s*dtdata->arrays_of_blocklengths[idx][i]); + out_addr = (char *)outdata + out_offset + + (int)dtdata->arrays_of_p_displacements[idx][i]; + in_addr = (char *)indata + in_offset + + (int)dtdata->arrays_of_displacements[idx][i]; + if (ADTOOL_AMPI_isActiveType(datatype) == AMPI_ACTIVE) { + memcpy(out_addr, + ADTOOL_AMPI_rawData((void *)in_addr, + &dtdata->arrays_of_blocklengths[idx][i]), + sizeof(revreal) * dtdata->arrays_of_blocklengths[idx][i]); + } else if (isDerivedType(dt_idx)) { + ADTOOL_AMPI_packDType(in_addr, out_addr, + dtdata->arrays_of_blocklengths[idx][i], dt_idx); + } else { + if (datatype == MPI_DOUBLE) + s = (int)sizeof(double); + else if (datatype == MPI_INT) + s = (int)sizeof(int); + else if (datatype == MPI_FLOAT) + s = (int)sizeof(float); + else if (datatype == MPI_CHAR) + s = (int)sizeof(char); + else + assert(0); + memcpy(out_addr, in_addr, s * dtdata->arrays_of_blocklengths[idx][i]); } } } return outdata; } -void * ADTOOL_AMPI_unpackDType(void* indata, void* outdata, int count, int idx) { - if (!isDerivedType(idx)) return indata; /* not derived type, or only passive elements */ +void *ADTOOL_AMPI_unpackDType(void *indata, void *outdata, int count, int idx) { + if (!isDerivedType(idx)) + return indata; /* not derived type, or only passive elements */ int i, j, s, in_offset, out_offset, dt_idx; MPI_Aint p_extent, extent; MPI_Datatype datatype; - derivedTypeData* dtdata = getDTypeData(); + derivedTypeData *dtdata = getDTypeData(); char *out_addr, *in_addr; p_extent = dtdata->p_extents[idx]; extent = dtdata->extents[idx]; - for (j=0;jcounts[idx];i++) { + for (j = 0; j < count; j++) { + in_offset = j * p_extent; + out_offset = j * extent; + for (i = 0; i < dtdata->counts[idx]; i++) { datatype = dtdata->arrays_of_types[idx][i]; - if (datatype==MPI_UB || datatype==MPI_LB) assert(0); + if (datatype == MPI_UB || datatype == MPI_LB) + assert(0); dt_idx = derivedTypeIdx(datatype); - out_addr = (char*)outdata + out_offset + (int)dtdata->arrays_of_displacements[idx][i]; - in_addr = (char*)indata + in_offset + (int)dtdata->arrays_of_p_displacements[idx][i]; - if (ADTOOL_AMPI_isActiveType(datatype)==AMPI_ACTIVE) { - memcpy(ADTOOL_AMPI_rawData((void*)out_addr,&dtdata->arrays_of_blocklengths[idx][i]), - in_addr, - sizeof(revreal)*dtdata->arrays_of_blocklengths[idx][i]); - } - else if (isDerivedType(dt_idx)) { - ADTOOL_AMPI_unpackDType(in_addr, - out_addr, - dtdata->arrays_of_blocklengths[idx][i], - dt_idx); - } - else { - if (datatype==MPI_DOUBLE) s = (int)sizeof(double); - else if (datatype==MPI_INT) s = (int)sizeof(int); - else if (datatype==MPI_FLOAT) s = (int)sizeof(float); - else if (datatype==MPI_CHAR) s = (int)sizeof(char); - else assert(0); - memcpy(out_addr, - in_addr, - s*dtdata->arrays_of_blocklengths[idx][i]); + out_addr = (char *)outdata + out_offset + + (int)dtdata->arrays_of_displacements[idx][i]; + in_addr = (char *)indata + in_offset + + (int)dtdata->arrays_of_p_displacements[idx][i]; + if (ADTOOL_AMPI_isActiveType(datatype) == AMPI_ACTIVE) { + memcpy(ADTOOL_AMPI_rawData((void *)out_addr, + &dtdata->arrays_of_blocklengths[idx][i]), + in_addr, + sizeof(revreal) * dtdata->arrays_of_blocklengths[idx][i]); + } else if (isDerivedType(dt_idx)) { + ADTOOL_AMPI_unpackDType(in_addr, out_addr, + dtdata->arrays_of_blocklengths[idx][i], dt_idx); + } else { + if (datatype == MPI_DOUBLE) + s = (int)sizeof(double); + else if (datatype == MPI_INT) + s = (int)sizeof(int); + else if (datatype == MPI_FLOAT) + s = (int)sizeof(float); + else if (datatype == MPI_CHAR) + s = (int)sizeof(char); + else + assert(0); + memcpy(out_addr, in_addr, s * dtdata->arrays_of_blocklengths[idx][i]); } } } return outdata; } -void ADTOOL_AMPI_writeData(void* activeData,int *size) {} +void ADTOOL_AMPI_writeData(void *activeData, int *size) {} -void ADTOOL_AMPI_writeDataV(void* activeData, int *counts, int* displs) {} +void ADTOOL_AMPI_writeDataV(void *activeData, int *counts, int *displs) {} -void * ADTOOL_AMPI_rawAdjointData(void* activeData) { - return activeData; -} +void *ADTOOL_AMPI_rawAdjointData(void *activeData) { return activeData; } -void ADTOOL_AMPI_mapBufForAdjoint(struct AMPI_Request_S *ampiRequest, - void* buf) { - ampiRequest->buf=buf; +void ADTOOL_AMPI_mapBufForAdjoint(struct AMPI_Request_S *ampiRequest, + void *buf) { + ampiRequest->buf = buf; } -void ADTOOL_AMPI_Turn(void* buf, void* adjointBuf) {} +void ADTOOL_AMPI_Turn(void *buf, void *adjointBuf) {} -void ADTOOL_AMPI_setBufForAdjoint(struct AMPI_Request_S *ampiRequest, - void* buf) { +void ADTOOL_AMPI_setBufForAdjoint(struct AMPI_Request_S *ampiRequest, + void *buf) { /* do nothing */ } -void ADTOOL_AMPI_getAdjointCount(int *count, - MPI_Datatype datatype) { +void ADTOOL_AMPI_getAdjointCount(int *count, MPI_Datatype datatype) { int dt_idx = derivedTypeIdx(datatype); - if (isDerivedType(dt_idx)) *count *= getDTypeData()->num_actives[dt_idx]; + if (isDerivedType(dt_idx)) + *count *= getDTypeData()->num_actives[dt_idx]; } -void ADTOOL_AMPI_setAdjointCount(struct AMPI_Request_S *ampiRequest) { - /* for now we keep the count as is but for example in vector mode one would have to multiply by vector length */ - ampiRequest->adjointCount=ampiRequest->count; +void ADTOOL_AMPI_setAdjointCount(struct AMPI_Request_S *ampiRequest) { + /* for now we keep the count as is but for example in vector mode one would + * have to multiply by vector length */ + ampiRequest->adjointCount = ampiRequest->count; } -void ADTOOL_AMPI_setAdjointCountAndTempBuf(struct AMPI_Request_S *ampiRequest) { +void ADTOOL_AMPI_setAdjointCountAndTempBuf(struct AMPI_Request_S *ampiRequest) { ADTOOL_AMPI_setAdjointCount(ampiRequest); - ampiRequest->adjointTempBuf= - ADTOOL_AMPI_allocateTempBuf(ampiRequest->adjointCount, - ampiRequest->datatype, - ampiRequest->comm); + ampiRequest->adjointTempBuf = ADTOOL_AMPI_allocateTempBuf( + ampiRequest->adjointCount, ampiRequest->datatype, ampiRequest->comm); } -void* ADTOOL_AMPI_allocateTempBuf(int adjointCount, - MPI_Datatype dataType, +void *ADTOOL_AMPI_allocateTempBuf(int adjointCount, MPI_Datatype dataType, MPI_Comm comm) { - size_t s=0; - void* buf; + size_t s = 0; + void *buf; int dt_idx = derivedTypeIdx(dataType); - if (dataType==AMPI_ADOUBLE) s=sizeof(revreal); - else if(dataType==MPI_DOUBLE) s=sizeof(double); - else if(dataType==MPI_FLOAT) s=sizeof(float); - else if(isDerivedType(dt_idx)) s=getDTypeData()->p_extents[dt_idx]; - else MPI_Abort(comm, MPI_ERR_TYPE); - buf=malloc(adjointCount*s); + if (dataType == AMPI_ADOUBLE) + s = sizeof(revreal); + else if (dataType == MPI_DOUBLE) + s = sizeof(double); + else if (dataType == MPI_FLOAT) + s = sizeof(float); + else if (isDerivedType(dt_idx)) + s = getDTypeData()->p_extents[dt_idx]; + else + MPI_Abort(comm, MPI_ERR_TYPE); + buf = malloc(adjointCount * s); assert(buf); return buf; } -void ADTOOL_AMPI_releaseAdjointTempBuf(void *tempBuf) { - free(tempBuf); -} +void ADTOOL_AMPI_releaseAdjointTempBuf(void *tempBuf) { free(tempBuf); } -void* ADTOOL_AMPI_allocateTempActiveBuf(int count, - MPI_Datatype datatype, - MPI_Comm comm) { +void *ADTOOL_AMPI_allocateTempActiveBuf(int count, MPI_Datatype datatype, + MPI_Comm comm) { int dt_idx = derivedTypeIdx(datatype); if (isDerivedType(dt_idx)) { int i, j, extent, struct_offset, block_offset; MPI_Datatype blocktype; - derivedTypeData* dtdata = getDTypeData(); - void* buf; + derivedTypeData *dtdata = getDTypeData(); + void *buf; extent = dtdata->extents[dt_idx]; - buf = malloc(count*extent); + buf = malloc(count * extent); assert(buf); - for (j=0;jcounts[dt_idx];i++) { - blocktype = dtdata->arrays_of_types[dt_idx][i]; - if (blocktype==MPI_UB || blocktype==MPI_LB) assert(0); - block_offset = struct_offset + dtdata->arrays_of_displacements[dt_idx][i]; - if (blocktype==AMPI_ADOUBLE) { - new ((void*)((char*)buf + block_offset)) adouble[dtdata->arrays_of_blocklengths[dt_idx][i]]; - } + for (j = 0; j < count; j++) { + struct_offset = j * extent; + for (i = 0; i < dtdata->counts[dt_idx]; i++) { + blocktype = dtdata->arrays_of_types[dt_idx][i]; + if (blocktype == MPI_UB || blocktype == MPI_LB) + assert(0); + block_offset = + struct_offset + dtdata->arrays_of_displacements[dt_idx][i]; + if (blocktype == AMPI_ADOUBLE) { + new ((void *)((char *)buf + block_offset)) + adouble[dtdata->arrays_of_blocklengths[dt_idx][i]]; + } } } return buf; - } - else if (datatype==AMPI_ADOUBLE) { - adouble* buf = new adouble[count]; + } else if (datatype == AMPI_ADOUBLE) { + adouble *buf = new adouble[count]; assert(buf); return buf; - } - else assert(0); + } else + assert(0); } -void ADTOOL_AMPI_releaseTempActiveBuf(void *buf, - int count, - MPI_Datatype datatype) { +void ADTOOL_AMPI_releaseTempActiveBuf(void *buf, int count, + MPI_Datatype datatype) { int dt_idx = derivedTypeIdx(datatype); if (isDerivedType(dt_idx)) { int i, j, k, extent, struct_offset, block_offset; MPI_Datatype blocktype; - derivedTypeData* dtdata = getDTypeData(); + derivedTypeData *dtdata = getDTypeData(); extent = dtdata->extents[dt_idx]; - for (j=0;jcounts[dt_idx];i++) { - blocktype = dtdata->arrays_of_types[dt_idx][i]; - block_offset = struct_offset + dtdata->arrays_of_displacements[dt_idx][i]; - if (blocktype==AMPI_ADOUBLE) { - for (k=0;karrays_of_blocklengths[dt_idx][i];k++) { - ((adouble*)((char*)buf + block_offset + k*sizeof(adouble)))->~adouble(); - } - } + for (j = 0; j < count; j++) { + struct_offset = j * extent; + for (i = 0; i < dtdata->counts[dt_idx]; i++) { + blocktype = dtdata->arrays_of_types[dt_idx][i]; + block_offset = + struct_offset + dtdata->arrays_of_displacements[dt_idx][i]; + if (blocktype == AMPI_ADOUBLE) { + for (k = 0; k < dtdata->arrays_of_blocklengths[dt_idx][i]; k++) { + ((adouble *)((char *)buf + block_offset + k * sizeof(adouble))) + ->~adouble(); + } + } } } free(buf); - } - else if (datatype==AMPI_ADOUBLE) delete[] (adouble*)buf; - else assert(0); + } else if (datatype == AMPI_ADOUBLE) + delete[] (adouble *)buf; + else + assert(0); } -void * ADTOOL_AMPI_copyActiveBuf(void* source, - void* target, - int count, - MPI_Datatype datatype, - MPI_Comm comm) { +void *ADTOOL_AMPI_copyActiveBuf(void *source, void *target, int count, + MPI_Datatype datatype, MPI_Comm comm) { int s, k, dt_idx = derivedTypeIdx(datatype); - if (ADTOOL_AMPI_isActiveType(datatype)==AMPI_ACTIVE) { - for (k=0;kextents[dt_idx]; - for (j=0;jcounts[dt_idx];i++) { - blocktype = dtdata->arrays_of_types[dt_idx][i]; - if (blocktype==MPI_UB || blocktype==MPI_LB) assert(0); - block_offset = struct_offset + (int)dtdata->arrays_of_displacements[dt_idx][i]; - if (ADTOOL_AMPI_isActiveType(blocktype)==AMPI_ACTIVE) { - for (k=0;karrays_of_blocklengths[dt_idx][i];k++) { - ((adouble*)((char*)target + block_offset))[k] = ((adouble*)((char*)source + block_offset))[k]; - } - } - else { - if (blocktype==MPI_DOUBLE) s = sizeof(double); - else if (blocktype==MPI_INT) s = sizeof(int); - else if (blocktype==MPI_FLOAT) s = sizeof(float); - else if (blocktype==MPI_CHAR) s = sizeof(char); - memcpy((char*)target + block_offset, - (char*)source + block_offset, - s*dtdata->arrays_of_blocklengths[dt_idx][i]); - } + for (j = 0; j < count; j++) { + struct_offset = j * extent; + for (i = 0; i < dtdata->counts[dt_idx]; i++) { + blocktype = dtdata->arrays_of_types[dt_idx][i]; + if (blocktype == MPI_UB || blocktype == MPI_LB) + assert(0); + block_offset = + struct_offset + (int)dtdata->arrays_of_displacements[dt_idx][i]; + if (ADTOOL_AMPI_isActiveType(blocktype) == AMPI_ACTIVE) { + for (k = 0; k < dtdata->arrays_of_blocklengths[dt_idx][i]; k++) { + ((adouble *)((char *)target + block_offset))[k] = + ((adouble *)((char *)source + block_offset))[k]; + } + } else { + if (blocktype == MPI_DOUBLE) + s = sizeof(double); + else if (blocktype == MPI_INT) + s = sizeof(int); + else if (blocktype == MPI_FLOAT) + s = sizeof(float); + else if (blocktype == MPI_CHAR) + s = sizeof(char); + memcpy((char *)target + block_offset, (char *)source + block_offset, + s * dtdata->arrays_of_blocklengths[dt_idx][i]); + } } } - } - else assert(0); + } else + assert(0); return target; } -void ADTOOL_AMPI_incrementAdjoint(int adjointCount, - MPI_Datatype datatype, - MPI_Comm comm, - void* target, - void *source, - void *idx) { - for (unsigned int i=0; ipacked_types[dt_idx]; - else return datatype; + if (datatype == AMPI_ADOUBLE) + return MPI_DOUBLE; + else if (datatype == AMPI_AFLOAT) + return MPI_FLOAT; + else if (isDerivedType(dt_idx)) + return getDTypeData()->packed_types[dt_idx]; + else + return datatype; } MPI_Datatype ADTOOL_AMPI_BW_rawType(MPI_Datatype datatype) { int dt_idx = derivedTypeIdx(datatype); - if (datatype==AMPI_ADOUBLE) return MPI_DOUBLE; - else if (datatype==AMPI_AFLOAT) return MPI_FLOAT; - else if (isDerivedType(dt_idx)) return MPI_DOUBLE; - else return datatype; + if (datatype == AMPI_ADOUBLE) + return MPI_DOUBLE; + else if (datatype == AMPI_AFLOAT) + return MPI_FLOAT; + else if (isDerivedType(dt_idx)) + return MPI_DOUBLE; + else + return datatype; } -// tracing - -int AMPI_Send(void* buf, - int count, - MPI_Datatype datatype, - int src, - int tag, - AMPI_PairedWith pairedWith, - MPI_Comm comm) { - return FW_AMPI_Send(buf, - count, - datatype, - src, - tag, - pairedWith, - comm); +// tracing + +int AMPI_Send(void *buf, int count, MPI_Datatype datatype, int src, int tag, + AMPI_PairedWith pairedWith, MPI_Comm comm) { + return FW_AMPI_Send(buf, count, datatype, src, tag, pairedWith, comm); } -int AMPI_Recv(void* buf, - int count, - MPI_Datatype datatype, - int src, - int tag, - AMPI_PairedWith pairedWith, - MPI_Comm comm, - MPI_Status* status) { - return FW_AMPI_Recv(buf, - count, - datatype, - src, - tag, - pairedWith, - comm, - status); +int AMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, + AMPI_PairedWith pairedWith, MPI_Comm comm, MPI_Status *status) { + return FW_AMPI_Recv(buf, count, datatype, src, tag, pairedWith, comm, status); } -int AMPI_Isend (void* buf, - int count, - MPI_Datatype datatype, - int dest, - int tag, - AMPI_PairedWith pairedWith, - MPI_Comm comm, - AMPI_Request* request) { - return FW_AMPI_Isend(buf, - count, - datatype, - dest, - tag, - pairedWith, - comm, +int AMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, + AMPI_PairedWith pairedWith, MPI_Comm comm, + AMPI_Request *request) { + return FW_AMPI_Isend(buf, count, datatype, dest, tag, pairedWith, comm, request); } -int AMPI_Irecv (void* buf, - int count, - MPI_Datatype datatype, - int src, - int tag, - AMPI_PairedWith pairedWith, - MPI_Comm comm, - AMPI_Request* request) { - return FW_AMPI_Irecv(buf, - count, - datatype, - src, - tag, - pairedWith, - comm, +int AMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, + AMPI_PairedWith pairedWith, MPI_Comm comm, + AMPI_Request *request) { + return FW_AMPI_Irecv(buf, count, datatype, src, tag, pairedWith, comm, request); } -int AMPI_Wait(AMPI_Request *request, - MPI_Status *status) { - return FW_AMPI_Wait(request, - status); +int AMPI_Wait(AMPI_Request *request, MPI_Status *status) { + return FW_AMPI_Wait(request, status); } -int AMPI_Barrier(MPI_Comm comm) { - return FW_AMPI_Barrier(comm); -} +int AMPI_Barrier(MPI_Comm comm) { return FW_AMPI_Barrier(comm); } -int AMPI_Gather(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, - int root, +int AMPI_Gather(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm) { - return FW_AMPI_Gather(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnt, - recvtype, - root, - comm); + return FW_AMPI_Gather(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, recvtype, + root, comm); } -int AMPI_Scatter(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, - int root, MPI_Comm comm) { - return FW_AMPI_Scatter(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnt, - recvtype, - root, - comm); +int AMPI_Scatter(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, + MPI_Comm comm) { + return FW_AMPI_Scatter(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, recvtype, + root, comm); } -int AMPI_Allgather(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, +int AMPI_Allgather(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int recvcnt, MPI_Datatype recvtype, MPI_Comm comm) { - return FW_AMPI_Allgather(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnt, - recvtype, - comm); + return FW_AMPI_Allgather(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, + recvtype, comm); } -int AMPI_Gatherv(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int *recvcnts, - int *displs, - MPI_Datatype recvtype, - int root, - MPI_Comm comm) { - return FW_AMPI_Gatherv(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnts, - displs, - recvtype, - root, - comm); +int AMPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int *recvcnts, int *displs, + MPI_Datatype recvtype, int root, MPI_Comm comm) { + return FW_AMPI_Gatherv(sendbuf, sendcnt, sendtype, recvbuf, recvcnts, displs, + recvtype, root, comm); } -int AMPI_Scatterv(void *sendbuf, - int *sendcnts, - int *displs, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, - int root, MPI_Comm comm) { - return FW_AMPI_Scatterv(sendbuf, - sendcnts, - displs, - sendtype, - recvbuf, - recvcnt, - recvtype, - root, - comm); +int AMPI_Scatterv(void *sendbuf, int *sendcnts, int *displs, + MPI_Datatype sendtype, void *recvbuf, int recvcnt, + MPI_Datatype recvtype, int root, MPI_Comm comm) { + return FW_AMPI_Scatterv(sendbuf, sendcnts, displs, sendtype, recvbuf, recvcnt, + recvtype, root, comm); } -int AMPI_Allgatherv(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int *recvcnts, - int *displs, - MPI_Datatype recvtype, - MPI_Comm comm) { - return FW_AMPI_Allgatherv(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnts, - displs, - recvtype, - comm); +int AMPI_Allgatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int *recvcnts, int *displs, + MPI_Datatype recvtype, MPI_Comm comm) { + return FW_AMPI_Allgatherv(sendbuf, sendcnt, sendtype, recvbuf, recvcnts, + displs, recvtype, comm); } -int AMPI_Bcast(void* buf, - int count, - MPI_Datatype datatype, - int root, - MPI_Comm comm) { - return FW_AMPI_Bcast(buf, - count, - datatype, - root, - comm); +int AMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, + MPI_Comm comm) { + return FW_AMPI_Bcast(buf, count, datatype, root, comm); } -int AMPI_Reduce(void* sbuf, - void* rbuf, - int count, - MPI_Datatype datatype, - MPI_Op op, - int root, - MPI_Comm comm) { - return FWB_AMPI_Reduce(sbuf, - rbuf, - count, - datatype, - op, - root, - comm); +int AMPI_Reduce(void *sbuf, void *rbuf, int count, MPI_Datatype datatype, + MPI_Op op, int root, MPI_Comm comm) { + return FWB_AMPI_Reduce(sbuf, rbuf, count, datatype, op, root, comm); } -int AMPI_Allreduce(void* sbuf, - void* rbuf, - int count, - MPI_Datatype datatype, - MPI_Op op, - MPI_Comm comm) { - return FW_AMPI_Allreduce(sbuf, - rbuf, - count, - datatype, - op, - comm); +int AMPI_Allreduce(void *sbuf, void *rbuf, int count, MPI_Datatype datatype, + MPI_Op op, MPI_Comm comm) { + return FW_AMPI_Allreduce(sbuf, rbuf, count, datatype, op, comm); } #endif diff --git a/ADOL-C/src/ampisupportAdolc.cpp b/ADOL-C/src/ampisupportAdolc.cpp index f867d9a6a..0397e56ef 100644 --- a/ADOL-C/src/ampisupportAdolc.cpp +++ b/ADOL-C/src/ampisupportAdolc.cpp @@ -4,274 +4,202 @@ Revision: $Id$ Copyright (c) Jean Utke - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ +#include "adolc/adouble.h" +#include "oplate.h" +#include "taping_p.h" #include #include -#include "taping_p.h" -#include "oplate.h" -#include "adolc/adouble.h" #ifdef ADOLC_AMPI_SUPPORT -#include "ampisupportAdolc.h" -#include "ampi/adTool/support.h" -#include "ampi/tape/support.h" + #include "ampi/adTool/support.h" + #include "ampi/tape/support.h" + #include "ampisupportAdolc.h" -extern "C" void ADOLC_TLM_AMPI_PROD(void *invec, void *inoutvec, int *len, MPI_Datatype *dtype); +extern "C" void ADOLC_TLM_AMPI_PROD(void *invec, void *inoutvec, int *len, + MPI_Datatype *dtype); -void ADOLC_TLM_AMPI_PROD(void *invec, void *inoutvec, int *len, MPI_Datatype *dtype){ - int order=ADOLC_CURRENT_TAPE_INFOS.gDegree; - int dir=ADOLC_CURRENT_TAPE_INFOS.numTay; - double *in=(double*)invec; - double *inout=(double*)inoutvec; - int count=(*len)/((order*dir)+1); - assert((*len)%((order*dir)+1)==0); // has to evenly divide or something is wrong - for (int i=0;i0;--o) { - double z=0; + for (int o = order; o > 0; --o) { + double z = 0; // do the convolution except for the 0-th coefficients - for (int conv=1;conv0) { - TAPE_AMPI_read_int(&recvcnt); - startRLoc = get_locint_f(); - TAPE_AMPI_read_MPI_Datatype(&recvtype); - allocatePack(&recvbuf, - startRLoc, - recvcnt, - packedRCount, - recvtype, - packedRDatatype); + if (commSizeForRootOrNull > 0) { + TAPE_AMPI_read_int(&recvcnt); + startRLoc = get_locint_f(); + TAPE_AMPI_read_MPI_Datatype(&recvtype); + allocatePack(&recvbuf, startRLoc, recvcnt, packedRCount, recvtype, + packedRDatatype); } startSLoc = get_locint_f(); TAPE_AMPI_read_int(&sendcnt); @@ -279,47 +207,25 @@ int ADOLC_TLM_AMPI_Gather(void *sendbuf, TAPE_AMPI_read_int(&root); TAPE_AMPI_read_MPI_Comm(&comm); if (sendcnt > 0) { - allocatePack(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); - } - rc = TLM_AMPI_Gather(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnt, - recvtype, - root, - comm); - if (commSizeForRootOrNull>0) { - unpackDeallocate(&recvbuf, - startRLoc, - recvcnt, - packedRCount, - recvtype, - packedRDatatype); + allocatePack(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); + } + rc = TLM_AMPI_Gather(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, recvtype, + root, comm); + if (commSizeForRootOrNull > 0) { + unpackDeallocate(&recvbuf, startRLoc, recvcnt, packedRCount, recvtype, + packedRDatatype); } if (sendcnt > 0) { - unpackDeallocate(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); + unpackDeallocate(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); } TAPE_AMPI_read_int(&commSizeForRootOrNull); return rc; } -int ADOLC_TLM_AMPI_Scatter(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, +int ADOLC_TLM_AMPI_Scatter(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm) { int rc; int commSizeForRootOrNull; @@ -329,16 +235,12 @@ int ADOLC_TLM_AMPI_Scatter(void *sendbuf, MPI_Datatype packedSDatatype; int packedSCount; TAPE_AMPI_read_int(&commSizeForRootOrNull); - if (commSizeForRootOrNull>0) { - TAPE_AMPI_read_int(&recvcnt); - startRLoc = get_locint_f(); - TAPE_AMPI_read_MPI_Datatype(&recvtype); - allocatePack(&recvbuf, - startRLoc, - recvcnt, - packedRCount, - recvtype, - packedRDatatype); + if (commSizeForRootOrNull > 0) { + TAPE_AMPI_read_int(&recvcnt); + startRLoc = get_locint_f(); + TAPE_AMPI_read_MPI_Datatype(&recvtype); + allocatePack(&recvbuf, startRLoc, recvcnt, packedRCount, recvtype, + packedRDatatype); } startSLoc = get_locint_f(); TAPE_AMPI_read_int(&sendcnt); @@ -346,47 +248,25 @@ int ADOLC_TLM_AMPI_Scatter(void *sendbuf, TAPE_AMPI_read_int(&root); TAPE_AMPI_read_MPI_Comm(&comm); if (sendcnt > 0) { - allocatePack(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); - } - rc = TLM_AMPI_Scatter(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnt, - recvtype, - root, - comm); - if (commSizeForRootOrNull>0) { - unpackDeallocate(&recvbuf, - startRLoc, - recvcnt, - packedRCount, - recvtype, - packedRDatatype); + allocatePack(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); + } + rc = TLM_AMPI_Scatter(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, recvtype, + root, comm); + if (commSizeForRootOrNull > 0) { + unpackDeallocate(&recvbuf, startRLoc, recvcnt, packedRCount, recvtype, + packedRDatatype); } if (sendcnt > 0) { - unpackDeallocate(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); + unpackDeallocate(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); } TAPE_AMPI_read_int(&commSizeForRootOrNull); return rc; } -int ADOLC_TLM_AMPI_Allgather(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, +int ADOLC_TLM_AMPI_Allgather(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int recvcnt, MPI_Datatype recvtype, MPI_Comm comm) { int rc; int rootPlaceholder; @@ -397,16 +277,12 @@ int ADOLC_TLM_AMPI_Allgather(void *sendbuf, MPI_Datatype packedSDatatype; int packedSCount; TAPE_AMPI_read_int(&commSizeForRootOrNull); - if (commSizeForRootOrNull>0) { - TAPE_AMPI_read_int(&recvcnt); - startRLoc = get_locint_f(); - TAPE_AMPI_read_MPI_Datatype(&recvtype); - allocatePack(&recvbuf, - startRLoc, - recvcnt, - packedRCount, - recvtype, - packedRDatatype); + if (commSizeForRootOrNull > 0) { + TAPE_AMPI_read_int(&recvcnt); + startRLoc = get_locint_f(); + TAPE_AMPI_read_MPI_Datatype(&recvtype); + allocatePack(&recvbuf, startRLoc, recvcnt, packedRCount, recvtype, + packedRDatatype); } startSLoc = get_locint_f(); TAPE_AMPI_read_int(&sendcnt); @@ -414,72 +290,44 @@ int ADOLC_TLM_AMPI_Allgather(void *sendbuf, TAPE_AMPI_read_int(&rootPlaceholder); TAPE_AMPI_read_MPI_Comm(&comm); if (sendcnt > 0) { - allocatePack(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); - } - rc = TLM_AMPI_Allgather(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnt, - recvtype, - comm); - if (commSizeForRootOrNull>0) { - unpackDeallocate(&recvbuf, - startRLoc, - recvcnt, - packedRCount, - recvtype, - packedRDatatype); + allocatePack(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); + } + rc = TLM_AMPI_Allgather(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, + recvtype, comm); + if (commSizeForRootOrNull > 0) { + unpackDeallocate(&recvbuf, startRLoc, recvcnt, packedRCount, recvtype, + packedRDatatype); } if (sendcnt > 0) { - unpackDeallocate(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); + unpackDeallocate(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); } TAPE_AMPI_read_int(&commSizeForRootOrNull); return rc; } -int ADOLC_TLM_AMPI_Gatherv(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int *recvcnts, - int *displs, - MPI_Datatype recvtype, - int root, - MPI_Comm comm) { - int rc,i; +int ADOLC_TLM_AMPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int *recvcnts, int *displs, + MPI_Datatype recvtype, int root, MPI_Comm comm) { + int rc, i; int commSizeForRootOrNull; locint startRLoc, startSLoc; MPI_Datatype packedRDatatype, packedSDatatype; int packedRCount, packedSCount; int totalrecvcnt = 0; TAPE_AMPI_read_int(&commSizeForRootOrNull); - for(i=0;i0) && - (totalrecvcnt0) { - startRLoc = get_locint_f(); - TAPE_AMPI_read_MPI_Datatype(&recvtype); - allocatePack(&recvbuf, - startRLoc, - totalrecvcnt, - packedRCount, - recvtype, - packedRDatatype); + for (i = 0; i < commSizeForRootOrNull; ++i) { + TAPE_AMPI_read_int(&recvcnts[i]); + TAPE_AMPI_read_int(&displs[i]); + if ((recvcnts[i] > 0) && (totalrecvcnt < displs[i] + recvcnts[i])) + totalrecvcnt = displs[i] + recvcnts[i]; + } + if (commSizeForRootOrNull > 0) { + startRLoc = get_locint_f(); + TAPE_AMPI_read_MPI_Datatype(&recvtype); + allocatePack(&recvbuf, startRLoc, totalrecvcnt, packedRCount, recvtype, + packedRDatatype); } startSLoc = get_locint_f(); TAPE_AMPI_read_int(&sendcnt); @@ -487,73 +335,44 @@ int ADOLC_TLM_AMPI_Gatherv(void *sendbuf, TAPE_AMPI_read_int(&root); TAPE_AMPI_read_MPI_Comm(&comm); if (sendcnt > 0) { - allocatePack(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); - } - rc = TLM_AMPI_Gatherv(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnts, - displs, - recvtype, - root, - comm); + allocatePack(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); + } + rc = TLM_AMPI_Gatherv(sendbuf, sendcnt, sendtype, recvbuf, recvcnts, displs, + recvtype, root, comm); if (sendcnt > 0) { - unpackDeallocate(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); - } - if (commSizeForRootOrNull>0) { - unpackDeallocate(&recvbuf, - startRLoc, - totalrecvcnt, - packedRCount, - recvtype, - packedRDatatype); + unpackDeallocate(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); + } + if (commSizeForRootOrNull > 0) { + unpackDeallocate(&recvbuf, startRLoc, totalrecvcnt, packedRCount, recvtype, + packedRDatatype); } TAPE_AMPI_read_int(&commSizeForRootOrNull); return rc; } -int ADOLC_TLM_AMPI_Scatterv(void *sendbuf, - int *sendcnts, - int *displs, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, - int root, MPI_Comm comm) { - int rc,i; +int ADOLC_TLM_AMPI_Scatterv(void *sendbuf, int *sendcnts, int *displs, + MPI_Datatype sendtype, void *recvbuf, int recvcnt, + MPI_Datatype recvtype, int root, MPI_Comm comm) { + int rc, i; int commSizeForRootOrNull; locint startRLoc, startSLoc; MPI_Datatype packedRDatatype, packedSDatatype; int packedRCount, packedSCount; int totalsendcnt = 0; TAPE_AMPI_read_int(&commSizeForRootOrNull); - for(i=0;i0) && - (totalsendcnt0) { - startSLoc = get_locint_f(); - TAPE_AMPI_read_MPI_Datatype(&sendtype); - allocatePack(&sendbuf, - startSLoc, - totalsendcnt, - packedSCount, - sendtype, - packedSDatatype); + for (i = 0; i < commSizeForRootOrNull; ++i) { + TAPE_AMPI_read_int(&sendcnts[i]); + TAPE_AMPI_read_int(&displs[i]); + if ((sendcnts[i] > 0) && (totalsendcnt < displs[i] + sendcnts[i])) + totalsendcnt = displs[i] + sendcnts[i]; + } + if (commSizeForRootOrNull > 0) { + startSLoc = get_locint_f(); + TAPE_AMPI_read_MPI_Datatype(&sendtype); + allocatePack(&sendbuf, startSLoc, totalsendcnt, packedSCount, sendtype, + packedSDatatype); } startRLoc = get_locint_f(); TAPE_AMPI_read_int(&recvcnt); @@ -561,73 +380,44 @@ int ADOLC_TLM_AMPI_Scatterv(void *sendbuf, TAPE_AMPI_read_int(&root); TAPE_AMPI_read_MPI_Comm(&comm); if (recvcnt > 0) { - allocatePack(&recvbuf, - startRLoc, - recvcnt, - packedRCount, - recvtype, - packedRDatatype); - } - rc = TLM_AMPI_Scatterv(sendbuf, - sendcnts, - displs, - sendtype, - recvbuf, - recvcnt, - recvtype, - root, - comm); - if (commSizeForRootOrNull>0) { - unpackDeallocate(&sendbuf, - startSLoc, - totalsendcnt, - packedSCount, - sendtype, - packedSDatatype); + allocatePack(&recvbuf, startRLoc, recvcnt, packedRCount, recvtype, + packedRDatatype); + } + rc = TLM_AMPI_Scatterv(sendbuf, sendcnts, displs, sendtype, recvbuf, recvcnt, + recvtype, root, comm); + if (commSizeForRootOrNull > 0) { + unpackDeallocate(&sendbuf, startSLoc, totalsendcnt, packedSCount, sendtype, + packedSDatatype); } if (recvcnt > 0) { - unpackDeallocate(&recvbuf, - startRLoc, - recvcnt, - packedRCount, - recvtype, - packedRDatatype); + unpackDeallocate(&recvbuf, startRLoc, recvcnt, packedRCount, recvtype, + packedRDatatype); } TAPE_AMPI_read_int(&commSizeForRootOrNull); return rc; } -int ADOLC_TLM_AMPI_Allgatherv(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int *recvcnts, - int *displs, - MPI_Datatype recvtype, - MPI_Comm comm) { - int rc,i; +int ADOLC_TLM_AMPI_Allgatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int *recvcnts, int *displs, + MPI_Datatype recvtype, MPI_Comm comm) { + int rc, i; int commSizeForRootOrNull, rootPlaceholder; locint startRLoc, startSLoc; MPI_Datatype packedRDatatype, packedSDatatype; int packedRCount, packedSCount; int totalrecvcnt = 0; TAPE_AMPI_read_int(&commSizeForRootOrNull); - for(i=0;i0) && - (totalrecvcnt0) { - startRLoc = get_locint_f(); - TAPE_AMPI_read_MPI_Datatype(&recvtype); - allocatePack(&recvbuf, - startRLoc, - totalrecvcnt, - packedRCount, - recvtype, - packedRDatatype); + for (i = 0; i < commSizeForRootOrNull; ++i) { + TAPE_AMPI_read_int(&recvcnts[i]); + TAPE_AMPI_read_int(&displs[i]); + if ((recvcnts[i] > 0) && (totalrecvcnt < displs[i] + recvcnts[i])) + totalrecvcnt = displs[i] + recvcnts[i]; + } + if (commSizeForRootOrNull > 0) { + startRLoc = get_locint_f(); + TAPE_AMPI_read_MPI_Datatype(&recvtype); + allocatePack(&recvbuf, startRLoc, totalrecvcnt, packedRCount, recvtype, + packedRDatatype); } startSLoc = get_locint_f(); TAPE_AMPI_read_int(&sendcnt); @@ -635,143 +425,82 @@ int ADOLC_TLM_AMPI_Allgatherv(void *sendbuf, TAPE_AMPI_read_int(&rootPlaceholder); TAPE_AMPI_read_MPI_Comm(&comm); if (sendcnt > 0) { - allocatePack(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); - } - rc = TLM_AMPI_Allgatherv(sendbuf, - sendcnt, - sendtype, - recvbuf, - recvcnts, - displs, - recvtype, - comm); + allocatePack(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); + } + rc = TLM_AMPI_Allgatherv(sendbuf, sendcnt, sendtype, recvbuf, recvcnts, + displs, recvtype, comm); if (sendcnt > 0) { - unpackDeallocate(&sendbuf, - startSLoc, - sendcnt, - packedSCount, - sendtype, - packedSDatatype); - } - if (commSizeForRootOrNull>0) { - unpackDeallocate(&recvbuf, - startRLoc, - totalrecvcnt, - packedRCount, - recvtype, - packedRDatatype); + unpackDeallocate(&sendbuf, startSLoc, sendcnt, packedSCount, sendtype, + packedSDatatype); + } + if (commSizeForRootOrNull > 0) { + unpackDeallocate(&recvbuf, startRLoc, totalrecvcnt, packedRCount, recvtype, + packedRDatatype); } TAPE_AMPI_read_int(&commSizeForRootOrNull); return rc; } - -int ADOLC_TLM_AMPI_Bcast(void* buf, - int count, - MPI_Datatype datatype, - int root, +int ADOLC_TLM_AMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) { - locint startLoc=get_locint_f(); + locint startLoc = get_locint_f(); TAPE_AMPI_read_int(&count); TAPE_AMPI_read_MPI_Datatype(&datatype); TAPE_AMPI_read_int(&root); TAPE_AMPI_read_MPI_Comm(&comm); - int packedCount=0; + int packedCount = 0; MPI_Datatype packedDatatype; - allocatePack(&buf, - startLoc, - count, - packedCount, - datatype, - packedDatatype); - int rc=TLM_AMPI_Bcast(buf, - packedCount, - packedDatatype, - root, - comm); - unpackDeallocate(&buf, - startLoc, - count, - packedCount, - datatype, + allocatePack(&buf, startLoc, count, packedCount, datatype, packedDatatype); + int rc = TLM_AMPI_Bcast(buf, packedCount, packedDatatype, root, comm); + unpackDeallocate(&buf, startLoc, count, packedCount, datatype, packedDatatype); return rc; } -int ADOLC_TLM_AMPI_Reduce(void* sbuf, - void* rbuf, - int count, - MPI_Datatype datatype, - MPI_Op op, - int root, +int ADOLC_TLM_AMPI_Reduce(void *sbuf, void *rbuf, int count, + MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) { locint rbufStart = get_locint_f(); locint sbufStart = get_locint_f(); TAPE_AMPI_read_int(&count); - int pushedResultsCount; TAPE_AMPI_read_int(&pushedResultsCount); + int pushedResultsCount; + TAPE_AMPI_read_int(&pushedResultsCount); double pushedDoubles; - for (int i=0;i0) for (int i=0;i 0) + for (int i = 0; i < count; ++i) + TAPE_AMPI_read_double(&pushedDoubles); TAPE_AMPI_read_int(&pushedResultsCount); TAPE_AMPI_read_MPI_Op(&op); TAPE_AMPI_read_int(&root); /* root */ TAPE_AMPI_read_MPI_Comm(&comm); TAPE_AMPI_read_MPI_Datatype(&datatype); TAPE_AMPI_read_int(&count); /* count again */ - int packedCount=0; + int packedCount = 0; MPI_Datatype packedDatatype; - int myRank; MPI_Comm_rank(comm,&myRank); - allocatePack(&sbuf, - sbufStart, - count, - packedCount, - datatype, - packedDatatype); - if (myRank==root) { - allocatePack(&rbuf, - rbufStart, - count, - packedCount, - datatype, + int myRank; + MPI_Comm_rank(comm, &myRank); + allocatePack(&sbuf, sbufStart, count, packedCount, datatype, packedDatatype); + if (myRank == root) { + allocatePack(&rbuf, rbufStart, count, packedCount, datatype, packedDatatype); } - MPI_Op packedOp=opForPackedData(op); - int rc=TLB_AMPI_Reduce(sbuf, - rbuf, - packedCount, - packedDatatype, - packedOp, - root, - comm); + MPI_Op packedOp = opForPackedData(op); + int rc = TLB_AMPI_Reduce(sbuf, rbuf, packedCount, packedDatatype, packedOp, + root, comm); deallocate(&sbuf); - if (myRank==root) { - unpackDeallocate(&rbuf, - rbufStart, - count, - packedCount, - datatype, + if (myRank == root) { + unpackDeallocate(&rbuf, rbufStart, count, packedCount, datatype, packedDatatype); } return rc; } -int ADOLC_TLM_AMPI_Allreduce(void* sbuf, - void* rbuf, - int count, - MPI_Datatype datatype, - MPI_Op op, - MPI_Comm comm) { - return TLM_AMPI_Allreduce(sbuf, - rbuf, - count, - datatype, - op, - comm); +int ADOLC_TLM_AMPI_Allreduce(void *sbuf, void *rbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { + return TLM_AMPI_Allreduce(sbuf, rbuf, count, datatype, op, comm); } #endif diff --git a/ADOL-C/src/ampisupportAdolc.h b/ADOL-C/src/ampisupportAdolc.h old mode 100755 new mode 100644 index fcb00763e..e12510500 --- a/ADOL-C/src/ampisupportAdolc.h +++ b/ADOL-C/src/ampisupportAdolc.h @@ -4,142 +4,81 @@ Revision: $Id$ Copyright (c) Jean Utke - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_AMPISUPPORTADOLC_H) -#define ADOLC_AMPISUPPORTADOLC_H 1 + #define ADOLC_AMPISUPPORTADOLC_H 1 -#ifdef ADOLC_AMPI_SUPPORT -#include "ampi/ampi.h" -#include "ampi/libCommon/modified.h" + #ifdef ADOLC_AMPI_SUPPORT + #include "ampi/ampi.h" + #include "ampi/libCommon/modified.h" -#if defined(__cplusplus) + #if defined(__cplusplus) extern "C" { -#endif + #endif void ADOLC_TLM_init(); -int ADOLC_TLM_AMPI_Send(void* buf, - int count, - MPI_Datatype datatype, - int src, - int tag, - AMPI_PairedWith pairedWith, - MPI_Comm comm); - -int ADOLC_TLM_AMPI_Recv(void* buf, - int count, - MPI_Datatype datatype, - int src, - int tag, - AMPI_PairedWith pairedWith, - MPI_Comm comm, - MPI_Status* status); - -int ADOLC_TLM_AMPI_Isend (void* buf, - int count, - MPI_Datatype datatype, - int dest, - int tag, - AMPI_PairedWith pairedWith, - MPI_Comm comm, - AMPI_Request* request); - -int ADOLC_TLM_AMPI_Irecv (void* buf, - int count, - MPI_Datatype datatype, - int src, - int tag, - AMPI_PairedWith pairedWith, - MPI_Comm comm, - AMPI_Request* request); - -int ADOLC_TLM_AMPI_Wait(AMPI_Request *request, +int ADOLC_TLM_AMPI_Send(void *buf, int count, MPI_Datatype datatype, int src, + int tag, AMPI_PairedWith pairedWith, MPI_Comm comm); + +int ADOLC_TLM_AMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, + int tag, AMPI_PairedWith pairedWith, MPI_Comm comm, MPI_Status *status); +int ADOLC_TLM_AMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dest, + int tag, AMPI_PairedWith pairedWith, MPI_Comm comm, + AMPI_Request *request); + +int ADOLC_TLM_AMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, + int tag, AMPI_PairedWith pairedWith, MPI_Comm comm, + AMPI_Request *request); + +int ADOLC_TLM_AMPI_Wait(AMPI_Request *request, MPI_Status *status); + int ADOLC_TLM_AMPI_Barrier(MPI_Comm comm); -int ADOLC_TLM_AMPI_Gather(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, - int root, - MPI_Comm comm); +int ADOLC_TLM_AMPI_Gather(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int recvcnt, MPI_Datatype recvtype, + int root, MPI_Comm comm); -int ADOLC_TLM_AMPI_Scatter(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, +int ADOLC_TLM_AMPI_Scatter(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm); -int ADOLC_TLM_AMPI_Allgather(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, +int ADOLC_TLM_AMPI_Allgather(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int recvcnt, MPI_Datatype recvtype, MPI_Comm comm); -int ADOLC_TLM_AMPI_Gatherv(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int *recvcnts, - int *displs, - MPI_Datatype recvtype, - int root, - MPI_Comm comm); - -int ADOLC_TLM_AMPI_Scatterv(void *sendbuf, - int *sendcnts, - int *displs, - MPI_Datatype sendtype, - void *recvbuf, - int recvcnt, - MPI_Datatype recvtype, - int root, MPI_Comm comm); - -int ADOLC_TLM_AMPI_Allgatherv(void *sendbuf, - int sendcnt, - MPI_Datatype sendtype, - void *recvbuf, - int *recvcnts, - int *displs, - MPI_Datatype recvtype, - MPI_Comm comm); - -int ADOLC_TLM_AMPI_Bcast(void* buf, - int count, - MPI_Datatype datatype, - int root, +int ADOLC_TLM_AMPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int *recvcnts, int *displs, + MPI_Datatype recvtype, int root, MPI_Comm comm); + +int ADOLC_TLM_AMPI_Scatterv(void *sendbuf, int *sendcnts, int *displs, + MPI_Datatype sendtype, void *recvbuf, int recvcnt, + MPI_Datatype recvtype, int root, MPI_Comm comm); + +int ADOLC_TLM_AMPI_Allgatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + void *recvbuf, int *recvcnts, int *displs, + MPI_Datatype recvtype, MPI_Comm comm); + +int ADOLC_TLM_AMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm); -int ADOLC_TLM_AMPI_Reduce(void* sbuf, - void* rbuf, - int count, - MPI_Datatype datatype, - MPI_Op op, - int root, +int ADOLC_TLM_AMPI_Reduce(void *sbuf, void *rbuf, int count, + MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm); -int ADOLC_TLM_AMPI_Allreduce(void* sbuf, - void* rbuf, - int count, - MPI_Datatype datatype, - MPI_Op op, - MPI_Comm comm); +int ADOLC_TLM_AMPI_Allreduce(void *sbuf, void *rbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); -#if defined(__cplusplus) + #if defined(__cplusplus) } -#endif -#endif + #endif + #endif #endif diff --git a/ADOL-C/src/buffer_temp.h b/ADOL-C/src/buffer_temp.h index e97d2b97b..a0c0ed208 100644 --- a/ADOL-C/src/buffer_temp.h +++ b/ADOL-C/src/buffer_temp.h @@ -5,136 +5,138 @@ Contents: - template class for linked list of Type buffers with constant length per buffer - intended to be used with structs - + Copyright (c) Andreas Kowarz, Kshitij Kulshreshtha, Jean Utke - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_STRUCT_BUF_H) -#define ADOLC_STRUCT_BUF_H 1 + #define ADOLC_STRUCT_BUF_H 1 -#include -#include "taping_p.h" + #include "taping_p.h" + #include -#if defined(__cplusplus) -/****************************************************************************/ -/* This is all C++ */ + #if defined(__cplusplus) + /****************************************************************************/ + /* This is all C++ */ -#include + #include -#define BUFFER Buffer -#define BUFFER_TEMPLATE template + #define BUFFER Buffer + #define BUFFER_TEMPLATE \ + template typedef locint IndexType; BUFFER_TEMPLATE class Buffer { - typedef void (*InitFunctionPointer) (SubBufferElement *subBufferElement); + typedef void (*InitFunctionPointer)(SubBufferElement *subBufferElement); - static void zeroAll(SubBufferElement* subBufferElement); + static void zeroAll(SubBufferElement *subBufferElement); - typedef struct SubBuffer { - SubBufferElement elements[_subBufferSize]; - struct SubBuffer *nextSubBuffer; - SubBuffer(); - } - SubBuffer; + typedef struct SubBuffer { + SubBufferElement elements[_subBufferSize]; + struct SubBuffer *nextSubBuffer; + SubBuffer(); + } SubBuffer; public: - inline Buffer() { - firstSubBuffer = NULL; - numEntries = 0; - initFunction = zeroAll; - } - inline Buffer(InitFunctionPointer _initFunction) { - firstSubBuffer = NULL; - numEntries = 0; - initFunction = _initFunction; - } - inline ~Buffer(); - - inline void init(InitFunctionPointer _initFunction) { - initFunction = _initFunction; - } - SubBufferElement *append(); - SubBufferElement *getElement(IndexType index); + inline Buffer() { + firstSubBuffer = NULL; + numEntries = 0; + initFunction = zeroAll; + } + inline Buffer(InitFunctionPointer _initFunction) { + firstSubBuffer = NULL; + numEntries = 0; + initFunction = _initFunction; + } + inline ~Buffer(); + + inline void init(InitFunctionPointer _initFunction) { + initFunction = _initFunction; + } + SubBufferElement *append(); + SubBufferElement *getElement(IndexType index); private: - SubBuffer *firstSubBuffer; - InitFunctionPointer initFunction; - IndexType numEntries; + SubBuffer *firstSubBuffer; + InitFunctionPointer initFunction; + IndexType numEntries; }; BUFFER_TEMPLATE -void BUFFER::zeroAll(SubBufferElement* subBufferElement) { - memset(subBufferElement,0,sizeof(*subBufferElement)); +void BUFFER::zeroAll(SubBufferElement *subBufferElement) { + memset(subBufferElement, 0, sizeof(*subBufferElement)); } BUFFER_TEMPLATE BUFFER::SubBuffer::SubBuffer() { - memset(elements,0,sizeof(SubBufferElement)*_subBufferSize); - nextSubBuffer = NULL; + memset(elements, 0, sizeof(SubBufferElement) * _subBufferSize); + nextSubBuffer = NULL; } BUFFER_TEMPLATE BUFFER::~Buffer() { - SubBuffer *tmpSubBuffer = NULL; - - while (firstSubBuffer != NULL) { - tmpSubBuffer = firstSubBuffer; - firstSubBuffer = firstSubBuffer->nextSubBuffer; - for(IndexType i = 0; i < _subBufferSize; i++) - if (tmpSubBuffer->elements[i].allmem != NULL) - free(tmpSubBuffer->elements[i].allmem); - delete tmpSubBuffer; - } + SubBuffer *tmpSubBuffer = NULL; + + while (firstSubBuffer != NULL) { + tmpSubBuffer = firstSubBuffer; + firstSubBuffer = firstSubBuffer->nextSubBuffer; + for (IndexType i = 0; i < _subBufferSize; i++) + if (tmpSubBuffer->elements[i].allmem != NULL) + free(tmpSubBuffer->elements[i].allmem); + delete tmpSubBuffer; + } } BUFFER_TEMPLATE SubBufferElement *BUFFER::append() { - SubBuffer *currentSubBuffer=firstSubBuffer, *previousSubBuffer=NULL; - IndexType index, tmp=numEntries; - - while (tmp>=_subBufferSize) { - previousSubBuffer=currentSubBuffer; - currentSubBuffer=currentSubBuffer->nextSubBuffer; - tmp-=_subBufferSize; - } - if (currentSubBuffer==NULL) { - currentSubBuffer=new SubBuffer; - if (firstSubBuffer==NULL) firstSubBuffer=currentSubBuffer; - else previousSubBuffer->nextSubBuffer=currentSubBuffer; - currentSubBuffer->nextSubBuffer=NULL; - } - index=tmp; - - currentSubBuffer->elements[index].allmem=NULL; - if (initFunction!=NULL) - initFunction(&(currentSubBuffer->elements[index])); - - currentSubBuffer->elements[index].index=numEntries; - ++numEntries; - - return ¤tSubBuffer->elements[index]; + SubBuffer *currentSubBuffer = firstSubBuffer, *previousSubBuffer = NULL; + IndexType index, tmp = numEntries; + + while (tmp >= _subBufferSize) { + previousSubBuffer = currentSubBuffer; + currentSubBuffer = currentSubBuffer->nextSubBuffer; + tmp -= _subBufferSize; + } + if (currentSubBuffer == NULL) { + currentSubBuffer = new SubBuffer; + if (firstSubBuffer == NULL) + firstSubBuffer = currentSubBuffer; + else + previousSubBuffer->nextSubBuffer = currentSubBuffer; + currentSubBuffer->nextSubBuffer = NULL; + } + index = tmp; + + currentSubBuffer->elements[index].allmem = NULL; + if (initFunction != NULL) + initFunction(&(currentSubBuffer->elements[index])); + + currentSubBuffer->elements[index].index = numEntries; + ++numEntries; + + return ¤tSubBuffer->elements[index]; } BUFFER_TEMPLATE SubBufferElement *BUFFER::getElement(IndexType index) { - SubBuffer *currentSubBuffer=firstSubBuffer; - - if (index>=numEntries) fail(ADOLC_BUFFER_INDEX_TO_LARGE); - while (index>=_subBufferSize) { - currentSubBuffer=currentSubBuffer->nextSubBuffer; - index-=_subBufferSize; - } - return ¤tSubBuffer->elements[index]; + SubBuffer *currentSubBuffer = firstSubBuffer; + + if (index >= numEntries) + fail(ADOLC_BUFFER_INDEX_TO_LARGE); + while (index >= _subBufferSize) { + currentSubBuffer = currentSubBuffer->nextSubBuffer; + index -= _subBufferSize; + } + return ¤tSubBuffer->elements[index]; } -#endif /* __cplusplus */ + #endif /* __cplusplus */ #endif /* ADOLC_STRUCT_BUF_H */ - diff --git a/ADOL-C/src/checkpointing.cpp b/ADOL-C/src/checkpointing.cpp index 8371f0c0b..edffbca72 100644 --- a/ADOL-C/src/checkpointing.cpp +++ b/ADOL-C/src/checkpointing.cpp @@ -3,22 +3,22 @@ File: checkpointing.cpp Revision: $Id$ Contents: checkpointing algorithms - + Copyright (c) Andreas Kowarz, Jean Utke - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ +#include "checkpointing_p.h" #include "oplate.h" #include "taping_p.h" #include +#include #include #include -#include -#include "checkpointing_p.h" #include #include @@ -50,103 +50,100 @@ void revolve_for(CpInfos *cpInfos); void revolveError(CpInfos *cpInfos); /* we do not really have an ext. diff. function that we want to be called */ -int dummy(int n, double *x, int m, double *y) { - return 0; -} +int dummy(int n, double *x, int m, double *y) { return 0; } /* register one time step function (uses buffer template) */ CpInfos *reg_timestep_fct(ADOLC_TimeStepFuncion timeStepFunction) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - CpInfos* theCpInfos=ADOLC_EXT_DIFF_FCTS_BUFFER.append(); - theCpInfos->function=timeStepFunction; - return theCpInfos; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + CpInfos *theCpInfos = ADOLC_EXT_DIFF_FCTS_BUFFER.append(); + theCpInfos->function = timeStepFunction; + return theCpInfos; } /* This is the main checkpointing function the user calls within the taping * process. It performs n time steps with or without taping and registers an * external dummy function which calls the actual checkpointing workhorses * from within the used drivers. */ -int checkpointing (CpInfos *cpInfos) { - int i; - ext_diff_fct *edf; - int oldTraceFlag; - locint numVals; - double *vals; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - // knockout - if (cpInfos==NULL) - fail(ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER); - if (cpInfos->function==NULL) - fail(ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION); - if (cpInfos->function_double==NULL) - fail(ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION_DOUBLE); - if (cpInfos->adp_x==NULL) - fail(ADOLC_CHECKPOINTING_NULLPOINTER_ARGUMENT); - - // register extern function - edf=reg_ext_fct(dummy); - init_edf(edf); - - // but we do not call it - // we use direct taping to avoid unnecessary argument copying - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(ext_diff); - ADOLC_PUT_LOCINT(edf->index); - ADOLC_PUT_LOCINT(0); - ADOLC_PUT_LOCINT(0); - ADOLC_PUT_LOCINT(cpInfos->adp_x[0].loc()); - ADOLC_PUT_LOCINT(cpInfos->adp_y[0].loc()); - // this CpInfos id has to be read by the actual checkpointing - // functions - ADOLC_PUT_LOCINT(cpInfos->index); - - oldTraceFlag=ADOLC_CURRENT_TAPE_INFOS.traceFlag; - ADOLC_CURRENT_TAPE_INFOS.traceFlag=0; - } else oldTraceFlag=0; - - numVals = ADOLC_GLOBAL_TAPE_VARS.storeSize; - vals = new double[numVals]; - memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store, - numVals * sizeof(double)); - - cpInfos->dp_internal_for = new double[cpInfos->n]; - // initialize internal arguments - for (i=0; in; ++i) - cpInfos->dp_internal_for[i]=cpInfos->adp_x[i].getValue(); - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0) - // perform all time steps, tape the last, take checkpoints - revolve_for(cpInfos); - else - // perform all time steps without taping - for (i=0; isteps; ++i) - cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for); - - memcpy(ADOLC_GLOBAL_TAPE_VARS.store, vals, - numVals * sizeof(double)); - delete[] vals; - - // update taylor stack; same structure as in adouble.cpp + - // correction in taping.c - if (oldTraceFlag != 0) { - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += cpInfos->n; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0) - for (i = 0; i < cpInfos->n; ++i) - ADOLC_WRITE_SCAYLOR(cpInfos->adp_y[i].getValue()); - } - // save results - for (i=0; in; ++i) { - cpInfos->adp_y[i].setValue(cpInfos->dp_internal_for[i]); - } - delete[] cpInfos->dp_internal_for; - cpInfos->dp_internal_for = NULL; +int checkpointing(CpInfos *cpInfos) { + int i; + ext_diff_fct *edf; + int oldTraceFlag; + locint numVals; + double *vals; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + // knockout + if (cpInfos == NULL) + fail(ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER); + if (cpInfos->function == NULL) + fail(ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION); + if (cpInfos->function_double == NULL) + fail(ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION_DOUBLE); + if (cpInfos->adp_x == NULL) + fail(ADOLC_CHECKPOINTING_NULLPOINTER_ARGUMENT); + + // register extern function + edf = reg_ext_fct(dummy); + init_edf(edf); + + // but we do not call it + // we use direct taping to avoid unnecessary argument copying + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(ext_diff); + ADOLC_PUT_LOCINT(edf->index); + ADOLC_PUT_LOCINT(0); + ADOLC_PUT_LOCINT(0); + ADOLC_PUT_LOCINT(cpInfos->adp_x[0].loc()); + ADOLC_PUT_LOCINT(cpInfos->adp_y[0].loc()); + // this CpInfos id has to be read by the actual checkpointing + // functions + ADOLC_PUT_LOCINT(cpInfos->index); - // normal taping again - ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag; - - return 0; + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + } else + oldTraceFlag = 0; + + numVals = ADOLC_GLOBAL_TAPE_VARS.storeSize; + vals = new double[numVals]; + memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store, numVals * sizeof(double)); + + cpInfos->dp_internal_for = new double[cpInfos->n]; + // initialize internal arguments + for (i = 0; i < cpInfos->n; ++i) + cpInfos->dp_internal_for[i] = cpInfos->adp_x[i].getValue(); + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0) + // perform all time steps, tape the last, take checkpoints + revolve_for(cpInfos); + else + // perform all time steps without taping + for (i = 0; i < cpInfos->steps; ++i) + cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for); + + memcpy(ADOLC_GLOBAL_TAPE_VARS.store, vals, numVals * sizeof(double)); + delete[] vals; + + // update taylor stack; same structure as in adouble.cpp + + // correction in taping.c + if (oldTraceFlag != 0) { + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += cpInfos->n; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0) + for (i = 0; i < cpInfos->n; ++i) + ADOLC_WRITE_SCAYLOR(cpInfos->adp_y[i].getValue()); + } + // save results + for (i = 0; i < cpInfos->n; ++i) { + cpInfos->adp_y[i].setValue(cpInfos->dp_internal_for[i]); + } + delete[] cpInfos->dp_internal_for; + cpInfos->dp_internal_for = NULL; + + // normal taping again + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; + + return 0; } /* - reinit external function buffer and checkpointing buffer @@ -154,35 +151,36 @@ int checkpointing (CpInfos *cpInfos) { void reinit_checkpointing() {} CpInfos *get_cp_fct(int index) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - return ADOLC_EXT_DIFF_FCTS_BUFFER.getElement(index); + return ADOLC_EXT_DIFF_FCTS_BUFFER.getElement(index); } /* initialize the CpInfos variable (function and index are set within * the template code */ void init_CpInfos(CpInfos *cpInfos) { - char *ptr; + char *ptr; - ptr = (char *)cpInfos; - for (unsigned int i = 0; i < sizeof(CpInfos); ++i) ptr[i] = 0; - cpInfos->tapeNumber = -1; + ptr = (char *)cpInfos; + for (unsigned int i = 0; i < sizeof(CpInfos); ++i) + ptr[i] = 0; + cpInfos->tapeNumber = -1; } /* initialize the information for the external function in a way that our * checkpointing functions are called */ void init_edf(ext_diff_fct *edf) { - edf->function=dummy; - edf->zos_forward=cp_zos_forward; - edf->fos_forward=cp_fos_forward; - edf->fov_forward=cp_fov_forward; - edf->hos_forward=cp_hos_forward; - edf->hov_forward=cp_hov_forward; - edf->fos_reverse=cp_fos_reverse; - edf->fov_reverse=cp_fov_reverse; - edf->hos_reverse=cp_hos_reverse; - edf->hov_reverse=cp_hov_reverse; + edf->function = dummy; + edf->zos_forward = cp_zos_forward; + edf->fos_forward = cp_fos_forward; + edf->fov_forward = cp_fov_forward; + edf->hos_forward = cp_hos_forward; + edf->hov_forward = cp_hov_forward; + edf->fos_reverse = cp_fos_reverse; + edf->fov_reverse = cp_fov_reverse; + edf->hos_reverse = cp_hos_reverse; + edf->hov_reverse = cp_hov_reverse; } /****************************************************************************/ @@ -191,326 +189,332 @@ void init_edf(ext_diff_fct *edf) { /****************************************************************************/ /* special case: use double version where possible, no taping */ -int cp_zos_forward (int n, double *dp_x, int m, double *dp_y) { - CpInfos *cpInfos; - double *T0; - int i, oldTraceFlag; - locint arg; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - // taping off - oldTraceFlag=ADOLC_CURRENT_TAPE_INFOS.traceFlag; - ADOLC_CURRENT_TAPE_INFOS.traceFlag=0; - - // get checkpointing information - cpInfos=get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex); - T0 = ADOLC_CURRENT_TAPE_INFOS.dp_T0; - - // note the mode - cpInfos->modeForward = ADOLC_ZOS_FORWARD; - cpInfos->modeReverse = ADOLC_NO_MODE; - - // prepare arguments - cpInfos->dp_internal_for=new double[cpInfos->n]; - arg=ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; - for (i=0; in; ++i) { - cpInfos->dp_internal_for[i]=T0[arg]; - ++arg; - } - - revolve_for(cpInfos); - - // write back - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; // keep input - for (i=0; in; ++i) { - ADOLC_WRITE_SCAYLOR(T0[arg]); - T0[arg]=cpInfos->dp_internal_for[i]; - ++arg; - } - delete[] cpInfos->dp_internal_for; - cpInfos->dp_internal_for = NULL; - - // taping "on" - ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag; - - return 0; +int cp_zos_forward(int n, double *dp_x, int m, double *dp_y) { + CpInfos *cpInfos; + double *T0; + int i, oldTraceFlag; + locint arg; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + // taping off + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + + // get checkpointing information + cpInfos = get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex); + T0 = ADOLC_CURRENT_TAPE_INFOS.dp_T0; + + // note the mode + cpInfos->modeForward = ADOLC_ZOS_FORWARD; + cpInfos->modeReverse = ADOLC_NO_MODE; + + // prepare arguments + cpInfos->dp_internal_for = new double[cpInfos->n]; + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; + for (i = 0; i < cpInfos->n; ++i) { + cpInfos->dp_internal_for[i] = T0[arg]; + ++arg; + } + + revolve_for(cpInfos); + + // write back + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; // keep input + for (i = 0; i < cpInfos->n; ++i) { + ADOLC_WRITE_SCAYLOR(T0[arg]); + T0[arg] = cpInfos->dp_internal_for[i]; + ++arg; + } + delete[] cpInfos->dp_internal_for; + cpInfos->dp_internal_for = NULL; + + // taping "on" + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; + + return 0; } void revolve_for(CpInfos *cpInfos) { - /* init revolve */ - cpInfos->check=-1; - cpInfos->capo=0; - cpInfos->info = 0; - cpInfos->fine=cpInfos->steps; - - /* execute all time steps */ - enum revolve_action whattodo; - do { - whattodo=revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine, - cpInfos->checkpoints, &cpInfos->info); - switch (whattodo) { - case revolve_takeshot: - cp_takeshot(cpInfos); - cpInfos->currentCP=cpInfos->capo; - break; - case revolve_advance: - for (int i=0; icapo-cpInfos->currentCP; ++i) { - cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for); - } - break; - case revolve_firsturn: - cp_taping(cpInfos); - break; - case revolve_error: - revolveError(cpInfos); - break; - default: - fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION); - } - } while (whattodo==revolve_takeshot || whattodo==revolve_advance); + /* init revolve */ + cpInfos->check = -1; + cpInfos->capo = 0; + cpInfos->info = 0; + cpInfos->fine = cpInfos->steps; + + /* execute all time steps */ + enum revolve_action whattodo; + do { + whattodo = revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine, + cpInfos->checkpoints, &cpInfos->info); + switch (whattodo) { + case revolve_takeshot: + cp_takeshot(cpInfos); + cpInfos->currentCP = cpInfos->capo; + break; + case revolve_advance: + for (int i = 0; i < cpInfos->capo - cpInfos->currentCP; ++i) { + cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for); + } + break; + case revolve_firsturn: + cp_taping(cpInfos); + break; + case revolve_error: + revolveError(cpInfos); + break; + default: + fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION); + } + } while (whattodo == revolve_takeshot || whattodo == revolve_advance); } -int cp_fos_forward (int n, double *dp_x, double *dp_X, - int m, double *dp_y, double *dp_Y) { - printf("WARNING: Checkpointing algorithm not " - "implemented for the fos_forward mode!\n"); - return 0; +int cp_fos_forward(int n, double *dp_x, double *dp_X, int m, double *dp_y, + double *dp_Y) { + printf("WARNING: Checkpointing algorithm not " + "implemented for the fos_forward mode!\n"); + return 0; } -int cp_fov_forward (int n, double *dp_x, int p, double **dpp_X, - int m, double *dp_y, double **dpp_Y) { - printf("WARNING: Checkpointing algorithm not " - "implemented for the fov_forward mode!\n"); - return 0; +int cp_fov_forward(int n, double *dp_x, int p, double **dpp_X, int m, + double *dp_y, double **dpp_Y) { + printf("WARNING: Checkpointing algorithm not " + "implemented for the fov_forward mode!\n"); + return 0; } -int cp_hos_forward (int n, double *dp_x, int d, double **dpp_X, - int m, double *dp_y, double **dpp_Y) { - printf("WARNING: Checkpointing algorithm not " - "implemented for the hos_forward mode!\n"); - return 0; +int cp_hos_forward(int n, double *dp_x, int d, double **dpp_X, int m, + double *dp_y, double **dpp_Y) { + printf("WARNING: Checkpointing algorithm not " + "implemented for the hos_forward mode!\n"); + return 0; } -int cp_hov_forward (int n, double *dp_x, int d, int p, double ***dppp_X, - int m, double *dp_y, double ***dppp_Y) { - printf("WARNING: Checkpointing algorithm not " - "implemented for the hov_forward mode!\n"); - return 0; +int cp_hov_forward(int n, double *dp_x, int d, int p, double ***dppp_X, int m, + double *dp_y, double ***dppp_Y) { + printf("WARNING: Checkpointing algorithm not " + "implemented for the hov_forward mode!\n"); + return 0; } -int cp_fos_reverse (int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - revreal *A = ADOLC_CURRENT_TAPE_INFOS.rp_A; - int oldTraceFlag; - locint arg; - CpInfos *cpInfos=get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex); - char old_bsw; - - // note the mode - cpInfos->modeReverse = ADOLC_FOS_REVERSE; - - cpInfos->dp_internal_for=new double[cpInfos->n]; - cpInfos->dp_internal_rev=new double[cpInfos->n]; - - // taping "off" - oldTraceFlag=ADOLC_CURRENT_TAPE_INFOS.traceFlag; - ADOLC_CURRENT_TAPE_INFOS.traceFlag=0; - - arg=ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (int i=0; in; ++i) { - cpInfos->dp_internal_rev[i]=A[arg]; - ++arg; - } - // update taylor buffer - for (int i = 0; i < cpInfos->n; ++i) { - --arg; - ADOLC_GET_TAYLOR(arg); - } - // execute second part of revolve_firstturn left from forward sweep - fos_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, - cpInfos->dp_internal_rev, cpInfos->dp_internal_rev); - - old_bsw = ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning; - ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 0; - // checkpointing - enum revolve_action whattodo; - do { - whattodo=revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine, - cpInfos->checkpoints, &cpInfos->info); - switch (whattodo) { - case revolve_terminate: - break; - case revolve_takeshot: - cp_takeshot(cpInfos); - cpInfos->currentCP=cpInfos->capo; - break; - case revolve_advance: - for (int i=0; icapo-cpInfos->currentCP; ++i) - cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for); - break; - case revolve_youturn: - if (cpInfos->retaping != 0) cp_taping(cpInfos); // retaping forced - else { - // one forward step with keep and retaping if necessary - if (zos_forward(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, 1, - cpInfos->dp_internal_for, cpInfos->dp_internal_for) < 0) - cp_taping(cpInfos); - } - // one reverse step - fos_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, - cpInfos->dp_internal_rev, cpInfos->dp_internal_rev); - break; - case revolve_restore: - if (cpInfos->capo!=cpInfos->currentCP) cp_release(cpInfos); - cpInfos->currentCP=cpInfos->capo; - cp_restore(cpInfos); - break; - case revolve_error: - revolveError(cpInfos); - break; - default: - fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION); - break; - } - } while (whattodo!=revolve_terminate && whattodo!=revolve_error); - cp_release(cpInfos); // release first checkpoint if written - ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = old_bsw; - - // save results - arg=ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (int i=0; in; ++i) { - A[arg]=cpInfos->dp_internal_rev[i]; - ++arg; +int cp_fos_reverse(int m, double *dp_U, int n, double *dp_Z, double *dp_x, + double *dp_y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + revreal *A = ADOLC_CURRENT_TAPE_INFOS.rp_A; + int oldTraceFlag; + locint arg; + CpInfos *cpInfos = get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex); + char old_bsw; + + // note the mode + cpInfos->modeReverse = ADOLC_FOS_REVERSE; + + cpInfos->dp_internal_for = new double[cpInfos->n]; + cpInfos->dp_internal_rev = new double[cpInfos->n]; + + // taping "off" + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (int i = 0; i < cpInfos->n; ++i) { + cpInfos->dp_internal_rev[i] = A[arg]; + ++arg; + } + // update taylor buffer + for (int i = 0; i < cpInfos->n; ++i) { + --arg; + ADOLC_GET_TAYLOR(arg); + } + // execute second part of revolve_firstturn left from forward sweep + fos_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, + cpInfos->dp_internal_rev, cpInfos->dp_internal_rev); + + old_bsw = ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning; + ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 0; + // checkpointing + enum revolve_action whattodo; + do { + whattodo = revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine, + cpInfos->checkpoints, &cpInfos->info); + switch (whattodo) { + case revolve_terminate: + break; + case revolve_takeshot: + cp_takeshot(cpInfos); + cpInfos->currentCP = cpInfos->capo; + break; + case revolve_advance: + for (int i = 0; i < cpInfos->capo - cpInfos->currentCP; ++i) + cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for); + break; + case revolve_youturn: + if (cpInfos->retaping != 0) + cp_taping(cpInfos); // retaping forced + else { + // one forward step with keep and retaping if necessary + if (zos_forward(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, 1, + cpInfos->dp_internal_for, cpInfos->dp_internal_for) < 0) + cp_taping(cpInfos); + } + // one reverse step + fos_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, + cpInfos->dp_internal_rev, cpInfos->dp_internal_rev); + break; + case revolve_restore: + if (cpInfos->capo != cpInfos->currentCP) + cp_release(cpInfos); + cpInfos->currentCP = cpInfos->capo; + cp_restore(cpInfos); + break; + case revolve_error: + revolveError(cpInfos); + break; + default: + fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION); + break; } - - // clean up - delete[] cpInfos->dp_internal_for; - cpInfos->dp_internal_for = NULL; - delete[] cpInfos->dp_internal_rev; - cpInfos->dp_internal_rev = NULL; - - // taping "on" - ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag; - - return 0; + } while (whattodo != revolve_terminate && whattodo != revolve_error); + cp_release(cpInfos); // release first checkpoint if written + ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = old_bsw; + + // save results + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (int i = 0; i < cpInfos->n; ++i) { + A[arg] = cpInfos->dp_internal_rev[i]; + ++arg; + } + + // clean up + delete[] cpInfos->dp_internal_for; + cpInfos->dp_internal_for = NULL; + delete[] cpInfos->dp_internal_rev; + cpInfos->dp_internal_rev = NULL; + + // taping "on" + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; + + return 0; } -int cp_fov_reverse (int m, int p, double **dpp_U, int n, double **dpp_Z, double */*unused*/, double */*unused*/) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - revreal **A = ADOLC_CURRENT_TAPE_INFOS.rpp_A; - int oldTraceFlag, numDirs; - locint arg; - CpInfos *cpInfos = get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex); - char old_bsw; - - // note the mode - cpInfos->modeReverse = ADOLC_FOV_REVERSE; - - numDirs = ADOLC_CURRENT_TAPE_INFOS.numDirs_rev; - cpInfos->dp_internal_for = new double[cpInfos->n]; - cpInfos->dpp_internal_rev = myalloc2(numDirs, cpInfos->n); - - // taping "off" - oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; - ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; - - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (int i = 0; i < cpInfos->n; ++i) { - for (int j = 0; j < numDirs; ++j) { - cpInfos->dpp_internal_rev[j][i] = A[arg][j]; - } - ++arg; +int cp_fov_reverse(int m, int p, double **dpp_U, int n, double **dpp_Z, + double * /*unused*/, double * /*unused*/) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + revreal **A = ADOLC_CURRENT_TAPE_INFOS.rpp_A; + int oldTraceFlag, numDirs; + locint arg; + CpInfos *cpInfos = get_cp_fct(ADOLC_CURRENT_TAPE_INFOS.cpIndex); + char old_bsw; + + // note the mode + cpInfos->modeReverse = ADOLC_FOV_REVERSE; + + numDirs = ADOLC_CURRENT_TAPE_INFOS.numDirs_rev; + cpInfos->dp_internal_for = new double[cpInfos->n]; + cpInfos->dpp_internal_rev = myalloc2(numDirs, cpInfos->n); + + // taping "off" + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (int i = 0; i < cpInfos->n; ++i) { + for (int j = 0; j < numDirs; ++j) { + cpInfos->dpp_internal_rev[j][i] = A[arg][j]; } - // update taylor buffer - for (int i = 0; i < cpInfos->n; ++i) { - --arg; - ADOLC_GET_TAYLOR(arg); + ++arg; + } + // update taylor buffer + for (int i = 0; i < cpInfos->n; ++i) { + --arg; + ADOLC_GET_TAYLOR(arg); + } + // execute second part of revolve_firstturn left from forward sweep + fov_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, numDirs, + cpInfos->dpp_internal_rev, cpInfos->dpp_internal_rev); + + old_bsw = ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning; + ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 0; + // checkpointing + enum revolve_action whattodo; + do { + whattodo = revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine, + cpInfos->checkpoints, &cpInfos->info); + switch (whattodo) { + case revolve_terminate: + break; + case revolve_takeshot: + cp_takeshot(cpInfos); + cpInfos->currentCP = cpInfos->capo; + break; + case revolve_advance: + for (int i = 0; i < cpInfos->capo - cpInfos->currentCP; ++i) + cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for); + break; + case revolve_youturn: + if (cpInfos->retaping != 0) + cp_taping(cpInfos); // retaping forced + else { + // one forward step with keep and retaping if necessary + if (zos_forward(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, 1, + cpInfos->dp_internal_for, cpInfos->dp_internal_for) < 0) + cp_taping(cpInfos); + } + // one reverse step + fov_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, numDirs, + cpInfos->dpp_internal_rev, cpInfos->dpp_internal_rev); + break; + case revolve_restore: + if (cpInfos->capo != cpInfos->currentCP) + cp_release(cpInfos); + cpInfos->currentCP = cpInfos->capo; + cp_restore(cpInfos); + break; + case revolve_error: + revolveError(cpInfos); + break; + default: + fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION); + break; } - // execute second part of revolve_firstturn left from forward sweep - fov_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, numDirs, - cpInfos->dpp_internal_rev, cpInfos->dpp_internal_rev); - - old_bsw = ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning; - ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 0; - // checkpointing - enum revolve_action whattodo; - do { - whattodo=revolve(&cpInfos->check, &cpInfos->capo, &cpInfos->fine, - cpInfos->checkpoints, &cpInfos->info); - switch (whattodo) { - case revolve_terminate: - break; - case revolve_takeshot: - cp_takeshot(cpInfos); - cpInfos->currentCP = cpInfos->capo; - break; - case revolve_advance: - for (int i = 0; i < cpInfos->capo - cpInfos->currentCP; ++i) - cpInfos->function_double(cpInfos->n, cpInfos->dp_internal_for); - break; - case revolve_youturn: - if (cpInfos->retaping != 0) cp_taping(cpInfos); // retaping forced - else { - // one forward step with keep and retaping if necessary - if (zos_forward(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, 1, - cpInfos->dp_internal_for, cpInfos->dp_internal_for) < 0) - cp_taping(cpInfos); - } - // one reverse step - fov_reverse(cpInfos->tapeNumber, cpInfos->n, cpInfos->n, numDirs, - cpInfos->dpp_internal_rev, cpInfos->dpp_internal_rev); - break; - case revolve_restore: - if (cpInfos->capo != cpInfos->currentCP) cp_release(cpInfos); - cpInfos->currentCP = cpInfos->capo; - cp_restore(cpInfos); - break; - case revolve_error: - revolveError(cpInfos); - break; - default: - fail(ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION); - break; - } - } while (whattodo != revolve_terminate && whattodo != revolve_error); - cp_release(cpInfos); // release first checkpoint if written - ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = old_bsw; - - // save results - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (int i = 0; i < cpInfos->n; ++i) { - for (int j = 0; j < numDirs; ++j) { - A[arg][j] = cpInfos->dpp_internal_rev[j][i]; - } - ++arg; + } while (whattodo != revolve_terminate && whattodo != revolve_error); + cp_release(cpInfos); // release first checkpoint if written + ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = old_bsw; + + // save results + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (int i = 0; i < cpInfos->n; ++i) { + for (int j = 0; j < numDirs; ++j) { + A[arg][j] = cpInfos->dpp_internal_rev[j][i]; } + ++arg; + } - // clean up - delete[] cpInfos->dp_internal_for; - cpInfos->dp_internal_for = NULL; - myfree2(cpInfos->dpp_internal_rev); - cpInfos->dpp_internal_rev = NULL; + // clean up + delete[] cpInfos->dp_internal_for; + cpInfos->dp_internal_for = NULL; + myfree2(cpInfos->dpp_internal_rev); + cpInfos->dpp_internal_rev = NULL; - // taping "on" - ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag; + // taping "on" + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; - return 0; + return 0; } -int cp_hos_reverse (int m, double *dp_U, int n, int d, double **dpp_Z) { - printf("WARNING: Checkpointing algorithm not " - "implemented for the hos_reverse mode!\n"); - return 0; +int cp_hos_reverse(int m, double *dp_U, int n, int d, double **dpp_Z) { + printf("WARNING: Checkpointing algorithm not " + "implemented for the hos_reverse mode!\n"); + return 0; } -int cp_hov_reverse (int m, int p, double **dpp_U, int n, int d, double ***dppp_Z, - short **spp_nz) { - printf("WARNING: Checkpointing algorithm not " - "implemented for the hov_reverse mode!\n"); - return 0; +int cp_hov_reverse(int m, int p, double **dpp_U, int n, int d, double ***dppp_Z, + short **spp_nz) { + printf("WARNING: Checkpointing algorithm not " + "implemented for the hov_reverse mode!\n"); + return 0; } /****************************************************************************/ @@ -518,108 +522,107 @@ int cp_hov_reverse (int m, int p, double **dpp_U, int n, int d, double ***dppp_Z /****************************************************************************/ void cp_clearStack() { - StackElement se; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - while (!ADOLC_CHECKPOINTS_STACK.empty()) { - se = ADOLC_CHECKPOINTS_STACK.top(); - ADOLC_CHECKPOINTS_STACK.pop(); - delete[] se[0]; - delete[] se; - } + StackElement se; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + while (!ADOLC_CHECKPOINTS_STACK.empty()) { + se = ADOLC_CHECKPOINTS_STACK.top(); + ADOLC_CHECKPOINTS_STACK.pop(); + delete[] se[0]; + delete[] se; + } } -void cp_takeshot (CpInfos *cpInfos) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - StackElement se = new double *[2]; - ADOLC_CHECKPOINTS_STACK.push(se); - se[0] = new double[cpInfos->n]; - for (int i = 0; i < cpInfos->n; ++i) - se[0][i] = cpInfos->dp_internal_for[i]; - if (cpInfos->saveNonAdoubles != NULL) - se[1] = static_cast(cpInfos->saveNonAdoubles()); - else - se[1] = NULL; +void cp_takeshot(CpInfos *cpInfos) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + StackElement se = new double *[2]; + ADOLC_CHECKPOINTS_STACK.push(se); + se[0] = new double[cpInfos->n]; + for (int i = 0; i < cpInfos->n; ++i) + se[0][i] = cpInfos->dp_internal_for[i]; + if (cpInfos->saveNonAdoubles != NULL) + se[1] = static_cast(cpInfos->saveNonAdoubles()); + else + se[1] = NULL; } -void cp_restore (CpInfos *cpInfos) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; +void cp_restore(CpInfos *cpInfos) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - StackElement se = ADOLC_CHECKPOINTS_STACK.top(); - for (int i = 0; i < cpInfos->n; ++i) - cpInfos->dp_internal_for[i] = se[0][i]; - if (se[1] != NULL) - cpInfos->restoreNonAdoubles(static_cast(se[1])); + StackElement se = ADOLC_CHECKPOINTS_STACK.top(); + for (int i = 0; i < cpInfos->n; ++i) + cpInfos->dp_internal_for[i] = se[0][i]; + if (se[1] != NULL) + cpInfos->restoreNonAdoubles(static_cast(se[1])); } -void cp_release (CpInfos *cpInfos) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (!ADOLC_CHECKPOINTS_STACK.empty()) { - StackElement se = ADOLC_CHECKPOINTS_STACK.top(); - ADOLC_CHECKPOINTS_STACK.pop(); - delete[] se[0]; - if (se[1] != NULL) - delete[] se[1]; - delete[] se; - } +void cp_release(CpInfos *cpInfos) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (!ADOLC_CHECKPOINTS_STACK.empty()) { + StackElement se = ADOLC_CHECKPOINTS_STACK.top(); + ADOLC_CHECKPOINTS_STACK.pop(); + delete[] se[0]; + if (se[1] != NULL) + delete[] se[1]; + delete[] se; + } } void cp_taping(CpInfos *cpInfos) { - adouble *tapingAdoubles = new adouble[cpInfos->n]; + adouble *tapingAdoubles = new adouble[cpInfos->n]; - trace_on(cpInfos->tapeNumber, 1); + trace_on(cpInfos->tapeNumber, 1); - for (int i = 0; i < cpInfos->n; ++i) - tapingAdoubles[i] <<= cpInfos->dp_internal_for[i]; + for (int i = 0; i < cpInfos->n; ++i) + tapingAdoubles[i] <<= cpInfos->dp_internal_for[i]; - cpInfos->function(cpInfos->n, tapingAdoubles); + cpInfos->function(cpInfos->n, tapingAdoubles); - for (int i = 0; i < cpInfos->n; ++i) - tapingAdoubles[i] >>= cpInfos->dp_internal_for[i]; + for (int i = 0; i < cpInfos->n; ++i) + tapingAdoubles[i] >>= cpInfos->dp_internal_for[i]; - trace_off(); + trace_off(); - delete[] tapingAdoubles; + delete[] tapingAdoubles; } /****************************************************************************/ /* revolve error function */ /****************************************************************************/ -void revolveError (CpInfos *cpInfos) { - switch(cpInfos->info) { - case 10: - printf(" Number of checkpoints stored exceeds " - "checkup!\n Increase constant 'checkup' " - "and recompile!\n"); - break; - case 11: - printf(" Number of checkpoints stored = %d exceeds " - "snaps = %d!\n Ensure 'snaps' > 0 and increase " - "initial 'fine'!\n", cpInfos->check+1, - cpInfos->checkpoints); - break; - case 12: - printf(" Error occurred in numforw!\n"); - break; - case 13: - printf(" Enhancement of 'fine', 'snaps' checkpoints " - "stored!\n Increase 'snaps'!\n"); - break; - case 14: - printf(" Number of snaps exceeds checkup!\n Increase " - "constant 'checkup' and recompile!\n"); - break; - case 15: - printf(" Number of reps exceeds repsup!\n Increase " - "constant 'repsup' and recompile!\n"); - break; - } - fail(ADOLC_CHECKPOINTING_REVOLVE_IRREGULAR_TERMINATED); +void revolveError(CpInfos *cpInfos) { + switch (cpInfos->info) { + case 10: + printf(" Number of checkpoints stored exceeds " + "checkup!\n Increase constant 'checkup' " + "and recompile!\n"); + break; + case 11: + printf(" Number of checkpoints stored = %d exceeds " + "snaps = %d!\n Ensure 'snaps' > 0 and increase " + "initial 'fine'!\n", + cpInfos->check + 1, cpInfos->checkpoints); + break; + case 12: + printf(" Error occurred in numforw!\n"); + break; + case 13: + printf(" Enhancement of 'fine', 'snaps' checkpoints " + "stored!\n Increase 'snaps'!\n"); + break; + case 14: + printf(" Number of snaps exceeds checkup!\n Increase " + "constant 'checkup' and recompile!\n"); + break; + case 15: + printf(" Number of reps exceeds repsup!\n Increase " + "constant 'repsup' and recompile!\n"); + break; + } + fail(ADOLC_CHECKPOINTING_REVOLVE_IRREGULAR_TERMINATED); } - diff --git a/ADOL-C/src/checkpointing_p.h b/ADOL-C/src/checkpointing_p.h index d2cba0d7c..42c710c41 100644 --- a/ADOL-C/src/checkpointing_p.h +++ b/ADOL-C/src/checkpointing_p.h @@ -3,31 +3,31 @@ File: checkpointing_p.h Revision: $Id$ Contents: private functions for the checkpointing functions. - + Copyright (c) Andreas Kowarz, Jean Utke - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_CHECKPOINTING_P_H) -#define ADOLC_CHECKPOINTING_P_H 1 + #define ADOLC_CHECKPOINTING_P_H 1 -#include -#include -#include "buffer_temp.h" -#include "taping_p.h" + #include "buffer_temp.h" + #include "taping_p.h" + #include + #include -#include + #include using std::stack; BEGIN_C_DECLS /****************************************************************************/ /* Now the C THINGS */ -#define CP_BLOCK_SIZE 10 + #define CP_BLOCK_SIZE 10 CpInfos *get_cp_fct(int index); @@ -37,9 +37,9 @@ END_C_DECLS /****************************************************************************/ -#if defined(__cplusplus) + #if defined(__cplusplus) -#define ADOLC_BUFFER_TYPE Buffer< CpInfos, CP_BLOCK_SIZE > + #define ADOLC_BUFFER_TYPE Buffer extern ADOLC_BUFFER_TYPE ADOLC_EXT_DIFF_FCTS_BUFFER_DECL; /* field of pointers to the value fields of a checkpoint */ @@ -49,7 +49,6 @@ extern stack ADOLC_CHECKPOINTS_STACK_DECL; /* a cleanup function */ void cp_clearStack(); -#endif + #endif #endif /* ADOLC_CHECKPOITING_P_H */ - diff --git a/ADOL-C/src/convolut.c b/ADOL-C/src/convolut.c index af74f1894..993feb161 100644 --- a/ADOL-C/src/convolut.c +++ b/ADOL-C/src/convolut.c @@ -3,14 +3,14 @@ File: convolute.c Revision: $Id$ Contents: Convolution routines (used by ho_rev.mc) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #include @@ -22,26 +22,26 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* Evaluates convolution of a and b to c */ -void conv( int dim, revreal *a, revreal *b, revreal *c ) { - double tmpVal; - int i,j; - for (i=dim-1; i>=0; i--) { - tmpVal = a[i]*b[0]; - for (j=1; j<=i; j++) - tmpVal += a[i-j]*b[j]; - c[i] = tmpVal; - } +void conv(int dim, revreal *a, revreal *b, revreal *c) { + double tmpVal; + int i, j; + for (i = dim - 1; i >= 0; i--) { + tmpVal = a[i] * b[0]; + for (j = 1; j <= i; j++) + tmpVal += a[i - j] * b[j]; + c[i] = tmpVal; + } } -void conv0( int dim, revreal *a, revreal *b, revreal *c ) { - double tmpVal; - int i,j; - for (i=dim-1; i>=0; i--) { - tmpVal = a[i]*b[0]; - for (j=1; j<=i; j++) - tmpVal += a[i-j]*b[j]; - c[i] = tmpVal; - } +void conv0(int dim, revreal *a, revreal *b, revreal *c) { + double tmpVal; + int i, j; + for (i = dim - 1; i >= 0; i--) { + tmpVal = a[i] * b[0]; + for (j = 1; j <= i; j++) + tmpVal += a[i - j] * b[j]; + c[i] = tmpVal; + } } /****************************************************************************/ @@ -49,44 +49,44 @@ void conv0( int dim, revreal *a, revreal *b, revreal *c ) { /*--------------------------------------------------------------------------*/ /* Increments truncated convolution of a and b to c */ -void inconv( int dim, revreal *a, revreal *b, revreal *c ) { - double tmpVal; - int i,j; - for (i=dim-1; i>=0; i--) { - tmpVal = a[i]*b[0]; - for (j=1; j<=i; j++) - tmpVal += a[i-j]*b[j]; - c[i] += tmpVal; - } +void inconv(int dim, revreal *a, revreal *b, revreal *c) { + double tmpVal; + int i, j; + for (i = dim - 1; i >= 0; i--) { + tmpVal = a[i] * b[0]; + for (j = 1; j <= i; j++) + tmpVal += a[i - j] * b[j]; + c[i] += tmpVal; + } } /*--------------------------------------------------------------------------*/ /* olvo 980616 nf */ /* Increments truncated convolution of a and b to c and sets a to zero */ -void inconv0( int dim, revreal *a, revreal *b, revreal *c ) { - double tmpVal; - int i,j; - for (i=dim-1; i>=0; i--) { - tmpVal = a[i]*b[0]; - a[i] = 0; - for (j=1; j<=i; j++) - tmpVal += a[i-j]*b[j]; - c[i] += tmpVal; - } +void inconv0(int dim, revreal *a, revreal *b, revreal *c) { + double tmpVal; + int i, j; + for (i = dim - 1; i >= 0; i--) { + tmpVal = a[i] * b[0]; + a[i] = 0; + for (j = 1; j <= i; j++) + tmpVal += a[i - j] * b[j]; + c[i] += tmpVal; + } } /*--------------------------------------------------------------------------*/ /* olvo 980616 nf */ /* Increments truncated convolution of a and b to c */ -void inconv1( int dim, revreal *a, revreal *b, revreal *c ) { - revreal tmpVal; - int i,j; - for (i=dim-1; i>=0; i--) { - tmpVal = a[i]*b[0]; - for (j=1; j<=i; j++) - tmpVal += a[i-j]*b[j]; - c[i] += tmpVal; - } +void inconv1(int dim, revreal *a, revreal *b, revreal *c) { + revreal tmpVal; + int i, j; + for (i = dim - 1; i >= 0; i--) { + tmpVal = a[i] * b[0]; + for (j = 1; j <= i; j++) + tmpVal += a[i - j] * b[j]; + c[i] += tmpVal; + } } /****************************************************************************/ @@ -94,71 +94,71 @@ void inconv1( int dim, revreal *a, revreal *b, revreal *c ) { /*--------------------------------------------------------------------------*/ /* Decrements truncated convolution of a and b to c */ -void deconv( int dim, revreal *a, revreal *b, revreal *c ) { - double tmpVal; - int i,j; - for (i=dim-1; i>=0; i--) { - tmpVal = a[i]*b[0]; - for (j=1; j<=i; j++) - tmpVal += a[i-j]*b[j]; - c[i] -= tmpVal; - } +void deconv(int dim, revreal *a, revreal *b, revreal *c) { + double tmpVal; + int i, j; + for (i = dim - 1; i >= 0; i--) { + tmpVal = a[i] * b[0]; + for (j = 1; j <= i; j++) + tmpVal += a[i - j] * b[j]; + c[i] -= tmpVal; + } } /*--------------------------------------------------------------------------*/ /* olvo 980616 nf */ /* Decrements truncated convolution of a and b to c and sets a to zero */ -void deconv0( int dim, revreal *a, revreal *b, revreal *c ) { - double tmpVal; - int i,j; - for (i=dim-1; i>=0; i--) { - tmpVal = a[i]*b[0]; - a[i] = 0; - for (j=1; j<=i; j++) - tmpVal += a[i-j]*b[j]; - c[i] -= tmpVal; - } +void deconv0(int dim, revreal *a, revreal *b, revreal *c) { + double tmpVal; + int i, j; + for (i = dim - 1; i >= 0; i--) { + tmpVal = a[i] * b[0]; + a[i] = 0; + for (j = 1; j <= i; j++) + tmpVal += a[i - j] * b[j]; + c[i] -= tmpVal; + } } /*--------------------------------------------------------------------------*/ /* Decrements truncated convolution of a and b to c */ -void deconv1( int dim, revreal *a, revreal *b, revreal *c ) { - revreal tmpVal; - int i,j; - for (i=dim-1; i>=0; i--) { - tmpVal = a[i]*b[0]; - for (j=1; j<=i; j++) - tmpVal += a[i-j]*b[j]; - c[i] -= tmpVal; - } +void deconv1(int dim, revreal *a, revreal *b, revreal *c) { + revreal tmpVal; + int i, j; + for (i = dim - 1; i >= 0; i--) { + tmpVal = a[i] * b[0]; + for (j = 1; j <= i; j++) + tmpVal += a[i - j] * b[j]; + c[i] -= tmpVal; + } } /****************************************************************************/ /* OTHER USEFUL ROUTINES */ /*--------------------------------------------------------------------------*/ -void divide( int dim, revreal *a, revreal *b, revreal *c ) { - int i,j; - double rec = 1/b[0]; - for (i=0; i #include #include -#include #include @@ -27,304 +27,270 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* function */ /* function(tag, m, n, x[n], y[m]) */ -int function(short tag, - int m, - int n, - const double* argument, - double* result) { - int rc= -1; +int function(short tag, int m, int n, const double *argument, double *result) { + int rc = -1; - rc= zos_forward(tag,m,n,0,argument,result); + rc = zos_forward(tag, m, n, 0, argument, result); - return rc; + return rc; } /*--------------------------------------------------------------------------*/ /* gradient */ /* gradient(tag, n, x[n], g[n]) */ -int gradient(short tag, - int n, - const double* argument, - double* result) { - int rc= -1; - double one = 1.0; - - rc = zos_forward(tag,1,n,1,argument,result); - if(rc < 0) - return rc; - MINDEC(rc, fos_reverse(tag,1,n,&one,result)); +int gradient(short tag, int n, const double *argument, double *result) { + int rc = -1; + double one = 1.0; + + rc = zos_forward(tag, 1, n, 1, argument, result); + if (rc < 0) return rc; + MINDEC(rc, fos_reverse(tag, 1, n, &one, result)); + return rc; } /*--------------------------------------------------------------------------*/ /* */ /* vec_jac(tag, m, n, repeat, x[n], u[m], v[n]) */ -int vec_jac(short tag, - int m, - int n, - int repeat, - const double* argument, - double* lagrange, - double* row) { - int rc= -1; - double *y = NULL; - - if(!repeat) { - y = myalloc1(m); - rc = zos_forward(tag,m,n,1, argument, y); - if(rc < 0) return rc; - } - MINDEC(rc, fos_reverse(tag,m,n,lagrange,row)); - if (!repeat) myfree1(y); - return rc; +int vec_jac(short tag, int m, int n, int repeat, const double *argument, + double *lagrange, double *row) { + int rc = -1; + double *y = NULL; + + if (!repeat) { + y = myalloc1(m); + rc = zos_forward(tag, m, n, 1, argument, y); + if (rc < 0) + return rc; + } + MINDEC(rc, fos_reverse(tag, m, n, lagrange, row)); + if (!repeat) + myfree1(y); + return rc; } /*--------------------------------------------------------------------------*/ /* jacobian */ /* jacobian(tag, m, n, x[n], J[m][n]) */ -int jacobian(short tag, - int depen, - int indep, - const double *argument, +int jacobian(short tag, int depen, int indep, const double *argument, double **jacobian) { - int rc; - double *result, **I; - - result = myalloc1(depen); - - if (indep/2 < depen) { - I = myallocI2(indep); - rc = fov_forward(tag,depen,indep,indep,argument,I,result,jacobian); - myfreeI2(indep, I); - } else { - I = myallocI2(depen); - rc = zos_forward(tag,depen,indep,1,argument,result); - if (rc < 0) return rc; - MINDEC(rc,fov_reverse(tag,depen,indep,depen,I,jacobian)); - myfreeI2(depen, I); - } + int rc; + double *result, **I; - myfree1(result); + result = myalloc1(depen); - return rc; + if (indep / 2 < depen) { + I = myallocI2(indep); + rc = fov_forward(tag, depen, indep, indep, argument, I, result, jacobian); + myfreeI2(indep, I); + } else { + I = myallocI2(depen); + rc = zos_forward(tag, depen, indep, 1, argument, result); + if (rc < 0) + return rc; + MINDEC(rc, fov_reverse(tag, depen, indep, depen, I, jacobian)); + myfreeI2(depen, I); + } + + myfree1(result); + + return rc; } /*--------------------------------------------------------------------------*/ /* large_jacobian */ /* large_jacobian(tag, m, n, k, x[n], y[m], J[m][n]) */ -int large_jacobian(short tag, - int depen, - int indep, - int runns, - double *argument, - double *result, - double **jacobian) -{ - int rc, dirs, i; - double **I; - - I = myallocI2(indep); - if (runns > indep) runns = indep; - if (runns < 1) runns = 1; - dirs = indep / runns; - if (indep % runns) ++dirs; - for (i=0; i indep) + runns = indep; + if (runns < 1) + runns = 1; + dirs = indep / runns; + if (indep % runns) + ++dirs; + for (i = 0; i < runns - 1; ++i) { + rc = fov_offset_forward(tag, depen, indep, dirs, i * dirs, argument, I, + result, jacobian); + } + dirs = indep - (runns - 1) * dirs; + rc = fov_offset_forward(tag, depen, indep, dirs, indep - dirs, argument, I, + result, jacobian); + myfreeI2(indep, I); + return rc; } /*--------------------------------------------------------------------------*/ /* jac_vec */ /* jac_vec(tag, m, n, x[n], v[n], u[m]); */ -int jac_vec(short tag, - int m, - int n, - const double* argument, - const double* tangent, - double* column) { - int rc= -1; - double *y; +int jac_vec(short tag, int m, int n, const double *argument, + const double *tangent, double *column) { + int rc = -1; + double *y; - y = myalloc1(m); + y = myalloc1(m); - rc = fos_forward(tag, m, n, 0, argument, tangent, y, column); - myfree1(y); + rc = fos_forward(tag, m, n, 0, argument, tangent, y, column); + myfree1(y); - return rc; + return rc; } /*--------------------------------------------------------------------------*/ /* hess_vec */ /* hess_vec(tag, n, x[n], v[n], w[n]) */ -int hess_vec(short tag, - int n, - const double *argument, - const double *tangent, +int hess_vec(short tag, int n, const double *argument, const double *tangent, double *result) { - double one = 1.0; - return lagra_hess_vec(tag,1,n,argument,tangent,&one,result); + double one = 1.0; + return lagra_hess_vec(tag, 1, n, argument, tangent, &one, result); } /*--------------------------------------------------------------------------*/ /* hess_mat */ /* hess_mat(tag, n, q, x[n], V[n][q], W[n][q]) */ -int hess_mat(short tag, - int n, - int q, - const double *argument, - const double * const *tangent, - double **result) { - int rc; - int i,j; - double y; - double*** Xppp; - double*** Yppp; - double*** Zppp; - double** Upp; - - Xppp = myalloc3(n,q,1); /* matrix on right-hand side */ - Yppp = myalloc3(1,q,1); /* results of hos_wk_forward */ - Zppp = myalloc3(q,n,2); /* result of Up x H x XPPP */ - Upp = myalloc2(1,2); /* vector on left-hand side */ - - for (i = 0; i < n; ++i) - for (j = 0; j < q; ++j) - Xppp[i][j][0] = tangent[i][j]; - - Upp[0][0] = 1; - Upp[0][1] = 0; - - rc = hov_wk_forward(tag, 1, n, 1, 2, q, argument, Xppp, &y, Yppp); - MINDEC(rc, hos_ov_reverse(tag, 1, n, 1, q, Upp, Zppp)); - - for (i = 0; i < q; ++i) - for (j = 0; j < n; ++j) - result[j][i] = Zppp[i][j][1]; - - myfree2(Upp); - myfree3(Zppp); - myfree3(Yppp); - myfree3(Xppp); - - return rc; +int hess_mat(short tag, int n, int q, const double *argument, + const double *const *tangent, double **result) { + int rc; + int i, j; + double y; + double ***Xppp; + double ***Yppp; + double ***Zppp; + double **Upp; + + Xppp = myalloc3(n, q, 1); /* matrix on right-hand side */ + Yppp = myalloc3(1, q, 1); /* results of hos_wk_forward */ + Zppp = myalloc3(q, n, 2); /* result of Up x H x XPPP */ + Upp = myalloc2(1, 2); /* vector on left-hand side */ + + for (i = 0; i < n; ++i) + for (j = 0; j < q; ++j) + Xppp[i][j][0] = tangent[i][j]; + + Upp[0][0] = 1; + Upp[0][1] = 0; + + rc = hov_wk_forward(tag, 1, n, 1, 2, q, argument, Xppp, &y, Yppp); + MINDEC(rc, hos_ov_reverse(tag, 1, n, 1, q, Upp, Zppp)); + + for (i = 0; i < q; ++i) + for (j = 0; j < n; ++j) + result[j][i] = Zppp[i][j][1]; + + myfree2(Upp); + myfree3(Zppp); + myfree3(Yppp); + myfree3(Xppp); + + return rc; } /*--------------------------------------------------------------------------*/ /* hessian */ /* hessian(tag, n, x[n], lower triangle of H[n][n]) */ /* uses Hessian-vector product */ -int hessian(short tag, - int n, - const double* argument, - double** hess) { - int rc= 3; - int i,j; - double *v = myalloc1(n); - double *w = myalloc1(n); - for(i=0;i -#include #include +#include #include +#include #include @@ -28,189 +28,161 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* function */ /* function(tag, m, n, x[n], y[m]) */ -fint function_(fint* ftag, - fint* fm, - fint* fn, - fdouble* fargument, - fdouble* fresult) { - int rc= -1; - short tag= (short) *ftag; - int m=*fm, n=*fn; - double* argument = myalloc1(n); - double* result = myalloc1(m); - spread1(n,fargument,argument); - rc= function(tag,m,n,argument,result); - pack1(m,result,fresult); - myfree1(argument); - myfree1(result); - return rc; +fint function_(fint *ftag, fint *fm, fint *fn, fdouble *fargument, + fdouble *fresult) { + int rc = -1; + short tag = (short)*ftag; + int m = *fm, n = *fn; + double *argument = myalloc1(n); + double *result = myalloc1(m); + spread1(n, fargument, argument); + rc = function(tag, m, n, argument, result); + pack1(m, result, fresult); + myfree1(argument); + myfree1(result); + return rc; } /*--------------------------------------------------------------------------*/ /* gradient */ /* gradient(tag, n, x[n], g[n]) */ -fint gradient_(fint* ftag, - fint* fn, - fdouble* fargument, - fdouble* fresult) { - int rc= -1; - short tag= (short) *ftag; - int n=*fn; - double* argument=myalloc1(n); - double* result=myalloc1(n); - spread1(n,fargument,argument); - rc= gradient(tag,n,argument,result); - pack1(n,result,fresult); - myfree1(result); - myfree1(argument); - return rc; +fint gradient_(fint *ftag, fint *fn, fdouble *fargument, fdouble *fresult) { + int rc = -1; + short tag = (short)*ftag; + int n = *fn; + double *argument = myalloc1(n); + double *result = myalloc1(n); + spread1(n, fargument, argument); + rc = gradient(tag, n, argument, result); + pack1(n, result, fresult); + myfree1(result); + myfree1(argument); + return rc; } /*--------------------------------------------------------------------------*/ /* */ /* vec_jac(tag, m, n, repeat, x[n], u[m], v[n]) */ -fint vec_jac_(fint* ftag, - fint* fm, - fint* fn, - fint* frepeat, - fdouble* fargument, - fdouble* flagrange, - fdouble* frow) { - int rc= -1; - short tag= (short) *ftag; - int m=*fm, n=*fn, repeat=*frepeat; - double* argument = myalloc1(n); - double* lagrange = myalloc1(m); - double* row = myalloc1(n); - spread1(m,flagrange,lagrange); - spread1(n,fargument,argument); - rc= vec_jac(tag,m,n,repeat,argument,lagrange, row); - pack1(n,row,frow); - myfree1(argument); - myfree1(lagrange); - myfree1(row); - return rc; +fint vec_jac_(fint *ftag, fint *fm, fint *fn, fint *frepeat, fdouble *fargument, + fdouble *flagrange, fdouble *frow) { + int rc = -1; + short tag = (short)*ftag; + int m = *fm, n = *fn, repeat = *frepeat; + double *argument = myalloc1(n); + double *lagrange = myalloc1(m); + double *row = myalloc1(n); + spread1(m, flagrange, lagrange); + spread1(n, fargument, argument); + rc = vec_jac(tag, m, n, repeat, argument, lagrange, row); + pack1(n, row, frow); + myfree1(argument); + myfree1(lagrange); + myfree1(row); + return rc; } /*--------------------------------------------------------------------------*/ /* jacobian */ /* jacobian(tag, m, n, x[n], J[m][n]) */ -fint jacobian_(fint* ftag, - fint* fdepen, - fint* findep, - fdouble *fargument, +fint jacobian_(fint *ftag, fint *fdepen, fint *findep, fdouble *fargument, fdouble *fjac) { - int rc= -1; - short tag= (short) *ftag; - int depen=*fdepen, indep=*findep; - double** Jac = myalloc2(depen,indep); - double* argument = myalloc1(indep); - spread1(indep,fargument,argument); - rc= jacobian(tag,depen,indep,argument,Jac); - pack2(depen,indep,Jac,fjac); - myfree2(Jac); - myfree1(argument); - return rc; + int rc = -1; + short tag = (short)*ftag; + int depen = *fdepen, indep = *findep; + double **Jac = myalloc2(depen, indep); + double *argument = myalloc1(indep); + spread1(indep, fargument, argument); + rc = jacobian(tag, depen, indep, argument, Jac); + pack2(depen, indep, Jac, fjac); + myfree2(Jac); + myfree1(argument); + return rc; } /*--------------------------------------------------------------------------*/ /* */ /* jac_vec(tag, m, n, x[n], v[n], u[m]); */ -fint jac_vec_(fint* ftag, - fint* fm, - fint* fn, - fdouble* fargument, - fdouble* ftangent, - fdouble* fcolumn) { - int rc= -1; - short tag= (short) *ftag; - int m=*fm, n=*fn; - double* argument = myalloc1(n); - double* tangent = myalloc1(n); - double* column = myalloc1(m); - spread1(n,ftangent,tangent); - spread1(n,fargument,argument); - rc= jac_vec(tag,m,n,argument,tangent,column); - pack1(m,column,fcolumn); - myfree1(argument); - myfree1(tangent); - myfree1(column); - return rc; +fint jac_vec_(fint *ftag, fint *fm, fint *fn, fdouble *fargument, + fdouble *ftangent, fdouble *fcolumn) { + int rc = -1; + short tag = (short)*ftag; + int m = *fm, n = *fn; + double *argument = myalloc1(n); + double *tangent = myalloc1(n); + double *column = myalloc1(m); + spread1(n, ftangent, tangent); + spread1(n, fargument, argument); + rc = jac_vec(tag, m, n, argument, tangent, column); + pack1(m, column, fcolumn); + myfree1(argument); + myfree1(tangent); + myfree1(column); + return rc; } /*--------------------------------------------------------------------------*/ /* */ /* hess_vec(tag, n, x[n], v[n], w[n]) */ -fint hess_vec_(fint* ftag, - fint* fn, - fdouble *fargument, - fdouble *ftangent, +fint hess_vec_(fint *ftag, fint *fn, fdouble *fargument, fdouble *ftangent, fdouble *fresult) { - int rc= -1; - short tag= (short) *ftag; - int n=*fn; - double *argument = myalloc1(n); - double *tangent = myalloc1(n); - double *result = myalloc1(n); - spread1(n,fargument,argument); - spread1(n,ftangent,tangent); - rc= hess_vec(tag,n,argument,tangent,result); - pack1(n,result,fresult); - myfree1(argument); - myfree1(tangent); - myfree1(result); - return rc; + int rc = -1; + short tag = (short)*ftag; + int n = *fn; + double *argument = myalloc1(n); + double *tangent = myalloc1(n); + double *result = myalloc1(n); + spread1(n, fargument, argument); + spread1(n, ftangent, tangent); + rc = hess_vec(tag, n, argument, tangent, result); + pack1(n, result, fresult); + myfree1(argument); + myfree1(tangent); + myfree1(result); + return rc; } /*--------------------------------------------------------------------------*/ /* hessian */ /* hessian(tag, n, x[n], lower triangle of H[n][n]) */ -fint hessian_(fint* ftag, - fint* fn, - fdouble* fx, - fdouble* fh) /* length of h should be n*n but the +fint hessian_(fint *ftag, fint *fn, fdouble *fx, + fdouble *fh) /* length of h should be n*n but the upper half of this matrix remains unchanged */ { - int rc= -1; - short tag= (short) *ftag; - int n=*fn; - double** H = myalloc2(n,n); - double* x = myalloc1(n); - spread1(n,fx,x); - rc= hessian(tag,n,x,H); - pack2(n,n,H,fh); - myfree2(H); - myfree1(x); - return rc; + int rc = -1; + short tag = (short)*ftag; + int n = *fn; + double **H = myalloc2(n, n); + double *x = myalloc1(n); + spread1(n, fx, x); + rc = hessian(tag, n, x, H); + pack2(n, n, H, fh); + myfree2(H); + myfree1(x); + return rc; } /*--------------------------------------------------------------------------*/ /* */ /* lagra_hess_vec(tag, m, n, x[n], v[n], u[m], w[n]) */ -fint lagra_hess_vec_(fint* ftag, - fint* fm, - fint* fn, - fdouble *fargument, - fdouble *ftangent, - fdouble *flagrange, - fdouble *fresult) { - int rc=-1; - short tag= (short) *ftag; - int m=*fm, n=*fn; - double *argument = myalloc1(n); - double *tangent = myalloc1(n); - double *lagrange = myalloc1(m); - double *result = myalloc1(n); - spread1(n,fargument,argument); - spread1(n,ftangent,tangent); - spread1(m,flagrange,lagrange); - rc= lagra_hess_vec(tag,m,n,argument,tangent,lagrange,result); - pack1(n,result,fresult); - myfree1(argument); - myfree1(tangent); - myfree1(lagrange); - myfree1(result); - return rc; +fint lagra_hess_vec_(fint *ftag, fint *fm, fint *fn, fdouble *fargument, + fdouble *ftangent, fdouble *flagrange, fdouble *fresult) { + int rc = -1; + short tag = (short)*ftag; + int m = *fm, n = *fn; + double *argument = myalloc1(n); + double *tangent = myalloc1(n); + double *lagrange = myalloc1(m); + double *result = myalloc1(n); + spread1(n, fargument, argument); + spread1(n, ftangent, tangent); + spread1(m, flagrange, lagrange); + rc = lagra_hess_vec(tag, m, n, argument, tangent, lagrange, result); + pack1(n, result, fresult); + myfree1(argument); + myfree1(tangent); + myfree1(lagrange); + myfree1(result); + return rc; } END_C_DECLS diff --git a/ADOL-C/src/drivers/odedrivers.c b/ADOL-C/src/drivers/odedrivers.c index 5be4f8449..85c5d854d 100644 --- a/ADOL-C/src/drivers/odedrivers.c +++ b/ADOL-C/src/drivers/odedrivers.c @@ -3,21 +3,21 @@ File: drivers/odedrivers.c Revision: $Id$ Contents: Easy to use drivers for ordinary differential equations (ODE) - (with C and C++ callable interfaces including Fortran + (with C and C++ callable interfaces including Fortran callable versions). - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ +#include "taping_p.h" +#include #include #include -#include -#include "taping_p.h" #include @@ -29,211 +29,210 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* forodec */ /* forodec(tag, n, tau, dold, dnew, X[n][d+1]) */ -int forodec(short tag, /* tape identifier */ - int n, /* space dimension */ - double tau, /* scaling defaults to 1.0 */ - int dol, /* previous degree defaults to zero */ - int deg, /* New degree of consistency */ - double** Y) /* Taylor series */ +int forodec(short tag, /* tape identifier */ + int n, /* space dimension */ + double tau, /* scaling defaults to 1.0 */ + int dol, /* previous degree defaults to zero */ + int deg, /* New degree of consistency */ + double **Y) /* Taylor series */ { - /********************************************************************* - This is assumed to be the autonomous case. - Here we are just going around computing the vectors - y[][j] for dol < j <= deg - by successive calls to forward that works on the tape identified - by tag. This tape (array of file) must obviously have been - generated by a the execution of an active section between - trace_on and trace_off with n independent and n dependent variables - y must have been set up as pointer to an array of n pointers - to double arrays containing at least deg+1 components. - The scaling by tau is sometimes necessary to avoid overflow. - **********************************************************************/ - - int rc= 3; - int i, j, k; - double taut; - TapeInfos* tapeInfos; - - tapeInfos = getTapeInfos(tag); - if ( n > tapeInfos->pTapeInfos.forodec_nax || - deg > tapeInfos->pTapeInfos.forodec_dax ) - { - if (tapeInfos->pTapeInfos.forodec_nax) { - myfree1(tapeInfos->pTapeInfos.forodec_y); - myfree1(tapeInfos->pTapeInfos.forodec_z); - myfree2(tapeInfos->pTapeInfos.forodec_Z); - } - tapeInfos->pTapeInfos.forodec_Z = myalloc2(n, deg); - tapeInfos->pTapeInfos.forodec_z = myalloc1(n); - tapeInfos->pTapeInfos.forodec_y = myalloc1(n); - tapeInfos->pTapeInfos.forodec_nax = n; - tapeInfos->pTapeInfos.forodec_dax = deg; - } + /********************************************************************* + This is assumed to be the autonomous case. + Here we are just going around computing the vectors + y[][j] for dol < j <= deg + by successive calls to forward that works on the tape identified + by tag. This tape (array of file) must obviously have been + generated by a the execution of an active section between + trace_on and trace_off with n independent and n dependent variables + y must have been set up as pointer to an array of n pointers + to double arrays containing at least deg+1 components. + The scaling by tau is sometimes necessary to avoid overflow. + **********************************************************************/ - for (i = 0; i < n; ++i) { - tapeInfos->pTapeInfos.forodec_y[i] = Y[i][0]; - /*printf("y[%i] = %f\n",i,y[i]);*/ - for (k = 0; k < deg; ++k) { - Y[i][k] = Y[i][k+1]; - /*printf("Y[%i][%i] = %f\n",i,k,Y[i][k]);*/ - } - } + int rc = 3; + int i, j, k; + double taut; + TapeInfos *tapeInfos; - /****** Here we get going ********/ - if (dol == 0) { - j = dol; /* j = 0 */ - k = (deg) * (j == deg-1 ) ; /* keep death values in prepration */ - MINDEC(rc, zos_forward(tag, n, n, k, - tapeInfos->pTapeInfos.forodec_y, - tapeInfos->pTapeInfos.forodec_z)); - /* for reverse called by jacode */ - if(rc < 0) return rc; - taut = tau / (1 + j); /* only the last time through. */ - for (i = 0; i < n; ++i) - Y[i][j] = taut * tapeInfos->pTapeInfos.forodec_z[i]; - dol++; /* !!! */ + tapeInfos = getTapeInfos(tag); + if (n > tapeInfos->pTapeInfos.forodec_nax || + deg > tapeInfos->pTapeInfos.forodec_dax) { + if (tapeInfos->pTapeInfos.forodec_nax) { + myfree1(tapeInfos->pTapeInfos.forodec_y); + myfree1(tapeInfos->pTapeInfos.forodec_z); + myfree2(tapeInfos->pTapeInfos.forodec_Z); } - for (j = dol; j < deg; ++j) { - k = (deg)*(j == deg-1) ; /* keep death values in prepration */ - MINDEC(rc, hos_forward(tag, n, n, j, k, - tapeInfos->pTapeInfos.forodec_y, - Y, tapeInfos->pTapeInfos.forodec_z, - tapeInfos->pTapeInfos.forodec_Z)); - /* for reverse called by jacode */ - if( rc < 0) return rc; - taut = tau / (1 + j); /* only the last time through. */ - for (i = 0; i < n; ++i) - Y[i][j] = taut * - tapeInfos->pTapeInfos.forodec_Z[i][j-1]; + tapeInfos->pTapeInfos.forodec_Z = myalloc2(n, deg); + tapeInfos->pTapeInfos.forodec_z = myalloc1(n); + tapeInfos->pTapeInfos.forodec_y = myalloc1(n); + tapeInfos->pTapeInfos.forodec_nax = n; + tapeInfos->pTapeInfos.forodec_dax = deg; + } + + for (i = 0; i < n; ++i) { + tapeInfos->pTapeInfos.forodec_y[i] = Y[i][0]; + /*printf("y[%i] = %f\n",i,y[i]);*/ + for (k = 0; k < deg; ++k) { + Y[i][k] = Y[i][k + 1]; + /*printf("Y[%i][%i] = %f\n",i,k,Y[i][k]);*/ } - /****** Done ********/ + } - for (i = 0; i < n; ++i) { - for (k = deg; k > 0; --k) { - Y[i][k] = Y[i][k-1]; - /*printf("Y[%i][%i] = %f\n",i,k,Y[i][k]);*/ - } - Y[i][0] = tapeInfos->pTapeInfos.forodec_y[i]; - /*printf("Y[%i][0] = %f\n",i,Y[i][0]);*/ + /****** Here we get going ********/ + if (dol == 0) { + j = dol; /* j = 0 */ + k = (deg) * (j == deg - 1); /* keep death values in prepration */ + MINDEC(rc, zos_forward(tag, n, n, k, tapeInfos->pTapeInfos.forodec_y, + tapeInfos->pTapeInfos.forodec_z)); + /* for reverse called by jacode */ + if (rc < 0) + return rc; + taut = tau / (1 + j); /* only the last time through. */ + for (i = 0; i < n; ++i) + Y[i][j] = taut * tapeInfos->pTapeInfos.forodec_z[i]; + dol++; /* !!! */ + } + for (j = dol; j < deg; ++j) { + k = (deg) * (j == deg - 1); /* keep death values in prepration */ + MINDEC(rc, hos_forward(tag, n, n, j, k, tapeInfos->pTapeInfos.forodec_y, Y, + tapeInfos->pTapeInfos.forodec_z, + tapeInfos->pTapeInfos.forodec_Z)); + /* for reverse called by jacode */ + if (rc < 0) + return rc; + taut = tau / (1 + j); /* only the last time through. */ + for (i = 0; i < n; ++i) + Y[i][j] = taut * tapeInfos->pTapeInfos.forodec_Z[i][j - 1]; + } + /****** Done ********/ + + for (i = 0; i < n; ++i) { + for (k = deg; k > 0; --k) { + Y[i][k] = Y[i][k - 1]; + /*printf("Y[%i][%i] = %f\n",i,k,Y[i][k]);*/ } + Y[i][0] = tapeInfos->pTapeInfos.forodec_y[i]; + /*printf("Y[%i][0] = %f\n",i,Y[i][0]);*/ + } - return rc; + return rc; } /*--------------------------------------------------------------------------*/ /* accodec */ /* accodec(n, tau, d, Z[n][n][d+1], B[n][n][d+1], nz[n][n]) */ -void accodec(int n, /* space dimension */ - double tau, /* scaling defaults to 1.0 */ - int deg, /* highest degree */ - double*** A, /* input tensor of "partial" Jacobians */ - double*** B, /* output tensor of "total" Jacobians */ - short** nonzero ) /* optional sparsity characterization */ +void accodec(int n, /* space dimension */ + double tau, /* scaling defaults to 1.0 */ + int deg, /* highest degree */ + double ***A, /* input tensor of "partial" Jacobians */ + double ***B, /* output tensor of "total" Jacobians */ + short **nonzero) /* optional sparsity characterization */ { - /* - The purpose of this subroutine is to compute the total derivatives - B[i=0...n-1][j=0...n-1][k=0...deg]. - The matrix obtained for fixed k represents the Jacobian of the - (k+1)-st Taylor coefficient vector with respect to the base point of - the ODE, i.e., the 0-th coefficient vector. The input array - A[i=0...n-1][j=0...n-1][k=0...deg] - has exactly the same format, except that it-s k-th matrix slice - represents a partial derivative in that the indirect dependence - of the k-th coefficient vector on the base point via the (k-1)-st - and other lower Taylor coefficients has not been taken into account. - The B's are compute from the A's by the chainrule with the parameter - tau thrown in for scaling. The calculation is performed so that - A may directly be overwritten by B i.e. their pointers arguments may - coincide to save storage. - Sparsity is used so far only to reduce the operations count - but not to save space. In general we expect that for each given pair - (i,j) the entries A[i][j][k=0...] are nonzero either for all k, or for no k, - or for k=0 only. - On entry the optional short array nonzero may be used to identify - all entries of the A[.][.][k] that are potentially nonzero, i.e. - - nonzero[i][j] <= 0 implies A[i][j][k] = 0 for all k - nonzero[i][j] = 1 implies A[i][j][k] = 0 for all k > 0 . - - In other words we only allow the sparsity of the matrices A[.][.][k] - to be increasing in that A[.][.][1] is possibly sparser than A[.][.][0] - and all subsequent A[.][.][k] with k > 0 have the same sparsity pattern. - That is the typical situation since A[.][.][k] is the k-th - Taylor coefficient in the time expansion of the Jacobian of the - right hand side. The entries of this square matrix tend to be either - constant or trancendental functions of time. - The matrices B_k = B[.][.][k] are obtained from the A_k = A[.][.][k] - by the recurrence - tau / k \ - B_k = ----- | A_k + SUM A_{j-1} B_{k-j} | - k+1 \ j=1 / - - Assuming that the diagonal entries A[i][i][0] are structurally nonzero - we find that the matrices B[.][.][k=1..] can only lose sparsity - as k increase. Therefore, we can redefine the nonpositive values - nonzero[i][j] so that on exit - - k <= -nonzero[i][j] implies B[i][j][k] = 0 - - which is trivially satisfied for all positive values of nonzero[i][j]. - Due to the increasing sparsity of the A_i and the decreasing sparsity - of the B_i the first product in the sum of the RHS above determines the - sparsity pattern of the resulting B_k. Hence the optimal values of - the nonzero[i][j] depend only on the sparsity pattern of A_0. More - specifically, all positive -nonzero[i][j] represent the length of the - shortest directed path connecting nodes j and i in the incidence graph - of A_0. - */ - - int i,j,k,m,p,nzip,nzpj,isum; - double *Aip, *Bpj, scale, sum; - for (k=0;k<=deg;k++) /* Lets calculate B_k */ - { - scale = tau/(1.0+k); - if(nonzero) { - for (i=0;i 0); - for (p=0;p 0) nzpj = 0; - if(nzip > 0 && k > -nzpj ) /*otherwise all terms vanish*/ - { - Aip = A[i][p]; - Bpj = B[p][j]+k-1; - sum += *Aip*(*Bpj); - isum =1; - if(nzip > 1 ) /* the A[i][p][m>0] may be nonzero*/ - for(m=k-1; m>-nzpj;m--) - sum += (*(++Aip))*(*(--Bpj)); - } - } - if(isum) /* we found something nonzero after all*/ - B[i][j][k] = sum*scale; - else { - B[i][j][k]= 0; - nonzero[i][j]--; - } - } - } else { - for (i=0;i0 ;m--) - sum += (*(Aip++))*(*Bpj--); - B[i][j][k] = sum*scale; - } - } + /* + The purpose of this subroutine is to compute the total derivatives + B[i=0...n-1][j=0...n-1][k=0...deg]. + The matrix obtained for fixed k represents the Jacobian of the + (k+1)-st Taylor coefficient vector with respect to the base point of + the ODE, i.e., the 0-th coefficient vector. The input array + A[i=0...n-1][j=0...n-1][k=0...deg] + has exactly the same format, except that it-s k-th matrix slice + represents a partial derivative in that the indirect dependence + of the k-th coefficient vector on the base point via the (k-1)-st + and other lower Taylor coefficients has not been taken into account. + The B's are compute from the A's by the chainrule with the parameter + tau thrown in for scaling. The calculation is performed so that + A may directly be overwritten by B i.e. their pointers arguments may + coincide to save storage. + Sparsity is used so far only to reduce the operations count + but not to save space. In general we expect that for each given pair + (i,j) the entries A[i][j][k=0...] are nonzero either for all k, or for no + k, or for k=0 only. On entry the optional short array nonzero may be used + to identify all entries of the A[.][.][k] that are potentially nonzero, + i.e. + + nonzero[i][j] <= 0 implies A[i][j][k] = 0 for all k + nonzero[i][j] = 1 implies A[i][j][k] = 0 for all k > 0 . + + In other words we only allow the sparsity of the matrices A[.][.][k] + to be increasing in that A[.][.][1] is possibly sparser than A[.][.][0] + and all subsequent A[.][.][k] with k > 0 have the same sparsity pattern. + That is the typical situation since A[.][.][k] is the k-th + Taylor coefficient in the time expansion of the Jacobian of the + right hand side. The entries of this square matrix tend to be either + constant or trancendental functions of time. + The matrices B_k = B[.][.][k] are obtained from the A_k = A[.][.][k] + by the recurrence + tau / k \ + B_k = ----- | A_k + SUM A_{j-1} B_{k-j} | + k+1 \ j=1 / + + Assuming that the diagonal entries A[i][i][0] are structurally nonzero + we find that the matrices B[.][.][k=1..] can only lose sparsity + as k increase. Therefore, we can redefine the nonpositive values + nonzero[i][j] so that on exit + + k <= -nonzero[i][j] implies B[i][j][k] = 0 + + which is trivially satisfied for all positive values of nonzero[i][j]. + Due to the increasing sparsity of the A_i and the decreasing sparsity + of the B_i the first product in the sum of the RHS above determines the + sparsity pattern of the resulting B_k. Hence the optimal values of + the nonzero[i][j] depend only on the sparsity pattern of A_0. More + specifically, all positive -nonzero[i][j] represent the length of the + shortest directed path connecting nodes j and i in the incidence graph + of A_0. + */ + + int i, j, k, m, p, nzip, nzpj, isum; + double *Aip, *Bpj, scale, sum; + for (k = 0; k <= deg; k++) /* Lets calculate B_k */ + { + scale = tau / (1.0 + k); + if (nonzero) { + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + if (k < -nonzero[i][j]) + B[i][j][k] = 0.0; + else { + sum = A[i][j][k]; + isum = (nonzero[i][j] > 0); + for (p = 0; p < n; p++) { + nzip = nonzero[i][p]; + nzpj = nonzero[p][j]; + if (nzpj > 0) + nzpj = 0; + if (nzip > 0 && k > -nzpj) /*otherwise all terms vanish*/ + { + Aip = A[i][p]; + Bpj = B[p][j] + k - 1; + sum += *Aip * (*Bpj); + isum = 1; + if (nzip > 1) /* the A[i][p][m>0] may be nonzero*/ + for (m = k - 1; m > -nzpj; m--) + sum += (*(++Aip)) * (*(--Bpj)); + } + } + if (isum) /* we found something nonzero after all*/ + B[i][j][k] = sum * scale; + else { + B[i][j][k] = 0; + nonzero[i][j]--; + } + } + } else { + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) { + sum = A[i][j][k]; + for (p = 0; p < n; p++) { + Aip = A[i][p]; + Bpj = B[p][j] + k - 1; + for (m = k; m > 0; m--) + sum += (*(Aip++)) * (*Bpj--); + B[i][j][k] = sum * scale; + } } } + } } END_C_DECLS diff --git a/ADOL-C/src/drivers/odedriversf.c b/ADOL-C/src/drivers/odedriversf.c index 1c0c63491..ec4a5256d 100644 --- a/ADOL-C/src/drivers/odedriversf.c +++ b/ADOL-C/src/drivers/odedriversf.c @@ -4,19 +4,19 @@ Revision: $Id$ Contents: Easy to use drivers for optimization and nonlinear equations (Implementation of the Fortran callable interfaces). - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ -#include -#include #include +#include #include +#include #include @@ -28,52 +28,52 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* forodec */ /* forodec(tag, n, tau, dold, dnew, X[n][d+1]) */ -fint forodec_(fint* ftag, /* tape identifier */ - fint* fn, /* space dimension */ - fdouble* ftau, /* scaling defaults to 1.0 */ - fint* fdol, /* previous degree defaults to zero */ - fint* fdeg, /* New degree of consistency */ - fdouble* fy) /* Taylor series */ +fint forodec_(fint *ftag, /* tape identifier */ + fint *fn, /* space dimension */ + fdouble *ftau, /* scaling defaults to 1.0 */ + fint *fdol, /* previous degree defaults to zero */ + fint *fdeg, /* New degree of consistency */ + fdouble *fy) /* Taylor series */ { - int rc= -1; - short tag= (short) *ftag; - int n=*fn, dol=*fdol, deg=*fdeg; - int i; - double tau=*ftau; - double** Y = myalloc2(n,deg+1); - for(i=0;i #include #include -#include -#include "taping_p.h" -#include "dvlparms.h" #include - BEGIN_C_DECLS /****************************************************************************/ @@ -30,64 +29,64 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* abs-normal form */ -int abs_normal(short tag, /* tape identifier */ - int m, /* number od dependents */ - int n, /* number of independents */ - int swchk, /* number of switches (check) */ - double *x, /* base point */ - double *y, /* function value */ - double *z, /* switching variables */ - double *cz, /* first constant */ - double *cy, /* second constant */ - double **Y, /* m times n */ - double **J, /* m times s */ - double **Z, /* s times n */ - double **L) /* s times s (lowtri) */ +int abs_normal(short tag, /* tape identifier */ + int m, /* number od dependents */ + int n, /* number of independents */ + int swchk, /* number of switches (check) */ + double *x, /* base point */ + double *y, /* function value */ + double *z, /* switching variables */ + double *cz, /* first constant */ + double *cy, /* second constant */ + double **Y, /* m times n */ + double **J, /* m times s */ + double **Z, /* s times n */ + double **L) /* s times s (lowtri) */ { - int i,j,s; + int i, j, s; double *res; - s=get_num_switches(tag); - - /* This check is required because the user is probably allocating his + s = get_num_switches(tag); + + /* This check is required because the user is probably allocating his * arrays sigma, cz, Z, L, Y, J according to swchk */ if (s != swchk) { - fprintf(DIAG_OUT, "ADOL-C error: Number of switches passed %d does not " - "match the one recorded on tape %d (%d)\n", swchk, tag, s); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, + "ADOL-C error: Number of switches passed %d does not " + "match the one recorded on tape %d (%d)\n", + swchk, tag, s); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); } - res=(double*)myalloc1(n+s); + res = (double *)myalloc1(n + s); - zos_pl_forward(tag,m,n,1,x,y,z); + zos_pl_forward(tag, m, n, 1, x, y, z); - - for(i=0;i #include +#include #include BEGIN_C_DECLS @@ -27,53 +27,44 @@ BEGIN_C_DECLS /* abs-normal form */ /* abs_normal(tag,m,n,s,x[n],sig[s],y[m],z[s],cz[s],cy[m], */ /* J[m][n],Y[m][s],Z[s][n],L[s][s]) */ -fint abs_normal_(fint* ftag, - fint* fdepen, - fint* findep, - fint* fswchk, - fdouble* fx, - fdouble* fy, - fdouble* fz, - fdouble* fcz, - fdouble* fcy, - fdouble* fJ, - fdouble* fY, - fdouble* fZ, - fdouble* fL) { - int rc = -1; - short tag = (short)*ftag; - int m = (int)*fdepen, n = (int)*findep, s=(int)*fswchk; - double **J, **Y, **Z, **L; - double *cy, *cz, *x, *y, *z; - J = myalloc2(m,n); - Y = myalloc2(m,s); - Z = myalloc2(s,n); - L = myalloc2(s,s); - cy = myalloc1(m); - cz = myalloc1(s); - x = myalloc1(n); - y = myalloc1(m); - z = myalloc1(s); - spread1(n,fx,x); - rc = abs_normal(tag,m,n,s,x,y,z,cz,cy,J,Y,Z,L); - pack1(m,y,fy); - pack1(s,z,fz); - pack1(s,cz,fcz); - pack1(m,cy,fcy); - pack2(m,n,J,fJ); - pack2(m,s,Y,fY); - pack2(s,n,Z,fZ); - pack2(s,s,L,fL); - myfree2(J); - myfree2(Y); - myfree2(Z); - myfree2(L); - myfree1(x); - myfree1(y); - myfree1(z); - myfree1(cz); - myfree1(cy); - return rc; +fint abs_normal_(fint *ftag, fint *fdepen, fint *findep, fint *fswchk, + fdouble *fx, fdouble *fy, fdouble *fz, fdouble *fcz, + fdouble *fcy, fdouble *fJ, fdouble *fY, fdouble *fZ, + fdouble *fL) { + int rc = -1; + short tag = (short)*ftag; + int m = (int)*fdepen, n = (int)*findep, s = (int)*fswchk; + double **J, **Y, **Z, **L; + double *cy, *cz, *x, *y, *z; + J = myalloc2(m, n); + Y = myalloc2(m, s); + Z = myalloc2(s, n); + L = myalloc2(s, s); + cy = myalloc1(m); + cz = myalloc1(s); + x = myalloc1(n); + y = myalloc1(m); + z = myalloc1(s); + spread1(n, fx, x); + rc = abs_normal(tag, m, n, s, x, y, z, cz, cy, J, Y, Z, L); + pack1(m, y, fy); + pack1(s, z, fz); + pack1(s, cz, fcz); + pack1(m, cy, fcy); + pack2(m, n, J, fJ); + pack2(m, s, Y, fY); + pack2(s, n, Z, fZ); + pack2(s, s, L, fL); + myfree2(J); + myfree2(Y); + myfree2(Z); + myfree2(L); + myfree1(x); + myfree1(y); + myfree1(z); + myfree1(cz); + myfree1(cy); + return rc; } /****************************************************************************/ diff --git a/ADOL-C/src/drivers/taylor.c b/ADOL-C/src/drivers/taylor.c index c622193d1..71e899fed 100644 --- a/ADOL-C/src/drivers/taylor.c +++ b/ADOL-C/src/drivers/taylor.c @@ -4,913 +4,885 @@ Revision: $Id$ Contents: Easy to use drivers for the evaluation of higher order derivative tensors and inverse/impicit function differentiation - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ +#include "taping_p.h" +#include #include #include -#include -#include "taping_p.h" #include BEGIN_C_DECLS - /****************************************************************************/ /* STRUCT ITEM */ struct item { - int a; /* address in array of derivatives */ - int b; /* absolute value of the corresponding multiindex i */ - double c; /* value of the coefficient c_{i,j} */ - struct item *next; /* next item */ + int a; /* address in array of derivatives */ + int b; /* absolute value of the corresponding multiindex i */ + double c; /* value of the coefficient c_{i,j} */ + struct item *next; /* next item */ }; /****************************************************************************/ /* DEALLOCATE COEFFLIST */ -void freecoefflist( int dim, struct item *coeff_list ) { - int i; - struct item *ptr1; - struct item *ptr2; - - for (i=0; inext; - while (ptr1 != NULL) { - ptr2 = ptr1->next; - free((char *) ptr1); - ptr1 = ptr2; - } +void freecoefflist(int dim, struct item *coeff_list) { + int i; + struct item *ptr1; + struct item *ptr2; + + for (i = 0; i < dim; i++) /* sum over all multiindices jm with |jm| = d */ + { + ptr1 = &coeff_list[i]; + ptr1 = ptr1->next; + while (ptr1 != NULL) { + ptr2 = ptr1->next; + free((char *)ptr1); + ptr1 = ptr2; } + } } - /****************************************************************************/ /* ALLOCATE/DEALLOCATE COEFFLIST */ -double* tensoriglob; +double *tensoriglob; /*--------------------------------------------------------------------------*/ /* Allocate space for symmetric derivative tensors of up to order d in n variables, derivatives are */ -void* tensorpoint( int n, int d ) { - int i; - void* t; - - if (d == 1) { - t = (void*) tensoriglob; - tensoriglob += n+1; - } else { - t = (void*) malloc((n+1)*sizeof(void*)); - for (i=0; i<=n; i++) - ((void**)t)[i] = (void*) tensorpoint(i,d-1); - } - return t; +void *tensorpoint(int n, int d) { + int i; + void *t; + + if (d == 1) { + t = (void *)tensoriglob; + tensoriglob += n + 1; + } else { + t = (void *)malloc((n + 1) * sizeof(void *)); + for (i = 0; i <= n; i++) + ((void **)t)[i] = (void *)tensorpoint(i, d - 1); + } + return t; } /*--------------------------------------------------------------------------*/ -void** tensorsetup( int m, int n, int d, double** tensorig ) { - int i; - void** t = (void**) malloc(m*sizeof(void*)); - - for (i=0; i 2) - for(i=0;i<=n;i++) { - t = tensor[i]; - freetensorpoint(i,d-1,(double **) t); - free((char *) t); - } +void freetensorpoint(int n, int d, double **tensor) { + int i; + double *t; + + if (d > 2) + for (i = 0; i <= n; i++) { + t = tensor[i]; + freetensorpoint(i, d - 1, (double **)t); + free((char *)t); + } } /*--------------------------------------------------------------------------*/ -void freetensor( int m, int n, int d, double** tensor ) { - int i; - double* t; - - for (i=0; i n) - return 0; + if (k > n) + return 0; - if (k > n/2) - k = n-k; + if (k > n / 2) + k = n - k; - for (i = 1; i <= k; i++) - accum = accum * (n-k+i) / i; + for (i = 1; i <= k; i++) + accum = accum * (n - k + i) / i; - return (long) accum + 0.5; + return (long)accum + 0.5; } /*--------------------------------------------------------------------------*/ -double dbinomi( double a, int b ) { - int i; - double result = 1.0; +double dbinomi(double a, int b) { + int i; + double result = 1.0; - for (i=1; i<=b; i++) - result = result*(a-i+1)/i; - return result; + for (i = 1; i <= b; i++) + result = result * (a - i + 1) / i; + return result; } /*--------------------------------------------------------------------------*/ -double summand(int p, int d, int* jm, int* km, int order_im, int order_km, long binomiZ) { /* calculates summation value for fixed j, i, k with terms used in the article.*/ - int i; - double result, order_k_by_d; - - order_k_by_d = order_km/(double)d; - result = 1.0; - for (i=0; i0)&&(im[i]==0)) break; - if (i==p) - while (1) { /* create all k where 0=0; i--) - if (km[i] 0) { /* Store coefficient */ - if (ptr==NULL) - ptr = &coeff_list[index_coeff_list]; - else { - ptr->next = (struct item*) malloc(sizeof(struct item)); - ptr = ptr->next; - }; - - address = 0; /* calculate address for ptr->a */ - j = d-order_im+1; - for (u=0; ua = address; - ptr->b = order_im; - ptr->c = sum; - }; - - if ((im[p-1]==order_im)||(p==1)) break; - for (i=p-2; im[i]==0; i--); /* find first nonvanishing entry on the right. */ - im[i]--; - im[i+1] = im[p-1]+1; - if (i!=p-2) im[p-1] = 0; +void coeff(int p, int d, struct item *coeff_list) { + int i, j, u, n, index_coeff_list, order_im, order_km, address; + int *jm = (int *)malloc(p * sizeof(int)); /* Multiindex j */ + int *im = (int *)malloc(p * sizeof(int)); /* Multiindex i */ + int *km = (int *)malloc(p * sizeof(int)); /* Multiindex k */ + struct item *ptr; + double sum; + long binomiZ; /* whole number binomial coefficient */ + + jm[0] = d; + for (i = 1; i < p; i++) + jm[i] = im[i] = 0; + for (i = 0; i < p; i++) + km[i] = 0; + order_km = 0; + + for (index_coeff_list = 0; 1; + index_coeff_list++) { /* travers coeff_list, i.e. create all j with |j| = + d. */ + ptr = NULL; + for (order_im = 1; order_im <= d; + order_im++) { /* travers all orders from 1 to d for i */ + im[p - 1] = 0; + im[0] = order_im; + while (1) { /* create all i with order order_im. */ + sum = 0; + binomiZ = 1; + for (i = 0; i < p; i++) /* check, whether i valid. */ + if ((jm[i] > 0) && (im[i] == 0)) + break; + if (i == p) + while (1) { /* create all k where 0= 0; i--) + if (km[i] < im[i]) { + km[i]++; + order_km++; + binomiZ *= im[i] - km[i] + + 1; /* for (i over k)/(i over k-1) = (i-k+1)/k */ + binomiZ /= km[i]; + break; + } else { + /* binomiZ doesn't change, for (i over k) = 1 if k=0 and also if + * k=i */ + order_km -= km[i]; + km[i] = 0; + }; + if (i == -1) + break; + + sum += summand(p, d, jm, km, order_im, order_km, binomiZ); + }; + + if (fabs(sum) > 0) { /* Store coefficient */ + if (ptr == NULL) + ptr = &coeff_list[index_coeff_list]; + else { + ptr->next = (struct item *)malloc(sizeof(struct item)); + ptr = ptr->next; + }; + + address = 0; /* calculate address for ptr->a */ + j = d - order_im + 1; + for (u = 0; u < p; u++) /* It is sum(binomial(i+k,j+k),k=0..n-1) = */ + if (im[u] != + 0) /* = ((j+n)*binomial(i+n,j+n)-j*binomial(i,j))/(1+i-j) */ + { + i = u + j; + n = im[u]; + address += ((j + n) * binomi(i + n, j + n) - binomi(i, j) * j) / + (1 + i - j); + j += n; }; + ptr->a = address; + ptr->b = order_im; + ptr->c = sum; }; - ptr->next = NULL; /* mark end of queue. */ - - if ((jm[p-1]==d)||(p==1)) break; - for (i=p-2; jm[i]==0; i--); /* find first nonvanishing entry on the right. */ - jm[i]--; - jm[i+1] = jm[p-1]+1; - if (i!=p-2) jm[p-1] = 0; + if ((im[p - 1] == order_im) || (p == 1)) + break; + for (i = p - 2; im[i] == 0; i--) + ; /* find first nonvanishing entry on the right. */ + im[i]--; + im[i + 1] = im[p - 1] + 1; + if (i != p - 2) + im[p - 1] = 0; + }; }; - free((char*) jm); - free((char*) im); - free((char*) km); + ptr->next = NULL; /* mark end of queue. */ + + if ((jm[p - 1] == d) || (p == 1)) + break; + for (i = p - 2; jm[i] == 0; i--) + ; /* find first nonvanishing entry on the right. */ + jm[i]--; + jm[i + 1] = jm[p - 1] + 1; + if (i != p - 2) + jm[p - 1] = 0; + }; + + free((char *)jm); + free((char *)im); + free((char *)km); } - /*--------------------------------------------------------------------------*/ -void convert( int p, int d, int *im, int *multi ) { - int i; - - for (i=0; i max) - max = mymulti[i]; - im[i] = 0; - } - - for (i=0; i max) - max = mymulti[j]; - } +int tensor_address(int d, int *multi) { + int i, j, max, ind; + int add = 0; + int *im = (int *)malloc(d * sizeof(int)); + int *mymulti = (int *)malloc(d * sizeof(int)); + + max = 0; + ind = d - 1; + for (i = 0; i < d; i++) { + mymulti[i] = multi[i]; + if (mymulti[i] > max) + max = mymulti[i]; + im[i] = 0; + } + + for (i = 0; i < d; i++) { + if (mymulti[i] == max) { + im[ind] = mymulti[i]; + mymulti[i] = 0; + max = 0; + ind -= 1; + for (j = 0; j < d; j++) + if (mymulti[j] > max) + max = mymulti[j]; } + } - for (i=0; iv) { - v=fabs(J[RI[i]][CI[j]]); - rIdx=i; - cIdx=j; - } - if (ZERO > v) { - fprintf(DIAG_OUT, - "Error:LUFactorisation(..): no Pivot in step %d (%E)\n",k+1,v); - return -(k+1); - } - /* row and column change resp. */ - if (rIdx > k) { - h=RI[k]; - RI[k]=RI[rIdx]; - RI[rIdx]=h; - } - if (cIdx > k) { - h=CI[k]; - CI[k]=CI[cIdx]; - CI[cIdx]=h; - } - /* Factorisation step */ - for (i=k+1; i v) { + v = fabs(J[RI[i]][CI[j]]); + rIdx = i; + cIdx = j; } + if (ZERO > v) { + fprintf(DIAG_OUT, "Error:LUFactorisation(..): no Pivot in step %d (%E)\n", + k + 1, v); + return -(k + 1); } - return k; -} - -/*--------------------------------------------------------------------------*/ -void GauszSolve( double** J, int n, int* RI, int* CI, double* b ) { - double* tmpZ; - int i,j; - - tmpZ = myalloc1(n); - for (i=0; i k) { + h = RI[k]; + RI[k] = RI[rIdx]; + RI[rIdx] = h; + } + if (cIdx > k) { + h = CI[k]; + CI[k] = CI[cIdx]; + CI[cIdx] = h; } - for (i=n-1; i>=0; i--) { - b[CI[i]]=tmpZ[i]; - for (j=i+1; j= 0; i--) { + b[CI[i]] = tmpZ[i]; + for (j = i + 1; j < n; j++) + b[CI[i]] -= J[RI[i]][CI[j]] * b[CI[j]]; + b[CI[i]] /= J[RI[i]][CI[i]]; + } + myfree1(tmpZ); +} /****************************************************************************/ -int jac_solv( unsigned short tag, int n, const double* x, double* b, unsigned short mode ) { - double *y; - int i, newX = 0; - int rc = 3; - TapeInfos* tapeInfos; - - tapeInfos = getTapeInfos(tag); - y = myalloc1(n); - if (n != tapeInfos->pTapeInfos.jacSolv_nax) { - if (tapeInfos->pTapeInfos.jacSolv_nax) { - free(tapeInfos->pTapeInfos.jacSolv_ci); - free(tapeInfos->pTapeInfos.jacSolv_ri); - myfree1(tapeInfos->pTapeInfos.jacSolv_xold); - myfreeI2(tapeInfos->pTapeInfos.jacSolv_nax, - tapeInfos->pTapeInfos.jacSolv_I); - myfree2(tapeInfos->pTapeInfos.jacSolv_J); - } - tapeInfos->pTapeInfos.jacSolv_J = myalloc2(n,n); - tapeInfos->pTapeInfos.jacSolv_I = myallocI2(n); - tapeInfos->pTapeInfos.jacSolv_xold = myalloc1(n); - tapeInfos->pTapeInfos.jacSolv_ri = - (int*)malloc(n*sizeof(int)); - tapeInfos->pTapeInfos.jacSolv_ci = - (int*)malloc(n*sizeof(int)); - - tapeInfos->pTapeInfos.jacSolv_modeold = 0; - tapeInfos->pTapeInfos.jacSolv_nax = n; +int jac_solv(unsigned short tag, int n, const double *x, double *b, + unsigned short mode) { + double *y; + int i, newX = 0; + int rc = 3; + TapeInfos *tapeInfos; + + tapeInfos = getTapeInfos(tag); + y = myalloc1(n); + if (n != tapeInfos->pTapeInfos.jacSolv_nax) { + if (tapeInfos->pTapeInfos.jacSolv_nax) { + free(tapeInfos->pTapeInfos.jacSolv_ci); + free(tapeInfos->pTapeInfos.jacSolv_ri); + myfree1(tapeInfos->pTapeInfos.jacSolv_xold); + myfreeI2(tapeInfos->pTapeInfos.jacSolv_nax, + tapeInfos->pTapeInfos.jacSolv_I); + myfree2(tapeInfos->pTapeInfos.jacSolv_J); } - for (i = 0; i < n; ++i) - if (x[i] != tapeInfos->pTapeInfos.jacSolv_xold[i]) { - tapeInfos->pTapeInfos.jacSolv_xold[i] = x[i]; - newX = 1; - } - switch(mode) { - case 0: - MINDEC(rc,zos_forward(tag, n, n, 1, x, y)); - MINDEC(rc,fov_reverse(tag, n, n, n, - tapeInfos->pTapeInfos.jacSolv_I, - tapeInfos->pTapeInfos.jacSolv_J)); - break; - case 1: - MINDEC(rc,zos_forward(tag, n, n, 1, x, y)); - MINDEC(rc,fov_reverse(tag, n, n, n, - tapeInfos->pTapeInfos.jacSolv_I, - tapeInfos->pTapeInfos.jacSolv_J)); - if (LUFactorization( - tapeInfos->pTapeInfos.jacSolv_J, n, + tapeInfos->pTapeInfos.jacSolv_J = myalloc2(n, n); + tapeInfos->pTapeInfos.jacSolv_I = myallocI2(n); + tapeInfos->pTapeInfos.jacSolv_xold = myalloc1(n); + tapeInfos->pTapeInfos.jacSolv_ri = (int *)malloc(n * sizeof(int)); + tapeInfos->pTapeInfos.jacSolv_ci = (int *)malloc(n * sizeof(int)); + + tapeInfos->pTapeInfos.jacSolv_modeold = 0; + tapeInfos->pTapeInfos.jacSolv_nax = n; + } + for (i = 0; i < n; ++i) + if (x[i] != tapeInfos->pTapeInfos.jacSolv_xold[i]) { + tapeInfos->pTapeInfos.jacSolv_xold[i] = x[i]; + newX = 1; + } + switch (mode) { + case 0: + MINDEC(rc, zos_forward(tag, n, n, 1, x, y)); + MINDEC(rc, fov_reverse(tag, n, n, n, tapeInfos->pTapeInfos.jacSolv_I, + tapeInfos->pTapeInfos.jacSolv_J)); + break; + case 1: + MINDEC(rc, zos_forward(tag, n, n, 1, x, y)); + MINDEC(rc, fov_reverse(tag, n, n, n, tapeInfos->pTapeInfos.jacSolv_I, + tapeInfos->pTapeInfos.jacSolv_J)); + if (LUFactorization(tapeInfos->pTapeInfos.jacSolv_J, n, tapeInfos->pTapeInfos.jacSolv_ri, - tapeInfos->pTapeInfos.jacSolv_ci) < 0) - { - rc = -3; - break; - } - tapeInfos->pTapeInfos.jacSolv_modeold = 1; - break; - case 2: - if ((tapeInfos->pTapeInfos.jacSolv_modeold < 1) || - (newX == 1)) - { - MINDEC(rc,zos_forward(tag, n, n, 1, x, y)); - MINDEC(rc,fov_reverse(tag, n, n, n, - tapeInfos->pTapeInfos.jacSolv_I, - tapeInfos->pTapeInfos.jacSolv_J)); - if (LUFactorization( - tapeInfos->pTapeInfos.jacSolv_J, n, - tapeInfos->pTapeInfos.jacSolv_ri, - tapeInfos->pTapeInfos.jacSolv_ci) < 0) - { - rc = -3; - break; - } - } - GauszSolve(tapeInfos->pTapeInfos.jacSolv_J, n, - tapeInfos->pTapeInfos.jacSolv_ri, - tapeInfos->pTapeInfos.jacSolv_ci, b); - tapeInfos->pTapeInfos.jacSolv_modeold = 2; - break; + tapeInfos->pTapeInfos.jacSolv_ci) < 0) { + rc = -3; + break; + } + tapeInfos->pTapeInfos.jacSolv_modeold = 1; + break; + case 2: + if ((tapeInfos->pTapeInfos.jacSolv_modeold < 1) || (newX == 1)) { + MINDEC(rc, zos_forward(tag, n, n, 1, x, y)); + MINDEC(rc, fov_reverse(tag, n, n, n, tapeInfos->pTapeInfos.jacSolv_I, + tapeInfos->pTapeInfos.jacSolv_J)); + if (LUFactorization(tapeInfos->pTapeInfos.jacSolv_J, n, + tapeInfos->pTapeInfos.jacSolv_ri, + tapeInfos->pTapeInfos.jacSolv_ci) < 0) { + rc = -3; + break; + } } - myfree1(y); - return rc; + GauszSolve(tapeInfos->pTapeInfos.jacSolv_J, n, + tapeInfos->pTapeInfos.jacSolv_ri, + tapeInfos->pTapeInfos.jacSolv_ci, b); + tapeInfos->pTapeInfos.jacSolv_modeold = 2; + break; + } + myfree1(y); + return rc; } - /****************************************************************************/ -int inverse_Taylor_prop( short tag, int n, int d, - double** Y, double** X ) { - int i,j,l,q; - static double **I; - register double bi; - static double** Xhelp; - static double** W; - static double* xold; - static double ***A; - static double *w; - static int *dd; - static double *b; - static int nax,dax,bd,cgd; - static short **nonzero; - short* nz; - double* Aij; - double* Xj; - int ii, di, da, Di, indexA, indexX; - int rc = 3; - - /* Re/Allocation Stuff */ - if ((n != nax) || (d != dax)) - { - if (nax) - { - myfree3(A); - myfree2(I); - myfree2(W); - myfree2(Xhelp); - myfree1(w); - free(xold); - free(*nonzero); - free(nonzero); - free(dd); - free(b); - } - A = myalloc3(n,n,d+1); - I = myalloc2(n,n); - W = myalloc2(n,d); - Xhelp = myalloc2(n,d); - w = myalloc1(n); - dd = (int*)malloc((d+1)*sizeof(int)); - b = (double*)malloc(n*sizeof(double)); - xold = (double*)malloc(n*sizeof(double)); - nonzero = (short**)malloc(n*sizeof(short*)); - nz = (short*)malloc(n*n*sizeof(short)); - for (i=0; i 1) - dd[i+1] = (int)ceil(dd[i]*0.5); - bd = i+1; +int inverse_Taylor_prop(short tag, int n, int d, double **Y, double **X) { + int i, j, l, q; + static double **I; + register double bi; + static double **Xhelp; + static double **W; + static double *xold; + static double ***A; + static double *w; + static int *dd; + static double *b; + static int nax, dax, bd, cgd; + static short **nonzero; + short *nz; + double *Aij; + double *Xj; + int ii, di, da, Di, indexA, indexX; + int rc = 3; + + /* Re/Allocation Stuff */ + if ((n != nax) || (d != dax)) { + if (nax) { + myfree3(A); + myfree2(I); + myfree2(W); + myfree2(Xhelp); + myfree1(w); + free(xold); + free(*nonzero); + free(nonzero); + free(dd); + free(b); } - if (cgd == 0) - for (i=0; i 0) { - di = dd[ii-1]-1; - Di = dd[ii-1]-dd[ii]-1; - MINDEC(rc,hos_forward(tag,n,n,di,Di+1,xold,Xhelp,w,W)); - MINDEC(rc,hov_reverse(tag,n,n,Di,n,I,A,nonzero)); - da = dd[ii]; - for (l=da; l1) { - Aij = A[i][j]; - indexA = l-1; - Xj = X[j]+l; - indexX = 1; - if (da == l-1) - { - bi += (*(++Aij))*(*(--Xj)); - } - else - { - for (q=da; q 1) + dd[i + 1] = (int)ceil(dd[i] * 0.5); + bd = i + 1; + } + if (cgd == 0) + for (i = 0; i < n; i++) + if (X[i][0] != xold[i]) + cgd = 1; + for (i = 0; i < n; i++) + b[i] = 0; + if (cgd == 1) { + cgd = 0; + for (i = 0; i < n; i++) + xold[i] = X[i][0]; + MINDEC(rc, jac_solv(tag, n, xold, b, 1)); + if (rc == -3) + return -3; + } + ii = bd; + for (i = 0; i < n; i++) { + for (j = 0; j < d; j++) { + Xhelp[i][j] = 0; + X[i][j + 1] = 0; + W[i][j] = 0; + } + for (j = 0; j < n; j++) + for (l = 0; l <= d; l++) + A[i][j][l] = 0; + } + + while (--ii > 0) { + di = dd[ii - 1] - 1; + Di = dd[ii - 1] - dd[ii] - 1; + MINDEC(rc, hos_forward(tag, n, n, di, Di + 1, xold, Xhelp, w, W)); + MINDEC(rc, hov_reverse(tag, n, n, Di, n, I, A, nonzero)); + da = dd[ii]; + for (l = da; l < dd[ii - 1]; l++) { + for (i = 0; i < n; i++) { + if (l == 0) + bi = w[i] - Y[i][0]; + else + bi = W[i][l - 1] - Y[i][l]; + for (j = 0; j < n; j++) + if (nonzero[i][j] > 1) { + Aij = A[i][j]; + indexA = l - 1; + Xj = X[j] + l; + indexX = 1; + if (da == l - 1) { + bi += (*(++Aij)) * (*(--Xj)); + } else { + for (q = da; q < l; q++) { + bi += (*(++Aij)) * (*(--Xj)); + bi += A[i][j][indexA] * X[j][indexX]; + indexA--; + indexX++; + } } - } + } + b[i] = -bi; + } + MINDEC(rc, jac_solv(tag, n, xold, b, 2)); + if (rc == -3) + return -3; + for (i = 0; i < n; i++) { + X[i][l] += b[i]; + Xhelp[i][l - 1] += b[i]; + } } - return rc; + } + return rc; } - /****************************************************************************/ -int inverse_tensor_eval( short tag, int n, int d, int p, - double *x, double **tensor, double** S ) { - static int dim; - static int dold,pold; - static struct item *coeff_list; - int i,j,dimten; - int *it = (int*) malloc(d*sizeof(int)); - double** X; - double** Y; - int *jm; - double *y = (double*) malloc(n*sizeof(double)); - struct item *ptr; - int rc = 3; - - dimten=binomi(p+d,d); - for(i=0;i 0) { - if ((d != dold) || (p != pold)) { - if (pold) { /* olvo 980728 */ - dim = binomi(pold+dold-1,dold); - freecoefflist(dim,coeff_list); - free((char*) coeff_list); - } - dim = binomi(p+d-1,d); - coeff_list = (struct item *) malloc(sizeof(struct item)*dim); - coeff(p,d, coeff_list); - dold = d; - pold = p; - } - jm = (int *)malloc(sizeof(int)*p); - X = myalloc2(n,d+1); - Y = myalloc2(n,d+1); - for (i=0; ia] += X[j][ptr->b]*ptr->c; - ptr = ptr->next; - } while (ptr != NULL); - } - } else { - for (i=0; i=0; j--) - it[j] = it[j] + it[j+1]/(p+1); - for (j=1; j p) it[j] = it[j-1]; - convert(p,d,it,jm); - multma2vec1(n,p,d,Y,S,jm); /* Store S*jm in Y */ - MINDEC(rc,inverse_Taylor_prop(tag,n,d,Y,X)); - if (rc == -3) - return -3; - ptr = &coeff_list[i]; - do { - for(j=0;ja] += X[j][ptr->b]*ptr->c; - } - ptr = ptr->next; - } while (ptr != NULL); - } - } - free((char*) jm); - myfree2(X); - myfree2(Y); +int inverse_tensor_eval(short tag, int n, int d, int p, double *x, + double **tensor, double **S) { + static int dim; + static int dold, pold; + static struct item *coeff_list; + int i, j, dimten; + int *it = (int *)malloc(d * sizeof(int)); + double **X; + double **Y; + int *jm; + double *y = (double *)malloc(n * sizeof(double)); + struct item *ptr; + int rc = 3; + + dimten = binomi(p + d, d); + for (i = 0; i < n; i++) + for (j = 0; j < dimten; j++) + tensor[i][j] = 0; + MINDEC(rc, zos_forward(tag, n, n, 0, x, y)); + if (d > 0) { + if ((d != dold) || (p != pold)) { + if (pold) { /* olvo 980728 */ + dim = binomi(pold + dold - 1, dold); + freecoefflist(dim, coeff_list); + free((char *)coeff_list); + } + dim = binomi(p + d - 1, d); + coeff_list = (struct item *)malloc(sizeof(struct item) * dim); + coeff(p, d, coeff_list); + dold = d; + pold = p; + } + jm = (int *)malloc(sizeof(int) * p); + X = myalloc2(n, d + 1); + Y = myalloc2(n, d + 1); + for (i = 0; i < n; i++) { + X[i][0] = x[i]; + Y[i][0] = y[i]; + for (j = 1; j < d; j++) { + X[i][j] = 0; + Y[i][j] = 0; + } } - for(i=0;ia] += X[j][ptr->b] * ptr->c; + ptr = ptr->next; + } while (ptr != NULL); + } + } else { + for (i = 0; i < d - 1; i++) + it[i] = 1; + it[d - 1] = 0; + for (i = 0; i < dim; i++) /* sum over all multiindices jm with |jm| = d */ + { + it[d - 1] = it[d - 1] + 1; + for (j = d - 2; j >= 0; j--) + it[j] = it[j] + it[j + 1] / (p + 1); + for (j = 1; j < d; j++) + if (it[j] > p) + it[j] = it[j - 1]; + convert(p, d, it, jm); + multma2vec1(n, p, d, Y, S, jm); /* Store S*jm in Y */ + MINDEC(rc, inverse_Taylor_prop(tag, n, d, Y, X)); + if (rc == -3) + return -3; + ptr = &coeff_list[i]; + do { + for (j = 0; j < n; j++) { + tensor[j][ptr->a] += X[j][ptr->b] * ptr->c; + } + ptr = ptr->next; + } while (ptr != NULL); + } + } + free((char *)jm); + myfree2(X); + myfree2(Y); + } + for (i = 0; i < n; i++) + tensor[i][0] = x[i]; + free((char *)y); + free((char *)it); + return rc; } - /****************************************************************************/ -int tensor_eval( short tag, int m, int n, int d, int p, - double* x, double **tensor, double **S ) { - static int bd,dim; - static int dold,pold; - static struct item *coeff_list; - int i,j,k,dimten,ctr; - int **jm, jmbd=0; - int *it = (int*) malloc(d*sizeof(int)); - double *y = (double*) malloc(m*sizeof(double)); - double*** X; - double*** Y; - struct item *ptr[10]; - int rc = 3; - - dimten=binomi(p+d,d); - for (i=0; ia] += Y[0][j][k] * ptr[k]->c; + } + ptr[k] = ptr[k]->next; + } while (ptr[k] != NULL); + if (dim - i <= bd) + bd = dim - i - 1; + ctr = 0; } - jmbd = bd; - jm = (int **) malloc(jmbd*sizeof(int*)); - for (i=0; ia] += Y[0][j][k]*ptr[k]->c; - } - ptr[k] = ptr[k]->next; - } while (ptr[k] != NULL); - if (dim-i <= bd) - bd = dim-i-1; - ctr = 0; - } - } - } else { - X = myalloc3(n,bd,d); - Y = myalloc3(m,bd,d); - ctr = 0; - for (i=0; i=0; j--) - it[j] = it[j] + it[j+1]/(p+1); - for (j=1; j p) - it[j] = it[j-1]; - convert(p,d,it,jm[ctr]); - ptr[ctr] = &coeff_list[i]; - if (ctr < bd-1) - ctr += 1; - else { - multma3vec2(n,p,d,bd,X,S,jm); - MINDEC(rc,hov_forward(tag,m,n,d,bd,x,X,y,Y)); - for (k=0; ka] += Y[j][k][ptr[k]->b-1]*ptr[k]->c; - ptr[k] = ptr[k]->next; - } while (ptr[k] != NULL); - if (dim-i <= bd) - bd = dim-i-1; - ctr = 0; - } - } + } + } else { + X = myalloc3(n, bd, d); + Y = myalloc3(m, bd, d); + ctr = 0; + for (i = 0; i < d - 1; i++) + it[i] = 1; + it[d - 1] = 0; + for (i = 0; i < dim; i++) /* sum over all multiindices jm with |jm| = d */ + { + it[d - 1] = it[d - 1] + 1; + for (j = d - 2; j >= 0; j--) + it[j] = it[j] + it[j + 1] / (p + 1); + for (j = 1; j < d; j++) + if (it[j] > p) + it[j] = it[j - 1]; + convert(p, d, it, jm[ctr]); + ptr[ctr] = &coeff_list[i]; + if (ctr < bd - 1) + ctr += 1; + else { + multma3vec2(n, p, d, bd, X, S, jm); + MINDEC(rc, hov_forward(tag, m, n, d, bd, x, X, y, Y)); + for (k = 0; k < bd; k++) + do { + for (j = 0; j < m; j++) + tensor[j][ptr[k]->a] += Y[j][k][ptr[k]->b - 1] * ptr[k]->c; + ptr[k] = ptr[k]->next; + } while (ptr[k] != NULL); + if (dim - i <= bd) + bd = dim - i - 1; + ctr = 0; } - - for (i=0; i max) - max = multi[i]; - im[i] = 0; - } - for (i=0; i max) - max = multi[j]; - } +void tensor_value(int d, int m, double *y, double **tensor, int *multi) { + int i, j, max, ind, add; + int *im = (int *)malloc(d * sizeof(int)); + + max = 0; + ind = d - 1; + for (i = 0; i < d; i++) { + if (multi[i] > max) + max = multi[i]; + im[i] = 0; + } + for (i = 0; i < d; i++) { + if (multi[i] == max) /* olvo 980728 == instead of = */ + { + im[ind] = multi[i]; + multi[i] = 0; + max = 0; + ind -= 1; + for (j = 0; j < d; j++) + if (multi[j] > max) + max = multi[j]; } - add = tensor_address(d,im); - for (i=0; i /*--------------------------------------------------------------------------*/ -#endif +#endif // ADOLC_DVLPARMS_H diff --git a/ADOL-C/src/externfcts.cpp b/ADOL-C/src/externfcts.cpp index 044fcddc2..bd2de55c3 100644 --- a/ADOL-C/src/externfcts.cpp +++ b/ADOL-C/src/externfcts.cpp @@ -3,241 +3,246 @@ File: externfcts.cpp Revision: $Id$ Contents: functions and data types for extern (differentiated) functions. - + Copyright (c) Andreas Kowarz, Jean Utke - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#include "taping_p.h" -#include +#include "buffer_temp.h" #include "externfcts_p.h" -#include -#include #include "oplate.h" -#include "buffer_temp.h" +#include "taping_p.h" +#include +#include +#include #include /****************************************************************************/ /* extern differentiated functions stuff */ -#define ADOLC_BUFFER_TYPE \ - Buffer< ext_diff_fct, EDFCTS_BLOCK_SIZE > +#define ADOLC_BUFFER_TYPE Buffer static ADOLC_BUFFER_TYPE buffer(edf_zero); void edf_zero(ext_diff_fct *edf) { // sanity settings - edf->function=0; - edf->function_iArr=0; - - edf->zos_forward=0; - edf->zos_forward_iArr=0; - - edf->fos_forward=0; - edf->fos_forward_iArr=0; - edf->hos_forward=0; - edf->hos_forward_iArr=0; - edf->fov_forward=0; - edf->fov_forward_iArr=0; - edf->hov_forward=0; - edf->hov_forward_iArr=0; - - edf->fos_reverse=0; - edf->fos_reverse_iArr=0; - edf->hos_reverse=0; - edf->hos_reverse_iArr=0; - edf->fov_reverse=0; - edf->fov_reverse_iArr=0; - edf->hov_reverse=0; - edf->hov_reverse_iArr=0; - - edf->dp_x=0; - edf->dp_X=0; - edf->dpp_X=0; - edf->dppp_X=0; - edf->dp_y=0; - edf->dp_Y=0; - edf->dpp_Y=0; - edf->dppp_Y=0; - - edf->dp_U=0; - edf->dpp_U=0; - edf->dp_Z=0; - edf->dpp_Z=0; - edf->dppp_Z=0; - - edf->spp_nz=0; - - edf->max_n=0; - edf->max_m=0; - - edf->nestedAdolc=true; - edf->dp_x_changes=true; - edf->dp_y_priorRequired=true; + edf->function = 0; + edf->function_iArr = 0; + + edf->zos_forward = 0; + edf->zos_forward_iArr = 0; + + edf->fos_forward = 0; + edf->fos_forward_iArr = 0; + edf->hos_forward = 0; + edf->hos_forward_iArr = 0; + edf->fov_forward = 0; + edf->fov_forward_iArr = 0; + edf->hov_forward = 0; + edf->hov_forward_iArr = 0; + + edf->fos_reverse = 0; + edf->fos_reverse_iArr = 0; + edf->hos_reverse = 0; + edf->hos_reverse_iArr = 0; + edf->fov_reverse = 0; + edf->fov_reverse_iArr = 0; + edf->hov_reverse = 0; + edf->hov_reverse_iArr = 0; + + edf->dp_x = 0; + edf->dp_X = 0; + edf->dpp_X = 0; + edf->dppp_X = 0; + edf->dp_y = 0; + edf->dp_Y = 0; + edf->dpp_Y = 0; + edf->dppp_Y = 0; + + edf->dp_U = 0; + edf->dpp_U = 0; + edf->dp_Z = 0; + edf->dpp_Z = 0; + edf->dppp_Z = 0; + + edf->spp_nz = 0; + + edf->max_n = 0; + edf->max_m = 0; + + edf->nestedAdolc = true; + edf->dp_x_changes = true; + edf->dp_y_priorRequired = true; if (edf->allmem != NULL) - free(edf->allmem); - edf->allmem=NULL; - edf->user_allocated_mem=0; + free(edf->allmem); + edf->allmem = NULL; + edf->user_allocated_mem = 0; } ext_diff_fct *reg_ext_fct(ADOLC_ext_fct ext_fct) { // this call sets edf->index: - ext_diff_fct * edf=buffer.append(); - edf->function=ext_fct; + ext_diff_fct *edf = buffer.append(); + edf->function = ext_fct; return edf; } ext_diff_fct *reg_ext_fct(ADOLC_ext_fct_iArr ext_fct) { // this call sets edf->index: - ext_diff_fct * edf=buffer.append(); - edf->function_iArr=ext_fct; + ext_diff_fct *edf = buffer.append(); + edf->function_iArr = ext_fct; return edf; } /* * The externfcts.h had a comment previously that said the following: **** - * The user has to preallocate the variables and set the pointers for any of the call back functions - * that will be called during trace interpretation. - * The dimensions given below correspond to the formal arguments in the call back funtions signatures above. - * If the dimensions n and m change between multiple calls to the same external function, then the variables - * have to be preallocation with the maximum of the respective dimension values. - * The dp_x and dp_y pointers have to be valid during both, the tracing phase and the trace interpretation; - * all the other pointers are required to be valid only for the trace interpretation. + * The user has to preallocate the variables and set the pointers for any of the + *call back functions that will be called during trace interpretation. The + *dimensions given below correspond to the formal arguments in the call back + *funtions signatures above. If the dimensions n and m change between multiple + *calls to the same external function, then the variables have to be + *preallocation with the maximum of the respective dimension values. The dp_x + *and dp_y pointers have to be valid during both, the tracing phase and the + *trace interpretation; all the other pointers are required to be valid only for + *the trace interpretation. **** * Doing this now internally saves the user from doing it, as well as updating * when using multiple problem sizes. */ static void update_ext_fct_memory(ext_diff_fct *edfct, int n, int m) { - if (edfct->max_nmax_mallmem != NULL) free(edfct->allmem); - edfct->allmem = (char*)malloc(totalmem); - memset(edfct->allmem,0,totalmem); - edfct->dp_x = (double*)edfct->allmem; - edfct->dp_y = edfct->dp_x+n; - edfct->dp_X = edfct->dp_y+m; - edfct->dp_Y = edfct->dp_X+n; - edfct->dp_U = edfct->dp_Y+m; - edfct->dp_Z = edfct->dp_U+m; - tmp = (char*)(edfct->dp_Z+n); - edfct->dpp_X = (double**)tmp; - edfct->dpp_Y = edfct->dpp_X + n; - edfct->dpp_U = edfct->dpp_Y + m; - edfct->dpp_Z = edfct->dpp_U + m; - /* - tmp = populate_dpp(&edfct->dpp_X, tmp, n,n); - tmp = populate_dpp(&edfct->dpp_Y, tmp, m,n); - tmp = populate_dpp(&edfct->dpp_U, tmp, m,m); - tmp = populate_dpp(&edfct->dpp_Z, tmp, m,n); - */ + if (edfct->max_n < n || edfct->max_m < m) { + /* We need memory stored in the edfct dp_x[n], dp_X[n], dp_Z[n], + * dp_y[m], dp_Y[m], dp_U[m], dpp_X[n][n], dpp_Y[m][n], + * dpp_U[m][m], dpp_Z[m][n]. We have no implementation for higher order + * so leave it out. + */ + size_t totalmem = (3 * n + 3 * m /*+ n*n + 2*n*m + m*m*/) * sizeof(double) + + (3 * m + n) * sizeof(double *); + char *tmp; + if (edfct->allmem != NULL) + free(edfct->allmem); + edfct->allmem = (char *)malloc(totalmem); + memset(edfct->allmem, 0, totalmem); + edfct->dp_x = (double *)edfct->allmem; + edfct->dp_y = edfct->dp_x + n; + edfct->dp_X = edfct->dp_y + m; + edfct->dp_Y = edfct->dp_X + n; + edfct->dp_U = edfct->dp_Y + m; + edfct->dp_Z = edfct->dp_U + m; + tmp = (char *)(edfct->dp_Z + n); + edfct->dpp_X = (double **)tmp; + edfct->dpp_Y = edfct->dpp_X + n; + edfct->dpp_U = edfct->dpp_Y + m; + edfct->dpp_Z = edfct->dpp_U + m; + /* + tmp = populate_dpp(&edfct->dpp_X, tmp, n,n); + tmp = populate_dpp(&edfct->dpp_Y, tmp, m,n); + tmp = populate_dpp(&edfct->dpp_U, tmp, m,m); + tmp = populate_dpp(&edfct->dpp_Z, tmp, m,n); + */ } - edfct->max_n=(edfct->max_nmax_n; - edfct->max_m=(edfct->max_mmax_m; - + edfct->max_n = (edfct->max_n < n) ? n : edfct->max_n; + edfct->max_m = (edfct->max_m < m) ? m : edfct->max_m; } -void call_ext_fct_commonPrior(ext_diff_fct *edfct, - int n, adouble *xa, - int m, adouble *ya, - int &numVals, - double *&vals, +void call_ext_fct_commonPrior(ext_diff_fct *edfct, int n, adouble *xa, int m, + adouble *ya, int &numVals, double *&vals, int &oldTraceFlag) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (xa[n-1].loc()-xa[0].loc()!=(unsigned)n-1 || ya[m-1].loc()-ya[0].loc()!=(unsigned)m-1) fail(ADOLC_EXT_DIFF_LOCATIONGAP); - if (edfct==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_STRUCT); + if (xa[n - 1].loc() - xa[0].loc() != (unsigned)n - 1 || + ya[m - 1].loc() - ya[0].loc() != (unsigned)m - 1) + fail(ADOLC_EXT_DIFF_LOCATIONGAP); + if (edfct == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_STRUCT); if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { ADOLC_PUT_LOCINT(edfct->index); ADOLC_PUT_LOCINT(n); ADOLC_PUT_LOCINT(m); ADOLC_PUT_LOCINT(xa[0].loc()); ADOLC_PUT_LOCINT(ya[0].loc()); - ADOLC_PUT_LOCINT(0); /* keep space for checkpointing index */ - oldTraceFlag=ADOLC_CURRENT_TAPE_INFOS.traceFlag; - ADOLC_CURRENT_TAPE_INFOS.traceFlag=0; - } - else oldTraceFlag=0; + ADOLC_PUT_LOCINT(0); /* keep space for checkpointing index */ + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + } else + oldTraceFlag = 0; if (edfct->nestedAdolc) { numVals = ADOLC_GLOBAL_TAPE_VARS.storeSize; vals = new double[numVals]; - memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store, - numVals * sizeof(double)); + memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store, numVals * sizeof(double)); } if (!edfct->user_allocated_mem) - update_ext_fct_memory(edfct,n,m); + update_ext_fct_memory(edfct, n, m); /* update taylor buffer if keep != 0 ; possible double counting as in * adouble.cpp => correction in taping.c */ if (oldTraceFlag != 0) { - if (edfct->dp_x_changes) ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += n; - if (edfct->dp_y_priorRequired) ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += m; + if (edfct->dp_x_changes) + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += n; + if (edfct->dp_y_priorRequired) + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += m; if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) { - if (edfct->dp_x_changes) for (int i=0; idp_y_priorRequired) for (int i=0; idp_x_changes) + for (int i = 0; i < n; ++i) + ADOLC_WRITE_SCAYLOR(xa[i].getValue()); + if (edfct->dp_y_priorRequired) + for (int i = 0; i < m; ++i) + ADOLC_WRITE_SCAYLOR(ya[i].getValue()); } } - for (int i=0; idp_x[i]=xa[i].getValue(); - if (edfct->dp_y_priorRequired) for (int i=0; idp_y[i]=ya[i].getValue(); + for (int i = 0; i < n; ++i) + edfct->dp_x[i] = xa[i].getValue(); + if (edfct->dp_y_priorRequired) + for (int i = 0; i < m; ++i) + edfct->dp_y[i] = ya[i].getValue(); ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = edfct->index; } -void call_ext_fct_commonPost(ext_diff_fct *edfct, - int n, adouble *xa, - int m, adouble *ya, - int &numVals, - double *&vals, - int &oldTraceFlag) { +void call_ext_fct_commonPost(ext_diff_fct *edfct, int n, adouble *xa, int m, + adouble *ya, int &numVals, double *&vals, + int &oldTraceFlag) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; if (edfct->nestedAdolc) { - memcpy(ADOLC_GLOBAL_TAPE_VARS.store, vals, - numVals * sizeof(double)); + memcpy(ADOLC_GLOBAL_TAPE_VARS.store, vals, numVals * sizeof(double)); delete[] vals; - vals=0; + vals = 0; } /* write back */ - if (edfct->dp_x_changes) for (int i=0; idp_x[i]); - for (int i=0; idp_y[i]); - ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag; + if (edfct->dp_x_changes) + for (int i = 0; i < n; ++i) + xa[i].setValue(edfct->dp_x[i]); + for (int i = 0; i < m; ++i) + ya[i].setValue(edfct->dp_y[i]); + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; } -int call_ext_fct(ext_diff_fct *edfct, - int n, adouble *xa, - int m, adouble *ya) { +int call_ext_fct(ext_diff_fct *edfct, int n, adouble *xa, int m, adouble *ya) { int ret; int numVals = 0; double *vals = NULL; int oldTraceFlag; ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) put_op(ext_diff); - call_ext_fct_commonPrior (edfct,n,xa,m,ya,numVals,vals,oldTraceFlag); - ret=edfct->function(n, edfct->dp_x, m, edfct->dp_y); - call_ext_fct_commonPost (edfct,n,xa,m,ya,numVals,vals,oldTraceFlag); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) + put_op(ext_diff); + call_ext_fct_commonPrior(edfct, n, xa, m, ya, numVals, vals, oldTraceFlag); + ret = edfct->function(n, edfct->dp_x, m, edfct->dp_y); + call_ext_fct_commonPost(edfct, n, xa, m, ya, numVals, vals, oldTraceFlag); return ret; } -int call_ext_fct(ext_diff_fct *edfct, - int iArrLength, int *iArr, - int n, adouble *xa, - int m, adouble *ya) { +int call_ext_fct(ext_diff_fct *edfct, int iArrLength, int *iArr, int n, + adouble *xa, int m, adouble *ya) { int ret; int numVals = 0; double *vals = NULL; @@ -245,171 +250,188 @@ int call_ext_fct(ext_diff_fct *edfct, ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op_reserve(ext_diff_iArr,iArrLength+2); + put_op_reserve(ext_diff_iArr, iArrLength + 2); ADOLC_PUT_LOCINT(iArrLength); - for (int i=0; ifunction_iArr(iArrLength, iArr, n, edfct->dp_x, m, edfct->dp_y); - call_ext_fct_commonPost (edfct,n,xa,m,ya,numVals,vals,oldTraceFlag); + call_ext_fct_commonPrior(edfct, n, xa, m, ya, numVals, vals, oldTraceFlag); + ret = edfct->function_iArr(iArrLength, iArr, n, edfct->dp_x, m, edfct->dp_y); + call_ext_fct_commonPost(edfct, n, xa, m, ya, numVals, vals, oldTraceFlag); return ret; } -ext_diff_fct *get_ext_diff_fct( int index ) { - return buffer.getElement(index); -} +ext_diff_fct *get_ext_diff_fct(int index) { return buffer.getElement(index); } -static int edfoo_wrapper_function(int n, double *x, int m, double* y) { - ext_diff_fct* edf; - EDFobject* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->function(n,x,m,y); +static int edfoo_wrapper_function(int n, double *x, int m, double *y) { + ext_diff_fct *edf; + EDFobject *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->function(n, x, m, y); } -static int edfoo_wrapper_zos_forward(int n, double *x, int m, double* y) { - ext_diff_fct* edf; - EDFobject* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->zos_forward(n,x,m,y); +static int edfoo_wrapper_zos_forward(int n, double *x, int m, double *y) { + ext_diff_fct *edf; + EDFobject *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->zos_forward(n, x, m, y); } -static int edfoo_wrapper_fos_forward(int n, double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y) { - ext_diff_fct* edf; - EDFobject* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fos_forward(n,dp_x,dp_X,m,dp_y,dp_Y); +static int edfoo_wrapper_fos_forward(int n, double *dp_x, double *dp_X, int m, + double *dp_y, double *dp_Y) { + ext_diff_fct *edf; + EDFobject *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fos_forward(n, dp_x, dp_X, m, dp_y, dp_Y); } -static int edfoo_wrapper_fov_forward(int n, double *dp_x, int p, double **dpp_X, int m, double *dp_y, double **dpp_Y) { - ext_diff_fct* edf; - EDFobject* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fov_forward(n,dp_x,p,dpp_X,m,dp_y,dpp_Y); +static int edfoo_wrapper_fov_forward(int n, double *dp_x, int p, double **dpp_X, + int m, double *dp_y, double **dpp_Y) { + ext_diff_fct *edf; + EDFobject *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fov_forward(n, dp_x, p, dpp_X, m, dp_y, dpp_Y); } -static int edfoo_wrapper_fos_reverse(int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y) { - ext_diff_fct* edf; - EDFobject* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fos_reverse(m,dp_U,n,dp_Z,dp_x,dp_y); +static int edfoo_wrapper_fos_reverse(int m, double *dp_U, int n, double *dp_Z, + double *dp_x, double *dp_y) { + ext_diff_fct *edf; + EDFobject *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fos_reverse(m, dp_U, n, dp_Z, dp_x, dp_y); } -static int edfoo_wrapper_fov_reverse(int m, int p, double **dpp_U, int n, double **dpp_Z, double *dp_x, double *dp_y) { - ext_diff_fct* edf; - EDFobject* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fov_reverse(m,p,dpp_U,n,dpp_Z,dp_x,dp_y); +static int edfoo_wrapper_fov_reverse(int m, int p, double **dpp_U, int n, + double **dpp_Z, double *dp_x, + double *dp_y) { + ext_diff_fct *edf; + EDFobject *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fov_reverse(m, p, dpp_U, n, dpp_Z, dp_x, dp_y); } -void EDFobject::init_edf(EDFobject* ebase) { - edf = buffer.append(); - edf->obj = reinterpret_cast(ebase); - edf->function = edfoo_wrapper_function; - edf->zos_forward = edfoo_wrapper_zos_forward; - edf->fos_forward = edfoo_wrapper_fos_forward; - edf->fov_forward = edfoo_wrapper_fov_forward; - edf->fos_reverse = edfoo_wrapper_fos_reverse; - edf->fov_reverse = edfoo_wrapper_fov_reverse; +void EDFobject::init_edf(EDFobject *ebase) { + edf = buffer.append(); + edf->obj = reinterpret_cast(ebase); + edf->function = edfoo_wrapper_function; + edf->zos_forward = edfoo_wrapper_zos_forward; + edf->fos_forward = edfoo_wrapper_fos_forward; + edf->fov_forward = edfoo_wrapper_fov_forward; + edf->fos_reverse = edfoo_wrapper_fos_reverse; + edf->fov_reverse = edfoo_wrapper_fov_reverse; } -static int edfoo_iarr_wrapper_function(int iArrLength, int *iArr, int n, double *x, int m, double* y) { - ext_diff_fct* edf; - EDFobject_iArr* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->function(iArrLength,iArr,n,x,m,y); +static int edfoo_iarr_wrapper_function(int iArrLength, int *iArr, int n, + double *x, int m, double *y) { + ext_diff_fct *edf; + EDFobject_iArr *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->function(iArrLength, iArr, n, x, m, y); } -static int edfoo_iarr_wrapper_zos_forward(int iArrLength, int *iArr, int n, double *x, int m, double* y) { - ext_diff_fct* edf; - EDFobject_iArr* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->zos_forward(iArrLength,iArr,n,x,m,y); +static int edfoo_iarr_wrapper_zos_forward(int iArrLength, int *iArr, int n, + double *x, int m, double *y) { + ext_diff_fct *edf; + EDFobject_iArr *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->zos_forward(iArrLength, iArr, n, x, m, y); } -static int edfoo_iarr_wrapper_fos_forward(int iArrLength, int *iArr, int n, double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y) { - ext_diff_fct* edf; - EDFobject_iArr* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fos_forward(iArrLength,iArr,n,dp_x,dp_X,m,dp_y,dp_Y); +static int edfoo_iarr_wrapper_fos_forward(int iArrLength, int *iArr, int n, + double *dp_x, double *dp_X, int m, + double *dp_y, double *dp_Y) { + ext_diff_fct *edf; + EDFobject_iArr *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fos_forward(iArrLength, iArr, n, dp_x, dp_X, m, dp_y, dp_Y); } -static int edfoo_iarr_wrapper_fov_forward(int iArrLength, int *iArr, int n, double *dp_x, int p, double **dpp_X, int m, double *dp_y, double **dpp_Y) { - ext_diff_fct* edf; - EDFobject_iArr* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fov_forward(iArrLength,iArr,n,dp_x,p,dpp_X,m,dp_y,dpp_Y); +static int edfoo_iarr_wrapper_fov_forward(int iArrLength, int *iArr, int n, + double *dp_x, int p, double **dpp_X, + int m, double *dp_y, double **dpp_Y) { + ext_diff_fct *edf; + EDFobject_iArr *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fov_forward(iArrLength, iArr, n, dp_x, p, dpp_X, m, dp_y, + dpp_Y); } -static int edfoo_iarr_wrapper_fos_reverse(int iArrLength, int *iArr, int m, double *dp_U, int n, double *dp_Z, double *dp_x, double *dp_y) { - ext_diff_fct* edf; - EDFobject_iArr* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fos_reverse(iArrLength,iArr,m,dp_U,n,dp_Z,dp_x,dp_y); +static int edfoo_iarr_wrapper_fos_reverse(int iArrLength, int *iArr, int m, + double *dp_U, int n, double *dp_Z, + double *dp_x, double *dp_y) { + ext_diff_fct *edf; + EDFobject_iArr *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fos_reverse(iArrLength, iArr, m, dp_U, n, dp_Z, dp_x, dp_y); } -static int edfoo_iarr_wrapper_fov_reverse(int iArrLength, int *iArr, int m, int p, double **dpp_U, int n, double **dpp_Z, double *dp_x, double *dp_y) { - ext_diff_fct* edf; - EDFobject_iArr* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fov_reverse(iArrLength,iArr,m,p,dpp_U,n,dpp_Z,dp_x,dp_y); +static int edfoo_iarr_wrapper_fov_reverse(int iArrLength, int *iArr, int m, + int p, double **dpp_U, int n, + double **dpp_Z, double *dp_x, + double *dp_y) { + ext_diff_fct *edf; + EDFobject_iArr *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fov_reverse(iArrLength, iArr, m, p, dpp_U, n, dpp_Z, dp_x, + dp_y); } -void EDFobject_iArr::init_edf(EDFobject_iArr* ebase) { - edf = buffer.append(); - edf->obj = reinterpret_cast(ebase); - edf->function = edfoo_wrapper_function; - edf->zos_forward_iArr = edfoo_iarr_wrapper_zos_forward; - edf->fos_forward_iArr = edfoo_iarr_wrapper_fos_forward; - edf->fov_forward_iArr = edfoo_iarr_wrapper_fov_forward; - edf->fos_reverse_iArr = edfoo_iarr_wrapper_fos_reverse; - edf->fov_reverse_iArr = edfoo_iarr_wrapper_fov_reverse; +void EDFobject_iArr::init_edf(EDFobject_iArr *ebase) { + edf = buffer.append(); + edf->obj = reinterpret_cast(ebase); + edf->function = edfoo_wrapper_function; + edf->zos_forward_iArr = edfoo_iarr_wrapper_zos_forward; + edf->fos_forward_iArr = edfoo_iarr_wrapper_fos_forward; + edf->fov_forward_iArr = edfoo_iarr_wrapper_fov_forward; + edf->fos_reverse_iArr = edfoo_iarr_wrapper_fos_reverse; + edf->fov_reverse_iArr = edfoo_iarr_wrapper_fov_reverse; } /****************************************************************************/ /* THAT'S ALL */ - diff --git a/ADOL-C/src/externfcts2.cpp b/ADOL-C/src/externfcts2.cpp index 207b0e713..570c032d7 100644 --- a/ADOL-C/src/externfcts2.cpp +++ b/ADOL-C/src/externfcts2.cpp @@ -12,32 +12,31 @@ ----------------------------------------------------------------------------*/ -#include "taping_p.h" -#include +#include "buffer_temp.h" #include "externfcts_p.h" -#include -#include #include "oplate.h" -#include "buffer_temp.h" +#include "taping_p.h" +#include +#include +#include #include /****************************************************************************/ /* extern differentiated functions stuff */ -#define ADOLC_BUFFER_TYPE \ - Buffer< ext_diff_fct_v2, EDFCTS_BLOCK_SIZE > +#define ADOLC_BUFFER_TYPE Buffer static ADOLC_BUFFER_TYPE buffer(edf_zero); void edf_zero(ext_diff_fct_v2 *edf) { // sanity settings - edf->function=0; - edf->zos_forward=0; - edf->fos_forward=0; - edf->fov_forward=0; - edf->fos_reverse=0; - edf->fov_reverse=0; + edf->function = 0; + edf->zos_forward = 0; + edf->fos_forward = 0; + edf->fov_forward = 0; + edf->fos_reverse = 0; + edf->fov_reverse = 0; edf->x = 0; edf->y = 0; edf->xp = 0; @@ -52,224 +51,249 @@ void edf_zero(ext_diff_fct_v2 *edf) { edf->max_nout = 0; edf->max_insz = 0; edf->max_outsz = 0; - edf->nestedAdolc=false; - edf->dp_x_changes=true; - edf->dp_y_priorRequired=true; + edf->nestedAdolc = false; + edf->dp_x_changes = true; + edf->dp_y_priorRequired = true; edf->context = NULL; if (edf->allmem != NULL) - free(edf->allmem); - edf->allmem=NULL; - edf->user_allocated_mem=0; + free(edf->allmem); + edf->allmem = NULL; + edf->user_allocated_mem = 0; } ext_diff_fct_v2 *reg_ext_fct(ADOLC_ext_fct_v2 *ext_fct) { - ext_diff_fct_v2 *edf = buffer.append(); - edf->function = ext_fct; - return edf; + ext_diff_fct_v2 *edf = buffer.append(); + edf->function = ext_fct; + return edf; } -static void update_ext_fct_memory(ext_diff_fct_v2 *edfct, int nin, int nout, int *insz, int *outsz) { - int m_isz=0, m_osz=0; - int i,j; - for(i=0;imax_ninmax_noutmax_inszmax_outszallmem != NULL) free(edfct->allmem); - edfct->allmem=(char*)malloc(totalmem); - memset(edfct->allmem,0,totalmem); - tmp = edfct->allmem; - tmp = populate_dpp(&edfct->x,tmp,nin,m_isz); - tmp = populate_dpp(&edfct->y,tmp,nout,m_osz); - tmp = populate_dpp(&edfct->xp,tmp,nin,m_isz); - tmp = populate_dpp(&edfct->yp,tmp,nout,m_osz); - tmp = populate_dpp(&edfct->up,tmp,nout,m_osz); - tmp = populate_dpp(&edfct->zp,tmp,nin,m_isz); - tmp = populate_dppp_nodata(&edfct->Xp,tmp,nin,m_isz); - tmp = populate_dppp_nodata(&edfct->Yp,tmp,nout,m_osz); - tmp = populate_dppp_nodata(&edfct->Up,tmp,nout,m_osz); - tmp = populate_dppp_nodata(&edfct->Zp,tmp,nin,m_isz); - } - edfct->max_nin=(edfct->max_ninmax_nin; - edfct->max_nout=(edfct->max_noutmax_nout; - edfct->max_insz=(edfct->max_inszmax_insz; - edfct->max_outsz=(edfct->max_outszmax_outsz; +static void update_ext_fct_memory(ext_diff_fct_v2 *edfct, int nin, int nout, + int *insz, int *outsz) { + int m_isz = 0, m_osz = 0; + int i, j; + for (i = 0; i < nin; i++) + m_isz = (m_isz < insz[i]) ? insz[i] : m_isz; + for (i = 0; i < nout; i++) + m_osz = (m_osz < outsz[i]) ? outsz[i] : m_osz; + if (edfct->max_nin < nin || edfct->max_nout < nout || + edfct->max_insz < m_isz || edfct->max_outsz < m_osz) { + char *tmp; + size_t p = nin * m_isz, q = nout * m_osz; + size_t totalmem = + (3 * nin * m_isz + 3 * nout * m_osz + // + nin*m_isz*p + nout*m_osz*p + // + q*nout*m_osz + q*nin*m_isz + ) * sizeof(double) + + (3 * nin + 3 * nout + nin * m_isz + nout * m_osz + q * nout + q * nin) * + sizeof(double *) + + (nin + nout + 2 * q) * sizeof(double **); + if (edfct->allmem != NULL) + free(edfct->allmem); + edfct->allmem = (char *)malloc(totalmem); + memset(edfct->allmem, 0, totalmem); + tmp = edfct->allmem; + tmp = populate_dpp(&edfct->x, tmp, nin, m_isz); + tmp = populate_dpp(&edfct->y, tmp, nout, m_osz); + tmp = populate_dpp(&edfct->xp, tmp, nin, m_isz); + tmp = populate_dpp(&edfct->yp, tmp, nout, m_osz); + tmp = populate_dpp(&edfct->up, tmp, nout, m_osz); + tmp = populate_dpp(&edfct->zp, tmp, nin, m_isz); + tmp = populate_dppp_nodata(&edfct->Xp, tmp, nin, m_isz); + tmp = populate_dppp_nodata(&edfct->Yp, tmp, nout, m_osz); + tmp = populate_dppp_nodata(&edfct->Up, tmp, nout, m_osz); + tmp = populate_dppp_nodata(&edfct->Zp, tmp, nin, m_isz); + } + edfct->max_nin = (edfct->max_nin < nin) ? nin : edfct->max_nin; + edfct->max_nout = (edfct->max_nout < nout) ? nout : edfct->max_nout; + edfct->max_insz = (edfct->max_insz < m_isz) ? m_isz : edfct->max_insz; + edfct->max_outsz = (edfct->max_outsz < m_osz) ? m_osz : edfct->max_outsz; } -int call_ext_fct(ext_diff_fct_v2 *edfct, - int iArrLen, int* iArr, - int nin, int nout, - int *insz, adouble **x, - int *outsz, adouble **y) { - int ret; - int oldTraceFlag; - int i,j; size_t numVals; - double *vals; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op_reserve(ext_diff_v2, 2*(nin+nout)+iArrLen); - ADOLC_PUT_LOCINT(edfct->index); - ADOLC_PUT_LOCINT(iArrLen); - for(i=0;inestedAdolc) { - numVals = ADOLC_GLOBAL_TAPE_VARS.storeSize; - vals = new double[numVals]; - memcpy(vals,ADOLC_GLOBAL_TAPE_VARS.store, numVals*sizeof(double)); +int call_ext_fct(ext_diff_fct_v2 *edfct, int iArrLen, int *iArr, int nin, + int nout, int *insz, adouble **x, int *outsz, adouble **y) { + int ret; + int oldTraceFlag; + int i, j; + size_t numVals; + double *vals; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op_reserve(ext_diff_v2, 2 * (nin + nout) + iArrLen); + ADOLC_PUT_LOCINT(edfct->index); + ADOLC_PUT_LOCINT(iArrLen); + for (i = 0; i < iArrLen; i++) + ADOLC_PUT_LOCINT(iArr[i]); + ADOLC_PUT_LOCINT(iArrLen); + ADOLC_PUT_LOCINT(nin); + ADOLC_PUT_LOCINT(nout); + for (i = 0; i < nin; i++) { + if (x[i][insz[i] - 1].loc() - x[i][0].loc() != (unsigned)insz[i] - 1) + fail(ADOLC_EXT_DIFF_LOCATIONGAP); + ADOLC_PUT_LOCINT(insz[i]); + ADOLC_PUT_LOCINT(x[i][0].loc()); } - if (!edfct->user_allocated_mem) - update_ext_fct_memory(edfct,nin,nout,insz,outsz); - if (oldTraceFlag != 0) { - if (edfct->dp_x_changes) - for(i=0;idp_y_priorRequired) - for(i=0;idp_x_changes) - for(i=0;idp_y_priorRequired) - for(i=0;inestedAdolc) { + numVals = ADOLC_GLOBAL_TAPE_VARS.storeSize; + vals = new double[numVals]; + memcpy(vals, ADOLC_GLOBAL_TAPE_VARS.store, numVals * sizeof(double)); + } + if (!edfct->user_allocated_mem) + update_ext_fct_memory(edfct, nin, nout, insz, outsz); + if (oldTraceFlag != 0) { + if (edfct->dp_x_changes) + for (i = 0; i < nin; i++) + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += insz[i]; + if (edfct->dp_y_priorRequired) + for (i = 0; i < nout; i++) + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += outsz[i]; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) { + if (edfct->dp_x_changes) + for (i = 0; i < nin; i++) + for (j = 0; j < insz[i]; j++) + ADOLC_WRITE_SCAYLOR(x[i][j].getValue()); + if (edfct->dp_y_priorRequired) + for (i = 0; i < nout; i++) + for (j = 0; j < outsz[i]; j++) + ADOLC_WRITE_SCAYLOR(y[i][j].getValue()); } + } - for(i=0;ix[i][j] = x[i][j].getValue(); + for (i = 0; i < nin; i++) + for (j = 0; j < insz[i]; j++) + edfct->x[i][j] = x[i][j].getValue(); - if (edfct->dp_y_priorRequired) - for(i=0;iy[i][j] = y[i][j].getValue(); + if (edfct->dp_y_priorRequired) + for (i = 0; i < nout; i++) + for (j = 0; j < outsz[i]; j++) + edfct->y[i][j] = y[i][j].getValue(); - ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = edfct->index; - ret=edfct->function(iArrLen,iArr,nin,nout,insz,edfct->x,outsz,edfct->y,edfct->context); + ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = edfct->index; + ret = edfct->function(iArrLen, iArr, nin, nout, insz, edfct->x, outsz, + edfct->y, edfct->context); - if (edfct->nestedAdolc) { - memcpy(ADOLC_GLOBAL_TAPE_VARS.store, vals, numVals*sizeof(double)); - delete[] vals; - vals = NULL; - } - if (edfct->dp_x_changes) - for(i=0;ix[i][j]); + if (edfct->nestedAdolc) { + memcpy(ADOLC_GLOBAL_TAPE_VARS.store, vals, numVals * sizeof(double)); + delete[] vals; + vals = NULL; + } + if (edfct->dp_x_changes) + for (i = 0; i < nin; i++) + for (j = 0; j < insz[i]; j++) + x[i][j].setValue(edfct->x[i][j]); - for(i=0;iy[i][j]); + for (i = 0; i < nout; i++) + for (j = 0; j < outsz[i]; j++) + y[i][j].setValue(edfct->y[i][j]); - ADOLC_CURRENT_TAPE_INFOS.traceFlag=oldTraceFlag; - return ret; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; + return ret; } -ext_diff_fct_v2 *get_ext_diff_fct_v2( int index ) { - return buffer.getElement(index); +ext_diff_fct_v2 *get_ext_diff_fct_v2(int index) { + return buffer.getElement(index); } -static int edfoo_v2_wrapper_function(int iArrLen, int *iArr, int nin, int nout, int *insz, double **x, int *outsz, double **y, void* ctx) { - ext_diff_fct_v2* edf; - EDFobject_v2* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->function(iArrLen,iArr,nin,nout,insz,x,outsz,y,ctx); +static int edfoo_v2_wrapper_function(int iArrLen, int *iArr, int nin, int nout, + int *insz, double **x, int *outsz, + double **y, void *ctx) { + ext_diff_fct_v2 *edf; + EDFobject_v2 *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->function(iArrLen, iArr, nin, nout, insz, x, outsz, y, ctx); } -static int edfoo_v2_wrapper_zos_forward(int iArrLen, int *iArr, int nin, int nout, int *insz, double **x, int *outsz, double **y, void* ctx) { - ext_diff_fct_v2* edf; - EDFobject_v2* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->zos_forward(iArrLen,iArr,nin,nout,insz,x,outsz,y,ctx); +static int edfoo_v2_wrapper_zos_forward(int iArrLen, int *iArr, int nin, + int nout, int *insz, double **x, + int *outsz, double **y, void *ctx) { + ext_diff_fct_v2 *edf; + EDFobject_v2 *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->zos_forward(iArrLen, iArr, nin, nout, insz, x, outsz, y, ctx); } -static int edfoo_v2_wrapper_fos_forward(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, double **xp, int *outsz, double **y, double **yp, void *ctx) { - ext_diff_fct_v2* edf; - EDFobject_v2* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fos_forward(iArrLen,iArr,nin,nout,insz,x,xp,outsz,y,yp,ctx); +static int edfoo_v2_wrapper_fos_forward(int iArrLen, int *iArr, int nin, + int nout, int *insz, double **x, + double **xp, int *outsz, double **y, + double **yp, void *ctx) { + ext_diff_fct_v2 *edf; + EDFobject_v2 *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fos_forward(iArrLen, iArr, nin, nout, insz, x, xp, outsz, y, yp, + ctx); } -static int edfoo_v2_wrapper_fov_forward(int iArrLen, int* iArr, int nin, int nout, int *insz, double **x, int ndir, double ***Xp, int *outsz, double **y, double ***Yp, void* ctx) { - ext_diff_fct_v2* edf; - EDFobject_v2* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fov_forward(iArrLen,iArr,nin,nout,insz,x,ndir,Xp,outsz,y,Yp,ctx); +static int edfoo_v2_wrapper_fov_forward(int iArrLen, int *iArr, int nin, + int nout, int *insz, double **x, + int ndir, double ***Xp, int *outsz, + double **y, double ***Yp, void *ctx) { + ext_diff_fct_v2 *edf; + EDFobject_v2 *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fov_forward(iArrLen, iArr, nin, nout, insz, x, ndir, Xp, outsz, + y, Yp, ctx); } -static int edfoo_v2_wrapper_fos_reverse(int iArrLen, int* iArr, int nout, int nin, int *outsz, double **up, int *insz, double **zp, double **x, double **y, void *ctx) { - ext_diff_fct_v2* edf; - EDFobject_v2* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fos_reverse(iArrLen,iArr,nout,nin,outsz,up,insz,zp,x,y,ctx); +static int edfoo_v2_wrapper_fos_reverse(int iArrLen, int *iArr, int nout, + int nin, int *outsz, double **up, + int *insz, double **zp, double **x, + double **y, void *ctx) { + ext_diff_fct_v2 *edf; + EDFobject_v2 *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fos_reverse(iArrLen, iArr, nout, nin, outsz, up, insz, zp, x, y, + ctx); } -static int edfoo_v2_wrapper_fov_reverse(int iArrLen, int* iArr, int nout, int nin, int *outsz, int dir, double ***Up, int *insz, double ***Zp, double **x, double **y, void* ctx) { - ext_diff_fct_v2* edf; - EDFobject_v2* ebase; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - // figure out which edf - edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - ebase = reinterpret_cast(edf->obj); - return ebase->fov_reverse(iArrLen,iArr,nout,nin,outsz,dir,Up,insz,Zp,x,y,ctx); +static int edfoo_v2_wrapper_fov_reverse(int iArrLen, int *iArr, int nout, + int nin, int *outsz, int dir, + double ***Up, int *insz, double ***Zp, + double **x, double **y, void *ctx) { + ext_diff_fct_v2 *edf; + EDFobject_v2 *ebase; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + // figure out which edf + edf = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + ebase = reinterpret_cast(edf->obj); + return ebase->fov_reverse(iArrLen, iArr, nout, nin, outsz, dir, Up, insz, Zp, + x, y, ctx); } -void EDFobject_v2::init_edf(EDFobject_v2* ebase) { - edf = buffer.append(); - edf->obj = reinterpret_cast(ebase); - edf->function = edfoo_v2_wrapper_function; - edf->zos_forward = edfoo_v2_wrapper_zos_forward; - edf->fos_forward = edfoo_v2_wrapper_fos_forward; - edf->fov_forward = edfoo_v2_wrapper_fov_forward; - edf->fos_reverse = edfoo_v2_wrapper_fos_reverse; - edf->fov_reverse = edfoo_v2_wrapper_fov_reverse; +void EDFobject_v2::init_edf(EDFobject_v2 *ebase) { + edf = buffer.append(); + edf->obj = reinterpret_cast(ebase); + edf->function = edfoo_v2_wrapper_function; + edf->zos_forward = edfoo_v2_wrapper_zos_forward; + edf->fos_forward = edfoo_v2_wrapper_fos_forward; + edf->fov_forward = edfoo_v2_wrapper_fov_forward; + edf->fos_reverse = edfoo_v2_wrapper_fos_reverse; + edf->fov_reverse = edfoo_v2_wrapper_fov_reverse; } diff --git a/ADOL-C/src/externfcts_p.h b/ADOL-C/src/externfcts_p.h index 8b82033c6..9922aad94 100644 --- a/ADOL-C/src/externfcts_p.h +++ b/ADOL-C/src/externfcts_p.h @@ -4,27 +4,27 @@ Revision: $Id$ Contents: private functions and data types for extern (differentiated) functions. - + Copyright (c) Andreas Kowarz, Jean Utke - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_EXTERNFCTS_P_H) -#define ADOLC_EXTERNFCTS_P_H 1 + #define ADOLC_EXTERNFCTS_P_H 1 -#include -#include -#include + #include + #include + #include BEGIN_C_DECLS /****************************************************************************/ /* Now the C THINGS */ -#define EDFCTS_BLOCK_SIZE 10 + #define EDFCTS_BLOCK_SIZE 10 ext_diff_fct *get_ext_diff_fct(int index); ext_diff_fct_v2 *get_ext_diff_fct_v2(int index); @@ -34,4 +34,3 @@ END_C_DECLS /****************************************************************************/ #endif /* ADOLC_EXTERNFCTS_P_H */ - diff --git a/ADOL-C/src/fixpoint.cpp b/ADOL-C/src/fixpoint.cpp index 82e2080ea..112d475b3 100644 --- a/ADOL-C/src/fixpoint.cpp +++ b/ADOL-C/src/fixpoint.cpp @@ -5,257 +5,282 @@ Revision: $Id$ Contents: all C functions directly accessing at least one of the four tapes (operations, locations, constants, value stack) - + Copyright (c) Andreas Kowarz, Sebastian Schlenkrich - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ +#include "dvlparms.h" #include "taping_p.h" #include #include -#include "dvlparms.h" #include #include using namespace std; - /*--------------------------------------------------------------------------*/ /* F(x,u,y,dim_x,dim_u) */ /* norm(x,dim_x) */ typedef struct { - locint edf_index; - int sub_tape_num; - int (*double_F)(double*, double* ,double*, int, int); - int (*adouble_F)(adouble*, adouble*, adouble*, int, int); - double (*norm)(double*, int); - double (*norm_deriv)(double*, int); - double epsilon; - double epsilon_deriv; - int N_max; - int N_max_deriv; -} -fpi_data; - + locint edf_index; + int sub_tape_num; + int (*double_F)(double *, double *, double *, int, int); + int (*adouble_F)(adouble *, adouble *, adouble *, int, int); + double (*norm)(double *, int); + double (*norm_deriv)(double *, int); + double epsilon; + double epsilon_deriv; + int N_max; + int N_max_deriv; +} fpi_data; static vector fpi_stack; - -static int iteration ( int dim_xu, double *xu, int dim_x, double *x_fix ) { - int i, k; - double err; - const fpi_data& current = fpi_stack.back(); - for (i=0; iN_max; k++) { - for (i=0; idouble_F)( xu, xu+dim_x, x_fix, dim_x, dim_xu-dim_x ); - for (i=0; inorm)(xu,dim_x); - if (errepsilon) return k; - } - return -1; +static int fp_zos_forward(int dim_xu, double *xu, int dim_x, double *x_fix) { + int i, k; + double err; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint edf_index = ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index; + + // Find fpi_stack element with index 'edf_index'. + auto current = + std::find_if(fpi_stack.begin(), fpi_stack.end(), + [&](auto &&v) { return v.edf_index == edf_index; }); + + if (current == fpi_stack.end()) { + fprintf(stderr, "ADOL-C Error! No edf found for fixpoint iteration.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + + for (i = 0; i < dim_x; i++) + x_fix[i] = xu[i]; + for (k = 1; k <= current->N_max; k++) { + for (i = 0; i < dim_x; i++) + xu[i] = x_fix[i]; + (*current->double_F)(xu, xu + dim_x, x_fix, dim_x, dim_xu - dim_x); + for (i = 0; i < dim_x; i++) + xu[i] = x_fix[i] - xu[i]; + err = (*current->norm)(xu, dim_x); + if (err < current->epsilon) + return k; + } + return -1; } -static int fp_fos_forward ( int dim_xu, double *xu, double *xu_dot, - int dim_x, double *x_fix, double *x_fix_dot) { - // Piggy back - int i, k; - double err, err_deriv; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint edf_index = ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index; - - // Find fpi_stack element with index 'edf_index'. - auto current = std::find_if(fpi_stack.begin(), fpi_stack.end(), [&](auto&& v){return v.edf_index == edf_index;}); - - if (current==fpi_stack.end()) { - fprintf(stderr,"ADOL-C Error! No edf found for fixpoint iteration.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - for (k=1; (kN_max_deriv)|(kN_max); k++) { - for (i=0; isub_tape_num, dim_x, dim_xu, 0, xu, xu_dot, x_fix, x_fix_dot); - for (i=0; inorm)(xu,dim_x); - for (i=0; inorm_deriv)(xu_dot,dim_x); - if ((errepsilon)&&(err_derivepsilon_deriv)) { - return k; - } +static int fp_fos_forward(int dim_xu, double *xu, double *xu_dot, int dim_x, + double *x_fix, double *x_fix_dot) { + // Piggy back + int i, k; + double err, err_deriv; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint edf_index = ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index; + + // Find fpi_stack element with index 'edf_index'. + auto current = + std::find_if(fpi_stack.begin(), fpi_stack.end(), + [&](auto &&v) { return v.edf_index == edf_index; }); + + if (current == fpi_stack.end()) { + fprintf(stderr, "ADOL-C Error! No edf found for fixpoint iteration.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + for (k = 1; (k < current->N_max_deriv) | (k < current->N_max); k++) { + for (i = 0; i < dim_x; i++) + xu[i] = x_fix[i]; + for (i = 0; i < dim_x; i++) + xu_dot[i] = x_fix_dot[i]; + fos_forward(current->sub_tape_num, dim_x, dim_xu, 0, xu, xu_dot, x_fix, + x_fix_dot); + for (i = 0; i < dim_x; i++) + xu[i] = x_fix[i] - xu[i]; + err = (*current->norm)(xu, dim_x); + for (i = 0; i < dim_x; i++) + xu_dot[i] = x_fix_dot[i] - xu_dot[i]; + err_deriv = (*current->norm_deriv)(xu_dot, dim_x); + if ((err < current->epsilon) && (err_deriv < current->epsilon_deriv)) { + return k; } - return -1; + } + return -1; } -static int fp_hos_reverse ( int dim_x, double *x_fix_bar, int dim_xu, double *xu_bar, double* /*unused*/, double* /*unused*/) { - // (d x_fix) / (d x_0) = 0 (!) - int i, k; - double err; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint edf_index = ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index; - - // Find fpi_stack element with index 'edf_index'. - auto current = std::find_if(fpi_stack.begin(), fpi_stack.end(), [&](auto&& v){return v.edf_index == edf_index;}); - - if (current==fpi_stack.end()) { - fprintf(stderr,"ADOL-C Error! No edf found for fixpoint iteration.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - double *U = new double[dim_xu]; - double *xi = new double[dim_x]; - - for (k=1; kN_max_deriv; k++) { - for (i=0; isub_tape_num, dim_x, dim_xu, xi, U ); - for (i=0; inorm_deriv)(xi,dim_x); - printf(" fp_fos_reverse: k = %d err = %e\n",k,err); - if (errepsilon_deriv) { - for (i=0; iN_max_deriv; k++) { + for (i = 0; i < dim_x; i++) + xi[i] = U[i]; + fos_reverse(current->sub_tape_num, dim_x, dim_xu, xi, U); + for (i = 0; i < dim_x; i++) + U[i] += x_fix_bar[i]; + for (i = 0; i < dim_x; i++) + xi[i] = U[i] - xi[i]; + err = (*current->norm_deriv)(xi, dim_x); + printf(" fp_fos_reverse: k = %d err = %e\n", k, err); + if (err < current->epsilon_deriv) { + for (i = 0; i < dim_xu - dim_x; i++) { + xu_bar[dim_x + i] += U[dim_x + i]; + } + + delete[] xi; + delete[] U; + return k; } - for (i=0; iN_max_deriv; k++) { - for (i=0; isub_tape_num, dim_x, dim_xu, xi, U ); - for (i=0; inorm_deriv)(xi,dim_x); - printf(" fp_fos_reverse: k = %d err = %e\n",k,err); - if (errepsilon_deriv) { - for (i=0; iN_max_deriv; k++) { + for (i = 0; i < dim_x; i++) + xi[i] = U[i]; + fos_reverse(current->sub_tape_num, dim_x, dim_xu, xi, U); + for (i = 0; i < dim_x; i++) + U[i] += x_fix_bar[i]; + for (i = 0; i < dim_x; i++) + xi[i] = U[i] - xi[i]; + err = (*current->norm_deriv)(xi, dim_x); + printf(" fp_fos_reverse: k = %d err = %e\n", k, err); + if (err < current->epsilon_deriv) { + for (i = 0; i < dim_xu - dim_x; i++) { + xu_bar[dim_x + i] += U[dim_x + i]; + } + + delete[] xi; + delete[] U; + return k; } - for (i=0; izos_forward = &fp_zos_forward; - edf_iteration->fos_forward = &fp_fos_forward; - edf_iteration->fos_reverse = &fp_fos_reverse; - edf_iteration->fos_reverse = &fp_hos_reverse; - - // add new fp information - fpi_data data; - data.sub_tape_num = sub_tape_num; - data.double_F = double_F; - data.adouble_F = adouble_F; - data.norm = norm; - data.norm_deriv = norm_deriv; - data.epsilon = epsilon; - data.epsilon_deriv = epsilon_deriv; - data.N_max = N_max; - data.N_max_deriv = N_max_deriv; - data.edf_index = edf_iteration->index; - fpi_stack.push_back(data); - - // put x and u together - adouble *xu = new adouble[dim_x+dim_u]; - for (i=0; i>= dummy; - trace_off(); - - delete[] xu; - return k; +ADOLC_DLL_EXPORT int +fp_iteration(int sub_tape_num, + int (*double_F)(double *, double *, double *, int, int), + int (*adouble_F)(adouble *, adouble *, adouble *, int, int), + double (*norm)(double *, int), double (*norm_deriv)(double *, int), + double epsilon, double epsilon_deriv, int N_max, int N_max_deriv, + adouble *x_0, adouble *u, adouble *x_fix, int dim_x, int dim_u) { + int i, k; + double dummy; + + // declare extern differentiated function and data + ext_diff_fct *edf_iteration = reg_ext_fct(&iteration); + edf_iteration->zos_forward = &fp_zos_forward; + edf_iteration->fos_forward = &fp_fos_forward; + edf_iteration->fos_reverse = &fp_fos_reverse; + edf_iteration->fos_reverse = &fp_hos_reverse; + + // add new fp information + fpi_data data; + data.sub_tape_num = sub_tape_num; + data.double_F = double_F; + data.adouble_F = adouble_F; + data.norm = norm; + data.norm_deriv = norm_deriv; + data.epsilon = epsilon; + data.epsilon_deriv = epsilon_deriv; + data.N_max = N_max; + data.N_max_deriv = N_max_deriv; + data.edf_index = edf_iteration->index; + fpi_stack.push_back(data); + + // put x and u together + adouble *xu = new adouble[dim_x + dim_u]; + for (i = 0; i < dim_x; i++) + xu[i] = x_0[i]; + for (i = 0; i < dim_u; i++) + xu[dim_x + i] = u[i]; + + k = call_ext_fct(edf_iteration, dim_x + dim_u, xu, dim_x, x_fix); + + // tape near solution + trace_on(sub_tape_num, 1); + for (i = 0; i < dim_x; i++) + xu[i] <<= x_fix[i].getValue(); + for (i = 0; i < dim_u; i++) + xu[dim_x + i] <<= u[i].getValue(); + adouble_F(xu, xu + dim_x, x_fix, dim_x, dim_u); + for (i = 0; i < dim_x; i++) + x_fix[i] >>= dummy; + trace_off(); + + delete[] xu; + return k; } diff --git a/ADOL-C/src/fo_rev.c b/ADOL-C/src/fo_rev.c index 6fd04b068..afa1d9b2c 100644 --- a/ADOL-C/src/fo_rev.c +++ b/ADOL-C/src/fo_rev.c @@ -8,25 +8,25 @@ int_reverse_tight, ( first-order-vector reverse mode for bit patterns, checks all dependences on taylors and real values, - more precize) + more precize) int_reverse_safe, - ( first-order-vector reverse mode for bit patterns, - return always 3, + ( first-order-vector reverse mode for bit patterns, + return always 3, no dependences on taylors and real values, - faster than tight) + faster than tight) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel, Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ /***************************************************************************** - + There are four basic versions of the procedure `reverse', which are optimized for the cases of scalar or vector reverse sweeps with first or higher derivatives, respectively. In the calling @@ -34,27 +34,27 @@ parameters `lagrange' and `results'. The former may be left out and the integer parameters `depen', `indep', `degre', and `nrows' must be set or default according to the following matrix of - calling cases. - + calling cases. + no lagrange double* lagrange double** lagrange - -double* gradient of scalar weight vector times infeasible + +double* gradient of scalar weight vector times infeasible results valued function Jacobian product combination - - ( depen = 1 , ( depen > 0 , - degre = 0 , degre = 0 , ------ - nrows = 1 ) nrows = 1 ) - + + ( depen = 1 , ( depen > 0 , + degre = 0 , degre = 0 , ------ + nrows = 1 ) nrows = 1 ) + double** Jacobian of vector weight vector times weight matrix results valued function Taylor-Jacobians times Jacobian - - ( 0 < depen ( depen > 0 , ( depen > 0 , - = nrows , degre > 0 , degre = 0 , - degre = 0 ) nrows = 1 ) nrows > 0 ) - + + ( 0 < depen ( depen > 0 , ( depen > 0 , + = nrows , degre > 0 , degre = 0 , + degre = 0 ) nrows = 1 ) nrows > 0 ) + double*** full family of ------------ weigth matrix x results Taylor-Jacobians ------------ Taylor Jacobians - + *****************************************************************************/ /****************************************************************************/ @@ -63,145 +63,144 @@ results Taylor-Jacobians ------------ Taylor Jacobians /*--------------------------------------------------------------------------*/ #ifdef _FOS_ -#ifdef _ABS_NORM_ -#define GENERATED_FILENAME "fos_pl_reverse" -#else -#ifdef _ABS_NORM_SIG_ -#define GENERATED_FILENAME "fos_pl_sig_reverse" -#else -#define GENERATED_FILENAME "fos_reverse" -#endif -#endif - -#define RESULTS(l,indexi) results[indexi] -#define LAGRANGE(l,indexd) lagrange[indexd] -#define RESULTSTRANS(l,indexi) results[indexi] -#define LAGRANGETRANS(l,indexd) lagrange[indexd] + #ifdef _ABS_NORM_ + #define GENERATED_FILENAME "fos_pl_reverse" + #else + #ifdef _ABS_NORM_SIG_ + #define GENERATED_FILENAME "fos_pl_sig_reverse" + #else + #define GENERATED_FILENAME "fos_reverse" + #endif + #endif + + #define RESULTS(l, indexi) results[indexi] + #define LAGRANGE(l, indexd) lagrange[indexd] + #define RESULTSTRANS(l, indexi) results[indexi] + #define LAGRANGETRANS(l, indexd) lagrange[indexd] /*--------------------------------------------------------------------------*/ #elif _FOV_ -#define GENERATED_FILENAME "fov_reverse" - -#define _ADOLC_VECTOR_ - -#define RESULTS(l,indexi) results[l][indexi] -#define LAGRANGE(l,indexd) lagrange[l][indexd] -#define RESULTSTRANS(l,indexi) results[indexi][l] -#define LAGRANGETRANS(l,indexd) lagrange[indexd][l] - -#else -#if defined(_INT_REV_) -#if defined(_TIGHT_) -#define GENERATED_FILENAME "int_reverse_t" -#endif -#if defined(_NTIGHT_) -#define GENERATED_FILENAME "int_reverse_s" -#endif -#define RESULTS(l,indexi) results[l][indexi] -#define LAGRANGE(l,indexd) lagrange[l][indexd] -#define RESULTSTRANS(l,indexi) results[indexi][l] -#define LAGRANGETRANS(l,indexd) lagrange[indexd][l] -#else -#error Error ! Define [_FOS_ | _FOV_ | _INT_REV_SAFE_ | _INT_REV_TIGHT_ ] -#endif + #define GENERATED_FILENAME "fov_reverse" + + #define _ADOLC_VECTOR_ + + #define RESULTS(l, indexi) results[l][indexi] + #define LAGRANGE(l, indexd) lagrange[l][indexd] + #define RESULTSTRANS(l, indexi) results[indexi][l] + #define LAGRANGETRANS(l, indexd) lagrange[indexd][l] + +#else + #if defined(_INT_REV_) + #if defined(_TIGHT_) + #define GENERATED_FILENAME "int_reverse_t" + #endif + #if defined(_NTIGHT_) + #define GENERATED_FILENAME "int_reverse_s" + #endif + #define RESULTS(l, indexi) results[l][indexi] + #define LAGRANGE(l, indexd) lagrange[l][indexd] + #define RESULTSTRANS(l, indexi) results[indexi][l] + #define LAGRANGETRANS(l, indexd) lagrange[indexd][l] + #else + #error Error ! Define [_FOS_ | _FOV_ | _INT_REV_SAFE_ | _INT_REV_TIGHT_ ] + #endif #endif /*--------------------------------------------------------------------------*/ /* access to variables */ #ifdef _FOS_ -#define AARG *Aarg -#define AARG1 *Aarg1 -#define AARG2 *Aarg2 - -#define ARES_INC *Ares -#define AARG_INC *Aarg -#define AARG1_INC *Aarg1 -#define AARG2_INC *Aarg2 - -#define ARES_INC_O Ares -#define AARG_INC_O /adAarg -#define AARG1_INC_O Aarg1 -#define AARG2_INC_O Aarg2 - -#define ASSIGN_A(a,b) a = &b; - -#else /* _FOV_ */ -#ifdef _FOV_ -#define AARG *Aarg -#define AARG1 *Aarg1 -#define AARG2 *Aarg2 - -#define ARES_INC *Ares++ -#define AARG_INC *Aarg++ -#define AARG1_INC *Aarg1++ -#define AARG2_INC *Aarg2++ - -#define ARES_INC_O Ares++ -#define AARG_INC_O Aarg++ -#define AARG1_INC_O Aarg1++ -#define AARG2_INC_O Aarg2++ - -#define ASSIGN_A(a,b) a = b; -#else -#ifdef _INT_REV_ -#define AARG *Aarg -#define AARG1 *Aarg1 -#define AARG2 *Aarg2 - -#define ARES_INC *Ares++ -#define AARG_INC *Aarg++ -#define AARG1_INC *Aarg1++ -#define AARG2_INC *Aarg2++ - -#define ARES_INC_O Ares++ -#define AARG_INC_O Aarg++ -#define AARG1_INC_O Aarg1++ -#define AARG2_INC_O Aarg2++ - -#define ASSIGN_A(a,b) a = b; -#endif -#endif -#endif - -#define TRES rp_T[res] -#define TARG rp_T[arg] -#define TARG1 rp_T[arg1] -#define TARG2 rp_T[arg2] + #define AARG *Aarg + #define AARG1 *Aarg1 + #define AARG2 *Aarg2 + + #define ARES_INC *Ares + #define AARG_INC *Aarg + #define AARG1_INC *Aarg1 + #define AARG2_INC *Aarg2 + + #define ARES_INC_O Ares + #define AARG_INC_O / adAarg + #define AARG1_INC_O Aarg1 + #define AARG2_INC_O Aarg2 + + #define ASSIGN_A(a, b) a = &b; + +#else /* _FOV_ */ + #ifdef _FOV_ + #define AARG *Aarg + #define AARG1 *Aarg1 + #define AARG2 *Aarg2 + + #define ARES_INC *Ares++ + #define AARG_INC *Aarg++ + #define AARG1_INC *Aarg1++ + #define AARG2_INC *Aarg2++ + + #define ARES_INC_O Ares++ + #define AARG_INC_O Aarg++ + #define AARG1_INC_O Aarg1++ + #define AARG2_INC_O Aarg2++ + + #define ASSIGN_A(a, b) a = b; + #else + #ifdef _INT_REV_ + #define AARG *Aarg + #define AARG1 *Aarg1 + #define AARG2 *Aarg2 + + #define ARES_INC *Ares++ + #define AARG_INC *Aarg++ + #define AARG1_INC *Aarg1++ + #define AARG2_INC *Aarg2++ + + #define ARES_INC_O Ares++ + #define AARG_INC_O Aarg++ + #define AARG1_INC_O Aarg1++ + #define AARG2_INC_O Aarg2++ + + #define ASSIGN_A(a, b) a = b; + #endif + #endif +#endif + +#define TRES rp_T[res] +#define TARG rp_T[arg] +#define TARG1 rp_T[arg1] +#define TARG2 rp_T[arg2] /*--------------------------------------------------------------------------*/ /* loop stuff */ #ifdef _ADOLC_VECTOR_ -#define FOR_0_LE_l_LT_p for (int l=0; l -#include +#include "dvlparms.h" +#include "externfcts_p.h" #include "oplate.h" #include "taping_p.h" +#include #include -#include "externfcts_p.h" -#include "dvlparms.h" +#include #include #include #ifdef ADOLC_MEDIPACK_SUPPORT -#include "medipacksupport_p.h" + #include "medipacksupport_p.h" #endif #ifdef ADOLC_AMPI_SUPPORT -#include "ampi/ampi.h" -#include "ampi/libCommon/modified.h" + #include "ampi/ampi.h" + #include "ampi/libCommon/modified.h" #endif BEGIN_C_DECLS @@ -210,3181 +209,3084 @@ BEGIN_C_DECLS /* NOW THE CODE */ #ifdef _FOS_ -/****************************************************************************/ -/* First-Order Scalar Reverse Pass. */ -/****************************************************************************/ -#ifdef _ABS_NORM_ + /****************************************************************************/ + /* First-Order Scalar Reverse Pass. */ + /****************************************************************************/ + #ifdef _ABS_NORM_ /****************************************************************************/ /* Abs-Normal extended adjoint row computation. */ /****************************************************************************/ -int fos_pl_reverse(short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int swchk, /* consistency chk on # of switches */ - int rownum, /* required row no. of abs-normal form */ - double *results) /* coefficient vectors */ -#elif defined(_ABS_NORM_SIG_) +int fos_pl_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int swchk, /* consistency chk on # of switches */ + int rownum, /* required row no. of abs-normal form */ + double *results) /* coefficient vectors */ + #elif defined(_ABS_NORM_SIG_) /****************************************************************************/ /* Abs-Normal extended adjoint row computation. */ /****************************************************************************/ -int fos_pl_sig_reverse(short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int swchk, /* consistency chk on # of switches */ - short *siggrad, - double *lagrange, - double *results) /* coefficient vectors */ -#else -int fos_reverse(short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - double *lagrange, - double *results) /* coefficient vectors */ - -#endif +int fos_pl_sig_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int swchk, /* consistency chk on # of switches */ + short *siggrad, double *lagrange, + double *results) /* coefficient vectors */ + #else +int fos_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + double *lagrange, double *results) /* coefficient vectors */ + + #endif #elif _FOV_ /****************************************************************************/ /* First-Order Vector Reverse Pass. */ /****************************************************************************/ -int fov_reverse(short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int nrows, /* # of Jacobian rows being calculated */ - double **lagrange, /* domain weight vector */ - double **results) /* matrix of coefficient vectors */ +int fov_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int nrows, /* # of Jacobian rows being calculated */ + double **lagrange, /* domain weight vector */ + double **results) /* matrix of coefficient vectors */ #elif defined(_INT_REV_) -#if defined(_TIGHT_) + #if defined(_TIGHT_) /****************************************************************************/ /* First Order Vector version of the reverse mode for bit patterns, tight */ /****************************************************************************/ int int_reverse_tight( - short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int nrows, /* # of Jacobian rows being calculated */ - unsigned long int **lagrange,/* domain weight vector[var][row](in)*/ - unsigned long int **results) /* matrix of coeff. vectors[var][row]*/ - -#elif defined(_NTIGHT_) + short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int nrows, /* # of Jacobian rows being calculated */ + unsigned long int **lagrange, /* domain weight vector[var][row](in)*/ + unsigned long int **results) /* matrix of coeff. vectors[var][row]*/ + + #elif defined(_NTIGHT_) /****************************************************************************/ /* First Order Vector version of the reverse mode, bit pattern, safe */ /****************************************************************************/ int int_reverse_safe( - short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int nrows, /* # of Jacobian rows being calculated */ - unsigned long int **lagrange,/* domain weight vector[var][row](in)*/ - unsigned long int **results) /* matrix of coeff. vectors[var][row]*/ -#else -# error Neither _TIGHT_ nor _NTIGHT_ defined -#endif + short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int nrows, /* # of Jacobian rows being calculated */ + unsigned long int **lagrange, /* domain weight vector[var][row](in)*/ + unsigned long int **results) /* matrix of coeff. vectors[var][row]*/ + #else + #error Neither _TIGHT_ nor _NTIGHT_ defined + #endif #endif { - /****************************************************************************/ - /* ALL VARIABLES */ - unsigned char operation; /* operation code */ - int ret_c = 3; /* return value */ + /****************************************************************************/ + /* ALL VARIABLES */ + unsigned char operation; /* operation code */ + int ret_c = 3; /* return value */ - locint size = 0; - locint res = 0; - locint arg = 0; - locint arg1 = 0; - locint arg2 = 0; + locint size = 0; + locint res = 0; + locint arg = 0; + locint arg1 = 0; + locint arg2 = 0; -#if !defined (_NTIGHT_) - double coval = 0; +#if !defined(_NTIGHT_) + double coval = 0; #endif - int indexi = 0, indexd = 0; + int indexi = 0, indexd = 0; #if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) - int switchnum; + int switchnum; #endif - /* loop indices */ - int j, ls; + /* loop indices */ + int j, ls; - /* other necessary variables */ -#if !defined (_NTIGHT_) - double r0, r_0; - int taycheck; - int numdep,numind; + /* other necessary variables */ +#if !defined(_NTIGHT_) + double r0, r_0; + int taycheck; + int numdep, numind; #endif - /*--------------------------------------------------------------------------*/ - /* Adjoint stuff */ + /*--------------------------------------------------------------------------*/ + /* Adjoint stuff */ #ifdef _FOS_ - revreal *rp_A; + revreal *rp_A; #endif #ifdef _FOV_ - revreal **rpp_A, *Aqo; + revreal **rpp_A, *Aqo; #endif #if !defined(_NTIGHT_) - revreal *rp_T; + revreal *rp_T; #endif /* !_NTIGHT_ */ #if !defined _INT_REV_ - revreal *Ares, *Aarg, *Aarg1, *Aarg2; + revreal *Ares, *Aarg, *Aarg1, *Aarg2; #else - unsigned long int **upp_A; - unsigned long int *Ares, *Aarg, *Aarg1, *Aarg2; + unsigned long int **upp_A; + unsigned long int *Ares, *Aarg, *Aarg1, *Aarg2; #endif - /*--------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------*/ #ifdef _ADOLC_VECTOR_ - int p = nrows; + int p = nrows; #endif #ifdef _INT_REV_ - int p = nrows; + int p = nrows; #endif - /****************************************************************************/ - /* extern diff. function variables */ + /****************************************************************************/ + /* extern diff. function variables */ #if defined(_FOS_) -# define ADOLC_EXT_FCT_U edfct->dp_U -# define ADOLC_EXT_FCT_Z edfct->dp_Z -# define ADOLC_EXT_FCT_POINTER fos_reverse -# define ADOLC_EXT_FCT_IARR_POINTER fos_reverse_iArr -# define ADOLC_EXT_FCT_COMPLETE \ - fos_reverse(m, edfct->dp_U, n, edfct->dp_Z, edfct->dp_x, edfct->dp_y) -# define ADOLC_EXT_FCT_IARR_COMPLETE \ - fos_reverse_iArr(iArrLength,iArr, m, edfct->dp_U, n, edfct->dp_Z, edfct->dp_x, edfct->dp_y) -# define ADOLC_EXT_FCT_SAVE_NUMDIRS -# define ADOLC_EXT_FCT_V2_U edfct2->up -# define ADOLC_EXT_FCT_V2_Z edfct2->zp -# define ADOLC_EXT_FCT_V2_COMPLETE \ - fos_reverse(iArrLength,iArr,nout,nin,(int*)outsz,edfct2->up,(int*)insz,edfct2->zp,edfct2->x,edfct2->y,edfct2->context) -#else -# define ADOLC_EXT_FCT_U edfct->dpp_U -# define ADOLC_EXT_FCT_Z edfct->dpp_Z -# define ADOLC_EXT_FCT_POINTER fov_reverse -# define ADOLC_EXT_FCT_IARR_POINTER fov_reverse_iArr -# define ADOLC_EXT_FCT_COMPLETE \ - fov_reverse(m, p, edfct->dpp_U, n, edfct->dpp_Z, edfct->dp_x, edfct->dp_y) -# define ADOLC_EXT_FCT_IARR_COMPLETE \ - fov_reverse_iArr(iArrLength, iArr, m, p, edfct->dpp_U, n, edfct->dpp_Z, edfct->dp_x, edfct->dp_y) -# define ADOLC_EXT_FCT_SAVE_NUMDIRS ADOLC_CURRENT_TAPE_INFOS.numDirs_rev = nrows -# define ADOLC_EXT_FCT_V2_U edfct2->Up -# define ADOLC_EXT_FCT_V2_Z edfct2->Zp -# define ADOLC_EXT_FCT_V2_COMPLETE \ - fov_reverse(iArrLength,iArr,nout,nin,(int*)outsz,p,edfct2->Up,(int*)insz,edfct2->Zp,edfct2->x,edfct2->y, edfct2->context) + #define ADOLC_EXT_FCT_U edfct->dp_U + #define ADOLC_EXT_FCT_Z edfct->dp_Z + #define ADOLC_EXT_FCT_POINTER fos_reverse + #define ADOLC_EXT_FCT_IARR_POINTER fos_reverse_iArr + #define ADOLC_EXT_FCT_COMPLETE \ + fos_reverse(m, edfct->dp_U, n, edfct->dp_Z, edfct->dp_x, edfct->dp_y) + #define ADOLC_EXT_FCT_IARR_COMPLETE \ + fos_reverse_iArr(iArrLength, iArr, m, edfct->dp_U, n, edfct->dp_Z, \ + edfct->dp_x, edfct->dp_y) + #define ADOLC_EXT_FCT_SAVE_NUMDIRS + #define ADOLC_EXT_FCT_V2_U edfct2->up + #define ADOLC_EXT_FCT_V2_Z edfct2->zp + #define ADOLC_EXT_FCT_V2_COMPLETE \ + fos_reverse(iArrLength, iArr, nout, nin, (int *)outsz, edfct2->up, \ + (int *)insz, edfct2->zp, edfct2->x, edfct2->y, \ + edfct2->context) +#else + #define ADOLC_EXT_FCT_U edfct->dpp_U + #define ADOLC_EXT_FCT_Z edfct->dpp_Z + #define ADOLC_EXT_FCT_POINTER fov_reverse + #define ADOLC_EXT_FCT_IARR_POINTER fov_reverse_iArr + #define ADOLC_EXT_FCT_COMPLETE \ + fov_reverse(m, p, edfct->dpp_U, n, edfct->dpp_Z, edfct->dp_x, edfct->dp_y) + #define ADOLC_EXT_FCT_IARR_COMPLETE \ + fov_reverse_iArr(iArrLength, iArr, m, p, edfct->dpp_U, n, edfct->dpp_Z, \ + edfct->dp_x, edfct->dp_y) + #define ADOLC_EXT_FCT_SAVE_NUMDIRS \ + ADOLC_CURRENT_TAPE_INFOS.numDirs_rev = nrows + #define ADOLC_EXT_FCT_V2_U edfct2->Up + #define ADOLC_EXT_FCT_V2_Z edfct2->Zp + #define ADOLC_EXT_FCT_V2_COMPLETE \ + fov_reverse(iArrLength, iArr, nout, nin, (int *)outsz, p, edfct2->Up, \ + (int *)insz, edfct2->Zp, edfct2->x, edfct2->y, \ + edfct2->context) #endif #if !defined(_INT_REV_) - locint n, m; - ext_diff_fct *edfct; - ext_diff_fct_v2 *edfct2; - int iArrLength; - int *iArr; - int loop,oloop; - int ext_retc; - int oldTraceFlag; - locint *insz, *outsz, nin, nout; + locint n, m; + ext_diff_fct *edfct; + ext_diff_fct_v2 *edfct2; + int iArrLength; + int *iArr; + int loop, oloop; + int ext_retc; + int oldTraceFlag; + locint *insz, *outsz, nin, nout; #endif #ifdef ADOLC_AMPI_SUPPORT - MPI_Op op; - void *buf, *rbuf; - int count, rcount; - MPI_Datatype datatype, rtype; - int src; - int tag; - enum AMPI_PairedWith_E pairedWith; - MPI_Comm comm; - MPI_Status* status; - struct AMPI_Request_S request; + MPI_Op op; + void *buf, *rbuf; + int count, rcount; + MPI_Datatype datatype, rtype; + int src; + int tag; + enum AMPI_PairedWith_E pairedWith; + MPI_Comm comm; + MPI_Status *status; + struct AMPI_Request_S request; #endif - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; #if defined(ADOLC_DEBUG) - /****************************************************************************/ - /* DEBUG MESSAGES */ - fprintf(DIAG_OUT,"Call of %s(..) with tag: %d, n: %d, m %d,\n", - GENERATED_FILENAME, tnum, indep, depen); -#ifdef _ADOLC_VECTOR_ - fprintf(DIAG_OUT," p: %d\n\n",nrows); -#endif + /****************************************************************************/ + /* DEBUG MESSAGES */ + fprintf(DIAG_OUT, "Call of %s(..) with tag: %d, n: %d, m %d,\n", + GENERATED_FILENAME, tnum, indep, depen); + #ifdef _ADOLC_VECTOR_ + fprintf(DIAG_OUT, " p: %d\n\n", nrows); + #endif #endif - /****************************************************************************/ - /* INITs */ + /****************************************************************************/ + /* INITs */ - /*------------------------------------------------------------------------*/ - /* Set up stuff for the tape */ + /*------------------------------------------------------------------------*/ + /* Set up stuff for the tape */ - /* Initialize the Reverse Sweep */ - init_rev_sweep(tnum); + /* Initialize the Reverse Sweep */ + init_rev_sweep(tnum); - failAdditionalInfo3 = depen; - failAdditionalInfo4 = indep; - if ( (depen != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS]) || - (indep != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]) ) - fail(ADOLC_REVERSE_COUNTS_MISMATCH); + failAdditionalInfo3 = depen; + failAdditionalInfo4 = indep; + if ((depen != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS]) || + (indep != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS])) + fail(ADOLC_REVERSE_COUNTS_MISMATCH); - indexi = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS] - 1; - indexd = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS] - 1; + indexi = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS] - 1; + indexd = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS] - 1; #if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) - if (! ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX] ) { - fprintf(DIAG_OUT, "ADOL-C error: Tape %d was not created compatible " - "with %s(..)\n Please call enableMinMaxUsingAbs() " - "before trace_on(%d)\n", tnum, GENERATED_FILENAME, tnum); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - else if (swchk != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]) { - fprintf(DIAG_OUT, "ADOL-C error: Number of switches passed %d does not " - "match with the one recorded on tape %d (%zu)\n",swchk,tnum, - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - else - switchnum = swchk - 1; + if (!ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) { + fprintf(DIAG_OUT, + "ADOL-C error: Tape %d was not created compatible " + "with %s(..)\n Please call enableMinMaxUsingAbs() " + "before trace_on(%d)\n", + tnum, GENERATED_FILENAME, tnum); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } else if (swchk != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]) { + fprintf(DIAG_OUT, + "ADOL-C error: Number of switches passed %d does not " + "match with the one recorded on tape %d (%zu)\n", + swchk, tnum, ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } else + switchnum = swchk - 1; #endif - /****************************************************************************/ - /* MEMORY ALLOCATION STUFF */ + /* MEMORY ALLOCATION STUFF + */ /*--------------------------------------------------------------------------*/ -#ifdef _FOS_ /* FOS */ - rp_A = (revreal*) calloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], sizeof(revreal)); - if (rp_A == NULL) fail(ADOLC_MALLOC_FAILED); - ADOLC_CURRENT_TAPE_INFOS.rp_A = rp_A; - rp_T = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * - sizeof(revreal)); - if (rp_T == NULL) fail(ADOLC_MALLOC_FAILED); - ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOS_REVERSE; -#ifdef _ABS_NORM_ - memset(results,0,sizeof(double)*(indep+swchk)); -#endif -# define ADJOINT_BUFFER rp_A -# define ADJOINT_BUFFER_ARG_L rp_A[arg] -# define ADJOINT_BUFFER_RES_L rp_A[res] -# define ADJOINT_BUFFER_ARG rp_A[arg] -# define ADJOINT_BUFFER_RES rp_A[res] -# define ADOLC_EXT_FCT_U_L_LOOP edfct->dp_U[loop] -# define ADOLC_EXT_FCT_Z_L_LOOP edfct->dp_Z[loop] -# define ADOLC_EXT_FCT_V2_U_LOOP edfct2->up[oloop][loop] -# define ADOLC_EXT_FCT_V2_Z_LOOP edfct2->zp[oloop][loop] -# define ADOLC_EXT_FCT_COPY_ADJOINTS(dest,src) dest=src -# define ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(dest,src) src=dest +#ifdef _FOS_ /* FOS */ + rp_A = (revreal *)calloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], + sizeof(revreal)); + if (rp_A == NULL) + fail(ADOLC_MALLOC_FAILED); + ADOLC_CURRENT_TAPE_INFOS.rp_A = rp_A; + rp_T = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * + sizeof(revreal)); + if (rp_T == NULL) + fail(ADOLC_MALLOC_FAILED); + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOS_REVERSE; + #ifdef _ABS_NORM_ + memset(results, 0, sizeof(double) * (indep + swchk)); + #endif + #define ADJOINT_BUFFER rp_A + #define ADJOINT_BUFFER_ARG_L rp_A[arg] + #define ADJOINT_BUFFER_RES_L rp_A[res] + #define ADJOINT_BUFFER_ARG rp_A[arg] + #define ADJOINT_BUFFER_RES rp_A[res] + #define ADOLC_EXT_FCT_U_L_LOOP edfct->dp_U[loop] + #define ADOLC_EXT_FCT_Z_L_LOOP edfct->dp_Z[loop] + #define ADOLC_EXT_FCT_V2_U_LOOP edfct2->up[oloop][loop] + #define ADOLC_EXT_FCT_V2_Z_LOOP edfct2->zp[oloop][loop] + #define ADOLC_EXT_FCT_COPY_ADJOINTS(dest, src) dest = src + #define ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(dest, src) src = dest + + /*--------------------------------------------------------------------------*/ +#else + #if defined _FOV_ /* FOV */ + rpp_A = (revreal **)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * + sizeof(revreal *)); + if (rpp_A == NULL) + fail(ADOLC_MALLOC_FAILED); + Aqo = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * p * + sizeof(revreal)); + if (Aqo == NULL) + fail(ADOLC_MALLOC_FAILED); + for (j = 0; j < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; j++) { + rpp_A[j] = Aqo + j * p; + } + ADOLC_CURRENT_TAPE_INFOS.rpp_A = rpp_A; + rp_T = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * + sizeof(revreal)); + if (rp_T == NULL) + fail(ADOLC_MALLOC_FAILED); + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOV_REVERSE; + #define ADJOINT_BUFFER rpp_A + #define ADJOINT_BUFFER_ARG_L rpp_A[arg][l] + #define ADJOINT_BUFFER_RES_L rpp_A[res][l] + #define ADJOINT_BUFFER_ARG rpp_A[arg] + #define ADJOINT_BUFFER_RES rpp_A[res] + #define ADOLC_EXT_FCT_U_L_LOOP edfct->dpp_U[l][loop] + #define ADOLC_EXT_FCT_Z_L_LOOP edfct->dpp_Z[l][loop] + #define ADOLC_EXT_FCT_V2_U_LOOP edfct2->Up[oloop][loop] + #define ADOLC_EXT_FCT_V2_Z_LOOP edfct2->Zp[oloop][loop] + #define ADOLC_EXT_FCT_COPY_ADJOINTS(dest, src) dest = src + #define ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(dest, src) + #else + #if defined _INT_REV_ + upp_A = myalloc2_ulong(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p); + #if defined _TIGHT_ + ADOLC_CURRENT_TAPE_INFOS.upp_A = upp_A; + rp_T = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * + sizeof(revreal)); + if (rp_T == NULL) + fail(ADOLC_MALLOC_FAILED); + #endif + #define ADJOINT_BUFFER upp_A + #define ADJOINT_BUFFER_ARG_L upp_A[arg][l] + #define ADJOINT_BUFFER_RES_L upp_A[res][l] + #endif + #endif +#endif + + /****************************************************************************/ + /* TAYLOR INITIALIZATION */ + +#if !defined(_NTIGHT_) + + ADOLC_CURRENT_TAPE_INFOS.rp_T = rp_T; + + taylor_back(tnum, &numdep, &numind, &taycheck); + + if (taycheck < 0) { + fprintf(DIAG_OUT, "\n ADOL-C error: reverse fails because it was not" + " preceded\nby a forward sweep with degree>0, keep=1!\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + }; + + if ((numdep != depen) || (numind != indep)) + fail(ADOLC_REVERSE_TAYLOR_COUNTS_MISMATCH); + +#endif /* !_NTIGHT_ */ + + /****************************************************************************/ + /* REVERSE SWEEP */ + operation = get_op_r(); + while (operation != start_of_tape) { /* Switch statement to execute the + operations in Reverse */ + + switch (operation) { + + /****************************************************************************/ + /* MARKERS + */ + + /*--------------------------------------------------------------------------*/ + case end_of_op: /* end_of_op */ + get_op_block_r(); + operation = get_op_r(); + /* Skip next operation, it's another end_of_op */ + break; + + /*--------------------------------------------------------------------------*/ + case end_of_int: /* end_of_int */ + get_loc_block_r(); /* Get the next int block */ + break; + + /*--------------------------------------------------------------------------*/ + case end_of_val: /* end_of_val */ + get_val_block_r(); /* Get the next val block */ + break; + + /*--------------------------------------------------------------------------*/ + case start_of_tape: /* start_of_tape */ + break; + case end_of_tape: /* end_of_tape */ + discard_params_r(); + break; + + /****************************************************************************/ + /* COMPARISON + */ + + /*--------------------------------------------------------------------------*/ + case eq_zero: /* eq_zero */ + arg = get_locint_r(); + +#if !defined(_NTIGHT_) + ret_c = 0; +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case neq_zero: /* neq_zero */ + case gt_zero: /* gt_zero */ + case lt_zero: /* lt_zero */ + arg = get_locint_r(); + break; - /*--------------------------------------------------------------------------*/ -#else -#if defined _FOV_ /* FOV */ - rpp_A = (revreal**)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * - sizeof(revreal*)); - if (rpp_A == NULL) fail(ADOLC_MALLOC_FAILED); - Aqo = (revreal*)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * p * - sizeof(revreal)); - if (Aqo == NULL) fail(ADOLC_MALLOC_FAILED); - for (j=0; jdpp_U[l][loop] -# define ADOLC_EXT_FCT_Z_L_LOOP edfct->dpp_Z[l][loop] -# define ADOLC_EXT_FCT_V2_U_LOOP edfct2->Up[oloop][loop] -# define ADOLC_EXT_FCT_V2_Z_LOOP edfct2->Zp[oloop][loop] -# define ADOLC_EXT_FCT_COPY_ADJOINTS(dest,src) dest=src -# define ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(dest,src) -#else -#if defined _INT_REV_ - upp_A = myalloc2_ulong(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p); -#if defined _TIGHT_ - ADOLC_CURRENT_TAPE_INFOS.upp_A = upp_A; - rp_T = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * - sizeof(revreal)); - if (rp_T == NULL) fail(ADOLC_MALLOC_FAILED); -#endif -# define ADJOINT_BUFFER upp_A -# define ADJOINT_BUFFER_ARG_L upp_A[arg][l] -# define ADJOINT_BUFFER_RES_L upp_A[res][l] -#endif -#endif -#endif - - /****************************************************************************/ - /* TAYLOR INITIALIZATION */ - -#if !defined(_NTIGHT_) - - ADOLC_CURRENT_TAPE_INFOS.rp_T = rp_T; - - taylor_back(tnum, &numdep, &numind, &taycheck); - - if (taycheck < 0) { - fprintf(DIAG_OUT,"\n ADOL-C error: reverse fails because it was not" - " preceded\nby a forward sweep with degree>0, keep=1!\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); - }; - - if((numdep != depen)||(numind != indep)) - fail(ADOLC_REVERSE_TAYLOR_COUNTS_MISMATCH); - -#endif /* !_NTIGHT_ */ - - - /****************************************************************************/ - /* REVERSE SWEEP */ - operation=get_op_r(); - while (operation != start_of_tape) { /* Switch statement to execute the operations in Reverse */ - - switch (operation) { - - - /****************************************************************************/ - /* MARKERS */ - - /*--------------------------------------------------------------------------*/ - case end_of_op: /* end_of_op */ - get_op_block_r(); - operation = get_op_r(); - /* Skip next operation, it's another end_of_op */ - break; - - /*--------------------------------------------------------------------------*/ - case end_of_int: /* end_of_int */ - get_loc_block_r(); /* Get the next int block */ - break; - - /*--------------------------------------------------------------------------*/ - case end_of_val: /* end_of_val */ - get_val_block_r(); /* Get the next val block */ - break; - - /*--------------------------------------------------------------------------*/ - case start_of_tape: /* start_of_tape */ - break; - case end_of_tape: /* end_of_tape */ - discard_params_r(); - break; - - - /****************************************************************************/ - /* COMPARISON */ - - /*--------------------------------------------------------------------------*/ - case eq_zero : /* eq_zero */ - arg = get_locint_r(); - -#if !defined(_NTIGHT_) - ret_c = 0; -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case neq_zero : /* neq_zero */ - case gt_zero : /* gt_zero */ - case lt_zero : /* lt_zero */ - arg = get_locint_r(); - break; - - /*--------------------------------------------------------------------------*/ - case ge_zero : /* ge_zero */ - case le_zero : /* le_zero */ - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case ge_zero: /* ge_zero */ + case le_zero: /* le_zero */ + arg = get_locint_r(); #if !defined(_NTIGHT_) - if (TARG == 0) - ret_c = 0; + if (TARG == 0) + ret_c = 0; #endif /* !_NTIGHT_ */ - break; - + break; - /****************************************************************************/ - /* ASSIGNMENTS */ + /****************************************************************************/ + /* ASSIGNMENTS + */ - /*--------------------------------------------------------------------------*/ - case assign_a: /* assign an adouble variable an assign_a */ - /* adouble value. (=) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case assign_a: /* assign an adouble variable an assign_a */ + /* adouble value. (=) */ + res = get_locint_r(); + arg = get_locint_r(); - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - AARG_INC |= *Ares; - ARES_INC = 0; + FOR_0_LE_l_LT_p { +#if defined(_INT_REV_) + AARG_INC |= *Ares; + ARES_INC = 0; #else - AARG_INC += *Ares; - ARES_INC = 0.0; + AARG_INC += *Ares; + ARES_INC = 0.0; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case assign_d: /* assign an adouble variable a assign_d */ - /* double value. (=) */ - res = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case assign_d: /* assign an adouble variable a assign_d */ + /* double value. (=) */ + res = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - ARES_INC = 0; + FOR_0_LE_l_LT_p +#if defined(_INT_REV_) + ARES_INC = 0; #else - ARES_INC = 0.0; + ARES_INC = 0.0; #endif #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case neg_sign_p: - case recipr_p: - case assign_p: /* assign an adouble variable a assign_d */ - /* double value. (=) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case neg_sign_p: + case recipr_p: + case assign_p: /* assign an adouble variable a assign_d */ + /* double value. (=) */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - ARES_INC = 0; + FOR_0_LE_l_LT_p +#if defined(_INT_REV_) + ARES_INC = 0; #else - ARES_INC = 0.0; + ARES_INC = 0.0; #endif #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; - /*--------------------------------------------------------------------------*/ - case assign_d_zero: /* assign an adouble variable a assign_d_zero */ - case assign_d_one: /* double value (0 or 1). (=) assign_d_one */ - res = get_locint_r(); + break; + /*--------------------------------------------------------------------------*/ + case assign_d_zero: /* assign an adouble variable a assign_d_zero */ + case assign_d_one: /* double value (0 or 1). (=) assign_d_one */ + res = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - ARES_INC = 0; + FOR_0_LE_l_LT_p +#if defined(_INT_REV_) + ARES_INC = 0; #else - ARES_INC = 0.0; + ARES_INC = 0.0; #endif #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case assign_ind: /* assign an adouble variable an assign_ind */ - /* independent double value (<<=) */ - res = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case assign_ind: /* assign an adouble variable an assign_ind */ + /* independent double value (<<=) */ + res = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - if (ADOLC_CURRENT_TAPE_INFOS.in_nested_ctx) { - FOR_0_LE_l_LT_p - RESULTSTRANS(l,indexi) += ARES_INC; - } else { - FOR_0_LE_l_LT_p - RESULTS(l,indexi) = ARES_INC; - } + if (ADOLC_CURRENT_TAPE_INFOS.in_nested_ctx) { + FOR_0_LE_l_LT_p RESULTSTRANS(l, indexi) += ARES_INC; + } else { + FOR_0_LE_l_LT_p RESULTS(l, indexi) = ARES_INC; + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - indexi--; - break; + indexi--; + break; - /*--------------------------------------------------------------------------*/ - case assign_dep: /* assign a float variable a assign_dep */ - /* dependent adouble value. (>>=) */ - res = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case assign_dep: /* assign a float variable a assign_dep */ + /* dependent adouble value. (>>=) */ + res = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) #if defined(_ABS_NORM_) - if (indexd + swchk == rownum) - *Ares = 1.0; - else - *Ares = 0.0; + if (indexd + swchk == rownum) + *Ares = 1.0; + else + *Ares = 0.0; #else - if (ADOLC_CURRENT_TAPE_INFOS.in_nested_ctx) { - FOR_0_LE_l_LT_p { - ARES_INC = LAGRANGETRANS(l,indexd); - LAGRANGETRANS(l,indexd) = 0.0; - } - } else { - FOR_0_LE_l_LT_p - ARES_INC = LAGRANGE(l,indexd); - } + if (ADOLC_CURRENT_TAPE_INFOS.in_nested_ctx) { + FOR_0_LE_l_LT_p { + ARES_INC = LAGRANGETRANS(l, indexd); + LAGRANGETRANS(l, indexd) = 0.0; + } + } else { + FOR_0_LE_l_LT_p ARES_INC = LAGRANGE(l, indexd); + } #endif - indexd--; - break; - + indexd--; + break; - /****************************************************************************/ - /* OPERATION + ASSIGNMENT */ + /****************************************************************************/ + /* OPERATION + + * ASSIGNMENT */ - /*--------------------------------------------------------------------------*/ - case eq_plus_d: /* Add a floating point to an eq_plus_d */ - /* adouble. (+=) */ - res = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_plus_d: /* Add a floating point to an eq_plus_d */ + /* adouble. (+=) */ + res = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_plus_p: /* Add a floating point to an eq_plus_d */ - /* adouble. (+=) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_plus_p: /* Add a floating point to an eq_plus_d */ + /* adouble. (+=) */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_plus_a: /* Add an adouble to another eq_plus_a */ - /* adouble. (+=) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_plus_a: /* Add an adouble to another eq_plus_a */ + /* adouble. (+=) */ + res = get_locint_r(); + arg = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]); + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]); - FOR_0_LE_l_LT_p + FOR_0_LE_l_LT_p #if defined(_INT_REV_) - AARG_INC |= ARES_INC; + AARG_INC |= ARES_INC; #else - AARG_INC += ARES_INC; + AARG_INC += ARES_INC; #endif #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_min_d: /* Subtract a floating point from an eq_min_d */ - /* adouble. (-=) */ - res = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_min_d: /* Subtract a floating point from an eq_min_d */ + /* adouble. (-=) */ + res = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_min_p: /* Subtract a floating point from an eq_min_d */ - /* adouble. (-=) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_min_p: /* Subtract a floating point from an eq_min_d */ + /* adouble. (-=) */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_min_a: /* Subtract an adouble from another eq_min_a */ - /* adouble. (-=) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_min_a: /* Subtract an adouble from another eq_min_a */ + /* adouble. (-=) */ + res = get_locint_r(); + arg = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p + FOR_0_LE_l_LT_p #if defined(_INT_REV_) - AARG_INC |= ARES_INC; + AARG_INC |= ARES_INC; #else - AARG_INC -= ARES_INC; + AARG_INC -= ARES_INC; #endif #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_mult_d: /* Multiply an adouble by a eq_mult_d */ - /* flaoting point. (*=) */ - res = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_mult_d: /* Multiply an adouble by a eq_mult_d */ + /* flaoting point. (*=) */ + res = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); #endif /* !_NTIGHT_ */ -#if!defined(_INT_REV_) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) +#if !defined(_INT_REV_) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - ARES_INC *= coval; + FOR_0_LE_l_LT_p ARES_INC *= coval; #endif #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_mult_p: /* Multiply an adouble by a eq_mult_p */ - /* flaoting point. (*=) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_mult_p: /* Multiply an adouble by a eq_mult_p */ + /* flaoting point. (*=) */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; #endif /* !_NTIGHT_ */ -#if!defined(_INT_REV_) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) +#if !defined(_INT_REV_) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - ARES_INC *= coval; + FOR_0_LE_l_LT_p ARES_INC *= coval; #endif #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_mult_a: /* Multiply one adouble by another eq_mult_a */ - /* (*=) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case eq_mult_a: /* Multiply one adouble by another eq_mult_a */ + /* (*=) */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p + FOR_0_LE_l_LT_p #if defined(_INT_REV_) - AARG_INC |= ARES_INC; + AARG_INC |= ARES_INC; #else - { revreal aTmp = *Ares; - ARES_INC = aTmp * TARG; - AARG_INC += aTmp * TRES; - } -#endif - break; + { + revreal aTmp = *Ares; + ARES_INC = aTmp * TARG; + AARG_INC += aTmp * TRES; + } +#endif + break; - /*--------------------------------------------------------------------------*/ - case incr_a: /* Increment an adouble incr_a */ - case decr_a: /* Increment an adouble decr_a */ - res = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case incr_a: /* Increment an adouble incr_a */ + case decr_a: /* Increment an adouble decr_a */ + res = get_locint_r(); #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; - + break; - /****************************************************************************/ - /* BINARY OPERATIONS */ + /****************************************************************************/ + /* BINARY + * OPERATIONS */ - /*--------------------------------------------------------------------------*/ - case plus_a_a: /* : Add two adoubles. (+) plus a_a */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case plus_a_a: /* : Add two adoubles. (+) plus a_a */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG1_INC |= aTmp; - AARG2_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG1_INC |= aTmp; + AARG2_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG1_INC += aTmp; - AARG2_INC += aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG1_INC += aTmp; + AARG2_INC += aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case plus_d_a: /* Add an adouble and a double plus_d_a */ - /* (+) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case plus_d_a: /* Add an adouble and a double plus_d_a */ + /* (+) */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case plus_a_p: /* Add an adouble and a double plus_a_p */ - case min_a_p: /* Subtract an adouble from a min_d_a */ - /* (+) */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case plus_a_p: /* Add an adouble and a double plus_a_p */ + case min_a_p: /* Subtract an adouble from a min_d_a */ + /* (+) */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case min_a_a: /* Subtraction of two adoubles min_a_a */ - /* (-) */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case min_a_a: /* Subtraction of two adoubles min_a_a */ + /* (-) */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG1_INC |= aTmp; - AARG2_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG1_INC |= aTmp; + AARG2_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG1_INC += aTmp; - AARG2_INC -= aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG1_INC += aTmp; + AARG2_INC -= aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case min_d_a: /* Subtract an adouble from a min_d_a */ - /* double (-) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case min_d_a: /* Subtract an adouble from a min_d_a */ + /* double (-) */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC -= aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC -= aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case mult_a_a: /* Multiply two adoubles (*) mult_a_a */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case mult_a_a: /* Multiply two adoubles (*) mult_a_a */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG2_INC |= aTmp; - AARG1_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG2_INC |= aTmp; + AARG1_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG2_INC += aTmp * TARG1; - AARG1_INC += aTmp * TARG2; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG2_INC += aTmp * TARG1; + AARG1_INC += aTmp * TARG2; #endif - } - break; + } + break; - /*--------------------------------------------------------------------------*/ - /* olvo 991122: new op_code with recomputation */ - case eq_plus_prod: /* increment a product of eq_plus_prod */ - /* two adoubles (*) */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + /* olvo 991122: new op_code with recomputation */ + case eq_plus_prod: /* increment a product of eq_plus_prod */ + /* two adoubles (*) */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) #if !defined(_NTIGHT_) - /* RECOMPUTATION */ - TRES -= TARG1*TARG2; + /* RECOMPUTATION */ + TRES -= TARG1 * TARG2; #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - AARG2_INC |= *Ares; - AARG1_INC |= ARES_INC; + AARG2_INC |= *Ares; + AARG1_INC |= ARES_INC; #else - AARG2_INC += (*Ares) * TARG1; - AARG1_INC += ARES_INC * TARG2; + AARG2_INC += (*Ares) * TARG1; + AARG1_INC += ARES_INC * TARG2; #endif - } - break; + } + break; - /*--------------------------------------------------------------------------*/ - /* olvo 991122: new op_code with recomputation */ - case eq_min_prod: /* decrement a product of eq_min_prod */ - /* two adoubles (*) */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + /* olvo 991122: new op_code with recomputation */ + case eq_min_prod: /* decrement a product of eq_min_prod */ + /* two adoubles (*) */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) #if !defined(_NTIGHT_) - /* RECOMPUTATION */ - TRES += TARG1*TARG2; + /* RECOMPUTATION */ + TRES += TARG1 * TARG2; #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - AARG2_INC |= *Ares; - AARG1_INC |= ARES_INC; -#else - AARG2_INC -= (*Ares) * TARG1; - AARG1_INC -= ARES_INC * TARG2; + AARG2_INC |= *Ares; + AARG1_INC |= ARES_INC; +#else + AARG2_INC -= (*Ares) * TARG1; + AARG1_INC -= ARES_INC * TARG2; #endif - } - break; + } + break; - /*--------------------------------------------------------------------------*/ - case mult_d_a: /* Multiply an adouble by a double mult_d_a */ - /* (*) */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case mult_d_a: /* Multiply an adouble by a double mult_d_a */ + /* (*) */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += coval * aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += coval * aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case mult_a_p: /* Multiply an adouble by a double mult_a_p */ - /* (*) */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case mult_a_p: /* Multiply an adouble by a double mult_a_p */ + /* (*) */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += coval * aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += coval * aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case div_a_a: /* Divide an adouble by an adouble div_a_a */ - /* (/) */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case div_a_a: /* Divide an adouble by an adouble div_a_a */ + /* (/) */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) - /* olvo 980922 changed order to allow x=y/x */ + /* olvo 980922 changed order to allow x=y/x */ #if !defined(_NTIGHT_) - r_0 = -TRES; - ADOLC_GET_TAYLOR(res); - r0 = 1.0 / TARG2; - r_0 *= r0; + r_0 = -TRES; + ADOLC_GET_TAYLOR(res); + r0 = 1.0 / TARG2; + r_0 *= r0; #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG1_INC |= aTmp; - AARG2_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG1_INC |= aTmp; + AARG2_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG1_INC += aTmp * r0; - AARG2_INC += aTmp * r_0; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG1_INC += aTmp * r0; + AARG2_INC += aTmp * r_0; #endif - } + } - break; + break; - /*--------------------------------------------------------------------------*/ - case div_d_a: /* Division double - adouble (/) div_d_a */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case div_d_a: /* Division double - adouble (/) div_d_a */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) #if !defined(_NTIGHT_) - /* olvo 980922 changed order to allow x=d/x */ - r0 = -TRES; - if (arg == res) - ADOLC_GET_TAYLOR(arg); - r0 /= TARG; + /* olvo 980922 changed order to allow x=d/x */ + r0 = -TRES; + if (arg == res) + ADOLC_GET_TAYLOR(arg); + r0 /= TARG; #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp * r0; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp * r0; #endif - } + } #if !defined(_NTIGHT_) - if (arg != res) - ADOLC_GET_TAYLOR(res); + if (arg != res) + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - - /****************************************************************************/ - case div_p_a: /* Division double - adouble (/) div_p_a */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); + /****************************************************************************/ + case div_p_a: /* Division double - adouble (/) div_p_a */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) #if !defined(_NTIGHT_) - /* olvo 980922 changed order to allow x=d/x */ - r0 = -TRES; - if (arg == res) - ADOLC_GET_TAYLOR(arg); - r0 /= TARG; + /* olvo 980922 changed order to allow x=d/x */ + r0 = -TRES; + if (arg == res) + ADOLC_GET_TAYLOR(arg); + r0 /= TARG; #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp * r0; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp * r0; #endif - } + } #if !defined(_NTIGHT_) - if (arg != res) - ADOLC_GET_TAYLOR(res); + if (arg != res) + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; - + break; - /****************************************************************************/ - /* SIGN OPERATIONS */ + /****************************************************************************/ + /* SIGN OPERATIONS + */ - /*--------------------------------------------------------------------------*/ - case pos_sign_a: /* pos_sign_a */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case pos_sign_a: /* pos_sign_a */ + res = get_locint_r(); + arg = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case neg_sign_a: /* neg_sign_a */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case neg_sign_a: /* neg_sign_a */ + res = get_locint_r(); + arg = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC -= aTmp; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC -= aTmp; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; + /****************************************************************************/ + /* UNARY + * OPERATIONS */ - /****************************************************************************/ - /* UNARY OPERATIONS */ + /*--------------------------------------------------------------------------*/ + case exp_op: /* exponent operation exp_op */ + res = get_locint_r(); + arg = get_locint_r(); - /*--------------------------------------------------------------------------*/ - case exp_op: /* exponent operation exp_op */ - res = get_locint_r(); - arg = get_locint_r(); + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) - - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp*TRES; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp * TRES; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case sin_op: /* sine operation sin_op */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case sin_op: /* sine operation sin_op */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG1_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG1_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG1_INC += aTmp * TARG2; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG1_INC += aTmp * TARG2; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); - ADOLC_GET_TAYLOR(arg2); /* olvo 980710 covalue */ - /* NOTE: ADJOINT_BUFFER[arg2] should be 0 already */ + ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(arg2); /* olvo 980710 covalue */ + /* NOTE: ADJOINT_BUFFER[arg2] should be 0 already */ #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case cos_op: /* cosine operation cos_op */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case cos_op: /* cosine operation cos_op */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG1_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG1_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG1_INC -= aTmp * TARG2; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG1_INC -= aTmp * TARG2; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); - ADOLC_GET_TAYLOR(arg2); /* olvo 980710 covalue */ - /* NOTE ADJOINT_BUFFER[arg2] should be 0 already */ + ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(arg2); /* olvo 980710 covalue */ + /* NOTE ADJOINT_BUFFER[arg2] should be 0 already */ #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case atan_op: /* atan_op */ - case asin_op: /* asin_op */ - case acos_op: /* acos_op */ - case asinh_op: /* asinh_op */ - case acosh_op: /* acosh_op */ - case atanh_op: /* atanh_op */ - case erf_op: /* erf_op */ - case erfc_op: /* erfc_op */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case atan_op: /* atan_op */ + case asin_op: /* asin_op */ + case acos_op: /* acos_op */ + case asinh_op: /* asinh_op */ + case acosh_op: /* acosh_op */ + case atanh_op: /* atanh_op */ + case erf_op: /* erf_op */ + case erfc_op: /* erfc_op */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG1_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG1_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG1_INC += aTmp * TARG2; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG1_INC += aTmp * TARG2; #endif - } - break; + } + break; - /*--------------------------------------------------------------------------*/ - case log_op: /* log_op */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case log_op: /* log_op */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) #if !defined(_INT_REV_) - r0 = 1.0/TARG; + r0 = 1.0 / TARG; #endif - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp * r0; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp * r0; #endif - } - break; + } + break; - /*--------------------------------------------------------------------------*/ - case pow_op: /* pow_op */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case pow_op: /* pow_op */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) #if !defined(_NTIGHT_) - /* olvo 980921 changed order to allow x=pow(x,n) */ - r0 = TRES; - if (arg == res) - ADOLC_GET_TAYLOR(arg); - if (TARG == 0.0) - r0 = 0.0; - else - r0 *= coval/TARG; + /* olvo 980921 changed order to allow x=pow(x,n) */ + r0 = TRES; + if (arg == res) + ADOLC_GET_TAYLOR(arg); + if (TARG == 0.0) + r0 = 0.0; + else + r0 *= coval / TARG; #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp * r0; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp * r0; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case pow_op_p: /* pow_op_p */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case pow_op_p: /* pow_op_p */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) #if !defined(_NTIGHT_) - /* olvo 980921 changed order to allow x=pow(x,n) */ - r0 = TRES; - if (arg == res) - ADOLC_GET_TAYLOR(arg); - if (TARG == 0.0) - r0 = 0.0; - else - r0 *= coval/TARG; + /* olvo 980921 changed order to allow x=pow(x,n) */ + r0 = TRES; + if (arg == res) + ADOLC_GET_TAYLOR(arg); + if (TARG == 0.0) + r0 = 0.0; + else + r0 *= coval / TARG; #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp * r0; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp * r0; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case sqrt_op: /* sqrt_op */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case sqrt_op: /* sqrt_op */ + res = get_locint_r(); + arg = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) #if !defined(_NTIGHT_) - if (TRES == 0.0) - r0 = 0.0; - else - r0 = 0.5 / TRES; + if (TRES == 0.0) + r0 = 0.0; + else + r0 = 0.5 / TRES; #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp * r0; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp * r0; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case cbrt_op: /* cbrt_op */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case cbrt_op: /* cbrt_op */ + res = get_locint_r(); + arg = get_locint_r(); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) #if !defined(_NTIGHT_) - if (TRES == 0.0) - r0 = 0.0; - else - r0 = 1.0 / (3.0 * TRES * TRES); + if (TRES == 0.0) + r0 = 0.0; + else + r0 = 1.0 / (3.0 * TRES * TRES); #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; #else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += aTmp * r0; + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += aTmp * r0; #endif - } + } #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case gen_quad: /* gen_quad */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case gen_quad: /* gen_quad */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); - coval = get_val_r(); + coval = get_val_r(); + coval = get_val_r(); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG1_INC |= aTmp; -#else - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG1_INC += aTmp * TARG2; -#endif - } - -#if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case min_op: /* min_op */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - - ADOLC_GET_TAYLOR(res); -#endif /* !_NTIGHT_ */ + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG1_INC |= aTmp; +#else + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG1_INC += aTmp * TARG2; +#endif + } + +#if !defined(_NTIGHT_) + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case min_op: /* min_op */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + +#if !defined(_NTIGHT_) + if (TARG1 > TARG2) + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + unsigned long int aTmp = *Ares; + ARES_INC = 0; + #else + revreal aTmp = *Ares; + ARES_INC = 0.0; + #endif + if ((coval) && (aTmp)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG2_INC |= aTmp; + #else + AARG2_INC += aTmp; + #endif + } + else if (TARG1 < TARG2) + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + unsigned long int aTmp = *Ares; + ARES_INC = 0; + #else + revreal aTmp = *Ares; + ARES_INC = 0.0; + #endif + if ((!coval) && (aTmp)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= aTmp; + #else + AARG1_INC += aTmp; + #endif + } + else { /* both are equal */ + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG2_INC |= aTmp; + AARG1_INC |= aTmp; + #else + revreal aTmp = *Ares / 2.0; + fprintf(DIAG_OUT, "ADOL-C warning: fmin/fmax used with equal " + "arguments, adjoints might be incorrect.\n"); + ARES_INC = 0.0; + AARG2_INC += aTmp; + AARG1_INC += aTmp; + #endif + } + if (arg1 != arg2) + MINDEC(ret_c, 1); + } +#else + FOR_0_LE_l_LT_p { + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG1_INC |= aTmp; + AARG2_INC |= aTmp; + } +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case abs_val: /* abs_val */ + res = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - -#if !defined(_NTIGHT_) - if (TARG1 > TARG2) - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; -#else - revreal aTmp = *Ares; - ARES_INC = 0.0; -#endif - if ((coval) && (aTmp)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG2_INC |= aTmp; -#else - AARG2_INC += aTmp; -#endif - } else - if (TARG1 < TARG2) - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; -#else - revreal aTmp = *Ares; - ARES_INC = 0.0; -#endif - if ((!coval) && (aTmp)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG1_INC |= aTmp; -#else - AARG1_INC += aTmp; -#endif - } else { /* both are equal */ - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG2_INC |= aTmp; - AARG1_INC |= aTmp; -#else - revreal aTmp = *Ares / 2.0; - fprintf(DIAG_OUT, "ADOL-C warning: fmin/fmax used with equal arguments, adjoints might be incorrect.\n"); - ARES_INC = 0.0; - AARG2_INC += aTmp; - AARG1_INC += aTmp; -#endif - } - if (arg1 != arg2) - MINDEC(ret_c,1); - } -#else - FOR_0_LE_l_LT_p - { unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG1_INC |= aTmp; - AARG2_INC |= aTmp; - } -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case abs_val: /* abs_val */ - res = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - - ADOLC_GET_TAYLOR(res); -#endif /* !_NTIGHT_ */ - - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) - -#if defined(_ABS_NORM_) - if (rownum == switchnum) { - AARG = 1.0; - } else { - results[indep+switchnum] = *Ares; - *Ares = 0.0; - } - switchnum--; -#elif defined(_ABS_NORM_SIG_) - revreal aTmp = *Ares; - ARES_INC = 0.0; - AARG_INC += siggrad[switchnum]*aTmp; - switchnum--; -#else -#if !defined(_NTIGHT_) - if (TARG < 0.0) - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; -#else - revreal aTmp = *Ares; - ARES_INC = 0.0; -#endif - if ((coval) && (aTmp)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG_INC |= aTmp; -#else - AARG_INC -= aTmp; -#endif - } else - if (TARG > 0.0) - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; -#else - revreal aTmp = *Ares; - ARES_INC = 0.0; -#endif - if ((!coval) && (aTmp)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG_INC |= aTmp; -#else - AARG_INC += aTmp; -#endif - } else - FOR_0_LE_l_LT_p { -#if defined(_INT_REV_) - unsigned long int aTmp = *Ares; - ARES_INC = 0; -#else - revreal aTmp = *Ares; - ARES_INC = 0.0; -#endif - if (aTmp) - MINDEC(ret_c,1); - } -#else - FOR_0_LE_l_LT_p - { - unsigned long int aTmp = *Ares; - ARES_INC = 0; - AARG_INC |= aTmp; - } -#endif /* !_NTIGHT_ */ -#endif /* _ABS_NORM */ - break; - - /*--------------------------------------------------------------------------*/ - case ceil_op: /* ceil_op */ - res = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - - ADOLC_GET_TAYLOR(res); -#endif /* !_NTIGHT_ */ - - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - -#if !defined(_NTIGHT_) - coval = (coval != ceil(TARG) ); -#endif /* !_NTIGHT_ */ - - FOR_0_LE_l_LT_p - { -#if !defined(_NTIGHT_) - if ((coval) && (*Ares)) - MINDEC(ret_c,2); +#if defined(_ABS_NORM_) + if (rownum == switchnum) { + AARG = 1.0; + } else { + results[indep + switchnum] = *Ares; + *Ares = 0.0; + } + switchnum--; +#elif defined(_ABS_NORM_SIG_) + revreal aTmp = *Ares; + ARES_INC = 0.0; + AARG_INC += siggrad[switchnum] * aTmp; + switchnum--; +#else + #if !defined(_NTIGHT_) + if (TARG < 0.0) + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + unsigned long int aTmp = *Ares; + ARES_INC = 0; + #else + revreal aTmp = *Ares; + ARES_INC = 0.0; + #endif + if ((coval) && (aTmp)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG_INC |= aTmp; + #else + AARG_INC -= aTmp; + #endif + } + else if (TARG > 0.0) + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + unsigned long int aTmp = *Ares; + ARES_INC = 0; + #else + revreal aTmp = *Ares; + ARES_INC = 0.0; + #endif + if ((!coval) && (aTmp)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG_INC |= aTmp; + #else + AARG_INC += aTmp; + #endif + } + else + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + unsigned long int aTmp = *Ares; + ARES_INC = 0; + #else + revreal aTmp = *Ares; + ARES_INC = 0.0; + #endif + if (aTmp) + MINDEC(ret_c, 1); + } + #else + FOR_0_LE_l_LT_p { + unsigned long int aTmp = *Ares; + ARES_INC = 0; + AARG_INC |= aTmp; + } + #endif /* !_NTIGHT_ */ +#endif /* _ABS_NORM */ + break; + + /*--------------------------------------------------------------------------*/ + case ceil_op: /* ceil_op */ + res = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + +#if !defined(_NTIGHT_) + coval = (coval != ceil(TARG)); +#endif /* !_NTIGHT_ */ + + FOR_0_LE_l_LT_p { +#if !defined(_NTIGHT_) + if ((coval) && (*Ares)) + MINDEC(ret_c, 2); #endif /* !_NTIGHT_ */ #if defined(_INT_REV_) - ARES_INC = 0; + ARES_INC = 0; #else - ARES_INC = 0.0; + ARES_INC = 0.0; #endif - } - break; + } + break; - /*--------------------------------------------------------------------------*/ - case floor_op: /* floor_op */ - res = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case floor_op: /* floor_op */ + res = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) #if !defined(_NTIGHT_) - coval = ( coval != floor(TARG1) ); + coval = (coval != floor(TARG1)); #endif /* !_NTIGHT_ */ - FOR_0_LE_l_LT_p - { + FOR_0_LE_l_LT_p { #if !defined(_NTIGHT_) - if ( (coval) && (*Ares) ) - MINDEC(ret_c,2); + if ((coval) && (*Ares)) + MINDEC(ret_c, 2); #endif /* !_NTIGHT_ */ #if defined(_INT_REV_) - ARES_INC = 0; + ARES_INC = 0; #else - ARES_INC = 0.0; + ARES_INC = 0.0; #endif - } - break; - - - /****************************************************************************/ - /* CONDITIONALS */ - - /*--------------------------------------------------------------------------*/ - case cond_assign: /* cond_assign */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - - ADOLC_GET_TAYLOR(res); -#endif /* !_NTIGHT_ */ - - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) + } + break; -#if !defined(_NTIGHT_) - /* olvo 980924 changed code a little bit */ - if (TARG > 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if ((coval <= 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0; -#else - AARG1_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval <= 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } else { - if (res != arg2) - FOR_0_LE_l_LT_p - { if ((coval <= 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG2_INC |= *Ares; - ARES_INC = 0; -#else - AARG2_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval <= 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } -#else - if (res != arg1) { - FOR_0_LE_l_LT_p - AARG1_INC |= ARES_INC; - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - } - if (res != arg2) { - FOR_0_LE_l_LT_p - AARG2_INC |= ARES_INC; - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - } - if ((res != arg1) && (res != arg2)) - FOR_0_LE_l_LT_p - ARES_INC = 0; -#endif /* !_NTIGHT_ */ - break; - - case cond_eq_assign: /* cond_assign */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - - ADOLC_GET_TAYLOR(res); -#endif /* !_NTIGHT_ */ - - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) - -#if !defined(_NTIGHT_) - /* olvo 980924 changed code a little bit */ - if (TARG >= 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if ((coval < 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0; -#else - AARG1_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval < 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } else { - if (res != arg2) - FOR_0_LE_l_LT_p - { if ((coval < 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG2_INC |= *Ares; - ARES_INC = 0; -#else - AARG2_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval < 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } -#else - if (res != arg1) { - FOR_0_LE_l_LT_p - AARG1_INC |= ARES_INC; - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - } - if (res != arg2) { - FOR_0_LE_l_LT_p - AARG2_INC |= ARES_INC; - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - } - if ((res != arg1) && (res != arg2)) - FOR_0_LE_l_LT_p - ARES_INC = 0; -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case cond_assign_s: /* cond_assign_s */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - - ADOLC_GET_TAYLOR(res); -#endif /* !_NTIGHT_ */ - - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - -#if !defined(_NTIGHT_) - /* olvo 980924 changed code a little bit */ - if (TARG > 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if ((coval <= 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0.0; -#else - AARG1_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval <= 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } else - if (TARG == 0.0) /* we are at the tie */ - FOR_0_LE_l_LT_p - if (ARES_INC) - MINDEC(ret_c,0); -#else - if (res != arg1) - FOR_0_LE_l_LT_p - { AARG1 |= *Ares; - ARES_INC = 0; - } -#endif /* !_NTIGHT_ */ - break; + /****************************************************************************/ + /* CONDITIONALS + */ - case cond_eq_assign_s: /* cond_eq_assign_s */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case cond_assign: /* cond_assign */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - coval = get_val_r(); + coval = get_val_r(); - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #endif /* !_NTIGHT_ */ - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) #if !defined(_NTIGHT_) - /* olvo 980924 changed code a little bit */ - if (TARG >= 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if ((coval < 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0.0; -#else - AARG1_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval < 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } + /* olvo 980924 changed code a little bit */ + if (TARG > 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0; + #else + AARG1_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval <= 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } else { + if (res != arg2) + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG2_INC |= *Ares; + ARES_INC = 0; + #else + AARG2_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval <= 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } +#else + if (res != arg1) { + FOR_0_LE_l_LT_p AARG1_INC |= ARES_INC; + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + } + if (res != arg2) { + FOR_0_LE_l_LT_p AARG2_INC |= ARES_INC; + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + } + if ((res != arg1) && (res != arg2)) + FOR_0_LE_l_LT_p ARES_INC = 0; +#endif /* !_NTIGHT_ */ + break; + + case cond_eq_assign: /* cond_assign */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + +#if !defined(_NTIGHT_) + /* olvo 980924 changed code a little bit */ + if (TARG >= 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0; + #else + AARG1_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval < 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } else { + if (res != arg2) + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG2_INC |= *Ares; + ARES_INC = 0; + #else + AARG2_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval < 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } +#else + if (res != arg1) { + FOR_0_LE_l_LT_p AARG1_INC |= ARES_INC; + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + } + if (res != arg2) { + FOR_0_LE_l_LT_p AARG2_INC |= ARES_INC; + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + } + if ((res != arg1) && (res != arg2)) + FOR_0_LE_l_LT_p ARES_INC = 0; +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case cond_assign_s: /* cond_assign_s */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + +#if !defined(_NTIGHT_) + /* olvo 980924 changed code a little bit */ + if (TARG > 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0.0; + #else + AARG1_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval <= 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } else if (TARG == 0.0) /* we are at the tie */ + FOR_0_LE_l_LT_p if (ARES_INC) MINDEC(ret_c, 0); +#else + if (res != arg1) + FOR_0_LE_l_LT_p { + AARG1 |= *Ares; + ARES_INC = 0; + } +#endif /* !_NTIGHT_ */ + break; + + case cond_eq_assign_s: /* cond_eq_assign_s */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + +#if !defined(_NTIGHT_) + /* olvo 980924 changed code a little bit */ + if (TARG >= 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0.0; + #else + AARG1_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval < 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } #else - if (res != arg1) - FOR_0_LE_l_LT_p - { AARG1 |= *Ares; - ARES_INC = 0; - } + if (res != arg1) + FOR_0_LE_l_LT_p { + AARG1 |= *Ares; + ARES_INC = 0; + } #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - /* NEW CONDITIONALS */ - /*--------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------*/ + /* NEW CONDITIONALS */ + /*--------------------------------------------------------------------------*/ #if defined(ADOLC_ADVANCED_BRANCHING) - case neq_a_a: - case eq_a_a: - case le_a_a: - case ge_a_a: - case lt_a_a: - case gt_a_a: - case neq_a_p: - case eq_a_p: - case le_a_p: - case ge_a_p: - case lt_a_p: - case gt_a_p: - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); -#endif - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - ARES_INC = 0; + case neq_a_a: + case eq_a_a: + case le_a_a: + case ge_a_a: + case lt_a_a: + case gt_a_a: + case neq_a_p: + case eq_a_p: + case le_a_p: + case ge_a_p: + case lt_a_p: + case gt_a_p: + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + #if !defined(_NTIGHT_) + coval = get_val_r(); + #endif + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + + FOR_0_LE_l_LT_p + #if defined(_INT_REV_) + ARES_INC = 0; + #else + ARES_INC = 0.0; + #endif + + #if !defined(_NTIGHT_) + ADOLC_GET_TAYLOR(res); + #endif /* !_NTIGHT_ */ + + break; +#endif + /*--------------------------------------------------------------------------*/ + case subscript: { +#if !defined(_NTIGHT_) + double val = +#endif + get_val_r(); + res = get_locint_r(); +#if !defined(_NTIGHT_) + size_t idx, numval = (size_t)trunc(fabs(val)); + locint vectorloc; + vectorloc = +#endif + get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + idx = (size_t)trunc(fabs(TARG)); + if (idx >= numval) + fprintf(DIAG_OUT, + "ADOL-C warning: index out of bounds while subscripting n=%zu, " + "idx=%zu\n", + numval, idx); + arg1 = vectorloc + idx; + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0; + #else + AARG1_INC += *Ares; + *Ares = 0.0; + #endif + } + ADOLC_GET_TAYLOR(res); +#else + fprintf(DIAG_OUT, "ADOL-C error: active subscripting does not work in " + "safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif /* !_NTIGHT_ */ + } break; + + case subscript_ref: { +#if !defined(_NTIGHT_) + double val = +#endif + get_val_r(); + res = get_locint_r(); +#if !defined(_NTIGHT_) + size_t idx, numval = (size_t)trunc(fabs(val)); + locint vectorloc; + vectorloc = +#endif + get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + idx = (size_t)trunc(fabs(TARG)); + if (idx >= numval) + fprintf(DIAG_OUT, + "ADOL-C warning: index out of bounds while subscripting (ref) " + "n=%zu, idx=%zu\n", + numval, idx); + arg1 = (size_t)trunc(fabs(TRES)); + /* + * This is actually NOP + * basically all we need is that arg1 == vectorloc+idx + * so doing a check here is probably good + */ + if (arg1 != vectorloc + idx) { + fprintf(DIAG_OUT, + "ADOL-C error: indexed active position does not match " + "referenced position\nindexed = %zu, referenced = %d\n", + vectorloc + idx, arg1); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + } + ADOLC_GET_TAYLOR(res); +#else + fprintf(DIAG_OUT, "ADOL-C error: active subscripting does not work in " + "safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif /* !_NTIGHT_ */ + } break; + + case ref_copyout: + res = get_locint_r(); + arg1 = get_locint_r(); +#if !defined(_NTIGHT_) + arg = (size_t)trunc(fabs(TARG1)); + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) + + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + AARG_INC |= *Ares; + ARES_INC = 0; + #else + AARG_INC += *Ares; + ARES_INC = 0.0; + #endif + } + ADOLC_GET_TAYLOR(res); #else - ARES_INC = 0.0; + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif + break; + + case ref_incr_a: /* Increment an adouble incr_a */ + case ref_decr_a: /* Increment an adouble decr_a */ + arg1 = get_locint_r(); + +#if !defined(_NTIGHT_) + res = (size_t)trunc(fabs(TARG1)); + ADOLC_GET_TAYLOR(res); +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif /* !_NTIGHT_ */ + break; + case ref_assign_d: /* assign an adouble variable a assign_d */ + /* double value. (=) */ + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - ADOLC_GET_TAYLOR(res); -#endif /* !_NTIGHT_ */ + res = (size_t)trunc(fabs(TARG1)); + coval = get_val_r(); - break; -#endif - /*--------------------------------------------------------------------------*/ - case subscript: - { -#if !defined(_NTIGHT_) - double val = -#endif - get_val_r(); - res = get_locint_r(); -#if !defined(_NTIGHT_) - size_t idx, numval = (size_t)trunc(fabs(val)); - locint vectorloc; - vectorloc = -#endif - get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - idx = (size_t)trunc(fabs(TARG)); - if (idx >= numval) - fprintf(DIAG_OUT, "ADOL-C warning: index out of bounds while subscripting n=%zu, idx=%zu\n", numval, idx); - arg1 = vectorloc+idx; - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0; -#else - AARG1_INC += *Ares; - *Ares = 0.0; -#endif - } - ADOLC_GET_TAYLOR(res); -#else - fprintf(DIAG_OUT, "ADOL-C error: active subscripting does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* !_NTIGHT_ */ - } - break; + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - case subscript_ref: - { -#if !defined(_NTIGHT_) - double val = -#endif - get_val_r(); - res = get_locint_r(); -#if !defined(_NTIGHT_) - size_t idx, numval = (size_t)trunc(fabs(val)); - locint vectorloc; - vectorloc = -#endif - get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - idx = (size_t)trunc(fabs(TARG)); - if (idx >= numval) - fprintf(DIAG_OUT, "ADOL-C warning: index out of bounds while subscripting (ref) n=%zu, idx=%zu\n", numval, idx); - arg1 = (size_t)trunc(fabs(TRES)); - /* - * This is actually NOP - * basically all we need is that arg1 == vectorloc+idx - * so doing a check here is probably good - */ - if (arg1 != vectorloc+idx) { - fprintf(DIAG_OUT, "ADOL-C error: indexed active position does not match referenced position\nindexed = %zu, referenced = %d\n", vectorloc+idx, arg1); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); - } - ADOLC_GET_TAYLOR(res); -#else - fprintf(DIAG_OUT, "ADOL-C error: active subscripting does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* !_NTIGHT_ */ - } - break; - - case ref_copyout: - res = get_locint_r(); - arg1 = get_locint_r(); -#if !defined(_NTIGHT_) - arg = (size_t)trunc(fabs(TARG1)); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) - - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - AARG_INC |= *Ares; - ARES_INC = 0; -#else - AARG_INC += *Ares; - ARES_INC = 0.0; -#endif - } - ADOLC_GET_TAYLOR(res); -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif - break; - - - case ref_incr_a: /* Increment an adouble incr_a */ - case ref_decr_a: /* Increment an adouble decr_a */ - arg1 = get_locint_r(); + FOR_0_LE_l_LT_p + #if defined(_INT_REV_) + ARES_INC = 0; + #else + ARES_INC = 0.0; + #endif -#if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_assign_d: /* assign an adouble variable a assign_d */ - /* double value. (=) */ - arg1 = get_locint_r(); + case ref_assign_p: /* assign an adouble variable a assign_p */ + arg = get_locint_r(); + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - coval = get_val_r(); + res = (size_t)trunc(fabs(TARG1)); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - ARES_INC = 0; -#else - ARES_INC = 0.0; -#endif - - ADOLC_GET_TAYLOR(res); -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* !_NTIGHT_ */ - break; - - case ref_assign_p: /* assign an adouble variable a assign_p */ - arg = get_locint_r(); - arg1 = get_locint_r(); -#if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; - - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - ARES_INC = 0; -#else - ARES_INC = 0.0; -#endif + FOR_0_LE_l_LT_p + #if defined(_INT_REV_) + ARES_INC = 0; + #else + ARES_INC = 0.0; + #endif - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_assign_d_zero: /* assign an adouble variable a assign_d_zero */ - case ref_assign_d_one: /* double value (0 or 1). (=) assign_d_one */ - arg1 = get_locint_r(); + case ref_assign_d_zero: /* assign an adouble variable a assign_d_zero */ + case ref_assign_d_one: /* double value (0 or 1). (=) assign_d_one */ + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); + res = (size_t)trunc(fabs(TARG1)); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - ARES_INC = 0; -#else - ARES_INC = 0.0; -#endif - ADOLC_GET_TAYLOR(res); + FOR_0_LE_l_LT_p + #if defined(_INT_REV_) + ARES_INC = 0; + #else + ARES_INC = 0.0; + #endif + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_assign_a: /* assign an adouble variable an assign_a */ - /* adouble value. (=) */ - arg1 = get_locint_r(); - arg = get_locint_r(); + case ref_assign_a: /* assign an adouble variable an assign_a */ + /* adouble value. (=) */ + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); + res = (size_t)trunc(fabs(TARG1)); - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - { -#if defined(_INT_REV_) - AARG_INC |= *Ares; - ARES_INC = 0; -#else - AARG_INC += *Ares; - ARES_INC = 0.0; -#endif - } + FOR_0_LE_l_LT_p { + #if defined(_INT_REV_) + AARG_INC |= *Ares; + ARES_INC = 0; + #else + AARG_INC += *Ares; + ARES_INC = 0.0; + #endif + } - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_assign_ind: /* assign an adouble variable an assign_ind */ - /* independent double value (<<=) */ - arg1 = get_locint_r(); + case ref_assign_ind: /* assign an adouble variable an assign_ind */ + /* independent double value (<<=) */ + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); + res = (size_t)trunc(fabs(TARG1)); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - RESULTS(l,indexi) = ARES_INC; + FOR_0_LE_l_LT_p RESULTS(l, indexi) = ARES_INC; - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - indexi--; - break; + indexi--; + break; - case ref_eq_plus_d: /* Add a floating point to an eq_plus_d */ - /* adouble. (+=) */ - arg1 = get_locint_r(); + case ref_eq_plus_d: /* Add a floating point to an eq_plus_d */ + /* adouble. (+=) */ + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - coval = get_val_r(); + res = (size_t)trunc(fabs(TARG1)); + coval = get_val_r(); - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_plus_p: /* Add a floating point to an eq_plus_d */ - /* adouble. (+=) */ - arg1 = get_locint_r(); - arg = get_locint_r(); + case ref_eq_plus_p: /* Add a floating point to an eq_plus_d */ + /* adouble. (+=) */ + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + res = (size_t)trunc(fabs(TARG1)); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_plus_a: /* Add an adouble to another eq_plus_a */ - /* adouble. (+=) */ - arg1 = get_locint_r(); - arg = get_locint_r(); + case ref_eq_plus_a: /* Add an adouble to another eq_plus_a */ + /* adouble. (+=) */ + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); + res = (size_t)trunc(fabs(TARG1)); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]); + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]); - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - AARG_INC |= ARES_INC; -#else - AARG_INC += ARES_INC; -#endif + FOR_0_LE_l_LT_p + #if defined(_INT_REV_) + AARG_INC |= ARES_INC; + #else + AARG_INC += ARES_INC; + #endif - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_min_d: /* Subtract a floating point from an eq_min_d */ - /* adouble. (-=) */ - arg1 = get_locint_r(); + case ref_eq_min_d: /* Subtract a floating point from an eq_min_d */ + /* adouble. (-=) */ + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - coval = get_val_r(); + res = (size_t)trunc(fabs(TARG1)); + coval = get_val_r(); - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_min_p: /* Subtract a floating point from an eq_min_p */ - /* adouble. (-=) */ - arg1 = get_locint_r(); - arg = get_locint_r(); + case ref_eq_min_p: /* Subtract a floating point from an eq_min_p */ + /* adouble. (-=) */ + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + res = (size_t)trunc(fabs(TARG1)); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_min_a: /* Subtract an adouble from another eq_min_a */ - /* adouble. (-=) */ - arg1 = get_locint_r(); - arg = get_locint_r(); + case ref_eq_min_a: /* Subtract an adouble from another eq_min_a */ + /* adouble. (-=) */ + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + res = (size_t)trunc(fabs(TARG1)); + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - AARG_INC |= ARES_INC; -#else - AARG_INC -= ARES_INC; -#endif + FOR_0_LE_l_LT_p + #if defined(_INT_REV_) + AARG_INC |= ARES_INC; + #else + AARG_INC -= ARES_INC; + #endif - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_mult_d: /* Multiply an adouble by a eq_mult_d */ - /* flaoting point. (*=) */ - arg1 = get_locint_r(); + case ref_eq_mult_d: /* Multiply an adouble by a eq_mult_d */ + /* flaoting point. (*=) */ + arg1 = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - coval = get_val_r(); + res = (size_t)trunc(fabs(TARG1)); + coval = get_val_r(); -#if !defined(_INT_REV_) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + #if !defined(_INT_REV_) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - ARES_INC *= coval; -#endif + FOR_0_LE_l_LT_p ARES_INC *= coval; + #endif - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_mult_p: /* Multiply an adouble by a eq_mult_p */ - /* flaoting point. (*=) */ - arg1 = get_locint_r(); - arg = get_locint_r(); + case ref_eq_mult_p: /* Multiply an adouble by a eq_mult_p */ + /* flaoting point. (*=) */ + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + res = (size_t)trunc(fabs(TARG1)); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; -#if !defined(_INT_REV_) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + #if !defined(_INT_REV_) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - ARES_INC *= coval; -#endif + FOR_0_LE_l_LT_p ARES_INC *= coval; + #endif - ADOLC_GET_TAYLOR(res); + ADOLC_GET_TAYLOR(res); #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_mult_a: /* Multiply one adouble by another eq_mult_a */ - /* (*=) */ - arg1 = get_locint_r(); - arg = get_locint_r(); + case ref_eq_mult_a: /* Multiply one adouble by another eq_mult_a */ + /* (*=) */ + arg1 = get_locint_r(); + arg = get_locint_r(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(TARG1)); - ADOLC_GET_TAYLOR(res); + res = (size_t)trunc(fabs(TARG1)); + ADOLC_GET_TAYLOR(res); - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) - FOR_0_LE_l_LT_p -#if defined(_INT_REV_) - AARG_INC |= ARES_INC; -#else - { revreal aTmp = *Ares; - ARES_INC = aTmp * TARG; - AARG_INC += aTmp * TRES; - } -#endif + FOR_0_LE_l_LT_p + #if defined(_INT_REV_) + AARG_INC |= ARES_INC; + #else + { + revreal aTmp = *Ares; + ARES_INC = aTmp * TARG; + AARG_INC += aTmp * TRES; + } + #endif #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case vec_copy: - res = get_locint_r(); - size = get_locint_r(); - arg = get_locint_r(); - for (locint qq=0;qq 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if ((coval <= 0.0) && (*Ares)) - MINDEC(ret_c,2); + case vec_dot: + res = get_locint_r(); + size = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + for (locint qq = 0; qq < size; qq++) { + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0; -#else - AARG1_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval <= 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } else { - if (res != arg2) - FOR_0_LE_l_LT_p - { if ((coval <= 0.0) && (*Ares)) - MINDEC(ret_c,2); + AARG2_INC |= *Ares; + AARG1_INC |= ARES_INC; +#else + AARG2_INC += (*Ares) * TARG1; + AARG1_INC += ARES_INC * TARG2; +#endif + } + arg2++; + arg1++; + } +#if !defined(_NTIGHT_) + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + break; + + case vec_axpy: + res = get_locint_r(); + size = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + for (locint qq = 0; qq < size; qq++) { + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg, ADJOINT_BUFFER[arg]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - AARG2_INC |= *Ares; - ARES_INC = 0; -#else - AARG2_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval <= 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* !_NTIGHT_ */ - } - break; - - case ref_cond_eq_assign: /* cond_eq_assign */ - { -#if !defined(_NTIGHT_) - locint ref = -#endif - get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - res = (size_t)trunc(fabs(rp_T[ref])); - - ADOLC_GET_TAYLOR(res); - - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - ASSIGN_A( Aarg2, ADJOINT_BUFFER[arg2]) - - /* olvo 980924 changed code a little bit */ - if (TARG >= 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if ((coval < 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0; -#else - AARG1_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval < 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } else { - if (res != arg2) - FOR_0_LE_l_LT_p - { if ((coval < 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG2_INC |= *Ares; - ARES_INC = 0; -#else - AARG2_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval < 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* !_NTIGHT_ */ - } - break; - - case ref_cond_assign_s: /* cond_assign_s */ - arg2 = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - res = (size_t)trunc(fabs(TARG2)); - ADOLC_GET_TAYLOR(res); - - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - - /* olvo 980924 changed code a little bit */ - if (TARG > 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if ((coval <= 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0.0; -#else - AARG1_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval <= 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } else - if (TARG == 0.0) /* we are at the tie */ - FOR_0_LE_l_LT_p - if (ARES_INC) - MINDEC(ret_c,0); -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* !_NTIGHT_ */ - break; - - case ref_cond_eq_assign_s: /* cond_eq_assign_s */ - arg2 = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); -#if !defined(_NTIGHT_) - coval = get_val_r(); - res = (size_t)trunc(fabs(TARG2)); - ADOLC_GET_TAYLOR(res); - - ASSIGN_A( Aarg1, ADJOINT_BUFFER[arg1]) - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) - - /* olvo 980924 changed code a little bit */ - if (TARG >= 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if ((coval < 0.0) && (*Ares)) - MINDEC(ret_c,2); -#if defined(_INT_REV_) - AARG1_INC |= *Ares; - ARES_INC = 0.0; -#else - AARG1_INC += *Ares; - ARES_INC = 0.0; -#endif - } else - FOR_0_LE_l_LT_p - if ((coval < 0.0) && (ARES_INC)) - MINDEC(ret_c,2); - } + AARG_INC |= *Ares; + AARG2_INC |= *Ares; + AARG1_INC |= ARES_INC; +#else + AARG2_INC += *Ares; + AARG1_INC += (*Ares) * TARG; + AARG_INC += ARES_INC * TARG1; +#endif + } +#if !defined(_NTIGHT_) + ADOLC_GET_TAYLOR(res); +#endif /* !_NTIGHT_ */ + arg2++; + arg1++; + res++; + } + break; + + case ref_cond_assign: /* cond_assign */ + { +#if !defined(_NTIGHT_) + locint ref = +#endif + get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + res = (size_t)trunc(fabs(rp_T[ref])); + + ADOLC_GET_TAYLOR(res); + + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + + /* olvo 980924 changed code a little bit */ + if (TARG > 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0; + #else + AARG1_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval <= 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } else { + if (res != arg2) + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG2_INC |= *Ares; + ARES_INC = 0; + #else + AARG2_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval <= 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif /* !_NTIGHT_ */ + } break; + + case ref_cond_eq_assign: /* cond_eq_assign */ + { +#if !defined(_NTIGHT_) + locint ref = +#endif + get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + res = (size_t)trunc(fabs(rp_T[ref])); + + ADOLC_GET_TAYLOR(res); + + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Aarg2, ADJOINT_BUFFER[arg2]) + + /* olvo 980924 changed code a little bit */ + if (TARG >= 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0; + #else + AARG1_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval < 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } else { + if (res != arg2) + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG2_INC |= *Ares; + ARES_INC = 0; + #else + AARG2_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval < 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif /* !_NTIGHT_ */ + } break; + + case ref_cond_assign_s: /* cond_assign_s */ + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + res = (size_t)trunc(fabs(TARG2)); + ADOLC_GET_TAYLOR(res); + + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + + /* olvo 980924 changed code a little bit */ + if (TARG > 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0.0; + #else + AARG1_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval <= 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } else if (TARG == 0.0) /* we are at the tie */ + FOR_0_LE_l_LT_p if (ARES_INC) MINDEC(ret_c, 0); +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif /* !_NTIGHT_ */ + break; + + case ref_cond_eq_assign_s: /* cond_eq_assign_s */ + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); +#if !defined(_NTIGHT_) + coval = get_val_r(); + res = (size_t)trunc(fabs(TARG2)); + ADOLC_GET_TAYLOR(res); + + ASSIGN_A(Aarg1, ADJOINT_BUFFER[arg1]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) + + /* olvo 980924 changed code a little bit */ + if (TARG >= 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (*Ares)) + MINDEC(ret_c, 2); + #if defined(_INT_REV_) + AARG1_INC |= *Ares; + ARES_INC = 0.0; + #else + AARG1_INC += *Ares; + ARES_INC = 0.0; + #endif + } + else + FOR_0_LE_l_LT_p if ((coval < 0.0) && (ARES_INC)) MINDEC(ret_c, 2); + } #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; + /****************************************************************************/ + /* REMAINING + * STUFF */ - /****************************************************************************/ - /* REMAINING STUFF */ - - /*--------------------------------------------------------------------------*/ - case take_stock_op: /* take_stock_op */ - res = get_locint_r(); - size = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case take_stock_op: /* take_stock_op */ + res = get_locint_r(); + size = get_locint_r(); #if !defined(_NTIGHT_) - get_val_v_r(size); + get_val_v_r(size); #endif /* !_NTIGHT_ */ - res += size; - for (ls=size; ls>0; ls--) { - res--; + res += size; + for (ls = size; ls > 0; ls--) { + res--; - ASSIGN_A( Ares, ADJOINT_BUFFER[res]) + ASSIGN_A(Ares, ADJOINT_BUFFER[res]) - FOR_0_LE_l_LT_p - ARES_INC = 0.0; - } - break; + FOR_0_LE_l_LT_p ARES_INC = 0.0; + } + break; - /*--------------------------------------------------------------------------*/ - case death_not: /* death_not */ - arg2 = get_locint_r(); - arg1 = get_locint_r(); + /*--------------------------------------------------------------------------*/ + case death_not: /* death_not */ + arg2 = get_locint_r(); + arg1 = get_locint_r(); - for (j=arg1;j<=arg2;j++) { - ASSIGN_A(Aarg1, ADJOINT_BUFFER[j]) + for (j = arg1; j <= arg2; j++) { + ASSIGN_A(Aarg1, ADJOINT_BUFFER[j]) - FOR_0_LE_l_LT_p - AARG1_INC = 0.0; - } + FOR_0_LE_l_LT_p AARG1_INC = 0.0; + } #if !defined(_NTIGHT_) - for (j=arg1;j<=arg2;j++) - ADOLC_GET_TAYLOR(j); + for (j = arg1; j <= arg2; j++) + ADOLC_GET_TAYLOR(j); #endif /* !_NTIGHT_ */ - break; + break; #if !defined(_INT_REV_) - /*--------------------------------------------------------------------------*/ - case ext_diff: /* extern differntiated function */ - ADOLC_CURRENT_TAPE_INFOS.cpIndex = get_locint_r(); - ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev = get_locint_r(); - ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev = get_locint_r(); - m = get_locint_r(); - n = get_locint_r(); - ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_r(); - ADOLC_EXT_FCT_SAVE_NUMDIRS; - edfct = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - - oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; - ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; - - if (edfct->ADOLC_EXT_FCT_POINTER == NULL) - fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); - if (m>0) { - if (ADOLC_EXT_FCT_U == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - if (edfct->dp_y==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - } - if (n>0) { - if (ADOLC_EXT_FCT_Z == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - if (edfct->dp_x==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (loop = 0; loop < m; ++loop) { - ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_U[loop],ADJOINT_BUFFER_ARG); - ++arg; - } - - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - for (loop = 0; loop < n; ++loop) { - ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_Z[loop],ADJOINT_BUFFER_ARG); - ++arg; - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - for (loop = 0; loop < n; ++loop,++arg) { - edfct->dp_x[loop]=TARG; - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (loop = 0; loop < m; ++loop,++arg) { - edfct->dp_y[loop]=TARG; - } - ext_retc = edfct->ADOLC_EXT_FCT_COMPLETE; - MINDEC(ret_c, ext_retc); - - res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (loop = 0; loop < m; ++loop) { - FOR_0_LE_l_LT_p { - ADJOINT_BUFFER_RES_L = 0.; /* \bar{v}_i = 0 !!! */ - } - ++res; - } - res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - for (loop = 0; loop < n; ++loop) { - ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(ADOLC_EXT_FCT_Z[loop],ADJOINT_BUFFER_RES); - ++res; - } - if (edfct->dp_y_priorRequired) { - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev+m-1; - for (loop = 0; loop < m; ++loop,--arg) { - ADOLC_GET_TAYLOR(arg); - } - } - if (edfct->dp_x_changes) { - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev+n-1; - for (loop = 0; loop < n; ++loop,--arg) { - ADOLC_GET_TAYLOR(arg); - } - } - ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; - - break; - case ext_diff_iArr: /* extern differntiated function */ - ADOLC_CURRENT_TAPE_INFOS.cpIndex = get_locint_r(); - ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev = get_locint_r(); - ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev = get_locint_r(); - m = get_locint_r(); - n = get_locint_r(); - ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_r(); - iArrLength=get_locint_r(); - iArr=(int*)malloc(iArrLength*sizeof(int)); - for (loop=iArrLength-1;loop>=0;--loop) iArr[loop]=get_locint_r(); - get_locint_r(); /* get it again */ - ADOLC_EXT_FCT_SAVE_NUMDIRS; - edfct = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - - oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; - ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; - - if (edfct->ADOLC_EXT_FCT_IARR_POINTER == NULL) - fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); - if (m>0) { - if (ADOLC_EXT_FCT_U == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - if (edfct->dp_y==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - } - if (n>0) { - if (ADOLC_EXT_FCT_Z == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - if (edfct->dp_x==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (loop = 0; loop < m; ++loop) { - ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_U[loop],ADJOINT_BUFFER_ARG); - ++arg; - } - - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - for (loop = 0; loop < n; ++loop) { - ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_Z[loop],ADJOINT_BUFFER_ARG); - ++arg; - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - for (loop = 0; loop < n; ++loop,++arg) { - edfct->dp_x[loop]=TARG; - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (loop = 0; loop < m; ++loop,++arg) { - edfct->dp_y[loop]=TARG; - } - ext_retc = edfct->ADOLC_EXT_FCT_IARR_COMPLETE; - MINDEC(ret_c, ext_retc); - - res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - for (loop = 0; loop < m; ++loop) { - FOR_0_LE_l_LT_p { - ADJOINT_BUFFER_RES_L = 0.; /* \bar{v}_i = 0 !!! */ - } - ++res; - } - res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - for (loop = 0; loop < n; ++loop) { - ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(ADOLC_EXT_FCT_Z[loop],ADJOINT_BUFFER_RES); - ++res; - } - if (edfct->dp_y_priorRequired) { - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev+m-1; - for (loop = 0; loop < m; ++loop,--arg) { - ADOLC_GET_TAYLOR(arg); - } - } - if (edfct->dp_x_changes) { - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev+n-1; - for (loop = 0; loop < n; ++loop,--arg) { - ADOLC_GET_TAYLOR(arg); - } - } - ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; - - break; - case ext_diff_v2: - nout = get_locint_r(); - nin = get_locint_r(); - insz = malloc(2*(nin+nout)*sizeof(locint)); - outsz = insz + nin; - ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = outsz + nout; - ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = outsz + nout + nin; - for (loop=nout-1;loop>=0;--loop) { - ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2[loop] = get_locint_r(); - outsz[loop] = get_locint_r(); - } - for (loop=nin-1;loop>=0;--loop) { - ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[loop] = get_locint_r(); - insz[loop] = get_locint_r(); - } - get_locint_r(); /* nout again */ - get_locint_r(); /* nin again */ - iArrLength = get_locint_r(); - iArr = malloc(iArrLength*sizeof(int)); - for (loop=iArrLength-1;loop>=0;--loop) iArr[loop] = get_locint_r(); - get_locint_r(); /* iArrLength again */ - ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index=get_locint_r(); - ADOLC_EXT_FCT_SAVE_NUMDIRS; - edfct2 = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); - oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; - ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; - - if (edfct2->ADOLC_EXT_FCT_POINTER == NULL) - fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); - if (nout>0) { - if (ADOLC_EXT_FCT_V2_U == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - if (edfct2->y == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - } - if (nin>0) { - if (ADOLC_EXT_FCT_V2_Z == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - if (edfct2->x == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - } - for (oloop=0;oloopy[oloop][loop]=TARG; - ++arg; - } - } - for (oloop=0;oloopx[oloop][loop]=TARG; - ++arg; - } - } - ext_retc = edfct2->ADOLC_EXT_FCT_V2_COMPLETE; - MINDEC(ret_c, ext_retc); - for (oloop=0;oloopdp_y_priorRequired) { - for(oloop=nout-1;oloop>=0;--oloop) { - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2[oloop]+outsz[oloop]-1; - for (loop=outsz[oloop]-1; loop>=0; --loop) { - ADOLC_GET_TAYLOR(arg); - --arg; - } - } - } - if (edfct2->dp_x_changes) { - for(oloop=nin-1;oloop>=0;--oloop) { - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[oloop]+insz[oloop]-1; - for (loop=insz[oloop]-1; loop>=0; --loop) { - ADOLC_GET_TAYLOR(arg); - --arg; - } - } - } - ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; - free(iArr); - free(insz); - insz = 0; - iArr = 0; - outsz = 0; - ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = 0; - ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = 0; - break; -#ifdef ADOLC_MEDIPACK_SUPPORT - /*--------------------------------------------------------------------------*/ - case medi_call: { - locint mediIndex = get_locint_r(); - short tapeId = ADOLC_CURRENT_TAPE_INFOS.tapeID; - -#if defined _FOS_ - mediCallHandleReverse(tapeId, mediIndex, rp_T, &ADJOINT_BUFFER, 1); -#elif defined _FOV_ - mediCallHandleReverse(tapeId, mediIndex, rp_T, ADJOINT_BUFFER, p); -#endif - break; - } -#endif -#ifdef ADOLC_AMPI_SUPPORT - /*--------------------------------------------------------------------------*/ - case ampi_send: { - BW_AMPI_Send(buf, - count, - datatype, - src, - tag, - pairedWith, - comm); - break; - } - case ampi_recv: { - BW_AMPI_Recv(buf, - count, - datatype, - src, - tag, - pairedWith, - comm, - status); - break; - } - case ampi_isend: { - BW_AMPI_Isend(buf, - count, - datatype, - src, - tag, - pairedWith, - comm, - &request); - break; - } - case ampi_irecv: { - BW_AMPI_Irecv(buf, - count, - datatype, - src, - tag, - pairedWith, - comm, - &request); - break; + /*--------------------------------------------------------------------------*/ + case ext_diff: /* extern differntiated function */ + ADOLC_CURRENT_TAPE_INFOS.cpIndex = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev = get_locint_r(); + m = get_locint_r(); + n = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_r(); + ADOLC_EXT_FCT_SAVE_NUMDIRS; + edfct = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + + if (edfct->ADOLC_EXT_FCT_POINTER == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); + if (m > 0) { + if (ADOLC_EXT_FCT_U == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + if (edfct->dp_y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + } + if (n > 0) { + if (ADOLC_EXT_FCT_Z == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + if (edfct->dp_x == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (loop = 0; loop < m; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_U[loop], ADJOINT_BUFFER_ARG); + ++arg; + } + + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + for (loop = 0; loop < n; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_Z[loop], ADJOINT_BUFFER_ARG); + ++arg; + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + for (loop = 0; loop < n; ++loop, ++arg) { + edfct->dp_x[loop] = TARG; + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (loop = 0; loop < m; ++loop, ++arg) { + edfct->dp_y[loop] = TARG; + } + ext_retc = edfct->ADOLC_EXT_FCT_COMPLETE; + MINDEC(ret_c, ext_retc); + + res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (loop = 0; loop < m; ++loop) { + FOR_0_LE_l_LT_p { ADJOINT_BUFFER_RES_L = 0.; /* \bar{v}_i = 0 !!! */ } + ++res; + } + res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + for (loop = 0; loop < n; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(ADOLC_EXT_FCT_Z[loop], + ADJOINT_BUFFER_RES); + ++res; + } + if (edfct->dp_y_priorRequired) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev + m - 1; + for (loop = 0; loop < m; ++loop, --arg) { + ADOLC_GET_TAYLOR(arg); + } + } + if (edfct->dp_x_changes) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev + n - 1; + for (loop = 0; loop < n; ++loop, --arg) { + ADOLC_GET_TAYLOR(arg); + } + } + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; + + break; + case ext_diff_iArr: /* extern differntiated function */ + ADOLC_CURRENT_TAPE_INFOS.cpIndex = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev = get_locint_r(); + m = get_locint_r(); + n = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_r(); + iArrLength = get_locint_r(); + iArr = (int *)malloc(iArrLength * sizeof(int)); + for (loop = iArrLength - 1; loop >= 0; --loop) + iArr[loop] = get_locint_r(); + get_locint_r(); /* get it again */ + ADOLC_EXT_FCT_SAVE_NUMDIRS; + edfct = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + + if (edfct->ADOLC_EXT_FCT_IARR_POINTER == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); + if (m > 0) { + if (ADOLC_EXT_FCT_U == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + if (edfct->dp_y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + } + if (n > 0) { + if (ADOLC_EXT_FCT_Z == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + if (edfct->dp_x == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (loop = 0; loop < m; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_U[loop], ADJOINT_BUFFER_ARG); + ++arg; + } + + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + for (loop = 0; loop < n; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_Z[loop], ADJOINT_BUFFER_ARG); + ++arg; + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + for (loop = 0; loop < n; ++loop, ++arg) { + edfct->dp_x[loop] = TARG; + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (loop = 0; loop < m; ++loop, ++arg) { + edfct->dp_y[loop] = TARG; + } + ext_retc = edfct->ADOLC_EXT_FCT_IARR_COMPLETE; + MINDEC(ret_c, ext_retc); + + res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + for (loop = 0; loop < m; ++loop) { + FOR_0_LE_l_LT_p { ADJOINT_BUFFER_RES_L = 0.; /* \bar{v}_i = 0 !!! */ } + ++res; + } + res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + for (loop = 0; loop < n; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(ADOLC_EXT_FCT_Z[loop], + ADJOINT_BUFFER_RES); + ++res; + } + if (edfct->dp_y_priorRequired) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev + m - 1; + for (loop = 0; loop < m; ++loop, --arg) { + ADOLC_GET_TAYLOR(arg); + } + } + if (edfct->dp_x_changes) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev + n - 1; + for (loop = 0; loop < n; ++loop, --arg) { + ADOLC_GET_TAYLOR(arg); + } + } + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; + + break; + case ext_diff_v2: + nout = get_locint_r(); + nin = get_locint_r(); + insz = malloc(2 * (nin + nout) * sizeof(locint)); + outsz = insz + nin; + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = outsz + nout; + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = outsz + nout + nin; + for (loop = nout - 1; loop >= 0; --loop) { + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2[loop] = get_locint_r(); + outsz[loop] = get_locint_r(); + } + for (loop = nin - 1; loop >= 0; --loop) { + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[loop] = get_locint_r(); + insz[loop] = get_locint_r(); + } + get_locint_r(); /* nout again */ + get_locint_r(); /* nin again */ + iArrLength = get_locint_r(); + iArr = malloc(iArrLength * sizeof(int)); + for (loop = iArrLength - 1; loop >= 0; --loop) + iArr[loop] = get_locint_r(); + get_locint_r(); /* iArrLength again */ + ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_r(); + ADOLC_EXT_FCT_SAVE_NUMDIRS; + edfct2 = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + + if (edfct2->ADOLC_EXT_FCT_POINTER == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); + if (nout > 0) { + if (ADOLC_EXT_FCT_V2_U == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + if (edfct2->y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + } + if (nin > 0) { + if (ADOLC_EXT_FCT_V2_Z == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + if (edfct2->x == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + } + for (oloop = 0; oloop < nout; ++oloop) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2[oloop]; + for (loop = 0; loop < outsz[oloop]; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_V2_U_LOOP, + ADJOINT_BUFFER_ARG); + edfct2->y[oloop][loop] = TARG; + ++arg; + } + } + for (oloop = 0; oloop < nin; ++oloop) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[oloop]; + for (loop = 0; loop < insz[oloop]; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS(ADOLC_EXT_FCT_V2_Z_LOOP, + ADJOINT_BUFFER_ARG); + edfct2->x[oloop][loop] = TARG; + ++arg; + } + } + ext_retc = edfct2->ADOLC_EXT_FCT_V2_COMPLETE; + MINDEC(ret_c, ext_retc); + for (oloop = 0; oloop < nout; ++oloop) { + res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2[oloop]; + for (loop = 0; loop < outsz[oloop]; ++loop) { + FOR_0_LE_l_LT_p { + ADJOINT_BUFFER_RES_L = 0.0; /* \bar{v}_i = 0 !!! */ } - case ampi_wait: { - BW_AMPI_Wait(&request, - status); - break; - } - case ampi_barrier: { - BW_AMPI_Barrier(comm); - break; - } - case ampi_gather: { - BW_AMPI_Gather(buf, - count, - datatype, - rbuf, - rcount, - rtype, - src, - comm); - break; - } - case ampi_scatter: { - BW_AMPI_Scatter(rbuf, - rcount, - rtype, - buf, - count, - datatype, - src, - comm); - break; - } - case ampi_allgather: { - BW_AMPI_Allgather(buf, - count, - datatype, - rbuf, - rcount, - rtype, - comm); - break; - } - case ampi_gatherv: { - BW_AMPI_Gatherv(buf, - count, - datatype, - rbuf, - NULL, - NULL, - rtype, - src, - comm); - break; - } - case ampi_scatterv: { - BW_AMPI_Scatterv(rbuf, - NULL, - NULL, - rtype, - buf, - count, - datatype, - src, - comm); - break; - } - case ampi_allgatherv: { - BW_AMPI_Allgatherv(buf, - count, - datatype, - rbuf, - NULL, - NULL, - rtype, - comm); - break; - } - case ampi_bcast: { - BW_AMPI_Bcast(buf, - count, - datatype, - src, - comm); - break; - } - case ampi_reduce: { - BWB_AMPI_Reduce(buf, - rbuf, - count, - datatype, - op, - src, - comm); - break; - } - case ampi_allreduce: { - BW_AMPI_Allreduce(buf, - rbuf, - count, - datatype, - op, - comm); - break; - } -#endif + ++res; + } + } + for (oloop = 0; oloop < nin; ++oloop) { + res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[oloop]; + for (loop = 0; loop < insz[oloop]; ++loop) { + ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(ADOLC_EXT_FCT_V2_Z_LOOP, + ADJOINT_BUFFER_RES); + ++res; + } + } + if (edfct2->dp_y_priorRequired) { + for (oloop = nout - 1; oloop >= 0; --oloop) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2[oloop] + + outsz[oloop] - 1; + for (loop = outsz[oloop] - 1; loop >= 0; --loop) { + ADOLC_GET_TAYLOR(arg); + --arg; + } + } + } + if (edfct2->dp_x_changes) { + for (oloop = nin - 1; oloop >= 0; --oloop) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[oloop] + + insz[oloop] - 1; + for (loop = insz[oloop] - 1; loop >= 0; --loop) { + ADOLC_GET_TAYLOR(arg); + --arg; + } + } + } + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; + free(iArr); + free(insz); + insz = 0; + iArr = 0; + outsz = 0; + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = 0; + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = 0; + break; + #ifdef ADOLC_MEDIPACK_SUPPORT + /*--------------------------------------------------------------------------*/ + case medi_call: { + locint mediIndex = get_locint_r(); + short tapeId = ADOLC_CURRENT_TAPE_INFOS.tapeID; + + #if defined _FOS_ + mediCallHandleReverse(tapeId, mediIndex, rp_T, &ADJOINT_BUFFER, 1); + #elif defined _FOV_ + mediCallHandleReverse(tapeId, mediIndex, rp_T, ADJOINT_BUFFER, p); + #endif + break; + } + #endif + #ifdef ADOLC_AMPI_SUPPORT + /*--------------------------------------------------------------------------*/ + case ampi_send: { + BW_AMPI_Send(buf, count, datatype, src, tag, pairedWith, comm); + break; + } + case ampi_recv: { + BW_AMPI_Recv(buf, count, datatype, src, tag, pairedWith, comm, status); + break; + } + case ampi_isend: { + BW_AMPI_Isend(buf, count, datatype, src, tag, pairedWith, comm, &request); + break; + } + case ampi_irecv: { + BW_AMPI_Irecv(buf, count, datatype, src, tag, pairedWith, comm, &request); + break; + } + case ampi_wait: { + BW_AMPI_Wait(&request, status); + break; + } + case ampi_barrier: { + BW_AMPI_Barrier(comm); + break; + } + case ampi_gather: { + BW_AMPI_Gather(buf, count, datatype, rbuf, rcount, rtype, src, comm); + break; + } + case ampi_scatter: { + BW_AMPI_Scatter(rbuf, rcount, rtype, buf, count, datatype, src, comm); + break; + } + case ampi_allgather: { + BW_AMPI_Allgather(buf, count, datatype, rbuf, rcount, rtype, comm); + break; + } + case ampi_gatherv: { + BW_AMPI_Gatherv(buf, count, datatype, rbuf, NULL, NULL, rtype, src, comm); + break; + } + case ampi_scatterv: { + BW_AMPI_Scatterv(rbuf, NULL, NULL, rtype, buf, count, datatype, src, + comm); + break; + } + case ampi_allgatherv: { + BW_AMPI_Allgatherv(buf, count, datatype, rbuf, NULL, NULL, rtype, comm); + break; + } + case ampi_bcast: { + BW_AMPI_Bcast(buf, count, datatype, src, comm); + break; + } + case ampi_reduce: { + BWB_AMPI_Reduce(buf, rbuf, count, datatype, op, src, comm); + break; + } + case ampi_allreduce: { + BW_AMPI_Allreduce(buf, rbuf, count, datatype, op, comm); + break; + } + #endif #endif /* !_INT_REV_ */ - /*--------------------------------------------------------------------------*/ - default: /* default */ - /* Die here, we screwed up */ - - fprintf(DIAG_OUT,"ADOL-C fatal error in " GENERATED_FILENAME " (" - __FILE__ - ") : no such operation %d\n", operation); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - break; - } /* endswitch */ - - /* Get the next operation */ - operation=get_op_r(); - } /* endwhile */ - - /* clean up */ + /*--------------------------------------------------------------------------*/ + default: /* default */ + /* Die here, we screwed up */ + + fprintf(DIAG_OUT, + "ADOL-C fatal error in " GENERATED_FILENAME " (" __FILE__ + ") : no such operation %d\n", + operation); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + break; + } /* endswitch */ + + /* Get the next operation */ + operation = get_op_r(); + } /* endwhile */ + + /* clean up */ #if !defined(_INT_REV_) - free(rp_T); + free(rp_T); #endif #ifdef _FOS_ - free(rp_A); + free(rp_A); #endif #ifdef _FOV_ - free(Aqo); - myfree2(rpp_A); + free(Aqo); + myfree2(rpp_A); #endif #ifdef _INT_REV_ - free(upp_A); + free(upp_A); #endif - ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; - end_sweep(); + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; + end_sweep(); - return ret_c; + return ret_c; } - /****************************************************************************/ /* THAT'S ALL */ diff --git a/ADOL-C/src/fortutils.c b/ADOL-C/src/fortutils.c index ac84a6417..1d6184383 100644 --- a/ADOL-C/src/fortutils.c +++ b/ADOL-C/src/fortutils.c @@ -3,14 +3,14 @@ File: fortutils.c Revision: $Id$ Contents: Internal tools to handle Fortran arrays - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #include @@ -21,51 +21,51 @@ BEGIN_C_DECLS /* */ /*--------------------------------------------------------------------------*/ -void spread1(int m, fdouble* x, double* X) { - int j; - for (j=0; j @@ -22,120 +22,121 @@ BEGIN_C_DECLS /* zos_forward_partx(tag, m, mdim[n], n, x[n][d], y[m]) */ /* (based on zos_forward) */ -int zos_forward_partx(short tag, int m, int n, int *ndim, double **x, double *y) { - double *x0; /* base point */ - int i,j,ind,sum_n, rc; +int zos_forward_partx(short tag, int m, int n, int *ndim, double **x, + double *y) { + double *x0; /* base point */ + int i, j, ind, sum_n, rc; - sum_n = 0; - for(i=0;i #undef _KEEP_ diff --git a/ADOL-C/src/fos_pl_forward.c b/ADOL-C/src/fos_pl_forward.c index 64423876a..deddf41ec 100644 --- a/ADOL-C/src/fos_pl_forward.c +++ b/ADOL-C/src/fos_pl_forward.c @@ -5,13 +5,13 @@ Contents: fos_an_forward (first-order-scalar abs-normal forward mode) Copyright (c) Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _FOS_ 1 +#define _FOS_ 1 #undef _KEEP_ #define _ABS_NORM_ 1 #include diff --git a/ADOL-C/src/fos_pl_reverse.c b/ADOL-C/src/fos_pl_reverse.c index 9aa9dabfe..2cb80abc7 100644 --- a/ADOL-C/src/fos_pl_reverse.c +++ b/ADOL-C/src/fos_pl_reverse.c @@ -3,13 +3,13 @@ File: fos_reverse.c Revision: $Id$ Contents: fos_reverse (first-order-scalar reverse mode) - + Copyright (c) Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _FOS_ 1 diff --git a/ADOL-C/src/fos_pl_sig_forward.c b/ADOL-C/src/fos_pl_sig_forward.c index dbcdae2ec..f06a396cb 100644 --- a/ADOL-C/src/fos_pl_sig_forward.c +++ b/ADOL-C/src/fos_pl_sig_forward.c @@ -5,13 +5,13 @@ Contents: fos_an_forward (first-order-scalar abs-normal forward mode) Copyright (c) Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _FOS_ 1 +#define _FOS_ 1 #undef _KEEP_ #define _ABS_NORM_SIG_ 1 #include diff --git a/ADOL-C/src/fos_pl_sig_reverse.c b/ADOL-C/src/fos_pl_sig_reverse.c index dba177216..d8e2372dd 100644 --- a/ADOL-C/src/fos_pl_sig_reverse.c +++ b/ADOL-C/src/fos_pl_sig_reverse.c @@ -3,13 +3,13 @@ File: fos_reverse.c Revision: $Id$ Contents: fos_reverse (first-order-scalar reverse mode) - + Copyright (c) Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _FOS_ 1 diff --git a/ADOL-C/src/fos_reverse.c b/ADOL-C/src/fos_reverse.c index dfb3ae853..9b5a3daf1 100644 --- a/ADOL-C/src/fos_reverse.c +++ b/ADOL-C/src/fos_reverse.c @@ -3,17 +3,16 @@ File: fos_reverse.c Revision: $Id$ Contents: fos_reverse (first-order-scalar reverse mode) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _FOS_ 1 #include #undef _FOS_ - diff --git a/ADOL-C/src/fov_forward.c b/ADOL-C/src/fov_forward.c index 1e01b0acf..c0d5c02be 100644 --- a/ADOL-C/src/fov_forward.c +++ b/ADOL-C/src/fov_forward.c @@ -3,17 +3,16 @@ File: fov_forward.c Revision: $Id$ Contents: fov_forward (first-order-vector forward mode) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _FOV_ 1 +#define _FOV_ 1 #undef _KEEP_ #include #undef _FOV_ - diff --git a/ADOL-C/src/fov_offset_forward.c b/ADOL-C/src/fov_offset_forward.c index 8cfabacf6..57592aec1 100644 --- a/ADOL-C/src/fov_offset_forward.c +++ b/ADOL-C/src/fov_offset_forward.c @@ -6,16 +6,15 @@ p-offset in arguments and taylors) Copyright (c) Sebastian Schlenkrich - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ -#define _FOV_ 1 +#define _FOV_ 1 #define _CHUNKED_ #undef _KEEP_ #include #undef _CHUNKED_ #undef _FOV_ - diff --git a/ADOL-C/src/fov_pl_forward.c b/ADOL-C/src/fov_pl_forward.c index ca61c2b28..f3795f36e 100644 --- a/ADOL-C/src/fov_pl_forward.c +++ b/ADOL-C/src/fov_pl_forward.c @@ -3,18 +3,17 @@ File: fov_an_forward.c Revision: $Id$ Contents: fov_an_forward (first-order-vector abs-normal forward mode) - + Copyright (c) Kshitij Kulshrestha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _FOV_ 1 +#define _FOV_ 1 #undef _KEEP_ #define _ABS_NORM_ 1 #include #undef _ABS_NORM_ #undef _FOV_ - diff --git a/ADOL-C/src/fov_pl_sig_forward.c b/ADOL-C/src/fov_pl_sig_forward.c index e88a7cb84..941281453 100644 --- a/ADOL-C/src/fov_pl_sig_forward.c +++ b/ADOL-C/src/fov_pl_sig_forward.c @@ -3,15 +3,15 @@ File: fov_an_forward.c Revision: $Id$ Contents: fov_an_forward (first-order-vector abs-normal forward mode) - + Copyright (c) Kshitij Kulshrestha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _FOV_ 1 +#define _FOV_ 1 #undef _KEEP_ #define _ABS_NORM_SIG_ 1 #include diff --git a/ADOL-C/src/fov_reverse.c b/ADOL-C/src/fov_reverse.c index e653b30c2..d48b0a6bf 100644 --- a/ADOL-C/src/fov_reverse.c +++ b/ADOL-C/src/fov_reverse.c @@ -3,17 +3,16 @@ File: fov_reverse.c Revision: $Id$ Contents: fov_reverse (first-order-vector reverse mode) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _FOV_ 1 #include #undef _FOV_ - diff --git a/ADOL-C/src/ho_rev.c b/ADOL-C/src/ho_rev.c index de1404e35..8f2a2918e 100644 --- a/ADOL-C/src/ho_rev.c +++ b/ADOL-C/src/ho_rev.c @@ -3,25 +3,25 @@ File: ho_rev.c Revision: $Id$ Contents: Contains the routines : - hos_reverse (higher-order-scalar reverse mode): + hos_reverse (higher-order-scalar reverse mode): define _HOS_ - hos_ov_reverse (higher-order-scalar reverse mode on vectors): + hos_ov_reverse (higher-order-scalar reverse mode on vectors): define _HOS_OV_ - hov_reverse (higher-order-vector reverse mode): + hov_reverse (higher-order-vector reverse mode): define _HOV_ - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel, Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ /***************************************************************************** - + There are four basic versions of the procedure `reverse', which are optimized for the cases of scalar or vector reverse sweeps with first or higher derivatives, respectively. In the calling @@ -29,27 +29,27 @@ parameters `lagrange' and `results'. The former may be left out and the integer parameters `depen', `indep', `degre', and `nrows' must be set or default according to the following matrix of - calling cases. - + calling cases. + no lagrange double* lagrange double** lagrange - -double* gradient of scalar weight vector times infeasible + +double* gradient of scalar weight vector times infeasible results valued function Jacobian product combination - - ( depen = 1 , ( depen > 0 , - degre = 0 , degre = 0 , ------ - nrows = 1 ) nrows = 1 ) - + + ( depen = 1 , ( depen > 0 , + degre = 0 , degre = 0 , ------ + nrows = 1 ) nrows = 1 ) + double** Jacobian of vector weight vector times weight matrix results valued function Taylor-Jacobians times Jacobian - - ( 0 < depen ( depen > 0 , ( depen > 0 , - = nrows , degre > 0 , degre = 0 , - degre = 0 ) nrows = 1 ) nrows > 0 ) - + + ( 0 < depen ( depen > 0 , ( depen > 0 , + = nrows , degre > 0 , degre = 0 , + degre = 0 ) nrows = 1 ) nrows > 0 ) + double*** full family of ------------ weight matrix x results Taylor-Jacobians ------------ Taylor Jacobians - + *****************************************************************************/ /****************************************************************************/ @@ -58,194 +58,198 @@ results Taylor-Jacobians ------------ Taylor Jacobians /*--------------------------------------------------------------------------*/ #ifdef _HOS_ -#define GENERATED_FILENAME "hos_reverse" + #define GENERATED_FILENAME "hos_reverse" -#define RESULTS(l,indexi,k) results[indexi][k] -#define LAGRANGE(l,indexd,k) lagrange[indexd][k] + #define RESULTS(l, indexi, k) results[indexi][k] + #define LAGRANGE(l, indexd, k) lagrange[indexd][k] -#define HOV_INC(T,degree) {} -#define HOS_OV_INC(T,degree) {} + #define HOV_INC(T, degree) \ + {} + #define HOS_OV_INC(T, degree) \ + {} -#define GET_TAYL(loc,depth,p) \ - { \ - UPDATE_TAYLORREAD(depth) \ - get_taylors(loc,depth); \ + #define GET_TAYL(loc, depth, p) \ + { \ + UPDATE_TAYLORREAD(depth) \ + get_taylors(loc, depth); \ } /*--------------------------------------------------------------------------*/ #elif _HOS_OV_ -#define GENERATED_FILENAME "hos_ov_reverse" + #define GENERATED_FILENAME "hos_ov_reverse" -#define RESULTS(l,indexi,k) results[l][indexi][k] -#define LAGRANGE(l,indexd,k) lagrange[indexd][k] + #define RESULTS(l, indexi, k) results[l][indexi][k] + #define LAGRANGE(l, indexd, k) lagrange[indexd][k] -#define HOV_INC(T,degree) T += degree; -#define HOS_OV_INC(T,degree) T += degree; + #define HOV_INC(T, degree) T += degree; + #define HOS_OV_INC(T, degree) T += degree; -#define GET_TAYL(loc,depth,p) \ - { \ - UPDATE_TAYLORREAD(depth * p) \ - get_taylors_p(loc,depth,p); \ + #define GET_TAYL(loc, depth, p) \ + { \ + UPDATE_TAYLORREAD(depth *p) \ + get_taylors_p(loc, depth, p); \ } /*--------------------------------------------------------------------------*/ #elif _HOV_ -#define GENERATED_FILENAME "hov_reverse" + #define GENERATED_FILENAME "hov_reverse" -#define _ADOLC_VECTOR_ + #define _ADOLC_VECTOR_ -#define RESULTS(l,indexi,k) results[l][indexi][k] -#define LAGRANGE(l,indexd,k) lagrange[l][indexd][k] + #define RESULTS(l, indexi, k) results[l][indexi][k] + #define LAGRANGE(l, indexd, k) lagrange[l][indexd][k] -#define IF_HOV_ -#define ENDIF_HOV_ + #define IF_HOV_ + #define ENDIF_HOV_ -#define HOV_INC(T,degree) T += degree; -#define HOS_OV_INC(T,degree) + #define HOV_INC(T, degree) T += degree; + #define HOS_OV_INC(T, degree) -#define GET_TAYL(loc,depth,p) \ - { \ - UPDATE_TAYLORREAD(depth) \ - get_taylors(loc,depth); \ + #define GET_TAYL(loc, depth, p) \ + { \ + UPDATE_TAYLORREAD(depth) \ + get_taylors(loc, depth); \ } #else -#error Error ! Define [_HOS_ | _HOS_OV_ | _HOV_] + #error Error ! Define [_HOS_ | _HOS_OV_ | _HOV_] #endif /*--------------------------------------------------------------------------*/ /* access to variables */ -#ifdef _FOS_ /* why?, not in fo_rev.c ? */ -#define ARES *Ares -#define AARG *Aarg -#define AARG1 *Aarg1 -#define AARG2 *Aarg2 -#define AQO *Aqo - -#define ARES_INC *Ares -#define AARG_INC *Aarg -#define AARG1_INC *Aarg1 -#define AARG2_INC *Aarg2 -#define AQO_INC *Aqo - -#define ARES_INC_O Ares -#define AARG_INC_O Aarg -#define AARG1_INC_O Aarg1 -#define AARG2_INC_O Aarg2 -#define AQO_INC_O Aqo - -#define ASSIGN_A(a,b) a = &b; -#define HOS_OV_ASSIGN_A(Aqo, rp_Atemp) -#define FOR_0_LE_l_LT_q l = 0; +#ifdef _FOS_ /* why?, not in fo_rev.c ? */ + #define ARES *Ares + #define AARG *Aarg + #define AARG1 *Aarg1 + #define AARG2 *Aarg2 + #define AQO *Aqo + + #define ARES_INC *Ares + #define AARG_INC *Aarg + #define AARG1_INC *Aarg1 + #define AARG2_INC *Aarg2 + #define AQO_INC *Aqo + + #define ARES_INC_O Ares + #define AARG_INC_O Aarg + #define AARG1_INC_O Aarg1 + #define AARG2_INC_O Aarg2 + #define AQO_INC_O Aqo + + #define ASSIGN_A(a, b) a = &b; + #define HOS_OV_ASSIGN_A(Aqo, rp_Atemp) + #define FOR_0_LE_l_LT_q l = 0; #elif _HOS_OV_ -#define ARES *Ares -#define AARG *Aarg -#define AARG1 *Aarg1 -#define AARG2 *Aarg2 -#define AQO *Aqo - -#define ARES_INC *Ares++ -#define AARG_INC *Aarg++ -#define AARG1_INC *Aarg1++ -#define AARG2_INC *Aarg2++ -#define AQO_INC *Aqo++ - -#define ARES_INC_O Ares++ -#define AARG_INC_O Aarg++ -#define AARG1_INC_O Aarg1++ -#define AARG2_INC_O Aarg2++ -#define AQO_INC_O Aqo++ - -#define ASSIGN_A(a,b) a = b; -#define HOS_OV_ASSIGN_A(a, b) a = b; -#define FOR_0_LE_l_LT_q for (int l=0;l=0; l--) /* why ? not used here */ + #define FOR_0_LE_l_LT_p for (int l = 0; l < p; l++) + #define FOR_p_GT_l_GE_0 \ + for (int l = p - 1; l >= 0; l--) /* why ? not used here */ #elif _HOS_OV_ -#define FOR_0_LE_l_LT_p for (int l=0; l -#include +#include "dvlparms.h" +#include "externfcts_p.h" #include "oplate.h" #include "taping_p.h" -#include -#include "externfcts_p.h" +#include #include -#include "dvlparms.h" +#include +#include #include #if defined(ADOLC_DEBUG) -#include + #include #endif /* ADOLC_DEBUG */ BEGIN_C_DECLS @@ -257,3156 +261,3138 @@ BEGIN_C_DECLS /***************************************************************************/ /* Higher Order Scalar Reverse Pass. */ /***************************************************************************/ -int hos_reverse(short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int degre, /* highest derivative degree */ - const double *lagrange, /* range weight vector */ - double **results) /* matrix of coefficient vectors */ +int hos_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int degre, /* highest derivative degree */ + const double *lagrange, /* range weight vector */ + double **results) /* matrix of coefficient vectors */ { - double** L = myalloc2(depen,degre+1); - for ( int i = 0; i < depen; ++i ) { - L[i][0] = lagrange[i]; - for ( int j = 1; j <= degre; ++j ) - L[i][j] = 0.0; - } - int rc = hos_ti_reverse(tnum,depen,indep,degre,L,results); - myfree2(L); - return rc; + double **L = myalloc2(depen, degre + 1); + for (int i = 0; i < depen; ++i) { + L[i][0] = lagrange[i]; + for (int j = 1; j <= degre; ++j) + L[i][j] = 0.0; + } + int rc = hos_ti_reverse(tnum, depen, indep, degre, L, results); + myfree2(L); + return rc; } -int hos_ti_reverse( - short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int degre, /* highest derivative degre */ - double **lagrange, /* range weight vectors */ - double **results) /* matrix of coefficient vectors */ +int hos_ti_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int degre, /* highest derivative degre */ + double **lagrange, /* range weight vectors */ + double **results) /* matrix of coefficient vectors */ #elif _HOS_OV_ /***************************************************************************/ /* Higher Order Scalar Reverse Pass, Vector Keep. */ /***************************************************************************/ -int hos_ov_reverse(short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int degre, /* highest derivative degre */ - int nrows, /* # of Jacobian rows calculated */ - double **lagrange, /* range weight vector */ - double ***results) /* matrix of coefficient vectors */ +int hos_ov_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int degre, /* highest derivative degre */ + int nrows, /* # of Jacobian rows calculated */ + double **lagrange, /* range weight vector */ + double ***results) /* matrix of coefficient vectors */ #elif _HOV_ /***************************************************************************/ /* Higher Order Vector Reverse Pass. */ /***************************************************************************/ -int hov_reverse(short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int degre, /* highest derivative degre */ - int nrows, /* # of Jacobian rows calculated */ - double **lagrange, /* domain weight vector */ - double ***results, /* matrix of coefficient vectors */ - short **nonzero ) /* structural sparsity pattern */ +int hov_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int degre, /* highest derivative degre */ + int nrows, /* # of Jacobian rows calculated */ + double **lagrange, /* domain weight vector */ + double ***results, /* matrix of coefficient vectors */ + short **nonzero) /* structural sparsity pattern */ { - double*** L = myalloc3(nrows,depen,degre+1); - for ( int k = 0; k < nrows; ++k ) - for ( int i = 0; i < depen; ++i ) { - L[k][i][0] = lagrange[k][i]; - for ( int j = 1; j <= degre; ++j ) - L[k][i][j] = 0.0; - } - int rc = hov_ti_reverse(tnum,depen,indep,degre,nrows,L,results,nonzero); - myfree3(L); - return rc; + double ***L = myalloc3(nrows, depen, degre + 1); + for (int k = 0; k < nrows; ++k) + for (int i = 0; i < depen; ++i) { + L[k][i][0] = lagrange[k][i]; + for (int j = 1; j <= degre; ++j) + L[k][i][j] = 0.0; + } + int rc = + hov_ti_reverse(tnum, depen, indep, degre, nrows, L, results, nonzero); + myfree3(L); + return rc; } -int hov_ti_reverse( - short tnum, /* tape id */ - int depen, /* consistency chk on # of deps */ - int indep, /* consistency chk on # of indeps */ - int degre, /* highest derivative degre */ - int nrows, /* # of Jacobian rows calculated */ - double ***lagrange, /* domain weight vectors */ - double ***results, /* matrix of coefficient vectors */ - short **nonzero ) /* structural sparsity pattern */ +int hov_ti_reverse(short tnum, /* tape id */ + int depen, /* consistency chk on # of deps */ + int indep, /* consistency chk on # of indeps */ + int degre, /* highest derivative degre */ + int nrows, /* # of Jacobian rows calculated */ + double ***lagrange, /* domain weight vectors */ + double ***results, /* matrix of coefficient vectors */ + short **nonzero) /* structural sparsity pattern */ #endif { - /************************************************************************/ - /* ALL VARIABLES */ - unsigned char operation; /* operation code */ - int dc, ret_c=3; - - locint size = 0; - locint res = 0; - locint arg = 0; - locint arg1 = 0; - locint arg2 = 0; - - double coval = 0; - - int indexi = 0, indexd = 0; - - /* other necessary variables */ - double *x; - int *jj; - int taycheck; - int numdep,numind; - - /*----------------------------------------------------------------------*/ - /* Taylor stuff */ - revreal *Tres, *Targ, *Targ1, *Targ2, *Tqo, *rp_Ttemp, *rp_Ttemp2; - revreal **rpp_T; - - /*----------------------------------------------------------------------*/ - /* Adjoint stuff */ - revreal *Ares, *Aarg=NULL, *Aarg1, *Aarg2, *Aqo, *rp_Atemp, *rp_Atemp2; - revreal **rpp_A, *AP1, *AP2; - - /*----------------------------------------------------------------------*/ - const int k = degre + 1; - const int k1 = k + 1; - revreal comp; + /************************************************************************/ + /* ALL VARIABLES */ + unsigned char operation; /* operation code */ + int dc, ret_c = 3; + + locint size = 0; + locint res = 0; + locint arg = 0; + locint arg1 = 0; + locint arg2 = 0; + + double coval = 0; + + int indexi = 0, indexd = 0; + + /* other necessary variables */ + double *x; + int *jj; + int taycheck; + int numdep, numind; + + /*----------------------------------------------------------------------*/ + /* Taylor stuff */ + revreal *Tres, *Targ, *Targ1, *Targ2, *Tqo, *rp_Ttemp, *rp_Ttemp2; + revreal **rpp_T; + + /*----------------------------------------------------------------------*/ + /* Adjoint stuff */ + revreal *Ares, *Aarg = NULL, *Aarg1, *Aarg2, *Aqo, *rp_Atemp, *rp_Atemp2; + revreal **rpp_A, *AP1, *AP2; + + /*----------------------------------------------------------------------*/ + const int k = degre + 1; + const int k1 = k + 1; + revreal comp; #ifdef _ADOLC_VECTOR_ - const int p = nrows; + const int p = nrows; #endif - /****************************************************************************/ - /* extern diff. function variables */ + /****************************************************************************/ + /* extern diff. function variables */ #if defined(_HOS_) -# define ADOLC_EXT_FCT_U dpp_U -# define ADOLC_EXT_FCT_Z dpp_Z -# define ADOLC_EXT_FCT_POINTER hos_ti_reverse -# define ADOLC_EXT_FCT_COMPLETE \ - hos_ti_reverse(m, dpp_U, n, degre, dpp_Z, dpp_x, dpp_y) + #define ADOLC_EXT_FCT_U dpp_U + #define ADOLC_EXT_FCT_Z dpp_Z + #define ADOLC_EXT_FCT_POINTER hos_ti_reverse + #define ADOLC_EXT_FCT_COMPLETE \ + hos_ti_reverse(m, dpp_U, n, degre, dpp_Z, dpp_x, dpp_y) #else -# define ADOLC_EXT_FCT_U dppp_U -# define ADOLC_EXT_FCT_Z dppp_Z -# define ADOLC_EXT_FCT_POINTER hov_reverse -# define ADOLC_EXT_FCT_COMPLETE \ - hov_reverse(m, p, edfct->dpp_U, n, degre, edfct->dppp_Z, edfct->spp_nz) + #define ADOLC_EXT_FCT_U dppp_U + #define ADOLC_EXT_FCT_Z dppp_Z + #define ADOLC_EXT_FCT_POINTER hov_reverse + #define ADOLC_EXT_FCT_COMPLETE \ + hov_reverse(m, p, edfct->dpp_U, n, degre, edfct->dppp_Z, edfct->spp_nz) #endif #ifdef _HOV_ - const int pk1 = p*k1; - const int q = 1; + const int pk1 = p * k1; + const int q = 1; #elif _HOS_OV_ - const int p = nrows; - const int pk1 = p*k1; - const int q = p; + const int p = nrows; + const int pk1 = p * k1; + const int q = p; #else - const int q = 1; + const int q = 1; #endif - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; #if defined(ADOLC_DEBUG) - /************************************************************************/ - /* DEBUG MESSAGES */ - fprintf(DIAG_OUT,"Call of %s(..) with tag: %d, n: %d, m %d,\n", - GENERATED_FILENAME, tnum, indep, depen); + /************************************************************************/ + /* DEBUG MESSAGES */ + fprintf(DIAG_OUT, "Call of %s(..) with tag: %d, n: %d, m %d,\n", + GENERATED_FILENAME, tnum, indep, depen); - fprintf(DIAG_OUT," degree: %d\n",degre); -#ifdef _ADOLC_VECTOR_ - fprintf(DIAG_OUT," p: %d\n\n",nrows); -#endif + fprintf(DIAG_OUT, " degree: %d\n", degre); + #ifdef _ADOLC_VECTOR_ + fprintf(DIAG_OUT, " p: %d\n\n", nrows); + #endif #endif - - /************************************************************************/ - /* INITs */ - - /*----------------------------------------------------------------------*/ - /* Set up stuff for the tape */ - - /* Initialize the Reverse Sweep */ - init_rev_sweep(tnum); - - if ( (depen != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS]) || - (indep != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]) ) - fail(ADOLC_REVERSE_COUNTS_MISMATCH); - - indexi = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS] - 1; - indexd = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS] - 1; - - - /************************************************************************/ - /* MEMORY ALLOCATION STUFF */ - - /*----------------------------------------------------------------------*/ -#ifdef _HOS_ /* HOS */ - rpp_A = (revreal**)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * - sizeof(revreal*)); - if (rpp_A == NULL) fail(ADOLC_MALLOC_FAILED); - Aqo = (revreal*)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * k1 * - sizeof(revreal)); - if (Aqo == NULL) fail(ADOLC_MALLOC_FAILED); - for (int i=0; i%i," - " keep=%i!\n",degre,degre+1); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); - }; - - if((numdep != depen)||(numind != indep)) { - fprintf(DIAG_OUT,"\n ADOL-C error: reverse fails on tape %d because " - "the number of\nindependent and/or dependent variables" - " given to reverse are\ninconsistent with that of the" - " internal taylor array.\n",tnum); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); - } - - - /************************************************************************/ - /* REVERSE SWEEP */ + rp_Ttemp = (revreal *)malloc(k * sizeof(revreal)); + if (rp_Ttemp == NULL) + fail(ADOLC_MALLOC_FAILED); + if (rp_Ttemp2 == NULL) + fail(ADOLC_MALLOC_FAILED); + x = myalloc1(q); + jj = (int *)malloc(q * sizeof(int)); + if (jj == NULL) + fail(ADOLC_MALLOC_FAILED); + + /************************************************************************/ + /* TAYLOR INITIALIZATION */ + ADOLC_CURRENT_TAPE_INFOS.rpp_A = rpp_A; + ADOLC_CURRENT_TAPE_INFOS.rpp_T = rpp_T; + taylor_back(tnum, &numdep, &numind, &taycheck); + + if (taycheck != degre) { + fprintf(DIAG_OUT, + "\n ADOL-C error: reverse fails because it was not" + " preceded\nby a forward sweep with degree>%i," + " keep=%i!\n", + degre, degre + 1); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + }; + + if ((numdep != depen) || (numind != indep)) { + fprintf(DIAG_OUT, + "\n ADOL-C error: reverse fails on tape %d because " + "the number of\nindependent and/or dependent variables" + " given to reverse are\ninconsistent with that of the" + " internal taylor array.\n", + tnum); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + } + + /************************************************************************/ + /* REVERSE SWEEP */ #if defined(ADOLC_DEBUG) - int v = 0; - unsigned int countPerOperation[256], taylorPerOperation[256]; - memset(countPerOperation, 0, 1024); - memset(taylorPerOperation, 0, 1024); -# define UPDATE_TAYLORREAD(X) taylorPerOperation[operation] += X; + int v = 0; + unsigned int countPerOperation[256], taylorPerOperation[256]; + memset(countPerOperation, 0, 1024); + memset(taylorPerOperation, 0, 1024); + #define UPDATE_TAYLORREAD(X) taylorPerOperation[operation] += X; #else -# define UPDATE_TAYLORREAD(X) + #define UPDATE_TAYLORREAD(X) #endif /* ADOLC_DEBUG */ - operation=get_op_r(); + operation = get_op_r(); #if defined(ADOLC_DEBUG) - ++countPerOperation[operation]; + ++countPerOperation[operation]; #endif /* ADOLC_DEBUG */ - while (operation != start_of_tape) { - /* Switch statement to execute the operations in Reverse */ - switch (operation) { - - - /************************************************************/ - /* MARKERS */ - - /*----------------------------------------------------------*/ - case end_of_op: /* end_of_op */ - get_op_block_r(); - operation = get_op_r(); - /* Skip next operation, it's another end_of_op */ - break; - - /*----------------------------------------------------------*/ - case end_of_int: /* end_of_int */ - get_loc_block_r(); /* Get the next int block */ - break; - - /*----------------------------------------------------------*/ - case end_of_val: /* end_of_val */ - get_val_block_r(); /* Get the next val block */ - break; - - /*----------------------------------------------------------*/ - case start_of_tape: /* start_of_tape */ - break; - case end_of_tape: /* end_of_tape */ - discard_params_r(); - break; - - - /************************************************************/ - /* COMPARISON */ - - /*----------------------------------------------------------*/ - case eq_zero : /* eq_zero */ - arg = get_locint_r(); - - ret_c = 0; - break; - - /*----------------------------------------------------------*/ - case neq_zero : /* neq_zero */ - case gt_zero : /* gt_zero */ - case lt_zero : /* lt_zero */ - arg = get_locint_r(); - break; - - /*----------------------------------------------------------*/ - case ge_zero : /* ge_zero */ - case le_zero : /* le_zero */ - arg = get_locint_r(); - - if (*rpp_T[arg] == 0) - ret_c = 0; - break; - - - /************************************************************/ - /* ASSIGNMENTS */ - - /*----------------------------------------------------------*/ - case assign_a: /* assign an adouble variable an assign_a */ - /* adouble value. (=) */ - res = get_locint_r(); - arg = get_locint_r(); - - ASSIGN_A(Aarg, rpp_A[arg]) - ASSIGN_A(Ares, rpp_A[res]) - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Aarg, k1) - HOV_INC(Ares, k1) - } else { - MAXDEC(AARG,ARES); - AARG_INC_O; - ARES_INC = 0.0; - for (int i=0; i>=) */ - res = get_locint_r(); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[res]) /* just a helpful pointers */ - - FOR_0_LE_l_LT_p - { ARES_INC_O; - dc = -1; - for (int i=0; i 0)? 2.0 : 1.0; - HOV_INC(Aarg, k1) - } - indexd--; - break; - - - /****************************************************************************/ - /* OPERATION + ASSIGNMENT */ - - /*--------------------------------------------------------------------------*/ - case eq_plus_d: /* Add a floating point to an eq_plus_d */ - /* adouble. (+=) */ - res = get_locint_r(); - coval = get_val_r(); - - GET_TAYL(res,k,p) - break; - - /*--------------------------------------------------------------------------*/ - case eq_plus_p: /* Add a floating point to an eq_plus_p */ - /* adouble. (+=) */ - res = get_locint_r(); - arg = get_locint_r(); - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; - - GET_TAYL(res,k,p) - break; - - /*--------------------------------------------------------------------------*/ - case eq_plus_a: /* Add an adouble to another eq_plus_a */ - /* adouble. (+=) */ - res = get_locint_r(); - arg = get_locint_r(); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]); - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg, k1) - } else { - MAXDEC(AARG,ARES); - AARG_INC_O; - ARES_INC_O; - for (int i=0; i 2.0) ? ARES : 2.0 ; - ARES_INC = 0.0; - MAXDEC(AARG1,comp); - MAXDEC(AARG2,comp); - /* Skip first value of input: these again represent - functional relation. */ - AARG1_INC_O; - AARG2_INC_O; - - /* Copy to a temporary variables in case one of the - arguments uses the same storage as the result. */ - copyAndZeroset(k,Ares,rp_Atemp); - - // Aarg2 += convolution of rp_Atemp with Targ1 - inconv(k,rp_Atemp,Targ1,Aarg2); - - // Aarg1 += convolution of rp_Atemp with Targ2 - inconv(k,rp_Atemp,Targ2,Aarg1); - - /* Vector mode: update pointers for next loop iteration - (see loop above) */ - HOV_INC(Ares, k) - HOV_INC(Aarg1, k) - HOV_INC(Aarg2, k) - HOS_OV_INC(Targ1, k) - HOS_OV_INC(Targ2, k) - } - break; - - /*--------------------------------------------------------------------------*/ - /* olvo 991122: new op_code with recomputation */ - case eq_plus_prod: /* increment a product of eq_plus_prod */ - /* two adoubles (*) */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg2, rpp_A[arg2]) - ASSIGN_A(Aarg1, rpp_A[arg1]) - Targ1 = rpp_T[arg1]; - Targ2 = rpp_T[arg2]; - - /* RECOMPUTATION */ - Tres = rpp_T[res]; + ARES_INC_O; + for (int i = 0; i < k; i++) + RESULTS(l, indexi, i) = ARES_INC; + } + + GET_TAYL(res, k, p) + indexi--; + break; + + /*--------------------------------------------------------------------------*/ + case assign_dep: /* assign a float variable a assign_dep */ + /* dependent adouble value. (>>=) */ + res = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[res]) /* just a helpful pointers */ + + FOR_0_LE_l_LT_p { + ARES_INC_O; + dc = -1; + for (int i = 0; i < k; i++) { + ARES_INC = LAGRANGE(l, indexd, i); + if (LAGRANGE(l, indexd, i)) + dc = i; + } + AARG = (dc < 0) ? 0.0 : (dc > 0) ? 2.0 : 1.0; + HOV_INC(Aarg, k1) + } + indexd--; + break; + + /****************************************************************************/ + /* OPERATION + + * ASSIGNMENT */ + + /*--------------------------------------------------------------------------*/ + case eq_plus_d: /* Add a floating point to an eq_plus_d */ + /* adouble. (+=) */ + res = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case eq_plus_p: /* Add a floating point to an eq_plus_p */ + /* adouble. (+=) */ + res = get_locint_r(); + arg = get_locint_r(); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case eq_plus_a: /* Add an adouble to another eq_plus_a */ + /* adouble. (+=) */ + res = get_locint_r(); + arg = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]); + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + MAXDEC(AARG, ARES); + AARG_INC_O; + ARES_INC_O; + for (int i = 0; i < k; i++) + AARG_INC += ARES_INC; + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case eq_min_d: /* Subtract a floating point from an eq_min_d */ + /* adouble. (-=) */ + res = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case eq_min_p: /* Subtract a floating point from an eq_min_p */ + /* adouble. (-=) */ + res = get_locint_r(); + arg = get_locint_r(); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case eq_min_a: /* Subtract an adouble from another eq_min_a */ + /* adouble. (-=) */ + res = get_locint_r(); + arg = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + MAXDEC(AARG, ARES); + AARG_INC_O; + ARES_INC_O; + for (int i = 0; i < k; i++) + AARG_INC -= ARES_INC; + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case eq_mult_d: /* Multiply an adouble by a eq_mult_d */ + /* floating point. (*=) */ + res = get_locint_r(); + coval = get_val_r(); + + ASSIGN_A(Ares, rpp_A[res]) + + FOR_0_LE_l_LT_p if (0 == ARES_INC) + HOV_INC(Ares, k) else for (int i = 0; i < k; i++) ARES_INC *= coval; + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case eq_mult_p: /* Multiply an adouble by a eq_mult_p */ + /* floating point. (*=) */ + res = get_locint_r(); + arg = get_locint_r(); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + + ASSIGN_A(Ares, rpp_A[res]) + + FOR_0_LE_l_LT_p if (0 == ARES_INC) + HOV_INC(Ares, k) else for (int i = 0; i < k; i++) ARES_INC *= coval; + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case eq_mult_a: /* Multiply one adouble by another eq_mult_a */ + /* (*=) */ + res = get_locint_r(); + arg = get_locint_r(); + + GET_TAYL(res, k, p) + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + ASSIGN_A(Aqo, rp_Atemp) + Tres = rpp_T[res]; + Targ = rpp_T[arg]; + + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } else { + MAXDEC(ARES, 2.0); + MAXDEC(AARG, ARES); + AARG_INC_O; + ARES_INC_O; + conv(k, Ares, Targ, rp_Atemp); + if (arg != res) { + inconv(k, Ares, Tres, Aarg); + for (int i = 0; i < k; i++) + ARES_INC = AQO_INC; + } else + for (int i = 0; i < k; i++) + ARES_INC = 2.0 * AQO_INC; + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + HOS_OV_INC(Targ, k) + HOS_OV_ASSIGN_A(Aqo, rp_Atemp) + } + } + break; + + /*--------------------------------------------------------------------------*/ + case incr_a: /* Increment an adouble incr_a */ + case decr_a: /* Increment an adouble decr_a */ + res = get_locint_r(); + + GET_TAYL(res, k, p) + break; + + /****************************************************************************/ + /* BINARY + * OPERATIONS */ + + /*--------------------------------------------------------------------------*/ + case plus_a_a: /* : Add two adoubles. (+) plus a_a */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG1, aTmp); + MAXDEC(AARG2, aTmp); + AARG2_INC_O; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG1_INC += aTmp; + AARG2_INC += aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case plus_a_p: /* Add an adouble and a double plus_a_p */ + case min_a_p: /* Subtract an adouble from a min_a_p */ + /* (+) */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + AARG_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG_INC += aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case plus_d_a: /* Add an adouble and a double plus_d_a */ + /* (+) */ + res = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + AARG_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG_INC += aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case min_a_a: /* Subtraction of two adoubles min_a_a */ + /* (-) */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG1, aTmp); + MAXDEC(AARG2, aTmp); + AARG2_INC_O; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG1_INC += aTmp; + AARG2_INC -= aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case min_d_a: /* Subtract an adouble from a min_d_a */ + /* double (-) */ + res = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + AARG_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG_INC -= aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case mult_a_a: /* Multiply two adoubles (*) mult_a_a */ + /* Obtain indices for result and argument variables. */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + /* Read Taylor polynomial into rpp_T. */ + GET_TAYL(res, k, p) + + /* Set pointer to result and argument variables. */ + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + + /* Set pointer to Taylor polynomial for argument variables. */ + Targ1 = rpp_T[arg1]; + Targ2 = rpp_T[arg2]; + + /* Loop over all input weight vectors (in vector mode). + In scalar mode this loop is trivial. */ + FOR_0_LE_l_LT_p if (0 == ARES) { + /* This branch is taken if the input of this operation is independent of + * the independent variables. For example if it is some constant that + * happens to be stored as an adouble. The derivative of that is zero. + */ + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + HOV_INC(Ares, k1) + } + else { + /* The output includes the functional relation between + input and output. For multiplication this is at + least polynomial unless the input already has a more + generic relation on its own inputs (e.g., rational, + trancendental or non-smooth). + See the parameter `nz` of `hov_reverse` and the table of values in + page 44 of the manual. + */ + comp = (ARES > 2.0) ? ARES : 2.0; + ARES_INC = 0.0; + MAXDEC(AARG1, comp); + MAXDEC(AARG2, comp); + /* Skip first value of input: these again represent + functional relation. */ + AARG1_INC_O; + AARG2_INC_O; + + /* Copy to a temporary variables in case one of the + arguments uses the same storage as the result. */ + copyAndZeroset(k, Ares, rp_Atemp); + + // Aarg2 += convolution of rp_Atemp with Targ1 + inconv(k, rp_Atemp, Targ1, Aarg2); + + // Aarg1 += convolution of rp_Atemp with Targ2 + inconv(k, rp_Atemp, Targ2, Aarg1); + + /* Vector mode: update pointers for next loop iteration + (see loop above) */ + HOV_INC(Ares, k) + HOV_INC(Aarg1, k) + HOV_INC(Aarg2, k) + HOS_OV_INC(Targ1, k) + HOS_OV_INC(Targ2, k) + } + break; + + /*--------------------------------------------------------------------------*/ + /* olvo 991122: new op_code with recomputation */ + case eq_plus_prod: /* increment a product of eq_plus_prod */ + /* two adoubles (*) */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + Targ1 = rpp_T[arg1]; + Targ2 = rpp_T[arg2]; + + /* RECOMPUTATION */ + Tres = rpp_T[res]; #if !defined(_HOS_OV_) - deconv1(k,Targ1,Targ2,Tres); + deconv1(k, Targ1, Targ2, Tres); #endif - FOR_0_LE_l_LT_p { + FOR_0_LE_l_LT_p { #if defined(_HOS_OV_) - deconv1(k,Targ1,Targ2,Tres); + deconv1(k, Targ1, Targ2, Tres); #endif - if (0 == ARES) { - HOV_INC(Aarg1, k1) - HOV_INC(Aarg2, k1) - HOV_INC(Ares, k1) - } else { - comp = (ARES > 2.0) ? ARES : 2.0 ; - ARES_INC = comp; - MAXDEC(AARG1,comp); - MAXDEC(AARG2,comp); - AARG1_INC_O; - AARG2_INC_O; - - inconv(k,Ares,Targ1,Aarg2); - inconv(k,Ares,Targ2,Aarg1); - - HOV_INC(Ares, k) - HOV_INC(Aarg1, k) - HOV_INC(Aarg2, k) - HOS_OV_INC(Targ1, k) - HOS_OV_INC(Targ2, k) - HOS_OV_INC(Tres, k) - } - } - break; - - /*--------------------------------------------------------------------------*/ - /* olvo 991122: new op_code with recomputation */ - case eq_min_prod: /* decrement a product of eq_min_prod */ - /* two adoubles (*) */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg2, rpp_A[arg2]) - ASSIGN_A(Aarg1, rpp_A[arg1]) - Targ1 = rpp_T[arg1]; - Targ2 = rpp_T[arg2]; - - /* RECOMPUTATION */ - Tres = rpp_T[res]; + if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + HOV_INC(Ares, k1) + } else { + comp = (ARES > 2.0) ? ARES : 2.0; + ARES_INC = comp; + MAXDEC(AARG1, comp); + MAXDEC(AARG2, comp); + AARG1_INC_O; + AARG2_INC_O; + + inconv(k, Ares, Targ1, Aarg2); + inconv(k, Ares, Targ2, Aarg1); + + HOV_INC(Ares, k) + HOV_INC(Aarg1, k) + HOV_INC(Aarg2, k) + HOS_OV_INC(Targ1, k) + HOS_OV_INC(Targ2, k) + HOS_OV_INC(Tres, k) + } + } + break; + + /*--------------------------------------------------------------------------*/ + /* olvo 991122: new op_code with recomputation */ + case eq_min_prod: /* decrement a product of eq_min_prod */ + /* two adoubles (*) */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + Targ1 = rpp_T[arg1]; + Targ2 = rpp_T[arg2]; + + /* RECOMPUTATION */ + Tres = rpp_T[res]; #if !defined(_HOS_OV_) - inconv1(k,Targ1,Targ2,Tres); + inconv1(k, Targ1, Targ2, Tres); #endif - FOR_0_LE_l_LT_p { + FOR_0_LE_l_LT_p { #if defined(_HOS_OV_) - inconv1(k,Targ1,Targ2,Tres); + inconv1(k, Targ1, Targ2, Tres); #endif - if (0 == ARES) { - HOV_INC(Aarg1, k1) - HOV_INC(Aarg2, k1) - HOV_INC(Ares, k1) - } else { - comp = (ARES > 2.0) ? ARES : 2.0 ; - ARES_INC = comp; - MAXDEC(AARG1,comp); - MAXDEC(AARG2,comp); - AARG1_INC_O; - AARG2_INC_O; - - deconv1(k,Ares,Targ1,Aarg2); - deconv1(k,Ares,Targ2,Aarg1); - - HOV_INC(Ares, k) - HOV_INC(Aarg1, k) - HOV_INC(Aarg2, k) - HOS_OV_INC(Targ1, k) - HOS_OV_INC(Targ2, k) - HOS_OV_INC(Tres, k) + if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + HOV_INC(Ares, k1) + } else { + comp = (ARES > 2.0) ? ARES : 2.0; + ARES_INC = comp; + MAXDEC(AARG1, comp); + MAXDEC(AARG2, comp); + AARG1_INC_O; + AARG2_INC_O; + + deconv1(k, Ares, Targ1, Aarg2); + deconv1(k, Ares, Targ2, Aarg1); + + HOV_INC(Ares, k) + HOV_INC(Aarg1, k) + HOV_INC(Aarg2, k) + HOS_OV_INC(Targ1, k) + HOS_OV_INC(Targ2, k) + HOS_OV_INC(Tres, k) + } + } + break; + + /*--------------------------------------------------------------------------*/ + case mult_d_a: /* Multiply an adouble by a double mult_d_a */ + /* (*) */ + res = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + AARG_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG_INC += coval * aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case mult_a_p: /* Multiply an adouble by a double mult_a_p */ + /* (*) */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + AARG_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG_INC += coval * aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case div_a_a: /* Divide an adouble by an adouble div_a_a */ + /* (/) */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + Tres = rpp_T[res]; + Targ2 = rpp_T[arg2]; + + /* olvo 980922 allows reflexive operation */ + if (arg2 == res) { + FOR_0_LE_l_LT_pk rp_Ttemp2[l] = Tres[l]; + Tres = rp_Ttemp2; + GET_TAYL(res, k, p) + } + + VEC_COMPUTED_INIT + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG1, 3.0); + MAXDEC(AARG1, aTmp); + MAXDEC(AARG2, 3.0); + MAXDEC(AARG2, aTmp); + AARG1_INC_O; + AARG2_INC_O; + + VEC_COMPUTED_CHECK + recipr(k, 1.0, Targ2, rp_Ttemp); + conv0(k, rp_Ttemp, Tres, rp_Atemp2); + VEC_COMPUTED_END + copyAndZeroset(k, Ares, rp_Atemp); + inconv(k, rp_Atemp, rp_Ttemp, Aarg1); + deconv(k, rp_Atemp, rp_Atemp2, Aarg2); + + HOV_INC(Ares, k) + HOV_INC(Aarg1, k) + HOV_INC(Aarg2, k) + HOS_OV_INC(Tres, k) + HOS_OV_INC(Targ2, k) + } + } + + if (res != arg2) + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case div_d_a: /* Division double - adouble (/) div_d_a */ + res = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + Tres = rpp_T[res]; + Targ = rpp_T[arg]; + + /* olvo 980922 allows reflexive operation */ + if (arg == res) { + FOR_0_LE_l_LT_pk rp_Ttemp2[l] = Tres[l]; + Tres = rp_Ttemp2; + GET_TAYL(arg, k, p) + } + + VEC_COMPUTED_INIT + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + MAXDEC(AARG, 3.0); + AARG_INC_O; + + VEC_COMPUTED_CHECK + recipr(k, 1.0, Targ, rp_Ttemp); + conv0(k, rp_Ttemp, Tres, rp_Atemp); + VEC_COMPUTED_END + deconv0(k, Ares, rp_Atemp, Aarg); + + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + HOS_OV_INC(Targ, k) + } + } + + if (arg != res) + GET_TAYL(res, k, p) + break; + + /****************************************************************************/ + case div_p_a: /* Division double - adouble (/) div_p_a */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + Tres = rpp_T[res]; + Targ = rpp_T[arg]; + + /* olvo 980922 allows reflexive operation */ + if (arg == res) { + FOR_0_LE_l_LT_pk rp_Ttemp2[l] = Tres[l]; + Tres = rp_Ttemp2; + GET_TAYL(arg, k, p) + } + + VEC_COMPUTED_INIT + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + MAXDEC(AARG, 3.0); + AARG_INC_O; + + VEC_COMPUTED_CHECK + recipr(k, 1.0, Targ, rp_Ttemp); + conv0(k, rp_Ttemp, Tres, rp_Atemp); + VEC_COMPUTED_END + deconv0(k, Ares, rp_Atemp, Aarg); + + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + HOS_OV_INC(Targ, k) + } + } + + if (arg != res) + GET_TAYL(res, k, p) + break; + + /****************************************************************************/ + /* SIGN OPERATIONS + */ + + /*--------------------------------------------------------------------------*/ + case pos_sign_a: /* pos_sign_a */ + res = get_locint_r(); + arg = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + AARG_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG_INC += aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case neg_sign_a: /* neg_sign_a */ + res = get_locint_r(); + arg = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + AARG_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG_INC -= aTmp; + } + } + + GET_TAYL(res, k, p) + break; + + /****************************************************************************/ + /* UNARY + * OPERATIONS */ + + /*--------------------------------------------------------------------------*/ + case exp_op: /* exponent operation exp_op */ + res = get_locint_r(); + arg = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + Tres = rpp_T[res]; + Targ = rpp_T[arg]; + + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + MAXDEC(AARG, 4.0); + AARG_INC_O; + + inconv0(k, Ares, Tres, Aarg); + + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + } + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case sin_op: /* sine operation sin_op */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + Targ2 = rpp_T[arg2]; + + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Ares, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG1, aTmp); + MAXDEC(AARG1, 4.0); + AARG1_INC_O; + + inconv0(k, Ares, Targ2, Aarg1); + + HOV_INC(Ares, k) + HOV_INC(Aarg1, k) + HOS_OV_INC(Targ2, k) + } + } + + GET_TAYL(res, k, p) + GET_TAYL(arg2, k, p) /* olvo 980710 covalue */ + /* NOTE: rpp_A[arg2] should be 0 already */ + break; + + /*--------------------------------------------------------------------------*/ + case cos_op: /* cosine operation cos_op */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + Targ2 = rpp_T[arg2]; + + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Ares, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG1, aTmp); + MAXDEC(AARG1, 4.0); + AARG1_INC_O; + + deconv0(k, Ares, Targ2, Aarg1); + + HOV_INC(Ares, k) + HOV_INC(Aarg1, k) + HOS_OV_INC(Targ2, k) + } + } + + GET_TAYL(res, k, p) + GET_TAYL(arg2, k, p) /* olvo 980710 covalue */ + /* NOTE: rpp_A[arg2] should be 0 already */ + break; + /*xxx*/ + /*--------------------------------------------------------------------------*/ + case atan_op: /* atan_op */ + case asin_op: /* asin_op */ + case acos_op: /* acos_op */ + case asinh_op: /* asinh_op */ + case acosh_op: /* acosh_op */ + case atanh_op: /* atanh_op */ + case erf_op: /* erf_op */ + case erfc_op: /* erfc_op */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + GET_TAYL(res, k, p) + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + Targ2 = rpp_T[arg2]; + + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Ares, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG1, aTmp); + MAXDEC(AARG1, 4.0); + AARG1_INC_O; + + inconv0(k, Ares, Targ2, Aarg1); + + HOV_INC(Aarg1, k) + HOV_INC(Ares, k) + HOS_OV_INC(Targ2, k) + } + } + break; + + /*--------------------------------------------------------------------------*/ + case log_op: /* log_op */ + res = get_locint_r(); + arg = get_locint_r(); + + GET_TAYL(res, k, p) + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + Targ = rpp_T[arg]; + + VEC_COMPUTED_INIT + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + MAXDEC(AARG, 4.0); + AARG_INC_O; + + VEC_COMPUTED_CHECK + recipr(k, 1.0, Targ, rp_Ttemp); + VEC_COMPUTED_END + inconv0(k, Ares, rp_Ttemp, Aarg); + + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Targ, k) + } + } + break; + + /*--------------------------------------------------------------------------*/ + case pow_op: /* pow_op */ + res = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + Targ = rpp_T[arg]; + Tres = rpp_T[res]; + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + /* olvo 980921 allows reflexive operation */ + if (arg == res) { + FOR_0_LE_l_LT_pk rp_Ttemp2[l] = Tres[l]; + Tres = rp_Ttemp2; + GET_TAYL(arg, k, p) + } + + VEC_COMPUTED_INIT + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + MAXDEC(AARG, 4.0); + AARG_INC_O; + + VEC_COMPUTED_CHECK + if (fabs(Targ[0]) > ADOLC_EPS) { + divide(k, Tres, Targ, rp_Ttemp); + for (int i = 0; i < k; i++) { + rp_Ttemp[i] *= coval; + /* printf(" EPS i %d %f\n",i,rp_Ttemp[i]); */ + } + inconv0(k, Ares, rp_Ttemp, Aarg); + } else { + if (coval <= 0.0) { + for (int i = 0; i < k; i++) { + Aarg[i] = make_nan(); + Ares[i] = 0; + } + } else { + /* coval not a whole number */ + if (coval - floor(coval) != 0) { + for (int i = 0; i < k; i++) { + if (coval - i > 1) { + Aarg[i] = 0; + Ares[i] = 0; } - } - break; - - /*--------------------------------------------------------------------------*/ - case mult_d_a: /* Multiply an adouble by a double mult_d_a */ - /* (*) */ - res = get_locint_r(); - arg = get_locint_r(); - coval = get_val_r(); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - AARG_INC_O; - for (int i=0; i 0)) { + Aarg[i] = make_inf(); + Ares[i] = 0; } - - GET_TAYL(res,k,p) - break; - - /*--------------------------------------------------------------------------*/ - case mult_a_p: /* Multiply an adouble by a double mult_a_p */ - /* (*) */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - AARG_INC_O; - for (int i=0; i 1 */ + /* the following is not efficient but at least it works */ + /* it reformulates x^n into x* ... *x n times */ + + copyAndZeroset(k, Ares, rp_Atemp); + inconv(k, rp_Atemp, Targ, Aarg); + inconv(k, rp_Atemp, Targ, Aarg); + if (coval == 3) { + conv(k, Aarg, Targ, rp_Atemp); + for (int i = 0; i < k; i++) + Aarg[i] = 2.0 * rp_Atemp[i]; } - - VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - MAXDEC(AARG,3.0); - AARG_INC_O; - - VEC_COMPUTED_CHECK - recipr(k,1.0,Targ,rp_Ttemp); - conv0(k, rp_Ttemp, - Tres, rp_Atemp); - VEC_COMPUTED_END - deconv0(k,Ares,rp_Atemp,Aarg); - - HOV_INC(Ares, k) - HOV_INC(Aarg, k) - HOS_OV_INC(Tres, k) - HOS_OV_INC(Targ, k) - } + } } - - if (arg != res) - GET_TAYL(res,k,p) - break; - - - /****************************************************************************/ - case div_p_a: /* Division double - adouble (/) div_p_a */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - Tres = rpp_T[res]; - Targ = rpp_T[arg]; - - /* olvo 980922 allows reflexive operation */ - if (arg == res) { - FOR_0_LE_l_LT_pk - rp_Ttemp2[l] = Tres[l]; - Tres = rp_Ttemp2; - GET_TAYL(arg,k,p) - } - - VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - MAXDEC(AARG,3.0); - AARG_INC_O; - - VEC_COMPUTED_CHECK - recipr(k,1.0,Targ,rp_Ttemp); - conv0(k, rp_Ttemp, - Tres, rp_Atemp); - VEC_COMPUTED_END - deconv0(k,Ares,rp_Atemp,Aarg); - - HOV_INC(Ares, k) - HOV_INC(Aarg, k) - HOS_OV_INC(Tres, k) - HOS_OV_INC(Targ, k) - } + } + } + VEC_COMPUTED_END + + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + HOS_OV_INC(Targ, k) + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case pow_op_p: /* pow_op_p */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + + Targ = rpp_T[arg]; + Tres = rpp_T[res]; + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + /* olvo 980921 allows reflexive operation */ + if (arg == res) { + FOR_0_LE_l_LT_pk rp_Ttemp2[l] = Tres[l]; + Tres = rp_Ttemp2; + GET_TAYL(arg, k, p) + } + + VEC_COMPUTED_INIT + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + MAXDEC(AARG, 4.0); + AARG_INC_O; + + VEC_COMPUTED_CHECK + if (fabs(Targ[0]) > ADOLC_EPS) { + divide(k, Tres, Targ, rp_Ttemp); + for (int i = 0; i < k; i++) { + rp_Ttemp[i] *= coval; + /* printf(" EPS i %d %f\n",i,rp_Ttemp[i]); */ + } + inconv0(k, Ares, rp_Ttemp, Aarg); + } else { + if (coval <= 0.0) { + for (int i = 0; i < k; i++) { + Aarg[i] = make_nan(); + Ares[i] = 0; } - - if (arg != res) - GET_TAYL(res,k,p) - break; - - - /****************************************************************************/ - /* SIGN OPERATIONS */ - - /*--------------------------------------------------------------------------*/ - case pos_sign_a: /* pos_sign_a */ - res = get_locint_r(); - arg = get_locint_r(); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - AARG_INC_O; - for (int i=0; i 1) { + Aarg[i] = 0; + Ares[i] = 0; } - - GET_TAYL(res,k,p) - break; - - /*--------------------------------------------------------------------------*/ - case neg_sign_a: /* neg_sign_a */ - res = get_locint_r(); - arg = get_locint_r(); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - AARG_INC_O; - for (int i=0; i 0)) { + Aarg[i] = make_inf(); + Ares[i] = 0; } + if (coval - i < 0) { + Aarg[i] = make_nan(); + Ares[i] = 0; + } + } + } else { + if (coval == 1) { + for (int i = 0; i < k; i++) { /* ! no temporary */ + Aarg[i] += Ares[i]; + Ares[i] = 0.0; + } + } else { + /* coval is an int > 1 */ + /* the following is not efficient but at least it works */ + /* it reformulates x^n into x* ... *x n times */ + + copyAndZeroset(k, Ares, rp_Atemp); + inconv(k, rp_Atemp, Targ, Aarg); + inconv(k, rp_Atemp, Targ, Aarg); + if (coval == 3) { + conv(k, Aarg, Targ, rp_Atemp); + for (int i = 0; i < k; i++) + Aarg[i] = 2.0 * rp_Atemp[i]; + } + } + } + } + } + VEC_COMPUTED_END + + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + HOS_OV_INC(Targ, k) + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case sqrt_op: /* sqrt_op */ + res = get_locint_r(); + arg = get_locint_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + Tres = rpp_T[res]; + + VEC_COMPUTED_INIT + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + MAXDEC(AARG, 4.0); + AARG_INC_O; + + VEC_COMPUTED_CHECK + recipr(k, 0.5, Tres, rp_Ttemp); + VEC_COMPUTED_END + inconv0(k, Ares, rp_Ttemp, Aarg); + + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case cbrt_op: /* cbrt_op */ + res = get_locint_r(); + arg = get_locint_r(); + fprintf(DIAG_OUT, + "ADOL-C error: higher order mode of cbrt not implemented yet\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + + break; + + /*--------------------------------------------------------------------------*/ + case gen_quad: /* gen_quad */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + coval = get_val_r(); + coval = get_val_r(); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg1, rpp_A[arg1]) + Targ2 = rpp_T[arg2]; + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Ares, k1) + } + else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG1, aTmp); + MAXDEC(AARG1, 4.0); + AARG1_INC_O; + + inconv0(k, Ares, Targ2, Aarg1); + + HOV_INC(Aarg1, k) + HOV_INC(Ares, k) + HOS_OV_INC(Targ2, k) + } + + GET_TAYL(res, k, p) + break; + + /*--------------------------------------------------------------------------*/ + case min_op: /* min_op */ - GET_TAYL(res,k,p) - break; - - - /****************************************************************************/ - /* UNARY OPERATIONS */ - - /*--------------------------------------------------------------------------*/ - case exp_op: /* exponent operation exp_op */ - res = get_locint_r(); - arg = get_locint_r(); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - Tres = rpp_T[res]; - Targ = rpp_T[arg]; - - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Aarg, k1) - HOV_INC(Ares, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - MAXDEC(AARG,4.0); - AARG_INC_O; - - inconv0(k,Ares,Tres,Aarg); +#ifdef _HOS_OV_ - HOV_INC(Ares, k) - HOV_INC(Aarg, k) - HOS_OV_INC(Tres, k) - } + fprintf(DIAG_OUT, " operation min_op not implemented for hos_ov"); + break; +#endif + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + ASSIGN_A(Ares, rpp_A[res]) + Targ1 = rpp_T[arg1]; + Targ2 = rpp_T[arg2]; + ASSIGN_A(AP1, NULL) + ASSIGN_A(AP2, Ares) + + if (Targ1[0] > Targ2[0]) { + FOR_0_LE_l_LT_p { + if ((coval) && (*AP2)) + MINDEC(ret_c, 2); + HOV_INC(AP2, k1) + } + AP1 = Aarg2; + arg = 0; + } else if (Targ1[0] < Targ2[0]) { + FOR_0_LE_l_LT_p { + if ((!coval) && (*AP2)) + MINDEC(ret_c, 2); + HOV_INC(AP2, k1) + } + AP1 = Aarg1; + arg = 0; + } else /* both are equal */ /* must be changed for hos_ov, but how? */ + /* seems to influence the return value */ + for (int i = 1; i < k; i++) { + if (Targ1[i] > Targ2[i]) { + FOR_0_LE_l_LT_p { + if (*AP2) + MINDEC(ret_c, 1); + HOV_INC(AP2, k1) } - - GET_TAYL(res,k,p) - break; - - /*--------------------------------------------------------------------------*/ - case sin_op: /* sine operation sin_op */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg1, rpp_A[arg1]) - Targ2 = rpp_T[arg2]; - - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Aarg1, k1) - HOV_INC(Ares, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG1,aTmp); - MAXDEC(AARG1,4.0); - AARG1_INC_O; - - inconv0(k,Ares,Targ2,Aarg1); - - HOV_INC(Ares, k) - HOV_INC(Aarg1, k) - HOS_OV_INC(Targ2, k) - } + AP1 = Aarg2; + arg = i + 1; + } else if (Targ1[i] < Targ2[i]) { + FOR_0_LE_l_LT_p { + if (*AP2) + MINDEC(ret_c, 1); + HOV_INC(AP2, k1) } + AP1 = Aarg1; + arg = i + 1; + } + if (AP1 != NULL) + break; + } - GET_TAYL(res,k,p) - GET_TAYL(arg2,k,p) /* olvo 980710 covalue */ - /* NOTE: rpp_A[arg2] should be 0 already */ - break; - - /*--------------------------------------------------------------------------*/ - case cos_op: /* cosine operation cos_op */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg1, rpp_A[arg1]) - Targ2 = rpp_T[arg2]; - - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Aarg1, k1) - HOV_INC(Ares, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG1,aTmp); - MAXDEC(AARG1,4.0); - AARG1_INC_O; - - deconv0(k,Ares,Targ2,Aarg1); - - HOV_INC(Ares, k) - HOV_INC(Aarg1, k) - HOS_OV_INC(Targ2, k) - } + if (AP1 != NULL) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(AP1, k1) + HOV_INC(Ares, k1); + } else { + double aTmp = ARES; + ARES_INC = 0.0; + if (arg) /* we are at the tie */ + *AP1 = 5.0; + else + MAXDEC(*AP1, aTmp); + AP1++; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + *AP1++ += aTmp; } - - GET_TAYL(res,k,p) - GET_TAYL(arg2,k,p) /* olvo 980710 covalue */ - /* NOTE: rpp_A[arg2] should be 0 already */ - break; - /*xxx*/ - /*--------------------------------------------------------------------------*/ - case atan_op: /* atan_op */ - case asin_op: /* asin_op */ - case acos_op: /* acos_op */ - case asinh_op: /* asinh_op */ - case acosh_op: /* acosh_op */ - case atanh_op: /* atanh_op */ - case erf_op: /* erf_op */ - case erfc_op: /* erfc_op */ - res = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - - GET_TAYL(res,k,p) - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg1, rpp_A[arg1]) - Targ2 = rpp_T[arg2]; - - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Aarg1, k1) - HOV_INC(Ares, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG1,aTmp); - MAXDEC(AARG1,4.0); - AARG1_INC_O; - - inconv0(k,Ares,Targ2,Aarg1); - - HOV_INC(Aarg1, k) - HOV_INC(Ares, k) - HOS_OV_INC(Targ2, k) - } + } + } + else /* both are identical */ + { + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + HOV_INC(Ares, k1) + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG1, aTmp); /*assume sthg like fmin(x,x) */ + MAXDEC(AARG2, aTmp); + AARG1_INC_O; + AARG2_INC_O; + for (int i = 0; i < k; i++) { + aTmp = ARES; + ARES_INC = 0.0; + AARG1_INC += aTmp / 2; + AARG2_INC += aTmp / 2; + } + } + } + if (arg1 != arg2) + MINDEC(ret_c, 1); + } + break; + + /*--------------------------------------------------------------------------*/ + case abs_val: /* abs_val */ + res = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + /* must be changed for hos_ov, but how? */ + /* seems to influence the return value */ + GET_TAYL(res, k, p) + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + Targ = rpp_T[arg]; + + FOR_0_LE_l_LT_q { + x[l] = 0.0; + jj[l] = 0; + for (int i = 0; i < k; i++) + if ((x[l] == 0.0) && (Targ[i] != 0.0)) { + jj[l] = i; + if (Targ[i] < 0.0) + x[l] = -1.0; + else + x[l] = 1.0; + } + HOS_OV_INC(Targ, k) + } + Targ = rpp_T[arg]; + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } else { + if (Targ[0] == 0.0) { + ARES_INC = 0.0; + AARG_INC = 5.0; + } else { + double aTmp = ARES; + ARES_INC = 0.0; + MAXDEC(AARG, aTmp); + AARG_INC_O; + } + if (Targ[0] == 0.0) + MINDEC(ret_c, 1); + for (int i = 0; i < jj[l]; i++) + ARES_INC = 0.0; + Aarg += jj[l]; + for (int i = jj[l]; i < k; i++) { + double aTmp = ARES; + ARES_INC = 0.0; + if ((coval) && (x[l] < 0) && (aTmp)) + MINDEC(ret_c, 2); + if ((!coval) && (x[l] > 0) && (aTmp)) + MINDEC(ret_c, 2); + AARG_INC += x[l] * aTmp; + } + } + HOS_OV_INC(Targ, k) + } + break; + + /*--------------------------------------------------------------------------*/ + case ceil_op: /* ceil_op */ + res = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + + coval = (coval != ceil(*rpp_T[arg])); + + ASSIGN_A(Ares, rpp_A[res]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } + else { + ARES_INC = 0.0; + AARG_INC = 5.0; + for (int i = 0; i < k; i++) { + if ((coval) && (ARES)) + MINDEC(ret_c, 2); + ARES_INC = 0.0; + } + HOV_INC(Aarg, k) + } + break; + + /*--------------------------------------------------------------------------*/ + case floor_op: /* floor_op */ + res = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + + coval = (coval != floor(*rpp_T[arg])); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } + else { + ARES = 0.0; + AARG_INC = 5.0; + for (int i = 0; i < k; i++) { + if ((coval) && (ARES)) + MINDEC(ret_c, 2); + ARES_INC = 0.0; + } + HOV_INC(Aarg, k) + } + break; + + /****************************************************************************/ + /* CONDITIONALS + */ + + /*--------------------------------------------------------------------------*/ + case cond_assign: /* cond_assign */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + Targ = rpp_T[arg]; + + /* olvo 980925 changed code a little bit */ + if (*Targ > 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + } else { + if (coval <= 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG1, ARES); + ARES_INC = 0.0; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + AARG1_INC += ARES; + ARES_INC = 0; + } } - break; - - /*--------------------------------------------------------------------------*/ - case log_op: /* log_op */ - res = get_locint_r(); - arg = get_locint_r(); - - GET_TAYL(res,k,p) - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - Targ = rpp_T[arg]; - - VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Aarg, k1) - HOV_INC(Ares, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - MAXDEC(AARG,4.0); - AARG_INC_O; - - VEC_COMPUTED_CHECK - recipr(k,1.0,Targ,rp_Ttemp); - VEC_COMPUTED_END - inconv0(k,Ares,rp_Ttemp,Aarg); - - HOV_INC(Ares, k) - HOV_INC(Aarg, k) - HOS_OV_INC(Targ, k) - } + } + else + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (ARES)) + MINDEC(ret_c, 2); + HOV_INC(Ares, k1) + } + } else /* TARG <= 0.0 */ + { + if (res != arg2) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg2, k1) + } else { + if (*Targ == 0.0) /* we are at the tie */ + { + MINDEC(ret_c, 0); + AARG1 = 5.0; + AARG2_INC = 5.0; + } else { + if (coval <= 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG2, ARES); + AARG2_INC_O; + } + ARES_INC = 0.0; + + for (int i = 0; i < k; i++) { + AARG2_INC += ARES; + ARES_INC = 0; + } } - break; - - /*--------------------------------------------------------------------------*/ - case pow_op: /* pow_op */ - res = get_locint_r(); - arg = get_locint_r(); - coval = get_val_r(); - - Targ = rpp_T[arg]; - Tres = rpp_T[res]; - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - - /* olvo 980921 allows reflexive operation */ - if (arg == res) { - FOR_0_LE_l_LT_pk - rp_Ttemp2[l] = Tres[l]; - Tres = rp_Ttemp2; - GET_TAYL(arg,k,p) - } + HOV_INC(Aarg1, k1) + } + else + FOR_0_LE_l_LT_p { + if (ARES) { + if (*Targ == 0.0) /* we are at the tie */ + { + MINDEC(ret_c, 0); + AARG1 = 5.0; + AARG2 = 5.0; + } else if (coval <= 0.0) + MINDEC(ret_c, 2); + } + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } + } + break; + + case cond_eq_assign: /* cond_eq_assign */ + res = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + Targ = rpp_T[arg]; + + /* olvo 980925 changed code a little bit */ + if (*Targ >= 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + } else { + if (coval < 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG1, ARES); + ARES_INC = 0.0; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + AARG1_INC += ARES; + ARES_INC = 0; + } + } + } + else + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (ARES)) + MINDEC(ret_c, 2); + HOV_INC(Ares, k1) + } + } else /* TARG < 0.0 */ + { + if (res != arg2) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg2, k1) + } else { + if (coval < 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG2, ARES); + AARG2_INC_O; + ARES_INC = 0.0; + + for (int i = 0; i < k; i++) { + AARG2_INC += ARES; + ARES_INC = 0; + } + } + HOV_INC(Aarg1, k1) + } + else + FOR_0_LE_l_LT_p { + if (ARES) { + if (coval < 0.0) + MINDEC(ret_c, 2); + } + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } + } + break; + + /*--------------------------------------------------------------------------*/ + case cond_assign_s: /* cond_assign_s */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + Targ = rpp_T[arg]; + + /* olvo 980925 changed code a little bit */ + if (*Targ == 0.0) /* we are at the tie */ + { + FOR_0_LE_l_LT_p { + if (ARES) + AARG1 = 5.0; + HOV_INC(Aarg1, k1) + HOV_INC(Ares, k1) + } + MINDEC(ret_c, 0); + } else if (*Targ > 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + } else { + if (coval <= 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG1, ARES); + ARES_INC = 0.0; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + (AARG1_INC) += ARES; + ARES_INC = 0; + } + } + } + else + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (ARES)) + MINDEC(ret_c, 2); + HOV_INC(Ares, k1) + } + } + break; + case cond_eq_assign_s: /* cond_eq_assign_s */ + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + Targ = rpp_T[arg]; + + /* olvo 980925 changed code a little bit */ + if (*Targ >= 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + } else { + if (coval < 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG1, ARES); + ARES_INC = 0.0; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + (AARG1_INC) += ARES; + ARES_INC = 0; + } + } + } + else + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (ARES)) + MINDEC(ret_c, 2); + HOV_INC(Ares, k1) + } + } + break; + /*--------------------------------------------------------------------------*/ + /* NEW CONDITIONALS */ + /*--------------------------------------------------------------------------*/ +#if defined(ADOLC_ADVANCED_BRANCHING) + case neq_a_a: + case eq_a_a: + case le_a_a: + case ge_a_a: + case lt_a_a: + case gt_a_a: + case neq_a_p: + case eq_a_p: + case le_a_p: + case ge_a_p: + case lt_a_p: + case gt_a_p: + res = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + ASSIGN_A(Ares, rpp_A[res]) + + FOR_0_LE_l_LT_pk1 ARES_INC = 0.0; + + GET_TAYL(res, k, p) + break; +#endif - VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Aarg, k1) - HOV_INC(Ares, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - MAXDEC(AARG,4.0); - AARG_INC_O; - - VEC_COMPUTED_CHECK - if (fabs(Targ[0]) > ADOLC_EPS) { - divide(k,Tres,Targ,rp_Ttemp); - for (int i=0;i 1) { - Aarg[i] = 0; - Ares[i] = 0; - } - if ((coval - i < 1) && (coval - i > 0)) { - Aarg[i] = make_inf(); - Ares[i] = 0; - } - if (coval - i < 0) { - Aarg[i] = make_nan(); - Ares[i] = 0; - } - } - } else { - if (coval == 1) { - for (int i=0; i 1 */ - /* the following is not efficient but at least it works */ - /* it reformulates x^n into x* ... *x n times */ - - copyAndZeroset(k,Ares,rp_Atemp); - inconv(k,rp_Atemp,Targ,Aarg); - inconv(k,rp_Atemp,Targ,Aarg); - if (coval == 3) { - conv(k,Aarg,Targ,rp_Atemp); - for (int i=0; i= numval) + fprintf(DIAG_OUT, + "ADOL-C warning: index out of bounds while subscripting " + "n=%zu, idx=%zu\n", + numval, idx); + arg1 = vectorloc + idx; + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Ares, k1) + } + else { + MAXDEC(AARG1, ARES); + AARG1_INC_O; + ARES_INC = 0.0; + for (int i = 0; i < k; i++) { + AARG1_INC += ARES; + ARES_INC = 0.0; + } + } + GET_TAYL(res, k, p) + } + break; + + case subscript_ref: + coval = get_val_r(); + { + size_t idx, numval = (size_t)trunc(fabs(coval)); + locint vectorloc; + res = get_locint_r(); + vectorloc = get_locint_r(); + arg = get_locint_r(); + Targ = rpp_T[arg]; + Tres = rpp_T[res]; + idx = (size_t)trunc(fabs(*Targ)); + if (idx >= numval) + fprintf(DIAG_OUT, + "ADOL-C warning: index out of bounds while subscripting " + "(ref) n=%zu, idx=%zu\n", + numval, idx); + arg1 = (size_t)trunc(fabs(*Tres)); + /* + * This is actually NOP + * basically all we need is that arg1 == vectorloc[idx] + * so doing a check here is probably good + */ + if (arg1 != vectorloc + idx) { + fprintf(DIAG_OUT, + "ADOL-C error: indexed active position does not match " + "referenced position\nindexed = %zu, referenced = %d\n", + vectorloc + idx, arg1); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + } + GET_TAYL(res, k, p) + } + break; + + case ref_copyout: + res = get_locint_r(); + arg1 = get_locint_r(); + + Targ1 = rpp_T[arg1]; + arg = (size_t)trunc(fabs(*Targ1)); + + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg, rpp_A[arg]) + + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } + else { + MAXDEC(AARG, ARES); + AARG_INC_O; + ARES_INC = 0.0; + for (int i = 0; i < k; i++) { + AARG_INC += ARES; + ARES_INC = 0.0; + } + } + GET_TAYL(res, k, p) + break; - GET_TAYL(res,k,p) - break; - - /*--------------------------------------------------------------------------*/ - case pow_op_p: /* pow_op_p */ - res = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; - - Targ = rpp_T[arg]; - Tres = rpp_T[res]; - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - - /* olvo 980921 allows reflexive operation */ - if (arg == res) { - FOR_0_LE_l_LT_pk - rp_Ttemp2[l] = Tres[l]; - Tres = rp_Ttemp2; - GET_TAYL(arg,k,p) - } + case ref_incr_a: /* Increment an adouble incr_a */ + case ref_decr_a: /* Increment an adouble decr_a */ + arg1 = get_locint_r(); - VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Aarg, k1) - HOV_INC(Ares, k1) - } else { - double aTmp = ARES; - ARES_INC = 0.0; - MAXDEC(AARG,aTmp); - MAXDEC(AARG,4.0); - AARG_INC_O; - - VEC_COMPUTED_CHECK - if (fabs(Targ[0]) > ADOLC_EPS) { - divide(k,Tres,Targ,rp_Ttemp); - for (int i=0;i 1) { - Aarg[i] = 0; - Ares[i] = 0; - } - if ((coval - i < 1) && (coval - i > 0)) { - Aarg[i] = make_inf(); - Ares[i] = 0; - } - if (coval - i < 0) { - Aarg[i] = make_nan(); - Ares[i] = 0; - } - } - } else { - if (coval == 1) { - for (int i=0; i 1 */ - /* the following is not efficient but at least it works */ - /* it reformulates x^n into x* ... *x n times */ - - copyAndZeroset(k,Ares,rp_Atemp); - inconv(k,rp_Atemp,Targ,Aarg); - inconv(k,rp_Atemp,Targ,Aarg); - if (coval == 3) { - conv(k,Aarg,Targ,rp_Atemp); - for (int i=0; i Targ2[0]) { - FOR_0_LE_l_LT_p - { if ((coval) && (*AP2)) - MINDEC(ret_c,2); - HOV_INC(AP2,k1) - } - AP1 = Aarg2; - arg = 0; - } else - if (Targ1[0] < Targ2[0]) { - FOR_0_LE_l_LT_p - { if ((!coval) && (*AP2)) - MINDEC(ret_c,2); - HOV_INC(AP2,k1) - } - AP1 = Aarg1; - arg = 0; - } else /* both are equal */ /* must be changed for hos_ov, but how? */ - /* seems to influence the return value */ - for (int i=1;i Targ2[i]) { - FOR_0_LE_l_LT_p - { if (*AP2) - MINDEC(ret_c,1); - HOV_INC(AP2,k1) - } - AP1 = Aarg2; - arg = i+1; - } else - if (Targ1[i] < Targ2[i]) { - FOR_0_LE_l_LT_p - { if (*AP2) - MINDEC(ret_c,1); - HOV_INC(AP2,k1) - } - AP1 = Aarg1; - arg = i+1; - } - if (AP1 != NULL) - break; - } - - if (AP1 != NULL) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(AP1, k1) - HOV_INC(Ares,k1); - } else { - double aTmp = ARES; - ARES_INC = 0.0; - if (arg) /* we are at the tie */ - *AP1 = 5.0; - else - MAXDEC(*AP1,aTmp); - AP1++; - for (int i=0;i0) && (aTmp)) - MINDEC(ret_c,2); - AARG_INC += x[l] * aTmp; - } - } - HOS_OV_INC(Targ,k) - } - break; - - /*--------------------------------------------------------------------------*/ - case ceil_op: /* ceil_op */ - res = get_locint_r(); - arg = get_locint_r(); - coval = get_val_r(); - - GET_TAYL(res,k,p) - - coval = (coval != ceil(*rpp_T[arg]) ); - - ASSIGN_A(Ares, rpp_A[res]) - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Aarg, k1) - HOV_INC(Ares, k1) - } else { - ARES_INC = 0.0; - AARG_INC = 5.0; - for (int i=0; i 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg1, k1) - } else { - if (coval <= 0.0) - MINDEC(ret_c,2); - MAXDEC(AARG1,ARES); - ARES_INC = 0.0; - AARG1_INC_O; - for (int i=0; i= 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg1, k1) - } else { - if (coval < 0.0) - MINDEC(ret_c,2); - MAXDEC(AARG1,ARES); - ARES_INC = 0.0; - AARG1_INC_O; - for (int i=0; i 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg1, k1) - } else { - if (coval <= 0.0) - MINDEC(ret_c,2); - MAXDEC(AARG1,ARES); - ARES_INC = 0.0; - AARG1_INC_O; - for (int i=0; i= 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg1, k1) - } else { - if (coval < 0.0) - MINDEC(ret_c,2); - MAXDEC(AARG1,ARES); - ARES_INC = 0.0; - AARG1_INC_O; - for (int i=0; i= numval) - fprintf(DIAG_OUT, "ADOL-C warning: index out of bounds while subscripting n=%zu, idx=%zu\n", numval, idx); - arg1 = vectorloc+idx; - ASSIGN_A(Aarg1, rpp_A[arg1]) - ASSIGN_A(Ares, rpp_A[res]) - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Aarg1, k1) - HOV_INC(Ares, k1) - } else { - MAXDEC(AARG1,ARES); - AARG1_INC_O; - ARES_INC = 0.0; - for (int i=0; i= numval) - fprintf(DIAG_OUT, "ADOL-C warning: index out of bounds while subscripting (ref) n=%zu, idx=%zu\n", numval, idx); - arg1 = (size_t)trunc(fabs(*Tres)); - /* - * This is actually NOP - * basically all we need is that arg1 == vectorloc[idx] - * so doing a check here is probably good - */ - if (arg1 != vectorloc+idx) { - fprintf(DIAG_OUT, "ADOL-C error: indexed active position does not match referenced position\nindexed = %zu, referenced = %d\n", vectorloc+idx, arg1); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); - } - GET_TAYL(res,k,p) - } - break; - - case ref_copyout: - res = get_locint_r(); - arg1 = get_locint_r(); - - Targ1 = rpp_T[arg1]; - arg = (size_t)trunc(fabs(*Targ1)); - - ASSIGN_A(Ares, rpp_A[res]) - ASSIGN_A(Aarg, rpp_A[arg]) - - FOR_0_LE_l_LT_p - if (0 == ARES) { - HOV_INC(Aarg, k1) - HOV_INC(Ares, k1) - } else { - MAXDEC(AARG,ARES); - AARG_INC_O; - ARES_INC = 0.0; - for (int i=0; i 2.0) ? ARES : 2.0 ; - ARES_INC = comp; - MAXDEC(AARG1,comp); - MAXDEC(AARG2,comp); - AARG1_INC_O; - AARG2_INC_O; - - inconv(k,Ares,Targ1,Aarg2); - inconv(k,Ares,Targ2,Aarg1); - - HOV_INC(Ares, k) - HOV_INC(Aarg1, k) - HOV_INC(Aarg2, k) - HOS_OV_INC(Targ1, k) - HOS_OV_INC(Targ2, k) - HOS_OV_INC(Tres, k) - } - } - } - GET_TAYL(res,k,p) - break; - - case vec_axpy: - res = get_locint_r(); - size = get_locint_r(); - arg2 = get_locint_r(); - arg1 = get_locint_r(); - arg = get_locint_r(); - for (locint qq=0;qq 2.0) ? ARES : 2.0 ; - MAXDEC(AARG2,ARES); - ARES_INC = 0.0; - MAXDEC(AARG,comp); - MAXDEC(AARG1,comp); - AARG_INC_O; - AARG1_INC_O; - AARG2_INC_O; - copyAndZeroset(k,Ares,rp_Atemp); - inconv(k,rp_Atemp,Targ1,Aarg); - inconv(k,rp_Atemp,Targ,Aarg1); - for (int i=0; i 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg1, k1) - } else { - if (coval <= 0.0) - MINDEC(ret_c,2); - MAXDEC(AARG1,ARES); - ARES_INC = 0.0; - AARG1_INC_O; - for (int i=0; i= 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg1, k1) - } else { - if (coval < 0.0) - MINDEC(ret_c,2); - MAXDEC(AARG1,ARES); - ARES_INC = 0.0; - AARG1_INC_O; - for (int i=0; i 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg1, k1) - } else { - if (coval <= 0.0) - MINDEC(ret_c,2); - MAXDEC(AARG1,ARES); - ARES_INC = 0.0; - AARG1_INC_O; - for (int i=0; i= 0.0) { - if (res != arg1) - FOR_0_LE_l_LT_p - { if (0 == ARES) { - HOV_INC(Ares, k1) - HOV_INC(Aarg1, k1) - } else { - if (coval < 0.0) - MINDEC(ret_c,2); - MAXDEC(AARG1,ARES); - ARES_INC = 0.0; - AARG1_INC_O; - for (int i=0; i0;ls--) { - res--; + case vec_copy: - ASSIGN_A( Ares, rpp_A[res]) + res = get_locint_r(); + size = get_locint_r(); + arg = get_locint_r(); - FOR_0_LE_l_LT_pk1 - ARES_INC = 0.0; - } - break; + for (locint qq = 0; qq < size; qq++) { - /*--------------------------------------------------------------------------*/ - case death_not: /* death_not */ - arg2 = get_locint_r(); - arg1 = get_locint_r(); + ASSIGN_A(Aarg, rpp_A[arg + qq]) + ASSIGN_A(Ares, rpp_A[res + qq]) - for (int j=arg1;j<=arg2;j++) { - ASSIGN_A(Aarg1, rpp_A[j]) - - FOR_0_LE_l_LT_p - for (int i=0; iADOLC_EXT_FCT_POINTER == NULL) - fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); - if (m>0) { - if (ADOLC_EXT_FCT_U == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - if (edfct->dp_y==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - } - if (n>0) { - if (ADOLC_EXT_FCT_Z == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - if (edfct->dp_x==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev+m-1; - for (int loop = 0; loop < m; ++loop) { - // First entry of rpp_A[arg] is algorithmic dependency --> skip that! - dpp_U[loop] = rpp_A[arg] + 1; - ++arg; - } + FOR_0_LE_l_LT_p if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) + } + else { + MAXDEC(AARG, ARES); + AARG_INC_O; + ARES_INC = 0.0; + for (int i = 0; i < k; i++) { /* ! no temporary */ + AARG_INC += ARES; + ARES_INC = 0.0; + } + } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - for (int loop = 0; loop < n; ++loop) { - // This should copy data in case `revreal` is not double. - // (Note: copy back below doesn't actually do anything until this is changed to a copy.) - // (Note: first entry is alg. dependency which we just skip here for now.) - dpp_Z[loop] = rpp_A[arg]+1; - ++arg; - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - double** dpp_x = rpp_T + arg; // TODO: change to copy, use loop below - for (int loop = 0; loop < n; ++loop,++arg) { - // TODO: copy rpp_T[arg][0,...,keep] -> dpp_x[loop][0,...,keep] - // edfct->dp_x[loop] = rpp_T[arg]; - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - double** dpp_y = rpp_T + arg; // TODO: change to copy, use loop below - for (int loop = 0; loop < m; ++loop,++arg) { - // TODO: copy rpp_T[arg][0,...,keep] -> dpp_y[loop][0,...,keep] - // edfct->dp_y[loop] = rpp_T[arg]; - } - int ext_retc = edfct->ADOLC_EXT_FCT_COMPLETE; - MINDEC(ret_c, ext_retc); - - res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; - // Ares = A[res]; - for (int loop = 0; loop < m; ++loop) { - FOR_0_LE_l_LT_q { - // ADJOINT_BUFFER_RES_L = 0.; /* \bar{v}_i = 0 !!! */ - //rpp_T[res][l] = 0.0; - rpp_A[res][l] = 0.0; - } - ++res; - } - res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; - for (int loop = 0; loop < n; ++loop) { - // ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(ADOLC_EXT_FCT_Z[loop],ADJOINT_BUFFER_RES); - // Hmm, ist das nicht falsch? Wir sollten rpp_T vermutlich nicht anfassen. - // Sonst ändert sich ja das Ergebnis wenn man das Band nochmal abspielt? - //rpp_T[res] = dpp_Z[loop]; - // Assume non-smooth? - rpp_A[res][0] = 5.0; - for (int i=0; idp_y_priorRequired) { - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev+m-1; - for (int loop = 0; loop < m; ++loop,--arg) { - // ADOLC_GET_TAYLOR(arg); - GET_TAYL(arg, k, p); - } - } - if (edfct->dp_x_changes) { - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev+n-1; - for (int loop = 0; loop < n; ++loop,--arg) { - // ADOLC_GET_TAYLOR(arg); - GET_TAYL(arg, k, p); - } - } - ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; + GET_TAYL(res + qq, k, p) + } + + break; + + case vec_dot: + res = get_locint_r(); + size = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + for (locint qq = 0; qq < size; qq++) { + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2 + qq]) + ASSIGN_A(Aarg1, rpp_A[arg1 + qq]) + Targ1 = rpp_T[arg1 + qq]; + Targ2 = rpp_T[arg2 + qq]; + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + HOV_INC(Ares, k1) + } else { + comp = (ARES > 2.0) ? ARES : 2.0; + ARES_INC = comp; + MAXDEC(AARG1, comp); + MAXDEC(AARG2, comp); + AARG1_INC_O; + AARG2_INC_O; + + inconv(k, Ares, Targ1, Aarg2); + inconv(k, Ares, Targ2, Aarg1); + + HOV_INC(Ares, k) + HOV_INC(Aarg1, k) + HOV_INC(Aarg2, k) + HOS_OV_INC(Targ1, k) + HOS_OV_INC(Targ2, k) + HOS_OV_INC(Tres, k) + } + } + } + GET_TAYL(res, k, p) + break; + + case vec_axpy: + res = get_locint_r(); + size = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + for (locint qq = 0; qq < size; qq++) { + ASSIGN_A(Ares, rpp_A[res + qq]) + ASSIGN_A(Aarg, rpp_A[arg]) + ASSIGN_A(Aarg2, rpp_A[arg2 + qq]) + ASSIGN_A(Aarg1, rpp_A[arg1 + qq]) + Targ = rpp_T[arg]; + Targ1 = rpp_T[arg1 + qq]; + if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + HOV_INC(Ares, k1) + } else { + comp = (ARES > 2.0) ? ARES : 2.0; + MAXDEC(AARG2, ARES); + ARES_INC = 0.0; + MAXDEC(AARG, comp); + MAXDEC(AARG1, comp); + AARG_INC_O; + AARG1_INC_O; + AARG2_INC_O; + copyAndZeroset(k, Ares, rp_Atemp); + inconv(k, rp_Atemp, Targ1, Aarg); + inconv(k, rp_Atemp, Targ, Aarg1); + for (int i = 0; i < k; i++) + AARG2_INC += *rp_Atemp++; + + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOV_INC(Aarg1, k) + HOS_OV_INC(Targ, k) + HOS_OV_INC(Targ1, k) + } + GET_TAYL(res + qq, k, p) + } + break; + + case ref_cond_assign: /* cond_assign */ + { + revreal *Tref; + locint ref = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + Tref = rpp_T[ref]; + + res = (size_t)trunc(fabs(*Tref)); + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + Targ = rpp_T[arg]; + + /* olvo 980925 changed code a little bit */ + if (*Targ > 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + } else { + if (coval <= 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG1, ARES); + ARES_INC = 0.0; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + AARG1_INC += ARES; + ARES_INC = 0; + } + } + } + else + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (ARES)) + MINDEC(ret_c, 2); + HOV_INC(Ares, k1) + } + } else /* TARG <= 0.0 */ + { + if (res != arg2) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg2, k1) + } else { + if (*Targ == 0.0) /* we are at the tie */ + { + MINDEC(ret_c, 0); + AARG1 = 5.0; + AARG2_INC = 5.0; + } else { + if (coval <= 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG2, ARES); + AARG2_INC_O; + } + ARES_INC = 0.0; + + for (int i = 0; i < k; i++) { + AARG2_INC += ARES; + ARES_INC = 0; + } + } + HOV_INC(Aarg1, k1) + } + else + FOR_0_LE_l_LT_p { + if (ARES) { + if (*Targ == 0.0) /* we are at the tie */ + { + MINDEC(ret_c, 0); + AARG1 = 5.0; + AARG2 = 5.0; + } else if (coval <= 0.0) + MINDEC(ret_c, 2); + } + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } + } + } break; + case ref_cond_eq_assign: /* cond_eq_assign */ + { + revreal *Tref; + locint ref = get_locint_r(); + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + Tref = rpp_T[ref]; + + res = (size_t)trunc(fabs(*Tref)); + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + ASSIGN_A(Aarg2, rpp_A[arg2]) + Targ = rpp_T[arg]; + + /* olvo 980925 changed code a little bit */ + if (*Targ >= 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + } else { + if (coval < 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG1, ARES); + ARES_INC = 0.0; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + AARG1_INC += ARES; + ARES_INC = 0; + } + } + } + else + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (ARES)) + MINDEC(ret_c, 2); + HOV_INC(Ares, k1) + } + } else /* TARG < 0.0 */ + { + if (res != arg2) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg2, k1) + } else { + if (coval < 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG2, ARES); + AARG2_INC_O; + ARES_INC = 0.0; + + for (int i = 0; i < k; i++) { + AARG2_INC += ARES; + ARES_INC = 0; + } + } + HOV_INC(Aarg1, k1) + } + else + FOR_0_LE_l_LT_p { + if (ARES) { + if (coval < 0.0) + MINDEC(ret_c, 2); + } + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } + } + } break; + + case ref_cond_assign_s: /* cond_assign_s */ + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + Targ2 = rpp_T[arg2]; + res = (size_t)trunc(fabs(*Targ2)); + + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + Targ = rpp_T[arg]; + + /* olvo 980925 changed code a little bit */ + if (*Targ == 0.0) /* we are at the tie */ + { + FOR_0_LE_l_LT_p { + if (ARES) + AARG1 = 5.0; + HOV_INC(Aarg1, k1) + HOV_INC(Ares, k1) + } + MINDEC(ret_c, 0); + } else if (*Targ > 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + } else { + if (coval <= 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG1, ARES); + ARES_INC = 0.0; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + (AARG1_INC) += ARES; + ARES_INC = 0; + } + } + } + else + FOR_0_LE_l_LT_p { + if ((coval <= 0.0) && (ARES)) + MINDEC(ret_c, 2); + HOV_INC(Ares, k1) + } + } + break; + + case ref_cond_eq_assign_s: /* cond_eq_assign_s */ + arg2 = get_locint_r(); + arg1 = get_locint_r(); + arg = get_locint_r(); + coval = get_val_r(); + + Targ2 = rpp_T[arg2]; + res = (size_t)trunc(fabs(*Targ2)); + + GET_TAYL(res, k, p) + + ASSIGN_A(Aarg1, rpp_A[arg1]) + ASSIGN_A(Ares, rpp_A[res]) + Targ = rpp_T[arg]; + + /* olvo 980925 changed code a little bit */ + if (*Targ >= 0.0) { + if (res != arg1) + FOR_0_LE_l_LT_p { + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + } else { + if (coval < 0.0) + MINDEC(ret_c, 2); + MAXDEC(AARG1, ARES); + ARES_INC = 0.0; + AARG1_INC_O; + for (int i = 0; i < k; i++) { + (AARG1_INC) += ARES; + ARES_INC = 0; + } + } + } + else + FOR_0_LE_l_LT_p { + if ((coval < 0.0) && (ARES)) + MINDEC(ret_c, 2); + HOV_INC(Ares, k1) + } + } + break; + + /****************************************************************************/ + /* REMAINING + * STUFF */ + + /*--------------------------------------------------------------------------*/ + case take_stock_op: /* take_stock_op */ + res = get_locint_r(); + size = get_locint_r(); + get_val_v_r(size); + + res += size; + for (int ls = size; ls > 0; ls--) { + res--; + + ASSIGN_A(Ares, rpp_A[res]) + + FOR_0_LE_l_LT_pk1 ARES_INC = 0.0; + } + break; + + /*--------------------------------------------------------------------------*/ + case death_not: /* death_not */ + arg2 = get_locint_r(); + arg1 = get_locint_r(); + + for (int j = arg1; j <= arg2; j++) { + ASSIGN_A(Aarg1, rpp_A[j]) + + FOR_0_LE_l_LT_p for (int i = 0; i < k1; i++) AARG1_INC = 0.0; + } + + for (int j = arg1; j <= arg2; j++) + GET_TAYL(j, k, p) + + break; +#ifdef _HOS_ /* HOS */ + + /*--------------------------------------------------------------------------*/ + case ext_diff: /* extern differentiated function */ + { + ADOLC_CURRENT_TAPE_INFOS.cpIndex = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev = get_locint_r(); + m = get_locint_r(); + n = get_locint_r(); + ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_r(); + edfct = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + + oldTraceFlag = ADOLC_CURRENT_TAPE_INFOS.traceFlag; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + + /* degree is not known when registering external functions, + so do memory allocation here (at least for now) */ + double **dpp_U = malloc(sizeof(double *) * m); + double **dpp_Z = malloc(sizeof(double *) * n); + + if (edfct->ADOLC_EXT_FCT_POINTER == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); + if (m > 0) { + if (ADOLC_EXT_FCT_U == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + if (edfct->dp_y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + } + if (n > 0) { + if (ADOLC_EXT_FCT_Z == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + if (edfct->dp_x == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev + m - 1; + for (int loop = 0; loop < m; ++loop) { + // First entry of rpp_A[arg] is algorithmic dependency --> skip that! + dpp_U[loop] = rpp_A[arg] + 1; + ++arg; + } + + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + for (int loop = 0; loop < n; ++loop) { + // This should copy data in case `revreal` is not double. + // (Note: copy back below doesn't actually do anything until this is + // changed to a copy.) (Note: first entry is alg. dependency which we + // just skip here for now.) + dpp_Z[loop] = rpp_A[arg] + 1; + ++arg; + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + double **dpp_x = rpp_T + arg; // TODO: change to copy, use loop below + for (int loop = 0; loop < n; ++loop, ++arg) { + // TODO: copy rpp_T[arg][0,...,keep] -> dpp_x[loop][0,...,keep] + // edfct->dp_x[loop] = rpp_T[arg]; + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + double **dpp_y = rpp_T + arg; // TODO: change to copy, use loop below + for (int loop = 0; loop < m; ++loop, ++arg) { + // TODO: copy rpp_T[arg][0,...,keep] -> dpp_y[loop][0,...,keep] + // edfct->dp_y[loop] = rpp_T[arg]; + } + int ext_retc = edfct->ADOLC_EXT_FCT_COMPLETE; + MINDEC(ret_c, ext_retc); + + res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; + // Ares = A[res]; + for (int loop = 0; loop < m; ++loop) { + FOR_0_LE_l_LT_q { + // ADJOINT_BUFFER_RES_L = 0.; /* \bar{v}_i = 0 !!! */ + // rpp_T[res][l] = 0.0; + rpp_A[res][l] = 0.0; + } + ++res; + } + res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev; + for (int loop = 0; loop < n; ++loop) { + // ADOLC_EXT_FCT_COPY_ADJOINTS_BACK(ADOLC_EXT_FCT_Z[loop],ADJOINT_BUFFER_RES); + // Hmm, ist das nicht falsch? Wir sollten rpp_T vermutlich nicht + // anfassen. Sonst ändert sich ja das Ergebnis wenn man das Band nochmal + // abspielt? + // rpp_T[res] = dpp_Z[loop]; + // Assume non-smooth? + rpp_A[res][0] = 5.0; + for (int i = 0; i < k; i++) { + // `i+1` to do something similar a `ARES_INC_O` + // I still don't understand this ARES_INC_O, + // but apparently the first place is used to store + // some flag or so I don't understand (see me wondering + // in mult_a_a...) + rpp_A[res][i + 1] = dpp_Z[loop][i]; + } + ++res; + } + if (edfct->dp_y_priorRequired) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev + m - 1; + for (int loop = 0; loop < m; ++loop, --arg) { + // ADOLC_GET_TAYLOR(arg); + GET_TAYL(arg, k, p); + } + } + if (edfct->dp_x_changes) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_rev + n - 1; + for (int loop = 0; loop < n; ++loop, --arg) { + // ADOLC_GET_TAYLOR(arg); + GET_TAYL(arg, k, p); + } + } + ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; - free(dpp_Z); - free(dpp_U); + free(dpp_Z); + free(dpp_U); - break; - } + break; + } #endif - /*--------------------------------------------------------------------------*/ - default: /* default */ - /* Die here, we screwed up */ - - fprintf(DIAG_OUT,"ADOL-C fatal error in " GENERATED_FILENAME " (" - __FILE__ - ") : no such operation %d\n", operation); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - break; - } /* endswitch */ - - /* Get the next operation */ - operation=get_op_r(); + /*--------------------------------------------------------------------------*/ + default: /* default */ + /* Die here, we screwed up */ + + fprintf(DIAG_OUT, + "ADOL-C fatal error in " GENERATED_FILENAME " (" __FILE__ + ") : no such operation %d\n", + operation); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + break; + } /* endswitch */ + + /* Get the next operation */ + operation = get_op_r(); #if defined(ADOLC_DEBUG) - ++countPerOperation[operation]; + ++countPerOperation[operation]; #endif /* ADOLC_DEBUG */ - } + } #if defined(ADOLC_DEBUG) - printf("\nTape contains:\n"); - for (v = 0; v < 256; ++v) - if (countPerOperation[v] > 0) - printf("operation %3d: %6d time(s) - %6d taylors read (%10.2f per operation)\n", v, countPerOperation[v], taylorPerOperation[v], (double)taylorPerOperation[v] / (double)countPerOperation[v]); - printf("\n"); + printf("\nTape contains:\n"); + for (v = 0; v < 256; ++v) + if (countPerOperation[v] > 0) + printf("operation %3d: %6d time(s) - %6d taylors read (%10.2f per " + "operation)\n", + v, countPerOperation[v], taylorPerOperation[v], + (double)taylorPerOperation[v] / (double)countPerOperation[v]); + printf("\n"); #endif /* ADOLC_DEBUG */ - /* clean up */ - free((char*)*rpp_T); - free((char*) rpp_T); - free(*rpp_A); - free(rpp_A); - free(rp_Ttemp); - free(rp_Ttemp2); - free(rp_Atemp); - free(rp_Atemp2); + /* clean up */ + free((char *)*rpp_T); + free((char *)rpp_T); + free(*rpp_A); + free(rpp_A); + free(rp_Ttemp); + free(rp_Ttemp2); + free(rp_Atemp); + free(rp_Atemp2); - free((char*) jj); - free((char*) x); + free((char *)jj); + free((char *)x); - ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; - end_sweep(); + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; + end_sweep(); - return ret_c; + return ret_c; } /****************************************************************************/ diff --git a/ADOL-C/src/hos_forward.c b/ADOL-C/src/hos_forward.c index b1bef919b..1946ebfe4 100644 --- a/ADOL-C/src/hos_forward.c +++ b/ADOL-C/src/hos_forward.c @@ -3,18 +3,17 @@ File: hos_forward.c Revision: $Id$ Contents: hos_forward (higher-order-scalar forward mode) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _HOS_ 1 +#define _HOS_ 1 #define _KEEP_ 1 #include #undef _KEEP_ #undef _HOS_ - diff --git a/ADOL-C/src/hos_ov_reverse.c b/ADOL-C/src/hos_ov_reverse.c index fd09777c7..d0eac78bd 100644 --- a/ADOL-C/src/hos_ov_reverse.c +++ b/ADOL-C/src/hos_ov_reverse.c @@ -3,13 +3,13 @@ File: drivers/drivers.h Revision: $Id$ Contents: hos_ov_reverse (higher-order-scalar reverse mode on vectors) - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _HOS_OV_ 1 diff --git a/ADOL-C/src/hos_reverse.c b/ADOL-C/src/hos_reverse.c index d361e6bd9..6e0f19e09 100644 --- a/ADOL-C/src/hos_reverse.c +++ b/ADOL-C/src/hos_reverse.c @@ -3,17 +3,16 @@ File: hos_reverse.c Revision: $Id$ Contents: hos_reverse (higher-order-scalar reverse mode) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _HOS_ 1 #include #undef _HOS_ - diff --git a/ADOL-C/src/hov_forward.c b/ADOL-C/src/hov_forward.c index f0e81be78..201276ea1 100644 --- a/ADOL-C/src/hov_forward.c +++ b/ADOL-C/src/hov_forward.c @@ -3,17 +3,16 @@ File: hov_forward.c Revision: $Id$ Contents: hov_forward (higher-order-vector forward mode) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _HOV_ 1 #undef _KEEP_ #include #undef _HOV_ - diff --git a/ADOL-C/src/hov_reverse.c b/ADOL-C/src/hov_reverse.c index 62c245b61..905eeae27 100644 --- a/ADOL-C/src/hov_reverse.c +++ b/ADOL-C/src/hov_reverse.c @@ -3,17 +3,16 @@ File: hov_reverse.c Revision: $Id$ Contents: hov_reverse (higher-order-vector reverse mode) - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _HOV_ 1 #include #undef _HOV_ - diff --git a/ADOL-C/src/hov_wk_forward.c b/ADOL-C/src/hov_wk_forward.c index efa57335c..2982385bb 100644 --- a/ADOL-C/src/hov_wk_forward.c +++ b/ADOL-C/src/hov_wk_forward.c @@ -3,16 +3,16 @@ File: hov_wk_forward.c Revision: $Id$ Contents: hov_wk_forward (higher-order-vector forward mode with keep) - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ #define _HOV_WK_ 1 -#define _KEEP_ 1 +#define _KEEP_ 1 #include #undef _KEEP_ #undef _HOV_WK_ diff --git a/ADOL-C/src/indopro_forward_pl.c b/ADOL-C/src/indopro_forward_pl.c index d67d5affc..ea484cc6e 100644 --- a/ADOL-C/src/indopro_forward_pl.c +++ b/ADOL-C/src/indopro_forward_pl.c @@ -3,15 +3,15 @@ File: indopro_forward_pl.c Revision: $Id$ Contents: indopro_forward_pl (index domains abs-normal forward mode) - + Copyright (c) Kshitij Kulshrestha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _INDO_ 1 +#define _INDO_ 1 #define _INDOPRO_ 1 #define _NTIGHT_ 1 #define _ABS_NORM_ 1 diff --git a/ADOL-C/src/indopro_forward_s.c b/ADOL-C/src/indopro_forward_s.c index f774a9d4f..173b27975 100644 --- a/ADOL-C/src/indopro_forward_s.c +++ b/ADOL-C/src/indopro_forward_s.c @@ -3,19 +3,18 @@ File: int_forward_s.c Revision: $Id$ Contents: int_forward (integer forward mode for bit pattern propagation) - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INDO_ 1 #define _INDOPRO_ 1 #define _NTIGHT_ 1 -#include +#include #undef _INDO_ #undef _INDOPRO_ #undef _NTIGHT_ - diff --git a/ADOL-C/src/indopro_forward_t.c b/ADOL-C/src/indopro_forward_t.c index 462f7fd99..9cbfa04f4 100644 --- a/ADOL-C/src/indopro_forward_t.c +++ b/ADOL-C/src/indopro_forward_t.c @@ -5,17 +5,16 @@ Contents: int_forward (integer forward mode for bit pattern propagation) Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INDO_ 1 #define _INDOPRO_ 1 #define _TIGHT_ 1 -#include +#include #undef _INDO_ #undef _INDOPRO_ #undef _TIGHT_ - diff --git a/ADOL-C/src/int_forward_s.c b/ADOL-C/src/int_forward_s.c index 91e4139cc..1ac4a4022 100644 --- a/ADOL-C/src/int_forward_s.c +++ b/ADOL-C/src/int_forward_s.c @@ -3,17 +3,16 @@ File: int_forward_s.c Revision: $Id$ Contents: int_forward (integer forward mode safe for bit pattern propagation) - + Copyright (c) Andrea Walther, Christo Mitev - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INT_FOR_ 1 #define _NTIGHT_ 1 -#include +#include #undef _INT_FOR_ #undef _NTIGHT_ - diff --git a/ADOL-C/src/int_forward_t.c b/ADOL-C/src/int_forward_t.c index fc8379710..31c44b1bc 100644 --- a/ADOL-C/src/int_forward_t.c +++ b/ADOL-C/src/int_forward_t.c @@ -3,17 +3,16 @@ File: int_forward_t.c Revision: $Id$ Contents: int_forward (integer forward mode tight for bit pattern propagation) - + Copyright (c) Andrea Walther, Christo Mitev - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INT_FOR_ 1 #define _TIGHT_ 1 -#include +#include #undef _INT_FOR_ #undef _TIGHT_ - diff --git a/ADOL-C/src/int_reverse_s.c b/ADOL-C/src/int_reverse_s.c index e2130d770..3fc4900b8 100644 --- a/ADOL-C/src/int_reverse_s.c +++ b/ADOL-C/src/int_reverse_s.c @@ -3,17 +3,16 @@ File: int_reverse_s.c Revision: $Id$ Contents: int_reverse (integer reverse mode safe for bit pattern propagation) - + Copyright (c) Andrea Walther, Christo Mitev - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INT_REV_ 1 #define _NTIGHT_ 1 -#include +#include #undef _INT_REV_ #undef _NTIGHT_ - diff --git a/ADOL-C/src/int_reverse_t.c b/ADOL-C/src/int_reverse_t.c index b734ca923..e1cfde9c0 100644 --- a/ADOL-C/src/int_reverse_t.c +++ b/ADOL-C/src/int_reverse_t.c @@ -3,17 +3,16 @@ File: int_reverse_t.c Revision: $Id$ Contents: int_reverse (integer reverse mode tight for bit pattern propagation) - + Copyright (c) Andrea Walther, Christo Mitev - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ #define _INT_REV_ 1 #define _TIGHT_ 1 -#include +#include #undef _INT_REV_ #undef _TIGHT_ - diff --git a/ADOL-C/src/interfaces.cpp b/ADOL-C/src/interfaces.cpp index b8c00435b..18522d3ad 100644 --- a/ADOL-C/src/interfaces.cpp +++ b/ADOL-C/src/interfaces.cpp @@ -3,26 +3,27 @@ File: interfaces.cpp Revision: $Id$ Contents: Genuine C++ Interfaces to ADOL-C forward & reverse calls. - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#include -#include #include "dvlparms.h" +#include +#include /****************************************************************************/ /* MACROS */ #define fabs(x) ((x) > 0 ? (x) : -(x)) -#define ceil(x) ((int)((x)+1) - (int)((x) == (int)(x))) +#define ceil(x) ((int)((x) + 1) - (int)((x) == (int)(x))) -extern "C" void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line); +extern "C" void adolc_exit(int errorcode, const char *what, + const char *function, const char *file, int line); /****************************************************************************/ /* FORWARD MODE, overloaded calls */ @@ -30,441 +31,349 @@ extern "C" void adolc_exit(int errorcode, const char *what, const char* function /****************************************************************************/ /* general call */ /* */ -int forward( short tag, - int m, - int n, - int d, - int keep, - double **X, - double **Y) +int forward(short tag, int m, int n, int d, int keep, double **X, double **Y) /* forward(tag, m, n, d, keep, X[n][d+1], Y[m][d+1]) */ { /* olvo 980729 general ec */ - static double *x, *y, *xp, *yp; - static int maxn, maxm; - int rc = -1, i, k; - if (n > maxn) { - if (x) - myfree1(x); - if (xp) - myfree1(xp); - x = myalloc1(maxn = n); - xp = myalloc1(maxn); - } - if (m > maxm) { - if (y) - myfree1(y); - if (yp) - myfree1(yp); - y = myalloc1(maxm = m); - yp = myalloc1(maxm); - } - - /*------------------------------------------------------------------------*/ - /* prepare input */ - for (i=0; i maxn) { + if (x) + myfree1(x); + if (xp) + myfree1(xp); + x = myalloc1(maxn = n); + xp = myalloc1(maxn); + } + if (m > maxm) { + if (y) + myfree1(y); + if (yp) + myfree1(yp); + y = myalloc1(maxm = m); + yp = myalloc1(maxm); + } + + /*------------------------------------------------------------------------*/ + /* prepare input */ + for (i = 0; i < n; i++) { + x[i] = X[i][0]; + if (d == 1) + xp[i] = X[i][1]; + else + for (k = 0; k < d; k++) + X[i][k] = X[i][k + 1]; + } + + /*------------------------------------------------------------------------*/ + /* function calls */ + if (d == 0) + rc = zos_forward(tag, m, n, keep, x, y); + else if (d == 1) + rc = fos_forward(tag, m, n, keep, x, xp, y, yp); + else + rc = hos_forward(tag, m, n, d, keep, x, X, y, Y); + + /*------------------------------------------------------------------------*/ + /* prepare output */ + for (i = 0; i < n; i++) + if (d > 1) { + for (k = d; k > 0; k--) + X[i][k] = X[i][k - 1]; + X[i][0] = x[i]; } - /*------------------------------------------------------------------------*/ - /* function calls */ - if (d == 0) - rc = zos_forward(tag,m,n,keep,x,y); + for (i = 0; i < m; i++) { + if (d == 1) + Y[i][1] = yp[i]; else - if (d == 1) - rc = fos_forward(tag,m,n,keep,x,xp,y,yp); - else - rc = hos_forward(tag,m,n,d,keep,x,X,y,Y); - - /*------------------------------------------------------------------------*/ - /* prepare output */ - for (i=0; i 1) { - for (k=d; k>0; k--) - X[i][k] = X[i][k-1]; - X[i][0] = x[i]; - } - - for (i=0; i0; k--) - Y[i][k] = Y[i][k-1]; - Y[i][0] = y[i]; - } + for (k = d; k > 0; k--) + Y[i][k] = Y[i][k - 1]; + Y[i][0] = y[i]; + } - return rc; + return rc; } - /****************************************************************************/ /* Y can be one dimensional if m=1 */ /* */ -int forward( short tag, - int m, - int n, - int d, - int keep, - double **X, - double *Y) +int forward(short tag, int m, int n, int d, int keep, double **X, double *Y) /* forward(tag, 1, n, d, keep, X[n][d+1], Y[d+1]), m=1 */ { /* olvo 980729 general ec */ - static double *x, *xp; - static int maxn; - double y; - int rc= -1, i, k; - - if (m == 1) { - if (n > maxn) { - if (x) - myfree1(x); - if (xp) - myfree1(xp); - x = myalloc1(maxn = n); - xp = myalloc1(maxn); - } - - /*----------------------------------------------------------------------*/ - /* prepare input */ - for (i=0; i 1) { - for (k=d; k>0; k--) - X[i][k] = X[i][k-1]; - X[i][0] = x[i]; - } - - for (k=d; k>0; k--) - Y[k] = Y[k-1]; - Y[0] = y; - } else { - fprintf(DIAG_OUT,"ADOL-C error: wrong Y dimension in forward \n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + static double *x, *xp; + static int maxn; + double y; + int rc = -1, i, k; + + if (m == 1) { + if (n > maxn) { + if (x) + myfree1(x); + if (xp) + myfree1(xp); + x = myalloc1(maxn = n); + xp = myalloc1(maxn); } - return rc; -} + /*----------------------------------------------------------------------*/ + /* prepare input */ + for (i = 0; i < n; i++) { + x[i] = X[i][0]; + if (d == 1) + xp[i] = X[i][1]; + else + for (k = 0; k < d; k++) + X[i][k] = X[i][k + 1]; + } + + /*----------------------------------------------------------------------*/ + /* function calls */ + if (d == 0) + rc = zos_forward(tag, m, n, keep, x, &y); + else if (d == 1) + rc = fos_forward(tag, m, n, keep, x, xp, &y, Y); + else + rc = hos_forward(tag, m, n, d, keep, x, X, &y, &Y); + /*----------------------------------------------------------------------*/ + /* prepare output */ + for (i = 0; i < n; i++) + if (d > 1) { + for (k = d; k > 0; k--) + X[i][k] = X[i][k - 1]; + X[i][0] = x[i]; + } + + for (k = d; k > 0; k--) + Y[k] = Y[k - 1]; + Y[0] = y; + } else { + fprintf(DIAG_OUT, "ADOL-C error: wrong Y dimension in forward \n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + + return rc; +} /****************************************************************************/ /* X and Y can be one dimensional if d = 0 */ /* */ -int forward( short tag, - int m, - int n, - int d, - int keep, - double *X, - double *Y) +int forward(short tag, int m, int n, int d, int keep, double *X, double *Y) /* forward(tag, m, n, 0, keep, X[n], Y[m]), d=0 */ -{ int rc = -1; +{ + int rc = -1; - if (d != 0) { - fprintf(DIAG_OUT,"ADOL-C error: wrong X and Y dimensions in forward \n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else - rc = zos_forward(tag,m,n,keep,X,Y); + if (d != 0) { + fprintf(DIAG_OUT, "ADOL-C error: wrong X and Y dimensions in forward \n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } else + rc = zos_forward(tag, m, n, keep, X, Y); - return rc; + return rc; } - /****************************************************************************/ /* X and Y can be one dimensional if d omitted */ /* */ -int forward(short tag, - int m, - int n, - int keep, - double *X, - double *Y) +int forward(short tag, int m, int n, int keep, double *X, double *Y) /* forward(tag, m, n, keep, X[n], Y[m]) */ -{ return zos_forward(tag,m,n,keep,X,Y); +{ + return zos_forward(tag, m, n, keep, X, Y); } - /****************************************************************************/ /* general call */ /* */ -int forward( short tag, - int m, - int n, - int d, - int p, - double *x, - double ***X, - double *y, - double ***Y) +int forward(short tag, int m, int n, int d, int p, double *x, double ***X, + double *y, double ***Y) /* forward(tag, m, n, d, p, x[n], X[n][p][d], y[m], Y[m][p][d]) */ -{ return hov_forward(tag,m,n,d,p,x,X,y,Y); +{ + return hov_forward(tag, m, n, d, p, x, X, y, Y); } - /****************************************************************************/ /* general call */ /* */ -int forward( short tag, - int m, - int n, - int p, - double *x, - double **X, - double *y, - double **Y) +int forward(short tag, int m, int n, int p, double *x, double **X, double *y, + double **Y) /* forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]) */ -{ return fov_forward(tag,m,n,p,x,X,y,Y); +{ + return fov_forward(tag, m, n, p, x, X, y, Y); } - /****************************************************************************/ /* REVERSE MODE, overloaded calls */ /****************************************************************************/ /* general call */ /* */ -int reverse( short tag, - int m, - int n, - int d, - double *u, - double **Z) +int reverse(short tag, int m, int n, int d, double *u, double **Z) /* reverse(tag, m, n, d, u[m], Z[n][d+1]) */ -{ return hos_reverse(tag,m,n,d,u,Z); +{ + return hos_reverse(tag, m, n, d, u, Z); } - /****************************************************************************/ /* u can be a scalar if m=1 */ /* */ -int reverse( short tag, - int m, - int n, - int d, - double u, - double **Z) +int reverse(short tag, int m, int n, int d, double u, double **Z) /* reverse(tag, 1, n, 0, u, Z[n][d+1]), m=1 => u scalar */ -{ int rc=-1; +{ + int rc = -1; - if (m != 1) { - fprintf(DIAG_OUT,"ADOL-C error: wrong u dimension in scalar-reverse \n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else - rc = hos_reverse(tag,m,n,d,&u,Z); + if (m != 1) { + fprintf(DIAG_OUT, "ADOL-C error: wrong u dimension in scalar-reverse \n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } else + rc = hos_reverse(tag, m, n, d, &u, Z); - return rc; + return rc; } - /****************************************************************************/ /* Z can be vector if d = 0; Done by specialized code */ /* */ -int reverse( short tag, - int m, - int n, - int d, - double *u, - double *Z) +int reverse(short tag, int m, int n, int d, double *u, double *Z) /* reverse(tag, m, n, 0, u[m], Z[n]), d=0 */ -{ if (d != 0) { - fprintf(DIAG_OUT,"ADOL-C error: wrong Z dimension in scalar-reverse \n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } +{ + if (d != 0) { + fprintf(DIAG_OUT, "ADOL-C error: wrong Z dimension in scalar-reverse \n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } - return fos_reverse(tag,m,n,u,Z); + return fos_reverse(tag, m, n, u, Z); } - /****************************************************************************/ /* u and Z can be scalars if m=1 and d=0; */ /* */ -int reverse( short tag, - int m, - int n, - int d, - double u, - double *Z) +int reverse(short tag, int m, int n, int d, double u, double *Z) /* reverse(tag, 1, n, 0, u, Z[n]), m=1 and d=0 => u and Z scalars */ -{ int rc=-1; - - if (m != 1 || d != 0 ) { - fprintf(DIAG_OUT,"ADOL-C error: wrong u or Z dimension in scalar-reverse \n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else - rc = fos_reverse(tag,m,n,&u,Z); - \ - return rc; -} +{ + int rc = -1; + + if (m != 1 || d != 0) { + fprintf(DIAG_OUT, + "ADOL-C error: wrong u or Z dimension in scalar-reverse \n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } else + rc = fos_reverse(tag, m, n, &u, Z); + return rc; +} /****************************************************************************/ /* general call */ /* */ -int reverse( short tag, - int m, - int n, - int d, - int q, - double **U, - double ***Z, - short **nz) +int reverse(short tag, int m, int n, int d, int q, double **U, double ***Z, + short **nz) /* reverse(tag, m, n, d, q, U[q][m], Z[q][n][d+1], nz[q][n]) */ -{ return hov_reverse(tag,m,n,d,q,U,Z,nz); +{ + return hov_reverse(tag, m, n, d, q, U, Z, nz); } - /****************************************************************************/ /* U can be a vector if m=1 */ /* */ -int reverse( short tag, - int m, - int n, - int d, - int q, - double *U, - double ***Z, - short **nz) +int reverse(short tag, int m, int n, int d, int q, double *U, double ***Z, + short **nz) /* reverse(tag, 1, n, d, q, U[q], Z[q][n][d+1], nz[q][n]), m=1 => u vector */ -{ int rc=-1; - - if (m != 1) { - fprintf(DIAG_OUT,"ADOL-C error: wrong U dimension in vector-reverse \n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else { /* olvo 980727 ??? */ - /* double** upp = new double*[nrows]; */ - double **upp = (double**) malloc(q*sizeof(double*)); - for (int i=0; i Z matrix */ -{ int rc=-1; +{ + int rc = -1; - if (d != 0) { - fprintf(DIAG_OUT,"ADOL-C error: wrong degree in vector-reverse \n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else - rc = fov_reverse(tag,m,n,q,U,Z); + if (d != 0) { + fprintf(DIAG_OUT, "ADOL-C error: wrong degree in vector-reverse \n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } else + rc = fov_reverse(tag, m, n, q, U, Z); - return rc; + return rc; } - /****************************************************************************/ /* */ /* d=0 may be omitted, then Z may be a matrix; specialized code */ /* */ -int reverse( short tag, - int m, - int n, - int q, - double **U, - double **Z) +int reverse(short tag, int m, int n, int q, double **U, double **Z) /* reverse(tag, m, n, q, U[q][m], Z[q][n]), d=0 => Z matrix */ -{ int rc=-1; +{ + int rc = -1; - rc = fov_reverse(tag,m,n,q,U,Z); + rc = fov_reverse(tag, m, n, q, U, Z); - return rc; + return rc; } - /****************************************************************************/ /* */ /* If m=1 and d=0 then U can be vector and Z a matrix but no nz. */ /* */ -int reverse( short tag, - int m, - int n, - int d, - int q, - double *U, - double **Z) +int reverse(short tag, int m, int n, int d, int q, double *U, double **Z) /* reverse(tag, 1, n, 0, q, U[q], Z[q][n]), m=1 and d=0 => U vector and Z matrix but no nz */ -{ int rc=-1; - - /* olvo 981126 ??? what's that: */ - /* (++d)--; *//* degre is reserved for the future use. Ingore this line */ - - if ((m != 1) || (d != 0)) { - fprintf(DIAG_OUT,"ADOL-C error: wrong U dimension in vector-reverse \n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else { /* olvo 980727 ??? */ - /* double ** upp = new double*[nrows]; */ - double **upp = (double**) malloc(q*sizeof(double*)); - for (int i=0; i #include #include +#include BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ -fint hos_forward_(fint* ftag, - fint* fm, - fint* fn, - fint* fd, - fint* fk, - fdouble* fbase, - fdouble* fx, - fdouble* fvalue, - fdouble* fy) { - int rc= -1; - int tag=*ftag, m=*fm, n=*fn, d=*fd, k=*fk; - double* base = myalloc1(n); - double* value = myalloc1(m); - double** X = myalloc2(n,d); - double** Y = myalloc2(m,d); - spread1(n,fbase,base); - spread2(n,d,fx,X); - rc= hos_forward(tag,m,n,d,k,base,X,value,Y); - pack2(m,d,Y,fy); - pack1(m,value,fvalue); - myfree2(X); - myfree2(Y); - myfree1(base); - myfree1(value); - return rc; +fint hos_forward_(fint *ftag, fint *fm, fint *fn, fint *fd, fint *fk, + fdouble *fbase, fdouble *fx, fdouble *fvalue, fdouble *fy) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, d = *fd, k = *fk; + double *base = myalloc1(n); + double *value = myalloc1(m); + double **X = myalloc2(n, d); + double **Y = myalloc2(m, d); + spread1(n, fbase, base); + spread2(n, d, fx, X); + rc = hos_forward(tag, m, n, d, k, base, X, value, Y); + pack2(m, d, Y, fy); + pack1(m, value, fvalue); + myfree2(X); + myfree2(Y); + myfree1(base); + myfree1(value); + return rc; } /*--------------------------------------------------------------------------*/ -fint zos_forward_(fint* ftag, - fint* fm, - fint* fn, - fint* fk, - fdouble* fbase, - fdouble* fvalue) { - int rc=-1; - int tag=*ftag, m=*fm, n=*fn, k=*fk; - double* base=myalloc1(n); - double* value = myalloc1(m); - spread1(n,fbase,base); - rc=zos_forward(tag,m,n,k,base,value); - pack1(m,value,fvalue); - myfree1(base); - myfree1(value); - return rc; +fint zos_forward_(fint *ftag, fint *fm, fint *fn, fint *fk, fdouble *fbase, + fdouble *fvalue) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, k = *fk; + double *base = myalloc1(n); + double *value = myalloc1(m); + spread1(n, fbase, base); + rc = zos_forward(tag, m, n, k, base, value); + pack1(m, value, fvalue); + myfree1(base); + myfree1(value); + return rc; } /*--------------------------------------------------------------------------*/ -fint hov_forward_(fint* ftag, - fint* fm, - fint* fn, - fint* fd, - fint* fp, - fdouble* fbase, - fdouble* fx, - fdouble* fvalue, - fdouble* fy) { - int rc= -1; - int tag=*ftag, m=*fm, n=*fn, d=*fd, p=*fp; - double* base = myalloc1(n); - double* value = myalloc1(m); - double*** X = myalloc3(n,p,d); - double*** Y = myalloc3(m,p,d); - spread1(n,fbase,base); - spread3(n,p,d,fx,X); - rc= hov_forward(tag,m,n,d,p,base,X,value,Y); - pack3(m,p,d,Y,fy); - pack1(m,value,fvalue); - myfree3(X); - myfree3(Y); - myfree1(base); - myfree1(value); - return rc; +fint hov_forward_(fint *ftag, fint *fm, fint *fn, fint *fd, fint *fp, + fdouble *fbase, fdouble *fx, fdouble *fvalue, fdouble *fy) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, d = *fd, p = *fp; + double *base = myalloc1(n); + double *value = myalloc1(m); + double ***X = myalloc3(n, p, d); + double ***Y = myalloc3(m, p, d); + spread1(n, fbase, base); + spread3(n, p, d, fx, X); + rc = hov_forward(tag, m, n, d, p, base, X, value, Y); + pack3(m, p, d, Y, fy); + pack1(m, value, fvalue); + myfree3(X); + myfree3(Y); + myfree1(base); + myfree1(value); + return rc; } /*--------------------------------------------------------------------------*/ -fint fov_forward_(fint* ftag, - fint* fm, - fint* fn, - fint* fp, - fdouble* fbase, - fdouble* fx, - fdouble* fvalue, - fdouble* fy) { - int rc= -1; - int tag=*ftag, m=*fm, n=*fn, p=*fp; - double* base = myalloc1(n); - double* value = myalloc1(m); - double** X = myalloc2(n,p); - double** Y = myalloc2(m,p); - spread1(n,fbase,base); - spread2(n,p,fx,X); - rc= fov_forward(tag,m,n,p,base,X,value,Y); - pack2(m,p,Y,fy); - pack1(m,value,fvalue); - myfree2(X); - myfree2(Y); - myfree1(base); - myfree1(value); - return rc; +fint fov_forward_(fint *ftag, fint *fm, fint *fn, fint *fp, fdouble *fbase, + fdouble *fx, fdouble *fvalue, fdouble *fy) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, p = *fp; + double *base = myalloc1(n); + double *value = myalloc1(m); + double **X = myalloc2(n, p); + double **Y = myalloc2(m, p); + spread1(n, fbase, base); + spread2(n, p, fx, X); + rc = fov_forward(tag, m, n, p, base, X, value, Y); + pack2(m, p, Y, fy); + pack1(m, value, fvalue); + myfree2(X); + myfree2(Y); + myfree1(base); + myfree1(value); + return rc; } - /*--------------------------------------------------------------------------*/ -fint hos_reverse_(fint* ftag, - fint* fm, - fint* fn, - fint* fd, - fdouble* fu, - fdouble* fz) { - int rc=-1; - int tag=*ftag, m=*fm, n=*fn, d=*fd; - double** Z = myalloc2(n,d+1); - double* u = myalloc1(m); - spread1(m,fu,u); - rc=hos_reverse(tag,m,n,d,u,Z); - pack2(n,d+1,Z,fz); - myfree2(Z); - myfree1(u); - return rc; +fint hos_reverse_(fint *ftag, fint *fm, fint *fn, fint *fd, fdouble *fu, + fdouble *fz) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, d = *fd; + double **Z = myalloc2(n, d + 1); + double *u = myalloc1(m); + spread1(m, fu, u); + rc = hos_reverse(tag, m, n, d, u, Z); + pack2(n, d + 1, Z, fz); + myfree2(Z); + myfree1(u); + return rc; } /*--------------------------------------------------------------------------*/ -fint hos_ti_reverse_( - fint* ftag, - fint* fm, - fint* fn, - fint* fd, - fdouble* fu, - fdouble* fz) { - int rc=-1; - int tag=*ftag, m=*fm, n=*fn, d=*fd; - double** Z = myalloc2(n,d+1); - double** U = myalloc2(m,d+1); - spread2(m,d+1,fu,U); - rc=hos_ti_reverse(tag,m,n,d,U,Z); - pack2(n,d+1,Z,fz); - myfree2(Z); - myfree2(U); - return rc; +fint hos_ti_reverse_(fint *ftag, fint *fm, fint *fn, fint *fd, fdouble *fu, + fdouble *fz) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, d = *fd; + double **Z = myalloc2(n, d + 1); + double **U = myalloc2(m, d + 1); + spread2(m, d + 1, fu, U); + rc = hos_ti_reverse(tag, m, n, d, U, Z); + pack2(n, d + 1, Z, fz); + myfree2(Z); + myfree2(U); + return rc; } /*--------------------------------------------------------------------------*/ -fint fos_reverse_(fint* ftag, - fint* fm, - fint* fn, - fdouble* fu, - fdouble* fz) { - int rc=-1; - int tag=*ftag, m=*fm, n=*fn; - double* u = myalloc1(m); - double* Z = myalloc1(n); - spread1(m,fu,u); - rc=fos_reverse(tag,m,n,u,Z); - pack1(n,Z,fz); - myfree1(Z); - myfree1(u); - return rc; +fint fos_reverse_(fint *ftag, fint *fm, fint *fn, fdouble *fu, fdouble *fz) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn; + double *u = myalloc1(m); + double *Z = myalloc1(n); + spread1(m, fu, u); + rc = fos_reverse(tag, m, n, u, Z); + pack1(n, Z, fz); + myfree1(Z); + myfree1(u); + return rc; } /*--------------------------------------------------------------------------*/ -fint hov_reverse_(fint* ftag, - fint* fm, - fint* fn, - fint* fd, - fint* fq, - fdouble* fu, - fdouble* fz) { - int rc=-1; - int tag=*ftag, m=*fm, n=*fn, d=*fd, q=*fq; - double** U = myalloc2(q,m); - double*** Z = myalloc3(q,n,d+1); - short ** nop = 0; - spread2(q,m,fu,U); - rc=hov_reverse(tag,m,n,d,q,U,Z,nop); - pack3(q,n,d+1,Z,fz); - myfree3(Z); - myfree2(U); - return rc; +fint hov_reverse_(fint *ftag, fint *fm, fint *fn, fint *fd, fint *fq, + fdouble *fu, fdouble *fz) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, d = *fd, q = *fq; + double **U = myalloc2(q, m); + double ***Z = myalloc3(q, n, d + 1); + short **nop = 0; + spread2(q, m, fu, U); + rc = hov_reverse(tag, m, n, d, q, U, Z, nop); + pack3(q, n, d + 1, Z, fz); + myfree3(Z); + myfree2(U); + return rc; } /*--------------------------------------------------------------------------*/ -fint hov_ti_reverse_( - fint* ftag, - fint* fm, - fint* fn, - fint* fd, - fint* fq, - fdouble* fu, - fdouble* fz) { - int rc=-1; - int tag=*ftag, m=*fm, n=*fn, d=*fd, q=*fq; - double*** U = myalloc3(q,m,d+1); - double*** Z = myalloc3(q,n,d+1); - short ** nop = 0; - spread3(q,m,d+1,fu,U); - rc=hov_ti_reverse(tag,m,n,d,q,U,Z,nop); - pack3(q,n,d+1,Z,fz); - myfree3(Z); - myfree3(U); - return rc; +fint hov_ti_reverse_(fint *ftag, fint *fm, fint *fn, fint *fd, fint *fq, + fdouble *fu, fdouble *fz) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, d = *fd, q = *fq; + double ***U = myalloc3(q, m, d + 1); + double ***Z = myalloc3(q, n, d + 1); + short **nop = 0; + spread3(q, m, d + 1, fu, U); + rc = hov_ti_reverse(tag, m, n, d, q, U, Z, nop); + pack3(q, n, d + 1, Z, fz); + myfree3(Z); + myfree3(U); + return rc; } /*--------------------------------------------------------------------------*/ -fint fov_reverse_(fint* ftag, - fint* fm, - fint* fn, - fint* fq, - fdouble* fu, - fdouble* fz) { - int rc=-1; - int tag=*ftag, m=*fm, n=*fn, q=*fq; - double** U = myalloc2(q,m); - double** Z = myalloc2(q,n); - spread2(q,m,fu,U); - rc=fov_reverse(tag,m,n,q,U,Z); - pack2(q,n,Z,fz); - myfree2(Z); - myfree2(U); - return rc; +fint fov_reverse_(fint *ftag, fint *fm, fint *fn, fint *fq, fdouble *fu, + fdouble *fz) { + int rc = -1; + int tag = *ftag, m = *fm, n = *fn, q = *fq; + double **U = myalloc2(q, m); + double **Z = myalloc2(q, n); + spread2(q, m, fu, U); + rc = fov_reverse(tag, m, n, q, U, Z); + pack2(q, n, Z, fz); + myfree2(Z); + myfree2(U); + return rc; } - /****************************************************************************/ /* THAT'S ALL */ diff --git a/ADOL-C/src/lie/adolc_lie.cpp b/ADOL-C/src/lie/adolc_lie.cpp index db8580b24..b164316d6 100644 --- a/ADOL-C/src/lie/adolc_lie.cpp +++ b/ADOL-C/src/lie/adolc_lie.cpp @@ -3,42 +3,34 @@ File: lie/adolc_lie.cpp Revision: $Id$ Contents: Implementation of a C++ Wrapper for adolc_lie C-function calls - + Copyright (c) Siquian Wang, Klaus Röbenack, Jan Winkler, Mirko Franke This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ #include #include - -int lie_scalar(short Tape_F, short Tape_H, short n, short m, double* x0, - short d, double** result) -{ - return lie_scalarcv(Tape_F, Tape_H, n, m, x0, d, result); +int lie_scalar(short Tape_F, short Tape_H, short n, short m, double *x0, + short d, double **result) { + return lie_scalarcv(Tape_F, Tape_H, n, m, x0, d, result); } - -int lie_scalar(short Tape_F, short Tape_H, short n, double* x0, short d, - double* result) -{ - return lie_scalarc(Tape_F, Tape_H, n, x0, d, result); +int lie_scalar(short Tape_F, short Tape_H, short n, double *x0, short d, + double *result) { + return lie_scalarc(Tape_F, Tape_H, n, x0, d, result); } - -int lie_gradient(short int Tape_F, short int Tape_H, short int n, short int m, - double* x0, short int d, double*** result) -{ +int lie_gradient(short int Tape_F, short int Tape_H, short int n, short int m, + double *x0, short int d, double ***result) { return lie_gradientcv(Tape_F, Tape_H, n, m, x0, d, result); } - -int lie_gradient(short int Tape_F, short int Tape_H, short int n, double* x0, - short int d, double** result) -{ +int lie_gradient(short int Tape_F, short int Tape_H, short int n, double *x0, + short int d, double **result) { return lie_gradientc(Tape_F, Tape_H, n, x0, d, result); } diff --git a/ADOL-C/src/lie/adolc_lie_c.c b/ADOL-C/src/lie/adolc_lie_c.c index 84270846e..4a482d7bc 100644 --- a/ADOL-C/src/lie/adolc_lie_c.c +++ b/ADOL-C/src/lie/adolc_lie_c.c @@ -3,22 +3,19 @@ File: lie/adolc_lie_c.c Revision: $Id$ Contents: Implementation of functions for computation of Lie derivatives - + Copyright (c) Siquian Wang, Klaus Röbenack, Jan Winkler, Mirko Franke This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ +#include "dvlparms.h" #include #include #include -#include "dvlparms.h" - - - /** Computes the total derivative of the output * @@ -29,37 +26,30 @@ * @param ***C Partial derivative of the output mapping * @param ***D Total derivative of the output mapping */ -void accodeout (int p, int n, int deg, double ***B, double ***C, double ***D) -{ - int i, j, k, l, ip, jp, kp; - - /* D_k:=C_k (1. summation step) */ - for (k=0; k <= deg; k++) - { - for (j=0; j < p; j++) - for (i=0; i < n; i++) - D[j][i][k]=C[j][i][k]; - - /* add sum if necessary */ - if (k >= 1) - { - for (l=1; l<=k; l++) - for (jp=0; jp= 1) { + for (l = 1; l <= k; l++) + for (jp = 0; jp < p; jp++) + for (ip = 0; ip < n; ip++) { + double x = 0.0; + for (kp = 0; kp < n; kp++) { + x += C[jp][kp][k - l] * B[kp][ip][l - 1]; + }; + D[jp][ip][k] += x; + }; + }; + }; }; - - /** Helper function for calculation of the Lie derivatives of a covector field * * @param n Number of rows = number of columns @@ -68,94 +58,75 @@ void accodeout (int p, int n, int deg, double ***B, double ***C, double ***D) * @param **C Taylor coefficients of the output mapping (C[n][d]) * @retval **D Lie derivative along covector field (D[n][d]) */ -void acccov(int n, int d, double ***B, double **C, double **D) -{ - int i, k, l, ip, kp; - - /* factorial */ - int Fak = 1; - - /* D_k:=Fak*C_k (1. summation step) */ - for (k = 0; k <= d; k++) - { - if(k == 0) - Fak = 1; - else - Fak = Fak*k; - - for (i = 0; i < n; i++) - D[i][k]=Fak*C[i][k]; - - /* add sum if necessary */ - if (k>=1) - { - double x; - for (l = 1; l <= k; l++) - { - for (ip = 0; ip < n; ip++) - { - x = 0.0; - for (kp = 0; kp < n; kp++) - { - x+=C[kp][k-l]*B[kp][ip][l-1]; - }; - D[ip][k]+= Fak*x; - }; - }; - }; - }; +void acccov(int n, int d, double ***B, double **C, double **D) { + int i, k, l, ip, kp; + + /* factorial */ + int Fak = 1; + + /* D_k:=Fak*C_k (1. summation step) */ + for (k = 0; k <= d; k++) { + if (k == 0) + Fak = 1; + else + Fak = Fak * k; + + for (i = 0; i < n; i++) + D[i][k] = Fak * C[i][k]; + + /* add sum if necessary */ + if (k >= 1) { + double x; + for (l = 1; l <= k; l++) { + for (ip = 0; ip < n; ip++) { + x = 0.0; + for (kp = 0; kp < n; kp++) { + x += C[kp][k - l] * B[kp][ip][l - 1]; + }; + D[ip][k] += Fak * x; + }; + }; + }; + }; }; - - - -/** Helper function for calculation of Lie-brackets (solution of the adjoint variational equation) +/** Helper function for calculation of Lie-brackets (solution of the adjoint + * variational equation) * * @param n Number of columns of B (number of inputs) * @param deg Order of derivative * @param ***A Total derivative of A * @retval ***Bs Solution of adjoint variational equation */ -void accadj(int n, int deg, double ***A, double ***Bs) -{ - int i, j, k, l, ip, jp, kp; - - /* (1. summation step) */ - for (k = 0; k <= deg; k++) - { - for (j = 0; j < n; j++) - { - for (i = 0; i < n; i++) - { - Bs[j][i][k] = -A[i][j][k]/(k+1); - } - } - - /* add sum if necessary */ - if (k >= 1) - { - double x = 0.0; - for (l = 1; l <= k; l++) - { - for (jp = 0; jp < n; jp++) - { - for (ip = 0; ip < n; ip++) - { - x = 0.0; - for (kp = 0; kp < n; kp++) - { - x+=A[kp][jp][k-l]*Bs[kp][ip][l-1]; - }; - Bs[jp][ip][k] -= x/(k+1); - }; - }; - }; - }; - }; +void accadj(int n, int deg, double ***A, double ***Bs) { + int i, j, k, l, ip, jp, kp; + + /* (1. summation step) */ + for (k = 0; k <= deg; k++) { + for (j = 0; j < n; j++) { + for (i = 0; i < n; i++) { + Bs[j][i][k] = -A[i][j][k] / (k + 1); + } + } + + /* add sum if necessary */ + if (k >= 1) { + double x = 0.0; + for (l = 1; l <= k; l++) { + for (jp = 0; jp < n; jp++) { + for (ip = 0; ip < n; ip++) { + x = 0.0; + for (kp = 0; kp < n; kp++) { + x += A[kp][jp][k - l] * Bs[kp][ip][l - 1]; + }; + Bs[jp][ip][k] -= x / (k + 1); + }; + }; + }; + }; + }; }; - - /** Calculates the Lie-derivative along a co vector field * * @param n Number of rows and columns @@ -164,119 +135,99 @@ void accadj(int n, int deg, double ***A, double ***Bs) * @param b Taylor-coefficients of output mapping (b[n][d]) * @retval result Lie derivative along co-vector field (result[n][d]) */ -void accbrac(int n, int d, double ***Bs, double **b, double **result) -{ - int i, j, k, l, jp, kp; - - /* factorial */ - int Fak = 1; - - /* formula 3.58 */ - for (k = 0; k <= d; k++) - { - if(k == 0) - Fak = 1; - else - Fak = Fak*k; - - for (j = 0; j < n; j++) - { - for (i = 0; i < n; i++) - { - result[i][k] = Fak*b[i][k]; - } - - if(k >= 1) - { - double x; - for (l = 1; l <= k; l++) - { - for (jp = 0; jp < n; jp++) - { - x = 0.0; - for (kp = 0; kp < n; kp++) - { - x+=Bs[kp][jp][l-1]*b[kp][k-l]; - } - result[jp][k]+=Fak*x; - }; - }; - }; - }; - }; +void accbrac(int n, int d, double ***Bs, double **b, double **result) { + int i, j, k, l, jp, kp; + + /* factorial */ + int Fak = 1; + + /* formula 3.58 */ + for (k = 0; k <= d; k++) { + if (k == 0) + Fak = 1; + else + Fak = Fak * k; + + for (j = 0; j < n; j++) { + for (i = 0; i < n; i++) { + result[i][k] = Fak * b[i][k]; + } + + if (k >= 1) { + double x; + for (l = 1; l <= k; l++) { + for (jp = 0; jp < n; jp++) { + x = 0.0; + for (kp = 0; kp < n; kp++) { + x += Bs[kp][jp][l - 1] * b[kp][k - l]; + } + result[jp][k] += Fak * x; + }; + }; + }; + }; + }; }; - - - - - -/** Computes the Lie derivative of smooth map h : D -> R^m along a vector field f : D -> R^n - * \param Tape_F tape identification of vector field f - * \param Tape_H tape identification of vector field h - * \param n number of independent variables n - * \param m number of dependent variables m +/** Computes the Lie derivative of smooth map h : D -> R^m along a vector field + * f : D -> R^n \param Tape_F tape identification of vector field f \param + * Tape_H tape identification of vector field h \param n number of + * independent variables n \param m number of dependent variables m * \param x0 values of independent variables x0 (dimension [n]) * \param d highest derivative degree d - * \param result resulting Lie derivatives of vectorial scalar fields (dimension [m][d+1]) + * \param result resulting Lie derivatives of vectorial scalar fields (dimension + * [m][d+1]) */ -int lie_scalarcv(short Tape_F, short Tape_H, short n, short m, double* x0, short d, double** result) -{ - double** X = myalloc2(n, d+1); /* Taylorcoeff. expansion x(t) */ - double** Y = myalloc2(m, d+1); /* Taylorcoeff. expansion y(t) */ - double* x = myalloc1(n); - double* y = myalloc1(m); - int i=0, j=0, k=0; - double Fak = 1.0; - - for (i = 0; i < n; i++) - { - X[i][0] = x0[i]; - }; - - /* see odedrivers */ - forodec(Tape_F, n, 1.0, 0, d, X); - - /* prepare for input */ - for (i = 0; i < n; i++) - { - x[i] = X[i][0]; - for (k = 0; k < d; k++) - X[i][k] = X[i][k+1]; - } - - hos_forward(Tape_H, m, n, d, 0, x, X, y, Y); - - /* postprocess output of hos_forward */ - for (i=0; i 0; k--) - { - Y[i][k] = Y[i][k-1]; - }; - Y[i][0] = y[i]; - }; - - /* prepare output for lie_Scalar */ - for(j=0;j 0; k--) { + Y[i][k] = Y[i][k - 1]; + }; + Y[i][0] = y[i]; + }; + + /* prepare output for lie_Scalar */ + for (j = 0; j < m; j++) { + for (i = 0; i <= d; i++) { + result[j][i] = Fak * Y[j][i]; + Fak = Fak * (i + 1); + } + Fak = 1.0; + } + + myfree2(X); + myfree2(Y); + myfree1(x); + myfree1(y); + + return -1; } - /** Lie derivative of scalar field h : D -> R^m along vector field f : D -> R^n * \param Tape_F tape identification of vector field f * \param Tape_H tape identification of scalar field h @@ -285,127 +236,114 @@ int lie_scalarcv(short Tape_F, short Tape_H, short n, short m, double* x0, short * \param d highest derivative degree d * \retval result resulting Lie derivatives of a scalar field (dimension [d+1]) */ -int lie_scalarc(short Tape_F, short Tape_H, short n, double* x0, short d, double* result) -{ - int rc= -1; - short m = 1, i=0; - double** Temp = myalloc2(m, d+1); +int lie_scalarc(short Tape_F, short Tape_H, short n, double *x0, short d, + double *result) { + int rc = -1; + short m = 1, i = 0; + double **Temp = myalloc2(m, d + 1); - rc = lie_scalarcv(Tape_F, Tape_H, n, m, x0, d, Temp); + rc = lie_scalarcv(Tape_F, Tape_H, n, m, x0, d, Temp); - for (i = 0; i <= d; i++) - { - result[i] = Temp[0][i]; - } + for (i = 0; i <= d; i++) { + result[i] = Temp[0][i]; + } - myfree2(Temp); + myfree2(Temp); - return rc; + return rc; } - -/** Calculates the jacobians of the Lie derivatives of scalar fields h : D -> R^m - * \param Tape_F tape identification of vector field f - * \param Tape_H tape identification of vector field h - * \param n number of independent variables n - * \param m number of dependent variables m - * \param x0 values of independent variables x0 (dimension [n]) - * \param d highest derivative degree d - * \retval result resulting jacobians of Lie derivatives of vectorial scalar fields (dimension [m][n][d+1]) +/** Calculates the jacobians of the Lie derivatives of scalar fields h : D -> + * R^m \param Tape_F tape identification of vector field f \param Tape_H tape + * identification of vector field h \param n number of independent + * variables n \param m number of dependent variables m \param x0 values of + * independent variables x0 (dimension [n]) \param d highest derivative + * degree d \retval result resulting jacobians of Lie derivatives of vectorial + * scalar fields (dimension [m][n][d+1]) */ -int lie_gradientcv(short Tape_F, short Tape_H, short n, short m, double* x0, short d, double*** result) -{ - double **X=myalloc2(n,d+1); - double **Y=myalloc2(m,d+1); - double ***Pc=myalloc3(m,n,d+1); - double ***A=myalloc3(n,n,d); - double ***B=myalloc3(n,n,d); - double ***D=myalloc3(m,n,d+1); - - double* x = myalloc1(n); - double* y = myalloc1(m); - double* xp = myalloc1(n); - double* yp = myalloc1(m); - - static int depax_m,depax_n; - static double** In; - static double** Im; - - int i=0, j=0, l=0, k=0, rc=-1; - double Fak=1.0; - - for (i = 0; i < n; i++) - X[i][0] = x0[i]; - - forodec(Tape_F, n, 1.0, 0, d, X); - - if (n adolc_compsize depax_n) { - if (depax_n) - myfreeI2(depax_n,In); - In = myallocI2(depax_n = n); - } - if (m adolc_compsize depax_m) { - if (depax_m) - myfreeI2(depax_m,Im); - Im = myallocI2(depax_m = m); - } - - hov_reverse(Tape_F,n,n,d-1,n,In,A,0); /* explanation in interfaces.cpp */ - accodec(n, 1.0, d-1, A, B, 0); /* explanation in odedrivers.c */ - - /* prepare for input */ - for (i=0; i R * * \param Tape_F tape identification of vector field f @@ -413,118 +351,117 @@ int lie_gradientcv(short Tape_F, short Tape_H, short n, short m, double* x0, sho * \param n number of independent variables n * \param x0 values of independent variables x0 (dimension [n]) * \param d highest derivative degree d - * \retval result resulting jacobians of Lie derivatives of a scalar field (dimension [n][d+1]) + * \retval result resulting jacobians of Lie derivatives of a scalar field + * (dimension [n][d+1]) */ -int lie_gradientc(short Tape_F, short Tape_H, short n, double* x0, short d, double** result) -{ - int rc= -1; - short m = 1, i=0, j=0; - double*** Temp = myalloc3(m, n, d+1); - - rc = lie_gradientcv(Tape_F, Tape_H, n, m, x0, d, Temp); +int lie_gradientc(short Tape_F, short Tape_H, short n, double *x0, short d, + double **result) { + int rc = -1; + short m = 1, i = 0, j = 0; + double ***Temp = myalloc3(m, n, d + 1); - for(i=0; i (R^m)* along the vector field f : D -> R^n +/** Computes the Lie derivatives of the covector field w : D -> (R^m)* along the + * vector field f : D -> R^n * * \param Tape_F tape identification of vector field f * \param Tape_W tape identification of covector field h * \param n number of independent variables n * \param x0 values of independent variables x0 (dimension [n]) * \param d highest derivative degree d - * \retval result resulting Lie derivatives of a covector field (dimension [n][d+1]) + * \retval result resulting Lie derivatives of a covector field (dimension + * [n][d+1]) */ -int lie_covector( short int Tape_F, short int Tape_W, short int n, double* x0, short int d, double** result) -{ - int m=n; - double** X = myalloc2(n, d+1); /* Taylorcoeff. expansion x(t) */ - double** Y = myalloc2(m, d+1); /* Taylorcoeff. expansion y(t) */ - - double***A = myalloc3(n, n, d); - double***B = myalloc3(n, n, d+1); - - double* x = myalloc1(n); - double* y = myalloc1(m); - double* xp = myalloc1(n); - double* yp = myalloc1(m); - - int i=0, k=0; - - static int depax_m,depax_n; - static double** In; - static double** Im; - - for (i = 0; i < n; i++) X[i][0] = x0[i]; - - forodec(Tape_F, n, 1.0, 0, d, X); - - if (n adolc_compsize depax_n) { - if (depax_n) - myfreeI2(depax_n,In); - In = myallocI2(depax_n = n); - } - if (m adolc_compsize depax_m) { - if (depax_m) - myfreeI2(depax_m,Im); - Im = myallocI2(depax_m = m); - } - - hov_reverse(Tape_F,n,n,d-1,n,In,A,0); /* explanation in interfaces.cpp */ - - /* prepare for input */ - for (i=0; i0; k--) - Y[i][k] = Y[i][k-1]; - Y[i][0] = y[i]; - } - - accodec(n, 1.0, d-1, A, B, 0); /* explanation in odedrivers.c */ - acccov(n, d, B, Y, result); - - myfree2(X); - myfree2(Y); - myfree3(A); - myfree3(B); - - myfree1(x); - myfree1(y); - myfree1(xp); - myfree1(yp); - - return -1; +int lie_covector(short int Tape_F, short int Tape_W, short int n, double *x0, + short int d, double **result) { + int m = n; + double **X = myalloc2(n, d + 1); /* Taylorcoeff. expansion x(t) */ + double **Y = myalloc2(m, d + 1); /* Taylorcoeff. expansion y(t) */ + + double ***A = myalloc3(n, n, d); + double ***B = myalloc3(n, n, d + 1); + + double *x = myalloc1(n); + double *y = myalloc1(m); + double *xp = myalloc1(n); + double *yp = myalloc1(m); + + int i = 0, k = 0; + + static int depax_m, depax_n; + static double **In; + static double **Im; + + for (i = 0; i < n; i++) + X[i][0] = x0[i]; + + forodec(Tape_F, n, 1.0, 0, d, X); + + if (n adolc_compsize depax_n) { + if (depax_n) + myfreeI2(depax_n, In); + In = myallocI2(depax_n = n); + } + if (m adolc_compsize depax_m) { + if (depax_m) + myfreeI2(depax_m, Im); + Im = myallocI2(depax_m = m); + } + + hov_reverse(Tape_F, n, n, d - 1, n, In, A, + 0); /* explanation in interfaces.cpp */ + + /* prepare for input */ + for (i = 0; i < n; i++) { + x[i] = X[i][0]; + if (d == 1) + xp[i] = X[i][1]; + else + for (k = 0; k < d; k++) + X[i][k] = X[i][k + 1]; + } + + hos_forward(Tape_W, m, n, d, d + 1, x, X, y, Y); + + /* postprocess output of hos_forward */ + for (i = 0; i < m; i++) { + if (d == 1) + Y[i][1] = yp[i]; + else + for (k = d; k > 0; k--) + Y[i][k] = Y[i][k - 1]; + Y[i][0] = y[i]; + } + + accodec(n, 1.0, d - 1, A, B, 0); /* explanation in odedrivers.c */ + acccov(n, d, B, Y, result); + + myfree2(X); + myfree2(Y); + myfree3(A); + myfree3(B); + + myfree1(x); + myfree1(y); + myfree1(xp); + myfree1(yp); + + return -1; } - - - -/** Calculates the iterated Lie derivatives (Lie brackets) of the vector field g : D -> R^n along the vector field f : D -> R^n +/** Calculates the iterated Lie derivatives (Lie brackets) of the vector field g + * : D -> R^n along the vector field f : D -> R^n * * \param Tape_F tape identification of vector field f * \param Tape_G tape identification of vector field g @@ -532,70 +469,60 @@ int lie_covector( short int Tape_F, short int Tape_W, short int n, double* x0, s * \param x0 values of independent variables x0 (dimension [n]) * \param d highest derivative degree d */ -int lie_bracket(short int Tape_F, short int Tape_G, short int n, double* x0, short int d, double** result) -{ - int m = n; - double **X = myalloc2(n, d+2); /* Taylorcoeff. expansion x(t) */ - double **Y = myalloc2(m, d+2); /* Taylorcoeff. expansion y(t) */ - double ***A = myalloc3(n, n, d+1); - double ***Xs = myalloc3(n, n, d+1); - - double* y = myalloc1(m); - - int i, k; - - /* static identity matrix for hov_reverse */ - static int depax_n = 0; - static double** In = NULL; - - - for (i = 0; i < n; i++) - { - X[i][0] = x0[i]; - }; - forodec(Tape_F, n, 1.0, 0, d+1, X); - - /* for hov_reverse */ - if (n > depax_n) - { - if (depax_n) - { - myfreeI2(depax_n, In); - }; - In = myallocI2(depax_n = n); - } - hov_reverse(Tape_F, n, n, d, n, In, A, 0); - - /* prepare for input */ - for (i = 0; i < n; i++) - { - for (k = 0; k < d; k++) - { - X[i][k] = X[i][k+1]; - } - } - hos_forward(Tape_G, m, n, d+1, d+2, x0, X, y, Y); - - /* postprocess output of hos_forward */ - for (i = 0; i < m; i++) - { - for (k = d; k > 0; k--) - { - Y[i][k] = Y[i][k-1]; - } - Y[i][0] = y[i]; - } - - accadj(n, d, A, Xs); - accbrac(n, d, Xs, Y, result); - - myfree1(y); - myfree2(X); - myfree2(Y); - myfree3(A); - myfree3(Xs); - - return -1; +int lie_bracket(short int Tape_F, short int Tape_G, short int n, double *x0, + short int d, double **result) { + int m = n; + double **X = myalloc2(n, d + 2); /* Taylorcoeff. expansion x(t) */ + double **Y = myalloc2(m, d + 2); /* Taylorcoeff. expansion y(t) */ + double ***A = myalloc3(n, n, d + 1); + double ***Xs = myalloc3(n, n, d + 1); + + double *y = myalloc1(m); + + int i, k; + + /* static identity matrix for hov_reverse */ + static int depax_n = 0; + static double **In = NULL; + + for (i = 0; i < n; i++) { + X[i][0] = x0[i]; + }; + forodec(Tape_F, n, 1.0, 0, d + 1, X); + + /* for hov_reverse */ + if (n > depax_n) { + if (depax_n) { + myfreeI2(depax_n, In); + }; + In = myallocI2(depax_n = n); + } + hov_reverse(Tape_F, n, n, d, n, In, A, 0); + + /* prepare for input */ + for (i = 0; i < n; i++) { + for (k = 0; k < d; k++) { + X[i][k] = X[i][k + 1]; + } + } + hos_forward(Tape_G, m, n, d + 1, d + 2, x0, X, y, Y); + + /* postprocess output of hos_forward */ + for (i = 0; i < m; i++) { + for (k = d; k > 0; k--) { + Y[i][k] = Y[i][k - 1]; + } + Y[i][0] = y[i]; + } + + accadj(n, d, A, Xs); + accbrac(n, d, Xs, Y, result); + + myfree1(y); + myfree2(X); + myfree2(Y); + myfree3(A); + myfree3(Xs); + + return -1; }; - - diff --git a/ADOL-C/src/medipacksupport.cpp b/ADOL-C/src/medipacksupport.cpp index 5eaa509f1..02ccb1123 100644 --- a/ADOL-C/src/medipacksupport.cpp +++ b/ADOL-C/src/medipacksupport.cpp @@ -11,200 +11,195 @@ ----------------------------------------------------------------------------*/ -#include "taping_p.h" -#include "oplate.h" #include "adolc/adouble.h" +#include "oplate.h" +#include "taping_p.h" #ifdef ADOLC_MEDIPACK_SUPPORT -#include -#include "medipacksupport_p.h" + #include "medipacksupport_p.h" + #include struct AdolcMeDiAdjointInterface : public medi::AdjointInterface { - double** adjointBase; - double* primalBase; - int vecSize; + double **adjointBase; + double *primalBase; + int vecSize; - AdolcMeDiAdjointInterface(double** adjointBase, double* primalBase, int vecSize) : - adjointBase(adjointBase), - primalBase(primalBase), - vecSize(vecSize) {} + AdolcMeDiAdjointInterface(double **adjointBase, double *primalBase, + int vecSize) + : adjointBase(adjointBase), primalBase(primalBase), vecSize(vecSize) {} - int computeElements(int elements) const { - return elements * vecSize; - } + int computeElements(int elements) const { return elements * vecSize; } - int getVectorSize() const { - return vecSize; - } + int getVectorSize() const { return vecSize; } - inline void createAdjointTypeBuffer(void* &buf, size_t size) const { - buf = (void*)new double[size*vecSize]; - } + inline void createAdjointTypeBuffer(void *&buf, size_t size) const { + buf = (void *)new double[size * vecSize]; + } - inline void deleteAdjointTypeBuffer(void* &b) const { - if(NULL != b) { - double* buf = (double*)b; - delete [] buf; - b = NULL; - } + inline void deleteAdjointTypeBuffer(void *&b) const { + if (NULL != b) { + double *buf = (double *)b; + delete[] buf; + b = NULL; } + } - inline void createPrimalTypeBuffer(void* &buf, size_t size) const { - buf = (void*)new double[size]; - } + inline void createPrimalTypeBuffer(void *&buf, size_t size) const { + buf = (void *)new double[size]; + } - inline void deletePrimalTypeBuffer(void* &b) const { - if(NULL != b) { - double* buf = (double*)b; - delete [] buf; - b = NULL; - } + inline void deletePrimalTypeBuffer(void *&b) const { + if (NULL != b) { + double *buf = (double *)b; + delete[] buf; + b = NULL; } + } - inline void getAdjoints(const void* i, void* a, int elements) const { - double* adjoints = (double*)a; - int* indices = (int*)i; + inline void getAdjoints(const void *i, void *a, int elements) const { + double *adjoints = (double *)a; + int *indices = (int *)i; - for(int pos = 0; pos < elements; ++pos) { - for(int dim = 0; dim < vecSize; ++dim) { - adjoints[calcIndex(pos, dim)] = adjointBase[dim][indices[pos]]; - adjointBase[dim][indices[pos]] = 0.0; - } + for (int pos = 0; pos < elements; ++pos) { + for (int dim = 0; dim < vecSize; ++dim) { + adjoints[calcIndex(pos, dim)] = adjointBase[dim][indices[pos]]; + adjointBase[dim][indices[pos]] = 0.0; } } + } - inline void updateAdjoints(const void* i, const void* a, int elements) const { - double* adjoints = (double*)a; - int* indices = (int*)i; + inline void updateAdjoints(const void *i, const void *a, int elements) const { + double *adjoints = (double *)a; + int *indices = (int *)i; - for(int pos = 0; pos < elements; ++pos) { - for(int dim = 0; dim < vecSize; ++dim) { - adjointBase[dim][indices[pos]] += adjoints[calcIndex(pos, dim)]; - } + for (int pos = 0; pos < elements; ++pos) { + for (int dim = 0; dim < vecSize; ++dim) { + adjointBase[dim][indices[pos]] += adjoints[calcIndex(pos, dim)]; } } + } - inline void setPrimals(const void* i, const void* p, int elements) const { - double* primals = (double*)p; - int* indices = (int*)i; + inline void setPrimals(const void *i, const void *p, int elements) const { + double *primals = (double *)p; + int *indices = (int *)i; - for(int pos = 0; pos < elements; ++pos) { - primalBase[indices[pos]] = primals[pos]; - } + for (int pos = 0; pos < elements; ++pos) { + primalBase[indices[pos]] = primals[pos]; } + } - inline void getPrimals(const void* i, const void* p, int elements) const { - double* primals = (double*)p; - int* indices = (int*)i; + inline void getPrimals(const void *i, const void *p, int elements) const { + double *primals = (double *)p; + int *indices = (int *)i; - for(int pos = 0; pos < elements; ++pos) { - primals[pos] = primalBase[indices[pos]]; - } + for (int pos = 0; pos < elements; ++pos) { + primals[pos] = primalBase[indices[pos]]; } + } - inline void combineAdjoints(void* b, const int elements, const int ranks) const { - double* buf = (double*)b; - for(int curRank = 1; curRank < ranks; ++curRank) { - for(int curPos = 0; curPos < elements; ++curPos) { - for(int dim = 0; dim < vecSize; ++dim) { - buf[calcIndex(curPos, dim)] += buf[calcIndex(elements * curRank + curPos, dim)]; - } + inline void combineAdjoints(void *b, const int elements, + const int ranks) const { + double *buf = (double *)b; + for (int curRank = 1; curRank < ranks; ++curRank) { + for (int curPos = 0; curPos < elements; ++curPos) { + for (int dim = 0; dim < vecSize; ++dim) { + buf[calcIndex(curPos, dim)] += + buf[calcIndex(elements * curRank + curPos, dim)]; } } } + } - private: - - inline int calcIndex(int pos, int dim) const { - return pos * vecSize + dim; - } +private: + inline int calcIndex(int pos, int dim) const { return pos * vecSize + dim; } }; struct AdolcMediStatic { - typedef std::vector HandleVector; - std::vector tapeHandles; + typedef std::vector HandleVector; + std::vector tapeHandles; - ~AdolcMediStatic() { - for(size_t i = 0; i < tapeHandles.size(); ++i) { - if(nullptr != tapeHandles[i]) { - clearHandles(*tapeHandles[i]); + ~AdolcMediStatic() { + for (size_t i = 0; i < tapeHandles.size(); ++i) { + if (nullptr != tapeHandles[i]) { + clearHandles(*tapeHandles[i]); - delete tapeHandles[i]; - tapeHandles[i] = nullptr; - } + delete tapeHandles[i]; + tapeHandles[i] = nullptr; } } + } - HandleVector& getTapeVector(short tapeId) { - return *tapeHandles[tapeId]; - } - - void callHandleReverse(short tapeId, locint index, AdolcMeDiAdjointInterface& interface) { - HandleVector& handleVec = getTapeVector(tapeId); + HandleVector &getTapeVector(short tapeId) { return *tapeHandles[tapeId]; } - medi::HandleBase* handle = handleVec[index]; + void callHandleReverse(short tapeId, locint index, + AdolcMeDiAdjointInterface &interface) { + HandleVector &handleVec = getTapeVector(tapeId); - handle->funcReverse(handle, &interface); - } + medi::HandleBase *handle = handleVec[index]; - void callHandleForward(short tapeId, locint index, AdolcMeDiAdjointInterface& interface) { - HandleVector& handleVec = getTapeVector(tapeId); + handle->funcReverse(handle, &interface); + } - medi::HandleBase* handle = handleVec[index]; + void callHandleForward(short tapeId, locint index, + AdolcMeDiAdjointInterface &interface) { + HandleVector &handleVec = getTapeVector(tapeId); - handle->funcForward(handle, &interface); - } + medi::HandleBase *handle = handleVec[index]; - void callHandlePrimal(short tapeId, locint index, AdolcMeDiAdjointInterface& interface) { - HandleVector& handleVec = getTapeVector(tapeId); + handle->funcForward(handle, &interface); + } - medi::HandleBase* handle = handleVec[index]; + void callHandlePrimal(short tapeId, locint index, + AdolcMeDiAdjointInterface &interface) { + HandleVector &handleVec = getTapeVector(tapeId); - handle->funcPrimal(handle, &interface); - } + medi::HandleBase *handle = handleVec[index]; - void initTape(short tapeId) { - if((size_t)tapeId >= tapeHandles.size()) { - tapeHandles.resize(tapeId + 1, nullptr); - } + handle->funcPrimal(handle, &interface); + } - if(nullptr == tapeHandles[tapeId]) { - tapeHandles[tapeId] = new HandleVector(); - } else { - clearHandles(*tapeHandles[tapeId]); - } + void initTape(short tapeId) { + if ((size_t)tapeId >= tapeHandles.size()) { + tapeHandles.resize(tapeId + 1, nullptr); } - void freeTape(short tapeId) { - if((size_t)tapeId < tapeHandles.size() && nullptr != tapeHandles[tapeId]) { - clearHandles(*tapeHandles[tapeId]); - } + if (nullptr == tapeHandles[tapeId]) { + tapeHandles[tapeId] = new HandleVector(); + } else { + clearHandles(*tapeHandles[tapeId]); } + } - void clearHandles(HandleVector& handles) { - for(size_t i = 0; i < handles.size(); ++i) { - medi::HandleBase* h = handles[i]; + void freeTape(short tapeId) { + if ((size_t)tapeId < tapeHandles.size() && nullptr != tapeHandles[tapeId]) { + clearHandles(*tapeHandles[tapeId]); + } + } - delete h; - } + void clearHandles(HandleVector &handles) { + for (size_t i = 0; i < handles.size(); ++i) { + medi::HandleBase *h = handles[i]; - handles.resize(0); + delete h; } - locint addHandle(short tapeId, medi::HandleBase* handle) { - HandleVector& vector = getTapeVector(tapeId); + handles.resize(0); + } - locint index = (locint)vector.size(); - vector.push_back(handle); - return index; - } + locint addHandle(short tapeId, medi::HandleBase *handle) { + HandleVector &vector = getTapeVector(tapeId); + + locint index = (locint)vector.size(); + vector.push_back(handle); + return index; + } }; -AdolcMediStatic* adolcMediStatic; +AdolcMediStatic *adolcMediStatic; -void mediAddHandle(medi::HandleBase* h) { +void mediAddHandle(medi::HandleBase *h) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; @@ -215,46 +210,46 @@ void mediAddHandle(medi::HandleBase* h) { ADOLC_PUT_LOCINT(index); } -void mediCallHandleReverse(short tapeId, locint index, double* primalVec, double** adjointVec, int vecSize) { +void mediCallHandleReverse(short tapeId, locint index, double *primalVec, + double **adjointVec, int vecSize) { AdolcMeDiAdjointInterface interface(adjointVec, primalVec, vecSize); adolcMediStatic->callHandleReverse(tapeId, index, interface); } -void mediCallHandleForward(short tapeId, locint index, double* primalVec, double** adjointVec, int vecSize) { +void mediCallHandleForward(short tapeId, locint index, double *primalVec, + double **adjointVec, int vecSize) { AdolcMeDiAdjointInterface interface(adjointVec, primalVec, vecSize); adolcMediStatic->callHandleForward(tapeId, index, interface); } -void mediCallHandlePrimal(short tapeId, locint index, double* primalVec) { +void mediCallHandlePrimal(short tapeId, locint index, double *primalVec) { AdolcMeDiAdjointInterface interface(nullptr, primalVec, 1); adolcMediStatic->callHandlePrimal(tapeId, index, interface); } void mediInitTape(short tapeId) { - if(NULL == adolcMediStatic) { + if (NULL == adolcMediStatic) { mediInitStatic(); } adolcMediStatic->initTape(tapeId); } -void mediInitStatic() { - adolcMediStatic = new AdolcMediStatic(); -} +void mediInitStatic() { adolcMediStatic = new AdolcMediStatic(); } -void mediFinalizeStatic() { - delete adolcMediStatic; -} +void mediFinalizeStatic() { delete adolcMediStatic; } MPI_Datatype AdolcTool::MpiType; MPI_Datatype AdolcTool::ModifiedMpiType; MPI_Datatype AdolcTool::PrimalMpiType; MPI_Datatype AdolcTool::AdjointMpiType; -AdolcTool::MediType* AdolcTool::MPI_TYPE; +AdolcTool::MediType *AdolcTool::MPI_TYPE; medi::AMPI_Datatype AdolcTool::MPI_INT_TYPE; -medi::OperatorHelper> AdolcTool::operatorHelper; +medi::OperatorHelper< + medi::FunctionHelper> + AdolcTool::operatorHelper; #endif diff --git a/ADOL-C/src/medipacksupport_p.h b/ADOL-C/src/medipacksupport_p.h index 7bdcd78c9..b5379bad5 100644 --- a/ADOL-C/src/medipacksupport_p.h +++ b/ADOL-C/src/medipacksupport_p.h @@ -12,25 +12,27 @@ ----------------------------------------------------------------------------*/ #if !defined(ADOLC_MEDISUPPORTADOLCP_H) -#define ADOLC_MEDISUPPORTADOLCP_H 1 + #define ADOLC_MEDISUPPORTADOLCP_H 1 -#ifdef ADOLC_MEDIPACK_SUPPORT + #ifdef ADOLC_MEDIPACK_SUPPORT -#if defined(__cplusplus) -#include -#endif + #if defined(__cplusplus) + #include + #endif -#if defined(__cplusplus) + #if defined(__cplusplus) extern "C" { -#endif - void mediCallHandleReverse(short tapeId, locint index, double* primalVec, double** adjointVec, int vecSize); - void mediCallHandleForward(short tapeId, locint index, double* primalVec, double** adjointVec, int vecSize); - void mediCallHandlePrimal(short tapeId, locint index, double* primalVec); -#if defined(__cplusplus) + #endif +void mediCallHandleReverse(short tapeId, locint index, double *primalVec, + double **adjointVec, int vecSize); +void mediCallHandleForward(short tapeId, locint index, double *primalVec, + double **adjointVec, int vecSize); +void mediCallHandlePrimal(short tapeId, locint index, double *primalVec); + #if defined(__cplusplus) } -#endif + #endif void mediInitTape(short tapeId); -#endif + #endif #endif diff --git a/ADOL-C/src/nonl_ind_forward_s.c b/ADOL-C/src/nonl_ind_forward_s.c index 0e4846fd8..e0f860249 100644 --- a/ADOL-C/src/nonl_ind_forward_s.c +++ b/ADOL-C/src/nonl_ind_forward_s.c @@ -3,19 +3,18 @@ File: nonl_ind_forward_s.c Revision: $Id$ Contents: nonl_ind_forward_s (propagation of nonlinear index domains) - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INDO_ 1 #define _NONLIND_ 1 #define _NTIGHT_ 1 -#include +#include #undef _INDO_ #undef _NONLIND_ #undef _NTIGHT_ - diff --git a/ADOL-C/src/nonl_ind_forward_t.c b/ADOL-C/src/nonl_ind_forward_t.c index 789cf538c..ff127739e 100644 --- a/ADOL-C/src/nonl_ind_forward_t.c +++ b/ADOL-C/src/nonl_ind_forward_t.c @@ -3,19 +3,18 @@ File: nonl_ind_forward_t.c Revision: $Id$ Contents: nonl_ind_forward_t (propagation of nonlinear index domains) - + Copyright (c) Andrea Walther - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INDO_ 1 #define _NONLIND_ 1 #define _TIGHT_ 1 -#include +#include #undef _INDO_ #undef _NONLIND_ #undef _TIGHT_ - diff --git a/ADOL-C/src/nonl_ind_old_forward_s.c b/ADOL-C/src/nonl_ind_old_forward_s.c index ed49968be..a5f0c65ff 100644 --- a/ADOL-C/src/nonl_ind_old_forward_s.c +++ b/ADOL-C/src/nonl_ind_old_forward_s.c @@ -3,21 +3,20 @@ File: nonl_ind_forward_s.c Revision: $Id$ Contents: nonl_ind_forward_s (propagation of nonlinear index domains) - + Copyright (c) Andrea Walther, Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INDO_ 1 #define _NONLIND_OLD_ 1 #define _INDOPRO_ 1 #define _NTIGHT_ 1 -#include +#include #undef _INDO_ #undef _NONLIND_OLD_ #undef _INDOPRO_ #undef _NTIGHT_ - diff --git a/ADOL-C/src/nonl_ind_old_forward_t.c b/ADOL-C/src/nonl_ind_old_forward_t.c index 2deeaaf01..972e90669 100644 --- a/ADOL-C/src/nonl_ind_old_forward_t.c +++ b/ADOL-C/src/nonl_ind_old_forward_t.c @@ -3,21 +3,20 @@ File: nonl_ind_forward_t.c Revision: $Id$ Contents: nonl_ind_forward_t (propagation of nonlinear index domains) - + Copyright (c) Andrea Walther, Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #define _INDO_ 1 #define _NONLIND_OLD_ 1 #define _INDOPRO_ 1 #define _TIGHT_ 1 -#include +#include #undef _INDO_ #undef _NONLIND_OLD_ #undef _INDOPRO_ #undef _TIGHT_ - diff --git a/ADOL-C/src/oplate.h b/ADOL-C/src/oplate.h index 6d5186297..bea237b92 100644 --- a/ADOL-C/src/oplate.h +++ b/ADOL-C/src/oplate.h @@ -3,19 +3,19 @@ File: oplate.h Revision: $Id$ Contents: Numeric values for the various opcodes used by ADOL-C. - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel, Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_OPLATE_P_H) -#define ADOLC_OPLATE_P_H 1 + #define ADOLC_OPLATE_P_H 1 /****************************************************************************/ /* opcodes */ diff --git a/ADOL-C/src/param.cpp b/ADOL-C/src/param.cpp index 517e5b469..13c74aa76 100644 --- a/ADOL-C/src/param.cpp +++ b/ADOL-C/src/param.cpp @@ -3,698 +3,713 @@ File: param.cpp Revision: $Id$ Contents: class for parameter dependent functions - + Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ - +#include "dvlparms.h" #include "oplate.h" #include "taping_p.h" -#include "dvlparms.h" #include #include pdouble::pdouble(double pval) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - _val = pval; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc(); - ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = _val; - } else { - _idx = std::numeric_limits::max(); - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + _val = pval; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc(); + ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = _val; + } else { + _idx = std::numeric_limits::max(); + } } pdouble::pdouble(locint idx) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (idx < ADOLC_GLOBAL_TAPE_VARS.numparam) { - _val = ADOLC_GLOBAL_TAPE_VARS.pStore[idx]; - _idx = idx; - } else { - fprintf(DIAG_OUT, "ADOL-C error: Parameter index %d out of bounds, " - "# existing parameters = %zu\n", idx, - ADOLC_GLOBAL_TAPE_VARS.numparam); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (idx < ADOLC_GLOBAL_TAPE_VARS.numparam) { + _val = ADOLC_GLOBAL_TAPE_VARS.pStore[idx]; + _idx = idx; + } else { + fprintf(DIAG_OUT, + "ADOL-C error: Parameter index %d out of bounds, " + "# existing parameters = %zu\n", + idx, ADOLC_GLOBAL_TAPE_VARS.numparam); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } } -pdouble::operator pdouble*() const { - pdouble* ret = new pdouble(_idx); - return ret; +pdouble::operator pdouble *() const { + pdouble *ret = new pdouble(_idx); + return ret; } pdouble mkparam(double pval) { - locint _idx; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc(); - ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = pval; - } else { - return pval; - } - return _idx; + locint _idx; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc(); + ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = pval; + } else { + return pval; + } + return _idx; } -pdouble getparam(locint index) { - return index; -} +pdouble getparam(locint index) { return index; } locint mkparam_idx(double pval) { - locint _idx; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc(); - ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = pval; - } else { - fprintf(DIAG_OUT, "ADOL-C error: cannot define indexed parameter " - "while tracing is turned off!\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - return _idx; + locint _idx; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc(); + ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = pval; + } else { + fprintf(DIAG_OUT, "ADOL-C error: cannot define indexed parameter " + "while tracing is turned off!\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + return _idx; } pdouble::operator adub() const { - locint location; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - location = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(assign_p); - ADOLC_PUT_LOCINT(_idx); - ADOLC_PUT_LOCINT(location); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); - } - ADOLC_GLOBAL_TAPE_VARS.store[location] = _val; + locint location; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + location = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(assign_p); + ADOLC_PUT_LOCINT(_idx); + ADOLC_PUT_LOCINT(location); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + } + ADOLC_GLOBAL_TAPE_VARS.store[location] = _val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true; #endif - return location; + return location; } -badouble& badouble::operator = (const pdouble& p) { - locint loc; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - loc = this->loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(assign_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(loc); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc]); - } - ADOLC_GLOBAL_TAPE_VARS.store[loc] = p._val; +badouble &badouble::operator=(const pdouble &p) { + locint loc; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + loc = this->loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(assign_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(loc); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc]); + } + ADOLC_GLOBAL_TAPE_VARS.store[loc] = p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[loc] = true; #endif - return *this; + return *this; } -adouble& adouble::operator = (const pdouble& p) { - this->loc(); - (*this).badouble::operator=(p); - return (*this); +adouble &adouble::operator=(const pdouble &p) { + this->loc(); + (*this).badouble::operator=(p); + return (*this); } -adubref& adubref::operator = (const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(ref_assign_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(location); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] = p._val; +adubref &adubref::operator=(const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(ref_assign_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(location); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } + ADOLC_GLOBAL_TAPE_VARS.store[refloc] = p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true; #endif - return *this; + return *this; } -badouble& badouble::operator += (const pdouble& p) { - locint loc; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - loc = this->loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(eq_plus_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(loc); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc]); - } +badouble &badouble::operator+=(const pdouble &p) { + locint loc; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + loc = this->loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(eq_plus_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(loc); - ADOLC_GLOBAL_TAPE_VARS.store[loc] += p._val; + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[loc] += p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[loc] = true; #endif - return *this; + return *this; } -adubref& adubref::operator += (const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; +adubref &adubref::operator+=(const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(ref_eq_plus_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(location); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(ref_eq_plus_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(location); - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } - ADOLC_GLOBAL_TAPE_VARS.store[refloc] += p._val; + ADOLC_GLOBAL_TAPE_VARS.store[refloc] += p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true; #endif - return *this; + return *this; } -badouble& badouble::operator -= (const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_min_d,loc(),coval); - put_op(eq_min_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(loc()); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } - - ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= p._val; +badouble &badouble::operator-=(const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_min_d,loc(),coval); + put_op(eq_min_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(loc()); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true; #endif - return *this; + return *this; } -adubref& adubref::operator -= (const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_min_d,location,coval); - put_op(ref_eq_min_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(location); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } - - ADOLC_GLOBAL_TAPE_VARS.store[refloc] -= p._val; +adubref &adubref::operator-=(const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_min_d,location,coval); + put_op(ref_eq_min_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(location); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[refloc] -= p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true; #endif - return *this; + return *this; } -badouble& badouble::operator *= (const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_mult_d,loc(),coval); - put_op(eq_mult_p); - ADOLC_PUT_LOCINT(p._idx); // = coval - ADOLC_PUT_LOCINT(loc()); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); - } - - ADOLC_GLOBAL_TAPE_VARS.store[loc()] *= p._val; +badouble &badouble::operator*=(const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_mult_d,loc(),coval); + put_op(eq_mult_p); + ADOLC_PUT_LOCINT(p._idx); // = coval + ADOLC_PUT_LOCINT(loc()); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[loc()] *= p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true; #endif - return *this; + return *this; } -adubref& adubref::operator *= (const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_mult_d,location,coval); - put_op(ref_eq_mult_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(location); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); - } - - ADOLC_GLOBAL_TAPE_VARS.store[refloc] *= p._val; +adubref &adubref::operator*=(const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_d_same_arg(eq_mult_d,location,coval); + put_op(ref_eq_mult_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(location); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[refloc] *= p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true; #endif - return *this; + return *this; } -adub operator + (const badouble& a, const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); +adub operator+(const badouble &a, const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); - /* olvo 980708 test coval to be zero */ - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); + /* olvo 980708 test coval to be zero */ + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()] ) { - locint tmploc = a.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } -#endif - put_op(plus_a_p); - ADOLC_PUT_LOCINT(a.loc()); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(locat); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()]) { + locint tmploc = a.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); } - - ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] + p._val; +#endif + put_op(plus_a_p); + ADOLC_PUT_LOCINT(a.loc()); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(locat); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[locat] = + ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] + p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; #endif - return locat; + return locat; } -adub operator - (const badouble& a, const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); +adub operator-(const badouble &a, const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); - /* olvo 980708 test coval to be zero */ - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); + /* olvo 980708 test coval to be zero */ + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()] ) { - locint tmploc = a.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } -#endif - put_op(min_a_p); - ADOLC_PUT_LOCINT(a.loc()); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(locat); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()]) { + locint tmploc = a.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); } - - ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] - p._val; +#endif + put_op(min_a_p); + ADOLC_PUT_LOCINT(a.loc()); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(locat); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[locat] = + ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] - p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; #endif - return locat; + return locat; } -adub operator * (const badouble& a, const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); +adub operator*(const badouble &a, const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); - /* olvo 980708 test coval to be zero */ - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); + /* olvo 980708 test coval to be zero */ + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()] ) { - locint tmploc = a.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } -#endif - put_op(mult_a_p); - ADOLC_PUT_LOCINT(a.loc()); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(locat); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()]) { + locint tmploc = a.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); } - - ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] * p._val; +#endif + put_op(mult_a_p); + ADOLC_PUT_LOCINT(a.loc()); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(locat); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[locat] = + ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] * p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; #endif - return locat; + return locat; } -adub operator / (const pdouble& p, const badouble& a) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); +adub operator/(const pdouble &p, const badouble &a) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); - /* olvo 980708 test coval to be zero */ - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); + /* olvo 980708 test coval to be zero */ + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()] ) { - locint tmploc = a.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } -#endif - put_op(div_p_a); - ADOLC_PUT_LOCINT(a.loc()); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(locat); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()]) { + locint tmploc = a.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); } - - ADOLC_GLOBAL_TAPE_VARS.store[locat] = p._val/ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; +#endif + put_op(div_p_a); + ADOLC_PUT_LOCINT(a.loc()); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(locat); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[locat] = + p._val / ADOLC_GLOBAL_TAPE_VARS.store[a.loc()]; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; #endif - return locat; + return locat; } -adub pow( const badouble& x, const pdouble& p) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - locint locat = next_loc(); +adub pow(const badouble &x, const pdouble &p) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(pow_op,locat,cocval,x.loc()); + if (ADOLC_CURRENT_TAPE_INFOS + .traceFlag) { // old: write_args_d_a(pow_op,locat,cocval,x.loc()); #if defined(ADOLC_TRACK_ACTIVITY) - if (! ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] ) { - locint tmploc = x.loc(); - double temp = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - if (temp == 0.0) { - put_op(assign_d_zero); - ADOLC_PUT_LOCINT(tmploc); - } else if (temp == 1.0) { - put_op(assign_d_one); - ADOLC_PUT_LOCINT(tmploc); - } else { - put_op(assign_d); - ADOLC_PUT_LOCINT(tmploc); - ADOLC_PUT_VAL(temp); - } - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); - } -#endif - put_op(pow_op_p); - ADOLC_PUT_LOCINT(x.loc()); // = arg - ADOLC_PUT_LOCINT(p._idx); // = coval - ADOLC_PUT_LOCINT(locat); // = res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + if (!ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()]) { + locint tmploc = x.loc(); + double temp = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + if (temp == 0.0) { + put_op(assign_d_zero); + ADOLC_PUT_LOCINT(tmploc); + } else if (temp == 1.0) { + put_op(assign_d_one); + ADOLC_PUT_LOCINT(tmploc); + } else { + put_op(assign_d); + ADOLC_PUT_LOCINT(tmploc); + ADOLC_PUT_VAL(temp); + } + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]); } - - ADOLC_GLOBAL_TAPE_VARS.store[locat] = - ADOLC_MATH_NSP::pow(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()],p._val); +#endif + put_op(pow_op_p); + ADOLC_PUT_LOCINT(x.loc()); // = arg + ADOLC_PUT_LOCINT(p._idx); // = coval + ADOLC_PUT_LOCINT(locat); // = res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + + ADOLC_GLOBAL_TAPE_VARS.store[locat] = + ADOLC_MATH_NSP::pow(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()], p._val); #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true; #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - return locat; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + return locat; } -adub recipr( const pdouble& p) { - locint location; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - location = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(recipr_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(location); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); - } - ADOLC_GLOBAL_TAPE_VARS.store[location] = 1.0/p._val; +adub recipr(const pdouble &p) { + locint location; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + location = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(recipr_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(location); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + } + ADOLC_GLOBAL_TAPE_VARS.store[location] = 1.0 / p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true; #endif - return location; + return location; } -adub operator - (const pdouble& p) { - locint location; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - location = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(neg_sign_p); - ADOLC_PUT_LOCINT(p._idx); - ADOLC_PUT_LOCINT(location); - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); - } - ADOLC_GLOBAL_TAPE_VARS.store[location] = -p._val; +adub operator-(const pdouble &p) { + locint location; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + location = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(neg_sign_p); + ADOLC_PUT_LOCINT(p._idx); + ADOLC_PUT_LOCINT(location); + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]); + } + ADOLC_GLOBAL_TAPE_VARS.store[location] = -p._val; #if defined(ADOLC_TRACK_ACTIVITY) - ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true; + ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true; #endif - return location; + return location; } -adouble pow( const pdouble& p, const badouble& y) { - adouble a1, a2, ret; - double vx = p._val; - double vy = y.getValue(); - if (!(vx > 0)) { - if (vx < 0 || vy >= 0) - fprintf(DIAG_OUT,"\nADOL-C message: exponent of zero/negative basis deactivated\n"); - else - fprintf(DIAG_OUT,"\nADOL-C message: negative exponent and zero basis deactivated\n"); - } - condassign(a1, -y, (adouble) ADOLC_MATH_NSP::pow(vx,vy), pow(p,vy)); - condassign(a2, fabs(adub(p)), pow(p, vy), a1); - condassign(ret, p, exp(y*log(adub(p))),a2); - - return ret; +adouble pow(const pdouble &p, const badouble &y) { + adouble a1, a2, ret; + double vx = p._val; + double vy = y.getValue(); + if (!(vx > 0)) { + if (vx < 0 || vy >= 0) + fprintf( + DIAG_OUT, + "\nADOL-C message: exponent of zero/negative basis deactivated\n"); + else + fprintf( + DIAG_OUT, + "\nADOL-C message: negative exponent and zero basis deactivated\n"); + } + condassign(a1, -y, (adouble)ADOLC_MATH_NSP::pow(vx, vy), pow(p, vy)); + condassign(a2, fabs(adub(p)), pow(p, vy), a1); + condassign(ret, p, exp(y * log(adub(p))), a2); + + return ret; } #if defined(ADOLC_ADVANCED_BRANCHING) -adub operator != (const badouble& x, const pdouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = y._val; - double res = (double)(xval != yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(neq_a_p); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y._idx); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; +adub operator!=(const badouble &x, const pdouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = y._val; + double res = (double)(xval != yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(neq_a_p); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y._idx); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; } /*--------------------------------------------------------------------------*/ -adub operator == (const badouble& x, const pdouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = y._val; - double res = (double)(xval == yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(eq_a_p); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y._idx); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; +adub operator==(const badouble &x, const pdouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = y._val; + double res = (double)(xval == yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(eq_a_p); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y._idx); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; } /*--------------------------------------------------------------------------*/ -adub operator <= (const badouble& x, const pdouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = y._val; - double res = (double)(xval <= yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(le_a_p); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y._idx); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; +adub operator<=(const badouble &x, const pdouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = y._val; + double res = (double)(xval <= yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(le_a_p); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y._idx); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; } /*--------------------------------------------------------------------------*/ -adub operator >= (const badouble& x, const pdouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = y._val; - double res = (double)(xval >= yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(ge_a_p); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y._idx); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; +adub operator>=(const badouble &x, const pdouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = y._val; + double res = (double)(xval >= yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(ge_a_p); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y._idx); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; } /*--------------------------------------------------------------------------*/ -adub operator > (const badouble& x, const pdouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = y._val; - double res = (double)(xval > yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(gt_a_p); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y._idx); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; +adub operator>(const badouble &x, const pdouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = y._val; + double res = (double)(xval > yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(gt_a_p); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y._idx); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; } /*--------------------------------------------------------------------------*/ -adub operator < (const badouble& x, const pdouble& y) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; - double yval = y._val; - double res = (double)(xval < yval); - locint locat = next_loc(); - if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { - put_op(lt_a_p); - ADOLC_PUT_LOCINT(x.loc()); // arg - ADOLC_PUT_LOCINT(y._idx); // arg1 - ADOLC_PUT_VAL(res); // check for branch switch - ADOLC_PUT_LOCINT(locat); // res - - ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); - } - ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; - return locat; +adub operator<(const badouble &x, const pdouble &y) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()]; + double yval = y._val; + double res = (double)(xval < yval); + locint locat = next_loc(); + if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { + put_op(lt_a_p); + ADOLC_PUT_LOCINT(x.loc()); // arg + ADOLC_PUT_LOCINT(y._idx); // arg1 + ADOLC_PUT_VAL(res); // check for branch switch + ADOLC_PUT_LOCINT(locat); // res + + ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]); + } + ADOLC_GLOBAL_TAPE_VARS.store[locat] = res; + return locat; } #endif diff --git a/ADOL-C/src/revolve.c b/ADOL-C/src/revolve.c index 759184307..7f41d2e88 100644 --- a/ADOL-C/src/revolve.c +++ b/ADOL-C/src/revolve.c @@ -5,186 +5,186 @@ Contents: optimal binomial checkpointing adapted for ADOL-C Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /* ----- -* The function REVOLVE coded below is meant to be used as a * -* "controller" for running a time-dependent applications program * -* in the reverse mode with checkpointing described in the paper * -* "Achieving logarithmic Growth in temporal and spatial complexity * -* in reverse automatic differentiation", Optimization Methods and * -* Software, Vol.1 pp. 35-54. * -* A postscript source of that paper can be found in the ftp sites * -* info.mcs.anl.gov and nbtf02.math.tu-dresden.de. * -* Apart from REVOLVE this file contains five auxiliary routines * -* NUMFORW, EXPENSE, MAXRANGE, and ADJUST. * -* * -*--------------------------------------------------------------------* -* * -* To utilize REVOLVE the user must have procedures for * -* - Advancing the state of the modeled system to a certain time. * -* - Saving the current state onto a stack of snapshots. * -* - Restoring the the most recently saved snapshot and * -* restarting the forward simulation from there. * -* - Initializing the adjoints at the end of forward sweep. * -* - Performing one combined forward and adjoint step. * -* Through an encoding of its return value REVOLVE asks the * -* calling program to perform one of these 'actions', which we will * -* refer to as * -* * -* 'advance', 'takeshot', 'restore', 'firsturn' and 'youturn' .* -* There are two other return values, namely * -* 'terminate' and 'error' * -* which indicate a regular or faulty termination of the calls * -* to REVOLVE. * -* * -* The action 'firsturn' includes a 'youturn', in that it requires * -* -advancing through the last time-step with recording * -* of intermediates * -* -initializing the adjoint values (possibly after * -* performing some IO) * -* -reversing the last time step using the record just written * -* The action 'firsturn' is obtained when the difference FINE-CAPO * -* has been reduced to 1 for the first time. * -* * -*--------------------------------------------------------------------* -* * -* The calling sequence is * -* * -* REVOLVE(CHECK,CAPO,FINE,SNAPS,INFO) * -* * -* with the return value being one of the actions to be taken. The * -* calling parameters are all integers with the following meaning * -* * -* CHECK number of checkpoint being written or retrieved * -* CAPO beginning of subrange currently being processed * -* FINE end of subrange currently being processed * -* SNAPS upper bound on number of checkpoints taken * -* INFO determines how much information will be printed * -* and contains information about an error occurred * -* * -* Since REVOLVE involves only a few integer operations its * -* run-time is truly negligible within any nontrivial application. * -* * -* The parameter SNAPS is selected by the user (possibly with the * -* help of the routines EXPENSE and ADJUST described below ) and * -* remains unchanged throughout. * -* * -* The pair (CAPO,FINE) always represents the initial and final * -* state of the subsequence of time steps currently being traversed * -* backwards. * -* * -* The conditions * -* CHECK >= -1 and CAPO <= FINE * -* are necessary and sufficient for a regular response of REVOLVE. * -* If either condition is violated the value 'error' is returned. * -* * -* The first call to REVOLVE must be with CHECK=-1 so that * -* appropriate initializations can be performed internally. * -* * -* When CHECK =-1 and CAPO = FINE then 'terminate' is returned as * -* action value. This combination necessarily arises after a * -* sufficiently large number of calls to REVOLVE, which depends * -* only on the initial difference FINE-CAPO. * -* * -* The last parameter INFO determines how much information about * -* the actions performed will be printed. When INFO =0 no * -* information is sent to standard output. When INFO > 0 REVOLVE * -* produces an output that contains a prediction of the number of * -* forward steps and of the factor by which the execution will slow * -* down. When an error occurs, the return value of INFO contains * -* information about the reason: * -* * -* INFO = 10: number of checkpoints stored exceeds CHECKUP, * -* increase constant CHECKUP and recompile * -* INFO = 11: number of checkpoints stored exceeds SNAPS, ensure * -* SNAPS greater than 0 and increase initial FINE * -* INFO = 12: error occurs in NUMFORW * -* INFO = 13: enhancement of FINE, SNAPS checkpoints stored, * -* SNAPS must be increased * -* INFO = 14: number of SNAPS exceeds CHECKUP, increase constant * -* CHECKUP and recompile * -* INFO = 15: number of REPS exceeds REPSUP, increase constant * -* REPSUP and recompile * -* * -*--------------------------------------------------------------------* -* * -* Some further explanations and motivations: * -* * -* There is an implicit bound on CHECK through the dimensioning of * -* the integer array CH[CHEKUP] with CHECKUP = 64 being the default.* -* If anybody wants to have that even larger he must change the * -* source. Also for the variable REPS an upper bound REPSUP is * -* defined. The default value equals 64. If during a call to * -* TREEVERSE a (CHECKUP+1)-st checkpoint would normally be called * -* for then control is returned after an appropriate error message. * -* When the calculated REPS exceeds REPSUP also an error message * -* occurs. * -* During the forward sweep the user is free to change the last * -* three parameters from call to call, except that FINE may never * -* be less than the current value of CAPO. This may be useful when * -* the total number of time STEPS to be taken is not a priori * -* known. The choice FINE=CAPO+1 initiates the reverse sweep, which * -* happens automatically if is left constant as CAPO is eventually * -* moved up to it. Once the first reverse or restore action has * -* been taken only the last two parameters should be changed. * -* * -*--------------------------------------------------------------------* -* * -* The necessary number of forward steps without recording is * -* calculated by the function * -* * -* NUMFORW(STEPS,SNAPS) * -* * -* STEPS denotes the total number of time steps, i.e. FINE-CAPO * -* during the first call of REVOLVE. When SNAPS is less than 1 an * -* error message will be given and -1 is returned as value. * -* * -*--------------------------------------------------------------------* -* * -* To choose an appropriated value of SNAPS the function * -* * -* EXPENSE(STEPS,SNAPS) * -* * -* estimates the run-time factor incurred by REVOLVE for a * -* particular value of SNAPS. The ratio NUMFORW(STEPS,SNAPS)/STEPS * -* is returned. This ratio corresponds to the run-time factor of * -* the execution relative to the run-time of one forward time step. * -* * -*--------------------------------------------------------------------* -* * -* The auxiliary function * -* * -* MAXRANGE(SNAPS,REPS) * -* * -* returns the integer (SNAPS+REPS)!/(SNAPS!REPS!) provided * -* SNAPS >=0, REPS >= 0. Otherwise there will be appropriate error * -* messages and the value -1 will be returned. If the binomial * -* expression is not representable as a signed 4 byte integer, * -* greater than 2^31-1, this maximal value is returned and a * -* warning message printed. * -* * -*--------------------------------------------------------------------* -* * -* Furthermore, the function * -* * -* ADJUST(STEPS) * -* * -* is provided. It can be used to determine a value of SNAPS so * -* that the increase in spatial complexity equals approximately the * -* increase in temporal complexity. For that ADJUST computes a * -* return value satisfying SNAPS ~= log_4 (STEPS) because of the * -* theory developed in the paper mentioned above. * -* * -*--------------------------------------------------------------------*/ + * The function REVOLVE coded below is meant to be used as a * + * "controller" for running a time-dependent applications program * + * in the reverse mode with checkpointing described in the paper * + * "Achieving logarithmic Growth in temporal and spatial complexity * + * in reverse automatic differentiation", Optimization Methods and * + * Software, Vol.1 pp. 35-54. * + * A postscript source of that paper can be found in the ftp sites * + * info.mcs.anl.gov and nbtf02.math.tu-dresden.de. * + * Apart from REVOLVE this file contains five auxiliary routines * + * NUMFORW, EXPENSE, MAXRANGE, and ADJUST. * + * * + *--------------------------------------------------------------------* + * * + * To utilize REVOLVE the user must have procedures for * + * - Advancing the state of the modeled system to a certain time. * + * - Saving the current state onto a stack of snapshots. * + * - Restoring the the most recently saved snapshot and * + * restarting the forward simulation from there. * + * - Initializing the adjoints at the end of forward sweep. * + * - Performing one combined forward and adjoint step. * + * Through an encoding of its return value REVOLVE asks the * + * calling program to perform one of these 'actions', which we will * + * refer to as * + * * + * 'advance', 'takeshot', 'restore', 'firsturn' and 'youturn' .* + * There are two other return values, namely * + * 'terminate' and 'error' * + * which indicate a regular or faulty termination of the calls * + * to REVOLVE. * + * * + * The action 'firsturn' includes a 'youturn', in that it requires * + * -advancing through the last time-step with recording * + * of intermediates * + * -initializing the adjoint values (possibly after * + * performing some IO) * + * -reversing the last time step using the record just written * + * The action 'firsturn' is obtained when the difference FINE-CAPO * + * has been reduced to 1 for the first time. * + * * + *--------------------------------------------------------------------* + * * + * The calling sequence is * + * * + * REVOLVE(CHECK,CAPO,FINE,SNAPS,INFO) * + * * + * with the return value being one of the actions to be taken. The * + * calling parameters are all integers with the following meaning * + * * + * CHECK number of checkpoint being written or retrieved * + * CAPO beginning of subrange currently being processed * + * FINE end of subrange currently being processed * + * SNAPS upper bound on number of checkpoints taken * + * INFO determines how much information will be printed * + * and contains information about an error occurred * + * * + * Since REVOLVE involves only a few integer operations its * + * run-time is truly negligible within any nontrivial application. * + * * + * The parameter SNAPS is selected by the user (possibly with the * + * help of the routines EXPENSE and ADJUST described below ) and * + * remains unchanged throughout. * + * * + * The pair (CAPO,FINE) always represents the initial and final * + * state of the subsequence of time steps currently being traversed * + * backwards. * + * * + * The conditions * + * CHECK >= -1 and CAPO <= FINE * + * are necessary and sufficient for a regular response of REVOLVE. * + * If either condition is violated the value 'error' is returned. * + * * + * The first call to REVOLVE must be with CHECK=-1 so that * + * appropriate initializations can be performed internally. * + * * + * When CHECK =-1 and CAPO = FINE then 'terminate' is returned as * + * action value. This combination necessarily arises after a * + * sufficiently large number of calls to REVOLVE, which depends * + * only on the initial difference FINE-CAPO. * + * * + * The last parameter INFO determines how much information about * + * the actions performed will be printed. When INFO =0 no * + * information is sent to standard output. When INFO > 0 REVOLVE * + * produces an output that contains a prediction of the number of * + * forward steps and of the factor by which the execution will slow * + * down. When an error occurs, the return value of INFO contains * + * information about the reason: * + * * + * INFO = 10: number of checkpoints stored exceeds CHECKUP, * + * increase constant CHECKUP and recompile * + * INFO = 11: number of checkpoints stored exceeds SNAPS, ensure * + * SNAPS greater than 0 and increase initial FINE * + * INFO = 12: error occurs in NUMFORW * + * INFO = 13: enhancement of FINE, SNAPS checkpoints stored, * + * SNAPS must be increased * + * INFO = 14: number of SNAPS exceeds CHECKUP, increase constant * + * CHECKUP and recompile * + * INFO = 15: number of REPS exceeds REPSUP, increase constant * + * REPSUP and recompile * + * * + *--------------------------------------------------------------------* + * * + * Some further explanations and motivations: * + * * + * There is an implicit bound on CHECK through the dimensioning of * + * the integer array CH[CHEKUP] with CHECKUP = 64 being the default.* + * If anybody wants to have that even larger he must change the * + * source. Also for the variable REPS an upper bound REPSUP is * + * defined. The default value equals 64. If during a call to * + * TREEVERSE a (CHECKUP+1)-st checkpoint would normally be called * + * for then control is returned after an appropriate error message. * + * When the calculated REPS exceeds REPSUP also an error message * + * occurs. * + * During the forward sweep the user is free to change the last * + * three parameters from call to call, except that FINE may never * + * be less than the current value of CAPO. This may be useful when * + * the total number of time STEPS to be taken is not a priori * + * known. The choice FINE=CAPO+1 initiates the reverse sweep, which * + * happens automatically if is left constant as CAPO is eventually * + * moved up to it. Once the first reverse or restore action has * + * been taken only the last two parameters should be changed. * + * * + *--------------------------------------------------------------------* + * * + * The necessary number of forward steps without recording is * + * calculated by the function * + * * + * NUMFORW(STEPS,SNAPS) * + * * + * STEPS denotes the total number of time steps, i.e. FINE-CAPO * + * during the first call of REVOLVE. When SNAPS is less than 1 an * + * error message will be given and -1 is returned as value. * + * * + *--------------------------------------------------------------------* + * * + * To choose an appropriated value of SNAPS the function * + * * + * EXPENSE(STEPS,SNAPS) * + * * + * estimates the run-time factor incurred by REVOLVE for a * + * particular value of SNAPS. The ratio NUMFORW(STEPS,SNAPS)/STEPS * + * is returned. This ratio corresponds to the run-time factor of * + * the execution relative to the run-time of one forward time step. * + * * + *--------------------------------------------------------------------* + * * + * The auxiliary function * + * * + * MAXRANGE(SNAPS,REPS) * + * * + * returns the integer (SNAPS+REPS)!/(SNAPS!REPS!) provided * + * SNAPS >=0, REPS >= 0. Otherwise there will be appropriate error * + * messages and the value -1 will be returned. If the binomial * + * expression is not representable as a signed 4 byte integer, * + * greater than 2^31-1, this maximal value is returned and a * + * warning message printed. * + * * + *--------------------------------------------------------------------* + * * + * Furthermore, the function * + * * + * ADJUST(STEPS) * + * * + * is provided. It can be used to determine a value of SNAPS so * + * that the increase in spatial complexity equals approximately the * + * increase in temporal complexity. For that ADJUST computes a * + * return value satisfying SNAPS ~= log_4 (STEPS) because of the * + * theory developed in the paper mentioned above. * + * * + *--------------------------------------------------------------------*/ -#include #include "taping_p.h" +#include #define MAXINT 2147483647 @@ -197,301 +197,296 @@ revolve_nums *revolve_numbers = NULL; /* ************************************************************************* */ int numforw(int steps, int snaps) { - int reps, range, num; + int reps, range, num; - if (snaps < 1) { - printf(" error occurs in numforw: snaps < 1\n"); - return -1; - } - if (snaps > ADOLC_CHECKUP) { - printf(" number of snaps=%d exceeds ADOLC_CHECKUP \n",snaps); - printf(" redefine 'ADOLC_CHECKUP' \n"); - return -1; - } - reps = 0; - range = 1; - while(range < steps) { - reps += 1; - range = range*(reps + snaps)/reps; - } - printf("range = %d \n",range); - if (reps > ADOLC_REPSUP) { - printf(" number of reps=%d exceeds ADOLC_REPSUP \n",reps); - printf(" redefine 'ADOLC_REPSUP' \n"); - return -1; - } - num = reps * steps - range*reps/(snaps+1); - return num; + if (snaps < 1) { + printf(" error occurs in numforw: snaps < 1\n"); + return -1; + } + if (snaps > ADOLC_CHECKUP) { + printf(" number of snaps=%d exceeds ADOLC_CHECKUP \n", snaps); + printf(" redefine 'ADOLC_CHECKUP' \n"); + return -1; + } + reps = 0; + range = 1; + while (range < steps) { + reps += 1; + range = range * (reps + snaps) / reps; + } + printf("range = %d \n", range); + if (reps > ADOLC_REPSUP) { + printf(" number of reps=%d exceeds ADOLC_REPSUP \n", reps); + printf(" redefine 'ADOLC_REPSUP' \n"); + return -1; + } + num = reps * steps - range * reps / (snaps + 1); + return num; } /* ************************************************************************* */ double expense(int steps, int snaps) { - double ratio; + double ratio; - if (snaps < 1) { - printf(" error occurs in expense: snaps < 0\n"); - return -1; - } - if (steps < 1) { - printf(" error occurs in expense: steps < 0\n"); - return -1; - } - ratio = ((double) numforw(steps,snaps)); - if (ratio == -1) - return -1; - ratio = ratio/steps; - return ratio; + if (snaps < 1) { + printf(" error occurs in expense: snaps < 0\n"); + return -1; + } + if (steps < 1) { + printf(" error occurs in expense: steps < 0\n"); + return -1; + } + ratio = ((double)numforw(steps, snaps)); + if (ratio == -1) + return -1; + ratio = ratio / steps; + return ratio; } /* ************************************************************************* */ int maxrange(int ss, int tt) { - int i, ires; - double res = 1.0; + int i, ires; + double res = 1.0; - if((tt<0) || (ss<0)) { - printf("error in MAXRANGE: negative parameter"); - return -1; + if ((tt < 0) || (ss < 0)) { + printf("error in MAXRANGE: negative parameter"); + return -1; + } + for (i = 1; i <= tt; i++) { + res *= (ss + i); + res /= i; + if (res > MAXINT) { + ires = MAXINT; + printf("warning from MAXRANGE: returned maximal integer %d\n", ires); + return ires; } - for(i=1; i<= tt; i++) { - res *= (ss + i); - res /= i; - if (res > MAXINT) { - ires=MAXINT; - printf("warning from MAXRANGE: returned maximal integer %d\n", - ires); - return ires; - } - } - ires = res; - return ires; + } + ires = res; + return ires; } /* ************************************************************************* */ int adjust(int steps) { - int snaps, s, reps; - - snaps = 1; - reps = 1; - s = 0; - while( maxrange(snaps+s, reps+s) > steps ) - s--; - while( maxrange(snaps+s, reps+s) < steps ) - s++; - snaps += s; - reps += s ; - s = -1; - while( maxrange(snaps,reps) >= steps ) { - if (snaps > reps) { - snaps -= 1; - s = 0; - } else { - reps -= 1; - s = 1; - } + int snaps, s, reps; + + snaps = 1; + reps = 1; + s = 0; + while (maxrange(snaps + s, reps + s) > steps) + s--; + while (maxrange(snaps + s, reps + s) < steps) + s++; + snaps += s; + reps += s; + s = -1; + while (maxrange(snaps, reps) >= steps) { + if (snaps > reps) { + snaps -= 1; + s = 0; + } else { + reps -= 1; + s = 1; } - if ( s == 0 ) - snaps += 1 ; - if ( s == 1 ) - reps += 1; - return snaps; + } + if (s == 0) + snaps += 1; + if (s == 1) + reps += 1; + return snaps; } /* ************************************************************************* */ -enum revolve_action revolve -(int* check,int* capo,int* fine,int snaps,int* info) { - int ds, oldcapo, num, bino1, bino2, bino3, bino4, bino5, bino6; - /* (*capo,*fine) is the time range currently under consideration */ - /* ch[j] is the number of the state that is stored in checkpoint j */ - ADOLC_OPENMP_THREAD_NUMBER; - - ADOLC_OPENMP_GET_THREAD_NUMBER; - REVOLVE_NUMBERS.commands += 1; - if ((*check < -1) || (*capo > *fine)) { - *info = 9; - return revolve_error; +enum revolve_action revolve(int *check, int *capo, int *fine, int snaps, + int *info) { + int ds, oldcapo, num, bino1, bino2, bino3, bino4, bino5, bino6; + /* (*capo,*fine) is the time range currently under consideration */ + /* ch[j] is the number of the state that is stored in checkpoint j */ + ADOLC_OPENMP_THREAD_NUMBER; + + ADOLC_OPENMP_GET_THREAD_NUMBER; + REVOLVE_NUMBERS.commands += 1; + if ((*check < -1) || (*capo > *fine)) { + *info = 9; + return revolve_error; + } + if ((*check == -1) && (*capo < *fine)) { + if (*check == -1) + REVOLVE_NUMBERS.turn = 0; /* initialization of turn counter */ + *REVOLVE_NUMBERS.ch = *capo - 1; + } + switch (*fine - *capo) { + case 0: /* reduce capo to previous checkpoint, unless done */ + if (*check == -1 || *capo == *REVOLVE_NUMBERS.ch) { + *check -= 1; + if (*info > 0) { + printf(" \n advances: %5d", REVOLVE_NUMBERS.advances); + printf(" \n takeshots: %4d", REVOLVE_NUMBERS.takeshots); + printf(" \n commands: %5d \n", REVOLVE_NUMBERS.commands); + } + return revolve_terminate; + } else { + *capo = REVOLVE_NUMBERS.ch[*check]; + REVOLVE_NUMBERS.oldfine = *fine; + return revolve_restore; } - if ((*check == -1) && (*capo < *fine)) { - if (*check == -1) - REVOLVE_NUMBERS.turn = 0; /* initialization of turn counter */ - *REVOLVE_NUMBERS.ch = *capo-1; + case 1: /* (possibly first) combined forward/reverse step */ + *fine -= 1; + if (*check >= 0 && REVOLVE_NUMBERS.ch[*check] == *capo) + *check -= 1; + if (REVOLVE_NUMBERS.turn == 0) { + REVOLVE_NUMBERS.turn = 1; + REVOLVE_NUMBERS.oldfine = *fine; + return revolve_firsturn; + } else { + REVOLVE_NUMBERS.oldfine = *fine; + return revolve_youturn; } - switch(*fine-*capo) { - case 0: /* reduce capo to previous checkpoint, unless done */ - if(*check == -1 || *capo==*REVOLVE_NUMBERS.ch ) { - *check -= 1; - if (*info > 0) { - printf(" \n advances: %5d",REVOLVE_NUMBERS.advances); - printf(" \n takeshots: %4d",REVOLVE_NUMBERS.takeshots); - printf(" \n commands: %5d \n",REVOLVE_NUMBERS.commands); - } - return revolve_terminate; - } else { - *capo = REVOLVE_NUMBERS.ch[*check]; - REVOLVE_NUMBERS.oldfine = *fine; - return revolve_restore; - } - case 1: /* (possibly first) combined forward/reverse step */ - *fine -= 1; - if(*check >= 0 && REVOLVE_NUMBERS.ch[*check] == *capo) - *check -= 1; - if(REVOLVE_NUMBERS.turn == 0) { - REVOLVE_NUMBERS.turn = 1; - REVOLVE_NUMBERS.oldfine = *fine; - return revolve_firsturn; - } else { - REVOLVE_NUMBERS.oldfine = *fine; - return revolve_youturn; - } - default: - if(*check == -1 || REVOLVE_NUMBERS.ch[*check] != *capo) { - *check += 1 ; - if(*check >= ADOLC_CHECKUP) { - *info = 10; - return revolve_error; - } - if(*check+1 > snaps) { - *info = 11; - return revolve_error; - } - REVOLVE_NUMBERS.ch[*check] = *capo; - if (*check == 0) { - REVOLVE_NUMBERS.advances = 0; - REVOLVE_NUMBERS.takeshots = 0; - REVOLVE_NUMBERS.commands = 1; - REVOLVE_NUMBERS.oldsnaps = snaps; - if (snaps > ADOLC_CHECKUP) { - *info = 14; - return revolve_error; - } - if (*info > 0) { - num = numforw(*fine-*capo,snaps); - if (num == -1) { - *info = 12; - return revolve_error; - } - printf(" prediction of needed forward steps: %8d => " - "\n",num); - printf(" slowdown factor: %8.4f \n\n", - ((double) num)/(*fine-*capo)); - } - } - REVOLVE_NUMBERS.takeshots += 1; - REVOLVE_NUMBERS.oldfine = *fine; - return revolve_takeshot; - } else { - if ((REVOLVE_NUMBERS.oldfine < *fine) && - (snaps == *check+1)) - { - *info = 13; - return revolve_error; - } - oldcapo = *capo; - ds = snaps - *check; - if (ds < 1) { - *info = 11; - return revolve_error; - } - REVOLVE_NUMBERS.reps = 0; - REVOLVE_NUMBERS.range = 1; - while(REVOLVE_NUMBERS.range < *fine - *capo) { - REVOLVE_NUMBERS.reps += 1; - REVOLVE_NUMBERS.range = REVOLVE_NUMBERS.range * - (REVOLVE_NUMBERS.reps + ds) / REVOLVE_NUMBERS.reps; - } - if (REVOLVE_NUMBERS.reps > ADOLC_REPSUP) { - *info = 15; - return revolve_error; - } - if (snaps != REVOLVE_NUMBERS.oldsnaps) { - if (snaps > ADOLC_CHECKUP) { - *info = 14; - return revolve_error; - } - } - - bino1 = REVOLVE_NUMBERS.range * REVOLVE_NUMBERS.reps / - (ds+REVOLVE_NUMBERS.reps); - bino2 = (ds > 1) ? bino1*ds/(ds+REVOLVE_NUMBERS.reps-1) : 1; - if (ds == 1) - bino3 = 0; - else - bino3 = (ds > 2) ? bino2 * (ds - 1) / - (ds + REVOLVE_NUMBERS.reps - 2) : 1; - bino4 = bino2*(REVOLVE_NUMBERS.reps-1)/ds; - if (ds < 3) - bino5 = 0; - else - bino5 = (ds > 3) ? bino3*(ds-2)/REVOLVE_NUMBERS.reps : 1; - - bino6 = 0; - - /* range = beta(c,r) >= l (r -> min) - * bino1 = beta(c,r-1) - * bino2 = beta(c-1,r-1) - * bino3 = beta(c-2,r-1) - * bino4 = beta(c,r-2) - * bino5 = beta(c-3,r) */ - - /* new version by A. Kowarz - * l^ as large as possible - * bino6 = beta(c-1,r-2) - - if (ds < 1) - bino6 = 0; - else - bino6 = (ds > 1) ? bino2*(reps-1)/(ds+reps-2) : 1; - - if (*fine-*capo>=range-bino5) - *capo += bino1; - else - if (*fine-*capo>bino1+bino2) - *capo = *fine-bino2-bino3; - else - if (*fine-*capo>=bino1+bino6) - *capo += bino1-bino3; - else - *capo = *fine-bino1+bino4; */ - - /* new version by A. Kowarz - * l^ as small as possible - * bino6 = beta(c-1,r) */ - - bino6 = bino1*ds/REVOLVE_NUMBERS.reps; - - if (*fine-*capo<=bino1+bino3) - *capo += bino4; - else - if (*fine-*capo= ADOLC_CHECKUP) { + *info = 10; + return revolve_error; + } + if (*check + 1 > snaps) { + *info = 11; + return revolve_error; + } + REVOLVE_NUMBERS.ch[*check] = *capo; + if (*check == 0) { + REVOLVE_NUMBERS.advances = 0; + REVOLVE_NUMBERS.takeshots = 0; + REVOLVE_NUMBERS.commands = 1; + REVOLVE_NUMBERS.oldsnaps = snaps; + if (snaps > ADOLC_CHECKUP) { + *info = 14; + return revolve_error; + } + if (*info > 0) { + num = numforw(*fine - *capo, snaps); + if (num == -1) { + *info = 12; + return revolve_error; + } + printf(" prediction of needed forward steps: %8d => " + "\n", + num); + printf(" slowdown factor: %8.4f \n\n", + ((double)num) / (*fine - *capo)); + } + } + REVOLVE_NUMBERS.takeshots += 1; + REVOLVE_NUMBERS.oldfine = *fine; + return revolve_takeshot; + } else { + if ((REVOLVE_NUMBERS.oldfine < *fine) && (snaps == *check + 1)) { + *info = 13; + return revolve_error; + } + oldcapo = *capo; + ds = snaps - *check; + if (ds < 1) { + *info = 11; + return revolve_error; + } + REVOLVE_NUMBERS.reps = 0; + REVOLVE_NUMBERS.range = 1; + while (REVOLVE_NUMBERS.range < *fine - *capo) { + REVOLVE_NUMBERS.reps += 1; + REVOLVE_NUMBERS.range = REVOLVE_NUMBERS.range * + (REVOLVE_NUMBERS.reps + ds) / + REVOLVE_NUMBERS.reps; + } + if (REVOLVE_NUMBERS.reps > ADOLC_REPSUP) { + *info = 15; + return revolve_error; + } + if (snaps != REVOLVE_NUMBERS.oldsnaps) { + if (snaps > ADOLC_CHECKUP) { + *info = 14; + return revolve_error; + } + } + + bino1 = REVOLVE_NUMBERS.range * REVOLVE_NUMBERS.reps / + (ds + REVOLVE_NUMBERS.reps); + bino2 = (ds > 1) ? bino1 * ds / (ds + REVOLVE_NUMBERS.reps - 1) : 1; + if (ds == 1) + bino3 = 0; + else + bino3 = + (ds > 2) ? bino2 * (ds - 1) / (ds + REVOLVE_NUMBERS.reps - 2) : 1; + bino4 = bino2 * (REVOLVE_NUMBERS.reps - 1) / ds; + if (ds < 3) + bino5 = 0; + else + bino5 = (ds > 3) ? bino3 * (ds - 2) / REVOLVE_NUMBERS.reps : 1; + + bino6 = 0; + + /* range = beta(c,r) >= l (r -> min) + * bino1 = beta(c,r-1) + * bino2 = beta(c-1,r-1) + * bino3 = beta(c-2,r-1) + * bino4 = beta(c,r-2) + * bino5 = beta(c-3,r) */ + + /* new version by A. Kowarz + * l^ as large as possible + * bino6 = beta(c-1,r-2) + + if (ds < 1) + bino6 = 0; + else + bino6 = (ds > 1) ? bino2*(reps-1)/(ds+reps-2) : 1; + + if (*fine-*capo>=range-bino5) + *capo += bino1; + else + if (*fine-*capo>bino1+bino2) + *capo = *fine-bino2-bino3; + else + if (*fine-*capo>=bino1+bino6) + *capo += bino1-bino3; else - if (*fine-*capo<=bino1+bino2+bino5) - *capo += bino1-bino3; - else - *capo = *fine-bino6; - - /* original by A. Walther - - if (*fine-*capo <= bino1 + bino3) - *capo = *capo+bino4; - else - { - if (*fine-*capo >= range - bino5) - *capo = *capo + bino1; - else - *capo = *fine-bino2-bino3; - } */ - - if (*capo == oldcapo) - *capo = oldcapo+1; - REVOLVE_NUMBERS.advances = REVOLVE_NUMBERS.advances + - *capo - oldcapo; - REVOLVE_NUMBERS.oldfine = *fine; - return revolve_advance; - } + *capo = *fine-bino1+bino4; */ + + /* new version by A. Kowarz + * l^ as small as possible + * bino6 = beta(c-1,r) */ + + bino6 = bino1 * ds / REVOLVE_NUMBERS.reps; + + if (*fine - *capo <= bino1 + bino3) + *capo += bino4; + else if (*fine - *capo < bino1 + bino2) + *capo = *fine - bino2 - bino3; + else if (*fine - *capo <= bino1 + bino2 + bino5) + *capo += bino1 - bino3; + else + *capo = *fine - bino6; + + /* original by A. Walther + + if (*fine-*capo <= bino1 + bino3) + *capo = *capo+bino4; + else + { + if (*fine-*capo >= range - bino5) + *capo = *capo + bino1; + else + *capo = *fine-bino2-bino3; + } */ + + if (*capo == oldcapo) + *capo = oldcapo + 1; + REVOLVE_NUMBERS.advances = REVOLVE_NUMBERS.advances + *capo - oldcapo; + REVOLVE_NUMBERS.oldfine = *fine; + return revolve_advance; } + } } - diff --git a/ADOL-C/src/rpl_malloc.c b/ADOL-C/src/rpl_malloc.c index 42a4ecf1a..72614ac6f 100644 --- a/ADOL-C/src/rpl_malloc.c +++ b/ADOL-C/src/rpl_malloc.c @@ -3,14 +3,14 @@ File: malloc.c Revision: $Id$ Contents: malloc replacements for not gnu compatible malloc system functions - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #include "rpl_malloc.h" @@ -18,52 +18,57 @@ #undef ADOLC_NO_MALLOC #undef ADOLC_NO_REALLOC #if defined(ADOLC_INTERNAL) -# if !defined(HAVE_MALLOC) -# define ADOLC_NO_MALLOC 1 -# else -# if (HAVE_MALLOC == 0) -# define ADOLC_NO_MALLOC 1 -# endif /* HAVE_MALLOC == 0 */ -# endif /* HAVE_MALLOC */ -# if !defined(HAVE_REALLOC) -# define ADOLC_NO_REALLOC 1 -# else -# if (HAVE_REALLOC == 0) -# define ADOLC_NO_REALLOC 1 -# endif /* HAVE_REALLOC == 0 */ -# endif /* HAVE_REALLOC */ -#endif /* ADOLC_INTERNAL */ + #if !defined(HAVE_MALLOC) + #define ADOLC_NO_MALLOC 1 + #else + #if (HAVE_MALLOC == 0) + #define ADOLC_NO_MALLOC 1 + #endif /* HAVE_MALLOC == 0 */ + #endif /* HAVE_MALLOC */ + #if !defined(HAVE_REALLOC) + #define ADOLC_NO_REALLOC 1 + #else + #if (HAVE_REALLOC == 0) + #define ADOLC_NO_REALLOC 1 + #endif /* HAVE_REALLOC == 0 */ + #endif /* HAVE_REALLOC */ +#endif /* ADOLC_INTERNAL */ #if defined(ADOLC_NO_MALLOC) -# undef malloc -# undef calloc - extern void *malloc(); - extern void *calloc(); + #undef malloc + #undef calloc +extern void *malloc(); +extern void *calloc(); - /** Allocate an n-byte block from the heap! n>=1 - * If native malloc(0) returns an invalid pointer use the - * replacement-function instead. - */ - void *rpl_malloc(size_t n) { - if (n == 0) n = 1; - return malloc(n); - } +/** Allocate an n-byte block from the heap! n>=1 + * If native malloc(0) returns an invalid pointer use the + * replacement-function instead. + */ +void *rpl_malloc(size_t n) { + if (n == 0) + n = 1; + return malloc(n); +} - void *rpl_calloc(size_t n, size_t size) { - if (n == 0) n = 1; - if (size == 0) size = 1; - return calloc(n, size); - } +void *rpl_calloc(size_t n, size_t size) { + if (n == 0) + n = 1; + if (size == 0) + size = 1; + return calloc(n, size); +} #endif /* ADOLC_NO_MALLOC */ #if defined(ADOLC_NO_REALLOC) -# undef realloc - extern void *realloc(); + #undef realloc +extern void *realloc(); - void *rpl_realloc(void *ptr, size_t size) { - if (size == 0) size = 1; - if (ptr == NULL) ptr = rpl_malloc(1); - return realloc(ptr, size); - } +void *rpl_realloc(void *ptr, size_t size) { + if (size == 0) + size = 1; + if (ptr == NULL) + ptr = rpl_malloc(1); + return realloc(ptr, size); +} #endif /* ADOLC_NO_REALLOC */ diff --git a/ADOL-C/src/rpl_malloc.h b/ADOL-C/src/rpl_malloc.h index ab9eac373..0b560d105 100644 --- a/ADOL-C/src/rpl_malloc.h +++ b/ADOL-C/src/rpl_malloc.h @@ -4,65 +4,65 @@ Revision: $Id$ Contents: malloc replacements for not gnu compatible malloc system functions - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #if !defined(ADOLC_MALLOC_H) -# define ADOLC_MALLOC_H 1 + #define ADOLC_MALLOC_H 1 -# if defined(ADOLC_INTERNAL) -# if defined(HAVE_CONFIG_H) -# include "config.h" + #if defined(ADOLC_INTERNAL) + #if defined(HAVE_CONFIG_H) + #include "config.h" -# undef ADOLC_NO_MALLOC -# undef ADOLC_NO_REALLOC -# if !defined(HAVE_MALLOC) -# define ADOLC_NO_MALLOC 1 -# else -# if (HAVE_MALLOC == 0) -# define ADOLC_NO_MALLOC 1 -# endif /* HAVE_MALLOC == 0 */ -# endif /* HAVE_MALLOC */ -# if !defined(HAVE_REALLOC) -# define ADOLC_NO_REALLOC 1 -# else -# if (HAVE_REALLOC == 0) -# define ADOLC_NO_REALLOC 1 -# endif /* HAVE_REALLOC == 0 */ -# endif /* HAVE_REALLOC */ + #undef ADOLC_NO_MALLOC + #undef ADOLC_NO_REALLOC + #if !defined(HAVE_MALLOC) + #define ADOLC_NO_MALLOC 1 + #else + #if (HAVE_MALLOC == 0) + #define ADOLC_NO_MALLOC 1 + #endif /* HAVE_MALLOC == 0 */ + #endif /* HAVE_MALLOC */ + #if !defined(HAVE_REALLOC) + #define ADOLC_NO_REALLOC 1 + #else + #if (HAVE_REALLOC == 0) + #define ADOLC_NO_REALLOC 1 + #endif /* HAVE_REALLOC == 0 */ + #endif /* HAVE_REALLOC */ -# if defined(ADOLC_NO_MALLOC) -# include -# if defined(__cplusplus) - extern "C" { -# endif /* __cplusplus */ -# undef rpl_malloc -# undef rpl_calloc - extern void *rpl_malloc(size_t); - extern void *rpl_calloc(size_t, size_t); -# if defined(__cplusplus) - } -# endif /* __cplusplus */ -# endif /* ADOLC_NO_MALLOC */ + #if defined(ADOLC_NO_MALLOC) + #include + #if defined(__cplusplus) +extern "C" { + #endif /* __cplusplus */ + #undef rpl_malloc + #undef rpl_calloc +extern void *rpl_malloc(size_t); +extern void *rpl_calloc(size_t, size_t); + #if defined(__cplusplus) +} + #endif /* __cplusplus */ + #endif /* ADOLC_NO_MALLOC */ -# if defined(ADOLC_NO_REALLOC) -# include -# if defined(__cplusplus) - extern "C" { -# endif /* __cplusplus */ -# undef rpl_realloc - extern void *rpl_realloc(void *, size_t); -# if defined(__cplusplus) - } -# endif /* __cplusplus */ -# endif /* ADOLC_NO_REALLOC */ + #if defined(ADOLC_NO_REALLOC) + #include + #if defined(__cplusplus) +extern "C" { + #endif /* __cplusplus */ + #undef rpl_realloc +extern void *rpl_realloc(void *, size_t); + #if defined(__cplusplus) +} + #endif /* __cplusplus */ + #endif /* ADOLC_NO_REALLOC */ -# endif /* HAVE_CONFIG_H */ -# endif /* ADOLC_INTERNAL */ -#endif /* ADOLC_MALLOC_H */ + #endif /* HAVE_CONFIG_H */ + #endif /* ADOLC_INTERNAL */ +#endif /* ADOLC_MALLOC_H */ diff --git a/ADOL-C/src/sparse/sparse_fo_rev.cpp b/ADOL-C/src/sparse/sparse_fo_rev.cpp index 1b6d7cab5..411006338 100644 --- a/ADOL-C/src/sparse/sparse_fo_rev.cpp +++ b/ADOL-C/src/sparse/sparse_fo_rev.cpp @@ -3,111 +3,91 @@ File: sparse/sparse_fo_rev.cpp Revision: $Id$ Contents: All "Easy To Use" C++ interfaces of SPARSE package - + Copyright (c) Andrea Walther, Christo Mitev - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#include -#include #include "dvlparms.h" +#include +#include #include #if defined(__cplusplus) -extern "C" void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line); +extern "C" void adolc_exit(int errorcode, const char *what, + const char *function, const char *file, int line); /****************************************************************************/ /* Bit pattern propagation; general call */ /* */ -int forward( short tag, - int m, - int n, - int p, - double *x, - unsigned long int **X, - double *y, - unsigned long int **Y, - char mode) +int forward(short tag, int m, int n, int p, double *x, unsigned long int **X, + double *y, unsigned long int **Y, char mode) /* forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p], mode) */ { - int rc = -1; - if (mode == 1) // tight version - if (x != NULL) - rc = int_forward_tight(tag,m,n,p,x,X,y,Y); - else { - fprintf(DIAG_OUT,"ADOL-C error: no basepoint for bit" - " pattern forward tight.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - else - if (mode == 0) // safe version - rc = int_forward_safe(tag,m,n,p,X,Y); - else { - fprintf(DIAG_OUT,"ADOL-C error: bad mode parameter to bit" - " pattern forward.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - return (rc); + int rc = -1; + if (mode == 1) // tight version + if (x != NULL) + rc = int_forward_tight(tag, m, n, p, x, X, y, Y); + else { + fprintf(DIAG_OUT, "ADOL-C error: no basepoint for bit" + " pattern forward tight.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + else if (mode == 0) // safe version + rc = int_forward_safe(tag, m, n, p, X, Y); + else { + fprintf(DIAG_OUT, "ADOL-C error: bad mode parameter to bit" + " pattern forward.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + return (rc); } - /****************************************************************************/ /* Bit pattern propagation; no basepoint */ /* */ -int forward( short tag, - int m, - int n, - int p, - unsigned long int **X, - unsigned long int **Y, - char mode) +int forward(short tag, int m, int n, int p, unsigned long int **X, + unsigned long int **Y, char mode) /* forward(tag, m, n, p, X[n][p], Y[m][p], mode) */ { - if (mode != 0) // not safe - { fprintf(DIAG_OUT,"ADOL-C error: bad mode parameter to bit" - " pattern forward.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - return int_forward_safe(tag,m,n,p,X,Y); + if (mode != 0) // not safe + { + fprintf(DIAG_OUT, "ADOL-C error: bad mode parameter to bit" + " pattern forward.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + return int_forward_safe(tag, m, n, p, X, Y); } - - /****************************************************************************/ /* */ /* Bit pattern propagation, general call */ /* */ -int reverse( short tag, - int m, - int n, - int q, - unsigned long int **U, - unsigned long int **Z, - char mode) +int reverse(short tag, int m, int n, int q, unsigned long int **U, + unsigned long int **Z, char mode) /* reverse(tag, m, n, q, U[q][m], Z[q][n]) */ -{ int rc=-1; +{ + int rc = -1; - /* ! use better the tight version, the safe version supports no subscripts*/ + /* ! use better the tight version, the safe version supports no subscripts*/ - if (mode == 0) // safe version - rc = int_reverse_safe(tag,m,n,q,U,Z); - else - if (mode == 1) - rc = int_reverse_tight(tag,m,n,q,U,Z); - else { - fprintf(DIAG_OUT,"ADOL-C error: bad mode parameter" - " to bit pattern reverse.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - return rc; + if (mode == 0) // safe version + rc = int_reverse_safe(tag, m, n, q, U, Z); + else if (mode == 1) + rc = int_reverse_tight(tag, m, n, q, U, Z); + else { + fprintf(DIAG_OUT, "ADOL-C error: bad mode parameter" + " to bit pattern reverse.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + return rc; } - /****************************************************************************/ #endif diff --git a/ADOL-C/src/sparse/sparsedrivers.cpp b/ADOL-C/src/sparse/sparsedrivers.cpp index 203921ee0..1b9e50ef6 100644 --- a/ADOL-C/src/sparse/sparsedrivers.cpp +++ b/ADOL-C/src/sparse/sparsedrivers.cpp @@ -3,35 +3,35 @@ File: sparse/sparsedrivers.cpp Revision: $Id$ Contents: "Easy To Use" C++ interfaces of SPARSE package - + Copyright (c) Andrea Walther, Benjamin Letschert, Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ -#include "taping_p.h" -#include "oplate.h" #include "dvlparms.h" +#include "oplate.h" +#include "taping_p.h" -#include #include #include +#include #if defined(ADOLC_INTERNAL) -# if HAVE_CONFIG_H -# include "config.h" -# endif + #if HAVE_CONFIG_H + #include "config.h" + #endif #endif #if HAVE_LIBCOLPACK -#include + #include #endif -#include #include +#include #if HAVE_LIBCOLPACK using namespace ColPack; @@ -39,7 +39,6 @@ using namespace ColPack; using namespace std; - /****************************************************************************/ /******* sparse Jacobains, separate drivers ***************/ /****************************************************************************/ @@ -50,13 +49,13 @@ using namespace std; /* */ int jac_pat( - short tag, /* tape identification */ - int depen, /* number of dependent variables */ - int indep, /* number of independent variables */ - const double *basepoint, /* independent variable values */ + short tag, /* tape identification */ + int depen, /* number of dependent variables */ + int indep, /* number of independent variables */ + const double *basepoint, /* independent variable values */ unsigned int **crs, /* returned compressed row block-index storage */ - int *options + int *options /* control options options[0] : way of sparsity pattern computation 0 - propagation of index domains (default) @@ -66,94 +65,93 @@ int jac_pat( 1 - tight mode options[2] : way of bit pattern propagation 0 - automatic detection (default) - 1 - forward mode + 1 - forward mode 2 - reverse mode */ ) { - int rc= -1; - int i, ctrl_options[2]; - - if (crs == NULL) { - fprintf(DIAG_OUT,"ADOL-C user error in jac_pat(...) : " - "parameter crs may not be NULL !\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else - for (i=0; i 1 )) - options[0] = 0; /* default */ - if (( options[1] < 0 ) || (options[1] > 1 )) - options[1] = 0; /* default */ - if (( options[2] < -1 ) || (options[2] > 2 )) - options[2] = 0; /* default */ - - if (options[0] == 0) { - if (options[1] == 1) - rc = indopro_forward_tight(tag, depen, indep, basepoint, crs); - else - { - rc = indopro_forward_safe(tag, depen, indep, basepoint, crs); - } + int rc = -1; + int i, ctrl_options[2]; + + if (crs == NULL) { + fprintf(DIAG_OUT, "ADOL-C user error in jac_pat(...) : " + "parameter crs may not be NULL !\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } else + for (i = 0; i < depen; i++) + crs[i] = NULL; + + if ((options[0] < 0) || (options[0] > 1)) + options[0] = 0; /* default */ + if ((options[1] < 0) || (options[1] > 1)) + options[1] = 0; /* default */ + if ((options[2] < -1) || (options[2] > 2)) + options[2] = 0; /* default */ + + if (options[0] == 0) { + if (options[1] == 1) + rc = indopro_forward_tight(tag, depen, indep, basepoint, crs); + else { + rc = indopro_forward_safe(tag, depen, indep, basepoint, crs); } - else - { - ctrl_options[0] = options[1]; - ctrl_options[1] = options[2]; - rc = bit_vector_propagation( tag, depen, indep, basepoint, crs, ctrl_options); - } - - return(rc); + } else { + ctrl_options[0] = options[1]; + ctrl_options[1] = options[2]; + rc = + bit_vector_propagation(tag, depen, indep, basepoint, crs, ctrl_options); + } + + return (rc); } -int absnormal_jac_pat( - short tag, /* tape identification */ - int depen, /* number of dependent variables */ - int indep, /* number of independent variables */ - int numsw, /* number of switches */ - const double *basepoint, /* independent variable values */ - unsigned int **crs - /* returned compressed row block-index storage */ - ) { - - if (crs == NULL) { - fprintf(DIAG_OUT,"ADOL-C user error in jac_pat(...) : " - "parameter crs may not be NULL !\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else - for (int i=0; iGenerateSeedJacobian_unmanaged(Seed, p, &dummy, - "SMALLEST_LAST","ROW_PARTIAL_DISTANCE_TWO"); - else - g->GenerateSeedJacobian_unmanaged(Seed, &dummy, p, - "SMALLEST_LAST","COLUMN_PARTIAL_DISTANCE_TWO"); - delete g; + BipartiteGraphPartialColoringInterface *g = + new BipartiteGraphPartialColoringInterface(SRC_MEM_ADOLC, JP, m, n); + if (option == 1) + g->GenerateSeedJacobian_unmanaged(Seed, p, &dummy, "SMALLEST_LAST", + "ROW_PARTIAL_DISTANCE_TWO"); + else + g->GenerateSeedJacobian_unmanaged(Seed, &dummy, p, "SMALLEST_LAST", + "COLUMN_PARTIAL_DISTANCE_TWO"); + delete g; } #else { - fprintf(DIAG_OUT, "ADOL-C error: function %s can only be used if linked with ColPack\n", __FUNCTION__); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, + "ADOL-C error: function %s can only be used if linked with ColPack\n", + __FUNCTION__); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); } #endif @@ -165,278 +163,273 @@ void generate_seed_jac /* sparsity pattern Hessian */ /* */ -int hess_pat( - short tag, /* tape identification */ - int indep, /* number of independent variables */ - const double *basepoint, /* independent variable values */ - unsigned int **crs, - /* returned compressed row block-index storage */ - int option - /* control option - option : test the computational graph control flow - 0 - safe mode (default) - 1 - tight mode - 2 - old safe mode - 3 - old tight mode */ +int hess_pat(short tag, /* tape identification */ + int indep, /* number of independent variables */ + const double *basepoint, /* independent variable values */ + unsigned int **crs, + /* returned compressed row block-index storage */ + int option + /* control option + option : test the computational graph control flow + 0 - safe mode (default) + 1 - tight mode + 2 - old safe mode + 3 - old tight mode */ ) { - int rc= -1; - int i; - - if (crs == NULL) { - fprintf(DIAG_OUT,"ADOL-C user error in hess_pat(...) : " - "parameter crs may not be NULL !\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } else - for (i=0; i 3 )) - option = 0; /* default */ - - if (option == 3) - rc = nonl_ind_old_forward_tight(tag, 1, indep, basepoint, crs); - else if (option == 2) - rc = nonl_ind_old_forward_safe(tag, 1, indep, basepoint, crs); - else if (option == 1) - rc = nonl_ind_forward_tight(tag, 1, indep, basepoint, crs); - else - rc = nonl_ind_forward_safe(tag, 1, indep, basepoint, crs); + int rc = -1; + int i; + + if (crs == NULL) { + fprintf(DIAG_OUT, "ADOL-C user error in hess_pat(...) : " + "parameter crs may not be NULL !\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } else + for (i = 0; i < indep; i++) + crs[i] = NULL; + + if ((option < 0) || (option > 3)) + option = 0; /* default */ + + if (option == 3) + rc = nonl_ind_old_forward_tight(tag, 1, indep, basepoint, crs); + else if (option == 2) + rc = nonl_ind_old_forward_safe(tag, 1, indep, basepoint, crs); + else if (option == 1) + rc = nonl_ind_forward_tight(tag, 1, indep, basepoint, crs); + else + rc = nonl_ind_forward_safe(tag, 1, indep, basepoint, crs); - return(rc); + return (rc); } /*--------------------------------------------------------------------------*/ /* seed matrix for Hessian */ /*--------------------------------------------------------------------------*/ -void generate_seed_hess -(int n, unsigned int **HP, double*** Seed, int *p, int option - /* control options - option : way of compression - 0 - indirect recovery (default) - 1 - direct recovery */ +void generate_seed_hess(int n, unsigned int **HP, double ***Seed, int *p, + int option + /* control options + option : way of compression + 0 - indirect recovery + (default) 1 - direct recovery */ ) -#if HAVE_LIBCOLPACK +#if HAVE_LIBCOLPACK { int seed_rows; GraphColoringInterface *g = new GraphColoringInterface(SRC_MEM_ADOLC, HP, n); if (option == 0) - g->GenerateSeedHessian_unmanaged(Seed, &seed_rows, p, - "SMALLEST_LAST","ACYCLIC_FOR_INDIRECT_RECOVERY"); + g->GenerateSeedHessian_unmanaged(Seed, &seed_rows, p, "SMALLEST_LAST", + "ACYCLIC_FOR_INDIRECT_RECOVERY"); else - g->GenerateSeedHessian_unmanaged(Seed, &seed_rows, p, - "SMALLEST_LAST","STAR"); + g->GenerateSeedHessian_unmanaged(Seed, &seed_rows, p, "SMALLEST_LAST", + "STAR"); delete g; } #else { - fprintf(DIAG_OUT, "ADOL-C error: function %s can only be used if linked with ColPack\n", __FUNCTION__); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, + "ADOL-C error: function %s can only be used if linked with ColPack\n", + __FUNCTION__); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); } #endif -static void deepcopy_HP(unsigned int ***HPnew, unsigned int **HP, int indep) -{ - int i,j,s; - *HPnew = (unsigned int **)malloc(indep*sizeof(unsigned int *)); - for (i=0; i 1)) + options[0] = 0; /* default */ + if ((options[1] < 0) || (options[1] > 1)) + options[1] = 0; /* default */ + if ((options[2] < -1) || (options[2] > 2)) + options[2] = 0; /* default */ + if ((options[3] < 0) || (options[3] > 1)) + options[3] = 0; /* default */ + + sJinfos.JP = (unsigned int **)malloc(depen * sizeof(unsigned int *)); + ret_val = jac_pat(tag, depen, indep, basepoint, sJinfos.JP, options); - if (repeat == 0) { - if (( options[0] < 0 ) || (options[0] > 1 )) - options[0] = 0; /* default */ - if (( options[1] < 0 ) || (options[1] > 1 )) - options[1] = 0; /* default */ - if (( options[2] < -1 ) || (options[2] > 2 )) - options[2] = 0; /* default */ - if (( options[3] < 0 ) || (options[3] > 1 )) - options[3] = 0; /* default */ - - sJinfos.JP = (unsigned int **) malloc(depen*sizeof(unsigned int *)); - ret_val = jac_pat(tag, depen, indep, basepoint, sJinfos.JP, options); - + if (ret_val < 0) { + printf(" ADOL-C error in sparse_jac() \n"); + return ret_val; + } - if (ret_val < 0) { - printf(" ADOL-C error in sparse_jac() \n"); - return ret_val; - } - - sJinfos.depen = depen; - sJinfos.nnz_in = depen; - sJinfos.nnz_in = 0; - for (i=0;iGenerateSeedJacobian(&(sJinfos.Seed), &(sJinfos.seed_rows), - &(sJinfos.seed_clms), "SMALLEST_LAST","ROW_PARTIAL_DISTANCE_TWO"); - sJinfos.seed_clms = indep; - ret_val = sJinfos.seed_rows; - } - else - { - g->GenerateSeedJacobian(&(sJinfos.Seed), &(sJinfos.seed_rows), - &(sJinfos.seed_clms), "SMALLEST_LAST","COLUMN_PARTIAL_DISTANCE_TWO"); - sJinfos.seed_rows = depen; - ret_val = sJinfos.seed_clms; - } - - sJinfos.B = myalloc2(sJinfos.seed_rows,sJinfos.seed_clms); - sJinfos.y = myalloc1(depen); - - sJinfos.g = (void *) g; - sJinfos.jr1d = (void *) jr1d; - setTapeInfoJacSparse(tag, sJinfos); - tapeInfos=getTapeInfos(tag); - ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); + sJinfos.depen = depen; + sJinfos.nnz_in = depen; + sJinfos.nnz_in = 0; + for (i = 0; i < depen; i++) { + for (j = 1; j <= sJinfos.JP[i][0]; j++) + sJinfos.nnz_in++; } - else - { - tapeInfos=getTapeInfos(tag); - ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); - sJinfos.depen = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.depen; - sJinfos.nnz_in = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.nnz_in; - sJinfos.JP = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.JP; - sJinfos.B = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.B; - sJinfos.y = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.y; - sJinfos.Seed = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.Seed; - sJinfos.seed_rows = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.seed_rows; - sJinfos.seed_clms = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.seed_clms; - g = (BipartiteGraphPartialColoringInterface *)ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.g; - jr1d = (JacobianRecovery1D *)ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.jr1d; - } - - if (sJinfos.nnz_in != *nnz) { - printf(" ADOL-C error in sparse_jac():" - " Number of nonzeros not consistent," - " repeat call with repeat = 0 \n"); - return -3; + + *nnz = sJinfos.nnz_in; + + if (options[2] == -1) { + (*rind) = (unsigned int *)calloc(*nnz, sizeof(unsigned int)); + (*cind) = (unsigned int *)calloc(*nnz, sizeof(unsigned int)); + unsigned int index = 0; + for (i = 0; i < depen; i++) + for (j = 1; j <= sJinfos.JP[i][0]; j++) { + (*rind)[index] = i; + (*cind)[index++] = sJinfos.JP[i][j]; + } } - if (options[2] == -1) - return ret_val; + /* sJinfos.Seed is memory managed by ColPack and will be deleted + * along with g. We only keep it in sJinfos for the repeat != 0 case */ - /* compute jacobian times matrix product */ + g = new BipartiteGraphPartialColoringInterface(SRC_MEM_ADOLC, sJinfos.JP, + depen, indep); + jr1d = new JacobianRecovery1D; - if (options[3] == 1) - { - ret_val = zos_forward(tag,depen,indep,1,basepoint,sJinfos.y); - if (ret_val < 0) - return ret_val; - MINDEC(ret_val,fov_reverse(tag,depen,indep,sJinfos.seed_rows,sJinfos.Seed,sJinfos.B)); - } - else - ret_val = fov_forward(tag, depen, indep, sJinfos.seed_clms, basepoint, sJinfos.Seed, sJinfos.y, sJinfos.B); - - - /* recover compressed Jacobian => ColPack library */ - - if (*values != NULL && *rind != NULL && *cind != NULL) { - // everything is preallocated, we assume correctly - // call usermem versions - if (options[3] == 1) - jr1d->RecoverD2Row_CoordinateFormat_usermem(g, sJinfos.B, sJinfos.JP, rind, cind, values); - else - jr1d->RecoverD2Cln_CoordinateFormat_usermem(g, sJinfos.B, sJinfos.JP, rind, cind, values); + if (options[3] == 1) { + g->GenerateSeedJacobian(&(sJinfos.Seed), &(sJinfos.seed_rows), + &(sJinfos.seed_clms), "SMALLEST_LAST", + "ROW_PARTIAL_DISTANCE_TWO"); + sJinfos.seed_clms = indep; + ret_val = sJinfos.seed_rows; } else { - // at least one of rind cind values is not allocated, deallocate others - // and call unmanaged versions - if (*values != NULL) - free(*values); - if (*rind != NULL) - free(*rind); - if (*cind != NULL) - free(*cind); - if (options[3] == 1) - jr1d->RecoverD2Row_CoordinateFormat_unmanaged(g, sJinfos.B, sJinfos.JP, rind, cind, values); - else - jr1d->RecoverD2Cln_CoordinateFormat_unmanaged(g, sJinfos.B, sJinfos.JP, rind, cind, values); + g->GenerateSeedJacobian(&(sJinfos.Seed), &(sJinfos.seed_rows), + &(sJinfos.seed_clms), "SMALLEST_LAST", + "COLUMN_PARTIAL_DISTANCE_TWO"); + sJinfos.seed_rows = depen; + ret_val = sJinfos.seed_clms; } + sJinfos.B = myalloc2(sJinfos.seed_rows, sJinfos.seed_clms); + sJinfos.y = myalloc1(depen); + + sJinfos.g = (void *)g; + sJinfos.jr1d = (void *)jr1d; + setTapeInfoJacSparse(tag, sJinfos); + tapeInfos = getTapeInfos(tag); + ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); + } else { + tapeInfos = getTapeInfos(tag); + ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); + sJinfos.depen = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.depen; + sJinfos.nnz_in = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.nnz_in; + sJinfos.JP = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.JP; + sJinfos.B = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.B; + sJinfos.y = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.y; + sJinfos.Seed = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.Seed; + sJinfos.seed_rows = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.seed_rows; + sJinfos.seed_clms = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.seed_clms; + g = (BipartiteGraphPartialColoringInterface *) + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.g; + jr1d = + (JacobianRecovery1D *)ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sJinfos.jr1d; + } + + if (sJinfos.nnz_in != *nnz) { + printf(" ADOL-C error in sparse_jac():" + " Number of nonzeros not consistent," + " repeat call with repeat = 0 \n"); + return -3; + } + + if (options[2] == -1) return ret_val; + /* compute jacobian times matrix product */ + + if (options[3] == 1) { + ret_val = zos_forward(tag, depen, indep, 1, basepoint, sJinfos.y); + if (ret_val < 0) + return ret_val; + MINDEC(ret_val, fov_reverse(tag, depen, indep, sJinfos.seed_rows, + sJinfos.Seed, sJinfos.B)); + } else + ret_val = fov_forward(tag, depen, indep, sJinfos.seed_clms, basepoint, + sJinfos.Seed, sJinfos.y, sJinfos.B); + + /* recover compressed Jacobian => ColPack library */ + + if (*values != NULL && *rind != NULL && *cind != NULL) { + // everything is preallocated, we assume correctly + // call usermem versions + if (options[3] == 1) + jr1d->RecoverD2Row_CoordinateFormat_usermem(g, sJinfos.B, sJinfos.JP, + rind, cind, values); + else + jr1d->RecoverD2Cln_CoordinateFormat_usermem(g, sJinfos.B, sJinfos.JP, + rind, cind, values); + } else { + // at least one of rind cind values is not allocated, deallocate others + // and call unmanaged versions + if (*values != NULL) + free(*values); + if (*rind != NULL) + free(*rind); + if (*cind != NULL) + free(*cind); + if (options[3] == 1) + jr1d->RecoverD2Row_CoordinateFormat_unmanaged(g, sJinfos.B, sJinfos.JP, + rind, cind, values); + else + jr1d->RecoverD2Cln_CoordinateFormat_unmanaged(g, sJinfos.B, sJinfos.JP, + rind, cind, values); + } + + return ret_val; } #else { - fprintf(DIAG_OUT, "ADOL-C error: function %s can only be used if linked with ColPack\n", __FUNCTION__); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - return -1; + fprintf(DIAG_OUT, + "ADOL-C error: function %s can only be used if linked with ColPack\n", + __FUNCTION__); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + return -1; } #endif @@ -444,254 +437,259 @@ int sparse_jac( /******* sparse Hessians, complete driver ***************/ /****************************************************************************/ -int sparse_hess( - short tag, /* tape identification */ - int indep, /* number of independent variables */ - int repeat, /* indicated repeated call with same seed */ - const double *basepoint, /* independent variable values */ - int *nnz, /* number of nonzeros */ - unsigned int **rind, /* row index */ - unsigned int **cind, /* column index */ - double **values, /* non-zero values */ - int *options - /* control options - options[0] :test the computational graph control flow - 0 - safe mode (default) - 1 - tight mode - 2 - old safe mode - 3 - old tight mode - options[1] : way of recovery - 0 - indirect recovery - 1 - direct recovery */ +int sparse_hess(short tag, /* tape identification */ + int indep, /* number of independent variables */ + int repeat, /* indicated repeated call with same seed */ + const double *basepoint, /* independent variable values */ + int *nnz, /* number of nonzeros */ + unsigned int **rind, /* row index */ + unsigned int **cind, /* column index */ + double **values, /* non-zero values */ + int *options + /* control options + options[0] :test the computational graph control + flow 0 - safe mode (default) 1 - tight mode 2 - old safe mode + 3 - old tight mode + options[1] : way of recovery + 0 - indirect recovery + 1 - direct recovery */ ) #if HAVE_LIBCOLPACK { - int i, l; - unsigned int j; - SparseHessInfos sHinfos; - double **Seed; - int dummy; - double y; - int ret_val=-1; - GraphColoringInterface *g; - TapeInfos *tapeInfos; - HessianRecovery *hr; - - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* Generate sparsity pattern, determine nnz, allocate memory */ - if (repeat <= 0) { - if (( options[0] < 0 ) || (options[0] > 3 )) - options[0] = 0; /* default */ - if (( options[1] < 0 ) || (options[1] > 1 )) - options[1] = 0; /* default */ - - if (repeat == 0) - { - sHinfos.HP = (unsigned int **) malloc(indep*sizeof(unsigned int *)); - - /* generate sparsity pattern */ - ret_val = hess_pat(tag, indep, basepoint, sHinfos.HP, options[0]); - - if (ret_val < 0) { - printf(" ADOL-C error in sparse_hess() \n"); - return ret_val; - } - } - else - { - tapeInfos=getTapeInfos(tag); - ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); - if (indep != ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.indep) { - fprintf(DIAG_OUT,"ADOL-C Error: wrong number of independents stored in hessian pattern.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - deepcopy_HP(&sHinfos.HP,ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.HP,indep); - } - - sHinfos.indep = indep; - sHinfos.nnz_in = 0; + int i, l; + unsigned int j; + SparseHessInfos sHinfos; + double **Seed; + int dummy; + double y; + int ret_val = -1; + GraphColoringInterface *g; + TapeInfos *tapeInfos; + HessianRecovery *hr; + + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* Generate sparsity pattern, determine nnz, allocate memory */ + if (repeat <= 0) { + if ((options[0] < 0) || (options[0] > 3)) + options[0] = 0; /* default */ + if ((options[1] < 0) || (options[1] > 1)) + options[1] = 0; /* default */ - for (i=0;i= i) - sHinfos.nnz_in++; - } + if (repeat == 0) { + sHinfos.HP = (unsigned int **)malloc(indep * sizeof(unsigned int *)); - *nnz = sHinfos.nnz_in; + /* generate sparsity pattern */ + ret_val = hess_pat(tag, indep, basepoint, sHinfos.HP, options[0]); - /* compute seed matrix => ColPack library */ + if (ret_val < 0) { + printf(" ADOL-C error in sparse_hess() \n"); + return ret_val; + } + } else { + tapeInfos = getTapeInfos(tag); + ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); + if (indep != ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.indep) { + fprintf(DIAG_OUT, "ADOL-C Error: wrong number of independents stored " + "in hessian pattern.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + deepcopy_HP(&sHinfos.HP, ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.HP, + indep); + } - Seed = NULL; + sHinfos.indep = indep; + sHinfos.nnz_in = 0; - g = new GraphColoringInterface(SRC_MEM_ADOLC, sHinfos.HP, indep); - hr = new HessianRecovery; + for (i = 0; i < indep; i++) { + for (j = 1; j <= sHinfos.HP[i][0]; j++) + if ((int)sHinfos.HP[i][j] >= i) + sHinfos.nnz_in++; + } - if (options[1] == 0) - g->GenerateSeedHessian(&Seed, &dummy, &sHinfos.p, - "SMALLEST_LAST","ACYCLIC_FOR_INDIRECT_RECOVERY"); - else - g->GenerateSeedHessian(&Seed, &dummy, &sHinfos.p, - "SMALLEST_LAST","STAR"); + *nnz = sHinfos.nnz_in; - sHinfos.Hcomp = myalloc2(indep,sHinfos.p); - sHinfos.Xppp = myalloc3(indep,sHinfos.p,1); + /* compute seed matrix => ColPack library */ - for (i=0; iGenerateSeedHessian(&Seed, &dummy, &sHinfos.p, "SMALLEST_LAST", + "ACYCLIC_FOR_INDIRECT_RECOVERY"); + else + g->GenerateSeedHessian(&Seed, &dummy, &sHinfos.p, "SMALLEST_LAST", + "STAR"); - sHinfos.Zppp = myalloc3(sHinfos.p,indep,2); + sHinfos.Hcomp = myalloc2(indep, sHinfos.p); + sHinfos.Xppp = myalloc3(indep, sHinfos.p, 1); - sHinfos.Upp = myalloc2(1,2); - sHinfos.Upp[0][0] = 1; - sHinfos.Upp[0][1] = 0; + for (i = 0; i < indep; i++) + for (l = 0; l < sHinfos.p; l++) + sHinfos.Xppp[i][l][0] = Seed[i][l]; - sHinfos.g = (void *) g; - sHinfos.hr = (void *) hr; + /* Seed will be freed by ColPack when g is freed */ + Seed = NULL; - setTapeInfoHessSparse(tag, sHinfos); + sHinfos.Yppp = myalloc3(1, sHinfos.p, 1); - tapeInfos=getTapeInfos(tag); - ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); + sHinfos.Zppp = myalloc3(sHinfos.p, indep, 2); - } - else - { - tapeInfos=getTapeInfos(tag); - ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); - sHinfos.nnz_in = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.nnz_in; - sHinfos.HP = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.HP; - sHinfos.Hcomp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Hcomp; - sHinfos.Xppp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Xppp; - sHinfos.Yppp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Yppp; - sHinfos.Zppp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Zppp; - sHinfos.Upp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Upp; - sHinfos.p = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.p; - g = (GraphColoringInterface *)ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.g; - hr = (HessianRecovery *)ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.hr; - } + sHinfos.Upp = myalloc2(1, 2); + sHinfos.Upp[0][0] = 1; + sHinfos.Upp[0][1] = 0; - if (sHinfos.Upp == NULL) { - printf(" ADOL-C error in sparse_hess():" - " First call with repeat = 0 \n"); - return -3; - } + sHinfos.g = (void *)g; + sHinfos.hr = (void *)hr; - if (sHinfos.nnz_in != *nnz) { - printf(" ADOL-C error in sparse_hess():" - " Number of nonzeros not consistent," - " new call with repeat = 0 \n"); - return -3; - } + setTapeInfoHessSparse(tag, sHinfos); - if (repeat == -1) - return ret_val; + tapeInfos = getTapeInfos(tag); + ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); -// this is the most efficient variant. However, there was somewhere a bug in hos_ov_reverse - ret_val = hov_wk_forward(tag,1,indep,1,2,sHinfos.p,basepoint,sHinfos.Xppp,&y,sHinfos.Yppp); - MINDEC(ret_val,hos_ov_reverse(tag,1,indep,1,sHinfos.p,sHinfos.Upp,sHinfos.Zppp)); - - for (i = 0; i < sHinfos.p; ++i) - for (l = 0; l < indep; ++l) - sHinfos.Hcomp[l][i] = sHinfos.Zppp[i][l][1]; - - if (*values != NULL && *rind != NULL && *cind != NULL) { - // everything is preallocated, we assume correctly - // call usermem versions - if (options[1] == 0) - hr->IndirectRecover_CoordinateFormat_usermem(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values); - else - hr->DirectRecover_CoordinateFormat_usermem(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values); - } else { - // at least one of rind cind values is not allocated, deallocate others - // and call unmanaged versions - if (*values != NULL) - free(*values); - if (*rind != NULL) - free(*rind); - if (*cind != NULL) - free(*cind); - if (options[1] == 0) - hr->IndirectRecover_CoordinateFormat_unmanaged(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values); - else - hr->DirectRecover_CoordinateFormat_unmanaged(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values); - } + } else { + tapeInfos = getTapeInfos(tag); + ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); + sHinfos.nnz_in = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.nnz_in; + sHinfos.HP = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.HP; + sHinfos.Hcomp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Hcomp; + sHinfos.Xppp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Xppp; + sHinfos.Yppp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Yppp; + sHinfos.Zppp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Zppp; + sHinfos.Upp = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.Upp; + sHinfos.p = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.p; + g = (GraphColoringInterface *)ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.g; + hr = (HessianRecovery *)ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.hr; + } + + if (sHinfos.Upp == NULL) { + printf(" ADOL-C error in sparse_hess():" + " First call with repeat = 0 \n"); + return -3; + } + + if (sHinfos.nnz_in != *nnz) { + printf(" ADOL-C error in sparse_hess():" + " Number of nonzeros not consistent," + " new call with repeat = 0 \n"); + return -3; + } + + if (repeat == -1) return ret_val; + // this is the most efficient variant. However, there was somewhere a bug + // in hos_ov_reverse + ret_val = hov_wk_forward(tag, 1, indep, 1, 2, sHinfos.p, basepoint, + sHinfos.Xppp, &y, sHinfos.Yppp); + MINDEC(ret_val, hos_ov_reverse(tag, 1, indep, 1, sHinfos.p, sHinfos.Upp, + sHinfos.Zppp)); + + for (i = 0; i < sHinfos.p; ++i) + for (l = 0; l < indep; ++l) + sHinfos.Hcomp[l][i] = sHinfos.Zppp[i][l][1]; + + if (*values != NULL && *rind != NULL && *cind != NULL) { + // everything is preallocated, we assume correctly + // call usermem versions + if (options[1] == 0) + hr->IndirectRecover_CoordinateFormat_usermem(g, sHinfos.Hcomp, sHinfos.HP, + rind, cind, values); + else + hr->DirectRecover_CoordinateFormat_usermem(g, sHinfos.Hcomp, sHinfos.HP, + rind, cind, values); + } else { + // at least one of rind cind values is not allocated, deallocate others + // and call unmanaged versions + if (*values != NULL) + free(*values); + if (*rind != NULL) + free(*rind); + if (*cind != NULL) + free(*cind); + if (options[1] == 0) + hr->IndirectRecover_CoordinateFormat_unmanaged( + g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values); + else + hr->DirectRecover_CoordinateFormat_unmanaged(g, sHinfos.Hcomp, sHinfos.HP, + rind, cind, values); + } + return ret_val; } #else { - fprintf(DIAG_OUT, "ADOL-C error: function %s can only be used if linked with ColPack\n", __FUNCTION__); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - return -1; + fprintf(DIAG_OUT, + "ADOL-C error: function %s can only be used if linked with ColPack\n", + __FUNCTION__); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + return -1; } #endif - /****************************************************************************/ /******* sparse Hessians, set and get sparsity pattern ***************/ /****************************************************************************/ -void set_HP( - short tag, /* tape identification */ - int indep, /* number of independent variables */ - unsigned int ** HP) +void set_HP(short tag, /* tape identification */ + int indep, /* number of independent variables */ + unsigned int **HP) #ifdef SPARSE { - SparseHessInfos sHinfos; - TapeInfos *tapeInfos; - - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - tapeInfos=getTapeInfos(tag); - ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); - sHinfos.nnz_in = 0; - deepcopy_HP(&sHinfos.HP,HP,indep); - sHinfos.Hcomp = NULL; - sHinfos.Xppp = NULL; - sHinfos.Yppp = NULL; - sHinfos.Zppp = NULL; - sHinfos.Upp = NULL; - sHinfos.p = 0; - sHinfos.g = NULL; - sHinfos.hr = NULL; - sHinfos.indep = indep; - setTapeInfoHessSparse(tag, sHinfos); + SparseHessInfos sHinfos; + TapeInfos *tapeInfos; + + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + tapeInfos = getTapeInfos(tag); + ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); + sHinfos.nnz_in = 0; + deepcopy_HP(&sHinfos.HP, HP, indep); + sHinfos.Hcomp = NULL; + sHinfos.Xppp = NULL; + sHinfos.Yppp = NULL; + sHinfos.Zppp = NULL; + sHinfos.Upp = NULL; + sHinfos.p = 0; + sHinfos.g = NULL; + sHinfos.hr = NULL; + sHinfos.indep = indep; + setTapeInfoHessSparse(tag, sHinfos); } #else { - fprintf(DIAG_OUT, "ADOL-C error: function %s can only be used if sparse configuration option was used\n", __FUNCTION__); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, + "ADOL-C error: function %s can only be used if sparse configuration " + "option was used\n", + __FUNCTION__); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); } #endif -void get_HP( - short tag, /* tape identification */ - int indep, /* number of independent variables */ - unsigned int *** HP) +void get_HP(short tag, /* tape identification */ + int indep, /* number of independent variables */ + unsigned int ***HP) #ifdef SPARSE { - TapeInfos *tapeInfos; + TapeInfos *tapeInfos; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - tapeInfos=getTapeInfos(tag); - ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); - deepcopy_HP(HP,ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.HP,indep); + tapeInfos = getTapeInfos(tag); + ADOLC_CURRENT_TAPE_INFOS.copy(*tapeInfos); + deepcopy_HP(HP, ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.sHinfos.HP, indep); } #else { - fprintf(DIAG_OUT, "ADOL-C error: function %s can only be used if sparse configuration option was used\n", __FUNCTION__); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, + "ADOL-C error: function %s can only be used if sparse configuration " + "option was used\n", + __FUNCTION__); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); } #endif @@ -700,338 +698,333 @@ void get_HP( /* ------------------------------------------------------------------------- */ int bit_vector_propagation( - short tag, /* tape identification */ - int depen, /* number of dependent variables */ - int indep, /* number of independent variables */ - const double *basepoint, /* independent variable values */ + short tag, /* tape identification */ + int depen, /* number of dependent variables */ + int indep, /* number of independent variables */ + const double *basepoint, /* independent variable values */ unsigned int **crs, /* compressed block row storage */ - int *options /* control options */ - /* options[0] : way of bit pattern propagation - 0 - automatic detection (default) - 1 - forward mode - 2 - reverse mode - options[1] : test the computational graph control flow - 0 - safe variant (default) - 1 - tight variant */ + int *options /* control options */ + /* options[0] : way of bit pattern propagation + 0 - automatic detection (default) + 1 - forward mode + 2 - reverse mode + options[1] : test the computational graph control flow + 0 - safe variant (default) + 1 - tight variant */ ) { - int rc= 3; - char forward_mode, tight_mode; - int i, ii, j, jj, k, k_old, bits_per_long, - i_blocks_per_strip, d_blocks_per_strip; - int this_strip_i_bl_idx, next_strip_i_bl_idx, - this_strip_d_bl_idx, next_strip_d_bl_idx; - int stripmined_calls, strip_idx; - int p_stripmine, q_stripmine, p_ind_bl_bp, q_dep_bl_bp, - i_bl_idx, d_bl_idx; - unsigned long int value1, v; - unsigned long int **seed=NULL, *s, **jac_bit_pat=NULL, *jac; - unsigned char *indep_blocks_flags=NULL, *i_b_flags; - double *valuepoint=NULL; - - if ( options[1] == 0 ) { - if ( depen >= indep/2 ) - options[1] = 1; /* forward */ - else - options[1] = 2; /* reverse */ - } - - if ( options[1] == 1 ) - forward_mode = 1; + int rc = 3; + char forward_mode, tight_mode; + int i, ii, j, jj, k, k_old, bits_per_long, i_blocks_per_strip, + d_blocks_per_strip; + int this_strip_i_bl_idx, next_strip_i_bl_idx, this_strip_d_bl_idx, + next_strip_d_bl_idx; + int stripmined_calls, strip_idx; + int p_stripmine, q_stripmine, p_ind_bl_bp, q_dep_bl_bp, i_bl_idx, d_bl_idx; + unsigned long int value1, v; + unsigned long int **seed = NULL, *s, **jac_bit_pat = NULL, *jac; + unsigned char *indep_blocks_flags = NULL, *i_b_flags; + double *valuepoint = NULL; + + if (options[1] == 0) { + if (depen >= indep / 2) + options[1] = 1; /* forward */ else - forward_mode = 0; + options[1] = 2; /* reverse */ + } - if ( options[0] == 1 ) - tight_mode = 1; - else - tight_mode = 0; + if (options[1] == 1) + forward_mode = 1; + else + forward_mode = 0; - if ( ! forward_mode ) - valuepoint = myalloc1(depen); + if (options[0] == 1) + tight_mode = 1; + else + tight_mode = 0; - /* bit pattern parameters */ + if (!forward_mode) + valuepoint = myalloc1(depen); - /* number of bits in an unsigned long int variable */ - bits_per_long = 8 * sizeof(unsigned long int); - /* olvo 20000214 nl: inserted explicit cast to unsigned long int */ - value1 = (unsigned long int) 1 << (bits_per_long - 1); /* 10000....0 */ + /* bit pattern parameters */ - /* =================================================== forward propagation */ - if ( forward_mode ) { - - if (( tight_mode ) && ( basepoint == NULL )) { - fprintf(DIAG_OUT, "ADOL-C error in jac_pat(...) : supply basepoint x for tight mode.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } + /* number of bits in an unsigned long int variable */ + bits_per_long = 8 * sizeof(unsigned long int); + /* olvo 20000214 nl: inserted explicit cast to unsigned long int */ + value1 = (unsigned long int)1 << (bits_per_long - 1); /* 10000....0 */ - /* indep partial derivatives for the whole Jacobian */ + /* =================================================== forward propagation */ + if (forward_mode) { - /* number of unsigned longs to store the whole seed / Jacobian matrice */ - p_ind_bl_bp = indep / bits_per_long - + ( (indep % bits_per_long) != 0 ); + if ((tight_mode) && (basepoint == NULL)) { + fprintf(DIAG_OUT, "ADOL-C error in jac_pat(...) : supply basepoint x " + "for tight mode.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } - /* number of unsigned longs to store the seed / Jacobian strips */ - if ( p_ind_bl_bp <= PQ_STRIPMINE_MAX ) { - p_stripmine = p_ind_bl_bp; - stripmined_calls = 1; - } else { - p_stripmine = PQ_STRIPMINE_MAX; - stripmined_calls = p_ind_bl_bp / PQ_STRIPMINE_MAX - + ( (p_ind_bl_bp % PQ_STRIPMINE_MAX) != 0 ); - } + /* indep partial derivatives for the whole Jacobian */ - /* number of independent blocks per seed / Jacobian strip */ - i_blocks_per_strip = p_stripmine * bits_per_long; + /* number of unsigned longs to store the whole seed / Jacobian matrice */ + p_ind_bl_bp = indep / bits_per_long + ((indep % bits_per_long) != 0); - /* allocate memory --------------------------------------------------- */ + /* number of unsigned longs to store the seed / Jacobian strips */ + if (p_ind_bl_bp <= PQ_STRIPMINE_MAX) { + p_stripmine = p_ind_bl_bp; + stripmined_calls = 1; + } else { + p_stripmine = PQ_STRIPMINE_MAX; + stripmined_calls = p_ind_bl_bp / PQ_STRIPMINE_MAX + + ((p_ind_bl_bp % PQ_STRIPMINE_MAX) != 0); + } - if ( ! (indep_blocks_flags = (unsigned char*) - calloc(i_blocks_per_strip, sizeof(char)) ) ) { - fprintf(DIAG_OUT, "ADOL-C error, " __FILE__ - ":%i : \njac_pat(...) unable to allocate %i bytes !\n", - __LINE__, (int)(i_blocks_per_strip*sizeof(char))); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + /* number of independent blocks per seed / Jacobian strip */ + i_blocks_per_strip = p_stripmine * bits_per_long; + + /* allocate memory --------------------------------------------------- */ + + if (!(indep_blocks_flags = + (unsigned char *)calloc(i_blocks_per_strip, sizeof(char)))) { + fprintf(DIAG_OUT, + "ADOL-C error, " __FILE__ + ":%i : \njac_pat(...) unable to allocate %i bytes !\n", + __LINE__, (int)(i_blocks_per_strip * sizeof(char))); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + + seed = myalloc2_ulong(indep, p_stripmine); + jac_bit_pat = myalloc2_ulong(depen, p_stripmine); + + /* strip-mining : repeated forward calls ----------------------------- */ + + for (strip_idx = 0; strip_idx < stripmined_calls; strip_idx++) { + /* build a partition of the seed matrix (indep x indep_blocks) --- */ + /* (indep x i_blocks_per_strip) as a bit pattern */ + s = seed[0]; + for (i = 0; i < indep; i++) + for (ii = 0; ii < p_stripmine; ii++) /* 2 loops if short -> int !!! */ + *s++ = 0; /* set old seed matrix to 0 */ + + this_strip_i_bl_idx = strip_idx * i_blocks_per_strip; + next_strip_i_bl_idx = (strip_idx + 1) * i_blocks_per_strip; + if (next_strip_i_bl_idx > indep) + next_strip_i_bl_idx = indep; + v = value1; /* 10000....0 */ + + for (i = 0; i < indep; i++) + if ((this_strip_i_bl_idx <= i) && (i < next_strip_i_bl_idx)) { + ii = (i - this_strip_i_bl_idx) / bits_per_long; + seed[i][ii] = v >> ((i - this_strip_i_bl_idx) % bits_per_long); } - seed = myalloc2_ulong(indep, p_stripmine); - jac_bit_pat = myalloc2_ulong(depen, p_stripmine); + /* bit pattern propagation by forward ---------------------------- */ - /* strip-mining : repeated forward calls ----------------------------- */ + if (tight_mode) { + rc = int_forward_tight(tag, depen, indep, p_stripmine, basepoint, seed, + valuepoint, jac_bit_pat); + } else { + rc = + int_forward_safe(tag, depen, indep, p_stripmine, seed, jac_bit_pat); + } - for (strip_idx = 0; strip_idx < stripmined_calls; strip_idx++) { - /* build a partition of the seed matrix (indep x indep_blocks) --- */ - /* (indep x i_blocks_per_strip) as a bit pattern */ - s = seed[0]; - for (i=0; i int !!! */ - *s++ = 0; /* set old seed matrix to 0 */ + /* extract pattern from bit patterns --------------------- */ - this_strip_i_bl_idx = strip_idx * i_blocks_per_strip; - next_strip_i_bl_idx = (strip_idx+1) * i_blocks_per_strip; - if ( next_strip_i_bl_idx > indep ) - next_strip_i_bl_idx = indep; + for (j = 0; j < depen; j++) { + ii = -1; + v = 0; + + jac = jac_bit_pat[j]; + i_b_flags = indep_blocks_flags; + for (i_bl_idx = 0; i_bl_idx < i_blocks_per_strip; i_bl_idx++) { + if (!v) { v = value1; /* 10000....0 */ + ii++; + } + if (v & jac[ii]) + *i_b_flags = 1; + i_b_flags++; + + v = v >> 1; + } - for (i=0; i> ((i - this_strip_i_bl_idx) % bits_per_long); - } - - /* bit pattern propagation by forward ---------------------------- */ - - if ( tight_mode ) - { - rc = int_forward_tight( tag, depen, indep, p_stripmine, - basepoint, seed, valuepoint, jac_bit_pat); - } - else - { - rc = int_forward_safe ( tag, depen, indep, p_stripmine, - seed, jac_bit_pat); - } - - /* extract pattern from bit patterns --------------------- */ - - for (j = 0; j < depen; j++) { - ii = -1; - v = 0; - - jac = jac_bit_pat[j]; - i_b_flags = indep_blocks_flags; - for (i_bl_idx = 0; i_bl_idx < i_blocks_per_strip; i_bl_idx++) { - if ( !v ) { - v = value1; /* 10000....0 */ - ii++; - } - if ( v & jac[ii] ) - *i_b_flags = 1; - i_b_flags++; - - v = v >> 1; - } - - if ( strip_idx == 0 ) - k_old = 0; - else - k_old = crs[j][0]; - k = 0; - i_b_flags = indep_blocks_flags; - for (i = 0; i < i_blocks_per_strip; i++) - k += *i_b_flags++; - - if ((k > 0 ) || ( strip_idx == 0 )) { - if ( ! (crs[j] = (unsigned int*)realloc(crs[j], - (k_old+k+1)*sizeof(unsigned int))) ) { - fprintf(DIAG_OUT, "ADOL-C error, " __FILE__ - ":%i : \njac_pat(...) unable to allocate %i bytes !\n", - __LINE__, (int)((k_old+k+1)*sizeof(unsigned int))); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - if ( strip_idx == 0 ) - crs[j][0] = 0; - if ( k > 0 ) { - k = crs[j][0] + 1; - i_b_flags = indep_blocks_flags; - for (i = 0; i < i_blocks_per_strip; i++) { - if ( *i_b_flags ) { - crs[j][k++] = this_strip_i_bl_idx + i; - *i_b_flags = 0; - } - i_b_flags++; - } - /* current/total number of non-zero blocks of indep. vars. */ - crs[j][0] = k - 1; - } - } + if (strip_idx == 0) + k_old = 0; + else + k_old = crs[j][0]; + k = 0; + i_b_flags = indep_blocks_flags; + for (i = 0; i < i_blocks_per_strip; i++) + k += *i_b_flags++; + + if ((k > 0) || (strip_idx == 0)) { + if (!(crs[j] = (unsigned int *)realloc( + crs[j], (k_old + k + 1) * sizeof(unsigned int)))) { + fprintf(DIAG_OUT, + "ADOL-C error, " __FILE__ + ":%i : \njac_pat(...) unable to allocate %i bytes !\n", + __LINE__, (int)((k_old + k + 1) * sizeof(unsigned int))); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + if (strip_idx == 0) + crs[j][0] = 0; + if (k > 0) { + k = crs[j][0] + 1; + i_b_flags = indep_blocks_flags; + for (i = 0; i < i_blocks_per_strip; i++) { + if (*i_b_flags) { + crs[j][k++] = this_strip_i_bl_idx + i; + *i_b_flags = 0; + } + i_b_flags++; } - } /* strip_idx */ + /* current/total number of non-zero blocks of indep. vars. */ + crs[j][0] = k - 1; + } + } + } + } /* strip_idx */ - } /* forward */ + } /* forward */ + /* =================================================== reverse propagation */ + else { - /* =================================================== reverse propagation */ - else { + /* depen weight vectors for the whole Jacobian */ - /* depen weight vectors for the whole Jacobian */ + /* number of unsigned longs to store the whole seed / Jacobian matrice */ + q_dep_bl_bp = depen / bits_per_long + ((depen % bits_per_long) != 0); - /* number of unsigned longs to store the whole seed / Jacobian matrice */ - q_dep_bl_bp = depen / bits_per_long - + ( (depen % bits_per_long) != 0 ); + /* number of unsigned longs to store the seed / Jacobian strips */ + if (q_dep_bl_bp <= PQ_STRIPMINE_MAX) { + q_stripmine = q_dep_bl_bp; + stripmined_calls = 1; + } else { + q_stripmine = PQ_STRIPMINE_MAX; + stripmined_calls = q_dep_bl_bp / PQ_STRIPMINE_MAX + + ((q_dep_bl_bp % PQ_STRIPMINE_MAX) != 0); + } - /* number of unsigned longs to store the seed / Jacobian strips */ - if ( q_dep_bl_bp <= PQ_STRIPMINE_MAX ) { - q_stripmine = q_dep_bl_bp; - stripmined_calls = 1; - } else { - q_stripmine = PQ_STRIPMINE_MAX; - stripmined_calls = q_dep_bl_bp / PQ_STRIPMINE_MAX - + ( (q_dep_bl_bp % PQ_STRIPMINE_MAX) != 0 ); - } + /* number of dependent blocks per seed / Jacobian strip */ + d_blocks_per_strip = q_stripmine * bits_per_long; + + /* allocate memory --------------------------------------------------- */ + if (!(indep_blocks_flags = + (unsigned char *)calloc(indep, sizeof(unsigned char)))) { + fprintf(DIAG_OUT, + "ADOL-C error, " __FILE__ + ":%i : \njac_pat(...) unable to allocate %i bytes !\n", + __LINE__, (int)(indep * sizeof(unsigned char))); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } - /* number of dependent blocks per seed / Jacobian strip */ - d_blocks_per_strip = q_stripmine * bits_per_long; + seed = myalloc2_ulong(q_stripmine, depen); + jac_bit_pat = myalloc2_ulong(q_stripmine, indep); - /* allocate memory --------------------------------------------------- */ - if ( ! (indep_blocks_flags = (unsigned char*)calloc(indep, - sizeof(unsigned char)) ) ) { - fprintf(DIAG_OUT, "ADOL-C error, " __FILE__ - ":%i : \njac_pat(...) unable to allocate %i bytes !\n", - __LINE__, (int)(indep*sizeof(unsigned char))); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } + /* olvo 20000214: call to forward required in tight mode only, + in safe mode no basepoint available! */ + if (tight_mode) { + if (basepoint == NULL) { + fprintf(DIAG_OUT, "ADOL-C error in jac_pat(..) : "); + fprintf(DIAG_OUT, "no basepoint x for tight mode supplied.\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } - seed = myalloc2_ulong(q_stripmine, depen); - jac_bit_pat = myalloc2_ulong(q_stripmine, indep); + rc = zos_forward(tag, depen, indep, 1, basepoint, valuepoint); + } + /* strip-mining : repeated reverse calls ----------------------------- */ + + for (strip_idx = 0; strip_idx < stripmined_calls; strip_idx++) { + /* build a partition of the seed matrix (depen_blocks x depen) */ + /* (d_blocks_per_strip x depen) as a bit pattern */ + s = seed[0]; + for (jj = 0; jj < q_stripmine; jj++) /* 2 loops if short -> int !!! */ + for (j = 0; j < depen; j++) + *s++ = 0; /* set old seed matrix to 0 */ + + this_strip_d_bl_idx = strip_idx * d_blocks_per_strip; + next_strip_d_bl_idx = (strip_idx + 1) * d_blocks_per_strip; + if (next_strip_d_bl_idx > depen) + next_strip_d_bl_idx = depen; + v = value1; /* 10000....0 */ + + for (j = 0; j < depen; j++) + if ((this_strip_d_bl_idx <= j) && (j < next_strip_d_bl_idx)) { + jj = (j - this_strip_d_bl_idx) / bits_per_long; + seed[jj][j] = v >> ((j - this_strip_d_bl_idx) % bits_per_long); + } - /* olvo 20000214: call to forward required in tight mode only, - in safe mode no basepoint available! */ - if ( tight_mode ) { - if ( basepoint == NULL ) { - fprintf(DIAG_OUT, "ADOL-C error in jac_pat(..) : "); - fprintf(DIAG_OUT, "no basepoint x for tight mode supplied.\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } + /* bit pattern propagation by reverse ---------------------------- */ - rc = zos_forward(tag, depen, indep, 1, basepoint, valuepoint); + if (tight_mode) + rc = int_reverse_tight(tag, depen, indep, q_stripmine, seed, + jac_bit_pat); + else + rc = + int_reverse_safe(tag, depen, indep, q_stripmine, seed, jac_bit_pat); + + /* extract pattern from bit patterns --------------------- */ + + jj = -1; + v = 0; + for (d_bl_idx = this_strip_d_bl_idx; d_bl_idx < next_strip_d_bl_idx; + d_bl_idx++) { + if (!v) { + v = value1; /* 10000....0 */ + jj++; + } + jac = jac_bit_pat[jj]; + for (i = 0; i < indep; i++) { + if (v & *jac++) { + indep_blocks_flags[i] = 1; + } } - /* strip-mining : repeated reverse calls ----------------------------- */ + v = v >> 1; - for (strip_idx = 0; strip_idx < stripmined_calls; strip_idx++) { - /* build a partition of the seed matrix (depen_blocks x depen) */ - /* (d_blocks_per_strip x depen) as a bit pattern */ - s = seed[0]; - for (jj=0; jj int !!! */ - for (j=0; j depen ) - next_strip_d_bl_idx = depen; - v = value1; /* 10000....0 */ + if (!(crs[d_bl_idx] = + (unsigned int *)malloc((k + 1) * sizeof(unsigned int)))) { + fprintf(DIAG_OUT, + "ADOL-C error, " __FILE__ + ":%i : \njac_pat(...) unable to allocate %i bytes !\n", + __LINE__, (int)((k + 1) * sizeof(unsigned int))); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + crs[d_bl_idx][0] = k; /* number of non-zero indep. blocks */ + k = 1; + i_b_flags = indep_blocks_flags; + for (i = 0; i < indep; i++) { + if (*i_b_flags) { + crs[d_bl_idx][k++] = i; + *i_b_flags = 0; + } + i_b_flags++; + } + } - for (j=0; j> ((j - this_strip_d_bl_idx) % bits_per_long); - } - - /* bit pattern propagation by reverse ---------------------------- */ - - if ( tight_mode ) - rc = int_reverse_tight( tag, depen, indep, q_stripmine, - seed, jac_bit_pat); - else - rc = int_reverse_safe ( tag, depen, indep, q_stripmine, - seed, jac_bit_pat); - - - /* extract pattern from bit patterns --------------------- */ - - jj = -1; - v = 0; - for (d_bl_idx = this_strip_d_bl_idx; - d_bl_idx < next_strip_d_bl_idx; d_bl_idx++) { - if ( !v ) { - v = value1; /* 10000....0 */ - jj++; - } - jac = jac_bit_pat[jj]; - for (i=0; i> 1; - - k=0; - i_b_flags = indep_blocks_flags; - for (i=0; i -//namespace adtl { +// namespace adtl { #ifdef SPARSE -SparseJacInfos sJinfos - = { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0 }; +SparseJacInfos sJinfos = {NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0}; #endif -int ADOLC_get_sparse_jacobian( func_ad *const fun, func_ad *const fun_indo, - int n, int m, int repeat, double* basepoints, - int *nnz, unsigned int **rind, - unsigned int **cind, double **values) +int ADOLC_get_sparse_jacobian(func_ad *const fun, + func_ad *const fun_indo, + int n, int m, int repeat, double *basepoints, + int *nnz, unsigned int **rind, + unsigned int **cind, double **values) #if HAVE_LIBCOLPACK { - int i; - unsigned int j; - int ret_val = -1; - if (!repeat) { - freeSparseJacInfos(sJinfos.y, sJinfos.B, sJinfos.JP, sJinfos.g, sJinfos.jr1d, sJinfos.seed_rows, sJinfos.seed_clms, sJinfos.depen); - //setNumDir(n); - //setMode(ADTL_INDO); + int i; + unsigned int j; + int ret_val = -1; + if (!repeat) { + freeSparseJacInfos(sJinfos.y, sJinfos.B, sJinfos.JP, sJinfos.g, + sJinfos.jr1d, sJinfos.seed_rows, sJinfos.seed_clms, + sJinfos.depen); + // setNumDir(n); + // setMode(ADTL_INDO); { - adtl_indo::adouble *x, *y; - x = new adtl_indo::adouble[n]; - y = new adtl_indo::adouble[m]; - for (i=0; i < n ; i++){ - x[i] = basepoints[i]; - //x[i].setADValue(i,1); - } - ret_val = adtl_indo::ADOLC_Init_sparse_pattern(x,n,0); + adtl_indo::adouble *x, *y; + x = new adtl_indo::adouble[n]; + y = new adtl_indo::adouble[m]; + for (i = 0; i < n; i++) { + x[i] = basepoints[i]; + // x[i].setADValue(i,1); + } + ret_val = adtl_indo::ADOLC_Init_sparse_pattern(x, n, 0); - ret_val = (*fun_indo)(n,x,m,y); + ret_val = (*fun_indo)(n, x, m, y); - if (ret_val < 0) { - printf(" ADOL-C error in tapeless sparse_jac() \n"); - return ret_val; - } + if (ret_val < 0) { + printf(" ADOL-C error in tapeless sparse_jac() \n"); + return ret_val; + } - ret_val = adtl_indo::ADOLC_get_sparse_pattern(y, m, sJinfos.JP ); - delete[] x; - delete[] y; + ret_val = adtl_indo::ADOLC_get_sparse_pattern(y, m, sJinfos.JP); + delete[] x; + delete[] y; } sJinfos.depen = m; sJinfos.nnz_in = 0; - for (i=0;iGenerateSeedJacobian(&(sJinfos.Seed), &(sJinfos.seed_rows), - &(sJinfos.seed_clms), "SMALLEST_LAST","COLUMN_PARTIAL_DISTANCE_TWO"); - sJinfos.seed_rows = m; + g->GenerateSeedJacobian(&(sJinfos.Seed), &(sJinfos.seed_rows), + &(sJinfos.seed_clms), "SMALLEST_LAST", + "COLUMN_PARTIAL_DISTANCE_TWO"); + sJinfos.seed_rows = m; - sJinfos.B = myalloc2(sJinfos.seed_rows,sJinfos.seed_clms); - sJinfos.y = myalloc1(m); + sJinfos.B = myalloc2(sJinfos.seed_rows, sJinfos.seed_clms); + sJinfos.y = myalloc1(m); - sJinfos.g = (void *) g; - sJinfos.jr1d = (void *) jr1d; + sJinfos.g = (void *)g; + sJinfos.jr1d = (void *)jr1d; if (sJinfos.nnz_in != *nnz) { - printf(" ADOL-C error in sparse_jac():" - " Number of nonzeros not consistent," - " repeat call with repeat = 0 \n"); - return -3; + printf(" ADOL-C error in sparse_jac():" + " Number of nonzeros not consistent," + " repeat call with repeat = 0 \n"); + return -3; } - - } -// ret_val = fov_forward(tag, depen, indep, sJinfos.seed_clms, basepoint, sJinfos.Seed, sJinfos.y, sJinfos.B); - adtl::setNumDir(sJinfos.seed_clms); - //setMode(ADTL_FOV); - { + } + // ret_val = fov_forward(tag, depen, indep, sJinfos.seed_clms, basepoint, + // sJinfos.Seed, sJinfos.y, sJinfos.B); + adtl::setNumDir(sJinfos.seed_clms); + // setMode(ADTL_FOV); + { adtl::adouble *x, *y; - x = new adtl::adouble[n]; - y = new adtl::adouble[m]; + x = new adtl::adouble[n]; + y = new adtl::adouble[m]; - for (i=0; i < n ; i++){ + for (i = 0; i < n; i++) { x[i] = basepoints[i]; - for (int jj=0; jj < sJinfos.seed_clms; jj++) - x[i].setADValue(jj,sJinfos.Seed[i][jj]); + for (int jj = 0; jj < sJinfos.seed_clms; jj++) + x[i].setADValue(jj, sJinfos.Seed[i][jj]); } - ret_val = (*fun)(n,x,m,y); - - for (i=0;i ColPack library */ - - if (*values != NULL) - free(*values); - if (*rind != NULL) - free(*rind); - if (*cind != NULL) - free(*cind); - BipartiteGraphPartialColoringInterface *g; - JacobianRecovery1D *jr1d; - g = (BipartiteGraphPartialColoringInterface*)sJinfos.g; - jr1d = (JacobianRecovery1D*)sJinfos.jr1d; - jr1d->RecoverD2Cln_CoordinateFormat_unmanaged(g, sJinfos.B, sJinfos.JP, rind, cind, values); - - //delete g; - //delete jr1d; - - return ret_val; - + ret_val = (*fun)(n, x, m, y); + + for (i = 0; i < m; i++) + for (int jj = 0; jj < sJinfos.seed_clms; jj++) + sJinfos.B[i][jj] = y[i].getADValue(jj); + + delete[] x; + delete[] y; + } + /* recover compressed Jacobian => ColPack library */ + + if (*values != NULL) + free(*values); + if (*rind != NULL) + free(*rind); + if (*cind != NULL) + free(*cind); + BipartiteGraphPartialColoringInterface *g; + JacobianRecovery1D *jr1d; + g = (BipartiteGraphPartialColoringInterface *)sJinfos.g; + jr1d = (JacobianRecovery1D *)sJinfos.jr1d; + jr1d->RecoverD2Cln_CoordinateFormat_unmanaged(g, sJinfos.B, sJinfos.JP, rind, + cind, values); + + // delete g; + // delete jr1d; + + return ret_val; } #else { - fprintf(DIAG_OUT, "ADOL-C error: function %s can only be used if linked with ColPack\n", __FUNCTION__); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - return -1; + fprintf(DIAG_OUT, + "ADOL-C error: function %s can only be used if linked with ColPack\n", + __FUNCTION__); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + return -1; } #endif - //} /****************************************************************************/ /* THAT'S ALL */ - diff --git a/ADOL-C/src/storemanager.cpp b/ADOL-C/src/storemanager.cpp index 2926482de..4b9c71752 100644 --- a/ADOL-C/src/storemanager.cpp +++ b/ADOL-C/src/storemanager.cpp @@ -8,230 +8,228 @@ Benjamin Letschert, Jean Utke This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ -#include "taping_p.h" #include "checkpointing_p.h" #include "dvlparms.h" -#include +#include "taping_p.h" #include +#include #include -#include // For memset -#include +#include // For memset #include +#include #ifdef HAVE_UNISTD_H -#include + #include #endif #include - #if defined(ADOLC_TRACK_ACTIVITY) -char const* const StoreManagerLocint::nowhere = NULL; +char const *const StoreManagerLocint::nowhere = NULL; -StoreManagerLocint::StoreManagerLocint(double * &storePtr, char* &actStorePtr, size_t &size, size_t &numlives) : - storePtr(storePtr), - activityTracking(1), - actStorePtr(actStorePtr), - indexFree(0), - head(0), - maxsize(size), currentfill(numlives) -{ -#ifdef ADOLC_DEBUG - std::cerr << "StoreManagerLocint::StoreManagerLocint()\n"; -#endif +StoreManagerLocint::StoreManagerLocint(double *&storePtr, char *&actStorePtr, + size_t &size, size_t &numlives) + : storePtr(storePtr), activityTracking(1), actStorePtr(actStorePtr), + indexFree(0), head(0), maxsize(size), currentfill(numlives) { + #ifdef ADOLC_DEBUG + std::cerr << "StoreManagerLocint::StoreManagerLocint()\n"; + #endif } StoreManagerLocint::StoreManagerLocint(const StoreManagerLocint *const stm, - double * &storePtr, char* &actStorePtr, size_t &size, size_t &numlives) : - storePtr(storePtr), - actStorePtr(actStorePtr), - activityTracking(1), - maxsize(size), currentfill(numlives) -{ -#ifdef ADOLC_DEBUG - std::cerr << "StoreManagerLocint::StoreManagerLocint()\n"; -#endif - head = stm->head; - indexFree = new locint[maxsize]; - for (size_t i = 0; i < maxsize; i++) - indexFree[i] = stm->indexFree[i]; + double *&storePtr, char *&actStorePtr, + size_t &size, size_t &numlives) + : storePtr(storePtr), actStorePtr(actStorePtr), activityTracking(1), + maxsize(size), currentfill(numlives) { + #ifdef ADOLC_DEBUG + std::cerr << "StoreManagerLocint::StoreManagerLocint()\n"; + #endif + head = stm->head; + indexFree = new locint[maxsize]; + for (size_t i = 0; i < maxsize; i++) + indexFree[i] = stm->indexFree[i]; } #endif -StoreManagerLocint::StoreManagerLocint(double * &storePtr, size_t &size, size_t &numlives) : - storePtr(storePtr), +StoreManagerLocint::StoreManagerLocint(double *&storePtr, size_t &size, + size_t &numlives) + : storePtr(storePtr), #if defined(ADOLC_TRACK_ACTIVITY) - activityTracking(0), - actStorePtr(const_cast(nowhere)), + activityTracking(0), actStorePtr(const_cast(nowhere)), #endif - indexFree(0), - head(0), - maxsize(size), currentfill(numlives) -{ + indexFree(0), head(0), maxsize(size), currentfill(numlives) { #ifdef ADOLC_DEBUG - std::cerr << "StoreManagerLocint::StoreManagerLocint()\n"; + std::cerr << "StoreManagerLocint::StoreManagerLocint()\n"; #endif } -StoreManagerLocint::~StoreManagerLocint() -{ +StoreManagerLocint::~StoreManagerLocint() { #ifdef ADOLC_DEBUG - std::cerr << "StoreManagerLocint::~StoreManagerLocint()\n"; -#endif - if (storePtr) { - delete[] storePtr; - storePtr = 0; - } - if (indexFree) { - delete[] indexFree; - indexFree = 0; - } + std::cerr << "StoreManagerLocint::~StoreManagerLocint()\n"; +#endif + if (storePtr) { + delete[] storePtr; + storePtr = 0; + } + if (indexFree) { + delete[] indexFree; + indexFree = 0; + } #if defined(ADOLC_TRACK_ACTIVITY) - if (activityTracking && actStorePtr) { - delete[] actStorePtr; - } + if (activityTracking && actStorePtr) { + delete[] actStorePtr; + } #endif - maxsize = 0; - currentfill = 0; - head = 0; + maxsize = 0; + currentfill = 0; + head = 0; } StoreManagerLocint::StoreManagerLocint(const StoreManagerLocint *const stm, - double * &storePtr, size_t &size, size_t &numlives) : - storePtr(storePtr), + double *&storePtr, size_t &size, + size_t &numlives) + : storePtr(storePtr), #if defined(ADOLC_TRACK_ACTIVITY) - activityTracking(0), - actStorePtr(const_cast(nowhere)), + activityTracking(0), actStorePtr(const_cast(nowhere)), #endif - maxsize(size), currentfill(numlives) -{ + maxsize(size), currentfill(numlives) { #ifdef ADOLC_DEBUG - std::cerr << "StoreManagerLocint::StoreManagerLocint()\n"; + std::cerr << "StoreManagerLocint::StoreManagerLocint()\n"; #endif - head = stm->head; - indexFree = new locint[maxsize]; - for (size_t i = 0; i < maxsize; i++) - indexFree[i] = stm->indexFree[i]; + head = stm->head; + indexFree = new locint[maxsize]; + for (size_t i = 0; i < maxsize; i++) + indexFree[i] = stm->indexFree[i]; } locint StoreManagerLocint::next_loc() { - if (head == 0) { - grow(); - } - assert(head); - locint const result = head; - head = indexFree[head]; - ++currentfill; + if (head == 0) { + grow(); + } + assert(head); + locint const result = head; + head = indexFree[head]; + ++currentfill; #ifdef ADOLC_DEBUG - std::cerr << "next_loc: " << result << " fill: " << size() << "max: " << maxSize() << endl; + std::cerr << "next_loc: " << result << " fill: " << size() + << "max: " << maxSize() << endl; #endif - return result; + return result; } void StoreManagerLocint::free_loc(locint loc) { - assert(0 < loc && loc < maxsize); - indexFree[loc] = head; - head = loc; - --currentfill; + assert(0 < loc && loc < maxsize); + indexFree[loc] = head; + head = loc; + --currentfill; #ifdef ADOLC_DEBUG - std::cerr << "free_loc: " << loc << " fill: " << size() << "max: " << maxSize() << endl; + std::cerr << "free_loc: " << loc << " fill: " << size() + << "max: " << maxSize() << endl; #endif } void StoreManagerLocint::ensure_block(size_t n) { - fprintf(DIAG_OUT,"ADOL-C error: Location block required from singleton location store"); - adolc_exit(-4,"ADOL-C error: Location blocks not allowed",__func__,__FILE__,__LINE__); + fprintf( + DIAG_OUT, + "ADOL-C error: Location block required from singleton location store"); + adolc_exit(-4, "ADOL-C error: Location blocks not allowed", __func__, + __FILE__, __LINE__); } void StoreManagerLocint::grow(size_t mingrow) { - if (maxsize == 0) maxsize += initialSize; - size_t const oldMaxsize = maxsize; - maxsize *= 2; - if (maxsize < mingrow) maxsize = mingrow; - - if (maxsize > std::numeric_limits::max()) { - // encapsulate this error message - fprintf(DIAG_OUT,"\nADOL-C error:\n"); - fprintf(DIAG_OUT,"maximal number (%d) of live active variables exceeded\n\n", - std::numeric_limits::max()); - adolc_exit(-3,"",__func__,__FILE__,__LINE__); - } + if (maxsize == 0) + maxsize += initialSize; + size_t const oldMaxsize = maxsize; + maxsize *= 2; + if (maxsize < mingrow) + maxsize = mingrow; + + if (maxsize > std::numeric_limits::max()) { + // encapsulate this error message + fprintf(DIAG_OUT, "\nADOL-C error:\n"); + fprintf(DIAG_OUT, + "maximal number (%d) of live active variables exceeded\n\n", + std::numeric_limits::max()); + adolc_exit(-3, "", __func__, __FILE__, __LINE__); + } #ifdef ADOLC_DEBUG - std::cerr << "StoreManagerLocint::grow(): increase size from " << oldMaxsize - << " to " << maxsize << " entries (currently " << size() << " entries used)\n"; - assert(oldMaxsize == initialSize or size() == oldMaxsize); + std::cerr << "StoreManagerLocint::grow(): increase size from " << oldMaxsize + << " to " << maxsize << " entries (currently " << size() + << " entries used)\n"; + assert(oldMaxsize == initialSize or size() == oldMaxsize); #endif - double *const oldStore = storePtr; - locint *const oldIndex = indexFree; + double *const oldStore = storePtr; + locint *const oldIndex = indexFree; #if defined(ADOLC_TRACK_ACTIVITY) - char * oldactStore; - if (activityTracking) { - oldactStore = actStorePtr; - } + char *oldactStore; + if (activityTracking) { + oldactStore = actStorePtr; + } #endif #if defined(ADOLC_DEBUG) - std::cerr << "StoreManagerLocint::grow(): allocate " << maxsize * sizeof(double) << " B doubles " - << "and " << maxsize * sizeof(locint) << " B locints\n"; + std::cerr << "StoreManagerLocint::grow(): allocate " + << maxsize * sizeof(double) << " B doubles " + << "and " << maxsize * sizeof(locint) << " B locints\n"; #endif - storePtr = new double[maxsize]; - indexFree = new locint[maxsize]; + storePtr = new double[maxsize]; + indexFree = new locint[maxsize]; #if defined(ADOLC_TRACK_ACTIVITY) - if (activityTracking) - actStorePtr = new char[maxsize]; + if (activityTracking) + actStorePtr = new char[maxsize]; #endif - // we use index 0 as end-of-list marker - size_t i = 1; - storePtr[0] = std::numeric_limits::quiet_NaN(); + // we use index 0 as end-of-list marker + size_t i = 1; + storePtr[0] = std::numeric_limits::quiet_NaN(); - if (oldMaxsize != initialSize) { // not the first time + if (oldMaxsize != initialSize) { // not the first time #if defined(ADOLC_DEBUG) - std::cerr << "StoreManagerLocint::grow(): copy values\n"; + std::cerr << "StoreManagerLocint::grow(): copy values\n"; #endif - for (size_t j = i; j < oldMaxsize; ++j) { - indexFree[j] = oldIndex[j]; - } - for (size_t j = i; j < oldMaxsize; ++j) { - storePtr[j] = oldStore[j]; - } + for (size_t j = i; j < oldMaxsize; ++j) { + indexFree[j] = oldIndex[j]; + } + for (size_t j = i; j < oldMaxsize; ++j) { + storePtr[j] = oldStore[j]; + } #if defined(ADOLC_TRACK_ACTIVITY) - if (activityTracking) { - for (size_t j = i; j < oldMaxsize; ++j) { - actStorePtr[j] = oldactStore[j]; - } + if (activityTracking) { + for (size_t j = i; j < oldMaxsize; ++j) { + actStorePtr[j] = oldactStore[j]; } + } #endif - // reset i to start of new slots (upper half) - i = oldMaxsize; + // reset i to start of new slots (upper half) + i = oldMaxsize; #if defined(ADOLC_DEBUG) - std::cerr << "StoreManagerLocint::grow(): free " << oldMaxsize * sizeof(double) - << " + " << oldMaxsize * sizeof(locint) << " B\n"; + std::cerr << "StoreManagerLocint::grow(): free " + << oldMaxsize * sizeof(double) << " + " + << oldMaxsize * sizeof(locint) << " B\n"; #endif - delete [] oldStore; - delete [] oldIndex; + delete[] oldStore; + delete[] oldIndex; #if defined(ADOLC_TRACK_ACTIVITY) - if (activityTracking) - delete [] oldactStore; + if (activityTracking) + delete[] oldactStore; #endif - } + } - head = i; - // create initial linked list for new slots - for ( ; i < maxsize-1; ++i) { - indexFree[i] = i + 1; - } - indexFree[i] = 0; // end marker - assert(i == maxsize-1); + head = i; + // create initial linked list for new slots + for (; i < maxsize - 1; ++i) { + indexFree[i] = i + 1; + } + indexFree[i] = 0; // end marker + assert(i == maxsize - 1); } - /****************************************************************************/ /* Returns the next free location in "adouble" memory. */ /****************************************************************************/ @@ -252,383 +250,401 @@ void free_loc(locint loc) { #if defined(ADOLC_TRACK_ACTIVITY) -char const* const StoreManagerLocintBlock::nowhere = NULL; - -StoreManagerLocintBlock::StoreManagerLocintBlock(double * &storePtr, char* &actStorePtr, size_t &size, size_t &numlives) : - storePtr(storePtr), - actStorePtr(actStorePtr), - activityTracking(1), - maxsize(size), - currentfill(numlives) -#ifdef ADOLC_LOCDEBUG - ,ensure_blockCallsSinceLastConsolidateBlocks(0) -#endif - { - indexFree.clear(); -#ifdef ADOLC_LOCDEBUG - std::cerr << "StoreManagerLocintBlock::StoreManagerLocIntBlock()\n"; -#endif +char const *const StoreManagerLocintBlock::nowhere = NULL; + +StoreManagerLocintBlock::StoreManagerLocintBlock(double *&storePtr, + char *&actStorePtr, + size_t &size, size_t &numlives) + : storePtr(storePtr), actStorePtr(actStorePtr), activityTracking(1), + maxsize(size), currentfill(numlives) + #ifdef ADOLC_LOCDEBUG + , + ensure_blockCallsSinceLastConsolidateBlocks(0) + #endif +{ + indexFree.clear(); + #ifdef ADOLC_LOCDEBUG + std::cerr << "StoreManagerLocintBlock::StoreManagerLocIntBlock()\n"; + #endif } StoreManagerLocintBlock::StoreManagerLocintBlock( - const StoreManagerLocintBlock *const stm, - double * &storePtr, char * &actStorePtr, size_t &size, size_t &numlives) : - storePtr(storePtr), -#if defined(ADOLC_TRACK_ACTIVITY) - actStorePtr(actStorePtr), - activityTracking(1), -#endif - maxsize(size), - currentfill(numlives) -#ifdef ADOLC_LOCDEBUG - ,ensure_blockCallsSinceLastConsolidateBlocks(0) -#endif - { -#ifdef ADOLC_LOCDEBUG - std::cerr << "StoreManagerLocintBlock::StoreManagerLocintBlock()\n"; -#endif - indexFree.clear(); - std::forward_list::const_iterator iter = stm->indexFree.begin(); - for (; iter != stm->indexFree.end(); iter++) - indexFree.emplace_front( *iter ); + const StoreManagerLocintBlock *const stm, double *&storePtr, + char *&actStorePtr, size_t &size, size_t &numlives) + : storePtr(storePtr), + #if defined(ADOLC_TRACK_ACTIVITY) + actStorePtr(actStorePtr), activityTracking(1), + #endif + maxsize(size), currentfill(numlives) + #ifdef ADOLC_LOCDEBUG + , + ensure_blockCallsSinceLastConsolidateBlocks(0) + #endif +{ + #ifdef ADOLC_LOCDEBUG + std::cerr << "StoreManagerLocintBlock::StoreManagerLocintBlock()\n"; + #endif + indexFree.clear(); + std::forward_list::const_iterator iter = + stm->indexFree.begin(); + for (; iter != stm->indexFree.end(); iter++) + indexFree.emplace_front(*iter); } #endif -StoreManagerLocintBlock::StoreManagerLocintBlock(double * &storePtr, size_t &size, size_t &numlives) : - storePtr(storePtr), +StoreManagerLocintBlock::StoreManagerLocintBlock(double *&storePtr, + size_t &size, size_t &numlives) + : storePtr(storePtr), #if defined(ADOLC_TRACK_ACTIVITY) - activityTracking(0), - actStorePtr(const_cast(nowhere)), + activityTracking(0), actStorePtr(const_cast(nowhere)), #endif - maxsize(size), - currentfill(numlives) + maxsize(size), currentfill(numlives) #ifdef ADOLC_LOCDEBUG - ,ensure_blockCallsSinceLastConsolidateBlocks(0) + , + ensure_blockCallsSinceLastConsolidateBlocks(0) #endif - { - indexFree.clear(); +{ + indexFree.clear(); #ifdef ADOLC_LOCDEBUG - std::cerr << "StoreManagerLocintBlock::StoreManagerLocintBlock()\n"; + std::cerr << "StoreManagerLocintBlock::StoreManagerLocintBlock()\n"; #endif } -StoreManagerLocintBlock::~StoreManagerLocintBlock() -{ +StoreManagerLocintBlock::~StoreManagerLocintBlock() { #ifdef ADOLC_LOCDEBUG - std::cerr << "StoreManagerLocintBlock::~StoreManagerLocintBlock()\n"; + std::cerr << "StoreManagerLocintBlock::~StoreManagerLocintBlock()\n"; #endif - if (storePtr != NULL) { - delete[] storePtr; - storePtr = NULL; - } - if (!indexFree.empty() ) { - indexFree.clear(); - } + if (storePtr != NULL) { + delete[] storePtr; + storePtr = NULL; + } + if (!indexFree.empty()) { + indexFree.clear(); + } #if defined(ADOLC_TRACK_ACTIVITY) - if (activityTracking && actStorePtr) { - delete[] actStorePtr; - } + if (activityTracking && actStorePtr) { + delete[] actStorePtr; + } #endif - maxsize = 0; - currentfill = 0; + maxsize = 0; + currentfill = 0; } StoreManagerLocintBlock::StoreManagerLocintBlock( - const StoreManagerLocintBlock *const stm, - double * &storePtr, size_t &size, size_t &numlives) : - storePtr(storePtr), + const StoreManagerLocintBlock *const stm, double *&storePtr, size_t &size, + size_t &numlives) + : storePtr(storePtr), #if defined(ADOLC_TRACK_ACTIVITY) - activityTracking(0), - actStorePtr(const_cast(nowhere)), + activityTracking(0), actStorePtr(const_cast(nowhere)), #endif - maxsize(size), - currentfill(numlives) + maxsize(size), currentfill(numlives) #ifdef ADOLC_LOCDEBUG - ,ensure_blockCallsSinceLastConsolidateBlocks(0) + , + ensure_blockCallsSinceLastConsolidateBlocks(0) #endif - { +{ #ifdef ADOLC_LOCDEBUG - std::cerr << "StoreManagerLocintBlock::StoreManagerLocintBlock()\n"; + std::cerr << "StoreManagerLocintBlock::StoreManagerLocintBlock()\n"; #endif - indexFree.clear(); - std::forward_list::const_iterator iter = stm->indexFree.begin(); - for (; iter != stm->indexFree.end(); iter++) - indexFree.emplace_front( *iter ); + indexFree.clear(); + std::forward_list::const_iterator iter = + stm->indexFree.begin(); + for (; iter != stm->indexFree.end(); iter++) + indexFree.emplace_front(*iter); } - locint StoreManagerLocintBlock::next_loc() { - if ( indexFree.empty() ) - grow(); - - struct FreeBlock &front = indexFree.front(); - locint const result = front.next; - if (--front.size == 0) { - if (next(indexFree.cbegin()) == indexFree.cend()) { - front.next++; - grow(); - } else - indexFree.pop_front(); + if (indexFree.empty()) + grow(); + + struct FreeBlock &front = indexFree.front(); + locint const result = front.next; + if (--front.size == 0) { + if (next(indexFree.cbegin()) == indexFree.cend()) { + front.next++; + grow(); } else - front.next++; + indexFree.pop_front(); + } else + front.next++; - ++currentfill; + ++currentfill; #ifdef ADOLC_LOCDEBUG - std::cerr << "StoreManagerLocintBlock::next_loc: result: " << result << " fill: " << size() << "max: " << maxSize() << endl; - forward_list::iterator iter = indexFree.begin(); - for( ; iter != indexFree.end(); iter++ ) - std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl; + std::cerr << "StoreManagerLocintBlock::next_loc: result: " << result + << " fill: " << size() << "max: " << maxSize() << endl; + forward_list::iterator iter = indexFree.begin(); + for (; iter != indexFree.end(); iter++) + std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" + << endl; #endif - return result; + return result; } void StoreManagerLocintBlock::ensure_block(size_t n) { - bool found = false; + bool found = false; #ifdef ADOLC_LOCDEBUG - ++ensure_blockCallsSinceLastConsolidateBlocks; - std::cerr << "StoreManagerLocintBlock::ensure_block: required " << n << " ... "; - std::cerr << "searching for big enough block " << endl; -#endif - if (maxSize()-size()>n) { - if (indexFree.front().size>=n) found = true; - if ((!found) && ((double(maxSize())/double(size()))>gcTriggerRatio() || maxSize()>gcTriggerMaxSize())) { - consolidateBlocks(); + ++ensure_blockCallsSinceLastConsolidateBlocks; + std::cerr << "StoreManagerLocintBlock::ensure_block: required " << n + << " ... "; + std::cerr << "searching for big enough block " << endl; +#endif + if (maxSize() - size() > n) { + if (indexFree.front().size >= n) + found = true; + if ((!found) && ((double(maxSize()) / double(size())) > gcTriggerRatio() || + maxSize() > gcTriggerMaxSize())) { + consolidateBlocks(); #ifdef ADOLC_LOCDEBUG - std::cerr << "ADOLC: GC called consolidateBlocks because " << maxSize() << "/" << size() << ">" << gcTriggerRatio() << " or " << maxSize() << ">" << gcTriggerMaxSize() << " after " << ensure_blockCallsSinceLastConsolidateBlocks << std::endl; - ensure_blockCallsSinceLastConsolidateBlocks=0; -#endif - std::forward_list::iterator - biter = indexFree.before_begin(), - iter = indexFree.begin(); - for (; iter != indexFree.end() ; biter++, iter++ ) { - if ( iter->size >= n) { - if (iter != indexFree.begin() ) { - indexFree.emplace_front(*iter); - indexFree.erase_after(biter); - } - found = true; - break; + std::cerr << "ADOLC: GC called consolidateBlocks because " << maxSize() + << "/" << size() << ">" << gcTriggerRatio() << " or " + << maxSize() << ">" << gcTriggerMaxSize() << " after " + << ensure_blockCallsSinceLastConsolidateBlocks << std::endl; + ensure_blockCallsSinceLastConsolidateBlocks = 0; +#endif + std::forward_list::iterator biter = indexFree + .before_begin(), + iter = indexFree.begin(); + for (; iter != indexFree.end(); biter++, iter++) { + if (iter->size >= n) { + if (iter != indexFree.begin()) { + indexFree.emplace_front(*iter); + indexFree.erase_after(biter); } + found = true; + break; } } } - if (!found) { + } + if (!found) { #ifdef ADOLC_LOCDEBUG - std::cerr << "no big enough block...growing " << endl; + std::cerr << "no big enough block...growing " << endl; #endif - grow(n); - } + grow(n); + } #ifdef ADOLC_LOCDEBUG - std::cerr << "StoreManagerLocintBlock::ensure_Block: " << " fill: " << size() << "max: " << maxSize() << " ensure_Block (" << n << ")" << endl; - forward_list::iterator iter = indexFree.begin(); - for( ; iter != indexFree.end(); iter++ ) - std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl; + std::cerr << "StoreManagerLocintBlock::ensure_Block: " << " fill: " << size() + << "max: " << maxSize() << " ensure_Block (" << n << ")" << endl; + forward_list::iterator iter = indexFree.begin(); + for (; iter != indexFree.end(); iter++) + std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" + << endl; #endif } void StoreManagerLocintBlock::grow(size_t minGrow) { - // first figure out what eventual size we want - size_t const oldMaxsize = maxsize; + // first figure out what eventual size we want + size_t const oldMaxsize = maxsize; - if (maxsize == 0){ - maxsize = initialSize; - } else { - maxsize *= 2; - } + if (maxsize == 0) { + maxsize = initialSize; + } else { + maxsize *= 2; + } - if (minGrow > 0) { - while (maxsize - oldMaxsize < minGrow) { - maxsize *= 2; - } + if (minGrow > 0) { + while (maxsize - oldMaxsize < minGrow) { + maxsize *= 2; } + } - if (maxsize > std::numeric_limits::max()) { - // encapsulate this error message - fprintf(DIAG_OUT,"\nADOL-C error:\n"); - fprintf(DIAG_OUT,"maximal number (%u) of live active variables exceeded\n\n", - std::numeric_limits::max()); - adolc_exit(-3,"",__func__,__FILE__,__LINE__); - } + if (maxsize > std::numeric_limits::max()) { + // encapsulate this error message + fprintf(DIAG_OUT, "\nADOL-C error:\n"); + fprintf(DIAG_OUT, + "maximal number (%u) of live active variables exceeded\n\n", + std::numeric_limits::max()); + adolc_exit(-3, "", __func__, __FILE__, __LINE__); + } #ifdef ADOLC_LOCDEBUG - // index 0 is not used, means one slot less - std::cerr << "StoreManagerLocintBlock::grow(): increase size from " << oldMaxsize - << " to " << maxsize << " entries (currently " << size() << " entries used)\n"; + // index 0 is not used, means one slot less + std::cerr << "StoreManagerLocintBlock::grow(): increase size from " + << oldMaxsize << " to " << maxsize << " entries (currently " + << size() << " entries used)\n"; #endif - double *const oldStore = storePtr; + double *const oldStore = storePtr; #if defined(ADOLC_TRACK_ACTIVITY) - char * oldactStore; - if (activityTracking) - oldactStore = actStorePtr; + char *oldactStore; + if (activityTracking) + oldactStore = actStorePtr; #endif #if defined(ADOLC_LOCDEBUG) - std::cerr << "StoreManagerLocintBlock::grow(): allocate " << maxsize * sizeof(double) << " B doubles\n"; + std::cerr << "StoreManagerLocintBlock::grow(): allocate " + << maxsize * sizeof(double) << " B doubles\n"; #endif - storePtr = new double[maxsize]; - assert(storePtr); - memset(storePtr, 0, maxsize*sizeof(double)); + storePtr = new double[maxsize]; + assert(storePtr); + memset(storePtr, 0, maxsize * sizeof(double)); #if defined(ADOLC_TRACK_ACTIVITY) - if (activityTracking) { - actStorePtr = new char[maxsize]; - memset(actStorePtr,0,maxsize*sizeof(char)); - } + if (activityTracking) { + actStorePtr = new char[maxsize]; + memset(actStorePtr, 0, maxsize * sizeof(char)); + } #endif - if (oldStore != NULL) { // not the first time + if (oldStore != NULL) { // not the first time #if defined(ADOLC_LOCDEBUG) - std::cerr << "StoreManagerLocintBlock::grow(): copy values\n"; + std::cerr << "StoreManagerLocintBlock::grow(): copy values\n"; #endif - memcpy(storePtr, oldStore, oldMaxsize*sizeof(double)); + memcpy(storePtr, oldStore, oldMaxsize * sizeof(double)); #if defined(ADOLC_TRACK_ACTIVITY) - if (activityTracking) { - memcpy(actStorePtr, oldactStore, oldMaxsize*sizeof(char)); - } + if (activityTracking) { + memcpy(actStorePtr, oldactStore, oldMaxsize * sizeof(char)); + } #endif #if defined(ADOLC_LOCDEBUG) - std::cerr << "StoreManagerLocintBlock::grow(): free " << oldMaxsize * sizeof(double) << "\n"; + std::cerr << "StoreManagerLocintBlock::grow(): free " + << oldMaxsize * sizeof(double) << "\n"; #endif - delete [] oldStore; + delete[] oldStore; #if defined(ADOLC_TRACK_ACTIVITY) - if (activityTracking) { - delete[] oldactStore; - } -#endif - + if (activityTracking) { + delete[] oldactStore; } - - bool foundTail = false; - std::forward_list::iterator - biter = indexFree.before_begin(), - iter = indexFree.begin(); - for (; iter != indexFree.end() ; biter++,iter++ ) { - if (iter->next + iter->size == oldMaxsize ) { - iter->size += (maxsize - oldMaxsize); - indexFree.emplace_front(*iter); - indexFree.erase_after(biter); - foundTail = true; - break; - } +#endif + } + + bool foundTail = false; + std::forward_list::iterator biter = + indexFree.before_begin(), + iter = indexFree.begin(); + for (; iter != indexFree.end(); biter++, iter++) { + if (iter->next + iter->size == oldMaxsize) { + iter->size += (maxsize - oldMaxsize); + indexFree.emplace_front(*iter); + indexFree.erase_after(biter); + foundTail = true; + break; } + } - if (! foundTail) { - indexFree.emplace_front( + if (!foundTail) { + indexFree.emplace_front( #if defined(_MSC_VER) && _MSC_VER <= 1800 - FreeBlock( + FreeBlock( #endif - oldMaxsize,(maxsize - oldMaxsize) + oldMaxsize, (maxsize - oldMaxsize) #if defined(_MSC_VER) && _MSC_VER <= 1800 - ) + ) #endif - ); - } + ); + } - biter = indexFree.before_begin(); - iter = indexFree.begin(); - while (iter != indexFree.end()) { - if (iter->size == 0) { - indexFree.erase_after(biter); // don't leave 0 blocks around - iter = next(biter); - } - else { - biter++; - iter++; - } + biter = indexFree.before_begin(); + iter = indexFree.begin(); + while (iter != indexFree.end()) { + if (iter->size == 0) { + indexFree.erase_after(biter); // don't leave 0 blocks around + iter = next(biter); + } else { + biter++; + iter++; } + } #ifdef ADOLC_LOCDEBUG - std::cerr << "Growing:" << endl; - iter = indexFree.begin(); - for( ; iter != indexFree.end(); iter++ ) - std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl; + std::cerr << "Growing:" << endl; + iter = indexFree.begin(); + for (; iter != indexFree.end(); iter++) + std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" + << endl; #endif } void StoreManagerLocintBlock::free_loc(locint loc) { - assert( loc < maxsize); - - struct FreeBlock &front = indexFree.front(); - if ((loc+1 == front.next) - || (front.next + front.size == loc)) { - front.size++; - if (loc + 1 == front.next) - front.next = loc; - } - else { - indexFree.emplace_front( + assert(loc < maxsize); + + struct FreeBlock &front = indexFree.front(); + if ((loc + 1 == front.next) || (front.next + front.size == loc)) { + front.size++; + if (loc + 1 == front.next) + front.next = loc; + } else { + indexFree.emplace_front( #if defined(_MSC_VER) && _MSC_VER <= 1800 - FreeBlock( + FreeBlock( #endif - loc,1 + loc, 1 #if defined(_MSC_VER) && _MSC_VER <= 1800 - ) + ) #endif - ); - } + ); + } - --currentfill; + --currentfill; #ifdef ADOLC_LOCDEBUG - std::cerr << "free_loc: " << loc << " fill: " << size() << "max: " << maxSize() << endl; - forward_list::iterator iter = indexFree.begin(); - for( ; iter != indexFree.end(); iter++ ) - std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl; + std::cerr << "free_loc: " << loc << " fill: " << size() + << "max: " << maxSize() << endl; + forward_list::iterator iter = indexFree.begin(); + for (; iter != indexFree.end(); iter++) + std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" + << endl; #endif } void ensureContiguousLocations(size_t n) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr->ensure_block(n); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr->ensure_block(n); } void setStoreManagerControl(double gcTriggerRatio, size_t gcTriggerMaxSize) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr->setStoreManagerControl(gcTriggerRatio,gcTriggerMaxSize); + ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr->setStoreManagerControl( + gcTriggerRatio, gcTriggerMaxSize); } void StoreManagerLocintBlock::consolidateBlocks() { - indexFree.sort(); - std::forward_list::iterator - iter = indexFree.begin(), - niter = iter++; - while (iter != indexFree.end()) { - if (niter->next + niter->size == iter->next) { - niter->size += iter->size; - indexFree.erase_after(niter); - iter = next(niter); - } else { - niter++; - iter++; - } + indexFree.sort(); + std::forward_list::iterator iter = indexFree.begin(), + niter = iter++; + while (iter != indexFree.end()) { + if (niter->next + niter->size == iter->next) { + niter->size += iter->size; + indexFree.erase_after(niter); + iter = next(niter); + } else { + niter++; + iter++; } + } #ifdef ADOLC_LOCDEBUG - std::cerr << "StoreManagerLocintBlock::consolidateBlocks: " << " fill: " << size() << "max: " << maxSize() << endl; - iter = indexFree.begin(); - for( ; iter != indexFree.end(); iter++ ) - std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" << endl; + std::cerr << "StoreManagerLocintBlock::consolidateBlocks: " << " fill: " + << size() << "max: " << maxSize() << endl; + iter = indexFree.begin(); + for (; iter != indexFree.end(); iter++) + std::cerr << "INDEXFELD ( " << iter->next << " , " << iter->size << ")" + << endl; #endif } void setStoreManagerType(unsigned char type) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr->storeType() != type) { - if (ADOLC_GLOBAL_TAPE_VARS.numLives == 0) { - ADOLC_GLOBAL_TAPE_VARS.reallocStore(type); - } else { - fprintf(DIAG_OUT,"ADOL-C-warning: called %s after allocating %ld active variables\n" - "*** WILL NOT CHANGE ***\nto change type deallocate all active variables\n" - "continuing ...\n" - , __func__, ADOLC_GLOBAL_TAPE_VARS.numLives); - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr->storeType() != type) { + if (ADOLC_GLOBAL_TAPE_VARS.numLives == 0) { + ADOLC_GLOBAL_TAPE_VARS.reallocStore(type); } else { - fprintf(DIAG_OUT,"ADOL-C-warning: called %s with same type as before\n" - "*** NO CHANGE ***\ncontinuing ...\n",__func__); + fprintf( + DIAG_OUT, + "ADOL-C-warning: called %s after allocating %ld active variables\n" + "*** WILL NOT CHANGE ***\nto change type deallocate all active " + "variables\n" + "continuing ...\n", + __func__, ADOLC_GLOBAL_TAPE_VARS.numLives); } + } else { + fprintf(DIAG_OUT, + "ADOL-C-warning: called %s with same type as before\n" + "*** NO CHANGE ***\ncontinuing ...\n", + __func__); + } } diff --git a/ADOL-C/src/storemanager.h b/ADOL-C/src/storemanager.h index 54374f7b9..42d3aeca5 100644 --- a/ADOL-C/src/storemanager.h +++ b/ADOL-C/src/storemanager.h @@ -1,9 +1,9 @@ // -*- c++ -*- hello emacs... -/*---------------------------------------------------------------------------- +/*---------------------------------------------------------------------------- ADOL-C-- Automatic Differentiation by Overloading in C++ - simplified File: storemanager.h Revision: $Id$ - Contents: storemanager.h contains definitions of abstract interface + Contents: storemanager.h contains definitions of abstract interface class StoreManager and some derived classes implementing the desired functionality. @@ -14,7 +14,7 @@ This file is part of ADOL-C. - The classes StoreManagerXYZ basically takes the global double *store pointer + The classes StoreManagerXYZ basically takes the global double *store pointer into their obhut and implement next_loc and free_loc. They basic idea is taken from "The C++ Programming Language" by Bjarne @@ -30,7 +30,7 @@ old array into the lower half of the new one (we always double the size). 2) Have a look at StoreManagerLocint and convince yourself that these do - the same as StoreManagerInSitu except that the linked list of free + the same as StoreManagerInSitu except that the linked list of free slots is maintained in a completely different portion of memory. This means the values in freed slots remain untouched until they are allocated again. @@ -41,10 +41,10 @@ class StoreManagerInSitu An unsafe implementation is provided as well, but commented out. - It does not use the indexFeld array which saves between + It does not use the indexFeld array which saves between 25% and 50% memory relative to the above safe implementation. - It is most closely modelled after the example found in the + It is most closely modelled after the example found in the Stroustrup book. It appears that it works very well, if one does not use the @@ -52,7 +52,7 @@ If the first sweep is forward it works fine. Therefore I left it in here as a comment so an interested user with acute main memory scarcity may give it a try. - + History: 20120427 bl: add blocking store management @@ -65,139 +65,153 @@ #define ADOL_C__STOREMANAGER_H #if defined(ADOLC_INTERNAL) -# if HAVE_CONFIG_H -# include "config.h" -# endif + #if HAVE_CONFIG_H + #include "config.h" + #endif #endif #include #include -#if USE_BOOST_POOL -#include +#if USE_BOOST_POOL + #include #endif #include #include class GlobalTapeVarsCL; -extern "C" void checkInitialStoreSize(GlobalTapeVarsCL* gtv); +extern "C" void checkInitialStoreSize(GlobalTapeVarsCL *gtv); class StoreManager { - friend void checkInitialStoreSize(GlobalTapeVarsCL* gtv); + friend void checkInitialStoreSize(GlobalTapeVarsCL *gtv); + protected: static size_t const initialSize = 4; double myGcTriggerRatio; size_t myGcTriggerMaxSize; virtual void grow(size_t mingrow = 0) = 0; + public: StoreManager() : myGcTriggerRatio(1.5), myGcTriggerMaxSize(initialSize) {} virtual ~StoreManager() {} virtual locint next_loc() = 0; virtual void free_loc(locint) = 0; virtual void ensure_block(size_t n) = 0; - void setStoreManagerControl(double gcTriggerRatio, size_t gcTriggerMaxSize) { myGcTriggerRatio=gcTriggerRatio; myGcTriggerMaxSize=gcTriggerMaxSize;} - double gcTriggerRatio() const {return myGcTriggerRatio;} - size_t gcTriggerMaxSize() const {return myGcTriggerMaxSize;} -// // effectively the current size of the store array + void setStoreManagerControl(double gcTriggerRatio, size_t gcTriggerMaxSize) { + myGcTriggerRatio = gcTriggerRatio; + myGcTriggerMaxSize = gcTriggerMaxSize; + } + double gcTriggerRatio() const { return myGcTriggerRatio; } + size_t gcTriggerMaxSize() const { return myGcTriggerMaxSize; } + // // effectively the current size of the store array virtual size_t maxSize() const = 0; -// // the number of slots currently in use + // // the number of slots currently in use virtual size_t size() const = 0; virtual unsigned char storeType() const = 0; }; class StoreManagerLocint : public StoreManager { protected: - double * &storePtr; + double *&storePtr; #if defined(ADOLC_TRACK_ACTIVITY) char activityTracking; - static char const* const nowhere; - char * &actStorePtr; + static char const *const nowhere; + char *&actStorePtr; #endif - locint * indexFree; + locint *indexFree; locint head; size_t &maxsize; size_t ¤tfill; virtual void grow(size_t mingrow = 0); -public: +public: #if defined(ADOLC_TRACK_ACTIVITY) - StoreManagerLocint(double * &storePtr, char* &actStorePtr, size_t &size, size_t &numlives); - StoreManagerLocint(const StoreManagerLocint *const stm, double * &storePtr, char* &actStorePtr, size_t &size, size_t &numLives); + StoreManagerLocint(double *&storePtr, char *&actStorePtr, size_t &size, + size_t &numlives); + StoreManagerLocint(const StoreManagerLocint *const stm, double *&storePtr, + char *&actStorePtr, size_t &size, size_t &numLives); #endif - StoreManagerLocint(double * &storePtr, size_t &size, size_t &numlives); - StoreManagerLocint(const StoreManagerLocint *const stm, double * &storePtr, size_t &size, size_t &numLives); + StoreManagerLocint(double *&storePtr, size_t &size, size_t &numlives); + StoreManagerLocint(const StoreManagerLocint *const stm, double *&storePtr, + size_t &size, size_t &numLives); virtual ~StoreManagerLocint(); virtual inline size_t size() const { return currentfill; } virtual inline size_t maxSize() const { return maxsize; } - virtual inline unsigned char storeType() const { return ADOLC_LOCATION_SINGLETONS; } - - virtual inline bool realloc_on_next_loc() const { - return (head == 0); + virtual inline unsigned char storeType() const { + return ADOLC_LOCATION_SINGLETONS; } + virtual inline bool realloc_on_next_loc() const { return (head == 0); } + virtual locint next_loc(); - virtual void free_loc(locint loc); + virtual void free_loc(locint loc); virtual void ensure_block(size_t n); }; class StoreManagerLocintBlock : public StoreManager { protected: - double * &storePtr; + double *&storePtr; #if defined(ADOLC_TRACK_ACTIVITY) - char activityTracking; - static char const* const nowhere; - char * &actStorePtr; + char activityTracking; + static char const *const nowhere; + char *&actStorePtr; #endif - struct FreeBlock { - locint next; // next location - size_t size; // number of following free locations - FreeBlock(): next(0), size(0) {} - FreeBlock(const struct FreeBlock &block) : - next(block.next),size(block.size) {} - FreeBlock(const locint& n, const size_t& s) : - next(n), size(s) {} - bool operator<(const struct FreeBlock& b) const { - return (next < b.next); - } - }; - - std::forward_list -#endif - > indexFree; - size_t &maxsize; - size_t ¤tfill; + , + boost::fast_pool_allocator +#endif + > + indexFree; + size_t &maxsize; + size_t ¤tfill; - void consolidateBlocks(); + void consolidateBlocks(); #ifdef ADOLC_LOCDEBUG - unsigned int ensure_blockCallsSinceLastConsolidateBlocks; + unsigned int ensure_blockCallsSinceLastConsolidateBlocks; #endif - /** - * when minGrow is specified we asssume that we have already - * search the blocks and found no block with minGrow locations in it - */ - virtual void grow(size_t minGrow=0 ); + /** + * when minGrow is specified we asssume that we have already + * search the blocks and found no block with minGrow locations in it + */ + virtual void grow(size_t minGrow = 0); + public: #if defined(ADOLC_TRACK_ACTIVITY) - StoreManagerLocintBlock(double * &storePtr, char* &actStorePtr, size_t &size, size_t &numlives); - StoreManagerLocintBlock(const StoreManagerLocintBlock *const stm, double * &storePtr, char* &actStorePtr, size_t &size, size_t &numLives); + StoreManagerLocintBlock(double *&storePtr, char *&actStorePtr, size_t &size, + size_t &numlives); + StoreManagerLocintBlock(const StoreManagerLocintBlock *const stm, + double *&storePtr, char *&actStorePtr, size_t &size, + size_t &numLives); #endif - StoreManagerLocintBlock(double * &storePtr, size_t &size, size_t &numlives); - StoreManagerLocintBlock(const StoreManagerLocintBlock *const stm, double * &storePtr, size_t &size, size_t &numLives); + StoreManagerLocintBlock(double *&storePtr, size_t &size, size_t &numlives); + StoreManagerLocintBlock(const StoreManagerLocintBlock *const stm, + double *&storePtr, size_t &size, size_t &numLives); - virtual ~StoreManagerLocintBlock(); - virtual inline size_t size() const { return currentfill; } + virtual ~StoreManagerLocintBlock(); + virtual inline size_t size() const { return currentfill; } - virtual inline size_t maxSize() const { return maxsize; } - virtual inline unsigned char storeType() const { return ADOLC_LOCATION_BLOCKS; } + virtual inline size_t maxSize() const { return maxsize; } + virtual inline unsigned char storeType() const { + return ADOLC_LOCATION_BLOCKS; + } - virtual locint next_loc(); - virtual void free_loc(locint loc); - virtual void ensure_block(size_t n); + virtual locint next_loc(); + virtual void free_loc(locint loc); + virtual void ensure_block(size_t n); }; #if 0 @@ -299,4 +313,3 @@ class StoreManagerInSitu : public StoreManager { #endif /* 0 */ #endif /* ADOL_C__STOREMANAGER_H */ - diff --git a/ADOL-C/src/tape_handling.cpp b/ADOL-C/src/tape_handling.cpp index e885f7123..161be0077 100644 --- a/ADOL-C/src/tape_handling.cpp +++ b/ADOL-C/src/tape_handling.cpp @@ -8,39 +8,40 @@ Benjamin Letschert, Jean Utke This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ -#include "taping_p.h" #include "checkpointing_p.h" #include "dvlparms.h" -#include +#include "taping_p.h" #include +#include #ifdef ADOLC_MEDIPACK_SUPPORT -#include "medipacksupport_p.h" + #include "medipacksupport_p.h" #endif #include -#include #include +#include #ifdef HAVE_UNISTD_H -#include + #include #endif -#include -#include #include +#include +#include using namespace std; #ifdef SPARSE BEGIN_C_DECLS -extern void freeSparseJacInfos(double *y, double **B, unsigned int **JP, void *g, - void *jr1d, int seed_rows, int seed_clms, int depen); -extern void freeSparseHessInfos(double **Hcomp, double ***Xppp, double ***Yppp, double ***Zppp, - double **Upp, unsigned int **HP, - void *g, void *hr, int p, int indep); +extern void freeSparseJacInfos(double *y, double **B, unsigned int **JP, + void *g, void *jr1d, int seed_rows, + int seed_clms, int depen); +extern void freeSparseHessInfos(double **Hcomp, double ***Xppp, double ***Yppp, + double ***Zppp, double **Upp, unsigned int **HP, + void *g, void *hr, int p, int indep); END_C_DECLS #endif @@ -57,7 +58,8 @@ GlobalTapeVarsCL::GlobalTapeVarsCL() { maxparam = 0; initialStoreSize = 0; #if defined(ADOLC_TRACK_ACTIVITY) - storeManagerPtr = new StoreManagerLocintBlock(store, actStore, storeSize, numLives); + storeManagerPtr = + new StoreManagerLocintBlock(store, actStore, storeSize, numLives); #else storeManagerPtr = new StoreManagerLocintBlock(store, storeSize, numLives); #endif @@ -70,47 +72,44 @@ GlobalTapeVarsCL::~GlobalTapeVarsCL() { storeManagerPtr = NULL; } if (paramStoreMgrPtr != NULL) { - delete paramStoreMgrPtr; - paramStoreMgrPtr = NULL; + delete paramStoreMgrPtr; + paramStoreMgrPtr = NULL; } } -const GlobalTapeVarsCL& GlobalTapeVarsCL::operator=(const GlobalTapeVarsCL& gtv) { - storeSize = gtv.storeSize; - numLives = gtv.numLives; - maxLoc = gtv.maxLoc; - operationBufferSize = gtv.operationBufferSize; - locationBufferSize = gtv.locationBufferSize; - valueBufferSize = gtv.valueBufferSize; - taylorBufferSize = gtv.taylorBufferSize; - maxNumberTaylorBuffers = gtv.maxNumberTaylorBuffers; - inParallelRegion = gtv.inParallelRegion; - newTape = gtv.newTape; - branchSwitchWarning = gtv.branchSwitchWarning; - currentTapeInfosPtr = gtv.currentTapeInfosPtr; - initialStoreSize = gtv.initialStoreSize; - store = new double[storeSize]; - memcpy(store, gtv.store, storeSize*sizeof(double)); +const GlobalTapeVarsCL & +GlobalTapeVarsCL::operator=(const GlobalTapeVarsCL >v) { + storeSize = gtv.storeSize; + numLives = gtv.numLives; + maxLoc = gtv.maxLoc; + operationBufferSize = gtv.operationBufferSize; + locationBufferSize = gtv.locationBufferSize; + valueBufferSize = gtv.valueBufferSize; + taylorBufferSize = gtv.taylorBufferSize; + maxNumberTaylorBuffers = gtv.maxNumberTaylorBuffers; + inParallelRegion = gtv.inParallelRegion; + newTape = gtv.newTape; + branchSwitchWarning = gtv.branchSwitchWarning; + currentTapeInfosPtr = gtv.currentTapeInfosPtr; + initialStoreSize = gtv.initialStoreSize; + store = new double[storeSize]; + memcpy(store, gtv.store, storeSize * sizeof(double)); #if defined(ADOLC_TRACK_ACTIVITY) - actStore = new char[storeSize]; - memcpy(actStore, gtv.actStore, storeSize*sizeof(char)); + actStore = new char[storeSize]; + memcpy(actStore, gtv.actStore, storeSize * sizeof(char)); #endif - storeManagerPtr = new - StoreManagerLocintBlock( - dynamic_cast(gtv.storeManagerPtr), - store, + storeManagerPtr = new StoreManagerLocintBlock( + dynamic_cast(gtv.storeManagerPtr), store, #if defined(ADOLC_TRACK_ACTIVITY) - actStore, + actStore, #endif - storeSize, numLives); - paramStoreMgrPtr = new - StoreManagerLocintBlock( - dynamic_cast(gtv.paramStoreMgrPtr), - pStore, maxparam, numparam); - return *this; + storeSize, numLives); + paramStoreMgrPtr = new StoreManagerLocintBlock( + dynamic_cast(gtv.paramStoreMgrPtr), pStore, + maxparam, numparam); + return *this; } - /* vector of tape infos for all tapes in use */ vector ADOLC_TAPE_INFOS_BUFFER_DECL; @@ -127,22 +126,22 @@ GlobalTapeVars ADOLC_GLOBAL_TAPE_VARS_DECL; #if defined(_OPENMP) static vector *tapeInfosBuffer_s; -static stack *tapeStack_s; -static TapeInfos *currentTapeInfos_s; -static TapeInfos *currentTapeInfos_fallBack_s; -static GlobalTapeVars *globalTapeVars_s; -static ADOLC_BUFFER_TYPE *ADOLC_extDiffFctsBuffer_s; +static stack *tapeStack_s; +static TapeInfos *currentTapeInfos_s; +static TapeInfos *currentTapeInfos_fallBack_s; +static GlobalTapeVars *globalTapeVars_s; +static ADOLC_BUFFER_TYPE *ADOLC_extDiffFctsBuffer_s; static stack *ADOLC_checkpointsStack_s; -static revolve_nums *revolve_numbers_s; +static revolve_nums *revolve_numbers_s; static vector *tapeInfosBuffer_p; -static stack *tapeStack_p; -static TapeInfos *currentTapeInfos_p; -static TapeInfos *currentTapeInfos_fallBack_p; -static GlobalTapeVars *globalTapeVars_p; -static ADOLC_BUFFER_TYPE *ADOLC_extDiffFctsBuffer_p; +static stack *tapeStack_p; +static TapeInfos *currentTapeInfos_p; +static TapeInfos *currentTapeInfos_fallBack_p; +static GlobalTapeVars *globalTapeVars_p; +static ADOLC_BUFFER_TYPE *ADOLC_extDiffFctsBuffer_p; static stack *ADOLC_checkpointsStack_p; -static revolve_nums *revolve_numbers_p; +static revolve_nums *revolve_numbers_p; #endif /*--------------------------------------------------------------------------*/ @@ -152,653 +151,619 @@ static revolve_nums *revolve_numbers_p; /* the binary when linking statically! */ /*--------------------------------------------------------------------------*/ void markNewTape() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - ADOLC_GLOBAL_TAPE_VARS.newTape = 1; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_GLOBAL_TAPE_VARS.newTape = 1; } /* inits the struct for the new tape */ void initTapeInfos(TapeInfos *newTapeInfos) { - char *ptr, *end; + char *ptr, *end; - ptr = (char *)(&newTapeInfos->tapeID); - end = (char *)(&newTapeInfos->pTapeInfos); - for ( ; ptr != end ; ptr++ ) - *ptr = 0; + ptr = (char *)(&newTapeInfos->tapeID); + end = (char *)(&newTapeInfos->pTapeInfos); + for (; ptr != end; ptr++) + *ptr = 0; } /* as above but keep allocated buffers if possible */ void initTapeInfos_keep(TapeInfos *newTapeInfos) { - unsigned char *opBuffer = newTapeInfos->opBuffer; - locint *locBuffer = newTapeInfos->locBuffer; - double *valBuffer = newTapeInfos->valBuffer; - revreal *tayBuffer = newTapeInfos->tayBuffer; - double *signature = newTapeInfos->signature; - FILE *tay_file = newTapeInfos->tay_file; - - initTapeInfos(newTapeInfos); - - newTapeInfos->opBuffer = opBuffer; - newTapeInfos->locBuffer = locBuffer; - newTapeInfos->valBuffer = valBuffer; - newTapeInfos->tayBuffer = tayBuffer; - newTapeInfos->signature = signature; - newTapeInfos->tay_file = tay_file; + unsigned char *opBuffer = newTapeInfos->opBuffer; + locint *locBuffer = newTapeInfos->locBuffer; + double *valBuffer = newTapeInfos->valBuffer; + revreal *tayBuffer = newTapeInfos->tayBuffer; + double *signature = newTapeInfos->signature; + FILE *tay_file = newTapeInfos->tay_file; + + initTapeInfos(newTapeInfos); + + newTapeInfos->opBuffer = opBuffer; + newTapeInfos->locBuffer = locBuffer; + newTapeInfos->valBuffer = valBuffer; + newTapeInfos->tayBuffer = tayBuffer; + newTapeInfos->signature = signature; + newTapeInfos->tay_file = tay_file; } /* inits a new tape and updates the tape stack (called from start_trace) * - returns 0 without error * - returns 1 if tapeID was already/still in use */ int initNewTape(short tapeID) { - TapeInfos *newTapeInfos = NULL; - bool newTI = false; - int retval = 0; - - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* check if tape is in use */ - vector::iterator tiIter = std::find_if(ADOLC_TAPE_INFOS_BUFFER.begin(), - ADOLC_TAPE_INFOS_BUFFER.end(), - [&tapeID](auto&& ti){return ti->tapeID == tapeID;}); - - if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { - newTapeInfos=*tiIter; - if ((*tiIter)->inUse != 0) { - if ((*tiIter)->tapingComplete == 0) - fail(ADOLC_TAPING_TAPE_STILL_IN_USE); - if ( (*tiIter)->stats[OP_FILE_ACCESS] == 0 && - (*tiIter)->stats[LOC_FILE_ACCESS] == 0 && - (*tiIter)->stats[VAL_FILE_ACCESS] == 0 ) { -# if defined(ADOLC_DEBUG) - fprintf(DIAG_OUT, "\nADOL-C warning: Tape %d existed in main memory" - " only and gets overwritten!\n\n", tapeID); -# endif - /* free associated resources */ - retval = 1; - } - } - if ((*tiIter)->tay_file != NULL) - rewind((*tiIter)->tay_file); - initTapeInfos_keep(*tiIter); - (*tiIter)->tapeID = tapeID; -#ifdef SPARSE - freeSparseJacInfos(newTapeInfos->pTapeInfos.sJinfos.y, - newTapeInfos->pTapeInfos.sJinfos.B, - newTapeInfos->pTapeInfos.sJinfos.JP, - newTapeInfos->pTapeInfos.sJinfos.g, - newTapeInfos->pTapeInfos.sJinfos.jr1d, - newTapeInfos->pTapeInfos.sJinfos.seed_rows, - newTapeInfos->pTapeInfos.sJinfos.seed_clms, - newTapeInfos->pTapeInfos.sJinfos.depen); - freeSparseHessInfos(newTapeInfos->pTapeInfos.sHinfos.Hcomp, - newTapeInfos->pTapeInfos.sHinfos.Xppp, - newTapeInfos->pTapeInfos.sHinfos.Yppp, - newTapeInfos->pTapeInfos.sHinfos.Zppp, - newTapeInfos->pTapeInfos.sHinfos.Upp, - newTapeInfos->pTapeInfos.sHinfos.HP, - newTapeInfos->pTapeInfos.sHinfos.g, - newTapeInfos->pTapeInfos.sHinfos.hr, - newTapeInfos->pTapeInfos.sHinfos.p, - newTapeInfos->pTapeInfos.sHinfos.indep); - newTapeInfos->pTapeInfos.sJinfos.B=NULL; - newTapeInfos->pTapeInfos.sJinfos.y=NULL; - newTapeInfos->pTapeInfos.sJinfos.g=NULL; - newTapeInfos->pTapeInfos.sJinfos.jr1d=NULL; - newTapeInfos->pTapeInfos.sJinfos.Seed=NULL; - newTapeInfos->pTapeInfos.sJinfos.JP=NULL; - newTapeInfos->pTapeInfos.sJinfos.depen=0; - newTapeInfos->pTapeInfos.sJinfos.nnz_in=0; - newTapeInfos->pTapeInfos.sJinfos.seed_rows=0; - newTapeInfos->pTapeInfos.sJinfos.seed_clms=0; - newTapeInfos->pTapeInfos.sHinfos.Zppp=NULL; - newTapeInfos->pTapeInfos.sHinfos.Yppp=NULL; - newTapeInfos->pTapeInfos.sHinfos.Xppp=NULL; - newTapeInfos->pTapeInfos.sHinfos.Upp=NULL; - newTapeInfos->pTapeInfos.sHinfos.Hcomp=NULL; - newTapeInfos->pTapeInfos.sHinfos.HP=NULL; - newTapeInfos->pTapeInfos.sHinfos.g=NULL; - newTapeInfos->pTapeInfos.sHinfos.hr=NULL; - newTapeInfos->pTapeInfos.sHinfos.nnz_in=0; - newTapeInfos->pTapeInfos.sHinfos.indep=0; - newTapeInfos->pTapeInfos.sHinfos.p=0; + TapeInfos *newTapeInfos = NULL; + bool newTI = false; + int retval = 0; + + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* check if tape is in use */ + vector::iterator tiIter = std::find_if( + ADOLC_TAPE_INFOS_BUFFER.begin(), ADOLC_TAPE_INFOS_BUFFER.end(), + [&tapeID](auto &&ti) { return ti->tapeID == tapeID; }); + + if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { + newTapeInfos = *tiIter; + if ((*tiIter)->inUse != 0) { + if ((*tiIter)->tapingComplete == 0) + fail(ADOLC_TAPING_TAPE_STILL_IN_USE); + if ((*tiIter)->stats[OP_FILE_ACCESS] == 0 && + (*tiIter)->stats[LOC_FILE_ACCESS] == 0 && + (*tiIter)->stats[VAL_FILE_ACCESS] == 0) { +#if defined(ADOLC_DEBUG) + fprintf(DIAG_OUT, + "\nADOL-C warning: Tape %d existed in main memory" + " only and gets overwritten!\n\n", + tapeID); #endif + /* free associated resources */ + retval = 1; + } } + if ((*tiIter)->tay_file != NULL) + rewind((*tiIter)->tay_file); + initTapeInfos_keep(*tiIter); + (*tiIter)->tapeID = tapeID; +#ifdef SPARSE + freeSparseJacInfos( + newTapeInfos->pTapeInfos.sJinfos.y, newTapeInfos->pTapeInfos.sJinfos.B, + newTapeInfos->pTapeInfos.sJinfos.JP, newTapeInfos->pTapeInfos.sJinfos.g, + newTapeInfos->pTapeInfos.sJinfos.jr1d, + newTapeInfos->pTapeInfos.sJinfos.seed_rows, + newTapeInfos->pTapeInfos.sJinfos.seed_clms, + newTapeInfos->pTapeInfos.sJinfos.depen); + freeSparseHessInfos( + newTapeInfos->pTapeInfos.sHinfos.Hcomp, + newTapeInfos->pTapeInfos.sHinfos.Xppp, + newTapeInfos->pTapeInfos.sHinfos.Yppp, + newTapeInfos->pTapeInfos.sHinfos.Zppp, + newTapeInfos->pTapeInfos.sHinfos.Upp, + newTapeInfos->pTapeInfos.sHinfos.HP, newTapeInfos->pTapeInfos.sHinfos.g, + newTapeInfos->pTapeInfos.sHinfos.hr, newTapeInfos->pTapeInfos.sHinfos.p, + newTapeInfos->pTapeInfos.sHinfos.indep); + newTapeInfos->pTapeInfos.sJinfos.B = NULL; + newTapeInfos->pTapeInfos.sJinfos.y = NULL; + newTapeInfos->pTapeInfos.sJinfos.g = NULL; + newTapeInfos->pTapeInfos.sJinfos.jr1d = NULL; + newTapeInfos->pTapeInfos.sJinfos.Seed = NULL; + newTapeInfos->pTapeInfos.sJinfos.JP = NULL; + newTapeInfos->pTapeInfos.sJinfos.depen = 0; + newTapeInfos->pTapeInfos.sJinfos.nnz_in = 0; + newTapeInfos->pTapeInfos.sJinfos.seed_rows = 0; + newTapeInfos->pTapeInfos.sJinfos.seed_clms = 0; + newTapeInfos->pTapeInfos.sHinfos.Zppp = NULL; + newTapeInfos->pTapeInfos.sHinfos.Yppp = NULL; + newTapeInfos->pTapeInfos.sHinfos.Xppp = NULL; + newTapeInfos->pTapeInfos.sHinfos.Upp = NULL; + newTapeInfos->pTapeInfos.sHinfos.Hcomp = NULL; + newTapeInfos->pTapeInfos.sHinfos.HP = NULL; + newTapeInfos->pTapeInfos.sHinfos.g = NULL; + newTapeInfos->pTapeInfos.sHinfos.hr = NULL; + newTapeInfos->pTapeInfos.sHinfos.nnz_in = 0; + newTapeInfos->pTapeInfos.sHinfos.indep = 0; + newTapeInfos->pTapeInfos.sHinfos.p = 0; +#endif + } - /* create new info struct and initialize it */ - if (newTapeInfos == NULL) { - newTapeInfos = new TapeInfos(tapeID); - newTI = true; - } - newTapeInfos->traceFlag=1; - newTapeInfos->inUse=1; - - newTapeInfos->stats[OP_BUFFER_SIZE] = - ADOLC_GLOBAL_TAPE_VARS.operationBufferSize; - newTapeInfos->stats[LOC_BUFFER_SIZE] = - ADOLC_GLOBAL_TAPE_VARS.locationBufferSize; - newTapeInfos->stats[VAL_BUFFER_SIZE] = - ADOLC_GLOBAL_TAPE_VARS.valueBufferSize; - newTapeInfos->stats[TAY_BUFFER_SIZE] = - ADOLC_GLOBAL_TAPE_VARS.taylorBufferSize; - - /* update tapeStack and save tapeInfos */ - if (ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr != NULL) { - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr->copy( - ADOLC_CURRENT_TAPE_INFOS); - ADOLC_TAPE_STACK.push(ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr); - } else { - ADOLC_CURRENT_TAPE_INFOS_FALLBACK.copy( - ADOLC_CURRENT_TAPE_INFOS); - ADOLC_TAPE_STACK.push(&ADOLC_CURRENT_TAPE_INFOS_FALLBACK); - } - if (newTI) ADOLC_TAPE_INFOS_BUFFER.push_back(newTapeInfos); + /* create new info struct and initialize it */ + if (newTapeInfos == NULL) { + newTapeInfos = new TapeInfos(tapeID); + newTI = true; + } + newTapeInfos->traceFlag = 1; + newTapeInfos->inUse = 1; + + newTapeInfos->stats[OP_BUFFER_SIZE] = + ADOLC_GLOBAL_TAPE_VARS.operationBufferSize; + newTapeInfos->stats[LOC_BUFFER_SIZE] = + ADOLC_GLOBAL_TAPE_VARS.locationBufferSize; + newTapeInfos->stats[VAL_BUFFER_SIZE] = ADOLC_GLOBAL_TAPE_VARS.valueBufferSize; + newTapeInfos->stats[TAY_BUFFER_SIZE] = + ADOLC_GLOBAL_TAPE_VARS.taylorBufferSize; + + /* update tapeStack and save tapeInfos */ + if (ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr != NULL) { + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr->copy(ADOLC_CURRENT_TAPE_INFOS); + ADOLC_TAPE_STACK.push(ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr); + } else { + ADOLC_CURRENT_TAPE_INFOS_FALLBACK.copy(ADOLC_CURRENT_TAPE_INFOS); + ADOLC_TAPE_STACK.push(&ADOLC_CURRENT_TAPE_INFOS_FALLBACK); + } + if (newTI) + ADOLC_TAPE_INFOS_BUFFER.push_back(newTapeInfos); - newTapeInfos->pTapeInfos.skipFileCleanup=0; + newTapeInfos->pTapeInfos.skipFileCleanup = 0; - /* set the new tape infos as current */ - ADOLC_CURRENT_TAPE_INFOS.copy(*newTapeInfos); - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = newTapeInfos; + /* set the new tape infos as current */ + ADOLC_CURRENT_TAPE_INFOS.copy(*newTapeInfos); + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = newTapeInfos; - return retval; + return retval; } /* opens an existing tape or creates a new handle for a tape on hard disk * - called from init_for_sweep and init_rev_sweep */ void openTape(short tapeID, char mode) { - TapeInfos *tempTapeInfos=NULL; - - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* check if tape information exist in memory */ - vector::iterator tiIter = std::find_if(ADOLC_TAPE_INFOS_BUFFER.begin(), - ADOLC_TAPE_INFOS_BUFFER.end(), - [&tapeID](auto&& ti){return ti->tapeID == tapeID;}); - - if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) - { - /* tape has been used before (in the current program) */ - if ((*tiIter)->inUse == 0) { - /* forward sweep */ - if ((*tiIter)->tay_file != NULL) - rewind((*tiIter)->tay_file); - initTapeInfos_keep(*tiIter); - (*tiIter)->traceFlag=1; - (*tiIter)->tapeID = tapeID; - (*tiIter)->tapingComplete = 1; - (*tiIter)->inUse = 1; - read_tape_stats(*tiIter); - } - if (ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr != NULL) { - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr->copy( - ADOLC_CURRENT_TAPE_INFOS); - ADOLC_TAPE_STACK.push( - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr); - } else { - ADOLC_CURRENT_TAPE_INFOS_FALLBACK.copy( - ADOLC_CURRENT_TAPE_INFOS); - ADOLC_TAPE_STACK.push(&ADOLC_CURRENT_TAPE_INFOS_FALLBACK); - } - ADOLC_CURRENT_TAPE_INFOS.copy(**tiIter); - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = *tiIter; - return; - } - - /* tapeID not used so far */ - if (mode == ADOLC_REVERSE) { - failAdditionalInfo1 = tapeID; - fail(ADOLC_REVERSE_NO_TAYLOR_STACK); + TapeInfos *tempTapeInfos = NULL; + + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* check if tape information exist in memory */ + vector::iterator tiIter = std::find_if( + ADOLC_TAPE_INFOS_BUFFER.begin(), ADOLC_TAPE_INFOS_BUFFER.end(), + [&tapeID](auto &&ti) { return ti->tapeID == tapeID; }); + + if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { + /* tape has been used before (in the current program) */ + if ((*tiIter)->inUse == 0) { + /* forward sweep */ + if ((*tiIter)->tay_file != NULL) + rewind((*tiIter)->tay_file); + initTapeInfos_keep(*tiIter); + (*tiIter)->traceFlag = 1; + (*tiIter)->tapeID = tapeID; + (*tiIter)->tapingComplete = 1; + (*tiIter)->inUse = 1; + read_tape_stats(*tiIter); } - - /* create new info struct and initialize it */ - tempTapeInfos = new TapeInfos(tapeID); - tempTapeInfos->traceFlag=1; - tempTapeInfos->inUse = 1; - tempTapeInfos->tapingComplete = 1; - ADOLC_TAPE_INFOS_BUFFER.push_back(tempTapeInfos); - - read_tape_stats(tempTapeInfos); - /* update tapeStack and save tapeInfos */ if (ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr != NULL) { - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr->copy( - ADOLC_CURRENT_TAPE_INFOS); - ADOLC_TAPE_STACK.push(ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr); + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr->copy( + ADOLC_CURRENT_TAPE_INFOS); + ADOLC_TAPE_STACK.push(ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr); } else { - ADOLC_CURRENT_TAPE_INFOS_FALLBACK.copy( - ADOLC_CURRENT_TAPE_INFOS); - ADOLC_TAPE_STACK.push(&ADOLC_CURRENT_TAPE_INFOS_FALLBACK); + ADOLC_CURRENT_TAPE_INFOS_FALLBACK.copy(ADOLC_CURRENT_TAPE_INFOS); + ADOLC_TAPE_STACK.push(&ADOLC_CURRENT_TAPE_INFOS_FALLBACK); } + ADOLC_CURRENT_TAPE_INFOS.copy(**tiIter); + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = *tiIter; + return; + } + + /* tapeID not used so far */ + if (mode == ADOLC_REVERSE) { + failAdditionalInfo1 = tapeID; + fail(ADOLC_REVERSE_NO_TAYLOR_STACK); + } - /* set the new tape infos as current */ - ADOLC_CURRENT_TAPE_INFOS.copy(*tempTapeInfos); - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = tempTapeInfos; + /* create new info struct and initialize it */ + tempTapeInfos = new TapeInfos(tapeID); + tempTapeInfos->traceFlag = 1; + tempTapeInfos->inUse = 1; + tempTapeInfos->tapingComplete = 1; + ADOLC_TAPE_INFOS_BUFFER.push_back(tempTapeInfos); + + read_tape_stats(tempTapeInfos); + /* update tapeStack and save tapeInfos */ + if (ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr != NULL) { + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr->copy(ADOLC_CURRENT_TAPE_INFOS); + ADOLC_TAPE_STACK.push(ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr); + } else { + ADOLC_CURRENT_TAPE_INFOS_FALLBACK.copy(ADOLC_CURRENT_TAPE_INFOS); + ADOLC_TAPE_STACK.push(&ADOLC_CURRENT_TAPE_INFOS_FALLBACK); + } + + /* set the new tape infos as current */ + ADOLC_CURRENT_TAPE_INFOS.copy(*tempTapeInfos); + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = tempTapeInfos; } /* release the current tape and give control to the previous one */ void releaseTape() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* if operations, locations and constants tapes have been written and value - * stack information have not been created tapeInfos are no longer needed*/ - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors == 0 && - ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] == 1 && - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_FILE_ACCESS] == 1 && - ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] == 1 ) { - ADOLC_CURRENT_TAPE_INFOS.inUse = 0; - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* if operations, locations and constants tapes have been written and value + * stack information have not been created tapeInfos are no longer needed*/ + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors == 0 && + ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] == 1 && + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_FILE_ACCESS] == 1 && + ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] == 1) { + ADOLC_CURRENT_TAPE_INFOS.inUse = 0; + } - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr->copy( - ADOLC_CURRENT_TAPE_INFOS); - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = ADOLC_TAPE_STACK.top(); - ADOLC_CURRENT_TAPE_INFOS.copy( - *ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr); - ADOLC_TAPE_STACK.pop(); - if (ADOLC_TAPE_STACK.empty()) - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = NULL; + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr->copy(ADOLC_CURRENT_TAPE_INFOS); + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = ADOLC_TAPE_STACK.top(); + ADOLC_CURRENT_TAPE_INFOS.copy(*ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr); + ADOLC_TAPE_STACK.pop(); + if (ADOLC_TAPE_STACK.empty()) + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = NULL; } /* updates the tape infos for the given ID - a tapeInfos struct is created * and registered if non is found but its state will remain "not in use" */ TapeInfos *getTapeInfos(short tapeID) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - /* check if TapeInfos for tapeID exist */ - auto tiIter = std::find_if(ADOLC_TAPE_INFOS_BUFFER.begin(), - ADOLC_TAPE_INFOS_BUFFER.end(), - [&tapeID](auto&& ti){return ti->tapeID == tapeID;}); - - // Return the tapeInfos pointer if it has been found. - if (tiIter!=ADOLC_TAPE_INFOS_BUFFER.end()) { - TapeInfos *tapeInfos = *tiIter; - if (tapeInfos->inUse==0) - read_tape_stats(tapeInfos); - return tapeInfos; - } + /* check if TapeInfos for tapeID exist */ + auto tiIter = std::find_if( + ADOLC_TAPE_INFOS_BUFFER.begin(), ADOLC_TAPE_INFOS_BUFFER.end(), + [&tapeID](auto &&ti) { return ti->tapeID == tapeID; }); - /* create new TapeInfos, initialize and update tapeInfosBuffer */ - TapeInfos *tapeInfos = new TapeInfos(tapeID); - ADOLC_TAPE_INFOS_BUFFER.push_back(tapeInfos); - tapeInfos->traceFlag=1; - tapeInfos->inUse=0; - tapeInfos->tapingComplete = 1; - read_tape_stats(tapeInfos); + // Return the tapeInfos pointer if it has been found. + if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { + TapeInfos *tapeInfos = *tiIter; + if (tapeInfos->inUse == 0) + read_tape_stats(tapeInfos); return tapeInfos; + } + + /* create new TapeInfos, initialize and update tapeInfosBuffer */ + TapeInfos *tapeInfos = new TapeInfos(tapeID); + ADOLC_TAPE_INFOS_BUFFER.push_back(tapeInfos); + tapeInfos->traceFlag = 1; + tapeInfos->inUse = 0; + tapeInfos->tapingComplete = 1; + read_tape_stats(tapeInfos); + return tapeInfos; } /****************************************************************************/ /* Set a trace to nested_ctx */ /****************************************************************************/ void set_nested_ctx(short tag, char nested) { - TapeInfos* tiInfos = getTapeInfos(tag); - tiInfos->in_nested_ctx = nested; + TapeInfos *tiInfos = getTapeInfos(tag); + tiInfos->in_nested_ctx = nested; } /****************************************************************************/ /* Check whether a tape has been set to nested_ctx */ /****************************************************************************/ char currently_nested(short tag) { - TapeInfos* tiInfos = getTapeInfos(tag); - return tiInfos->in_nested_ctx; + TapeInfos *tiInfos = getTapeInfos(tag); + return tiInfos->in_nested_ctx; } - -void cachedTraceTags(std::vector& result) { - vector::const_iterator tiIter; - vector::iterator tIdIter; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - result.resize(ADOLC_TAPE_INFOS_BUFFER.size()); - if (!ADOLC_TAPE_INFOS_BUFFER.empty()) { - for(tiIter=ADOLC_TAPE_INFOS_BUFFER.begin(), tIdIter=result.begin(); - tiIter!=ADOLC_TAPE_INFOS_BUFFER.end(); - ++tiIter, ++tIdIter) { - *tIdIter = (*tiIter)->tapeID; - } +void cachedTraceTags(std::vector &result) { + vector::const_iterator tiIter; + vector::iterator tIdIter; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + result.resize(ADOLC_TAPE_INFOS_BUFFER.size()); + if (!ADOLC_TAPE_INFOS_BUFFER.empty()) { + for (tiIter = ADOLC_TAPE_INFOS_BUFFER.begin(), tIdIter = result.begin(); + tiIter != ADOLC_TAPE_INFOS_BUFFER.end(); ++tiIter, ++tIdIter) { + *tIdIter = (*tiIter)->tapeID; } + } } #ifdef SPARSE /* updates the tape infos on sparse Jac for the given ID */ void setTapeInfoJacSparse(short tapeID, SparseJacInfos sJinfos) { - TapeInfos *tapeInfos; - - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* check if TapeInfos for tapeID exist */ - vector::iterator tiIter = std::find_if(ADOLC_TAPE_INFOS_BUFFER.begin(), - ADOLC_TAPE_INFOS_BUFFER.end(), - [&tapeID](auto&& ti){return ti->tapeID == tapeID;}); - - if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { - tapeInfos=*tiIter; - // free memory of tape entry that had been used previously - freeSparseJacInfos(tapeInfos->pTapeInfos.sJinfos.y, - tapeInfos->pTapeInfos.sJinfos.B, - tapeInfos->pTapeInfos.sJinfos.JP, - tapeInfos->pTapeInfos.sJinfos.g, - tapeInfos->pTapeInfos.sJinfos.jr1d, - tapeInfos->pTapeInfos.sJinfos.seed_rows, - tapeInfos->pTapeInfos.sJinfos.seed_clms, - tapeInfos->pTapeInfos.sJinfos.depen); - tapeInfos->pTapeInfos.sJinfos.y=sJinfos.y; - tapeInfos->pTapeInfos.sJinfos.Seed=sJinfos.Seed; - tapeInfos->pTapeInfos.sJinfos.B=sJinfos.B; - tapeInfos->pTapeInfos.sJinfos.JP=sJinfos.JP; - tapeInfos->pTapeInfos.sJinfos.depen=sJinfos.depen; - tapeInfos->pTapeInfos.sJinfos.nnz_in=sJinfos.nnz_in; - tapeInfos->pTapeInfos.sJinfos.seed_clms=sJinfos.seed_clms; - tapeInfos->pTapeInfos.sJinfos.seed_rows=sJinfos.seed_rows; - tapeInfos->pTapeInfos.sJinfos.g=sJinfos.g; - tapeInfos->pTapeInfos.sJinfos.jr1d=sJinfos.jr1d; - } + TapeInfos *tapeInfos; + + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* check if TapeInfos for tapeID exist */ + vector::iterator tiIter = std::find_if( + ADOLC_TAPE_INFOS_BUFFER.begin(), ADOLC_TAPE_INFOS_BUFFER.end(), + [&tapeID](auto &&ti) { return ti->tapeID == tapeID; }); + + if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { + tapeInfos = *tiIter; + // free memory of tape entry that had been used previously + freeSparseJacInfos( + tapeInfos->pTapeInfos.sJinfos.y, tapeInfos->pTapeInfos.sJinfos.B, + tapeInfos->pTapeInfos.sJinfos.JP, tapeInfos->pTapeInfos.sJinfos.g, + tapeInfos->pTapeInfos.sJinfos.jr1d, + tapeInfos->pTapeInfos.sJinfos.seed_rows, + tapeInfos->pTapeInfos.sJinfos.seed_clms, + tapeInfos->pTapeInfos.sJinfos.depen); + tapeInfos->pTapeInfos.sJinfos.y = sJinfos.y; + tapeInfos->pTapeInfos.sJinfos.Seed = sJinfos.Seed; + tapeInfos->pTapeInfos.sJinfos.B = sJinfos.B; + tapeInfos->pTapeInfos.sJinfos.JP = sJinfos.JP; + tapeInfos->pTapeInfos.sJinfos.depen = sJinfos.depen; + tapeInfos->pTapeInfos.sJinfos.nnz_in = sJinfos.nnz_in; + tapeInfos->pTapeInfos.sJinfos.seed_clms = sJinfos.seed_clms; + tapeInfos->pTapeInfos.sJinfos.seed_rows = sJinfos.seed_rows; + tapeInfos->pTapeInfos.sJinfos.g = sJinfos.g; + tapeInfos->pTapeInfos.sJinfos.jr1d = sJinfos.jr1d; + } } #endif #ifdef SPARSE /* updates the tape infos on sparse Hess for the given ID */ void setTapeInfoHessSparse(short tapeID, SparseHessInfos sHinfos) { - TapeInfos *tapeInfos; - - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* check if TapeInfos for tapeID exist */ - vector::iterator tiIter = std::find_if(ADOLC_TAPE_INFOS_BUFFER.begin(), - ADOLC_TAPE_INFOS_BUFFER.end(), - [&tapeID](auto&& ti){return ti->tapeID == tapeID;}); - - if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { - tapeInfos=*tiIter; - // free memory of tape entry that had been used previously - freeSparseHessInfos(tapeInfos->pTapeInfos.sHinfos.Hcomp, - tapeInfos->pTapeInfos.sHinfos.Xppp, - tapeInfos->pTapeInfos.sHinfos.Yppp, - tapeInfos->pTapeInfos.sHinfos.Zppp, - tapeInfos->pTapeInfos.sHinfos.Upp, - tapeInfos->pTapeInfos.sHinfos.HP, - tapeInfos->pTapeInfos.sHinfos.g, - tapeInfos->pTapeInfos.sHinfos.hr, - tapeInfos->pTapeInfos.sHinfos.p, - tapeInfos->pTapeInfos.sHinfos.indep); - tapeInfos->pTapeInfos.sHinfos.Hcomp=sHinfos.Hcomp; - tapeInfos->pTapeInfos.sHinfos.Xppp=sHinfos.Xppp; - tapeInfos->pTapeInfos.sHinfos.Yppp=sHinfos.Yppp; - tapeInfos->pTapeInfos.sHinfos.Zppp=sHinfos.Zppp; - tapeInfos->pTapeInfos.sHinfos.Upp=sHinfos.Upp; - tapeInfos->pTapeInfos.sHinfos.HP=sHinfos.HP; - tapeInfos->pTapeInfos.sHinfos.indep=sHinfos.indep; - tapeInfos->pTapeInfos.sHinfos.nnz_in=sHinfos.nnz_in; - tapeInfos->pTapeInfos.sHinfos.p=sHinfos.p; - tapeInfos->pTapeInfos.sHinfos.g=sHinfos.g; - tapeInfos->pTapeInfos.sHinfos.hr=sHinfos.hr; - } + TapeInfos *tapeInfos; + + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* check if TapeInfos for tapeID exist */ + vector::iterator tiIter = std::find_if( + ADOLC_TAPE_INFOS_BUFFER.begin(), ADOLC_TAPE_INFOS_BUFFER.end(), + [&tapeID](auto &&ti) { return ti->tapeID == tapeID; }); + + if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { + tapeInfos = *tiIter; + // free memory of tape entry that had been used previously + freeSparseHessInfos( + tapeInfos->pTapeInfos.sHinfos.Hcomp, tapeInfos->pTapeInfos.sHinfos.Xppp, + tapeInfos->pTapeInfos.sHinfos.Yppp, tapeInfos->pTapeInfos.sHinfos.Zppp, + tapeInfos->pTapeInfos.sHinfos.Upp, tapeInfos->pTapeInfos.sHinfos.HP, + tapeInfos->pTapeInfos.sHinfos.g, tapeInfos->pTapeInfos.sHinfos.hr, + tapeInfos->pTapeInfos.sHinfos.p, tapeInfos->pTapeInfos.sHinfos.indep); + tapeInfos->pTapeInfos.sHinfos.Hcomp = sHinfos.Hcomp; + tapeInfos->pTapeInfos.sHinfos.Xppp = sHinfos.Xppp; + tapeInfos->pTapeInfos.sHinfos.Yppp = sHinfos.Yppp; + tapeInfos->pTapeInfos.sHinfos.Zppp = sHinfos.Zppp; + tapeInfos->pTapeInfos.sHinfos.Upp = sHinfos.Upp; + tapeInfos->pTapeInfos.sHinfos.HP = sHinfos.HP; + tapeInfos->pTapeInfos.sHinfos.indep = sHinfos.indep; + tapeInfos->pTapeInfos.sHinfos.nnz_in = sHinfos.nnz_in; + tapeInfos->pTapeInfos.sHinfos.p = sHinfos.p; + tapeInfos->pTapeInfos.sHinfos.g = sHinfos.g; + tapeInfos->pTapeInfos.sHinfos.hr = sHinfos.hr; + } } #endif static void init_lib() { - ADOLC_OPENMP_THREAD_NUMBER; - errno = 0; - ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; + errno = 0; + ADOLC_OPENMP_GET_THREAD_NUMBER; #if defined(_OPENMP) - tapeInfosBuffer = new vector; - tapeStack = new stack; - currentTapeInfos = new TapeInfos; - currentTapeInfos->tapingComplete = 1; - currentTapeInfos_fallBack = new TapeInfos; - globalTapeVars = new GlobalTapeVars; - ADOLC_extDiffFctsBuffer = new ADOLC_BUFFER_TYPE; - ADOLC_checkpointsStack = new stack; - revolve_numbers = new revolve_nums; + tapeInfosBuffer = new vector; + tapeStack = new stack; + currentTapeInfos = new TapeInfos; + currentTapeInfos->tapingComplete = 1; + currentTapeInfos_fallBack = new TapeInfos; + globalTapeVars = new GlobalTapeVars; + ADOLC_extDiffFctsBuffer = new ADOLC_BUFFER_TYPE; + ADOLC_checkpointsStack = new stack; + revolve_numbers = new revolve_nums; #endif /* _OPENMP */ - ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; - ADOLC_CURRENT_TAPE_INFOS.keepTaylors = 0; + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + ADOLC_CURRENT_TAPE_INFOS.keepTaylors = 0; - ADOLC_GLOBAL_TAPE_VARS.maxLoc=1; - for (uint i=0; iop_file!=NULL) - { - fclose((*tiIter)->op_file); - (*tiIter)->op_file = NULL; - } - if ((*tiIter)->val_file!=NULL) - { - fclose((*tiIter)->val_file); - (*tiIter)->val_file = NULL; - } - if ((*tiIter)->loc_file!=NULL) - { - fclose((*tiIter)->loc_file); - (*tiIter)->loc_file = NULL; - } - if ((*tiIter)->tay_file!=NULL && (*tiIter)->pTapeInfos.skipFileCleanup==0 ) { - fclose((*tiIter)->tay_file); - (*tiIter)->tay_file = NULL; - remove((*tiIter)->pTapeInfos.tay_fileName); - } - if ((*tiIter)->opBuffer != NULL) - { - free((*tiIter)->opBuffer); - (*tiIter)->opBuffer = NULL; - } - if ((*tiIter)->valBuffer != NULL) - { - free((*tiIter)->valBuffer); - (*tiIter)->valBuffer = NULL; - } - if ((*tiIter)->locBuffer != NULL) - { - free((*tiIter)->locBuffer); - (*tiIter)->locBuffer = NULL; - } - if ((*tiIter)->signature != NULL) - { - free((*tiIter)->signature); - (*tiIter)->signature = NULL; - } - if ((*tiIter)->tayBuffer != NULL) - { - free((*tiIter)->tayBuffer); - (*tiIter)->tayBuffer = NULL; - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + TapeInfos **tiIter; + clearCurrentTape(); + while (!ADOLC_TAPE_INFOS_BUFFER.empty()) { + tiIter = &ADOLC_TAPE_INFOS_BUFFER.back(); + ADOLC_TAPE_INFOS_BUFFER.pop_back(); + { + /* close open files though they may be incomplete */ + if ((*tiIter)->op_file != NULL) { + fclose((*tiIter)->op_file); + (*tiIter)->op_file = NULL; + } + if ((*tiIter)->val_file != NULL) { + fclose((*tiIter)->val_file); + (*tiIter)->val_file = NULL; + } + if ((*tiIter)->loc_file != NULL) { + fclose((*tiIter)->loc_file); + (*tiIter)->loc_file = NULL; + } + if ((*tiIter)->tay_file != NULL && + (*tiIter)->pTapeInfos.skipFileCleanup == 0) { + fclose((*tiIter)->tay_file); + (*tiIter)->tay_file = NULL; + remove((*tiIter)->pTapeInfos.tay_fileName); + } + if ((*tiIter)->opBuffer != NULL) { + free((*tiIter)->opBuffer); + (*tiIter)->opBuffer = NULL; + } + if ((*tiIter)->valBuffer != NULL) { + free((*tiIter)->valBuffer); + (*tiIter)->valBuffer = NULL; + } + if ((*tiIter)->locBuffer != NULL) { + free((*tiIter)->locBuffer); + (*tiIter)->locBuffer = NULL; + } + if ((*tiIter)->signature != NULL) { + free((*tiIter)->signature); + (*tiIter)->signature = NULL; + } + if ((*tiIter)->tayBuffer != NULL) { + free((*tiIter)->tayBuffer); + (*tiIter)->tayBuffer = NULL; + } #ifdef SPARSE - freeSparseJacInfos((*tiIter)->pTapeInfos.sJinfos.y, - (*tiIter)->pTapeInfos.sJinfos.B, - (*tiIter)->pTapeInfos.sJinfos.JP, - (*tiIter)->pTapeInfos.sJinfos.g, - (*tiIter)->pTapeInfos.sJinfos.jr1d, - (*tiIter)->pTapeInfos.sJinfos.seed_rows, - (*tiIter)->pTapeInfos.sJinfos.seed_clms, - (*tiIter)->pTapeInfos.sJinfos.depen); - freeSparseHessInfos((*tiIter)->pTapeInfos.sHinfos.Hcomp, - (*tiIter)->pTapeInfos.sHinfos.Xppp, - (*tiIter)->pTapeInfos.sHinfos.Yppp, - (*tiIter)->pTapeInfos.sHinfos.Zppp, - (*tiIter)->pTapeInfos.sHinfos.Upp, - (*tiIter)->pTapeInfos.sHinfos.HP, - (*tiIter)->pTapeInfos.sHinfos.g, - (*tiIter)->pTapeInfos.sHinfos.hr, - (*tiIter)->pTapeInfos.sHinfos.p, - (*tiIter)->pTapeInfos.sHinfos.indep); + freeSparseJacInfos( + (*tiIter)->pTapeInfos.sJinfos.y, (*tiIter)->pTapeInfos.sJinfos.B, + (*tiIter)->pTapeInfos.sJinfos.JP, (*tiIter)->pTapeInfos.sJinfos.g, + (*tiIter)->pTapeInfos.sJinfos.jr1d, + (*tiIter)->pTapeInfos.sJinfos.seed_rows, + (*tiIter)->pTapeInfos.sJinfos.seed_clms, + (*tiIter)->pTapeInfos.sJinfos.depen); + freeSparseHessInfos( + (*tiIter)->pTapeInfos.sHinfos.Hcomp, + (*tiIter)->pTapeInfos.sHinfos.Xppp, + (*tiIter)->pTapeInfos.sHinfos.Yppp, + (*tiIter)->pTapeInfos.sHinfos.Zppp, (*tiIter)->pTapeInfos.sHinfos.Upp, + (*tiIter)->pTapeInfos.sHinfos.HP, (*tiIter)->pTapeInfos.sHinfos.g, + (*tiIter)->pTapeInfos.sHinfos.hr, (*tiIter)->pTapeInfos.sHinfos.p, + (*tiIter)->pTapeInfos.sHinfos.indep); #endif - /* remove "main" tape files if not all three have been written */ - int filesWritten = (*tiIter)->stats[OP_FILE_ACCESS] + - (*tiIter)->stats[LOC_FILE_ACCESS] + - (*tiIter)->stats[VAL_FILE_ACCESS]; - if ( (filesWritten > 0) && ((*tiIter)->pTapeInfos.keepTape == 0) && (*tiIter)->pTapeInfos.skipFileCleanup==0 ) - { - /* try to remove all tapes (even those not written by this - * run) => this ensures that there is no mixture of tapes from - * different ADOLC runs */ - if ( (*tiIter)->stats[OP_FILE_ACCESS] == 1 ) - remove((*tiIter)->pTapeInfos.op_fileName); - if ( (*tiIter)->stats[LOC_FILE_ACCESS] == 1 ) - remove((*tiIter)->pTapeInfos.loc_fileName); - if ( (*tiIter)->stats[VAL_FILE_ACCESS] == 1 ) - remove((*tiIter)->pTapeInfos.val_fileName); - } - if ((*tiIter)->pTapeInfos.op_fileName != NULL) - { - free((*tiIter)->pTapeInfos.op_fileName); - (*tiIter)->pTapeInfos.op_fileName = NULL; - } - if ((*tiIter)->pTapeInfos.val_fileName != NULL) - { - free((*tiIter)->pTapeInfos.val_fileName); - (*tiIter)->pTapeInfos.val_fileName = NULL; - } - if ((*tiIter)->pTapeInfos.loc_fileName != NULL) - { - free((*tiIter)->pTapeInfos.loc_fileName); - (*tiIter)->pTapeInfos.loc_fileName = NULL; - } - if ((*tiIter)->pTapeInfos.tay_fileName != NULL) - { - free((*tiIter)->pTapeInfos.tay_fileName); - (*tiIter)->pTapeInfos.tay_fileName = NULL; - } - - delete *tiIter; - *tiIter = NULL; - } + /* remove "main" tape files if not all three have been written */ + int filesWritten = (*tiIter)->stats[OP_FILE_ACCESS] + + (*tiIter)->stats[LOC_FILE_ACCESS] + + (*tiIter)->stats[VAL_FILE_ACCESS]; + if ((filesWritten > 0) && ((*tiIter)->pTapeInfos.keepTape == 0) && + (*tiIter)->pTapeInfos.skipFileCleanup == 0) { + /* try to remove all tapes (even those not written by this + * run) => this ensures that there is no mixture of tapes from + * different ADOLC runs */ + if ((*tiIter)->stats[OP_FILE_ACCESS] == 1) + remove((*tiIter)->pTapeInfos.op_fileName); + if ((*tiIter)->stats[LOC_FILE_ACCESS] == 1) + remove((*tiIter)->pTapeInfos.loc_fileName); + if ((*tiIter)->stats[VAL_FILE_ACCESS] == 1) + remove((*tiIter)->pTapeInfos.val_fileName); + } + if ((*tiIter)->pTapeInfos.op_fileName != NULL) { + free((*tiIter)->pTapeInfos.op_fileName); + (*tiIter)->pTapeInfos.op_fileName = NULL; + } + if ((*tiIter)->pTapeInfos.val_fileName != NULL) { + free((*tiIter)->pTapeInfos.val_fileName); + (*tiIter)->pTapeInfos.val_fileName = NULL; + } + if ((*tiIter)->pTapeInfos.loc_fileName != NULL) { + free((*tiIter)->pTapeInfos.loc_fileName); + (*tiIter)->pTapeInfos.loc_fileName = NULL; + } + if ((*tiIter)->pTapeInfos.tay_fileName != NULL) { + free((*tiIter)->pTapeInfos.tay_fileName); + (*tiIter)->pTapeInfos.tay_fileName = NULL; + } + + delete *tiIter; + *tiIter = NULL; } + } - cp_clearStack(); + cp_clearStack(); - if (ADOLC_GLOBAL_TAPE_VARS.store != NULL) { - delete[] ADOLC_GLOBAL_TAPE_VARS.store; - ADOLC_GLOBAL_TAPE_VARS.store = NULL; - } - if (ADOLC_GLOBAL_TAPE_VARS.pStore != NULL) { - delete[] ADOLC_GLOBAL_TAPE_VARS.pStore; - ADOLC_GLOBAL_TAPE_VARS.pStore = NULL; - } + if (ADOLC_GLOBAL_TAPE_VARS.store != NULL) { + delete[] ADOLC_GLOBAL_TAPE_VARS.store; + ADOLC_GLOBAL_TAPE_VARS.store = NULL; + } + if (ADOLC_GLOBAL_TAPE_VARS.pStore != NULL) { + delete[] ADOLC_GLOBAL_TAPE_VARS.pStore; + ADOLC_GLOBAL_TAPE_VARS.pStore = NULL; + } #if defined(_OPENMP) - if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 0) { - /* cleanup on program exit */ - delete revolve_numbers; - delete ADOLC_checkpointsStack; - delete ADOLC_extDiffFctsBuffer; - delete globalTapeVars; - delete currentTapeInfos; - delete currentTapeInfos_fallBack; - delete tapeStack; - delete tapeInfosBuffer; - } + if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 0) { + /* cleanup on program exit */ + delete revolve_numbers; + delete ADOLC_checkpointsStack; + delete ADOLC_extDiffFctsBuffer; + delete globalTapeVars; + delete currentTapeInfos; + delete currentTapeInfos_fallBack; + delete tapeStack; + delete tapeInfosBuffer; + } #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - clearTapeBaseNames(); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + clearTapeBaseNames(); } int removeTape(short tapeID, short type) { - TapeInfos *tapeInfos = NULL; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* check if TapeInfos for tapeID exist */ - vector::iterator tiIter = std::find_if(ADOLC_TAPE_INFOS_BUFFER.begin(), - ADOLC_TAPE_INFOS_BUFFER.end(), - [&tapeID](auto&& ti){return ti->tapeID == tapeID;}); - - if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { - tapeInfos = *tiIter; - if (tapeInfos->tapingComplete == 0) return -1; - ADOLC_TAPE_INFOS_BUFFER.erase(tiIter); - } + TapeInfos *tapeInfos = NULL; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* check if TapeInfos for tapeID exist */ + vector::iterator tiIter = std::find_if( + ADOLC_TAPE_INFOS_BUFFER.begin(), ADOLC_TAPE_INFOS_BUFFER.end(), + [&tapeID](auto &&ti) { return ti->tapeID == tapeID; }); + + if (tiIter != ADOLC_TAPE_INFOS_BUFFER.end()) { + tapeInfos = *tiIter; + if (tapeInfos->tapingComplete == 0) + return -1; + ADOLC_TAPE_INFOS_BUFFER.erase(tiIter); + } - if (tapeInfos == NULL) { // might be on disk only - tapeInfos = new TapeInfos(tapeID); - tapeInfos->tapingComplete = 1; - } + if (tapeInfos == NULL) { // might be on disk only + tapeInfos = new TapeInfos(tapeID); + tapeInfos->tapingComplete = 1; + } - freeTapeResources(tapeInfos); + freeTapeResources(tapeInfos); #ifdef SPARSE - freeSparseJacInfos(tapeInfos->pTapeInfos.sJinfos.y, - tapeInfos->pTapeInfos.sJinfos.B, - tapeInfos->pTapeInfos.sJinfos.JP, - tapeInfos->pTapeInfos.sJinfos.g, - tapeInfos->pTapeInfos.sJinfos.jr1d, - tapeInfos->pTapeInfos.sJinfos.seed_rows, - tapeInfos->pTapeInfos.sJinfos.seed_clms, - tapeInfos->pTapeInfos.sJinfos.depen); - freeSparseHessInfos(tapeInfos->pTapeInfos.sHinfos.Hcomp, - tapeInfos->pTapeInfos.sHinfos.Xppp, - tapeInfos->pTapeInfos.sHinfos.Yppp, - tapeInfos->pTapeInfos.sHinfos.Zppp, - tapeInfos->pTapeInfos.sHinfos.Upp, - tapeInfos->pTapeInfos.sHinfos.HP, - tapeInfos->pTapeInfos.sHinfos.g, - tapeInfos->pTapeInfos.sHinfos.hr, - tapeInfos->pTapeInfos.sHinfos.p, - tapeInfos->pTapeInfos.sHinfos.indep); + freeSparseJacInfos( + tapeInfos->pTapeInfos.sJinfos.y, tapeInfos->pTapeInfos.sJinfos.B, + tapeInfos->pTapeInfos.sJinfos.JP, tapeInfos->pTapeInfos.sJinfos.g, + tapeInfos->pTapeInfos.sJinfos.jr1d, + tapeInfos->pTapeInfos.sJinfos.seed_rows, + tapeInfos->pTapeInfos.sJinfos.seed_clms, + tapeInfos->pTapeInfos.sJinfos.depen); + freeSparseHessInfos( + tapeInfos->pTapeInfos.sHinfos.Hcomp, tapeInfos->pTapeInfos.sHinfos.Xppp, + tapeInfos->pTapeInfos.sHinfos.Yppp, tapeInfos->pTapeInfos.sHinfos.Zppp, + tapeInfos->pTapeInfos.sHinfos.Upp, tapeInfos->pTapeInfos.sHinfos.HP, + tapeInfos->pTapeInfos.sHinfos.g, tapeInfos->pTapeInfos.sHinfos.hr, + tapeInfos->pTapeInfos.sHinfos.p, tapeInfos->pTapeInfos.sHinfos.indep); #endif - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - if (type == ADOLC_REMOVE_COMPLETELY) { - remove(tapeInfos->pTapeInfos.op_fileName); - remove(tapeInfos->pTapeInfos.loc_fileName); - remove(tapeInfos->pTapeInfos.val_fileName); - } + if (type == ADOLC_REMOVE_COMPLETELY) { + remove(tapeInfos->pTapeInfos.op_fileName); + remove(tapeInfos->pTapeInfos.loc_fileName); + remove(tapeInfos->pTapeInfos.val_fileName); + } - free(tapeInfos->pTapeInfos.op_fileName); - free(tapeInfos->pTapeInfos.val_fileName); - free(tapeInfos->pTapeInfos.loc_fileName); - if (tapeInfos->pTapeInfos.tay_fileName != NULL) - free(tapeInfos->pTapeInfos.tay_fileName); + free(tapeInfos->pTapeInfos.op_fileName); + free(tapeInfos->pTapeInfos.val_fileName); + free(tapeInfos->pTapeInfos.loc_fileName); + if (tapeInfos->pTapeInfos.tay_fileName != NULL) + free(tapeInfos->pTapeInfos.tay_fileName); - delete tapeInfos; + delete tapeInfos; - return 0; + return 0; } /****************************************************************************/ @@ -806,49 +771,50 @@ int removeTape(short tapeID, short type) { /* sets files names, and calls appropriate setup routines. */ /****************************************************************************/ int trace_on(short tnum, int keepTaylors) { - int retval = 0; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + int retval = 0; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - /* allocate memory for TapeInfos and update tapeStack */ - retval = initNewTape(tnum); + /* allocate memory for TapeInfos and update tapeStack */ + retval = initNewTape(tnum); #ifdef ADOLC_MEDIPACK_SUPPORT - mediInitTape(tnum); + mediInitTape(tnum); #endif - ADOLC_CURRENT_TAPE_INFOS.keepTaylors=keepTaylors; - ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX] = - ADOLC_GLOBAL_TAPE_VARS.nominmaxFlag; - if (keepTaylors!=0) ADOLC_CURRENT_TAPE_INFOS.deg_save=1; - start_trace(); - take_stock(); /* record all existing adoubles on the tape */ - return retval; + ADOLC_CURRENT_TAPE_INFOS.keepTaylors = keepTaylors; + ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX] = + ADOLC_GLOBAL_TAPE_VARS.nominmaxFlag; + if (keepTaylors != 0) + ADOLC_CURRENT_TAPE_INFOS.deg_save = 1; + start_trace(); + take_stock(); /* record all existing adoubles on the tape */ + return retval; } -int trace_on(short tnum, int keepTaylors, - uint obs, uint lbs, uint vbs, uint tbs, int skipFileCleanup) -{ - int retval = 0; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; +int trace_on(short tnum, int keepTaylors, uint obs, uint lbs, uint vbs, + uint tbs, int skipFileCleanup) { + int retval = 0; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - /* allocate memory for TapeInfos and update tapeStack */ - retval = initNewTape(tnum); + /* allocate memory for TapeInfos and update tapeStack */ + retval = initNewTape(tnum); #ifdef ADOLC_MEDIPACK_SUPPORT - mediInitTape(tnum); + mediInitTape(tnum); #endif - freeTapeResources(&ADOLC_CURRENT_TAPE_INFOS); - ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE] = obs; - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE] = lbs; - ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE] = vbs; - ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE] = tbs; - ADOLC_CURRENT_TAPE_INFOS.keepTaylors=keepTaylors; - ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX] = - ADOLC_GLOBAL_TAPE_VARS.nominmaxFlag; - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.skipFileCleanup=skipFileCleanup; - if (keepTaylors!=0) ADOLC_CURRENT_TAPE_INFOS.deg_save=1; - start_trace(); - take_stock(); /* record all existing adoubles on the tape */ - return retval; + freeTapeResources(&ADOLC_CURRENT_TAPE_INFOS); + ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE] = obs; + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE] = lbs; + ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE] = vbs; + ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE] = tbs; + ADOLC_CURRENT_TAPE_INFOS.keepTaylors = keepTaylors; + ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX] = + ADOLC_GLOBAL_TAPE_VARS.nominmaxFlag; + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.skipFileCleanup = skipFileCleanup; + if (keepTaylors != 0) + ADOLC_CURRENT_TAPE_INFOS.deg_save = 1; + start_trace(); + take_stock(); /* record all existing adoubles on the tape */ + return retval; } /****************************************************************************/ @@ -856,53 +822,47 @@ int trace_on(short tnum, int keepTaylors, /* enforces writing of the three main tape files (op+loc+val). */ /****************************************************************************/ void trace_off(int flag) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.workMode != ADOLC_TAPING) { - failAdditionalInfo1 = ADOLC_CURRENT_TAPE_INFOS.tapeID; - fail(ADOLC_TAPING_NOT_ACTUALLY_TAPING); - } - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.keepTape = flag; - keep_stock(); /* copy remaining live variables + trace_flag = 0 */ - stop_trace(flag); - cout.flush(); - ADOLC_CURRENT_TAPE_INFOS.tapingComplete = 1; - ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; - releaseTape(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.workMode != ADOLC_TAPING) { + failAdditionalInfo1 = ADOLC_CURRENT_TAPE_INFOS.tapeID; + fail(ADOLC_TAPING_NOT_ACTUALLY_TAPING); + } + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.keepTape = flag; + keep_stock(); /* copy remaining live variables + trace_flag = 0 */ + stop_trace(flag); + cout.flush(); + ADOLC_CURRENT_TAPE_INFOS.tapingComplete = 1; + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; + releaseTape(); } bool isTaping() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - return ADOLC_CURRENT_TAPE_INFOS.traceFlag != 0; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + return ADOLC_CURRENT_TAPE_INFOS.traceFlag != 0; } void checkInitialStoreSize(GlobalTapeVars *gtv) { - if (gtv->initialStoreSize > - gtv->storeManagerPtr->initialSize) - gtv->storeManagerPtr->grow( - gtv->initialStoreSize); + if (gtv->initialStoreSize > gtv->storeManagerPtr->initialSize) + gtv->storeManagerPtr->grow(gtv->initialStoreSize); } /****************************************************************************/ /* A class for initialization/finalization and OpenMP handling */ /****************************************************************************/ class Keeper { - public: - inline Keeper() { - dummy = 0; - init_lib(); - } - inline ~Keeper() { - cleanUp(); - } - - inline void touch() { - dummy = 1; - } - - private: - int dummy; +public: + inline Keeper() { + dummy = 0; + init_lib(); + } + inline ~Keeper() { cleanUp(); } + + inline void touch() { dummy = 1; } + +private: + int dummy; }; /* a static instance that does all work */ @@ -910,9 +870,7 @@ static Keeper theKeeper; /** * Hope to convince the linker to link the keeper code into the executable. */ -void initADOLC() { - theKeeper.touch(); -} +void initADOLC() { theKeeper.touch(); } /****************************************************************************/ /****************************************************************************/ @@ -921,108 +879,108 @@ void initADOLC() { /****************************************************************************/ /****************************************************************************/ #if defined(_OPENMP) -#include + #include ADOLC_OpenMP ADOLC_OpenMP_Handler; ADOLC_OpenMP_NC ADOLC_OpenMP_Handler_NC; int ADOLC_parallel_doCopy; static bool waitForMaster_begin = true; -static bool waitForMaster_end = true; -static bool firstParallel = true; +static bool waitForMaster_end = true; +static bool firstParallel = true; /****************************************************************************/ /* Used by OpenMP to create a separate environment for every worker thread. */ /****************************************************************************/ void beginParallel() { - ADOLC_OPENMP_THREAD_NUMBER; -#if defined(ADOLC_THREADSAVE_ERRNO) - errno = omp_get_thread_num(); -#endif - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_threadNumber == 0) { /* master only */ - int numThreads = omp_get_num_threads(); - - tapeInfosBuffer_s = tapeInfosBuffer; - tapeStack_s = tapeStack; - currentTapeInfos_s = currentTapeInfos; - currentTapeInfos_fallBack_s = currentTapeInfos_fallBack; - globalTapeVars_s = globalTapeVars; - ADOLC_extDiffFctsBuffer_s = ADOLC_extDiffFctsBuffer; - ADOLC_checkpointsStack_s = ADOLC_checkpointsStack; - revolve_numbers_s = revolve_numbers; - - if (firstParallel) { - tapeInfosBuffer = new vector[numThreads]; - tapeStack = new stack[numThreads]; - currentTapeInfos = new TapeInfos[numThreads]; - currentTapeInfos_fallBack = new TapeInfos[numThreads]; - globalTapeVars = new GlobalTapeVars[numThreads]; - ADOLC_extDiffFctsBuffer = new ADOLC_BUFFER_TYPE[numThreads]; - ADOLC_checkpointsStack = new stack[numThreads]; - revolve_numbers = new revolve_nums[numThreads]; - } else { - tapeInfosBuffer = tapeInfosBuffer_p; - tapeStack = tapeStack_p; - currentTapeInfos = currentTapeInfos_p; - currentTapeInfos_fallBack = currentTapeInfos_fallBack_p; - globalTapeVars = globalTapeVars_p; - ADOLC_extDiffFctsBuffer = ADOLC_extDiffFctsBuffer_p; - ADOLC_checkpointsStack = ADOLC_checkpointsStack_p; - revolve_numbers = revolve_numbers_p; - } - - /* - set inParallelRegion for tmpGlobalTapeVars because it is source - * for initializing the parallel globalTapeVars structs - * - inParallelRegion has to be set to one for all workers by master. - * This is necessary, to deter a speedy master from assuming all - * workers are done, in endParallel, before they even leaved - * beginParallel. */ - globalTapeVars_s[0].inParallelRegion = 1; - for (int i = 0; i < numThreads; ++i) - globalTapeVars[i].inParallelRegion = 1; - - waitForMaster_end = true; - waitForMaster_begin = false; - } else - while (waitForMaster_begin) { - usleep(1000); /* if anyone knows a better value, ... :-) */ - } + ADOLC_OPENMP_THREAD_NUMBER; + #if defined(ADOLC_THREADSAVE_ERRNO) + errno = omp_get_thread_num(); + #endif + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_threadNumber == 0) { /* master only */ + int numThreads = omp_get_num_threads(); + + tapeInfosBuffer_s = tapeInfosBuffer; + tapeStack_s = tapeStack; + currentTapeInfos_s = currentTapeInfos; + currentTapeInfos_fallBack_s = currentTapeInfos_fallBack; + globalTapeVars_s = globalTapeVars; + ADOLC_extDiffFctsBuffer_s = ADOLC_extDiffFctsBuffer; + ADOLC_checkpointsStack_s = ADOLC_checkpointsStack; + revolve_numbers_s = revolve_numbers; if (firstParallel) { - ADOLC_EXT_DIFF_FCTS_BUFFER.init(init_CpInfos); + tapeInfosBuffer = new vector[numThreads]; + tapeStack = new stack[numThreads]; + currentTapeInfos = new TapeInfos[numThreads]; + currentTapeInfos_fallBack = new TapeInfos[numThreads]; + globalTapeVars = new GlobalTapeVars[numThreads]; + ADOLC_extDiffFctsBuffer = new ADOLC_BUFFER_TYPE[numThreads]; + ADOLC_checkpointsStack = new stack[numThreads]; + revolve_numbers = new revolve_nums[numThreads]; + } else { + tapeInfosBuffer = tapeInfosBuffer_p; + tapeStack = tapeStack_p; + currentTapeInfos = currentTapeInfos_p; + currentTapeInfos_fallBack = currentTapeInfos_fallBack_p; + globalTapeVars = globalTapeVars_p; + ADOLC_extDiffFctsBuffer = ADOLC_extDiffFctsBuffer_p; + ADOLC_checkpointsStack = ADOLC_checkpointsStack_p; + revolve_numbers = revolve_numbers_p; + } - /* Use assignment operator instead of open coding - * this copies the store and the storemanager too - */ - ADOLC_GLOBAL_TAPE_VARS = *globalTapeVars_s; + /* - set inParallelRegion for tmpGlobalTapeVars because it is source + * for initializing the parallel globalTapeVars structs + * - inParallelRegion has to be set to one for all workers by master. + * This is necessary, to deter a speedy master from assuming all + * workers are done, in endParallel, before they even leaved + * beginParallel. */ + globalTapeVars_s[0].inParallelRegion = 1; + for (int i = 0; i < numThreads; ++i) + globalTapeVars[i].inParallelRegion = 1; + + waitForMaster_end = true; + waitForMaster_begin = false; + } else + while (waitForMaster_begin) { + usleep(1000); /* if anyone knows a better value, ... :-) */ + } - ADOLC_GLOBAL_TAPE_VARS.newTape = 0; - ADOLC_CURRENT_TAPE_INFOS.tapingComplete = 1; - ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = NULL; - } else { - if (ADOLC_parallel_doCopy) { - ADOLC_GLOBAL_TAPE_VARS.storeSize = globalTapeVars_s->storeSize; - ADOLC_GLOBAL_TAPE_VARS.numLives = globalTapeVars_s->numLives; - - ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = globalTapeVars_s->branchSwitchWarning; - - /* deleting the storemanager deletes the store too */ - delete ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr; - - ADOLC_GLOBAL_TAPE_VARS.store = new - double[ADOLC_GLOBAL_TAPE_VARS.storeSize]; - memcpy(ADOLC_GLOBAL_TAPE_VARS.store, globalTapeVars_s->store, - ADOLC_GLOBAL_TAPE_VARS.storeSize * sizeof(double)); - ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr = new - StoreManagerLocintBlock( - dynamic_cast(globalTapeVars_s->storeManagerPtr), - ADOLC_GLOBAL_TAPE_VARS.store, - ADOLC_GLOBAL_TAPE_VARS.storeSize, - ADOLC_GLOBAL_TAPE_VARS.numLives); - } + if (firstParallel) { + ADOLC_EXT_DIFF_FCTS_BUFFER.init(init_CpInfos); + + /* Use assignment operator instead of open coding + * this copies the store and the storemanager too + */ + ADOLC_GLOBAL_TAPE_VARS = *globalTapeVars_s; + + ADOLC_GLOBAL_TAPE_VARS.newTape = 0; + ADOLC_CURRENT_TAPE_INFOS.tapingComplete = 1; + ADOLC_GLOBAL_TAPE_VARS.currentTapeInfosPtr = NULL; + } else { + if (ADOLC_parallel_doCopy) { + ADOLC_GLOBAL_TAPE_VARS.storeSize = globalTapeVars_s->storeSize; + ADOLC_GLOBAL_TAPE_VARS.numLives = globalTapeVars_s->numLives; + + ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = + globalTapeVars_s->branchSwitchWarning; + + /* deleting the storemanager deletes the store too */ + delete ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr; + + ADOLC_GLOBAL_TAPE_VARS.store = + new double[ADOLC_GLOBAL_TAPE_VARS.storeSize]; + memcpy(ADOLC_GLOBAL_TAPE_VARS.store, globalTapeVars_s->store, + ADOLC_GLOBAL_TAPE_VARS.storeSize * sizeof(double)); + ADOLC_GLOBAL_TAPE_VARS.storeManagerPtr = new StoreManagerLocintBlock( + dynamic_cast( + globalTapeVars_s->storeManagerPtr), + ADOLC_GLOBAL_TAPE_VARS.store, ADOLC_GLOBAL_TAPE_VARS.storeSize, + ADOLC_GLOBAL_TAPE_VARS.numLives); } + } } /****************************************************************************/ @@ -1031,181 +989,187 @@ void beginParallel() { /* There are n+1 instances of ADOLC_OpenMP => n within the parallel region * and one in the serial part! */ void endParallel() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* do nothing if called at program exit (serial part) */ - if (ADOLC_threadNumber == 0 && - ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 0) return; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* do nothing if called at program exit (serial part) */ + if (ADOLC_threadNumber == 0 && ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 0) + return; + + ADOLC_GLOBAL_TAPE_VARS.inParallelRegion = 0; + + if (ADOLC_threadNumber == 0) { /* master only */ + int num; + int numThreads = omp_get_num_threads(); + bool firstIt = true; + do { /* wait until all slaves have left the parallel part */ + if (firstIt) + firstIt = false; + else + usleep(1000); /* no busy waiting */ + num = 1; + for (int i = 1; i < numThreads; ++i) + if (globalTapeVars[i].inParallelRegion == 0) + ++num; + } while (num != numThreads); + + firstParallel = false; + + revolve_numbers_p = revolve_numbers; + ADOLC_checkpointsStack_p = ADOLC_checkpointsStack; + ADOLC_extDiffFctsBuffer_p = ADOLC_extDiffFctsBuffer; + globalTapeVars_p = globalTapeVars; + currentTapeInfos_p = currentTapeInfos; + currentTapeInfos_fallBack_p = currentTapeInfos_fallBack; + tapeStack_p = tapeStack; + tapeInfosBuffer_p = tapeInfosBuffer; + + revolve_numbers = revolve_numbers_s; + ADOLC_checkpointsStack = ADOLC_checkpointsStack_s; + ADOLC_extDiffFctsBuffer = ADOLC_extDiffFctsBuffer_s; + globalTapeVars = globalTapeVars_s; + currentTapeInfos = currentTapeInfos_s; + currentTapeInfos_fallBack = currentTapeInfos_fallBack_s; + tapeStack = tapeStack_s; + tapeInfosBuffer = tapeInfosBuffer_s; ADOLC_GLOBAL_TAPE_VARS.inParallelRegion = 0; - - if (ADOLC_threadNumber == 0) { /* master only */ - int num; - int numThreads = omp_get_num_threads(); - bool firstIt = true; - do { /* wait until all slaves have left the parallel part */ - if (firstIt) firstIt = false; - else usleep(1000); /* no busy waiting */ - num = 1; - for (int i = 1; i < numThreads; ++i) - if (globalTapeVars[i].inParallelRegion == 0) ++num; - } while (num != numThreads); - - firstParallel = false; - - revolve_numbers_p = revolve_numbers; - ADOLC_checkpointsStack_p = ADOLC_checkpointsStack; - ADOLC_extDiffFctsBuffer_p = ADOLC_extDiffFctsBuffer; - globalTapeVars_p = globalTapeVars; - currentTapeInfos_p = currentTapeInfos; - currentTapeInfos_fallBack_p = currentTapeInfos_fallBack; - tapeStack_p = tapeStack; - tapeInfosBuffer_p = tapeInfosBuffer; - - revolve_numbers = revolve_numbers_s; - ADOLC_checkpointsStack = ADOLC_checkpointsStack_s; - ADOLC_extDiffFctsBuffer = ADOLC_extDiffFctsBuffer_s; - globalTapeVars = globalTapeVars_s; - currentTapeInfos = currentTapeInfos_s; - currentTapeInfos_fallBack = currentTapeInfos_fallBack_s; - tapeStack = tapeStack_s; - tapeInfosBuffer = tapeInfosBuffer_s; - - ADOLC_GLOBAL_TAPE_VARS.inParallelRegion = 0; - waitForMaster_begin = true; - waitForMaster_end = false; - } else - while (waitForMaster_end) { - usleep(1000); // no busy waiting - } + waitForMaster_begin = true; + waitForMaster_end = false; + } else + while (waitForMaster_end) { + usleep(1000); // no busy waiting + } } #endif /* _OPENMP */ -TapeInfos::TapeInfos() : pTapeInfos() { - initTapeInfos(this); -} +TapeInfos::TapeInfos() : pTapeInfos() { initTapeInfos(this); } TapeInfos::TapeInfos(short _tapeID) : pTapeInfos() { - initTapeInfos(this); - tapeID = _tapeID; - pTapeInfos.op_fileName = createFileName(tapeID, OPERATIONS_TAPE); - pTapeInfos.loc_fileName = createFileName(tapeID, LOCATIONS_TAPE); - pTapeInfos.val_fileName = createFileName(tapeID, VALUES_TAPE); - pTapeInfos.tay_fileName = NULL; + initTapeInfos(this); + tapeID = _tapeID; + pTapeInfos.op_fileName = createFileName(tapeID, OPERATIONS_TAPE); + pTapeInfos.loc_fileName = createFileName(tapeID, LOCATIONS_TAPE); + pTapeInfos.val_fileName = createFileName(tapeID, VALUES_TAPE); + pTapeInfos.tay_fileName = NULL; } -void TapeInfos::copy(const TapeInfos& tInfos) { - char *ptr, *end; - char const* tIptr = (char const*)(&tInfos.tapeID); +void TapeInfos::copy(const TapeInfos &tInfos) { + char *ptr, *end; + char const *tIptr = (char const *)(&tInfos.tapeID); - ptr = (char *)(&this->tapeID); - end = (char *)(&this->pTapeInfos); - for ( ; ptr != end ; ptr++, tIptr++ ) - *ptr = *tIptr; - pTapeInfos = tInfos.pTapeInfos; + ptr = (char *)(&this->tapeID); + end = (char *)(&this->pTapeInfos); + for (; ptr != end; ptr++, tIptr++) + *ptr = *tIptr; + pTapeInfos = tInfos.pTapeInfos; } PersistantTapeInfos::PersistantTapeInfos() { - char *ptr = (char*)(&forodec_nax), *end = (char*)(¶mstore); - for (; ptr != end ; ptr++ ) - *ptr = 0; - paramstore = NULL; + char *ptr = (char *)(&forodec_nax), *end = (char *)(¶mstore); + for (; ptr != end; ptr++) + *ptr = 0; + paramstore = NULL; } PersistantTapeInfos::~PersistantTapeInfos() { - if (jacSolv_nax) { - free(jacSolv_ci); - free(jacSolv_ri); - myfree1(jacSolv_xold); - myfreeI2(jacSolv_nax, jacSolv_I); - myfree2(jacSolv_J); - jacSolv_nax = 0; - } - if (forodec_nax) { - myfree1(forodec_y); - myfree1(forodec_z); - myfree2(forodec_Z); - forodec_nax = 0; - } - if (paramstore != NULL) { - free(paramstore); - paramstore = NULL; - } + if (jacSolv_nax) { + free(jacSolv_ci); + free(jacSolv_ri); + myfree1(jacSolv_xold); + myfreeI2(jacSolv_nax, jacSolv_I); + myfree2(jacSolv_J); + jacSolv_nax = 0; + } + if (forodec_nax) { + myfree1(forodec_y); + myfree1(forodec_z); + myfree2(forodec_Z); + forodec_nax = 0; + } + if (paramstore != NULL) { + free(paramstore); + paramstore = NULL; + } } void enableMinMaxUsingAbs() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (!isTaping()) - ADOLC_GLOBAL_TAPE_VARS.nominmaxFlag = 1; - else - fprintf(DIAG_OUT, "ADOL-C warning: " - "change from native Min/Max to using Abs during tracing " - "will lead to inconsistent results, not changing behaviour now\n" - " " - "call %s before trace_on(tape_id) for the correct behaviour\n" - ,__FUNCTION__); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (!isTaping()) + ADOLC_GLOBAL_TAPE_VARS.nominmaxFlag = 1; + else + fprintf(DIAG_OUT, + "ADOL-C warning: " + "change from native Min/Max to using Abs during tracing " + "will lead to inconsistent results, not changing behaviour now\n" + " " + "call %s before trace_on(tape_id) for the correct behaviour\n", + __FUNCTION__); } void disableMinMaxUsingAbs() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (!isTaping()) - ADOLC_GLOBAL_TAPE_VARS.nominmaxFlag = 0; - else - fprintf(DIAG_OUT, "ADOL-C warning: " - "change from native Min/Max to using Abs during tracing " - "will lead to inconsistent results, not changing behaviour now\n" - " " - "call %s after trace_off() for the correct behaviour\n" - ,__FUNCTION__); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (!isTaping()) + ADOLC_GLOBAL_TAPE_VARS.nominmaxFlag = 0; + else + fprintf(DIAG_OUT, + "ADOL-C warning: " + "change from native Min/Max to using Abs during tracing " + "will lead to inconsistent results, not changing behaviour now\n" + " " + "call %s after trace_off() for the correct behaviour\n", + __FUNCTION__); } #include -void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line) { - throw FatalError(errorcode, what, function, file, line); +void adolc_exit(int errorcode, const char *what, const char *function, + const char *file, int line) { + throw FatalError(errorcode, what, function, file, line); } /* Only called during stop_trace() via save_params() */ void free_all_taping_params() { - size_t np; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + size_t np; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - np = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; - while ( np > 0 ) - ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->free_loc(--np); + np = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; + while (np > 0) + ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->free_loc(--np); } void GlobalTapeVarsCL::reallocStore(unsigned char type) { - if (storeManagerPtr != NULL) - delete storeManagerPtr; + if (storeManagerPtr != NULL) + delete storeManagerPtr; - store = NULL; + store = NULL; #if defined(ADOLC_TRACK_ACTIVITY) - actStore = NULL; + actStore = NULL; #endif - storeSize = 0; - numLives = 0; - switch (type) { - case ADOLC_LOCATION_BLOCKS: + storeSize = 0; + numLives = 0; + switch (type) { + case ADOLC_LOCATION_BLOCKS: #if defined(ADOLC_TRACK_ACTIVITY) - storeManagerPtr = new StoreManagerLocintBlock(store, actStore, storeSize, numLives); + storeManagerPtr = + new StoreManagerLocintBlock(store, actStore, storeSize, numLives); #else - storeManagerPtr = new StoreManagerLocintBlock(store, storeSize, numLives); + storeManagerPtr = new StoreManagerLocintBlock(store, storeSize, numLives); #endif - break; - case ADOLC_LOCATION_SINGLETONS: + break; + case ADOLC_LOCATION_SINGLETONS: #if defined(ADOLC_TRACK_ACTIVITY) - storeManagerPtr = new StoreManagerLocint(store, actStore, storeSize, numLives); + storeManagerPtr = + new StoreManagerLocint(store, actStore, storeSize, numLives); #else - storeManagerPtr = new StoreManagerLocint(store, storeSize, numLives); + storeManagerPtr = new StoreManagerLocint(store, storeSize, numLives); #endif - break; - } + break; + } } diff --git a/ADOL-C/src/tapedoc/tapedoc.c b/ADOL-C/src/tapedoc/tapedoc.c index c2abd59f5..630173ed7 100644 --- a/ADOL-C/src/tapedoc/tapedoc.c +++ b/ADOL-C/src/tapedoc/tapedoc.c @@ -2,30 +2,30 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: tapedoc/tapedoc.c Revision: $Id$ - Contents: Routine tape_doc(..) writes the taped operations in LaTeX-code + Contents: Routine tape_doc(..) writes the taped operations in LaTeX-code to the file tape_doc.tex - - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#include +#include "dvlparms.h" #include "oplate.h" #include "taping_p.h" #include -#include "dvlparms.h" +#include #include #include #ifdef ADOLC_AMPI_SUPPORT -#include "ampi/ampi.h" -#include "ampi/tape/support.h" + #include "ampi/ampi.h" + #include "ampi/tape/support.h" #endif BEGIN_C_DECLS @@ -41,1525 +41,1565 @@ static int rev_op_cnt; static int pagelength; static FILE *fp; -static char baseName[]="tape_"; -static char extension[]=".tex"; +static char baseName[] = "tape_"; +static char extension[] = ".tex"; /****************************************************************************/ /* LOCAL WRITE ROUTINES */ /*--------------------------------------------------------------------------*/ -void filewrite_start( int opcode ) { - char *fileName; - int num; - - fileName=(char *)malloc(sizeof(char)*(9+sizeof(tag)*8+2)); - if (fileName==NULL) fail(ADOLC_MALLOC_FAILED); - strncpy(fileName, baseName, strlen(baseName)); - num=sprintf(fileName+strlen(baseName), "%d", tag); - strncpy(fileName+strlen(baseName)+num, extension, strlen(extension)); - fileName[strlen(baseName)+num+strlen(extension)]=0; - if ((fp = fopen(fileName,"w")) == NULL) { - fprintf(DIAG_OUT,"cannot open file !\n"); - adolc_exit(1,"",__func__,__FILE__,__LINE__); - } - free((void*)fileName); - fprintf(fp,"\\documentclass{article}\n"); - fprintf(fp,"\\headheight0cm\n"); - fprintf(fp,"\\headsep-1cm\n"); - fprintf(fp,"\\textheight25cm\n"); - fprintf(fp,"\\oddsidemargin-1cm\n"); - fprintf(fp,"\\topmargin0cm\n"); - fprintf(fp,"\\textwidth18cm\n"); - fprintf(fp,"\\begin{document}\n"); - fprintf(fp,"\\tiny\n"); +void filewrite_start(int opcode) { + char *fileName; + int num; + + fileName = (char *)malloc(sizeof(char) * (9 + sizeof(tag) * 8 + 2)); + if (fileName == NULL) + fail(ADOLC_MALLOC_FAILED); + strncpy(fileName, baseName, strlen(baseName)); + num = sprintf(fileName + strlen(baseName), "%d", tag); + strncpy(fileName + strlen(baseName) + num, extension, strlen(extension)); + fileName[strlen(baseName) + num + strlen(extension)] = 0; + if ((fp = fopen(fileName, "w")) == NULL) { + fprintf(DIAG_OUT, "cannot open file !\n"); + adolc_exit(1, "", __func__, __FILE__, __LINE__); + } + free((void *)fileName); + fprintf(fp, "\\documentclass{article}\n"); + fprintf(fp, "\\headheight0cm\n"); + fprintf(fp, "\\headsep-1cm\n"); + fprintf(fp, "\\textheight25cm\n"); + fprintf(fp, "\\oddsidemargin-1cm\n"); + fprintf(fp, "\\topmargin0cm\n"); + fprintf(fp, "\\textwidth18cm\n"); + fprintf(fp, "\\begin{document}\n"); + fprintf(fp, "\\tiny\n"); #ifdef ADOLC_TAPE_DOC_VALUES - fprintf(fp,"\\begin{tabular}{|r|r|r|l|r|r|r|r||r|r||r|r|r|r|} \\hline \n"); - fprintf(fp," & & code & op & loc & loc & loc & loc & double & double & value & value & value & value \\\\ \\hline \n"); - fprintf(fp," & & %i & start of tape & & & & & & & & & & \\\\ \\hline \n",opcode); + fprintf(fp, "\\begin{tabular}{|r|r|r|l|r|r|r|r||r|r||r|r|r|r|} \\hline \n"); + fprintf(fp, " & & code & op & loc & loc & loc & loc & double & double & " + "value & value & value & value \\\\ \\hline \n"); + fprintf(fp, " & & %i & start of tape & & & & & & & & & & \\\\ \\hline \n", + opcode); #else - fprintf(fp,"\\begin{tabular}{|r|r|r|l|r|r|r|r||r|r|} \\hline \n"); - fprintf(fp," & & code & op & loc & loc & loc & loc & double & double \\\\ \\hline \n"); - fprintf(fp," & & %i & start of tape & & & & & & \\\\ \\hline \n",opcode); + fprintf(fp, "\\begin{tabular}{|r|r|r|l|r|r|r|r||r|r|} \\hline \n"); + fprintf(fp, " & & code & op & loc & loc & loc & loc & double & double \\\\ " + "\\hline \n"); + fprintf(fp, " & & %i & start of tape & & & & & & \\\\ \\hline \n", opcode); #endif - pagelength = 0; + pagelength = 0; } -void checkPageBreak() { - if (pagelength == 100) { /* 101 lines per page */ - fprintf(fp,"\\end{tabular}\\\\\n"); - fprintf(fp,"\\newpage\n"); +void checkPageBreak() { + if (pagelength == 100) { /* 101 lines per page */ + fprintf(fp, "\\end{tabular}\\\\\n"); + fprintf(fp, "\\newpage\n"); #ifdef ADOLC_TAPE_DOC_VALUES - fprintf(fp,"\\begin{tabular}{|r|r|r|l|r|r|r|r||r|r||r|r|r|r|} \\hline \n"); - fprintf(fp," & & code & op & loc & loc & loc & loc & double & double & value & value & value & value \\\\ \\hline \n"); + fprintf(fp, "\\begin{tabular}{|r|r|r|l|r|r|r|r||r|r||r|r|r|r|} \\hline \n"); + fprintf(fp, " & & code & op & loc & loc & loc & loc & double & double & " + "value & value & value & value \\\\ \\hline \n"); #else - fprintf(fp,"\\begin{tabular}{|r|r|r|l|r|r|r|r||r|r|} \\hline \n"); - fprintf(fp," & & code & op & loc & loc & loc & loc & double & double \\\\ \\hline \n"); + fprintf(fp, "\\begin{tabular}{|r|r|r|l|r|r|r|r||r|r|} \\hline \n"); + fprintf(fp, " & & code & op & loc & loc & loc & loc & double & double \\\\ " + "\\hline \n"); #endif - pagelength=-1; - } -} + pagelength = -1; + } +} /****************************************************************************/ -/* filewrite( opcode number, op name, number locations, locations, values, */ +/* filewrite( opcode number, op name, number locations, locations, values, */ /* number constants, constants ) */ /****************************************************************************/ -void filewrite( unsigned short opcode, const char* opString, int nloc, int *loc, - double *val,int ncst, double* cst) { - int i; - - checkPageBreak(); - - /* write opcode counters and number */ - fprintf(fp,"%i & %i & %i & ",op_cnt, rev_op_cnt, opcode); - - /* write opcode name if available */ - if (opString) fprintf(fp,"%s",opString); - - /* write locations (max 4) right-justified */ - fprintf(fp," &"); - if (opcode==ext_diff || opcode==ext_diff_iArr || opcode==ext_diff_v2) - opcode = ext_diff; - if (opcode!=ext_diff) { /* default */ - for(i=0; i<(4-nloc); i++) - fprintf(fp," &"); - for(i=0; i>=) */ - res = get_locint_f(); - loc_a[0]=res; + /*--------------------------------------------------------------------------*/ + case assign_dep: /* assign a float variable a assign_dep */ + /* dependent adouble value. (>>=) */ + res = get_locint_f(); + loc_a[0] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[res]; - valuepoint[indexd++]=dp_T0[res]; -#endif - filewrite(operation,"assign dep",1,loc_a,val_a,0,cst_d); - break; - - - /****************************************************************************/ - /* OPERATION + ASSIGNMENT */ - - /*--------------------------------------------------------------------------*/ - case eq_plus_d: /* Add a floating point to an eq_plus_d */ - /* adouble. (+=) */ - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[res]; + valuepoint[indexd++] = dp_T0[res]; +#endif + filewrite(operation, "assign dep", 1, loc_a, val_a, 0, cst_d); + break; + + /****************************************************************************/ + /* OPERATION + + * ASSIGNMENT */ + + /*--------------------------------------------------------------------------*/ + case eq_plus_d: /* Add a floating point to an eq_plus_d */ + /* adouble. (+=) */ + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - dp_T0[res] += coval; - val_a[0] = dp_T0[res]; -#endif - filewrite(operation,"eq plus d",1,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case eq_plus_a: /* Add an adouble to another eq_plus_a */ - /* adouble. (+=) */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + dp_T0[res] += coval; + val_a[0] = dp_T0[res]; +#endif + filewrite(operation, "eq plus d", 1, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case eq_plus_a: /* Add an adouble to another eq_plus_a */ + /* adouble. (+=) */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]+= dp_T0[arg]; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"eq plus a",2,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case eq_plus_prod: /* Add an product to an eq_plus_prod */ - /* adouble. (+= x1*x2) */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] += dp_T0[arg]; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "eq plus a", 2, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case eq_plus_prod: /* Add an product to an eq_plus_prod */ + /* adouble. (+= x1*x2) */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - val_a[1]=dp_T0[arg2]; - dp_T0[res] += dp_T0[arg1]*dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"eq plus prod",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case eq_min_d: /* Subtract a floating point from an eq_min_d */ - /* adouble. (-=) */ - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg1]; + val_a[1] = dp_T0[arg2]; + dp_T0[res] += dp_T0[arg1] * dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "eq plus prod", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case eq_min_d: /* Subtract a floating point from an eq_min_d */ + /* adouble. (-=) */ + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - dp_T0[res] -= coval; - val_a[0] = dp_T0[res]; -#endif - filewrite(operation,"eq min d",1,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case eq_min_a: /* Subtract an adouble from another eq_min_a */ - /* adouble. (-=) */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + dp_T0[res] -= coval; + val_a[0] = dp_T0[res]; +#endif + filewrite(operation, "eq min d", 1, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case eq_min_a: /* Subtract an adouble from another eq_min_a */ + /* adouble. (-=) */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]-= dp_T0[arg]; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"eq min a",2,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case eq_min_prod: /* Subtract an product from an eq_min_prod */ - /* adouble. (+= x1*x2) */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] -= dp_T0[arg]; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "eq min a", 2, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case eq_min_prod: /* Subtract an product from an eq_min_prod */ + /* adouble. (+= x1*x2) */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - val_a[1]=dp_T0[arg2]; - dp_T0[res] -= dp_T0[arg1]*dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"eq min prod",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case eq_mult_d: /* Multiply an adouble by a eq_mult_d */ - /* flaoting point. (*=) */ - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg1]; + val_a[1] = dp_T0[arg2]; + dp_T0[res] -= dp_T0[arg1] * dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "eq min prod", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case eq_mult_d: /* Multiply an adouble by a eq_mult_d */ + /* flaoting point. (*=) */ + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - dp_T0[res] *= coval; - val_a[0] = dp_T0[res]; -#endif - filewrite(operation,"eq mult d",1,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case eq_mult_a: /* Multiply one adouble by another eq_mult_a */ - /* (*=) */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + dp_T0[res] *= coval; + val_a[0] = dp_T0[res]; +#endif + filewrite(operation, "eq mult d", 1, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case eq_mult_a: /* Multiply one adouble by another eq_mult_a */ + /* (*=) */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]*= dp_T0[arg]; - val_a[1]=dp_T0[res]; + val_a[0] = dp_T0[arg]; + dp_T0[res] *= dp_T0[arg]; + val_a[1] = dp_T0[res]; #endif - filewrite(operation,"eq mult a",2,loc_a,val_a,0,cst_d); - break; + filewrite(operation, "eq mult a", 2, loc_a, val_a, 0, cst_d); + break; - /*--------------------------------------------------------------------------*/ - case incr_a: /* Increment an adouble incr_a */ - res = get_locint_f(); - loc_a[0] = res; + /*--------------------------------------------------------------------------*/ + case incr_a: /* Increment an adouble incr_a */ + res = get_locint_f(); + loc_a[0] = res; #ifdef ADOLC_TAPE_DOC_VALUES - dp_T0[res]++; - val_a[0] = dp_T0[res]; + dp_T0[res]++; + val_a[0] = dp_T0[res]; #endif - filewrite(operation,"incr a",1,loc_a,val_a,0,cst_d); - break; + filewrite(operation, "incr a", 1, loc_a, val_a, 0, cst_d); + break; - /*--------------------------------------------------------------------------*/ - case decr_a: /* Increment an adouble decr_a */ - res = get_locint_f(); - loc_a[0] = res; + /*--------------------------------------------------------------------------*/ + case decr_a: /* Increment an adouble decr_a */ + res = get_locint_f(); + loc_a[0] = res; #ifdef ADOLC_TAPE_DOC_VALUES - dp_T0[res]--; - val_a[0] = dp_T0[res]; -#endif - filewrite(operation,"decr a",1,loc_a,val_a,0,cst_d); - break; - - - /****************************************************************************/ - /* BINARY OPERATIONS */ - - /*--------------------------------------------------------------------------*/ - case plus_a_a: /* : Add two adoubles. (+) plus a_a */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + dp_T0[res]--; + val_a[0] = dp_T0[res]; +#endif + filewrite(operation, "decr a", 1, loc_a, val_a, 0, cst_d); + break; + + /****************************************************************************/ + /* BINARY + * OPERATIONS */ + + /*--------------------------------------------------------------------------*/ + case plus_a_a: /* : Add two adoubles. (+) plus a_a */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - val_a[1]=dp_T0[arg2]; - dp_T0[res]=dp_T0[arg1]+dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"plus a a",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case plus_d_a: /* Add an adouble and a double plus_d_a */ - /* (+) */ - arg = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = arg; - loc_a[1] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg1]; + val_a[1] = dp_T0[arg2]; + dp_T0[res] = dp_T0[arg1] + dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "plus a a", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case plus_d_a: /* Add an adouble and a double plus_d_a */ + /* (+) */ + arg = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]= dp_T0[arg] + coval; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"plus d a",2,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case min_a_a: /* Subtraction of two adoubles min_a_a */ - /* (-) */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = dp_T0[arg] + coval; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "plus d a", 2, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case min_a_a: /* Subtraction of two adoubles min_a_a */ + /* (-) */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - val_a[1]=dp_T0[arg2]; - dp_T0[res]=dp_T0[arg1]-dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"min a a",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case min_d_a: /* Subtract an adouble from a min_d_a */ - /* double (-) */ - arg = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = arg; - loc_a[1] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg1]; + val_a[1] = dp_T0[arg2]; + dp_T0[res] = dp_T0[arg1] - dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "min a a", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case min_d_a: /* Subtract an adouble from a min_d_a */ + /* double (-) */ + arg = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0] = dp_T0[arg]; - dp_T0[res] = coval - dp_T0[arg]; - val_a[1] = dp_T0[res]; -#endif - filewrite(operation,"min d a",2,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case mult_a_a: /* Multiply two adoubles (*) mult_a_a */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = coval - dp_T0[arg]; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "min d a", 2, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case mult_a_a: /* Multiply two adoubles (*) mult_a_a */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - val_a[1]=dp_T0[arg2]; - dp_T0[res]=dp_T0[arg1]*dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"mult a a",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case mult_d_a: /* Multiply an adouble by a double mult_d_a */ - /* (*) */ - arg = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = arg; - loc_a[1] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg1]; + val_a[1] = dp_T0[arg2]; + dp_T0[res] = dp_T0[arg1] * dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "mult a a", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case mult_d_a: /* Multiply an adouble by a double mult_d_a */ + /* (*) */ + arg = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0] = dp_T0[arg]; - dp_T0[res] = coval * dp_T0[arg]; - val_a[1] = dp_T0[res]; -#endif - filewrite(operation,"mult d a",2,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case div_a_a: /* Divide an adouble by an adouble div_a_a */ - /* (/) */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = coval * dp_T0[arg]; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "mult d a", 2, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case div_a_a: /* Divide an adouble by an adouble div_a_a */ + /* (/) */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - val_a[1]=dp_T0[arg2]; - dp_T0[res]=dp_T0[arg1]/dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"div a a",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case div_d_a: /* Division double - adouble (/) div_d_a */ - arg = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = arg; - loc_a[1] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg1]; + val_a[1] = dp_T0[arg2]; + dp_T0[res] = dp_T0[arg1] / dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "div a a", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case div_d_a: /* Division double - adouble (/) div_d_a */ + arg = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0] = dp_T0[arg]; - dp_T0[res] = coval / dp_T0[arg]; - val_a[1] = dp_T0[res]; -#endif - filewrite(operation,"div d a",2,loc_a,val_a,1,cst_d); - break; - - - /****************************************************************************/ - /* SIGN OPERATIONS */ - - /*--------------------------------------------------------------------------*/ - case pos_sign_a: /* pos_sign_a */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = coval / dp_T0[arg]; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "div d a", 2, loc_a, val_a, 1, cst_d); + break; + + /****************************************************************************/ + /* SIGN OPERATIONS + */ + + /*--------------------------------------------------------------------------*/ + case pos_sign_a: /* pos_sign_a */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]= dp_T0[arg]; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"pos sign a",2,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case neg_sign_a: /* neg_sign_a */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = dp_T0[arg]; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "pos sign a", 2, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case neg_sign_a: /* neg_sign_a */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]= -dp_T0[arg]; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"neg sign a",2,loc_a,val_a,0,cst_d); - break; - - - /****************************************************************************/ - /* UNARY OPERATIONS */ - - /*--------------------------------------------------------------------------*/ - case exp_op: /* exponent operation exp_op */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = -dp_T0[arg]; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "neg sign a", 2, loc_a, val_a, 0, cst_d); + break; + + /****************************************************************************/ + /* UNARY + * OPERATIONS */ + + /*--------------------------------------------------------------------------*/ + case exp_op: /* exponent operation exp_op */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]= exp(dp_T0[arg]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"exp op",2,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case sin_op: /* sine operation sin_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = exp(dp_T0[arg]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "exp op", 2, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case sin_op: /* sine operation sin_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - /* olvo 980923 changed order to allow x=sin(x) */ - val_a[0]=dp_T0[arg1]; - dp_T0[arg2]= cos(dp_T0[arg1]); - dp_T0[res] = sin(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"sin op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case cos_op: /* cosine operation cos_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + /* olvo 980923 changed order to allow x=sin(x) */ + val_a[0] = dp_T0[arg1]; + dp_T0[arg2] = cos(dp_T0[arg1]); + dp_T0[res] = sin(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "sin op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case cos_op: /* cosine operation cos_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - /* olvo 980923 changed order to allow x=cos(x) */ - val_a[0]=dp_T0[arg1]; - dp_T0[arg2]= sin(dp_T0[arg1]); - dp_T0[res] = cos(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"cos op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case atan_op: /* atan_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + /* olvo 980923 changed order to allow x=cos(x) */ + val_a[0] = dp_T0[arg1]; + dp_T0[arg2] = sin(dp_T0[arg1]); + dp_T0[res] = cos(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "cos op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case atan_op: /* atan_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = atan(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"atan op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case asin_op: /* asin_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = atan(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "atan op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case asin_op: /* asin_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = asin(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"asin op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case acos_op: /* acos_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = asin(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "asin op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case acos_op: /* acos_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = acos(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"acos op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case asinh_op: /* asinh_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = acos(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "acos op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case asinh_op: /* asinh_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = asinh(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"asinh op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case acosh_op: /* acosh_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = asinh(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "asinh op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case acosh_op: /* acosh_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = acosh(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"acosh op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case atanh_op: /* atanh_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = acosh(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "acosh op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case atanh_op: /* atanh_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = atanh(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"atanh op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case erf_op: /* erf_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = atanh(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "atanh op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case erf_op: /* erf_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = erf(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"erf op",3,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case erfc_op: /* erfc_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = erf(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "erf op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case erfc_op: /* erfc_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = erfc(dp_T0[arg1]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"erfc op",3,loc_a,val_a,0,cst_d); - break; - - - /*--------------------------------------------------------------------------*/ - case log_op: /* log_op */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = erfc(dp_T0[arg1]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "erfc op", 3, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case log_op: /* log_op */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]= log(dp_T0[arg]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"log op",2,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case pow_op: /* pow_op */ - arg = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - cst_d[0]=coval; - loc_a[0]=arg; - loc_a[1]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = log(dp_T0[arg]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "log op", 2, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case pow_op: /* pow_op */ + arg = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + cst_d[0] = coval; + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res] = pow(dp_T0[arg],coval); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"pow op",2,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case sqrt_op: /* sqrt_op */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = pow(dp_T0[arg], coval); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "pow op", 2, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case sqrt_op: /* sqrt_op */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]= sqrt(dp_T0[arg]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"sqrt op",2,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case cbrt_op: /* cbrt_op */ - arg = get_locint_f(); - res = get_locint_f(); - loc_a[0]=arg; - loc_a[1]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = sqrt(dp_T0[arg]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "sqrt op", 2, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case cbrt_op: /* cbrt_op */ + arg = get_locint_f(); + res = get_locint_f(); + loc_a[0] = arg; + loc_a[1] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - dp_T0[res]= cbrt(dp_T0[arg]); - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; - val_a[1]=dp_T0[res]; -#endif - filewrite(operation,"cbrt op",2,loc_a,val_a,0,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case gen_quad: /* gen_quad */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - cst_d[0] = get_val_f(); - cst_d[1] = get_val_f(); - loc_a[0]=arg1; - loc_a[1]=arg2; - loc_a[2]=res; + val_a[0] = dp_T0[arg]; + dp_T0[res] = cbrt(dp_T0[arg]); + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "cbrt op", 2, loc_a, val_a, 0, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case gen_quad: /* gen_quad */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + cst_d[0] = get_val_f(); + cst_d[1] = get_val_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg1]; - dp_T0[res] = cst_d[1]; - val_a[1]=dp_T0[arg2]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"gen quad",3,loc_a,val_a,2,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case min_op: /* min_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = arg1; - loc_a[1] = arg2; - loc_a[2] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg1]; + dp_T0[res] = cst_d[1]; + val_a[1] = dp_T0[arg2]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "gen quad", 3, loc_a, val_a, 2, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case min_op: /* min_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg1; + loc_a[1] = arg2; + loc_a[2] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0] = dp_T0[arg1]; - val_a[1] = dp_T0[arg2]; - if (dp_T0[arg1] > dp_T0[arg2]) - dp_T0[res] = dp_T0[arg2]; - else - dp_T0[res] = dp_T0[arg1]; - val_a[2] = dp_T0[res]; -#endif - filewrite(operation,"min op",3,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case abs_val: /* abs_val */ - arg = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = arg; - loc_a[1] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg1]; + val_a[1] = dp_T0[arg2]; + if (dp_T0[arg1] > dp_T0[arg2]) + dp_T0[res] = dp_T0[arg2]; + else + dp_T0[res] = dp_T0[arg1]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "min op", 3, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case abs_val: /* abs_val */ + arg = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0] = dp_T0[arg]; - dp_T0[res] = fabs(dp_T0[arg]); - val_a[1] = dp_T0[res]; -#endif - filewrite(operation,"abs val",2,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case ceil_op: /* ceil_op */ - arg = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = arg; - loc_a[1] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg]; + dp_T0[res] = fabs(dp_T0[arg]); + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "abs val", 2, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case ceil_op: /* ceil_op */ + arg = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0] = dp_T0[arg]; - dp_T0[res] = ceil(dp_T0[arg]); - val_a[1] = dp_T0[res]; -#endif - filewrite(operation,"ceil op",2,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case floor_op: /* Compute ceil of adouble floor_op */ - arg = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0] = arg; - loc_a[1] = res; - cst_d[0] = coval; + val_a[0] = dp_T0[arg]; + dp_T0[res] = ceil(dp_T0[arg]); + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "ceil op", 2, loc_a, val_a, 1, cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case floor_op: /* Compute ceil of adouble floor_op */ + arg = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0] = dp_T0[arg]; - dp_T0[res] = floor(dp_T0[arg]); - val_a[1] = dp_T0[res]; -#endif - filewrite(operation,"floor op",2,loc_a,val_a,1,cst_d); - break; - - - /****************************************************************************/ - /* CONDITIONALS */ - - /*--------------------------------------------------------------------------*/ - case cond_assign: /* cond_assign */ - arg = get_locint_f(); - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0]=arg; - loc_a[1]=arg1; - loc_a[2]=arg2 ; - loc_a[3]=res; - cst_d[0]=coval; + val_a[0] = dp_T0[arg]; + dp_T0[res] = floor(dp_T0[arg]); + val_a[1] = dp_T0[res]; +#endif + filewrite(operation, "floor op", 2, loc_a, val_a, 1, cst_d); + break; + + /****************************************************************************/ + /* CONDITIONALS + */ + + /*--------------------------------------------------------------------------*/ + case cond_assign: /* cond_assign */ + arg = get_locint_f(); + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = arg1; + loc_a[2] = arg2; + loc_a[3] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - val_a[1]=dp_T0[arg1]; - val_a[2]=dp_T0[arg2]; - if (dp_T0[arg]>0) - dp_T0[res]=dp_T0[arg1]; - else - dp_T0[res]=dp_T0[arg2]; - val_a[3]=dp_T0[res]; -#endif - filewrite(operation,"cond assign $\\longrightarrow$",4,loc_a,val_a,1,cst_d); - break; - - /*--------------------------------------------------------------------------*/ - case cond_assign_s: /* cond_assign_s */ - arg = get_locint_f(); - arg1 = get_locint_f(); - res = get_locint_f(); - coval = get_val_f(); - loc_a[0]=arg; - loc_a[1]=arg1; - loc_a[2]=res; - cst_d[0]=coval; + val_a[0] = dp_T0[arg]; + val_a[1] = dp_T0[arg1]; + val_a[2] = dp_T0[arg2]; + if (dp_T0[arg] > 0) + dp_T0[res] = dp_T0[arg1]; + else + dp_T0[res] = dp_T0[arg2]; + val_a[3] = dp_T0[res]; +#endif + filewrite(operation, "cond assign $\\longrightarrow$", 4, loc_a, val_a, 1, + cst_d); + break; + + /*--------------------------------------------------------------------------*/ + case cond_assign_s: /* cond_assign_s */ + arg = get_locint_f(); + arg1 = get_locint_f(); + res = get_locint_f(); + coval = get_val_f(); + loc_a[0] = arg; + loc_a[1] = arg1; + loc_a[2] = res; + cst_d[0] = coval; #ifdef ADOLC_TAPE_DOC_VALUES - val_a[0]=dp_T0[arg]; - val_a[1]=dp_T0[arg1]; - if (dp_T0[arg]>0) - dp_T0[res]=dp_T0[arg1]; - val_a[2]=dp_T0[res]; -#endif - filewrite(operation,"cond assign s $\\longrightarrow$",3,loc_a,val_a,1,cst_d); - break; - - case vec_copy: - res = get_locint_f(); - arg = get_locint_f(); - size = get_locint_f(); - loc_a[0] = res; - loc_a[1] = arg; - loc_a[2] = size; + val_a[0] = dp_T0[arg]; + val_a[1] = dp_T0[arg1]; + if (dp_T0[arg] > 0) + dp_T0[res] = dp_T0[arg1]; + val_a[2] = dp_T0[res]; +#endif + filewrite(operation, "cond assign s $\\longrightarrow$", 3, loc_a, val_a, + 1, cst_d); + break; + + case vec_copy: + res = get_locint_f(); + arg = get_locint_f(); + size = get_locint_f(); + loc_a[0] = res; + loc_a[1] = arg; + loc_a[2] = size; #ifdef ADOLC_TAPE_DOC_VALUES - for(qq=0;qq0) { - loc_a[size++] = get_locint_f(); /* rbuf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* rcnt */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ - } - loc_a[size++]=get_locint_f(); /* buf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* count */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ - TAPE_AMPI_read_int(loc_a+size++); /* root */ - TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); - TAPE_AMPI_read_int(loc_a+0); /* commSizeForRootOrNull */ - filewrite_ampi(operation, "ampi gather",size, loc_a); - break; - - case ampi_scatter: - size=0; - TAPE_AMPI_read_int(loc_a+size++); /* commSizeForRootOrNull */ - if (*(loc_a+0)>0) { - loc_a[size++] = get_locint_f(); /* rbuf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* rcnt */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ - } - loc_a[size++]=get_locint_f(); /* buf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* count */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ - TAPE_AMPI_read_int(loc_a+size++); /* root */ - TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); - TAPE_AMPI_read_int(loc_a+0); /* commSizeForRootOrNull */ - filewrite_ampi(operation, "ampi scatter",size, loc_a); - break; - - case ampi_allgather: - TAPE_AMPI_read_int(loc_a+1); /* commSizeForRootOrNull */ - if (*(loc_a+1)>0) { - TAPE_AMPI_read_int(loc_a+2); /* rcnt */ - loc_a[2] = get_locint_f(); /* rbuf loc */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ - } - TAPE_AMPI_read_int(loc_a+3); /* count */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ - TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); - TAPE_AMPI_read_int(loc_a+1); /* commSizeForRootOrNull */ - filewrite_ampi(operation, "ampi allgather",4, loc_a); - break; - - case ampi_gatherv: - size=0; - TAPE_AMPI_read_int(loc_a+size++); /* commSizeForRootOrNull */ - if (*(loc_a+0)>0) { - loc_a[size++] = get_locint_f(); /* rbuf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* rcnt[0] */ - TAPE_AMPI_read_int(loc_a+size++); /* displs[0] */ - } - for (l=1;l<*(loc_a+0);++l) { - TAPE_AMPI_read_int(loc_a+size); - TAPE_AMPI_read_int(loc_a+size); - } - if (*(loc_a+0)>0) { - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ - } - loc_a[size++] = get_locint_f(); /* buf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* count */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ - TAPE_AMPI_read_int(loc_a+size++); /* root */ - TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); - TAPE_AMPI_read_int(loc_a+0); /* commSizeForRootOrNull */ - filewrite_ampi(operation, "ampi gatherv",size, loc_a); - break; - - case ampi_scatterv: - size=0; - TAPE_AMPI_read_int(loc_a+size++); /* commSizeForRootOrNull */ - if (*(loc_a+0)>0) { - loc_a[size++] = get_locint_f(); /* rbuf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* rcnt[0] */ - TAPE_AMPI_read_int(loc_a+size++); /* displs[0] */ - } - for (l=1;l<*(loc_a+0);++l) { - TAPE_AMPI_read_int(loc_a+size); - TAPE_AMPI_read_int(loc_a+size); - } - if (*(loc_a+0)>0) { - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ - } - loc_a[size++] = get_locint_f(); /* buf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* count */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ - TAPE_AMPI_read_int(loc_a+size++); /* root */ - TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); - TAPE_AMPI_read_int(loc_a+0); /* commSizeForRootOrNull */ - filewrite_ampi(operation, "ampi scatterv",size, loc_a); - break; - - case ampi_allgatherv: - size=0; - TAPE_AMPI_read_int(loc_a+size++); /* commSizeForRootOrNull */ - for (l=0;l<*(loc_a);++l) { - TAPE_AMPI_read_int(loc_a+size); /* rcnts */ - TAPE_AMPI_read_int(loc_a+size+1); /* displs */ - } - if (*(loc_a)>0) { - size+=2; - loc_a[size++] = get_locint_f(); /* rbuf loc */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ - } - loc_a[size++] = get_locint_f(); /* buf loc */ - TAPE_AMPI_read_int(loc_a+size++); /* count */ - TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ - TAPE_AMPI_read_int(loc_a+size++); /* root */ - TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); - TAPE_AMPI_read_int(loc_a); /* commSizeForRootOrNull */ - filewrite_ampi(operation, "ampi allgatherv",size, loc_a); - break; -#endif - /*--------------------------------------------------------------------------*/ - default: /* default */ - /* Die here, we screwed up */ - fprintf(DIAG_OUT,"ADOL-C error: Fatal error in tape_doc for op %d\n", - operation); - break; - - } /* endswitch */ - - /* Read the next operation */ - operation=get_op_f(); - ++op_cnt; - --rev_op_cnt; - } /* endwhile */ - - if (operation == end_of_tape) { - filewrite_end(operation); - }; - - if (dp_T0) free(dp_T0); - dp_T0 = NULL; - - end_sweep(); -} /* end tape_doc */ + case ampi_send: + loc_a[0] = get_locint_f(); /* start loc */ + TAPE_AMPI_read_int(loc_a + 1); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); + TAPE_AMPI_read_int(loc_a + 2); /* endpoint */ + TAPE_AMPI_read_int(loc_a + 3); /* tag */ + TAPE_AMPI_read_int(loc_a + 4); /* pairedWith */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + filewrite_ampi(operation, "ampi send", 5, loc_a); + break; + + case ampi_recv: + loc_a[0] = get_locint_f(); /* start loc */ + TAPE_AMPI_read_int(loc_a + 1); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); + TAPE_AMPI_read_int(loc_a + 2); /* endpoint */ + TAPE_AMPI_read_int(loc_a + 3); /* tag */ + TAPE_AMPI_read_int(loc_a + 4); /* pairedWith */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + filewrite_ampi(operation, "ampi recv", 5, loc_a); + break; + + case ampi_isend: + /* push is delayed to the accompanying completion */ + TAPE_AMPI_read_MPI_Request(&anMPI_Request); + filewrite_ampi(operation, "ampi isend", 0, loc_a); + break; + + case ampi_irecv: + /* push is delayed to the accompanying completion */ + TAPE_AMPI_read_MPI_Request(&anMPI_Request); + filewrite_ampi(operation, "ampi irecv", 0, loc_a); + break; + + case ampi_wait: + /* for the operation we had been waiting for */ + size = 0; + loc_a[size++] = get_locint_f(); /* start loc */ + TAPE_AMPI_read_int(loc_a + size++); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); + TAPE_AMPI_read_int(loc_a + size++); /* endpoint */ + TAPE_AMPI_read_int(loc_a + size++); /* tag */ + TAPE_AMPI_read_int(loc_a + size++); /* pairedWith */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_MPI_Request(&anMPI_Request); + TAPE_AMPI_read_int(loc_a + size++); /* origin */ + filewrite_ampi(operation, "ampi wait", size, loc_a); + break; + + case ampi_barrier: + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + filewrite_ampi(operation, "ampi barrier", 0, loc_a); + break; + + case ampi_bcast: + loc_a[0] = get_locint_f(); /* start loc */ + TAPE_AMPI_read_int(loc_a + 1); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); + TAPE_AMPI_read_int(loc_a + 2); /* root */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + filewrite_ampi(operation, "ampi bcast", 3, loc_a); + break; + + case ampi_reduce: + loc_a[0] = get_locint_f(); /* rbuf */ + loc_a[1] = get_locint_f(); /* sbuf */ + TAPE_AMPI_read_int(loc_a + 2); /* count */ + TAPE_AMPI_read_int(loc_a + 3); /* pushResultData */ + i = 0; /* read stored double array into dummy variable */ + while (i < loc_a[2]) { + TAPE_AMPI_read_double(&aDouble); + i++; + } + if (loc_a[3]) { + i = 0; /* for root, also read stored reduction result */ + while (i < loc_a[2]) { + TAPE_AMPI_read_double(&aDouble); + i++; + } + } + TAPE_AMPI_read_int(loc_a + 3); /* pushResultData again */ + TAPE_AMPI_read_MPI_Op(&anMPI_Op); + TAPE_AMPI_read_int(loc_a + 4); /* root */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); + TAPE_AMPI_read_int(loc_a + 2); /* count again */ + filewrite_ampi(operation, "ampi reduce", 5, loc_a); + break; + + case ampi_allreduce: + loc_a[0] = get_locint_f(); /* rbuf */ + loc_a[1] = get_locint_f(); /* sbuf */ + TAPE_AMPI_read_int(loc_a + 2); /* count */ + TAPE_AMPI_read_int(loc_a + 3); /* pushResultData */ + i = 0; /* read off stored double array into dummy variable */ + while (i < loc_a[2]) { + TAPE_AMPI_read_double(&aDouble); + i++; + } + if (loc_a[3]) { + i = 0; /* for root, also read off stored reduction result */ + while (i < loc_a[2]) { + TAPE_AMPI_read_double(&aDouble); + i++; + } + } + TAPE_AMPI_read_int(loc_a + 3); /* pushResultData again */ + TAPE_AMPI_read_MPI_Op(&anMPI_Op); + TAPE_AMPI_read_int(loc_a + 4); /* root */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); + TAPE_AMPI_read_int(loc_a + 2); /* count again */ + filewrite_ampi(operation, "ampi allreduce", 5, loc_a); + break; + + case ampi_gather: + size = 0; + TAPE_AMPI_read_int(loc_a + size++); /* commSizeForRootOrNull */ + if (*(loc_a + 0) > 0) { + loc_a[size++] = get_locint_f(); /* rbuf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* rcnt */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ + } + loc_a[size++] = get_locint_f(); /* buf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ + TAPE_AMPI_read_int(loc_a + size++); /* root */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_int(loc_a + 0); /* commSizeForRootOrNull */ + filewrite_ampi(operation, "ampi gather", size, loc_a); + break; + + case ampi_scatter: + size = 0; + TAPE_AMPI_read_int(loc_a + size++); /* commSizeForRootOrNull */ + if (*(loc_a + 0) > 0) { + loc_a[size++] = get_locint_f(); /* rbuf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* rcnt */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ + } + loc_a[size++] = get_locint_f(); /* buf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ + TAPE_AMPI_read_int(loc_a + size++); /* root */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_int(loc_a + 0); /* commSizeForRootOrNull */ + filewrite_ampi(operation, "ampi scatter", size, loc_a); + break; + + case ampi_allgather: + TAPE_AMPI_read_int(loc_a + 1); /* commSizeForRootOrNull */ + if (*(loc_a + 1) > 0) { + TAPE_AMPI_read_int(loc_a + 2); /* rcnt */ + loc_a[2] = get_locint_f(); /* rbuf loc */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ + } + TAPE_AMPI_read_int(loc_a + 3); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_int(loc_a + 1); /* commSizeForRootOrNull */ + filewrite_ampi(operation, "ampi allgather", 4, loc_a); + break; + + case ampi_gatherv: + size = 0; + TAPE_AMPI_read_int(loc_a + size++); /* commSizeForRootOrNull */ + if (*(loc_a + 0) > 0) { + loc_a[size++] = get_locint_f(); /* rbuf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* rcnt[0] */ + TAPE_AMPI_read_int(loc_a + size++); /* displs[0] */ + } + for (l = 1; l < *(loc_a + 0); ++l) { + TAPE_AMPI_read_int(loc_a + size); + TAPE_AMPI_read_int(loc_a + size); + } + if (*(loc_a + 0) > 0) { + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ + } + loc_a[size++] = get_locint_f(); /* buf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ + TAPE_AMPI_read_int(loc_a + size++); /* root */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_int(loc_a + 0); /* commSizeForRootOrNull */ + filewrite_ampi(operation, "ampi gatherv", size, loc_a); + break; + + case ampi_scatterv: + size = 0; + TAPE_AMPI_read_int(loc_a + size++); /* commSizeForRootOrNull */ + if (*(loc_a + 0) > 0) { + loc_a[size++] = get_locint_f(); /* rbuf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* rcnt[0] */ + TAPE_AMPI_read_int(loc_a + size++); /* displs[0] */ + } + for (l = 1; l < *(loc_a + 0); ++l) { + TAPE_AMPI_read_int(loc_a + size); + TAPE_AMPI_read_int(loc_a + size); + } + if (*(loc_a + 0) > 0) { + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ + } + loc_a[size++] = get_locint_f(); /* buf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ + TAPE_AMPI_read_int(loc_a + size++); /* root */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_int(loc_a + 0); /* commSizeForRootOrNull */ + filewrite_ampi(operation, "ampi scatterv", size, loc_a); + break; + + case ampi_allgatherv: + size = 0; + TAPE_AMPI_read_int(loc_a + size++); /* commSizeForRootOrNull */ + for (l = 0; l < *(loc_a); ++l) { + TAPE_AMPI_read_int(loc_a + size); /* rcnts */ + TAPE_AMPI_read_int(loc_a + size + 1); /* displs */ + } + if (*(loc_a) > 0) { + size += 2; + loc_a[size++] = get_locint_f(); /* rbuf loc */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* rtype */ + } + loc_a[size++] = get_locint_f(); /* buf loc */ + TAPE_AMPI_read_int(loc_a + size++); /* count */ + TAPE_AMPI_read_MPI_Datatype(&anMPI_Datatype); /* type */ + TAPE_AMPI_read_int(loc_a + size++); /* root */ + TAPE_AMPI_read_MPI_Comm(&anMPI_Comm); + TAPE_AMPI_read_int(loc_a); /* commSizeForRootOrNull */ + filewrite_ampi(operation, "ampi allgatherv", size, loc_a); + break; +#endif + /*--------------------------------------------------------------------------*/ + default: /* default */ + /* Die here, we screwed up */ + fprintf(DIAG_OUT, "ADOL-C error: Fatal error in tape_doc for op %d\n", + operation); + break; + + } /* endswitch */ + + /* Read the next operation */ + operation = get_op_f(); + ++op_cnt; + --rev_op_cnt; + } /* endwhile */ + + if (operation == end_of_tape) { + filewrite_end(operation); + }; + if (dp_T0) + free(dp_T0); + dp_T0 = NULL; + + end_sweep(); +} /* end tape_doc */ /****************************************************************************/ /* THAT'S ALL */ diff --git a/ADOL-C/src/taping.c b/ADOL-C/src/taping.c index 4caf0248c..73e2988da 100644 --- a/ADOL-C/src/taping.c +++ b/ADOL-C/src/taping.c @@ -5,41 +5,41 @@ Contents: all C functions directly accessing at least one of the four tapes (operations, locations, constants, value stack) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel, Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ #include #include +#include "dvlparms.h" #include "oplate.h" #include "taping_p.h" -#include "dvlparms.h" -#include #include +#include #ifdef ADOLC_AMPI_SUPPORT -#include "ampi/ampi.h" -#include "ampi/tape/support.h" + #include "ampi/ampi.h" + #include "ampi/tape/support.h" #endif #include #if defined(_WINDOWS) && !__STDC__ -#define stat _stat -#define S_IFDIR _S_IFDIR -#define S_IFMT _S_IFMT + #define stat _stat + #define S_IFDIR _S_IFDIR + #define S_IFMT _S_IFMT #endif #ifndef S_ISDIR -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) + #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif /*--------------------------------------------------------------------------*/ @@ -68,302 +68,309 @@ void *failAdditionalInfo6; /* outputs an appropriate error message using DIAG_OUT and exits the running * program */ -void fail( int error ) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - switch (error) { - case ADOLC_MALLOC_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: Memory allocation failed!\n"); - break; - case ADOLC_INTEGER_TAPE_FOPEN_FAILED: - case ADOLC_INTEGER_TAPE_FREAD_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: " - "reading integer tape number %d!\n", - failAdditionalInfo1); - printError(); - break; - case ADOLC_VALUE_TAPE_FOPEN_FAILED: - case ADOLC_VALUE_TAPE_FREAD_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: " - "reading value tape number %d!\n", - failAdditionalInfo1); - printError(); - break; - case ADOLC_TAPE_TO_OLD: - fprintf(DIAG_OUT, "ADOL-C error: " - "Used tape (%d) was written with ADOL-C version " - "older than %d.%d.%d\n", failAdditionalInfo1, - ADOLC_NEW_TAPE_VERSION, ADOLC_NEW_TAPE_SUBVERSION, - ADOLC_NEW_TAPE_PATCHLEVEL); - fprintf(DIAG_OUT, " " - "This is ADOL-C %d.%d.%d\n", ADOLC_VERSION, - ADOLC_SUBVERSION, ADOLC_PATCHLEVEL); - break; - case ADOLC_WRONG_LOCINT_SIZE: - fprintf(DIAG_OUT, "ADOL-C error: Used tape (%d) was written with " - "locints of size %d, size %d required.\n", - ADOLC_CURRENT_TAPE_INFOS.tapeID, failAdditionalInfo1, - failAdditionalInfo2); - break; - case ADOLC_MORE_STAT_SPACE_REQUIRED: - fprintf(DIAG_OUT, "ADOL-C error: Not enough space for stats!\n" - " Please contact the ADOL-C team!\n"); - break; - - case ADOLC_TAPING_BUFFER_ALLOCATION_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: Cannot allocate tape buffers!\n"); - break; - case ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: Cannot allocate taylor buffer!\n"); - break; - case ADOLC_TAPING_READ_ERROR_IN_TAYLOR_CLOSE: - fprintf(DIAG_OUT, "ADOL-C error: Read error in taylor_close n= %d\n", - failAdditionalInfo1); - break; - case ADOLC_TAPING_TO_MANY_TAYLOR_BUFFERS: - fprintf(DIAG_OUT, "ADOL-C error: To many taylor buffers!\n" - " Increase ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers\n"); - break; - case ADOLC_TAPING_TO_MANY_LOCINTS: - fprintf(DIAG_OUT, "ADOL-C error: Maximal number (%d) of live active " - "variables exceeded!\n\n" - "Possible remedies :\n\n" - " 1. Use more automatic local variables and\n" - " allocate/deallocate adoubles on free store\n" - " in a strictly last in first out fashion\n\n" - " 2. Extend the range by redefining the type of\n" - " locint (currently %d byte) from unsigned short " - "(%d byte) or int\n" - " to int (%d byte) or long (%d byte).\n", - failAdditionalInfo3, (int)sizeof(locint), - (int)sizeof(unsigned short), (int)sizeof(int), - (int)sizeof(long) ); - break; - case ADOLC_TAPING_STORE_REALLOC_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: Failure to reallocate storage for " - "adouble values!\n\n" - " oldStore = %p\n" - " newStore = NULL\n" - " oldStoreSize = %u\n" - " newStoreSize = %u\n\n" - "Possible remedies :\n" - " 1. Use more automatic local variables and \n" - " allocate/deallocate adoubles on free store\n" - " in a strictly last in first out fashion\n" - " 2. Enlarge your system stacksize limit\n" - , failAdditionalInfo5, failAdditionalInfo3, - failAdditionalInfo4 - ); - break; - case ADOLC_TAPING_FATAL_IO_ERROR: - fprintf(DIAG_OUT, "ADOL-C error: Fatal error-doing a read or " - "write!\n"); - printError(); - break; - case ADOLC_TAPING_TAPE_STILL_IN_USE: - fprintf(DIAG_OUT, "ADOL-C error: Tape %d is still in use!\n", - failAdditionalInfo1); - break; - case ADOLC_TAPING_TAYLOR_OPEN_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: while opening taylor file!\n"); - printError(); - break; - - case ADOLC_EVAL_SEEK_VALUE_STACK: - fprintf(DIAG_OUT, "ADOL-C error: in seeking value stack file!\n"); - break; - case ADOLC_EVAL_OP_TAPE_READ_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: while reading operations tape!\n"); - break; - case ADOLC_EVAL_VAL_TAPE_READ_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: while reading values tape!\n"); - break; - case ADOLC_EVAL_LOC_TAPE_READ_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: while reading locations tape!\n"); - break; - case ADOLC_EVAL_TAY_TAPE_READ_FAILED: - fprintf(DIAG_OUT, "ADOL-C error: while reading value stack tape!\n"); - break; - - case ADOLC_REVERSE_NO_TAYLOR_STACK: - fprintf(DIAG_OUT, "ADOL-C error: No taylor stack found for tape " - "%d! => Check forward sweep!\n", failAdditionalInfo1); - break; - case ADOLC_REVERSE_COUNTS_MISMATCH: - fprintf(DIAG_OUT, "ADOL-C error: Reverse sweep on tape %d aborted!\n" - " Number of dependents(%u) and/or " - "independents(%u)\n" - " variables passed to reverse is " - "inconsistent\n" - " with number recorded on tape(%zu/%zu)!\n", - ADOLC_CURRENT_TAPE_INFOS.tapeID, failAdditionalInfo3, - failAdditionalInfo4, - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS], - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]); - break; - case ADOLC_REVERSE_TAYLOR_COUNTS_MISMATCH: - fprintf(DIAG_OUT, "ADOL-C error: Reverse fails on tape %d because " - "the number of independent\n" - " and/or dependent variables given to" - " reverse are inconsistent\n" - " with that of the internal taylor " - "array!\n", - ADOLC_CURRENT_TAPE_INFOS.tapeID); - break; - - case ADOLC_BUFFER_NULLPOINTER_FUNCTION: - fprintf(DIAG_OUT, "ADOL-C error: NULL pointer supplied in buffer " - "handling.\n"); - break; - case ADOLC_BUFFER_INDEX_TO_LARGE: - fprintf(DIAG_OUT, "ADOL-C error: Index for buffer element too " - "large.\n"); - break; - - case ADOLC_EXT_DIFF_NULLPOINTER_STRUCT: - fprintf(DIAG_OUT, - "ADOL-C error: Got null pointer as pointer to struct " - " containing ext. diff. function information!\n"); - break; - case ADOLC_EXT_DIFF_WRONG_TAPESTATS: - fprintf(DIAG_OUT, - "ADOL-C error: Number of independents/dependents recorded on" - " tape differ from number supplied by user!\n"); - break; - case ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION: - fprintf(DIAG_OUT, - "ADOL-C error: Got NULL pointer as " - "extern function pointer!\n"); - break; - case ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC: - fprintf(DIAG_OUT, - "ADOL-C error: No function for external differentiation found" - " to work with (null pointer)\n!"); - break; - case ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT: - fprintf(DIAG_OUT, - "ADOL-C error: Got at least one null pointer as argument to" - " extern differentiated function!\n"); - break; - case ADOLC_EXT_DIFF_WRONG_FUNCTION_INDEX: - fprintf(DIAG_OUT, - "ADOL-C error: Function with specified index not found!\n"); - break; - - case ADOLC_EXT_DIFF_LOCATIONGAP: - fprintf(DIAG_OUT, - "ADOL-C error: active type arguments passed to call_ext_fct do not have contiguous ascending locations; use ensureContiguousLocations(size_t) to reserve contiguous blocks prior to allocation of the arguments.\n"); - break; - - case ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER: - fprintf(DIAG_OUT, - "ADOL-C error: Got null pointer as pointer to struct " - " containing checkpointing information!\n"); - break; - case ADOLC_CHECKPOINTING_NULLPOINTER_ARGUMENT: - fprintf(DIAG_OUT, - "ADOL-C error: Got null pointer instead of argument pointer " - "within checkpointing infos!\n"); - break; - case ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION: - fprintf(DIAG_OUT, - "ADOL-C error: Got null pointer instead of function pointer " - "within checkpointing infos!\n"); - break; - case ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION_DOUBLE: - fprintf(DIAG_OUT, - "ADOL-C error: Got null pointer instead of function (double " - "version) pointer within checkpointing infos!\n"); - break; - case ADOLC_CHECKPOINTING_REVOLVE_IRREGULAR_TERMINATED: - fprintf(DIAG_OUT, - "ADOL-C error: Irregualar termination of REVOLVE!\n"); - break; - case ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION: - fprintf(DIAG_OUT, - "ADOL-C error: Unextpected REVOLVE action in forward mode!\n" - ); - break; - case ADOLC_WRONG_PLATFORM_32: - fprintf(DIAG_OUT, - "ADOL-C error: Trace was created on a 64-bit platform, cannot be opened on 32-bit platform!\n" - ); - break; - case ADOLC_WRONG_PLATFORM_64: - fprintf(DIAG_OUT, - "ADOL-C error: Trace was created on a 32-bit platform, cannot be opened on 64-bit platform!\n" - ); - break; - case ADOLC_TAPING_NOT_ACTUALLY_TAPING: - fprintf(DIAG_OUT, - "ADOL-C error: Trace %d is not being currently created!\n", - failAdditionalInfo1); - break; - - case ADOLC_VEC_LOCATIONGAP: - fprintf(DIAG_OUT, - "ADOL-C error: arrays passed to vector operation do not have contiguous ascending locations;\nuse dynamic_cast(advector&) \nor call ensureContiguousLocations(size_t) to reserve contiguous blocks prior to allocation of the arrays.\n"); - break; - - default: - fprintf(DIAG_OUT, "ADOL-C error => unknown error type!\n"); - adolc_exit(-1, "", __func__, __FILE__, __LINE__); - break; - } - adolc_exit(error+1, "", __func__, __FILE__, __LINE__); - // exit (error + 1); +void fail(int error) { + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + switch (error) { + case ADOLC_MALLOC_FAILED: + fprintf(DIAG_OUT, "ADOL-C error: Memory allocation failed!\n"); + break; + case ADOLC_INTEGER_TAPE_FOPEN_FAILED: + case ADOLC_INTEGER_TAPE_FREAD_FAILED: + fprintf(DIAG_OUT, + "ADOL-C error: " + "reading integer tape number %d!\n", + failAdditionalInfo1); + printError(); + break; + case ADOLC_VALUE_TAPE_FOPEN_FAILED: + case ADOLC_VALUE_TAPE_FREAD_FAILED: + fprintf(DIAG_OUT, + "ADOL-C error: " + "reading value tape number %d!\n", + failAdditionalInfo1); + printError(); + break; + case ADOLC_TAPE_TO_OLD: + fprintf(DIAG_OUT, + "ADOL-C error: " + "Used tape (%d) was written with ADOL-C version " + "older than %d.%d.%d\n", + failAdditionalInfo1, ADOLC_NEW_TAPE_VERSION, + ADOLC_NEW_TAPE_SUBVERSION, ADOLC_NEW_TAPE_PATCHLEVEL); + fprintf(DIAG_OUT, + " " + "This is ADOL-C %d.%d.%d\n", + ADOLC_VERSION, ADOLC_SUBVERSION, ADOLC_PATCHLEVEL); + break; + case ADOLC_WRONG_LOCINT_SIZE: + fprintf(DIAG_OUT, + "ADOL-C error: Used tape (%d) was written with " + "locints of size %d, size %d required.\n", + ADOLC_CURRENT_TAPE_INFOS.tapeID, failAdditionalInfo1, + failAdditionalInfo2); + break; + case ADOLC_MORE_STAT_SPACE_REQUIRED: + fprintf(DIAG_OUT, "ADOL-C error: Not enough space for stats!\n" + " Please contact the ADOL-C team!\n"); + break; + + case ADOLC_TAPING_BUFFER_ALLOCATION_FAILED: + fprintf(DIAG_OUT, "ADOL-C error: Cannot allocate tape buffers!\n"); + break; + case ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED: + fprintf(DIAG_OUT, "ADOL-C error: Cannot allocate taylor buffer!\n"); + break; + case ADOLC_TAPING_READ_ERROR_IN_TAYLOR_CLOSE: + fprintf(DIAG_OUT, "ADOL-C error: Read error in taylor_close n= %d\n", + failAdditionalInfo1); + break; + case ADOLC_TAPING_TO_MANY_TAYLOR_BUFFERS: + fprintf(DIAG_OUT, "ADOL-C error: To many taylor buffers!\n" + " Increase " + "ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers\n"); + break; + case ADOLC_TAPING_TO_MANY_LOCINTS: + fprintf(DIAG_OUT, + "ADOL-C error: Maximal number (%d) of live active " + "variables exceeded!\n\n" + "Possible remedies :\n\n" + " 1. Use more automatic local variables and\n" + " allocate/deallocate adoubles on free store\n" + " in a strictly last in first out fashion\n\n" + " 2. Extend the range by redefining the type of\n" + " locint (currently %d byte) from unsigned short " + "(%d byte) or int\n" + " to int (%d byte) or long (%d byte).\n", + failAdditionalInfo3, (int)sizeof(locint), + (int)sizeof(unsigned short), (int)sizeof(int), (int)sizeof(long)); + break; + case ADOLC_TAPING_STORE_REALLOC_FAILED: + fprintf(DIAG_OUT, + "ADOL-C error: Failure to reallocate storage for " + "adouble values!\n\n" + " oldStore = %p\n" + " newStore = NULL\n" + " oldStoreSize = %u\n" + " newStoreSize = %u\n\n" + "Possible remedies :\n" + " 1. Use more automatic local variables and \n" + " allocate/deallocate adoubles on free store\n" + " in a strictly last in first out fashion\n" + " 2. Enlarge your system stacksize limit\n", + failAdditionalInfo5, failAdditionalInfo3, failAdditionalInfo4); + break; + case ADOLC_TAPING_FATAL_IO_ERROR: + fprintf(DIAG_OUT, "ADOL-C error: Fatal error-doing a read or " + "write!\n"); + printError(); + break; + case ADOLC_TAPING_TAPE_STILL_IN_USE: + fprintf(DIAG_OUT, "ADOL-C error: Tape %d is still in use!\n", + failAdditionalInfo1); + break; + case ADOLC_TAPING_TAYLOR_OPEN_FAILED: + fprintf(DIAG_OUT, "ADOL-C error: while opening taylor file!\n"); + printError(); + break; + + case ADOLC_EVAL_SEEK_VALUE_STACK: + fprintf(DIAG_OUT, "ADOL-C error: in seeking value stack file!\n"); + break; + case ADOLC_EVAL_OP_TAPE_READ_FAILED: + fprintf(DIAG_OUT, "ADOL-C error: while reading operations tape!\n"); + break; + case ADOLC_EVAL_VAL_TAPE_READ_FAILED: + fprintf(DIAG_OUT, "ADOL-C error: while reading values tape!\n"); + break; + case ADOLC_EVAL_LOC_TAPE_READ_FAILED: + fprintf(DIAG_OUT, "ADOL-C error: while reading locations tape!\n"); + break; + case ADOLC_EVAL_TAY_TAPE_READ_FAILED: + fprintf(DIAG_OUT, "ADOL-C error: while reading value stack tape!\n"); + break; + + case ADOLC_REVERSE_NO_TAYLOR_STACK: + fprintf(DIAG_OUT, + "ADOL-C error: No taylor stack found for tape " + "%d! => Check forward sweep!\n", + failAdditionalInfo1); + break; + case ADOLC_REVERSE_COUNTS_MISMATCH: + fprintf(DIAG_OUT, + "ADOL-C error: Reverse sweep on tape %d aborted!\n" + " Number of dependents(%u) and/or " + "independents(%u)\n" + " variables passed to reverse is " + "inconsistent\n" + " with number recorded on tape(%zu/%zu)!\n", + ADOLC_CURRENT_TAPE_INFOS.tapeID, failAdditionalInfo3, + failAdditionalInfo4, ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS], + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]); + break; + case ADOLC_REVERSE_TAYLOR_COUNTS_MISMATCH: + fprintf(DIAG_OUT, + "ADOL-C error: Reverse fails on tape %d because " + "the number of independent\n" + " and/or dependent variables given to" + " reverse are inconsistent\n" + " with that of the internal taylor " + "array!\n", + ADOLC_CURRENT_TAPE_INFOS.tapeID); + break; + + case ADOLC_BUFFER_NULLPOINTER_FUNCTION: + fprintf(DIAG_OUT, "ADOL-C error: NULL pointer supplied in buffer " + "handling.\n"); + break; + case ADOLC_BUFFER_INDEX_TO_LARGE: + fprintf(DIAG_OUT, "ADOL-C error: Index for buffer element too " + "large.\n"); + break; + + case ADOLC_EXT_DIFF_NULLPOINTER_STRUCT: + fprintf(DIAG_OUT, "ADOL-C error: Got null pointer as pointer to struct " + " containing ext. diff. function information!\n"); + break; + case ADOLC_EXT_DIFF_WRONG_TAPESTATS: + fprintf(DIAG_OUT, + "ADOL-C error: Number of independents/dependents recorded on" + " tape differ from number supplied by user!\n"); + break; + case ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION: + fprintf(DIAG_OUT, "ADOL-C error: Got NULL pointer as " + "extern function pointer!\n"); + break; + case ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC: + fprintf(DIAG_OUT, + "ADOL-C error: No function for external differentiation found" + " to work with (null pointer)\n!"); + break; + case ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT: + fprintf(DIAG_OUT, + "ADOL-C error: Got at least one null pointer as argument to" + " extern differentiated function!\n"); + break; + case ADOLC_EXT_DIFF_WRONG_FUNCTION_INDEX: + fprintf(DIAG_OUT, + "ADOL-C error: Function with specified index not found!\n"); + break; + + case ADOLC_EXT_DIFF_LOCATIONGAP: + fprintf(DIAG_OUT, + "ADOL-C error: active type arguments passed to call_ext_fct do not " + "have contiguous ascending locations; use " + "ensureContiguousLocations(size_t) to reserve contiguous blocks " + "prior to allocation of the arguments.\n"); + break; + + case ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER: + fprintf(DIAG_OUT, "ADOL-C error: Got null pointer as pointer to struct " + " containing checkpointing information!\n"); + break; + case ADOLC_CHECKPOINTING_NULLPOINTER_ARGUMENT: + fprintf(DIAG_OUT, + "ADOL-C error: Got null pointer instead of argument pointer " + "within checkpointing infos!\n"); + break; + case ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION: + fprintf(DIAG_OUT, + "ADOL-C error: Got null pointer instead of function pointer " + "within checkpointing infos!\n"); + break; + case ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION_DOUBLE: + fprintf(DIAG_OUT, + "ADOL-C error: Got null pointer instead of function (double " + "version) pointer within checkpointing infos!\n"); + break; + case ADOLC_CHECKPOINTING_REVOLVE_IRREGULAR_TERMINATED: + fprintf(DIAG_OUT, "ADOL-C error: Irregualar termination of REVOLVE!\n"); + break; + case ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION: + fprintf(DIAG_OUT, + "ADOL-C error: Unextpected REVOLVE action in forward mode!\n"); + break; + case ADOLC_WRONG_PLATFORM_32: + fprintf(DIAG_OUT, "ADOL-C error: Trace was created on a 64-bit platform, " + "cannot be opened on 32-bit platform!\n"); + break; + case ADOLC_WRONG_PLATFORM_64: + fprintf(DIAG_OUT, "ADOL-C error: Trace was created on a 32-bit platform, " + "cannot be opened on 64-bit platform!\n"); + break; + case ADOLC_TAPING_NOT_ACTUALLY_TAPING: + fprintf(DIAG_OUT, + "ADOL-C error: Trace %d is not being currently created!\n", + failAdditionalInfo1); + break; + + case ADOLC_VEC_LOCATIONGAP: + fprintf(DIAG_OUT, "ADOL-C error: arrays passed to vector operation do not " + "have contiguous ascending locations;\nuse " + "dynamic_cast(advector&) \nor call " + "ensureContiguousLocations(size_t) to reserve " + "contiguous blocks prior to allocation of the arrays.\n"); + break; + + default: + fprintf(DIAG_OUT, "ADOL-C error => unknown error type!\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + break; + } + adolc_exit(error + 1, "", __func__, __FILE__, __LINE__); + // exit (error + 1); } /* print an error message describing the error number */ void printError() { - fprintf(DIAG_OUT, " "); - switch (errno) { - case EACCES: - fprintf(DIAG_OUT, ">>> Access denied! <<<\n"); - break; - case EFBIG: - fprintf(DIAG_OUT, ">>> File too big! <<<\n"); - break; - case EMFILE: - fprintf(DIAG_OUT, ">>> Too many open files for this process! <<<\n"); - break; - case ENAMETOOLONG: - fprintf(DIAG_OUT, ">>> Path/file name too long! <<<\n"); - break; - case ENFILE: - fprintf(DIAG_OUT, ">>> Too many open files for this system! <<<\n"); - break; - case ENOENT: - fprintf(DIAG_OUT, ">>> File or directory not found! <<<\n"); - break; - case ENOSPC: - fprintf(DIAG_OUT, ">>> No space left on device! <<<\n"); - break; - case EPERM: - fprintf(DIAG_OUT, ">>> Operation not permitted! <<<\n"); - break; - case EROFS: - fprintf(DIAG_OUT, ">>> File system is mounted read only! <<<\n"); - break; - default: - fprintf(DIAG_OUT, ">>> "); - fprintf(DIAG_OUT, "%s", strerror(errno)); - fprintf(DIAG_OUT, " <<<\n"); - break; - } + fprintf(DIAG_OUT, " "); + switch (errno) { + case EACCES: + fprintf(DIAG_OUT, ">>> Access denied! <<<\n"); + break; + case EFBIG: + fprintf(DIAG_OUT, ">>> File too big! <<<\n"); + break; + case EMFILE: + fprintf(DIAG_OUT, ">>> Too many open files for this process! <<<\n"); + break; + case ENAMETOOLONG: + fprintf(DIAG_OUT, ">>> Path/file name too long! <<<\n"); + break; + case ENFILE: + fprintf(DIAG_OUT, ">>> Too many open files for this system! <<<\n"); + break; + case ENOENT: + fprintf(DIAG_OUT, ">>> File or directory not found! <<<\n"); + break; + case ENOSPC: + fprintf(DIAG_OUT, ">>> No space left on device! <<<\n"); + break; + case EPERM: + fprintf(DIAG_OUT, ">>> Operation not permitted! <<<\n"); + break; + case EROFS: + fprintf(DIAG_OUT, ">>> File system is mounted read only! <<<\n"); + break; + default: + fprintf(DIAG_OUT, ">>> "); + fprintf(DIAG_OUT, "%s", strerror(errno)); + fprintf(DIAG_OUT, " <<<\n"); + break; + } } /* the base names of every tape type */ -char *tapeBaseNames[4]={0,0,0,0}; +char *tapeBaseNames[4] = {0, 0, 0, 0}; void clearTapeBaseNames() { - int i; - for(i=0;i<4;i++) { - if (tapeBaseNames[i]) { - free(tapeBaseNames[i]); - tapeBaseNames[i]=0; - } + int i; + for (i = 0; i < 4; i++) { + if (tapeBaseNames[i]) { + free(tapeBaseNames[i]); + tapeBaseNames[i] = 0; } + } } /****************************************************************************/ @@ -372,244 +379,256 @@ void clearTapeBaseNames() { /* The result string must be freed be the caller! */ /****************************************************************************/ char *createFileName(short tapeID, int tapeType) { - char *numberString, *fileName, *extension = ".tap", *currPos; + char *numberString, *fileName, *extension = ".tap", *currPos; #if defined(_OPENMP) - char *threadName = "thread-", *threadNumberString = NULL; - int threadNumber, threadNumberStringLength = 0, threadNameLength = 0; + char *threadName = "thread-", *threadNumberString = NULL; + int threadNumber, threadNumberStringLength = 0, threadNameLength = 0; #endif /* _OPENMP */ - int tapeBaseNameLength, numberStringLength, fileNameLength; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - failAdditionalInfo1 = tapeID; - tapeBaseNameLength = strlen(tapeBaseNames[tapeType]); - /* determine length of the number string */ - if (tapeID != 0) - numberStringLength = (int)log10((double)tapeID); - else numberStringLength = 0; - ++numberStringLength; - numberString = malloc(sizeof(char) * (numberStringLength + 1)); - if (numberString == NULL) fail(ADOLC_MALLOC_FAILED); - sprintf(numberString, "%d", tapeID); + int tapeBaseNameLength, numberStringLength, fileNameLength; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + failAdditionalInfo1 = tapeID; + tapeBaseNameLength = strlen(tapeBaseNames[tapeType]); + /* determine length of the number string */ + if (tapeID != 0) + numberStringLength = (int)log10((double)tapeID); + else + numberStringLength = 0; + ++numberStringLength; + numberString = malloc(sizeof(char) * (numberStringLength + 1)); + if (numberString == NULL) + fail(ADOLC_MALLOC_FAILED); + sprintf(numberString, "%d", tapeID); #if defined(_OPENMP) - /* determine length of the thread number string */ - if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) { - threadNameLength = strlen(threadName); - threadNumber = omp_get_thread_num(); - if (threadNumber != 0) - threadNumberStringLength = (int)log10((double)threadNumber); - else threadNumberStringLength = 0; - ++threadNumberStringLength; - threadNumberString = - malloc(sizeof(char) * (threadNumberStringLength + 2)); - if (threadNumberString == NULL) fail(ADOLC_MALLOC_FAILED); - sprintf(threadNumberString, "%d", threadNumber); - threadNumberString[threadNumberStringLength] = '_'; - ++threadNumberStringLength; - threadNumberString[threadNumberStringLength] = 0; - } + /* determine length of the thread number string */ + if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) { + threadNameLength = strlen(threadName); + threadNumber = omp_get_thread_num(); + if (threadNumber != 0) + threadNumberStringLength = (int)log10((double)threadNumber); + else + threadNumberStringLength = 0; + ++threadNumberStringLength; + threadNumberString = malloc(sizeof(char) * (threadNumberStringLength + 2)); + if (threadNumberString == NULL) + fail(ADOLC_MALLOC_FAILED); + sprintf(threadNumberString, "%d", threadNumber); + threadNumberString[threadNumberStringLength] = '_'; + ++threadNumberStringLength; + threadNumberString[threadNumberStringLength] = 0; + } #endif /* _OPENMP */ - /* malloc and create */ - fileNameLength = tapeBaseNameLength + numberStringLength + 5; + /* malloc and create */ + fileNameLength = tapeBaseNameLength + numberStringLength + 5; #if defined(_OPENMP) - if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) - fileNameLength += threadNameLength + threadNumberStringLength; + if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) + fileNameLength += threadNameLength + threadNumberStringLength; #endif /* _OPENMP */ - fileName = (char *)malloc(sizeof(char) * fileNameLength); - if (fileName == NULL) fail(ADOLC_MALLOC_FAILED); - currPos = fileName; - strncpy(currPos, tapeBaseNames[tapeType], tapeBaseNameLength); - currPos += tapeBaseNameLength; + fileName = (char *)malloc(sizeof(char) * fileNameLength); + if (fileName == NULL) + fail(ADOLC_MALLOC_FAILED); + currPos = fileName; + strncpy(currPos, tapeBaseNames[tapeType], tapeBaseNameLength); + currPos += tapeBaseNameLength; #if defined(_OPENMP) - if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) { - strncpy(currPos, threadName, threadNameLength); - currPos += threadNameLength; - strncpy(currPos, threadNumberString, threadNumberStringLength); - currPos += threadNumberStringLength; - } + if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) { + strncpy(currPos, threadName, threadNameLength); + currPos += threadNameLength; + strncpy(currPos, threadNumberString, threadNumberStringLength); + currPos += threadNumberStringLength; + } #endif /* _OPENMP */ - strncpy(currPos, numberString, numberStringLength); - currPos += numberStringLength; - strncpy(currPos, extension, 4); - currPos += 4; - *currPos = 0; + strncpy(currPos, numberString, numberStringLength); + currPos += numberStringLength; + strncpy(currPos, extension, 4); + currPos += 4; + *currPos = 0; - free(numberString); + free(numberString); #if defined(_OPENMP) - if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) - free(threadNumberString); + if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) + free(threadNumberString); #endif /* _OPENMP */ - return fileName; + return fileName; } /****************************************************************************/ /* Tries to read a local config file containing, e.g., buffer sizes */ /****************************************************************************/ -static char* duplicatestr(const char* instr) { - size_t len = strlen(instr); - char *outstr = calloc(len+1,sizeof(char)); - strncpy(outstr,instr,len); - return outstr; +static char *duplicatestr(const char *instr) { + size_t len = strlen(instr); + char *outstr = calloc(len + 1, sizeof(char)); + strncpy(outstr, instr, len); + return outstr; } #define ADOLC_LINE_LENGTH 100 void readConfigFile() { - FILE *configFile = NULL; - char inputLine[ADOLC_LINE_LENGTH + 1]; - char *pos1 = NULL, *pos2 = NULL, *pos3 = NULL, *pos4 = NULL, *start = NULL, *end = NULL; - int base; - unsigned long int number = 0; - char *path = NULL; - int defdirsize = strlen(TAPE_DIR PATHSEPARATOR); - tapeBaseNames[0] = duplicatestr( - TAPE_DIR PATHSEPARATOR ADOLC_LOCATIONS_NAME); - tapeBaseNames[1] = duplicatestr( - TAPE_DIR PATHSEPARATOR ADOLC_VALUES_NAME); - tapeBaseNames[2] = duplicatestr( - TAPE_DIR PATHSEPARATOR ADOLC_OPERATIONS_NAME); - tapeBaseNames[3] = duplicatestr( - TAPE_DIR PATHSEPARATOR ADOLC_TAYLORS_NAME); - - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - ADOLC_GLOBAL_TAPE_VARS.operationBufferSize = OBUFSIZE; - ADOLC_GLOBAL_TAPE_VARS.locationBufferSize = LBUFSIZE; - ADOLC_GLOBAL_TAPE_VARS.valueBufferSize = VBUFSIZE; - ADOLC_GLOBAL_TAPE_VARS.taylorBufferSize = TBUFSIZE; - ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers = TBUFNUM; - if ((configFile = fopen(".adolcrc", "r")) != NULL) { - fprintf(DIAG_OUT, "\nFile .adolcrc found! => Try to parse it!\n"); - fprintf(DIAG_OUT, "****************************************\n"); - while (fgets(inputLine, ADOLC_LINE_LENGTH + 1, configFile) == inputLine) { - if (strlen(inputLine) == ADOLC_LINE_LENGTH && - inputLine[ADOLC_LINE_LENGTH - 1] != 0xA) { - fprintf(DIAG_OUT, "ADOL-C warning: Input line in .adolcrc exceeds" - " %d characters!\n", ADOLC_LINE_LENGTH); - fprintf(DIAG_OUT, " => Parsing aborted!!\n"); - break; - } - pos1 = strchr(inputLine, '"'); - pos2 = NULL; - pos3 = NULL; - pos4 = NULL; - if (pos1 != NULL) { - pos2 = strchr(pos1 + 1, '"'); - if (pos2 != NULL) { - pos3 = strchr(pos2 + 1, '"'); - if (pos3 != NULL) pos4 = strchr(pos3 + 1, '"'); - } - } - if (pos4 == NULL) { - if (pos1 != NULL) - fprintf(DIAG_OUT, "ADOL-C warning: Malformed input line " + FILE *configFile = NULL; + char inputLine[ADOLC_LINE_LENGTH + 1]; + char *pos1 = NULL, *pos2 = NULL, *pos3 = NULL, *pos4 = NULL, *start = NULL, + *end = NULL; + int base; + unsigned long int number = 0; + char *path = NULL; + int defdirsize = strlen(TAPE_DIR PATHSEPARATOR); + tapeBaseNames[0] = duplicatestr(TAPE_DIR PATHSEPARATOR ADOLC_LOCATIONS_NAME); + tapeBaseNames[1] = duplicatestr(TAPE_DIR PATHSEPARATOR ADOLC_VALUES_NAME); + tapeBaseNames[2] = duplicatestr(TAPE_DIR PATHSEPARATOR ADOLC_OPERATIONS_NAME); + tapeBaseNames[3] = duplicatestr(TAPE_DIR PATHSEPARATOR ADOLC_TAYLORS_NAME); + + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + ADOLC_GLOBAL_TAPE_VARS.operationBufferSize = OBUFSIZE; + ADOLC_GLOBAL_TAPE_VARS.locationBufferSize = LBUFSIZE; + ADOLC_GLOBAL_TAPE_VARS.valueBufferSize = VBUFSIZE; + ADOLC_GLOBAL_TAPE_VARS.taylorBufferSize = TBUFSIZE; + ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers = TBUFNUM; + if ((configFile = fopen(".adolcrc", "r")) != NULL) { + fprintf(DIAG_OUT, "\nFile .adolcrc found! => Try to parse it!\n"); + fprintf(DIAG_OUT, "****************************************\n"); + while (fgets(inputLine, ADOLC_LINE_LENGTH + 1, configFile) == inputLine) { + if (strlen(inputLine) == ADOLC_LINE_LENGTH && + inputLine[ADOLC_LINE_LENGTH - 1] != 0xA) { + fprintf(DIAG_OUT, + "ADOL-C warning: Input line in .adolcrc exceeds" + " %d characters!\n", + ADOLC_LINE_LENGTH); + fprintf(DIAG_OUT, " => Parsing aborted!!\n"); + break; + } + pos1 = strchr(inputLine, '"'); + pos2 = NULL; + pos3 = NULL; + pos4 = NULL; + if (pos1 != NULL) { + pos2 = strchr(pos1 + 1, '"'); + if (pos2 != NULL) { + pos3 = strchr(pos2 + 1, '"'); + if (pos3 != NULL) + pos4 = strchr(pos3 + 1, '"'); + } + } + if (pos4 == NULL) { + if (pos1 != NULL) + fprintf(DIAG_OUT, "ADOL-C warning: Malformed input line " "in .adolcrc ignored!\n"); - } else { - if (*(pos3 + 1) == '0' && (*(pos3 + 2) == 'x' || *(pos3 + 2) == 'X')) { - start = pos3 + 3; - base = 16; - } else if (*(pos3 + 1) == '0') { - start = pos3 + 2; - base = 8; - } else { - start = pos3 + 1; - base = 10; - } - number = strtoul(start, &end, base); - if (end == start) { - *pos2 = 0; - *pos4 = 0; - if (strcmp(pos1 + 1, "TAPE_DIR") == 0) { - struct stat st; - int err; - path = pos3 + 1; - err = stat(path,&st); - if (err == 0 && S_ISDIR(st.st_mode)) { - int pathlen, pathseplen, namelen[4]; - int i; - pathlen=strlen(path); - pathseplen=strlen(PATHSEPARATOR); - for(i = 0; i < 4; i++) - namelen[i] = strlen(tapeBaseNames[i]); - clearTapeBaseNames(); - for(i = 0; i < 4; i++) { - char *currpos; - int fnamelen; - tapeBaseNames[i] = (char*)calloc(namelen[i] - defdirsize + pathlen + pathseplen + 1, sizeof(char)); - currpos = tapeBaseNames[i]; - strncpy(currpos,path,pathlen); - currpos += pathlen; - strncpy(currpos,PATHSEPARATOR,pathseplen); - currpos += pathseplen; - switch (i) { - case 0: - fnamelen = strlen(ADOLC_LOCATIONS_NAME); - strncpy(currpos,ADOLC_LOCATIONS_NAME,fnamelen); - break; - case 1: - fnamelen = strlen(ADOLC_VALUES_NAME); - strncpy(currpos,ADOLC_VALUES_NAME,fnamelen); - break; - case 2: - fnamelen = strlen(ADOLC_OPERATIONS_NAME); - strncpy(currpos,ADOLC_OPERATIONS_NAME,fnamelen); - break; - case 3: - fnamelen = strlen(ADOLC_TAYLORS_NAME); - strncpy(currpos,ADOLC_TAYLORS_NAME,fnamelen); - break; - } - currpos += fnamelen; - *currpos = '\0'; - } - fprintf(DIAG_OUT, "ADOL-C info: using TAPE_DIR %s for all disk bound tapes\n",path); - } else - fprintf(DIAG_OUT, "ADOL-C warning: TAPE_DIR %s in .adolcrc is not an existing directory,\n will continue using %s for writing tapes\n", path, TAPE_DIR); - } - else - fprintf(DIAG_OUT, "ADOL-C warning: Unable to parse number in " - ".adolcrc!\n"); - } else { - *pos2 = 0; - *pos4 = 0; - if (strcmp(pos1 + 1, "OBUFSIZE") == 0) { - ADOLC_GLOBAL_TAPE_VARS.operationBufferSize = (locint)number; - fprintf(DIAG_OUT, "Found operation buffer size: %u\n", - (locint)number); - } else if (strcmp(pos1 + 1, "LBUFSIZE") == 0) { - ADOLC_GLOBAL_TAPE_VARS.locationBufferSize = (locint)number; - fprintf(DIAG_OUT, "Found location buffer size: %u\n", - (locint)number); - } else if (strcmp(pos1 + 1, "VBUFSIZE") == 0) { - ADOLC_GLOBAL_TAPE_VARS.valueBufferSize = (locint)number; - fprintf(DIAG_OUT, "Found value buffer size: %u\n", - (locint)number); - } else if (strcmp(pos1 + 1, "TBUFSIZE") == 0) { - ADOLC_GLOBAL_TAPE_VARS.taylorBufferSize = (locint)number; - fprintf(DIAG_OUT, "Found taylor buffer size: %u\n", - (locint)number); - } else if (strcmp(pos1 + 1, "TBUFNUM") == 0) { - ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers = (int)number; - fprintf(DIAG_OUT, "Found maximal number of taylor buffers: " - "%d\n", (int)number); - } else if (strcmp(pos1 + 1, "INITLIVE") == 0) { - ADOLC_GLOBAL_TAPE_VARS.initialStoreSize = (locint)number; - fprintf(DIAG_OUT, "Found initial live variable store size : %u\n", - (locint)number); - checkInitialStoreSize(&ADOLC_GLOBAL_TAPE_VARS); - } else { - fprintf(DIAG_OUT, "ADOL-C warning: Unable to parse " - "parameter name in .adolcrc!\n"); - } + } else { + if (*(pos3 + 1) == '0' && (*(pos3 + 2) == 'x' || *(pos3 + 2) == 'X')) { + start = pos3 + 3; + base = 16; + } else if (*(pos3 + 1) == '0') { + start = pos3 + 2; + base = 8; + } else { + start = pos3 + 1; + base = 10; + } + number = strtoul(start, &end, base); + if (end == start) { + *pos2 = 0; + *pos4 = 0; + if (strcmp(pos1 + 1, "TAPE_DIR") == 0) { + struct stat st; + int err; + path = pos3 + 1; + err = stat(path, &st); + if (err == 0 && S_ISDIR(st.st_mode)) { + int pathlen, pathseplen, namelen[4]; + int i; + pathlen = strlen(path); + pathseplen = strlen(PATHSEPARATOR); + for (i = 0; i < 4; i++) + namelen[i] = strlen(tapeBaseNames[i]); + clearTapeBaseNames(); + for (i = 0; i < 4; i++) { + char *currpos; + int fnamelen; + tapeBaseNames[i] = (char *)calloc(namelen[i] - defdirsize + + pathlen + pathseplen + 1, + sizeof(char)); + currpos = tapeBaseNames[i]; + strncpy(currpos, path, pathlen); + currpos += pathlen; + strncpy(currpos, PATHSEPARATOR, pathseplen); + currpos += pathseplen; + switch (i) { + case 0: + fnamelen = strlen(ADOLC_LOCATIONS_NAME); + strncpy(currpos, ADOLC_LOCATIONS_NAME, fnamelen); + break; + case 1: + fnamelen = strlen(ADOLC_VALUES_NAME); + strncpy(currpos, ADOLC_VALUES_NAME, fnamelen); + break; + case 2: + fnamelen = strlen(ADOLC_OPERATIONS_NAME); + strncpy(currpos, ADOLC_OPERATIONS_NAME, fnamelen); + break; + case 3: + fnamelen = strlen(ADOLC_TAYLORS_NAME); + strncpy(currpos, ADOLC_TAYLORS_NAME, fnamelen); + break; } - } + currpos += fnamelen; + *currpos = '\0'; + } + fprintf( + DIAG_OUT, + "ADOL-C info: using TAPE_DIR %s for all disk bound tapes\n", + path); + } else + fprintf( + DIAG_OUT, + "ADOL-C warning: TAPE_DIR %s in .adolcrc is not an existing " + "directory,\n will continue using %s for writing tapes\n", + path, TAPE_DIR); + } else + fprintf(DIAG_OUT, "ADOL-C warning: Unable to parse number in " + ".adolcrc!\n"); + } else { + *pos2 = 0; + *pos4 = 0; + if (strcmp(pos1 + 1, "OBUFSIZE") == 0) { + ADOLC_GLOBAL_TAPE_VARS.operationBufferSize = (locint)number; + fprintf(DIAG_OUT, "Found operation buffer size: %u\n", + (locint)number); + } else if (strcmp(pos1 + 1, "LBUFSIZE") == 0) { + ADOLC_GLOBAL_TAPE_VARS.locationBufferSize = (locint)number; + fprintf(DIAG_OUT, "Found location buffer size: %u\n", + (locint)number); + } else if (strcmp(pos1 + 1, "VBUFSIZE") == 0) { + ADOLC_GLOBAL_TAPE_VARS.valueBufferSize = (locint)number; + fprintf(DIAG_OUT, "Found value buffer size: %u\n", (locint)number); + } else if (strcmp(pos1 + 1, "TBUFSIZE") == 0) { + ADOLC_GLOBAL_TAPE_VARS.taylorBufferSize = (locint)number; + fprintf(DIAG_OUT, "Found taylor buffer size: %u\n", (locint)number); + } else if (strcmp(pos1 + 1, "TBUFNUM") == 0) { + ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers = (int)number; + fprintf(DIAG_OUT, + "Found maximal number of taylor buffers: " + "%d\n", + (int)number); + } else if (strcmp(pos1 + 1, "INITLIVE") == 0) { + ADOLC_GLOBAL_TAPE_VARS.initialStoreSize = (locint)number; + fprintf(DIAG_OUT, "Found initial live variable store size : %u\n", + (locint)number); + checkInitialStoreSize(&ADOLC_GLOBAL_TAPE_VARS); + } else { + fprintf(DIAG_OUT, "ADOL-C warning: Unable to parse " + "parameter name in .adolcrc!\n"); + } } - fprintf(DIAG_OUT, "****************************************\n\n"); - fclose(configFile); + } } - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + fprintf(DIAG_OUT, "****************************************\n\n"); + fclose(configFile); + } + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; } /****************************************************************************/ @@ -623,40 +642,40 @@ static unsigned int numTBuffersInUse = 0; /* record all existing adoubles on the tape * - intended to be used in start_trace only */ void take_stock() { - locint space_left, loc = 0; - double *vals; - size_t vals_left; - ADOLC_OPENMP_THREAD_NUMBER; - - ADOLC_OPENMP_GET_THREAD_NUMBER; - space_left = get_val_space(); /* remaining space in const. tape buffer */ - vals_left = ADOLC_GLOBAL_TAPE_VARS.storeSize; - vals = ADOLC_GLOBAL_TAPE_VARS.store; - - /* if we have adoubles in use */ - if (ADOLC_GLOBAL_TAPE_VARS.numLives > 0) { + locint space_left, loc = 0; + double *vals; + size_t vals_left; + ADOLC_OPENMP_THREAD_NUMBER; + + ADOLC_OPENMP_GET_THREAD_NUMBER; + space_left = get_val_space(); /* remaining space in const. tape buffer */ + vals_left = ADOLC_GLOBAL_TAPE_VARS.storeSize; + vals = ADOLC_GLOBAL_TAPE_VARS.store; + + /* if we have adoubles in use */ + if (ADOLC_GLOBAL_TAPE_VARS.numLives > 0) { /* fill the current values (real) tape buffer and write it to disk * - do this as long as buffer can be fully filled */ while (space_left < vals_left) { - put_op(take_stock_op); - ADOLC_PUT_LOCINT(space_left); - ADOLC_PUT_LOCINT(loc); - put_vals_writeBlock(vals, space_left); - vals += space_left; - vals_left -= space_left; - loc += space_left; - space_left = get_val_space(); + put_op(take_stock_op); + ADOLC_PUT_LOCINT(space_left); + ADOLC_PUT_LOCINT(loc); + put_vals_writeBlock(vals, space_left); + vals += space_left; + vals_left -= space_left; + loc += space_left; + space_left = get_val_space(); } /* store the remaining adouble values to the values tape buffer * -> no write to disk necessary */ if (vals_left > 0) { - put_op(take_stock_op); - ADOLC_PUT_LOCINT(vals_left); - ADOLC_PUT_LOCINT(loc); - put_vals_notWriteBlock(vals, vals_left); - } + put_op(take_stock_op); + ADOLC_PUT_LOCINT(vals_left); + ADOLC_PUT_LOCINT(loc); + put_vals_notWriteBlock(vals, vals_left); } - ADOLC_CURRENT_TAPE_INFOS.traceFlag = 1; + } + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 1; } /****************************************************************************/ @@ -665,163 +684,166 @@ void take_stock() { /* - intended to be used in stop_trace only */ /****************************************************************************/ locint keep_stock() { - locint loc2; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - /* save all the final adoubles when finishing tracing */ - loc2 = ADOLC_GLOBAL_TAPE_VARS.storeSize - 1; - - /* special signal -> all alive adoubles recorded on the end of the - * value stack -> special handling at the beginning of reverse */ - put_op(death_not); - ADOLC_PUT_LOCINT(0); /* lowest loc */ - ADOLC_PUT_LOCINT(loc2); /* highest loc */ - - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += ADOLC_GLOBAL_TAPE_VARS.storeSize; - /* now really do it if keepTaylors is set */ - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) { - do { - ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc2]); - } while (loc2-- > 0); - } - ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; - return ADOLC_GLOBAL_TAPE_VARS.storeSize; + locint loc2; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + /* save all the final adoubles when finishing tracing */ + loc2 = ADOLC_GLOBAL_TAPE_VARS.storeSize - 1; + + /* special signal -> all alive adoubles recorded on the end of the + * value stack -> special handling at the beginning of reverse */ + put_op(death_not); + ADOLC_PUT_LOCINT(0); /* lowest loc */ + ADOLC_PUT_LOCINT(loc2); /* highest loc */ + + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += ADOLC_GLOBAL_TAPE_VARS.storeSize; + /* now really do it if keepTaylors is set */ + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) { + do { + ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc2]); + } while (loc2-- > 0); + } + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 0; + return ADOLC_GLOBAL_TAPE_VARS.storeSize; } - /****************************************************************************/ /* Set up statics for writing taylor data */ /****************************************************************************/ void taylor_begin(uint bufferSize, int degreeSave) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer != NULL) { - # if defined(ADOLC_DEBUG) - fprintf(DIAG_OUT, "\nADOL-C warning: !!! Taylor information for tape %d" - " found that will be overwritten !!!\n\n", - ADOLC_CURRENT_TAPE_INFOS.tapeID); - # endif - taylor_close(false); - } else { /* check if new buffer is allowed */ - if (numTBuffersInUse == ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers) - fail(ADOLC_TAPING_TO_MANY_TAYLOR_BUFFERS); - ++numTBuffersInUse; - if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName == NULL) - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName = - createFileName(ADOLC_CURRENT_TAPE_INFOS.tapeID, TAYLORS_TAPE); - } - - /* initial setups */ - if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) - ADOLC_CURRENT_TAPE_INFOS.tayBuffer = (revreal *) malloc(sizeof(revreal) * bufferSize); - - if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) - fail(ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED); - ADOLC_CURRENT_TAPE_INFOS.deg_save = degreeSave; - if (degreeSave >= 0 ) ADOLC_CURRENT_TAPE_INFOS.keepTaylors = 1; - ADOLC_CURRENT_TAPE_INFOS.currTay = ADOLC_CURRENT_TAPE_INFOS.tayBuffer; - ADOLC_CURRENT_TAPE_INFOS.lastTayP1 = ADOLC_CURRENT_TAPE_INFOS.currTay + bufferSize; - ADOLC_CURRENT_TAPE_INFOS.inUse = 1; - - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape = 0; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer != NULL) { +#if defined(ADOLC_DEBUG) + fprintf(DIAG_OUT, + "\nADOL-C warning: !!! Taylor information for tape %d" + " found that will be overwritten !!!\n\n", + ADOLC_CURRENT_TAPE_INFOS.tapeID); +#endif + taylor_close(false); + } else { /* check if new buffer is allowed */ + if (numTBuffersInUse == ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers) + fail(ADOLC_TAPING_TO_MANY_TAYLOR_BUFFERS); + ++numTBuffersInUse; + if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName == NULL) + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName = + createFileName(ADOLC_CURRENT_TAPE_INFOS.tapeID, TAYLORS_TAPE); + } + + /* initial setups */ + if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) + ADOLC_CURRENT_TAPE_INFOS.tayBuffer = + (revreal *)malloc(sizeof(revreal) * bufferSize); + + if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) + fail(ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED); + ADOLC_CURRENT_TAPE_INFOS.deg_save = degreeSave; + if (degreeSave >= 0) + ADOLC_CURRENT_TAPE_INFOS.keepTaylors = 1; + ADOLC_CURRENT_TAPE_INFOS.currTay = ADOLC_CURRENT_TAPE_INFOS.tayBuffer; + ADOLC_CURRENT_TAPE_INFOS.lastTayP1 = + ADOLC_CURRENT_TAPE_INFOS.currTay + bufferSize; + ADOLC_CURRENT_TAPE_INFOS.inUse = 1; + + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape = 0; } /****************************************************************************/ /* Close the taylor file, reset data. */ /****************************************************************************/ void taylor_close(bool resetData) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (resetData == false) { - /* enforces failure of reverse => retaping */ - ADOLC_CURRENT_TAPE_INFOS.deg_save = -1; - if (ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) { - fclose(ADOLC_CURRENT_TAPE_INFOS.tay_file); - remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName); - ADOLC_CURRENT_TAPE_INFOS.tay_file = NULL; - } - return; - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (resetData == false) { + /* enforces failure of reverse => retaping */ + ADOLC_CURRENT_TAPE_INFOS.deg_save = -1; if (ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) { - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - put_tay_block(ADOLC_CURRENT_TAPE_INFOS.currTay); - } else { - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape = - ADOLC_CURRENT_TAPE_INFOS.currTay - - ADOLC_CURRENT_TAPE_INFOS.tayBuffer; + fclose(ADOLC_CURRENT_TAPE_INFOS.tay_file); + remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName); + ADOLC_CURRENT_TAPE_INFOS.tay_file = NULL; } - ADOLC_CURRENT_TAPE_INFOS.lastTayBlockInCore = 1; - ADOLC_CURRENT_TAPE_INFOS.stats[TAY_STACK_SIZE] = - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - - /* keep track of the Ind/Dep counts of the taylor stack */ - ADOLC_CURRENT_TAPE_INFOS.tay_numInds = - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]; - ADOLC_CURRENT_TAPE_INFOS.tay_numDeps = - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS]; - - #if defined(ADOLC_DEBUG) - if (ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) - fprintf(DIAG_OUT, "\n ADOL-C debug: Taylor file of length %d bytes " - "completed\n", - (int)(ADOLC_CURRENT_TAPE_INFOS.numTays_Tape*sizeof(revreal))); - else - fprintf(DIAG_OUT, "\n ADOL-C debug: Taylor array of length %d bytes " - "completed\n", - (int)(ADOLC_CURRENT_TAPE_INFOS.numTays_Tape*sizeof(revreal))); - #endif + return; + } + + if (ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + put_tay_block(ADOLC_CURRENT_TAPE_INFOS.currTay); + } else { + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape = + ADOLC_CURRENT_TAPE_INFOS.currTay - ADOLC_CURRENT_TAPE_INFOS.tayBuffer; + } + ADOLC_CURRENT_TAPE_INFOS.lastTayBlockInCore = 1; + ADOLC_CURRENT_TAPE_INFOS.stats[TAY_STACK_SIZE] = + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + + /* keep track of the Ind/Dep counts of the taylor stack */ + ADOLC_CURRENT_TAPE_INFOS.tay_numInds = + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]; + ADOLC_CURRENT_TAPE_INFOS.tay_numDeps = + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS]; + +#if defined(ADOLC_DEBUG) + if (ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) + fprintf(DIAG_OUT, + "\n ADOL-C debug: Taylor file of length %d bytes " + "completed\n", + (int)(ADOLC_CURRENT_TAPE_INFOS.numTays_Tape * sizeof(revreal))); + else + fprintf(DIAG_OUT, + "\n ADOL-C debug: Taylor array of length %d bytes " + "completed\n", + (int)(ADOLC_CURRENT_TAPE_INFOS.numTays_Tape * sizeof(revreal))); +#endif } /****************************************************************************/ /* Initializes a reverse sweep. */ /****************************************************************************/ -void taylor_back (short tag, int* dep, int* ind, int* degree) { - int i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* this should be removed soon since values can be accessed via */ - /* ADOLC_CURRENT_TAPE_INFOS directly */ - *dep = ADOLC_CURRENT_TAPE_INFOS.tay_numDeps; - *ind = ADOLC_CURRENT_TAPE_INFOS.tay_numInds; - *degree = ADOLC_CURRENT_TAPE_INFOS.deg_save; - - if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) - fail(ADOLC_REVERSE_NO_TAYLOR_STACK); - ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber = - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape / - ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; - number = ADOLC_CURRENT_TAPE_INFOS.numTays_Tape % +void taylor_back(short tag, int *dep, int *ind, int *degree) { + int i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* this should be removed soon since values can be accessed via */ + /* ADOLC_CURRENT_TAPE_INFOS directly */ + *dep = ADOLC_CURRENT_TAPE_INFOS.tay_numDeps; + *ind = ADOLC_CURRENT_TAPE_INFOS.tay_numInds; + *degree = ADOLC_CURRENT_TAPE_INFOS.deg_save; + + if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) + fail(ADOLC_REVERSE_NO_TAYLOR_STACK); + ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber = + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape / + ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; + number = ADOLC_CURRENT_TAPE_INFOS.numTays_Tape % ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; - ADOLC_CURRENT_TAPE_INFOS.currTay = - ADOLC_CURRENT_TAPE_INFOS.tayBuffer + number; - if (ADOLC_CURRENT_TAPE_INFOS.lastTayBlockInCore != 1) { - if ( fseek(ADOLC_CURRENT_TAPE_INFOS.tay_file, - sizeof(revreal) * - ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber * - ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE], - SEEK_SET) - == -1 ) fail(ADOLC_EVAL_SEEK_VALUE_STACK); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(revreal); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if ((failAdditionalInfo1 = - fread(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + - i * chunkSize, chunkSize * sizeof(revreal), 1, - ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - remain = number % chunkSize; - if (remain != 0) - if ((failAdditionalInfo1 = - fread(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + - chunks * chunkSize, remain * sizeof(revreal), 1, - ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - } - --ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber; + ADOLC_CURRENT_TAPE_INFOS.currTay = + ADOLC_CURRENT_TAPE_INFOS.tayBuffer + number; + if (ADOLC_CURRENT_TAPE_INFOS.lastTayBlockInCore != 1) { + if (fseek(ADOLC_CURRENT_TAPE_INFOS.tay_file, + sizeof(revreal) * ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber * + ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE], + SEEK_SET) == -1) + fail(ADOLC_EVAL_SEEK_VALUE_STACK); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(revreal); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if ((failAdditionalInfo1 = + fread(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + i * chunkSize, + chunkSize * sizeof(revreal), 1, + ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + remain = number % chunkSize; + if (remain != 0) + if ((failAdditionalInfo1 = + fread(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + chunks * chunkSize, + remain * sizeof(revreal), 1, + ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + } + --ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber; } /****************************************************************************/ @@ -830,33 +852,37 @@ void taylor_back (short tag, int* dep, int* ind, int* degree) { /* taylor tape. */ /****************************************************************************/ void write_taylor(locint loc, int keep) { - revreal *i; - double *T; - ADOLC_OPENMP_THREAD_NUMBER; - - ADOLC_OPENMP_GET_THREAD_NUMBER; - T = ADOLC_CURRENT_TAPE_INFOS.dpp_T[loc]; - - /* write data to buffer and put buffer to disk as long as data remain in - * the T-buffer => don't create an empty value stack buffer! */ - while (ADOLC_CURRENT_TAPE_INFOS.currTay + keep > ADOLC_CURRENT_TAPE_INFOS.lastTayP1) { - for (i = ADOLC_CURRENT_TAPE_INFOS.currTay; i < ADOLC_CURRENT_TAPE_INFOS.lastTayP1; ++i) { - *i = (revreal) * T; - /* In this assignment the precision will be sacrificed if the type - * revreal is defined as float. */ - ++T; - } - keep -= ADOLC_CURRENT_TAPE_INFOS.lastTayP1 - ADOLC_CURRENT_TAPE_INFOS.currTay; - put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1); - } - - for (i = ADOLC_CURRENT_TAPE_INFOS.currTay; i < ADOLC_CURRENT_TAPE_INFOS.currTay + keep; ++i) { - *i = (revreal) * T; - /* In this assignment the precision will be sacrificed - * if the type revreal is defined as float. */ - ++T; - } - ADOLC_CURRENT_TAPE_INFOS.currTay += keep; + revreal *i; + double *T; + ADOLC_OPENMP_THREAD_NUMBER; + + ADOLC_OPENMP_GET_THREAD_NUMBER; + T = ADOLC_CURRENT_TAPE_INFOS.dpp_T[loc]; + + /* write data to buffer and put buffer to disk as long as data remain in + * the T-buffer => don't create an empty value stack buffer! */ + while (ADOLC_CURRENT_TAPE_INFOS.currTay + keep > + ADOLC_CURRENT_TAPE_INFOS.lastTayP1) { + for (i = ADOLC_CURRENT_TAPE_INFOS.currTay; + i < ADOLC_CURRENT_TAPE_INFOS.lastTayP1; ++i) { + *i = (revreal)*T; + /* In this assignment the precision will be sacrificed if the type + * revreal is defined as float. */ + ++T; + } + keep -= + ADOLC_CURRENT_TAPE_INFOS.lastTayP1 - ADOLC_CURRENT_TAPE_INFOS.currTay; + put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1); + } + + for (i = ADOLC_CURRENT_TAPE_INFOS.currTay; + i < ADOLC_CURRENT_TAPE_INFOS.currTay + keep; ++i) { + *i = (revreal)*T; + /* In this assignment the precision will be sacrificed + * if the type revreal is defined as float. */ + ++T; + } + ADOLC_CURRENT_TAPE_INFOS.currTay += keep; } /****************************************************************************/ @@ -865,92 +891,97 @@ void write_taylor(locint loc, int keep) { /* taylor tape. */ /*--------------------------------------------------------------------------*/ void write_taylors(locint loc, int keep, int degree, int numDir) { - int i, j; - double *T; - ADOLC_OPENMP_THREAD_NUMBER; - - ADOLC_OPENMP_GET_THREAD_NUMBER; - T = ADOLC_CURRENT_TAPE_INFOS.dpp_T[loc]; - - for (j = 0; j < numDir; ++j) { - for (i = 0; i < keep; ++i) { - if (ADOLC_CURRENT_TAPE_INFOS.currTay == ADOLC_CURRENT_TAPE_INFOS.lastTayP1) - put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1); - *ADOLC_CURRENT_TAPE_INFOS.currTay = (revreal) * T; - /* The precision will be sacrificed if the type - * revreal is defined as float. */ - ++ADOLC_CURRENT_TAPE_INFOS.currTay; - ++T; - } -/* for (i = keep; i < degree; ++i) ++T;*/ - if (degree > keep) - T += degree - keep; + int i, j; + double *T; + ADOLC_OPENMP_THREAD_NUMBER; + + ADOLC_OPENMP_GET_THREAD_NUMBER; + T = ADOLC_CURRENT_TAPE_INFOS.dpp_T[loc]; + + for (j = 0; j < numDir; ++j) { + for (i = 0; i < keep; ++i) { + if (ADOLC_CURRENT_TAPE_INFOS.currTay == + ADOLC_CURRENT_TAPE_INFOS.lastTayP1) + put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1); + *ADOLC_CURRENT_TAPE_INFOS.currTay = (revreal)*T; + /* The precision will be sacrificed if the type + * revreal is defined as float. */ + ++ADOLC_CURRENT_TAPE_INFOS.currTay; + ++T; } + /* for (i = keep; i < degree; ++i) ++T;*/ + if (degree > keep) + T += degree - keep; + } } /****************************************************************************/ /* Write_scaylors writes # size elements from x to the taylor buffer. */ /****************************************************************************/ void write_scaylors(revreal *x, uint size) { - revreal *i; - uint j = 0; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* write data to buffer and put buffer to disk as long as data remain in - * the x-buffer => don't create an empty value stack buffer! */ - while (ADOLC_CURRENT_TAPE_INFOS.currTay + size > ADOLC_CURRENT_TAPE_INFOS.lastTayP1) { - for (i = ADOLC_CURRENT_TAPE_INFOS.currTay; i < ADOLC_CURRENT_TAPE_INFOS.lastTayP1; ++i) { - *i = x[j]; - ++j; - } - size -= ADOLC_CURRENT_TAPE_INFOS.lastTayP1 - ADOLC_CURRENT_TAPE_INFOS.currTay; - put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1); - } - - for (i = ADOLC_CURRENT_TAPE_INFOS.currTay; i < ADOLC_CURRENT_TAPE_INFOS.tayBuffer + size; ++i) { - *ADOLC_CURRENT_TAPE_INFOS.currTay = x[j]; - ++j; - } - ADOLC_CURRENT_TAPE_INFOS.currTay += size; + revreal *i; + uint j = 0; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* write data to buffer and put buffer to disk as long as data remain in + * the x-buffer => don't create an empty value stack buffer! */ + while (ADOLC_CURRENT_TAPE_INFOS.currTay + size > + ADOLC_CURRENT_TAPE_INFOS.lastTayP1) { + for (i = ADOLC_CURRENT_TAPE_INFOS.currTay; + i < ADOLC_CURRENT_TAPE_INFOS.lastTayP1; ++i) { + *i = x[j]; + ++j; + } + size -= + ADOLC_CURRENT_TAPE_INFOS.lastTayP1 - ADOLC_CURRENT_TAPE_INFOS.currTay; + put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1); + } + + for (i = ADOLC_CURRENT_TAPE_INFOS.currTay; + i < ADOLC_CURRENT_TAPE_INFOS.tayBuffer + size; ++i) { + *ADOLC_CURRENT_TAPE_INFOS.currTay = x[j]; + ++j; + } + ADOLC_CURRENT_TAPE_INFOS.currTay += size; } /****************************************************************************/ /* Writes the value stack buffer onto hard disk. */ /****************************************************************************/ void put_tay_block(revreal *lastTayP1) { - int i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_CURRENT_TAPE_INFOS.tay_file == NULL) { - ADOLC_CURRENT_TAPE_INFOS.tay_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName, "w+b"); - if (ADOLC_CURRENT_TAPE_INFOS.tay_file == NULL) - fail(ADOLC_TAPING_TAYLOR_OPEN_FAILED); - } - number = lastTayP1 - ADOLC_CURRENT_TAPE_INFOS.tayBuffer; - if (number != 0) { - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(revreal); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if ((failAdditionalInfo1 = - fwrite(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + i * - chunkSize, chunkSize * sizeof(revreal), 1, - ADOLC_CURRENT_TAPE_INFOS.tay_file) ) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - remain = number % chunkSize; - if (remain != 0) - if ((failAdditionalInfo1 = - fwrite(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + chunks * - chunkSize, remain * sizeof(revreal), 1, - ADOLC_CURRENT_TAPE_INFOS.tay_file) ) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += number; - } - ADOLC_CURRENT_TAPE_INFOS.currTay = ADOLC_CURRENT_TAPE_INFOS.tayBuffer; - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + int i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_CURRENT_TAPE_INFOS.tay_file == NULL) { + ADOLC_CURRENT_TAPE_INFOS.tay_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName, "w+b"); + if (ADOLC_CURRENT_TAPE_INFOS.tay_file == NULL) + fail(ADOLC_TAPING_TAYLOR_OPEN_FAILED); + } + number = lastTayP1 - ADOLC_CURRENT_TAPE_INFOS.tayBuffer; + if (number != 0) { + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(revreal); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if ((failAdditionalInfo1 = + fwrite(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + i * chunkSize, + chunkSize * sizeof(revreal), 1, + ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + remain = number % chunkSize; + if (remain != 0) + if ((failAdditionalInfo1 = + fwrite(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + chunks * chunkSize, + remain * sizeof(revreal), 1, + ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += number; + } + ADOLC_CURRENT_TAPE_INFOS.currTay = ADOLC_CURRENT_TAPE_INFOS.tayBuffer; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; } /****************************************************************************/ @@ -958,33 +989,34 @@ void put_tay_block(revreal *lastTayP1) { /* taylor buffer. --- Higher Order Scalar */ /****************************************************************************/ void get_taylors(locint loc, int degree) { - int j; - revreal *i; - revreal *T; - ADOLC_OPENMP_THREAD_NUMBER; - - ADOLC_OPENMP_GET_THREAD_NUMBER; - T = ADOLC_CURRENT_TAPE_INFOS.rpp_T[loc] + degree; - - /* As long as all values from the taylor stack buffer will be used copy - * them into the taylor buffer and load the next (previous) buffer. */ - while (ADOLC_CURRENT_TAPE_INFOS.currTay - degree < ADOLC_CURRENT_TAPE_INFOS.tayBuffer) { - for ( i = ADOLC_CURRENT_TAPE_INFOS.currTay - 1; - i >= ADOLC_CURRENT_TAPE_INFOS.tayBuffer; - --i ) { - --T; - *T = *i; - } - degree -= ADOLC_CURRENT_TAPE_INFOS.currTay - ADOLC_CURRENT_TAPE_INFOS.tayBuffer; - get_tay_block_r(); - } - - /* Copy the remaining values from the stack into the buffer ... */ - for (j = 0; j < degree; ++j) { - --ADOLC_CURRENT_TAPE_INFOS.currTay; - --T; - *T = *ADOLC_CURRENT_TAPE_INFOS.currTay; - } + int j; + revreal *i; + revreal *T; + ADOLC_OPENMP_THREAD_NUMBER; + + ADOLC_OPENMP_GET_THREAD_NUMBER; + T = ADOLC_CURRENT_TAPE_INFOS.rpp_T[loc] + degree; + + /* As long as all values from the taylor stack buffer will be used copy + * them into the taylor buffer and load the next (previous) buffer. */ + while (ADOLC_CURRENT_TAPE_INFOS.currTay - degree < + ADOLC_CURRENT_TAPE_INFOS.tayBuffer) { + for (i = ADOLC_CURRENT_TAPE_INFOS.currTay - 1; + i >= ADOLC_CURRENT_TAPE_INFOS.tayBuffer; --i) { + --T; + *T = *i; + } + degree -= + ADOLC_CURRENT_TAPE_INFOS.currTay - ADOLC_CURRENT_TAPE_INFOS.tayBuffer; + get_tay_block_r(); + } + + /* Copy the remaining values from the stack into the buffer ... */ + for (j = 0; j < degree; ++j) { + --ADOLC_CURRENT_TAPE_INFOS.currTay; + --T; + *T = *ADOLC_CURRENT_TAPE_INFOS.currTay; + } } /****************************************************************************/ @@ -992,67 +1024,70 @@ void get_taylors(locint loc, int degree) { /* taylor buffer. --- Higher Order Vector */ /****************************************************************************/ void get_taylors_p(locint loc, int degree, int numDir) { - int i, j; - revreal *T; - ADOLC_OPENMP_THREAD_NUMBER; - - ADOLC_OPENMP_GET_THREAD_NUMBER; - T = ADOLC_CURRENT_TAPE_INFOS.rpp_T[loc] + degree * numDir; - - /* update the directions except the base point parts */ - for (j = 0; j < numDir; ++j) { - for (i = 1; i < degree; ++i) { - if (ADOLC_CURRENT_TAPE_INFOS.currTay == ADOLC_CURRENT_TAPE_INFOS.tayBuffer) - get_tay_block_r(); - --ADOLC_CURRENT_TAPE_INFOS.currTay; - --T; - *T = *ADOLC_CURRENT_TAPE_INFOS.currTay; - } - --T; /* skip the base point part */ - } - /* now update the base point parts */ - if (ADOLC_CURRENT_TAPE_INFOS.currTay == ADOLC_CURRENT_TAPE_INFOS.tayBuffer) - get_tay_block_r(); - --ADOLC_CURRENT_TAPE_INFOS.currTay; - for (i = 0; i < numDir; ++i) { - *T = *ADOLC_CURRENT_TAPE_INFOS.currTay; - T += degree; + int i, j; + revreal *T; + ADOLC_OPENMP_THREAD_NUMBER; + + ADOLC_OPENMP_GET_THREAD_NUMBER; + T = ADOLC_CURRENT_TAPE_INFOS.rpp_T[loc] + degree * numDir; + + /* update the directions except the base point parts */ + for (j = 0; j < numDir; ++j) { + for (i = 1; i < degree; ++i) { + if (ADOLC_CURRENT_TAPE_INFOS.currTay == + ADOLC_CURRENT_TAPE_INFOS.tayBuffer) + get_tay_block_r(); + --ADOLC_CURRENT_TAPE_INFOS.currTay; + --T; + *T = *ADOLC_CURRENT_TAPE_INFOS.currTay; } + --T; /* skip the base point part */ + } + /* now update the base point parts */ + if (ADOLC_CURRENT_TAPE_INFOS.currTay == ADOLC_CURRENT_TAPE_INFOS.tayBuffer) + get_tay_block_r(); + --ADOLC_CURRENT_TAPE_INFOS.currTay; + for (i = 0; i < numDir; ++i) { + *T = *ADOLC_CURRENT_TAPE_INFOS.currTay; + T += degree; + } } /****************************************************************************/ /* Gets the next (previous block) of the value stack */ /****************************************************************************/ void get_tay_block_r() { - int i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - ADOLC_CURRENT_TAPE_INFOS.lastTayBlockInCore = 0; - number = ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; - if ( fseek(ADOLC_CURRENT_TAPE_INFOS.tay_file, sizeof(revreal) * - ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber * number, SEEK_SET) - == -1 ) - fail(ADOLC_EVAL_SEEK_VALUE_STACK); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(revreal); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if ((failAdditionalInfo1 = fread(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + - i * chunkSize, chunkSize * sizeof(revreal), 1, - ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - remain = number % chunkSize; - if (remain != 0) - if ((failAdditionalInfo1 = fread(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + - chunks * chunkSize, remain * sizeof(revreal), 1, - ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - ADOLC_CURRENT_TAPE_INFOS.currTay = ADOLC_CURRENT_TAPE_INFOS.lastTayP1; - --ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber; + int i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + ADOLC_CURRENT_TAPE_INFOS.lastTayBlockInCore = 0; + number = ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; + if (fseek(ADOLC_CURRENT_TAPE_INFOS.tay_file, + sizeof(revreal) * ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber * + number, + SEEK_SET) == -1) + fail(ADOLC_EVAL_SEEK_VALUE_STACK); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(revreal); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if ((failAdditionalInfo1 = + fread(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + i * chunkSize, + chunkSize * sizeof(revreal), 1, + ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + remain = number % chunkSize; + if (remain != 0) + if ((failAdditionalInfo1 = + fread(ADOLC_CURRENT_TAPE_INFOS.tayBuffer + chunks * chunkSize, + remain * sizeof(revreal), 1, + ADOLC_CURRENT_TAPE_INFOS.tay_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + ADOLC_CURRENT_TAPE_INFOS.currTay = ADOLC_CURRENT_TAPE_INFOS.lastTayP1; + --ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber; } - /****************************************************************************/ /****************************************************************************/ /* NON-VALUE-STACK FUNCTIONS */ @@ -1060,29 +1095,31 @@ void get_tay_block_r() { /****************************************************************************/ void initTapeBuffers() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_CURRENT_TAPE_INFOS.opBuffer == NULL) - ADOLC_CURRENT_TAPE_INFOS.opBuffer = (unsigned char *) - malloc(ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE] * - sizeof(unsigned char)); - if (ADOLC_CURRENT_TAPE_INFOS.locBuffer == NULL) - ADOLC_CURRENT_TAPE_INFOS.locBuffer = (locint *) - malloc(ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE] * sizeof(locint)); - if (ADOLC_CURRENT_TAPE_INFOS.valBuffer == NULL) - ADOLC_CURRENT_TAPE_INFOS.valBuffer = (double *) - malloc(ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE] * sizeof(double)); - if ( ADOLC_CURRENT_TAPE_INFOS.opBuffer == NULL || - ADOLC_CURRENT_TAPE_INFOS.locBuffer == NULL || - ADOLC_CURRENT_TAPE_INFOS.valBuffer == NULL ) - fail(ADOLC_TAPING_BUFFER_ALLOCATION_FAILED); - ADOLC_CURRENT_TAPE_INFOS.lastOpP1 = ADOLC_CURRENT_TAPE_INFOS.opBuffer + - ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]; - ADOLC_CURRENT_TAPE_INFOS.lastLocP1 = ADOLC_CURRENT_TAPE_INFOS.locBuffer + - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; - ADOLC_CURRENT_TAPE_INFOS.lastValP1 = ADOLC_CURRENT_TAPE_INFOS.valBuffer + - ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_CURRENT_TAPE_INFOS.opBuffer == NULL) + ADOLC_CURRENT_TAPE_INFOS.opBuffer = (unsigned char *)malloc( + ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE] * sizeof(unsigned char)); + if (ADOLC_CURRENT_TAPE_INFOS.locBuffer == NULL) + ADOLC_CURRENT_TAPE_INFOS.locBuffer = (locint *)malloc( + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE] * sizeof(locint)); + if (ADOLC_CURRENT_TAPE_INFOS.valBuffer == NULL) + ADOLC_CURRENT_TAPE_INFOS.valBuffer = (double *)malloc( + ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE] * sizeof(double)); + if (ADOLC_CURRENT_TAPE_INFOS.opBuffer == NULL || + ADOLC_CURRENT_TAPE_INFOS.locBuffer == NULL || + ADOLC_CURRENT_TAPE_INFOS.valBuffer == NULL) + fail(ADOLC_TAPING_BUFFER_ALLOCATION_FAILED); + ADOLC_CURRENT_TAPE_INFOS.lastOpP1 = + ADOLC_CURRENT_TAPE_INFOS.opBuffer + + ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]; + ADOLC_CURRENT_TAPE_INFOS.lastLocP1 = + ADOLC_CURRENT_TAPE_INFOS.locBuffer + + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; + ADOLC_CURRENT_TAPE_INFOS.lastValP1 = + ADOLC_CURRENT_TAPE_INFOS.valBuffer + + ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; } /****************************************************************************/ @@ -1091,226 +1128,222 @@ void initTapeBuffers() { /* files names, and calls appropriate setup routines. */ /****************************************************************************/ void start_trace() { - int i, space; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - initTapeBuffers(); - ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer; - ADOLC_CURRENT_TAPE_INFOS.currLoc = ADOLC_CURRENT_TAPE_INFOS.locBuffer; - ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.valBuffer; - ADOLC_CURRENT_TAPE_INFOS.num_eq_prod = 0; - ADOLC_CURRENT_TAPE_INFOS.numSwitches = 0; - ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_TAPING; - - /* Put operation denoting the start_of_the tape */ - put_op(start_of_tape); - - /* Leave space for the stats */ - space = STAT_SIZE * sizeof(size_t) + sizeof(ADOLC_ID); - if (space > statSpace * sizeof(locint)) - fail(ADOLC_MORE_STAT_SPACE_REQUIRED); - for (i = 0; i < statSpace; ++i) ADOLC_PUT_LOCINT(0); - - /* initialize value stack if necessary */ - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - taylor_begin(ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE], 0); + int i, space; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - /* mark possible (hard disk) tape creation */ - markNewTape(); + initTapeBuffers(); + ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer; + ADOLC_CURRENT_TAPE_INFOS.currLoc = ADOLC_CURRENT_TAPE_INFOS.locBuffer; + ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.valBuffer; + ADOLC_CURRENT_TAPE_INFOS.num_eq_prod = 0; + ADOLC_CURRENT_TAPE_INFOS.numSwitches = 0; + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_TAPING; + + /* Put operation denoting the start_of_the tape */ + put_op(start_of_tape); + + /* Leave space for the stats */ + space = STAT_SIZE * sizeof(size_t) + sizeof(ADOLC_ID); + if (space > statSpace * sizeof(locint)) + fail(ADOLC_MORE_STAT_SPACE_REQUIRED); + for (i = 0; i < statSpace; ++i) + ADOLC_PUT_LOCINT(0); + + /* initialize value stack if necessary */ + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + taylor_begin(ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE], 0); + + /* mark possible (hard disk) tape creation */ + markNewTape(); } static void save_params() { - size_t np; - size_t ip, avail, remain, chunk; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM] = - ADOLC_GLOBAL_TAPE_VARS.numparam; - if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore != NULL) - free(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore); - - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore = - malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]*sizeof(double)); - - // Sometimes we have pStore == nullptr and stats[NUM_PARAM] == 0. - // Calling memcpy with that is undefined behavior, and sanitizers will issue a warning. - if (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM] > 0) - { - memcpy(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore, - ADOLC_GLOBAL_TAPE_VARS.pStore, - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]*sizeof(double)); - } - free_all_taping_params(); - if (ADOLC_CURRENT_TAPE_INFOS.currVal + - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM] < - ADOLC_CURRENT_TAPE_INFOS.lastValP1) - put_vals_notWriteBlock(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore, - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]); - else { - np = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; - ip = 0; - while (ip < np) { - avail = ADOLC_CURRENT_TAPE_INFOS.lastValP1 - ADOLC_CURRENT_TAPE_INFOS.currVal; - remain = np - ip; - chunk = (avail 0) { + memcpy(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore, + ADOLC_GLOBAL_TAPE_VARS.pStore, + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM] * sizeof(double)); + } + free_all_taping_params(); + if (ADOLC_CURRENT_TAPE_INFOS.currVal + + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM] < + ADOLC_CURRENT_TAPE_INFOS.lastValP1) + put_vals_notWriteBlock(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore, + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]); + else { + np = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; + ip = 0; + while (ip < np) { + avail = + ADOLC_CURRENT_TAPE_INFOS.lastValP1 - ADOLC_CURRENT_TAPE_INFOS.currVal; + remain = np - ip; + chunk = (avail < remain) ? avail : remain; + put_vals_notWriteBlock( + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore + ip, chunk); + ip += chunk; + if (ip < np) + put_val_block(ADOLC_CURRENT_TAPE_INFOS.lastValP1); } + } } /****************************************************************************/ /* Stop Tracing. Clean up, and turn off trace_flag. */ /****************************************************************************/ void stop_trace(int flag) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - put_op(end_of_tape); /* Mark end of tape. */ - save_params(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + put_op(end_of_tape); /* Mark end of tape. */ + save_params(); - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS] = - ADOLC_CURRENT_TAPE_INFOS.numInds; - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS] = - ADOLC_CURRENT_TAPE_INFOS.numDeps; - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] = - ADOLC_GLOBAL_TAPE_VARS.storeSize; + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS] = + ADOLC_CURRENT_TAPE_INFOS.numInds; + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS] = + ADOLC_CURRENT_TAPE_INFOS.numDeps; + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] = + ADOLC_GLOBAL_TAPE_VARS.storeSize; - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_EQ_PROD] = - ADOLC_CURRENT_TAPE_INFOS.num_eq_prod; + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_EQ_PROD] = + ADOLC_CURRENT_TAPE_INFOS.num_eq_prod; - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES] = - ADOLC_CURRENT_TAPE_INFOS.numSwitches; + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES] = + ADOLC_CURRENT_TAPE_INFOS.numSwitches; - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) - taylor_close(true); - - ADOLC_CURRENT_TAPE_INFOS.stats[TAY_STACK_SIZE] = - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; - - /* The taylor stack size base estimation results in a doubled taylor count - * if we tape with keep (taylors counted in adouble.cpp/avector.cpp and - * "keep_stock" even if not written and a second time when actually - * written by "put_tay_block"). Correction follows here. */ - if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0 && - ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) - { - ADOLC_CURRENT_TAPE_INFOS.stats[TAY_STACK_SIZE] /= 2; - ADOLC_CURRENT_TAPE_INFOS.numTays_Tape /= 2; - } + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) + taylor_close(true); - close_tape(flag); /* closes the tape, files up stats, and writes the - tape stats to the integer tape */ + ADOLC_CURRENT_TAPE_INFOS.stats[TAY_STACK_SIZE] = + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape; + + /* The taylor stack size base estimation results in a doubled taylor count + * if we tape with keep (taylors counted in adouble.cpp/avector.cpp and + * "keep_stock" even if not written and a second time when actually + * written by "put_tay_block"). Correction follows here. */ + if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0 && + ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) { + ADOLC_CURRENT_TAPE_INFOS.stats[TAY_STACK_SIZE] /= 2; + ADOLC_CURRENT_TAPE_INFOS.numTays_Tape /= 2; + } + + close_tape(flag); /* closes the tape, files up stats, and writes the + tape stats to the integer tape */ } /****************************************************************************/ /* Close open tapes, update stats and clean up. */ /****************************************************************************/ void close_tape(int flag) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - /* finish operations tape, close it, update stats */ - if (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) { - if (ADOLC_CURRENT_TAPE_INFOS.currOp != - ADOLC_CURRENT_TAPE_INFOS.opBuffer) - { - put_op_block(ADOLC_CURRENT_TAPE_INFOS.currOp); - } - if (ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) - fclose(ADOLC_CURRENT_TAPE_INFOS.op_file); - ADOLC_CURRENT_TAPE_INFOS.op_file = NULL; - ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] = 1; - free(ADOLC_CURRENT_TAPE_INFOS.opBuffer); - ADOLC_CURRENT_TAPE_INFOS.opBuffer = NULL; - } else { - ADOLC_CURRENT_TAPE_INFOS.numOps_Tape = - ADOLC_CURRENT_TAPE_INFOS.currOp - ADOLC_CURRENT_TAPE_INFOS.opBuffer; - } - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] = - ADOLC_CURRENT_TAPE_INFOS.numOps_Tape; - - /* finish constants tape, close it, update stats */ - if (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { - if (ADOLC_CURRENT_TAPE_INFOS.currVal != - ADOLC_CURRENT_TAPE_INFOS.valBuffer) - { - put_val_block(ADOLC_CURRENT_TAPE_INFOS.currVal); - } - if (ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) - fclose(ADOLC_CURRENT_TAPE_INFOS.val_file); - ADOLC_CURRENT_TAPE_INFOS.val_file = NULL; - ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] = 1; - free(ADOLC_CURRENT_TAPE_INFOS.valBuffer); - ADOLC_CURRENT_TAPE_INFOS.valBuffer = NULL; - } else { - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape = - ADOLC_CURRENT_TAPE_INFOS.currVal - ADOLC_CURRENT_TAPE_INFOS.valBuffer; - } - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] = - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape; - - /* finish locations tape, update and write tape stats, close tape */ - if (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.loc_file != NULL) { - if (ADOLC_CURRENT_TAPE_INFOS.currLoc != - ADOLC_CURRENT_TAPE_INFOS.locBuffer) - { - put_loc_block(ADOLC_CURRENT_TAPE_INFOS.currLoc); - } - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] = - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape; - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_FILE_ACCESS] = 1; - /* write tape stats */ - fseek(ADOLC_CURRENT_TAPE_INFOS.loc_file, 0, 0); - fwrite(&adolc_id, sizeof(ADOLC_ID), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file); - fwrite(ADOLC_CURRENT_TAPE_INFOS.stats, STAT_SIZE * sizeof(size_t), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file); - fclose(ADOLC_CURRENT_TAPE_INFOS.loc_file); - ADOLC_CURRENT_TAPE_INFOS.loc_file = NULL; - free(ADOLC_CURRENT_TAPE_INFOS.locBuffer); - ADOLC_CURRENT_TAPE_INFOS.locBuffer = NULL; - } else { - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape = - ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer; - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] = - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape; - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + /* finish operations tape, close it, update stats */ + if (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.currOp != ADOLC_CURRENT_TAPE_INFOS.opBuffer) { + put_op_block(ADOLC_CURRENT_TAPE_INFOS.currOp); + } + if (ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) + fclose(ADOLC_CURRENT_TAPE_INFOS.op_file); + ADOLC_CURRENT_TAPE_INFOS.op_file = NULL; + ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] = 1; + free(ADOLC_CURRENT_TAPE_INFOS.opBuffer); + ADOLC_CURRENT_TAPE_INFOS.opBuffer = NULL; + } else { + ADOLC_CURRENT_TAPE_INFOS.numOps_Tape = + ADOLC_CURRENT_TAPE_INFOS.currOp - ADOLC_CURRENT_TAPE_INFOS.opBuffer; + } + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] = + ADOLC_CURRENT_TAPE_INFOS.numOps_Tape; + + /* finish constants tape, close it, update stats */ + if (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.currVal != + ADOLC_CURRENT_TAPE_INFOS.valBuffer) { + put_val_block(ADOLC_CURRENT_TAPE_INFOS.currVal); + } + if (ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) + fclose(ADOLC_CURRENT_TAPE_INFOS.val_file); + ADOLC_CURRENT_TAPE_INFOS.val_file = NULL; + ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] = 1; + free(ADOLC_CURRENT_TAPE_INFOS.valBuffer); + ADOLC_CURRENT_TAPE_INFOS.valBuffer = NULL; + } else { + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape = + ADOLC_CURRENT_TAPE_INFOS.currVal - ADOLC_CURRENT_TAPE_INFOS.valBuffer; + } + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] = + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape; + + /* finish locations tape, update and write tape stats, close tape */ + if (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.loc_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.currLoc != + ADOLC_CURRENT_TAPE_INFOS.locBuffer) { + put_loc_block(ADOLC_CURRENT_TAPE_INFOS.currLoc); + } + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] = + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape; + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_FILE_ACCESS] = 1; + /* write tape stats */ + fseek(ADOLC_CURRENT_TAPE_INFOS.loc_file, 0, 0); + fwrite(&adolc_id, sizeof(ADOLC_ID), 1, ADOLC_CURRENT_TAPE_INFOS.loc_file); + fwrite(ADOLC_CURRENT_TAPE_INFOS.stats, STAT_SIZE * sizeof(size_t), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file); + fclose(ADOLC_CURRENT_TAPE_INFOS.loc_file); + ADOLC_CURRENT_TAPE_INFOS.loc_file = NULL; + free(ADOLC_CURRENT_TAPE_INFOS.locBuffer); + ADOLC_CURRENT_TAPE_INFOS.locBuffer = NULL; + } else { + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape = + ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer; + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] = + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape; + } } /****************************************************************************/ /* Free all resources used by a tape before overwriting the tape. */ /****************************************************************************/ void freeTapeResources(TapeInfos *tapeInfos) { - free(tapeInfos->opBuffer); - tapeInfos->opBuffer = NULL; - free(tapeInfos->locBuffer); - tapeInfos->locBuffer = NULL; - free(tapeInfos->valBuffer); - tapeInfos->valBuffer = NULL; - if (tapeInfos->tayBuffer != NULL) { - free(tapeInfos->tayBuffer); - tapeInfos->tayBuffer = NULL; - --numTBuffersInUse; - } - if (tapeInfos->op_file != NULL) { - fclose(tapeInfos->op_file); - tapeInfos->op_file = NULL; - } - if (tapeInfos->loc_file != NULL) { - fclose(tapeInfos->loc_file); - tapeInfos->loc_file = NULL; - } - if (tapeInfos->val_file != NULL) { - fclose(tapeInfos->val_file); - tapeInfos->val_file = NULL; - } - if (tapeInfos->tay_file != NULL) { - fclose(tapeInfos->tay_file); - tapeInfos->tay_file = NULL; - } + free(tapeInfos->opBuffer); + tapeInfos->opBuffer = NULL; + free(tapeInfos->locBuffer); + tapeInfos->locBuffer = NULL; + free(tapeInfos->valBuffer); + tapeInfos->valBuffer = NULL; + if (tapeInfos->tayBuffer != NULL) { + free(tapeInfos->tayBuffer); + tapeInfos->tayBuffer = NULL; + --numTBuffersInUse; + } + if (tapeInfos->op_file != NULL) { + fclose(tapeInfos->op_file); + tapeInfos->op_file = NULL; + } + if (tapeInfos->loc_file != NULL) { + fclose(tapeInfos->loc_file); + tapeInfos->loc_file = NULL; + } + if (tapeInfos->val_file != NULL) { + fclose(tapeInfos->val_file); + tapeInfos->val_file = NULL; + } + if (tapeInfos->tay_file != NULL) { + fclose(tapeInfos->tay_file); + tapeInfos->tay_file = NULL; + } } /****************************************************************************/ @@ -1329,125 +1362,124 @@ void freeTapeResources(TapeInfos *tapeInfos) { /* tape_stat[10]= value file access flag (1 = file in use, 0 otherwise) */ /****************************************************************************/ void tapestats(short tag, size_t *tape_stats) { - int i; - TapeInfos *tapeInfos; + int i; + TapeInfos *tapeInfos; - /* get the tapeInfos for tag */ - tapeInfos = getTapeInfos(tag); - /* copy stats to the users field */ - for (i = 0; i < STAT_SIZE; ++i) - tape_stats[i] = tapeInfos->stats[i]; + /* get the tapeInfos for tag */ + tapeInfos = getTapeInfos(tag); + /* copy stats to the users field */ + for (i = 0; i < STAT_SIZE; ++i) + tape_stats[i] = tapeInfos->stats[i]; } /****************************************************************************/ /* An all-in-one tape stats printing routine. */ /****************************************************************************/ void printTapeStats(FILE *stream, short tag) { - size_t stats[STAT_SIZE]; - - tapestats(tag, (size_t *)&stats); - fprintf(stream, "\n*** TAPE STATS (tape %d) **********\n", (int)tag); - fprintf(stream, "Number of independents: %10zu\n", stats[NUM_INDEPENDENTS]); - fprintf(stream, "Number of dependents: %10zu\n", stats[NUM_DEPENDENTS]); - fprintf(stream, "\n"); - fprintf(stream, "Max # of live adoubles: %10zu\n", stats[NUM_MAX_LIVES]); - fprintf(stream, "Taylor stack size: %10zu\n", stats[TAY_STACK_SIZE]); - fprintf(stream, "\n"); - fprintf(stream, "Number of operations: %10zu\n", stats[NUM_OPERATIONS]); - fprintf(stream, "Number of locations: %10zu\n", stats[NUM_LOCATIONS]); - fprintf(stream, "Number of values: %10zu\n", stats[NUM_VALUES]); - fprintf(stream, "Number of parameters: %10zu\n", stats[NUM_PARAM]); - fprintf(stream, "\n"); - fprintf(stream, "Operation file written: %10zu\n", stats[OP_FILE_ACCESS]); - fprintf(stream, "Location file written: %10zu\n", stats[LOC_FILE_ACCESS]); - fprintf(stream, "Value file written: %10zu\n", stats[VAL_FILE_ACCESS]); - fprintf(stream, "\n"); - fprintf(stream, "Operation buffer size: %10zu\n", stats[OP_BUFFER_SIZE]); - fprintf(stream, "Location buffer size: %10zu\n", stats[LOC_BUFFER_SIZE]); - fprintf(stream, "Value buffer size: %10zu\n", stats[VAL_BUFFER_SIZE]); - fprintf(stream, "Taylor buffer size: %10zu\n", stats[TAY_BUFFER_SIZE]); - fprintf(stream, "\n"); - fprintf(stream, "Operation type size: %10zu\n", - (size_t)sizeof(unsigned char)); - fprintf(stream, "Location type size: %10zu\n", (size_t)sizeof(locint)); - fprintf(stream, "Value type size: %10zu\n", (size_t)sizeof(double)); - fprintf(stream, "Taylor type size: %10zu\n", (size_t)sizeof(revreal)); - fprintf(stream, "**********************************\n\n"); + size_t stats[STAT_SIZE]; + + tapestats(tag, (size_t *)&stats); + fprintf(stream, "\n*** TAPE STATS (tape %d) **********\n", (int)tag); + fprintf(stream, "Number of independents: %10zu\n", stats[NUM_INDEPENDENTS]); + fprintf(stream, "Number of dependents: %10zu\n", stats[NUM_DEPENDENTS]); + fprintf(stream, "\n"); + fprintf(stream, "Max # of live adoubles: %10zu\n", stats[NUM_MAX_LIVES]); + fprintf(stream, "Taylor stack size: %10zu\n", stats[TAY_STACK_SIZE]); + fprintf(stream, "\n"); + fprintf(stream, "Number of operations: %10zu\n", stats[NUM_OPERATIONS]); + fprintf(stream, "Number of locations: %10zu\n", stats[NUM_LOCATIONS]); + fprintf(stream, "Number of values: %10zu\n", stats[NUM_VALUES]); + fprintf(stream, "Number of parameters: %10zu\n", stats[NUM_PARAM]); + fprintf(stream, "\n"); + fprintf(stream, "Operation file written: %10zu\n", stats[OP_FILE_ACCESS]); + fprintf(stream, "Location file written: %10zu\n", stats[LOC_FILE_ACCESS]); + fprintf(stream, "Value file written: %10zu\n", stats[VAL_FILE_ACCESS]); + fprintf(stream, "\n"); + fprintf(stream, "Operation buffer size: %10zu\n", stats[OP_BUFFER_SIZE]); + fprintf(stream, "Location buffer size: %10zu\n", stats[LOC_BUFFER_SIZE]); + fprintf(stream, "Value buffer size: %10zu\n", stats[VAL_BUFFER_SIZE]); + fprintf(stream, "Taylor buffer size: %10zu\n", stats[TAY_BUFFER_SIZE]); + fprintf(stream, "\n"); + fprintf(stream, "Operation type size: %10zu\n", + (size_t)sizeof(unsigned char)); + fprintf(stream, "Location type size: %10zu\n", (size_t)sizeof(locint)); + fprintf(stream, "Value type size: %10zu\n", (size_t)sizeof(double)); + fprintf(stream, "Taylor type size: %10zu\n", (size_t)sizeof(revreal)); + fprintf(stream, "**********************************\n\n"); } /****************************************************************************/ /* Returns the number of parameters recorded on tape */ /****************************************************************************/ size_t get_num_param(short tag) { - TapeInfos *tapeInfos; - tapeInfos = getTapeInfos(tag); - return tapeInfos->stats[NUM_PARAM]; + TapeInfos *tapeInfos; + tapeInfos = getTapeInfos(tag); + return tapeInfos->stats[NUM_PARAM]; } /****************************************************************************/ /* Reads parameters from the end of value tape for disk based tapes */ /****************************************************************************/ -static void read_params(TapeInfos* tapeInfos) { - FILE* val_file; - int i, chunks; - size_t number, remain, chunkSize, nVT; - double *valBuffer = NULL, *currVal = NULL, *lastValP1 = NULL; - size_t np, ip, avail, rsize; - if (tapeInfos->pTapeInfos.paramstore == NULL) - tapeInfos->pTapeInfos.paramstore = - malloc(tapeInfos->stats[NUM_PARAM]*sizeof(double)); - valBuffer = (double*) - malloc(tapeInfos->stats[VAL_BUFFER_SIZE] *sizeof(double)); - lastValP1 = valBuffer + tapeInfos->stats[VAL_BUFFER_SIZE]; - if ((val_file = fopen(tapeInfos->pTapeInfos.val_fileName, "rb")) == NULL) - fail(ADOLC_VALUE_TAPE_FOPEN_FAILED); - number = (tapeInfos->stats[NUM_VALUES] / - tapeInfos->stats[VAL_BUFFER_SIZE]) * - tapeInfos->stats[VAL_BUFFER_SIZE]; - fseek(val_file, number * sizeof(double), SEEK_SET); - number = tapeInfos->stats[NUM_VALUES] % tapeInfos->stats[VAL_BUFFER_SIZE]; - if (number != 0) { - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(valBuffer + i * chunkSize, chunkSize * sizeof(double), 1, - val_file) != 1 ) - fail(ADOLC_VALUE_TAPE_FREAD_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(valBuffer + chunks * chunkSize, remain * sizeof(double), 1, - val_file) != 1) - fail(ADOLC_VALUE_TAPE_FREAD_FAILED); - } - nVT = tapeInfos->stats[NUM_VALUES] - number; - currVal = valBuffer + number; - np = tapeInfos->stats[NUM_PARAM]; - ip = np; - while ( ip > 0) { - avail = currVal - valBuffer; - rsize = (availpTapeInfos.paramstore[--ip] = *--currVal; - if (ip > 0) { - number = tapeInfos->stats[VAL_BUFFER_SIZE]; - fseek(val_file, sizeof(double)*(nVT - number), SEEK_SET); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(valBuffer + i * chunkSize, chunkSize * sizeof(double), 1, - val_file) != 1 ) - fail(ADOLC_VALUE_TAPE_FREAD_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(valBuffer + chunks * chunkSize, remain * sizeof(double), 1, - val_file) != 1) - fail(ADOLC_VALUE_TAPE_FREAD_FAILED); - nVT -= number; - currVal = lastValP1; - } - } - fclose(val_file); - free(valBuffer); +static void read_params(TapeInfos *tapeInfos) { + FILE *val_file; + int i, chunks; + size_t number, remain, chunkSize, nVT; + double *valBuffer = NULL, *currVal = NULL, *lastValP1 = NULL; + size_t np, ip, avail, rsize; + if (tapeInfos->pTapeInfos.paramstore == NULL) + tapeInfos->pTapeInfos.paramstore = + malloc(tapeInfos->stats[NUM_PARAM] * sizeof(double)); + valBuffer = + (double *)malloc(tapeInfos->stats[VAL_BUFFER_SIZE] * sizeof(double)); + lastValP1 = valBuffer + tapeInfos->stats[VAL_BUFFER_SIZE]; + if ((val_file = fopen(tapeInfos->pTapeInfos.val_fileName, "rb")) == NULL) + fail(ADOLC_VALUE_TAPE_FOPEN_FAILED); + number = (tapeInfos->stats[NUM_VALUES] / tapeInfos->stats[VAL_BUFFER_SIZE]) * + tapeInfos->stats[VAL_BUFFER_SIZE]; + fseek(val_file, number * sizeof(double), SEEK_SET); + number = tapeInfos->stats[NUM_VALUES] % tapeInfos->stats[VAL_BUFFER_SIZE]; + if (number != 0) { + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(valBuffer + i * chunkSize, chunkSize * sizeof(double), 1, + val_file) != 1) + fail(ADOLC_VALUE_TAPE_FREAD_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(valBuffer + chunks * chunkSize, remain * sizeof(double), 1, + val_file) != 1) + fail(ADOLC_VALUE_TAPE_FREAD_FAILED); + } + nVT = tapeInfos->stats[NUM_VALUES] - number; + currVal = valBuffer + number; + np = tapeInfos->stats[NUM_PARAM]; + ip = np; + while (ip > 0) { + avail = currVal - valBuffer; + rsize = (avail < ip) ? avail : ip; + for (i = 0; i < rsize; i++) + tapeInfos->pTapeInfos.paramstore[--ip] = *--currVal; + if (ip > 0) { + number = tapeInfos->stats[VAL_BUFFER_SIZE]; + fseek(val_file, sizeof(double) * (nVT - number), SEEK_SET); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(valBuffer + i * chunkSize, chunkSize * sizeof(double), 1, + val_file) != 1) + fail(ADOLC_VALUE_TAPE_FREAD_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(valBuffer + chunks * chunkSize, remain * sizeof(double), 1, + val_file) != 1) + fail(ADOLC_VALUE_TAPE_FREAD_FAILED); + nVT -= number; + currVal = lastValP1; + } + } + fclose(val_file); + free(valBuffer); } /****************************************************************************/ @@ -1455,198 +1487,198 @@ static void read_params(TapeInfos* tapeInfos) { /* the taylor stack, so next reverse call will fail, if not preceded by a */ /* forward call after setting the parameters. */ /****************************************************************************/ -void set_param_vec(short tag, size_t numparam, revreal* paramvec) { - size_t i; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* mark possible (hard disk) tape creation */ - markNewTape(); - - /* make room for tapeInfos and read tape stats if necessary, keep value - * stack information */ - openTape(tag, ADOLC_FORWARD); - if (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM] != numparam) { - fprintf(DIAG_OUT, "ADOL-C error: Setting parameters on tape %d " - "aborted!\nNumber of parameters (%zu) passed" - " is inconsistent with number recorded on tape (%zu)\n", - tag, numparam, ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore == NULL) - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore = (double*) - malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]*sizeof(double)); - for(i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; i++) - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[i] = paramvec[i]; - taylor_close(false); - releaseTape(); +void set_param_vec(short tag, size_t numparam, revreal *paramvec) { + size_t i; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* mark possible (hard disk) tape creation */ + markNewTape(); + + /* make room for tapeInfos and read tape stats if necessary, keep value + * stack information */ + openTape(tag, ADOLC_FORWARD); + if (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM] != numparam) { + fprintf(DIAG_OUT, + "ADOL-C error: Setting parameters on tape %d " + "aborted!\nNumber of parameters (%zu) passed" + " is inconsistent with number recorded on tape (%zu)\n", + tag, numparam, ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore == NULL) + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore = (double *)malloc( + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM] * sizeof(double)); + for (i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; i++) + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[i] = paramvec[i]; + taylor_close(false); + releaseTape(); } /****************************************************************************/ /* Does the actual reading from the hard disk into the stats buffer */ /****************************************************************************/ void read_tape_stats(TapeInfos *tapeInfos) { - FILE *loc_file; - int tapeVersion, limitVersion; - ADOLC_ID tape_ADOLC_ID; - - if (tapeInfos->inUse != 0 && tapeInfos->tapingComplete == 0) return; - - limitVersion = 100 * ADOLC_NEW_TAPE_VERSION + - 10 * ADOLC_NEW_TAPE_SUBVERSION + - 1 * ADOLC_NEW_TAPE_PATCHLEVEL ; - - if ((loc_file = fopen(tapeInfos->pTapeInfos.loc_fileName, "rb")) == NULL) - fail(ADOLC_INTEGER_TAPE_FOPEN_FAILED); - if (fread(&tape_ADOLC_ID, sizeof(ADOLC_ID), 1, loc_file) != 1) - fail(ADOLC_INTEGER_TAPE_FREAD_FAILED); - if (fread(tapeInfos->stats, STAT_SIZE * sizeof(size_t), 1, loc_file) != 1) - fail(ADOLC_INTEGER_TAPE_FREAD_FAILED); - - failAdditionalInfo1 = tapeInfos->tapeID; - tapeVersion = 100 * tape_ADOLC_ID.adolc_ver + - 10 * tape_ADOLC_ID.adolc_sub + - 1 * tape_ADOLC_ID.adolc_lvl ; - if (tapeVersion < limitVersion) fail(ADOLC_TAPE_TO_OLD); - - if (tape_ADOLC_ID.address_size != adolc_id.address_size) { - if (tape_ADOLC_ID.address_size < adolc_id.address_size) - fail(ADOLC_WRONG_PLATFORM_64); - else - fail(ADOLC_WRONG_PLATFORM_32); - } + FILE *loc_file; + int tapeVersion, limitVersion; + ADOLC_ID tape_ADOLC_ID; + + if (tapeInfos->inUse != 0 && tapeInfos->tapingComplete == 0) + return; + + limitVersion = 100 * ADOLC_NEW_TAPE_VERSION + 10 * ADOLC_NEW_TAPE_SUBVERSION + + 1 * ADOLC_NEW_TAPE_PATCHLEVEL; + + if ((loc_file = fopen(tapeInfos->pTapeInfos.loc_fileName, "rb")) == NULL) + fail(ADOLC_INTEGER_TAPE_FOPEN_FAILED); + if (fread(&tape_ADOLC_ID, sizeof(ADOLC_ID), 1, loc_file) != 1) + fail(ADOLC_INTEGER_TAPE_FREAD_FAILED); + if (fread(tapeInfos->stats, STAT_SIZE * sizeof(size_t), 1, loc_file) != 1) + fail(ADOLC_INTEGER_TAPE_FREAD_FAILED); + + failAdditionalInfo1 = tapeInfos->tapeID; + tapeVersion = 100 * tape_ADOLC_ID.adolc_ver + 10 * tape_ADOLC_ID.adolc_sub + + 1 * tape_ADOLC_ID.adolc_lvl; + if (tapeVersion < limitVersion) + fail(ADOLC_TAPE_TO_OLD); + + if (tape_ADOLC_ID.address_size != adolc_id.address_size) { + if (tape_ADOLC_ID.address_size < adolc_id.address_size) + fail(ADOLC_WRONG_PLATFORM_64); + else + fail(ADOLC_WRONG_PLATFORM_32); + } - if (tape_ADOLC_ID.locint_size != adolc_id.locint_size) { - failAdditionalInfo1 = tape_ADOLC_ID.locint_size; - failAdditionalInfo2 = adolc_id.locint_size; - fail(ADOLC_WRONG_LOCINT_SIZE); - } + if (tape_ADOLC_ID.locint_size != adolc_id.locint_size) { + failAdditionalInfo1 = tape_ADOLC_ID.locint_size; + failAdditionalInfo2 = adolc_id.locint_size; + fail(ADOLC_WRONG_LOCINT_SIZE); + } - fclose(loc_file); - tapeInfos->tapingComplete = 1; - if (tapeInfos->stats[NUM_PARAM] > 0) - read_params(tapeInfos); + fclose(loc_file); + tapeInfos->tapingComplete = 1; + if (tapeInfos->stats[NUM_PARAM] > 0) + read_params(tapeInfos); } void skip_tracefile_cleanup(short tnum) { - TapeInfos *tinfo = getTapeInfos(tnum); - tinfo->pTapeInfos.skipFileCleanup = 1; + TapeInfos *tinfo = getTapeInfos(tnum); + tinfo->pTapeInfos.skipFileCleanup = 1; } /****************************************************************************/ /* Initialize a forward sweep. Get stats, open tapes, fill buffers, ... */ /****************************************************************************/ void init_for_sweep(short tag) { - int i = 0, chunks, numLocsForStats; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* mark possible (hard disk) tape creation */ - markNewTape(); - - /* make room for tapeInfos and read tape stats if necessary, keep value - * stack information */ - openTape(tag, ADOLC_FORWARD); - initTapeBuffers(); - - /* init operations */ - number = 0; - if (ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] == 1) { - ADOLC_CURRENT_TAPE_INFOS.op_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "rb"); - /* how much to read ? */ - number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE], - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS]); - if (number != 0) { - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, - chunkSize * sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) != 1 ) - fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * - chunkSize, remain * sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) != 1 ) - fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); - } - /* how much remains ? */ - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] - number; - } - ADOLC_CURRENT_TAPE_INFOS.numOps_Tape = number; - ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer; - - /* init locations */ - number = 0; - if (ADOLC_CURRENT_TAPE_INFOS.stats[LOC_FILE_ACCESS] == 1) { - ADOLC_CURRENT_TAPE_INFOS.loc_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "rb"); - /* how much to read ? */ - number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE], - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS]); - if (number != 0) { - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, - chunkSize * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1 ) - fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * chunkSize, - remain * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1 ) - fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); - } - /* how much remains ? */ - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] - number; - } - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape = number; - - /* skip stats */ - numLocsForStats = statSpace; - while (numLocsForStats >= ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]) - { - get_loc_block_f(); - numLocsForStats -= ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; - } - ADOLC_CURRENT_TAPE_INFOS.currLoc = - ADOLC_CURRENT_TAPE_INFOS.locBuffer + numLocsForStats; - - /* init constants */ - number = 0; - if (ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] == 1) { - ADOLC_CURRENT_TAPE_INFOS.val_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "rb"); - /* how much to read ? */ - number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE], - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES]); - if (number != 0) { - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, - chunkSize * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1 ) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * - chunkSize, remain * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1 ) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - } - /* how much remains ? */ - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] - number; - } - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape = number; - ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.valBuffer; + int i = 0, chunks, numLocsForStats; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* mark possible (hard disk) tape creation */ + markNewTape(); + + /* make room for tapeInfos and read tape stats if necessary, keep value + * stack information */ + openTape(tag, ADOLC_FORWARD); + initTapeBuffers(); + + /* init operations */ + number = 0; + if (ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] == 1) { + ADOLC_CURRENT_TAPE_INFOS.op_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "rb"); + /* how much to read ? */ + number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE], + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS]); + if (number != 0) { + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, + chunkSize * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) + fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * chunkSize, + remain * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) + fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); + } + /* how much remains ? */ + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] - number; + } + ADOLC_CURRENT_TAPE_INFOS.numOps_Tape = number; + ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer; + + /* init locations */ + number = 0; + if (ADOLC_CURRENT_TAPE_INFOS.stats[LOC_FILE_ACCESS] == 1) { + ADOLC_CURRENT_TAPE_INFOS.loc_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "rb"); + /* how much to read ? */ + number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE], + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS]); + if (number != 0) { + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, + chunkSize * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) + fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * chunkSize, + remain * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) + fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); + } + /* how much remains ? */ + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] - number; + } + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape = number; + + /* skip stats */ + numLocsForStats = statSpace; + while (numLocsForStats >= ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]) { + get_loc_block_f(); + numLocsForStats -= ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; + } + ADOLC_CURRENT_TAPE_INFOS.currLoc = + ADOLC_CURRENT_TAPE_INFOS.locBuffer + numLocsForStats; + + /* init constants */ + number = 0; + if (ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] == 1) { + ADOLC_CURRENT_TAPE_INFOS.val_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "rb"); + /* how much to read ? */ + number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE], + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES]); + if (number != 0) { + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, + chunkSize * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * chunkSize, + remain * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + } + /* how much remains ? */ + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] - number; + } + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape = number; + ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.valBuffer; #ifdef ADOLC_AMPI_SUPPORT - TAPE_AMPI_resetBottom(); + TAPE_AMPI_resetBottom(); #endif } @@ -1654,119 +1686,116 @@ void init_for_sweep(short tag) { /* Initialize a reverse sweep. Get stats, open tapes, fill buffers, ... */ /****************************************************************************/ void init_rev_sweep(short tag) { - int i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - /* mark possible (hard disk) tape creation */ - markNewTape(); - - /* make room for tapeInfos and read tape stats if necessary, keep value - * stack information */ - openTape(tag, ADOLC_REVERSE); - initTapeBuffers(); - - /* init operations */ - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS]; - if (ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] == 1) { - ADOLC_CURRENT_TAPE_INFOS.op_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "rb"); - number = (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] / - ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]) * - ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]; - fseek(ADOLC_CURRENT_TAPE_INFOS.op_file, - number * sizeof(unsigned char), SEEK_SET); - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] % - ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE] ; - if (number != 0) { - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, - chunkSize * sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) != 1 ) - fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * - chunkSize, remain * sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) != 1 ) - fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); - } - } - ADOLC_CURRENT_TAPE_INFOS.numOps_Tape = - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] - number; - ADOLC_CURRENT_TAPE_INFOS.currOp = - ADOLC_CURRENT_TAPE_INFOS.opBuffer + number; - - /* init locations */ - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS]; - if (ADOLC_CURRENT_TAPE_INFOS.stats[LOC_FILE_ACCESS] == 1) { - ADOLC_CURRENT_TAPE_INFOS.loc_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "rb"); - number = (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] / - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]) * - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; - fseek(ADOLC_CURRENT_TAPE_INFOS.loc_file, - number * sizeof(locint), SEEK_SET); - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] % - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; - if (number != 0) { - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, - chunkSize * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1 ) - fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * - chunkSize, remain * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1 ) - fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); - } - } - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape = - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] - number; - ADOLC_CURRENT_TAPE_INFOS.currLoc = - ADOLC_CURRENT_TAPE_INFOS.locBuffer + number; - - /* init constants */ - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES]; - if (ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] == 1) { - ADOLC_CURRENT_TAPE_INFOS.val_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "rb"); - number = (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] / - ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]) * - ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; - fseek(ADOLC_CURRENT_TAPE_INFOS.val_file, - number * sizeof(double), SEEK_SET); - number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] % - ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; - if (number != 0) { - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, - chunkSize * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1 ) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * - chunkSize, remain * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1 ) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - } - } - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape = - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] - number; - ADOLC_CURRENT_TAPE_INFOS.currVal = - ADOLC_CURRENT_TAPE_INFOS.valBuffer + number; + int i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* mark possible (hard disk) tape creation */ + markNewTape(); + + /* make room for tapeInfos and read tape stats if necessary, keep value + * stack information */ + openTape(tag, ADOLC_REVERSE); + initTapeBuffers(); + + /* init operations */ + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS]; + if (ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] == 1) { + ADOLC_CURRENT_TAPE_INFOS.op_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "rb"); + number = (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] / + ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]) * + ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]; + fseek(ADOLC_CURRENT_TAPE_INFOS.op_file, number * sizeof(unsigned char), + SEEK_SET); + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] % + ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]; + if (number != 0) { + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, + chunkSize * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) + fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * chunkSize, + remain * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) + fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); + } + } + ADOLC_CURRENT_TAPE_INFOS.numOps_Tape = + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] - number; + ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer + number; + + /* init locations */ + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS]; + if (ADOLC_CURRENT_TAPE_INFOS.stats[LOC_FILE_ACCESS] == 1) { + ADOLC_CURRENT_TAPE_INFOS.loc_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "rb"); + number = (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] / + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]) * + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; + fseek(ADOLC_CURRENT_TAPE_INFOS.loc_file, number * sizeof(locint), SEEK_SET); + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] % + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; + if (number != 0) { + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, + chunkSize * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) + fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * chunkSize, + remain * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) + fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); + } + } + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape = + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_LOCATIONS] - number; + ADOLC_CURRENT_TAPE_INFOS.currLoc = + ADOLC_CURRENT_TAPE_INFOS.locBuffer + number; + + /* init constants */ + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES]; + if (ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] == 1) { + ADOLC_CURRENT_TAPE_INFOS.val_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "rb"); + number = (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] / + ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]) * + ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; + fseek(ADOLC_CURRENT_TAPE_INFOS.val_file, number * sizeof(double), SEEK_SET); + number = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] % + ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; + if (number != 0) { + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, + chunkSize * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * chunkSize, + remain * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + } + } + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape = + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_VALUES] - number; + ADOLC_CURRENT_TAPE_INFOS.currVal = + ADOLC_CURRENT_TAPE_INFOS.valBuffer + number; #ifdef ADOLC_AMPI_SUPPORT - TAPE_AMPI_resetTop(); + TAPE_AMPI_resetTop(); #endif } @@ -1774,77 +1803,88 @@ void init_rev_sweep(short tag) { /* Finish a forward or reverse sweep. */ /****************************************************************************/ void end_sweep() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) { - fclose(ADOLC_CURRENT_TAPE_INFOS.op_file); - ADOLC_CURRENT_TAPE_INFOS.op_file = NULL; - } - if (ADOLC_CURRENT_TAPE_INFOS.loc_file != NULL) { - fclose(ADOLC_CURRENT_TAPE_INFOS.loc_file); - ADOLC_CURRENT_TAPE_INFOS.loc_file = NULL; - } - if (ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { - fclose(ADOLC_CURRENT_TAPE_INFOS.val_file); - ADOLC_CURRENT_TAPE_INFOS.val_file = NULL; - } - if (ADOLC_CURRENT_TAPE_INFOS.deg_save > 0) releaseTape(); /* keep value stack */ - else releaseTape(); /* no value stack */ + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) { + fclose(ADOLC_CURRENT_TAPE_INFOS.op_file); + ADOLC_CURRENT_TAPE_INFOS.op_file = NULL; + } + if (ADOLC_CURRENT_TAPE_INFOS.loc_file != NULL) { + fclose(ADOLC_CURRENT_TAPE_INFOS.loc_file); + ADOLC_CURRENT_TAPE_INFOS.loc_file = NULL; + } + if (ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { + fclose(ADOLC_CURRENT_TAPE_INFOS.val_file); + ADOLC_CURRENT_TAPE_INFOS.val_file = NULL; + } + if (ADOLC_CURRENT_TAPE_INFOS.deg_save > 0) + releaseTape(); /* keep value stack */ + else + releaseTape(); /* no value stack */ } /* --- Operations --- */ -const int maxLocsPerOp=10; +const int maxLocsPerOp = 10; /****************************************************************************/ /* Puts an operation into the operation buffer. Ensures that location buffer*/ /* and constants buffer are prepared to take the belonging stuff. */ /****************************************************************************/ void put_op_reserve(unsigned char op, unsigned int reserveExtraLocations) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - /* make sure we have enough slots to write the locs */ - if (ADOLC_CURRENT_TAPE_INFOS.currLoc + maxLocsPerOp + reserveExtraLocations > ADOLC_CURRENT_TAPE_INFOS.lastLocP1) { - size_t remainder = ADOLC_CURRENT_TAPE_INFOS.lastLocP1 - ADOLC_CURRENT_TAPE_INFOS.currLoc; - if (remainder>0) memset(ADOLC_CURRENT_TAPE_INFOS.currLoc,0,(remainder-1)*sizeof(locint)); - *(ADOLC_CURRENT_TAPE_INFOS.lastLocP1 - 1) = remainder; - put_loc_block(ADOLC_CURRENT_TAPE_INFOS.lastLocP1); - /* every operation writes 1 opcode */ - if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; - } - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_int; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; - } - /* every operation writes <5 values --- 3 should be sufficient */ - if (ADOLC_CURRENT_TAPE_INFOS.currVal + 5 > ADOLC_CURRENT_TAPE_INFOS.lastValP1) { - locint valRemainder=ADOLC_CURRENT_TAPE_INFOS.lastValP1 - ADOLC_CURRENT_TAPE_INFOS.currVal; - ADOLC_PUT_LOCINT(valRemainder); - /* avoid writing uninitialized memory to the file and get valgrind upset */ - memset(ADOLC_CURRENT_TAPE_INFOS.currVal,0,valRemainder*sizeof(double)); - put_val_block(ADOLC_CURRENT_TAPE_INFOS.lastValP1); - /* every operation writes 1 opcode */ - if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; - } - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_val; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + /* make sure we have enough slots to write the locs */ + if (ADOLC_CURRENT_TAPE_INFOS.currLoc + maxLocsPerOp + reserveExtraLocations > + ADOLC_CURRENT_TAPE_INFOS.lastLocP1) { + size_t remainder = + ADOLC_CURRENT_TAPE_INFOS.lastLocP1 - ADOLC_CURRENT_TAPE_INFOS.currLoc; + if (remainder > 0) + memset(ADOLC_CURRENT_TAPE_INFOS.currLoc, 0, + (remainder - 1) * sizeof(locint)); + *(ADOLC_CURRENT_TAPE_INFOS.lastLocP1 - 1) = remainder; + put_loc_block(ADOLC_CURRENT_TAPE_INFOS.lastLocP1); /* every operation writes 1 opcode */ - if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; + if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == + ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; + } + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_int; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; + } + /* every operation writes <5 values --- 3 should be sufficient */ + if (ADOLC_CURRENT_TAPE_INFOS.currVal + 5 > + ADOLC_CURRENT_TAPE_INFOS.lastValP1) { + locint valRemainder = + ADOLC_CURRENT_TAPE_INFOS.lastValP1 - ADOLC_CURRENT_TAPE_INFOS.currVal; + ADOLC_PUT_LOCINT(valRemainder); + /* avoid writing uninitialized memory to the file and get valgrind upset */ + memset(ADOLC_CURRENT_TAPE_INFOS.currVal, 0, valRemainder * sizeof(double)); + put_val_block(ADOLC_CURRENT_TAPE_INFOS.lastValP1); + /* every operation writes 1 opcode */ + if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == + ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; } - *ADOLC_CURRENT_TAPE_INFOS.currOp = op; + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_val; ++ADOLC_CURRENT_TAPE_INFOS.currOp; + } + /* every operation writes 1 opcode */ + if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == + ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; + } + *ADOLC_CURRENT_TAPE_INFOS.currOp = op; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; } /****************************************************************************/ @@ -1852,109 +1892,109 @@ void put_op_reserve(unsigned char op, unsigned int reserveExtraLocations) { /* removal, ... */ /****************************************************************************/ void put_op_block(unsigned char *lastOpP1) { - size_t i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_CURRENT_TAPE_INFOS.op_file == NULL) { - ADOLC_CURRENT_TAPE_INFOS.op_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "rb"); - if (ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) { + size_t i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_CURRENT_TAPE_INFOS.op_file == NULL) { + ADOLC_CURRENT_TAPE_INFOS.op_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "rb"); + if (ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) { #if defined(ADOLC_DEBUG) - fprintf(DIAG_OUT, "ADOL-C debug: Old tapefile %s gets removed!\n", - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName); + fprintf(DIAG_OUT, "ADOL-C debug: Old tapefile %s gets removed!\n", + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName); #endif - fclose(ADOLC_CURRENT_TAPE_INFOS.op_file); - ADOLC_CURRENT_TAPE_INFOS.op_file = NULL; - if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName)) - fprintf(DIAG_OUT, "ADOL-C warning: " - "Unable to remove old tapefile\n"); - ADOLC_CURRENT_TAPE_INFOS.op_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "wb"); - } else { - ADOLC_CURRENT_TAPE_INFOS.op_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "wb"); - } + fclose(ADOLC_CURRENT_TAPE_INFOS.op_file); + ADOLC_CURRENT_TAPE_INFOS.op_file = NULL; + if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName)) + fprintf(DIAG_OUT, "ADOL-C warning: " + "Unable to remove old tapefile\n"); + ADOLC_CURRENT_TAPE_INFOS.op_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "wb"); + } else { + ADOLC_CURRENT_TAPE_INFOS.op_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "wb"); } + } - number = lastOpP1 - ADOLC_CURRENT_TAPE_INFOS.opBuffer; - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if ((failAdditionalInfo1 = fwrite(ADOLC_CURRENT_TAPE_INFOS.opBuffer + - i * chunkSize, chunkSize * - sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) ) != 1 ) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - remain = number % chunkSize; - if (remain != 0) - if ((failAdditionalInfo1 = fwrite(ADOLC_CURRENT_TAPE_INFOS.opBuffer + - chunks * chunkSize, remain * - sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) ) != 1 ) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - ADOLC_CURRENT_TAPE_INFOS.numOps_Tape += number; - ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer; - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + number = lastOpP1 - ADOLC_CURRENT_TAPE_INFOS.opBuffer; + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if ((failAdditionalInfo1 = + fwrite(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, + chunkSize * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + remain = number % chunkSize; + if (remain != 0) + if ((failAdditionalInfo1 = + fwrite(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * chunkSize, + remain * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + ADOLC_CURRENT_TAPE_INFOS.numOps_Tape += number; + ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; } /****************************************************************************/ /* Reads the next operations block into the internal buffer. */ /****************************************************************************/ void get_op_block_f() { - size_t i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE], - ADOLC_CURRENT_TAPE_INFOS.numOps_Tape); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, - chunkSize * sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) - fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * chunkSize, - remain * sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) - fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); - ADOLC_CURRENT_TAPE_INFOS.numOps_Tape -= remain; - ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer; + size_t i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE], + ADOLC_CURRENT_TAPE_INFOS.numOps_Tape); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, + chunkSize * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) + fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * chunkSize, + remain * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) + fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); + ADOLC_CURRENT_TAPE_INFOS.numOps_Tape -= remain; + ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer; } /****************************************************************************/ /* Reads the previous block of operations into the internal buffer. */ /****************************************************************************/ void get_op_block_r() { - size_t i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - number = ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]; - fseek(ADOLC_CURRENT_TAPE_INFOS.op_file, sizeof(unsigned char) * - (ADOLC_CURRENT_TAPE_INFOS.numOps_Tape - number), SEEK_SET); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, - chunkSize * sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) - fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * chunkSize, - remain * sizeof(unsigned char), 1, - ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) - fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); - ADOLC_CURRENT_TAPE_INFOS.numOps_Tape -= number; - ADOLC_CURRENT_TAPE_INFOS.currOp = - ADOLC_CURRENT_TAPE_INFOS.opBuffer + number; + size_t i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + number = ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]; + fseek(ADOLC_CURRENT_TAPE_INFOS.op_file, + sizeof(unsigned char) * (ADOLC_CURRENT_TAPE_INFOS.numOps_Tape - number), + SEEK_SET); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(unsigned char); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + i * chunkSize, + chunkSize * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) + fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.opBuffer + chunks * chunkSize, + remain * sizeof(unsigned char), 1, + ADOLC_CURRENT_TAPE_INFOS.op_file) != 1) + fail(ADOLC_EVAL_OP_TAPE_READ_FAILED); + ADOLC_CURRENT_TAPE_INFOS.numOps_Tape -= number; + ADOLC_CURRENT_TAPE_INFOS.currOp = ADOLC_CURRENT_TAPE_INFOS.opBuffer + number; } /* --- Locations --- */ @@ -1964,108 +2004,111 @@ void get_op_block_r() { /* removal, ... */ /****************************************************************************/ void put_loc_block(locint *lastLocP1) { - size_t i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_CURRENT_TAPE_INFOS.loc_file == NULL) { - ADOLC_CURRENT_TAPE_INFOS.loc_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "rb"); - if (ADOLC_CURRENT_TAPE_INFOS.loc_file != NULL) { - #if defined(ADOLC_DEBUG) - fprintf(DIAG_OUT, "ADOL-C debug: Old tapefile %s gets removed!\n", - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName); - #endif - fclose(ADOLC_CURRENT_TAPE_INFOS.loc_file); - ADOLC_CURRENT_TAPE_INFOS.loc_file = NULL; - if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName)) - fprintf(DIAG_OUT, "ADOL-C warning: " - "Unable to remove old tapefile!\n"); - ADOLC_CURRENT_TAPE_INFOS.loc_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "wb"); - } else { - ADOLC_CURRENT_TAPE_INFOS.loc_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "wb"); - } + size_t i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_CURRENT_TAPE_INFOS.loc_file == NULL) { + ADOLC_CURRENT_TAPE_INFOS.loc_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "rb"); + if (ADOLC_CURRENT_TAPE_INFOS.loc_file != NULL) { +#if defined(ADOLC_DEBUG) + fprintf(DIAG_OUT, "ADOL-C debug: Old tapefile %s gets removed!\n", + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName); +#endif + fclose(ADOLC_CURRENT_TAPE_INFOS.loc_file); + ADOLC_CURRENT_TAPE_INFOS.loc_file = NULL; + if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName)) + fprintf(DIAG_OUT, "ADOL-C warning: " + "Unable to remove old tapefile!\n"); + ADOLC_CURRENT_TAPE_INFOS.loc_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "wb"); + } else { + ADOLC_CURRENT_TAPE_INFOS.loc_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "wb"); } + } - number = lastLocP1 - ADOLC_CURRENT_TAPE_INFOS.locBuffer; - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if ((failAdditionalInfo1 = fwrite(ADOLC_CURRENT_TAPE_INFOS.locBuffer + - i * chunkSize, chunkSize * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) ) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - remain = number % chunkSize; - if (remain != 0) - if ((failAdditionalInfo1 = fwrite(ADOLC_CURRENT_TAPE_INFOS.locBuffer + - chunks * chunkSize, remain * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) ) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape += number; - ADOLC_CURRENT_TAPE_INFOS.currLoc = ADOLC_CURRENT_TAPE_INFOS.locBuffer; - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + number = lastLocP1 - ADOLC_CURRENT_TAPE_INFOS.locBuffer; + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if ((failAdditionalInfo1 = + fwrite(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, + chunkSize * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + remain = number % chunkSize; + if (remain != 0) + if ((failAdditionalInfo1 = + fwrite(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * chunkSize, + remain * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape += number; + ADOLC_CURRENT_TAPE_INFOS.currLoc = ADOLC_CURRENT_TAPE_INFOS.locBuffer; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; } /****************************************************************************/ /* Reads the next block of locations into the internal buffer. */ /****************************************************************************/ void get_loc_block_f() { - size_t i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE], - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof (locint); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, - chunkSize * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) - fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * chunkSize, - remain * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) - fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape -= number; - ADOLC_CURRENT_TAPE_INFOS.currLoc = ADOLC_CURRENT_TAPE_INFOS.locBuffer; + size_t i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE], + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, + chunkSize * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) + fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * chunkSize, + remain * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) + fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape -= number; + ADOLC_CURRENT_TAPE_INFOS.currLoc = ADOLC_CURRENT_TAPE_INFOS.locBuffer; } /****************************************************************************/ /* Reads the previous block of locations into the internal buffer. */ /****************************************************************************/ void get_loc_block_r() { - size_t i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - number = ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; - fseek(ADOLC_CURRENT_TAPE_INFOS.loc_file, sizeof(locint) * - (ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape - number), SEEK_SET); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, - chunkSize * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) - fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * chunkSize, - remain * sizeof(locint), 1, - ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) - fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); - ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape -= - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; - ADOLC_CURRENT_TAPE_INFOS.currLoc = ADOLC_CURRENT_TAPE_INFOS.lastLocP1 - - *(ADOLC_CURRENT_TAPE_INFOS.lastLocP1 - 1); + size_t i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + number = ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; + fseek(ADOLC_CURRENT_TAPE_INFOS.loc_file, + sizeof(locint) * (ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape - number), + SEEK_SET); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(locint); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + i * chunkSize, + chunkSize * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) + fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.locBuffer + chunks * chunkSize, + remain * sizeof(locint), 1, + ADOLC_CURRENT_TAPE_INFOS.loc_file) != 1) + fail(ADOLC_EVAL_LOC_TAPE_READ_FAILED); + ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape -= + ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]; + ADOLC_CURRENT_TAPE_INFOS.currLoc = ADOLC_CURRENT_TAPE_INFOS.lastLocP1 - + *(ADOLC_CURRENT_TAPE_INFOS.lastLocP1 - 1); } /* --- Values (Constants -- Real) --- */ @@ -2075,39 +2118,41 @@ void get_loc_block_r() { /* creation, removal, ... */ /****************************************************************************/ void put_vals_writeBlock(double *vals, locint numVals) { - int i; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + int i; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - for (i = 0; i < numVals; ++i) { - *ADOLC_CURRENT_TAPE_INFOS.currVal = vals[i]; - ++ADOLC_CURRENT_TAPE_INFOS.currVal; - } - ADOLC_PUT_LOCINT(ADOLC_CURRENT_TAPE_INFOS.lastValP1 - ADOLC_CURRENT_TAPE_INFOS.currVal); - put_val_block(ADOLC_CURRENT_TAPE_INFOS.lastValP1); - /* every operation writes 1 opcode */ - if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; - } - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_val; + for (i = 0; i < numVals; ++i) { + *ADOLC_CURRENT_TAPE_INFOS.currVal = vals[i]; + ++ADOLC_CURRENT_TAPE_INFOS.currVal; + } + ADOLC_PUT_LOCINT(ADOLC_CURRENT_TAPE_INFOS.lastValP1 - + ADOLC_CURRENT_TAPE_INFOS.currVal); + put_val_block(ADOLC_CURRENT_TAPE_INFOS.lastValP1); + /* every operation writes 1 opcode */ + if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == + ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; ++ADOLC_CURRENT_TAPE_INFOS.currOp; + } + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_val; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; } /****************************************************************************/ /* Write some constants to the buffer without disk access */ /****************************************************************************/ void put_vals_notWriteBlock(double *vals, locint numVals) { - int i; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + int i; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - for (i = 0; i < numVals; ++i) { - *ADOLC_CURRENT_TAPE_INFOS.currVal = vals[i]; - ++ADOLC_CURRENT_TAPE_INFOS.currVal; - } + for (i = 0; i < numVals; ++i) { + *ADOLC_CURRENT_TAPE_INFOS.currVal = vals[i]; + ++ADOLC_CURRENT_TAPE_INFOS.currVal; + } } /****************************************************************************/ @@ -2115,112 +2160,114 @@ void put_vals_notWriteBlock(double *vals, locint numVals) { /* removal, ... */ /****************************************************************************/ void put_val_block(double *lastValP1) { - size_t i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - if (ADOLC_CURRENT_TAPE_INFOS.val_file == NULL) { - ADOLC_CURRENT_TAPE_INFOS.val_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "rb"); - if (ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { - #if defined(ADOLC_DEBUG) - fprintf(DIAG_OUT, "ADOL-C debug: Old tapefile %s gets removed!\n", - ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName); - #endif - fclose(ADOLC_CURRENT_TAPE_INFOS.val_file); - ADOLC_CURRENT_TAPE_INFOS.val_file = NULL; - if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName)) - fprintf(DIAG_OUT, "ADOL-C warning: " - "Unable to remove old tapefile\n"); - ADOLC_CURRENT_TAPE_INFOS.val_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "wb"); - } else { - ADOLC_CURRENT_TAPE_INFOS.val_file = - fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "wb"); - } + size_t i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + if (ADOLC_CURRENT_TAPE_INFOS.val_file == NULL) { + ADOLC_CURRENT_TAPE_INFOS.val_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "rb"); + if (ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { +#if defined(ADOLC_DEBUG) + fprintf(DIAG_OUT, "ADOL-C debug: Old tapefile %s gets removed!\n", + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName); +#endif + fclose(ADOLC_CURRENT_TAPE_INFOS.val_file); + ADOLC_CURRENT_TAPE_INFOS.val_file = NULL; + if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName)) + fprintf(DIAG_OUT, "ADOL-C warning: " + "Unable to remove old tapefile\n"); + ADOLC_CURRENT_TAPE_INFOS.val_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "wb"); + } else { + ADOLC_CURRENT_TAPE_INFOS.val_file = + fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "wb"); } + } - number = lastValP1 - ADOLC_CURRENT_TAPE_INFOS.valBuffer; - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if ((failAdditionalInfo1 = fwrite(ADOLC_CURRENT_TAPE_INFOS.valBuffer + - i * chunkSize, chunkSize * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) ) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - remain = number % chunkSize; - if (remain != 0) - if ((failAdditionalInfo1 = fwrite(ADOLC_CURRENT_TAPE_INFOS.valBuffer + - chunks * chunkSize, remain * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) ) != 1) - fail(ADOLC_TAPING_FATAL_IO_ERROR); - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape += number; - ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.valBuffer; - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + number = lastValP1 - ADOLC_CURRENT_TAPE_INFOS.valBuffer; + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if ((failAdditionalInfo1 = + fwrite(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, + chunkSize * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + remain = number % chunkSize; + if (remain != 0) + if ((failAdditionalInfo1 = + fwrite(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * chunkSize, + remain * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file)) != 1) + fail(ADOLC_TAPING_FATAL_IO_ERROR); + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape += number; + ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.valBuffer; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; } /****************************************************************************/ /* Reads the next block of constants into the internal buffer. */ /****************************************************************************/ void get_val_block_f() { - size_t i, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE], - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof (double); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, - chunkSize * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * chunkSize, - remain * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape -= number; - ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.valBuffer; - /* get_locint_f(); value used in reverse only */ - ++ADOLC_CURRENT_TAPE_INFOS.currLoc; + size_t i, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + number = MIN_ADOLC(ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE], + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, + chunkSize * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * chunkSize, + remain * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape -= number; + ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.valBuffer; + /* get_locint_f(); value used in reverse only */ + ++ADOLC_CURRENT_TAPE_INFOS.currLoc; } /****************************************************************************/ /* Reads the previous block of values into the internal buffer. */ /****************************************************************************/ void get_val_block_r() { - size_t i, chunks; - size_t number, remain, chunkSize; - locint temp; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - number = ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; - fseek(ADOLC_CURRENT_TAPE_INFOS.val_file, sizeof(double) * - (ADOLC_CURRENT_TAPE_INFOS.numVals_Tape - number), SEEK_SET); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, - chunkSize * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * chunkSize, - remain * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape -= number; - --ADOLC_CURRENT_TAPE_INFOS.currLoc; - temp = *ADOLC_CURRENT_TAPE_INFOS.currLoc; - ADOLC_CURRENT_TAPE_INFOS.currVal = - ADOLC_CURRENT_TAPE_INFOS.lastValP1 - temp; + size_t i, chunks; + size_t number, remain, chunkSize; + locint temp; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + number = ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; + fseek(ADOLC_CURRENT_TAPE_INFOS.val_file, + sizeof(double) * (ADOLC_CURRENT_TAPE_INFOS.numVals_Tape - number), + SEEK_SET); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, + chunkSize * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * chunkSize, + remain * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape -= number; + --ADOLC_CURRENT_TAPE_INFOS.currLoc; + temp = *ADOLC_CURRENT_TAPE_INFOS.currLoc; + ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.lastValP1 - temp; } /****************************************************************************/ @@ -2228,61 +2275,66 @@ void get_val_block_r() { /* is at least 5. */ /****************************************************************************/ locint get_val_space(void) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.lastValP1 - 5 < ADOLC_CURRENT_TAPE_INFOS.currVal) { - ADOLC_PUT_LOCINT(ADOLC_CURRENT_TAPE_INFOS.lastValP1 - ADOLC_CURRENT_TAPE_INFOS.currVal); - put_val_block(ADOLC_CURRENT_TAPE_INFOS.lastValP1); - /* every operation writes 1 opcode */ - if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; - } - *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_val; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.lastValP1 - 5 < + ADOLC_CURRENT_TAPE_INFOS.currVal) { + ADOLC_PUT_LOCINT(ADOLC_CURRENT_TAPE_INFOS.lastValP1 - + ADOLC_CURRENT_TAPE_INFOS.currVal); + put_val_block(ADOLC_CURRENT_TAPE_INFOS.lastValP1); + /* every operation writes 1 opcode */ + if (ADOLC_CURRENT_TAPE_INFOS.currOp + 1 == + ADOLC_CURRENT_TAPE_INFOS.lastOpP1) { + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + put_op_block(ADOLC_CURRENT_TAPE_INFOS.lastOpP1); + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_op; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; } - return (ADOLC_CURRENT_TAPE_INFOS.lastValP1 - ADOLC_CURRENT_TAPE_INFOS.currVal); + *ADOLC_CURRENT_TAPE_INFOS.currOp = end_of_val; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; + } + return (ADOLC_CURRENT_TAPE_INFOS.lastValP1 - + ADOLC_CURRENT_TAPE_INFOS.currVal); } /****************************************************************************/ /* Discards parameters from the end of value tape during reverse mode */ /****************************************************************************/ void discard_params_r(void) { - size_t i, np, ip, avail, rsize, chunks; - size_t number, remain, chunkSize; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - np = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; - ip = np; - while ( ip > 0 ) { - avail = ADOLC_CURRENT_TAPE_INFOS.currVal - ADOLC_CURRENT_TAPE_INFOS.valBuffer; - rsize = (avail 0 ) { - number = ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; - fseek(ADOLC_CURRENT_TAPE_INFOS.val_file, sizeof(double) * - (ADOLC_CURRENT_TAPE_INFOS.numVals_Tape - number), SEEK_SET); - chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); - chunks = number / chunkSize; - for (i = 0; i < chunks; ++i) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + - i * chunkSize, chunkSize * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - remain = number % chunkSize; - if (remain != 0) - if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + - chunks * chunkSize, remain * sizeof(double), 1, - ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) - fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); - ADOLC_CURRENT_TAPE_INFOS.numVals_Tape -= number; - ADOLC_CURRENT_TAPE_INFOS.currVal = - ADOLC_CURRENT_TAPE_INFOS.lastValP1; - } + size_t i, np, ip, avail, rsize, chunks; + size_t number, remain, chunkSize; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + np = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; + ip = np; + while (ip > 0) { + avail = + ADOLC_CURRENT_TAPE_INFOS.currVal - ADOLC_CURRENT_TAPE_INFOS.valBuffer; + rsize = (avail < ip) ? avail : ip; + ip -= rsize; + ADOLC_CURRENT_TAPE_INFOS.currVal -= rsize; + if (ip > 0) { + number = ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]; + fseek(ADOLC_CURRENT_TAPE_INFOS.val_file, + sizeof(double) * (ADOLC_CURRENT_TAPE_INFOS.numVals_Tape - number), + SEEK_SET); + chunkSize = ADOLC_IO_CHUNK_SIZE / sizeof(double); + chunks = number / chunkSize; + for (i = 0; i < chunks; ++i) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + i * chunkSize, + chunkSize * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + remain = number % chunkSize; + if (remain != 0) + if (fread(ADOLC_CURRENT_TAPE_INFOS.valBuffer + chunks * chunkSize, + remain * sizeof(double), 1, + ADOLC_CURRENT_TAPE_INFOS.val_file) != 1) + fail(ADOLC_EVAL_VAL_TAPE_READ_FAILED); + ADOLC_CURRENT_TAPE_INFOS.numVals_Tape -= number; + ADOLC_CURRENT_TAPE_INFOS.currVal = ADOLC_CURRENT_TAPE_INFOS.lastValP1; } + } } /****************************************************************************/ @@ -2290,13 +2342,13 @@ void discard_params_r(void) { /* vector. -- Forward Mode -- */ /****************************************************************************/ double *get_val_v_f(locint size) { - double *temp; - ADOLC_OPENMP_THREAD_NUMBER; + double *temp; + ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - temp = ADOLC_CURRENT_TAPE_INFOS.currVal; - ADOLC_CURRENT_TAPE_INFOS.currVal += size; - return temp; + ADOLC_OPENMP_GET_THREAD_NUMBER; + temp = ADOLC_CURRENT_TAPE_INFOS.currVal; + ADOLC_CURRENT_TAPE_INFOS.currVal += size; + return temp; } /****************************************************************************/ @@ -2304,10 +2356,10 @@ double *get_val_v_f(locint size) { /* vector. -- Reverse Mode -- */ /****************************************************************************/ double *get_val_v_r(locint size) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - ADOLC_CURRENT_TAPE_INFOS.currVal -= size; - return ADOLC_CURRENT_TAPE_INFOS.currVal; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_CURRENT_TAPE_INFOS.currVal -= size; + return ADOLC_CURRENT_TAPE_INFOS.currVal; } /* --- Updates / Corrections --- */ @@ -2316,10 +2368,10 @@ double *get_val_v_r(locint size) { /* Not sure what's going on here! -> vector class ? --- kowarz */ /****************************************************************************/ void reset_val_r(void) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.currVal == ADOLC_CURRENT_TAPE_INFOS.valBuffer) - get_val_block_r(); + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.currVal == ADOLC_CURRENT_TAPE_INFOS.valBuffer) + get_val_block_r(); } /****************************************************************************/ @@ -2327,77 +2379,81 @@ void reset_val_r(void) { /* e.g. t = a + b ; y = t => y = a + b */ /****************************************************************************/ int upd_resloc(locint temp, locint lhs) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer < 1) return 0; - if (temp == *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1)) { - *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1) = lhs; - return 1; - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer < 1) return 0; + if (temp == *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1)) { + *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1) = lhs; + return 1; + } + return 0; } int upd_resloc_check(locint temp, locint lhs) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer < 1) return 0; - if (temp == *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1)) { - return 1; - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer < 1) return 0; + if (temp == *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1)) { + return 1; + } + return 0; } /****************************************************************************/ /* Update locations and operations tape to remove special operations inv. */ /* temporary variables. e.g. t = a * b ; y += t => y += a * b */ /****************************************************************************/ int upd_resloc_inc_prod(locint temp, locint newlhs, unsigned char newop) { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer < 3) return 0; - if (ADOLC_CURRENT_TAPE_INFOS.currOp - ADOLC_CURRENT_TAPE_INFOS.opBuffer < 1) return 0; - if (temp == *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1) && - mult_a_a == *(ADOLC_CURRENT_TAPE_INFOS.currOp - 1) && - /* skipping recursive case */ - newlhs != *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 2) && - newlhs != *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 3) ) { - *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1) = newlhs; - *(ADOLC_CURRENT_TAPE_INFOS.currOp - 1) = newop; - return 1; - } + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + if (ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer < 3) return 0; + if (ADOLC_CURRENT_TAPE_INFOS.currOp - ADOLC_CURRENT_TAPE_INFOS.opBuffer < 1) + return 0; + if (temp == *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1) && + mult_a_a == *(ADOLC_CURRENT_TAPE_INFOS.currOp - 1) && + /* skipping recursive case */ + newlhs != *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 2) && + newlhs != *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 3)) { + *(ADOLC_CURRENT_TAPE_INFOS.currLoc - 1) = newlhs; + *(ADOLC_CURRENT_TAPE_INFOS.currOp - 1) = newop; + return 1; + } + return 0; } void enableBranchSwitchWarnings() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 1; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 1; } void disableBranchSwitchWarnings() { - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 0; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning = 0; } /****************************************************************************/ /* UTILs */ /****************************************************************************/ double make_nan() { - double a, b; - #ifdef inf_num - a = non_num; - b = non_den; - #endif - return a / b; + double a, b; +#ifdef inf_num + a = non_num; + b = non_den; +#endif + return a / b; } double make_inf() { - double a, b; - #ifdef inf_num - a = inf_num; - b = inf_den; - #endif - return a / b; + double a, b; +#ifdef inf_num + a = inf_num; + b = inf_den; +#endif + return a / b; } /****************************************************************************/ @@ -2406,75 +2462,74 @@ double make_inf() { /*--------------------------------------------------------------------------*/ unsigned char get_op_f() { - unsigned char temp; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + unsigned char temp; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - temp = *ADOLC_CURRENT_TAPE_INFOS.currOp; - ++ADOLC_CURRENT_TAPE_INFOS.currOp; - fprintf(DIAG_OUT, "f_op: %i\n", temp - '\0'); /* why -'\0' ??? kowarz */ - return temp; + temp = *ADOLC_CURRENT_TAPE_INFOS.currOp; + ++ADOLC_CURRENT_TAPE_INFOS.currOp; + fprintf(DIAG_OUT, "f_op: %i\n", temp - '\0'); /* why -'\0' ??? kowarz */ + return temp; } /*--------------------------------------------------------------------------*/ unsigned char get_op_r() { - unsigned char temp; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + unsigned char temp; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - --ADOLC_CURRENT_TAPE_INFOS.currOp; - temp = *ADOLC_CURRENT_TAPE_INFOS.currOp; - fprintf(DIAG_OUT, "r_op: %i\n", temp - '\0'); - return temp; + --ADOLC_CURRENT_TAPE_INFOS.currOp; + temp = *ADOLC_CURRENT_TAPE_INFOS.currOp; + fprintf(DIAG_OUT, "r_op: %i\n", temp - '\0'); + return temp; } /*--------------------------------------------------------------------------*/ locint get_locint_f() { - locint temp; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + locint temp; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - temp = *ADOLC_CURRENT_TAPE_INFOS.currLoc; - ++ADOLC_CURRENT_TAPE_INFOS.currLoc; - fprintf(DIAG_OUT, "f_loc: %i\n", temp); - return temp; + temp = *ADOLC_CURRENT_TAPE_INFOS.currLoc; + ++ADOLC_CURRENT_TAPE_INFOS.currLoc; + fprintf(DIAG_OUT, "f_loc: %i\n", temp); + return temp; } /*--------------------------------------------------------------------------*/ locint get_locint_r() { - unsigned char temp; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + unsigned char temp; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - --ADOLC_CURRENT_TAPE_INFOS.currLoc; - temp = *ADOLC_CURRENT_TAPE_INFOS.currLoc; - fprintf(DIAG_OUT, "r_loc: %i\n", temp); - return temp; + --ADOLC_CURRENT_TAPE_INFOS.currLoc; + temp = *ADOLC_CURRENT_TAPE_INFOS.currLoc; + fprintf(DIAG_OUT, "r_loc: %i\n", temp); + return temp; } /*--------------------------------------------------------------------------*/ double get_val_f() { - double temp; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + double temp; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - temp = *ADOLC_CURRENT_TAPE_INFOS.currVal; - ++ADOLC_CURRENT_TAPE_INFOS.currVal; - fprintf(DIAG_OUT, "f_val: %e\n", temp); - return temp; + temp = *ADOLC_CURRENT_TAPE_INFOS.currVal; + ++ADOLC_CURRENT_TAPE_INFOS.currVal; + fprintf(DIAG_OUT, "f_val: %e\n", temp); + return temp; } /*--------------------------------------------------------------------------*/ double get_val_r() { - double temp; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; + double temp; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; - --ADOLC_CURRENT_TAPE_INFOS.currVal; - temp = *ADOLC_CURRENT_TAPE_INFOS.currVal; - fprintf(DIAG_OUT, "r_val: %e\n", temp); - return temp; + --ADOLC_CURRENT_TAPE_INFOS.currVal; + temp = *ADOLC_CURRENT_TAPE_INFOS.currVal; + fprintf(DIAG_OUT, "r_val: %e\n", temp); + return temp; } #endif - diff --git a/ADOL-C/src/taping_p.h b/ADOL-C/src/taping_p.h index e0b45bbd2..47fd6d3e5 100644 --- a/ADOL-C/src/taping_p.h +++ b/ADOL-C/src/taping_p.h @@ -3,126 +3,120 @@ File: taping_p.h Revision: $Id$ Contents: declarations for used by taping routines - + Copyright (c) Andreas Kowarz, Jean Utke This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. ----------------------------------------------------------------------------*/ #if !defined(ADOLC_TAPING_P_H) -#define ADOLC_TAPING_P_H 1 + #define ADOLC_TAPING_P_H 1 -#include + #include -#ifdef __cplusplus -#include "storemanager.h" -#endif -#include -#include -#include + #ifdef __cplusplus + #include "storemanager.h" + #endif + #include + #include + #include BEGIN_C_DECLS enum WORKMODES { - ADOLC_NO_MODE, - - ADOLC_FORWARD, - ADOLC_ZOS_FORWARD, - ADOLC_FOS_FORWARD, - ADOLC_FOV_FORWARD, - ADOLC_HOS_FORWARD, - ADOLC_HOV_FORWARD, - - ADOLC_REVERSE, - ADOLC_FOS_REVERSE, - ADOLC_FOV_REVERSE, - ADOLC_HOS_REVERSE, - ADOLC_HOV_REVERSE, - - ADOLC_TAPING + ADOLC_NO_MODE, + + ADOLC_FORWARD, + ADOLC_ZOS_FORWARD, + ADOLC_FOS_FORWARD, + ADOLC_FOV_FORWARD, + ADOLC_HOS_FORWARD, + ADOLC_HOV_FORWARD, + + ADOLC_REVERSE, + ADOLC_FOS_REVERSE, + ADOLC_FOV_REVERSE, + ADOLC_HOS_REVERSE, + ADOLC_HOV_REVERSE, + + ADOLC_TAPING }; /****************************************************************************/ /* Tape identification (ADOLC & version check) */ /****************************************************************************/ typedef struct { - short adolc_ver; - short adolc_sub; - short adolc_lvl; - short locint_size; - short revreal_size; - short address_size; -} -ADOLC_ID; + short adolc_ver; + short adolc_sub; + short adolc_lvl; + short locint_size; + short revreal_size; + short address_size; +} ADOLC_ID; extern ADOLC_ID adolc_id; /****************************************************************************/ /* tape types => used for file name generation */ /****************************************************************************/ -enum TAPENAMES { - LOCATIONS_TAPE, - VALUES_TAPE, - OPERATIONS_TAPE, - TAYLORS_TAPE -}; +enum TAPENAMES { LOCATIONS_TAPE, VALUES_TAPE, OPERATIONS_TAPE, TAYLORS_TAPE }; /****************************************************************************/ /* Errors handled by fail(...) */ /****************************************************************************/ enum ADOLC_ERRORS { - ADOLC_MALLOC_FAILED, - ADOLC_INTEGER_TAPE_FOPEN_FAILED, - ADOLC_INTEGER_TAPE_FREAD_FAILED, - ADOLC_VALUE_TAPE_FOPEN_FAILED, - ADOLC_VALUE_TAPE_FREAD_FAILED, - ADOLC_TAPE_TO_OLD, - ADOLC_WRONG_LOCINT_SIZE, - ADOLC_MORE_STAT_SPACE_REQUIRED, - - ADOLC_TAPING_BUFFER_ALLOCATION_FAILED, - ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED, - ADOLC_TAPING_READ_ERROR_IN_TAYLOR_CLOSE, - ADOLC_TAPING_TO_MANY_TAYLOR_BUFFERS, - ADOLC_TAPING_TO_MANY_LOCINTS, - ADOLC_TAPING_STORE_REALLOC_FAILED, - ADOLC_TAPING_FATAL_IO_ERROR, - ADOLC_TAPING_TAPE_STILL_IN_USE, - ADOLC_TAPING_TAYLOR_OPEN_FAILED, - - ADOLC_EVAL_SEEK_VALUE_STACK, - ADOLC_EVAL_OP_TAPE_READ_FAILED, - ADOLC_EVAL_VAL_TAPE_READ_FAILED, - ADOLC_EVAL_LOC_TAPE_READ_FAILED, - ADOLC_EVAL_TAY_TAPE_READ_FAILED, - - ADOLC_REVERSE_NO_TAYLOR_STACK, - ADOLC_REVERSE_COUNTS_MISMATCH, - ADOLC_REVERSE_TAYLOR_COUNTS_MISMATCH, - - ADOLC_BUFFER_NULLPOINTER_FUNCTION, - ADOLC_BUFFER_INDEX_TO_LARGE, - - ADOLC_EXT_DIFF_NULLPOINTER_STRUCT, - ADOLC_EXT_DIFF_WRONG_TAPESTATS, - ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION, - ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC, - ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT, - ADOLC_EXT_DIFF_WRONG_FUNCTION_INDEX, - ADOLC_EXT_DIFF_LOCATIONGAP, - - ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER, - ADOLC_CHECKPOINTING_NULLPOINTER_ARGUMENT, - ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION, - ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION_DOUBLE, - ADOLC_CHECKPOINTING_REVOLVE_IRREGULAR_TERMINATED, - ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION, - ADOLC_WRONG_PLATFORM_32, - ADOLC_WRONG_PLATFORM_64, - ADOLC_TAPING_NOT_ACTUALLY_TAPING, - ADOLC_VEC_LOCATIONGAP + ADOLC_MALLOC_FAILED, + ADOLC_INTEGER_TAPE_FOPEN_FAILED, + ADOLC_INTEGER_TAPE_FREAD_FAILED, + ADOLC_VALUE_TAPE_FOPEN_FAILED, + ADOLC_VALUE_TAPE_FREAD_FAILED, + ADOLC_TAPE_TO_OLD, + ADOLC_WRONG_LOCINT_SIZE, + ADOLC_MORE_STAT_SPACE_REQUIRED, + + ADOLC_TAPING_BUFFER_ALLOCATION_FAILED, + ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED, + ADOLC_TAPING_READ_ERROR_IN_TAYLOR_CLOSE, + ADOLC_TAPING_TO_MANY_TAYLOR_BUFFERS, + ADOLC_TAPING_TO_MANY_LOCINTS, + ADOLC_TAPING_STORE_REALLOC_FAILED, + ADOLC_TAPING_FATAL_IO_ERROR, + ADOLC_TAPING_TAPE_STILL_IN_USE, + ADOLC_TAPING_TAYLOR_OPEN_FAILED, + + ADOLC_EVAL_SEEK_VALUE_STACK, + ADOLC_EVAL_OP_TAPE_READ_FAILED, + ADOLC_EVAL_VAL_TAPE_READ_FAILED, + ADOLC_EVAL_LOC_TAPE_READ_FAILED, + ADOLC_EVAL_TAY_TAPE_READ_FAILED, + + ADOLC_REVERSE_NO_TAYLOR_STACK, + ADOLC_REVERSE_COUNTS_MISMATCH, + ADOLC_REVERSE_TAYLOR_COUNTS_MISMATCH, + + ADOLC_BUFFER_NULLPOINTER_FUNCTION, + ADOLC_BUFFER_INDEX_TO_LARGE, + + ADOLC_EXT_DIFF_NULLPOINTER_STRUCT, + ADOLC_EXT_DIFF_WRONG_TAPESTATS, + ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION, + ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC, + ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT, + ADOLC_EXT_DIFF_WRONG_FUNCTION_INDEX, + ADOLC_EXT_DIFF_LOCATIONGAP, + + ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER, + ADOLC_CHECKPOINTING_NULLPOINTER_ARGUMENT, + ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION, + ADOLC_CHECKPOINTING_NULLPOINTER_FUNCTION_DOUBLE, + ADOLC_CHECKPOINTING_REVOLVE_IRREGULAR_TERMINATED, + ADOLC_CHECKPOINTING_UNEXPECTED_REVOLVE_ACTION, + ADOLC_WRONG_PLATFORM_32, + ADOLC_WRONG_PLATFORM_64, + ADOLC_TAPING_NOT_ACTUALLY_TAPING, + ADOLC_VEC_LOCATIONGAP }; /* additional infos fail can work with */ extern int failAdditionalInfo1; @@ -136,7 +130,7 @@ extern void *failAdditionalInfo6; /* tape information */ /****************************************************************************/ -#ifdef SPARSE + #ifdef SPARSE typedef struct SparseJacInfos { void *g; void *jr1d; @@ -151,255 +145,256 @@ typedef struct SparseJacInfos { } SparseJacInfos; typedef struct SparseHessInfos { - void *g; - void *hr; + void *g; + void *hr; + + double **Hcomp; + double ***Xppp; + double ***Yppp; + double ***Zppp; + double **Upp; - double **Hcomp; - double*** Xppp; - double*** Yppp; - double*** Zppp; - double** Upp; - - unsigned int **HP; + unsigned int **HP; int nnz_in, indep, p; } SparseHessInfos; -#endif + #endif typedef struct PersistantTapeInfos { /* survive tape re-usage */ - int forodec_nax, forodec_dax; - double *forodec_y, *forodec_z, **forodec_Z; - double **jacSolv_J; - double **jacSolv_I; - double *jacSolv_xold; - int *jacSolv_ri; - int *jacSolv_ci; - int jacSolv_nax, jacSolv_modeold, jacSolv_cgd; - -#ifdef SPARSE - /* sparse Jacobian matrices */ - - SparseJacInfos sJinfos; - - /* sparse Hessian matrices */ - - SparseHessInfos sHinfos; -#endif - - /* file names */ - - char *op_fileName; - char *loc_fileName; - char *val_fileName; - char *tay_fileName; - - int keepTape; /* - remember if tapes shall be written out to disk - - this information can only be given at taping time and - must survive all other actions on the tape */ - - /** - * defaults to 0, if 1 skips file removal (when file operations are costly) - */ - int skipFileCleanup; - - revreal *paramstore; -#ifdef __cplusplus - PersistantTapeInfos(); - ~PersistantTapeInfos(); - PersistantTapeInfos& operator=(const PersistantTapeInfos&) = default; -#endif + int forodec_nax, forodec_dax; + double *forodec_y, *forodec_z, **forodec_Z; + double **jacSolv_J; + double **jacSolv_I; + double *jacSolv_xold; + int *jacSolv_ri; + int *jacSolv_ci; + int jacSolv_nax, jacSolv_modeold, jacSolv_cgd; + + #ifdef SPARSE + /* sparse Jacobian matrices */ + + SparseJacInfos sJinfos; + + /* sparse Hessian matrices */ + + SparseHessInfos sHinfos; + #endif + + /* file names */ + + char *op_fileName; + char *loc_fileName; + char *val_fileName; + char *tay_fileName; + + int keepTape; /* - remember if tapes shall be written out to disk + - this information can only be given at taping time and + must survive all other actions on the tape */ + + /** + * defaults to 0, if 1 skips file removal (when file operations are costly) + */ + int skipFileCleanup; + + revreal *paramstore; + #ifdef __cplusplus + PersistantTapeInfos(); + ~PersistantTapeInfos(); + PersistantTapeInfos &operator=(const PersistantTapeInfos &) = default; + #endif } PersistantTapeInfos; /** - * maximal number of locations writen per op code + * maximal number of locations writen per op code */ extern const int maxLocsPerOp; typedef struct TapeInfos { - short tapeID; - int inUse; - uint numInds; - uint numDeps; - int keepTaylors; /* == 1 - write taylor stack in taping mode */ - size_t stats[STAT_SIZE]; - int traceFlag; - char tapingComplete; - - /* operations tape */ - FILE *op_file; /* file descriptor */ - unsigned char *opBuffer; /* pointer to the current tape buffer */ - unsigned char *currOp; /* pointer to the current opcode */ - unsigned char *lastOpP1; /* pointer to element following the buffer */ - size_t numOps_Tape; /* overall number of opcodes */ - size_t num_eq_prod; /* overall number of eq_*_prod for nlf */ - - /* values (real) tape */ - FILE *val_file; - double *valBuffer; - double *currVal; - double *lastValP1; - size_t numVals_Tape; - - /* locations tape */ - FILE *loc_file; - locint *locBuffer; - locint *currLoc; - locint *lastLocP1; - size_t numLocs_Tape; - - /* taylor stack tape */ - FILE *tay_file; - revreal *tayBuffer; - revreal *currTay; - revreal *lastTayP1; - size_t numTays_Tape; - int nextBufferNumber; /* the next Buffer to read back */ - char lastTayBlockInCore; /* == 1 if last taylor buffer is still in - in core (first call of reverse) */ - double **T_for; /* derivative buffer - forward */ - uint deg_save; /* degree to save and saved respectively */ - uint tay_numInds; /* # of independents for the taylor stack */ - uint tay_numDeps; /* # of dependents for the taylor stack */ - - /* checkpointing */ - locint lowestXLoc_for; /* location of the first ind. - forward mode */ - locint lowestYLoc_for; /* location of the first dep. - forward mode */ - locint lowestXLoc_rev; /* location of the first ind. - reverse mode */ - locint lowestYLoc_rev; /* location of the first dep. - reverse mode */ - locint cpIndex; /* index of the curr. cp function <- tape */ - int numDirs_rev; /* # of directions for **v_reverse (checkpointing) */ - - locint *lowestXLoc_ext_v2; - locint *lowestYLoc_ext_v2; - - /* evaluation forward */ - double *dp_T0; - int gDegree, numTay; - enum WORKMODES workMode; - /* - * Taylor coefficient array allocated like this: - * dpp_T[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES][numTay*gDegree] - */ - double **dpp_T; - - /* evaluation reverse */ - revreal *rp_T; - revreal **rpp_T; - revreal *rp_A; - revreal **rpp_A; - unsigned long int **upp_A; - - /* extern diff. fcts */ - locint ext_diff_fct_index; /* set by forward and reverse (from tape) */ - char in_nested_ctx; - - size_t numSwitches; - locint* switchlocs; - double* signature; - - PersistantTapeInfos pTapeInfos; - -#if defined(__cplusplus) - TapeInfos(); - TapeInfos(short tapeID); - ~TapeInfos() {} - void copy(const TapeInfos&); -#endif -} -TapeInfos; + short tapeID; + int inUse; + uint numInds; + uint numDeps; + int keepTaylors; /* == 1 - write taylor stack in taping mode */ + size_t stats[STAT_SIZE]; + int traceFlag; + char tapingComplete; + + /* operations tape */ + FILE *op_file; /* file descriptor */ + unsigned char *opBuffer; /* pointer to the current tape buffer */ + unsigned char *currOp; /* pointer to the current opcode */ + unsigned char *lastOpP1; /* pointer to element following the buffer */ + size_t numOps_Tape; /* overall number of opcodes */ + size_t num_eq_prod; /* overall number of eq_*_prod for nlf */ + + /* values (real) tape */ + FILE *val_file; + double *valBuffer; + double *currVal; + double *lastValP1; + size_t numVals_Tape; + + /* locations tape */ + FILE *loc_file; + locint *locBuffer; + locint *currLoc; + locint *lastLocP1; + size_t numLocs_Tape; + + /* taylor stack tape */ + FILE *tay_file; + revreal *tayBuffer; + revreal *currTay; + revreal *lastTayP1; + size_t numTays_Tape; + int nextBufferNumber; /* the next Buffer to read back */ + char lastTayBlockInCore; /* == 1 if last taylor buffer is still in + in core (first call of reverse) */ + double **T_for; /* derivative buffer - forward */ + uint deg_save; /* degree to save and saved respectively */ + uint tay_numInds; /* # of independents for the taylor stack */ + uint tay_numDeps; /* # of dependents for the taylor stack */ + + /* checkpointing */ + locint lowestXLoc_for; /* location of the first ind. - forward mode */ + locint lowestYLoc_for; /* location of the first dep. - forward mode */ + locint lowestXLoc_rev; /* location of the first ind. - reverse mode */ + locint lowestYLoc_rev; /* location of the first dep. - reverse mode */ + locint cpIndex; /* index of the curr. cp function <- tape */ + int numDirs_rev; /* # of directions for **v_reverse (checkpointing) */ + + locint *lowestXLoc_ext_v2; + locint *lowestYLoc_ext_v2; + + /* evaluation forward */ + double *dp_T0; + int gDegree, numTay; + enum WORKMODES workMode; + /* + * Taylor coefficient array allocated like this: + * dpp_T[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES][numTay*gDegree] + */ + double **dpp_T; + + /* evaluation reverse */ + revreal *rp_T; + revreal **rpp_T; + revreal *rp_A; + revreal **rpp_A; + unsigned long int **upp_A; + + /* extern diff. fcts */ + locint ext_diff_fct_index; /* set by forward and reverse (from tape) */ + char in_nested_ctx; + + size_t numSwitches; + locint *switchlocs; + double *signature; + + PersistantTapeInfos pTapeInfos; + + #if defined(__cplusplus) + TapeInfos(); + TapeInfos(short tapeID); + ~TapeInfos() {} + void copy(const TapeInfos &); + #endif +} TapeInfos; typedef struct GlobalTapeVarsCL { - double* store; /* double store for calc. while taping */ -#if defined(ADOLC_TRACK_ACTIVITY) - char* actStore; /* activity store for tracking while taping */ -#endif - size_t storeSize; - size_t numLives; - locint maxLoc; - - locint operationBufferSize; /* Defaults to the value specified in */ - locint locationBufferSize; /* usrparms.h. May be overwritten by values */ - locint valueBufferSize; /* in a local config file .adolcrc. */ - locint taylorBufferSize; - int maxNumberTaylorBuffers; - - char inParallelRegion; /* set to 1 if in an OpenMP parallel region */ - char newTape; /* signals: at least one tape created (0/1) */ - char branchSwitchWarning; - TapeInfos *currentTapeInfosPtr; - uint nominmaxFlag; - size_t numparam; - size_t maxparam; - double *pStore; - size_t initialStoreSize; -#ifdef __cplusplus - StoreManager *paramStoreMgrPtr; - StoreManager *storeManagerPtr; - GlobalTapeVarsCL(); - ~GlobalTapeVarsCL(); - const GlobalTapeVarsCL& operator=(const GlobalTapeVarsCL&); - void reallocStore(unsigned char type); -#else - void *paramStoreMgrPtr; - void *storeManagerPtr; -#endif -} -GlobalTapeVars; - -#if defined(_OPENMP) + double *store; /* double store for calc. while taping */ + #if defined(ADOLC_TRACK_ACTIVITY) + char *actStore; /* activity store for tracking while taping */ + #endif + size_t storeSize; + size_t numLives; + locint maxLoc; + + locint operationBufferSize; /* Defaults to the value specified in */ + locint locationBufferSize; /* usrparms.h. May be overwritten by values */ + locint valueBufferSize; /* in a local config file .adolcrc. */ + locint taylorBufferSize; + int maxNumberTaylorBuffers; + + char inParallelRegion; /* set to 1 if in an OpenMP parallel region */ + char newTape; /* signals: at least one tape created (0/1) */ + char branchSwitchWarning; + TapeInfos *currentTapeInfosPtr; + uint nominmaxFlag; + size_t numparam; + size_t maxparam; + double *pStore; + size_t initialStoreSize; + #ifdef __cplusplus + StoreManager *paramStoreMgrPtr; + StoreManager *storeManagerPtr; + GlobalTapeVarsCL(); + ~GlobalTapeVarsCL(); + const GlobalTapeVarsCL &operator=(const GlobalTapeVarsCL &); + void reallocStore(unsigned char type); + #else + void *paramStoreMgrPtr; + void *storeManagerPtr; + #endif +} GlobalTapeVars; + + #if defined(_OPENMP) extern int isParallel(); -#define ADOLC_TAPE_INFOS_BUFFER_DECL *tapeInfosBuffer -#define ADOLC_TAPE_STACK_DECL *tapeStack -#define ADOLC_CURRENT_TAPE_INFOS_DECL *currentTapeInfos -#define ADOLC_CURRENT_TAPE_INFOS_FALLBACK_DECL *currentTapeInfos_fallBack -#define ADOLC_GLOBAL_TAPE_VARS_DECL *globalTapeVars -#define ADOLC_EXT_DIFF_FCTS_BUFFER_DECL *ADOLC_extDiffFctsBuffer -#define ADOLC_CHECKPOINTS_STACK_DECL *ADOLC_checkpointsStack - -#define ADOLC_OPENMP_THREAD_NUMBER int ADOLC_threadNumber -#if defined(ADOLC_THREADSAVE_ERRNO) -#define ADOLC_OPENMP_GET_THREAD_NUMBER ADOLC_threadNumber = errno -#define ADOLC_OPENMP_RESTORE_THREAD_NUMBER errno = ADOLC_threadNumber -#else -#define ADOLC_OPENMP_GET_THREAD_NUMBER ADOLC_threadNumber = omp_get_thread_num() -#define ADOLC_OPENMP_RESTORE_THREAD_NUMBER -#endif - -#define ADOLC_TAPE_INFOS_BUFFER tapeInfosBuffer[ADOLC_threadNumber] -#define ADOLC_TAPE_STACK tapeStack[ADOLC_threadNumber] -#define ADOLC_CURRENT_TAPE_INFOS currentTapeInfos[ADOLC_threadNumber] -#define ADOLC_CURRENT_TAPE_INFOS_FALLBACK currentTapeInfos_fallBack[ADOLC_threadNumber] -#define ADOLC_GLOBAL_TAPE_VARS globalTapeVars[ADOLC_threadNumber] -#define ADOLC_EXT_DIFF_FCTS_BUFFER ADOLC_extDiffFctsBuffer[ADOLC_threadNumber] -#define ADOLC_CHECKPOINTS_STACK ADOLC_checkpointsStack[ADOLC_threadNumber] -#define REVOLVE_NUMBERS revolve_numbers[ADOLC_threadNumber] - -#else - -#define ADOLC_TAPE_INFOS_BUFFER_DECL tapeInfosBuffer -#define ADOLC_TAPE_STACK_DECL tapeStack -#define ADOLC_CURRENT_TAPE_INFOS_DECL currentTapeInfos -#define ADOLC_CURRENT_TAPE_INFOS_FALLBACK_DECL currentTapeInfos_fallBack -#define ADOLC_GLOBAL_TAPE_VARS_DECL globalTapeVars -#define ADOLC_EXT_DIFF_FCTS_BUFFER_DECL ADOLC_extDiffFctsBuffer -#define ADOLC_CHECKPOINTS_STACK_DECL ADOLC_checkpointsStack - -#define ADOLC_OPENMP_THREAD_NUMBER -#define ADOLC_OPENMP_GET_THREAD_NUMBER -#define ADOLC_OPENMP_RESTORE_THREAD_NUMBER - -#define ADOLC_TAPE_INFOS_BUFFER tapeInfosBuffer -#define ADOLC_TAPE_STACK tapeStack -#define ADOLC_CURRENT_TAPE_INFOS currentTapeInfos -#define ADOLC_CURRENT_TAPE_INFOS_FALLBACK currentTapeInfos_fallBack -#define ADOLC_GLOBAL_TAPE_VARS globalTapeVars -#define ADOLC_EXT_DIFF_FCTS_BUFFER ADOLC_extDiffFctsBuffer -#define ADOLC_CHECKPOINTS_STACK ADOLC_checkpointsStack -#define REVOLVE_NUMBERS revolve_numbers - -#endif /* _OPENMP */ + #define ADOLC_TAPE_INFOS_BUFFER_DECL *tapeInfosBuffer + #define ADOLC_TAPE_STACK_DECL *tapeStack + #define ADOLC_CURRENT_TAPE_INFOS_DECL *currentTapeInfos + #define ADOLC_CURRENT_TAPE_INFOS_FALLBACK_DECL *currentTapeInfos_fallBack + #define ADOLC_GLOBAL_TAPE_VARS_DECL *globalTapeVars + #define ADOLC_EXT_DIFF_FCTS_BUFFER_DECL *ADOLC_extDiffFctsBuffer + #define ADOLC_CHECKPOINTS_STACK_DECL *ADOLC_checkpointsStack + + #define ADOLC_OPENMP_THREAD_NUMBER int ADOLC_threadNumber + #if defined(ADOLC_THREADSAVE_ERRNO) + #define ADOLC_OPENMP_GET_THREAD_NUMBER ADOLC_threadNumber = errno + #define ADOLC_OPENMP_RESTORE_THREAD_NUMBER errno = ADOLC_threadNumber + #else + #define ADOLC_OPENMP_GET_THREAD_NUMBER \ + ADOLC_threadNumber = omp_get_thread_num() + #define ADOLC_OPENMP_RESTORE_THREAD_NUMBER + #endif + + #define ADOLC_TAPE_INFOS_BUFFER tapeInfosBuffer[ADOLC_threadNumber] + #define ADOLC_TAPE_STACK tapeStack[ADOLC_threadNumber] + #define ADOLC_CURRENT_TAPE_INFOS currentTapeInfos[ADOLC_threadNumber] + #define ADOLC_CURRENT_TAPE_INFOS_FALLBACK \ + currentTapeInfos_fallBack[ADOLC_threadNumber] + #define ADOLC_GLOBAL_TAPE_VARS globalTapeVars[ADOLC_threadNumber] + #define ADOLC_EXT_DIFF_FCTS_BUFFER \ + ADOLC_extDiffFctsBuffer[ADOLC_threadNumber] + #define ADOLC_CHECKPOINTS_STACK ADOLC_checkpointsStack[ADOLC_threadNumber] + #define REVOLVE_NUMBERS revolve_numbers[ADOLC_threadNumber] + + #else + + #define ADOLC_TAPE_INFOS_BUFFER_DECL tapeInfosBuffer + #define ADOLC_TAPE_STACK_DECL tapeStack + #define ADOLC_CURRENT_TAPE_INFOS_DECL currentTapeInfos + #define ADOLC_CURRENT_TAPE_INFOS_FALLBACK_DECL currentTapeInfos_fallBack + #define ADOLC_GLOBAL_TAPE_VARS_DECL globalTapeVars + #define ADOLC_EXT_DIFF_FCTS_BUFFER_DECL ADOLC_extDiffFctsBuffer + #define ADOLC_CHECKPOINTS_STACK_DECL ADOLC_checkpointsStack + + #define ADOLC_OPENMP_THREAD_NUMBER + #define ADOLC_OPENMP_GET_THREAD_NUMBER + #define ADOLC_OPENMP_RESTORE_THREAD_NUMBER + + #define ADOLC_TAPE_INFOS_BUFFER tapeInfosBuffer + #define ADOLC_TAPE_STACK tapeStack + #define ADOLC_CURRENT_TAPE_INFOS currentTapeInfos + #define ADOLC_CURRENT_TAPE_INFOS_FALLBACK currentTapeInfos_fallBack + #define ADOLC_GLOBAL_TAPE_VARS globalTapeVars + #define ADOLC_EXT_DIFF_FCTS_BUFFER ADOLC_extDiffFctsBuffer + #define ADOLC_CHECKPOINTS_STACK ADOLC_checkpointsStack + #define REVOLVE_NUMBERS revolve_numbers + + #endif /* _OPENMP */ extern TapeInfos ADOLC_CURRENT_TAPE_INFOS_DECL; extern TapeInfos ADOLC_CURRENT_TAPE_INFOS_FALLBACK_DECL; @@ -426,13 +421,13 @@ TapeInfos *getTapeInfos(short tapeID); /* updates the tape infos for the given ID - a tapeInfos struct is created * and registered if non is found but its state will remain "not in use" */ -#ifdef SPARSE + #ifdef SPARSE void setTapeInfoJacSparse(short tapeID, SparseJacInfos sJinfos); /* updates the tape infos on sparse Jac for the given ID */ void setTapeInfoHessSparse(short tapeID, SparseHessInfos sHinfos); -/* updates the tape infos n sparse Hess for the given ID */ -#endif + /* updates the tape infos n sparse Hess for the given ID */ + #endif void take_stock(); /* record all existing adoubles on the tape @@ -457,7 +452,7 @@ void taylor_begin(uint bufferSize, int degreeSave); void taylor_close(bool resetData); /* close taylor file if necessary and refill buffer if possible */ -void taylor_back(short tag, int* dep, int* ind, int* degree); +void taylor_back(short tag, int *dep, int *ind, int *degree); /* initializes a reverse sweep */ void write_taylor(locint loc, int keep); @@ -470,12 +465,13 @@ void write_taylors(locint loc, int keep, int degree, int numDir); * the taylor buffer, if the buffer is filled, then it is written to the * taylor tape */ -#define ADOLC_WRITE_SCAYLOR(X) \ - {\ - if (ADOLC_CURRENT_TAPE_INFOS.currTay == ADOLC_CURRENT_TAPE_INFOS.lastTayP1)\ - put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1);\ - *ADOLC_CURRENT_TAPE_INFOS.currTay = (X);\ - ++ADOLC_CURRENT_TAPE_INFOS.currTay;\ + #define ADOLC_WRITE_SCAYLOR(X) \ + { \ + if (ADOLC_CURRENT_TAPE_INFOS.currTay == \ + ADOLC_CURRENT_TAPE_INFOS.lastTayP1) \ + put_tay_block(ADOLC_CURRENT_TAPE_INFOS.lastTayP1); \ + *ADOLC_CURRENT_TAPE_INFOS.currTay = (X); \ + ++ADOLC_CURRENT_TAPE_INFOS.currTay; \ } /* writes a single element (x) to the taylor buffer and writes the buffer to * disk if necessary */ @@ -483,29 +479,30 @@ void write_taylors(locint loc, int keep, int degree, int numDir); void write_scaylors(revreal *x, uint size); /* write_scaylors writes # size elements from x to the taylor buffer */ -#define ADOLC_OVERWRITE_SCAYLOR(X,Y) \ - {\ - *Y = *(ADOLC_CURRENT_TAPE_INFOS.currTay - 1);\ - *(ADOLC_CURRENT_TAPE_INFOS.currTay - 1) = X;\ + #define ADOLC_OVERWRITE_SCAYLOR(X, Y) \ + { \ + *Y = *(ADOLC_CURRENT_TAPE_INFOS.currTay - 1); \ + *(ADOLC_CURRENT_TAPE_INFOS.currTay - 1) = X; \ } /* overwrites the last (single) element (x) of the taylor buffer */ -#define ADOLC_DELETE_SCAYLOR(X) \ - {\ - --ADOLC_CURRENT_TAPE_INFOS.currTay;\ - *X = *ADOLC_CURRENT_TAPE_INFOS.currTay;\ + #define ADOLC_DELETE_SCAYLOR(X) \ + { \ + --ADOLC_CURRENT_TAPE_INFOS.currTay; \ + *X = *ADOLC_CURRENT_TAPE_INFOS.currTay; \ } /* deletes the last (single) element (x) of the taylor buffer */ void put_tay_block(revreal *lastValP1); /* writes the taylor stack buffer onto hard disk */ -#define ADOLC_GET_TAYLOR(X) \ - {\ - if (ADOLC_CURRENT_TAPE_INFOS.currTay == ADOLC_CURRENT_TAPE_INFOS.tayBuffer)\ - get_tay_block_r();\ - --ADOLC_CURRENT_TAPE_INFOS.currTay;\ - ADOLC_CURRENT_TAPE_INFOS.rp_T[X] = *ADOLC_CURRENT_TAPE_INFOS.currTay;\ + #define ADOLC_GET_TAYLOR(X) \ + { \ + if (ADOLC_CURRENT_TAPE_INFOS.currTay == \ + ADOLC_CURRENT_TAPE_INFOS.tayBuffer) \ + get_tay_block_r(); \ + --ADOLC_CURRENT_TAPE_INFOS.currTay; \ + ADOLC_CURRENT_TAPE_INFOS.rp_T[X] = *ADOLC_CURRENT_TAPE_INFOS.currTay; \ } /* puts a taylor value from the value stack buffer to the taylor buffer */ @@ -520,8 +517,6 @@ void get_taylors_p(locint loc, int degree, int numDir); void get_tay_block_r(); /* gets the next (previous block) of the value stack */ - - void initTapeBuffers(); /* free/allocate memory for buffers, initialize pointers */ @@ -550,8 +545,6 @@ void init_rev_sweep(short tag); void end_sweep(); /* finish a forward or reverse sweep */ - - void fail(int error); /* outputs an appropriate error message using DIAG_OUT and exits the running * program */ @@ -562,12 +555,10 @@ void printError(); char *createFileName(short tapeID, int tapeType); /* create file name depending on tape type and number */ - - /* puts an operation into the operation buffer, ensures that location buffer * and constants buffer are prepared to take the belonging stuff */ void put_op_reserve(unsigned char op, unsigned int reserveExtraLocations); -#define put_op(i) put_op_reserve((i),0) + #define put_op(i) put_op_reserve((i), 0) void put_op_block(unsigned char *lastOpP1); /* writes a block of operations onto hard disk and handles file creation, @@ -579,10 +570,10 @@ void get_op_block_f(); void get_op_block_r(); /* reads the previous block of operations into the internal buffer */ -#define ADOLC_PUT_LOCINT(X) \ - {\ - *ADOLC_CURRENT_TAPE_INFOS.currLoc = X;\ - ++ADOLC_CURRENT_TAPE_INFOS.currLoc;\ + #define ADOLC_PUT_LOCINT(X) \ + { \ + *ADOLC_CURRENT_TAPE_INFOS.currLoc = X; \ + ++ADOLC_CURRENT_TAPE_INFOS.currLoc; \ } /* puts a single locations into the location buffer, no disk access */ @@ -596,10 +587,10 @@ void get_loc_block_f(); void get_loc_block_r(); /* reads the previous block of locations into the internal buffer */ -#define ADOLC_PUT_VAL(X) \ - {\ - *ADOLC_CURRENT_TAPE_INFOS.currVal = X;\ - ++ADOLC_CURRENT_TAPE_INFOS.currVal;\ + #define ADOLC_PUT_VAL(X) \ + { \ + *ADOLC_CURRENT_TAPE_INFOS.currVal = X; \ + ++ADOLC_CURRENT_TAPE_INFOS.currVal; \ } /* puts a single constant into the location buffer, no disk access */ @@ -631,8 +622,6 @@ double *get_val_v_r(locint size); /* return a pointer to the first element of a constants vector * -- Reverse Mode -- */ - - /* suspicious function, maybe for vector class - kept for compatibility */ void reset_val_r(); @@ -648,20 +637,19 @@ double make_nan(); double make_inf(); + #if !defined(ADOLC_HARDDEBUG) + /*--------------------------------------------------------------------------*/ + /* MACRO or FUNCTION + */ + #define get_op_f() *ADOLC_CURRENT_TAPE_INFOS.currOp++ + #define get_op_r() *--ADOLC_CURRENT_TAPE_INFOS.currOp + #define get_locint_f() *ADOLC_CURRENT_TAPE_INFOS.currLoc++ + #define get_locint_r() *--ADOLC_CURRENT_TAPE_INFOS.currLoc -#if !defined(ADOLC_HARDDEBUG) -/*--------------------------------------------------------------------------*/ -/* MACRO or FUNCTION */ -#define get_op_f() *ADOLC_CURRENT_TAPE_INFOS.currOp++ -#define get_op_r() *--ADOLC_CURRENT_TAPE_INFOS.currOp - -#define get_locint_f() *ADOLC_CURRENT_TAPE_INFOS.currLoc++ -#define get_locint_r() *--ADOLC_CURRENT_TAPE_INFOS.currLoc - -#define get_val_f() *ADOLC_CURRENT_TAPE_INFOS.currVal++ -#define get_val_r() *--ADOLC_CURRENT_TAPE_INFOS.currVal -#else /* HARDDEBUG */ + #define get_val_f() *ADOLC_CURRENT_TAPE_INFOS.currVal++ + #define get_val_r() *--ADOLC_CURRENT_TAPE_INFOS.currVal + #else /* HARDDEBUG */ unsigned char get_op_f(); unsigned char get_op_r(); @@ -670,7 +658,7 @@ locint get_locint_r(); double get_val_f(); double get_val_r(); -#endif + #endif /* tries to read a local config file containing, e.g., buffer sizes */ void readConfigFile(); @@ -692,7 +680,8 @@ void markNewTape(); /* Allows us to throw an exception instead of calling exit() in case of a */ /* irrecoverable error */ /****************************************************************************/ -void adolc_exit(int errorcode, const char *what, const char *function, const char* file, int line); +void adolc_exit(int errorcode, const char *what, const char *function, + const char *file, int line); /****************************************************************************/ /* Discards parameters from the end of value tape during reverse mode */ @@ -711,5 +700,3 @@ END_C_DECLS /****************************************************************************/ #endif /* ADOLC_TAPING_P_H */ - - diff --git a/ADOL-C/src/uni5_for.c b/ADOL-C/src/uni5_for.c index 9becf479d..aa8735c71 100644 --- a/ADOL-C/src/uni5_for.c +++ b/ADOL-C/src/uni5_for.c @@ -13,7 +13,8 @@ fov_forward (first-order-vector forward mode): define _FOV_ hov_forward (higher-order-vector forward mode): define _HOV_ hov_wk_forward (higher-order-vector forward mode): define _HOV_WK_ - int_forward_safe: define _INT_FOR_ and _NTIGHT__ + int_forward_safe: define _INT_FOR_ +and _NTIGHT__ Uses the preprocessor to compile the 7 different object files with/without "keep" parameter: define _KEEP_ @@ -21,7 +22,7 @@ Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel, Benjamin Letschert, Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. Any use, reproduction, or distribution of the software constitutes @@ -29,27 +30,27 @@ ----------------------------------------------------------------------------*/ -#include -#include -#include -#include "taping_p.h" +#include "dvlparms.h" +#include "externfcts_p.h" #include "oplate.h" +#include "taping_p.h" +#include #include -#include "externfcts_p.h" -#include "dvlparms.h" +#include +#include #include #include #if defined(ADOLC_DEBUG) || defined(_ZOS_) -#include + #include #endif /* ADOLC_DEBUG */ #ifdef ADOLC_MEDIPACK_SUPPORT -#include "medipacksupport_p.h" + #include "medipacksupport_p.h" #endif #ifdef ADOLC_AMPI_SUPPORT -#include "ampisupportAdolc.h" + #include "ampisupportAdolc.h" #endif /****************************************************************************/ @@ -57,93 +58,91 @@ #undef _ADOLC_VECTOR_ #undef _HIGHER_ORDER_ - - /*--------------------------------------------------------------------------*/ #if defined(_ZOS_) -# if defined(_ABS_NORM_) -# define GENERATED_FILENAME "zos_pl_forward" -# elif defined(_ABS_NORM_SIG_) -# define GENERATED_FILENAME "zos_pl_sig_forward" -# else -# define GENERATED_FILENAME "zos_forward" -# endif + #if defined(_ABS_NORM_) + #define GENERATED_FILENAME "zos_pl_forward" + #elif defined(_ABS_NORM_SIG_) + #define GENERATED_FILENAME "zos_pl_sig_forward" + #else + #define GENERATED_FILENAME "zos_forward" + #endif /*--------------------------------------------------------------------------*/ #elif defined(_FOS_) -# if defined(_ABS_NORM_) -# define GENERATED_FILENAME "fos_pl_forward" -# elif defined(_ABS_NORM_SIG_) -# define GENERATED_FILENAME "fos_pl_sig_forward" -# else -# define GENERATED_FILENAME "fos_forward" -# endif + #if defined(_ABS_NORM_) + #define GENERATED_FILENAME "fos_pl_forward" + #elif defined(_ABS_NORM_SIG_) + #define GENERATED_FILENAME "fos_pl_sig_forward" + #else + #define GENERATED_FILENAME "fos_forward" + #endif -# define ARGUMENT(indexi,l,i) argument[indexi] -# define TAYLORS(indexd,l,i) taylors[indexd] + #define ARGUMENT(indexi, l, i) argument[indexi] + #define TAYLORS(indexd, l, i) taylors[indexd] /*--------------------------------------------------------------------------*/ #elif defined(_FOV_) -# if defined(_ABS_NORM_) -# define GENERATED_FILENAME "fov_pl_forward" -# elif defined(_ABS_NORM_SIG_) -# define GENERATED_FILENAME "fov_pl_sig_forward" -# if defined(_MSC_VER) && _MSC_VER < 180 -# define fmin __min -# define fmax __max -# endif -# else -# define GENERATED_FILENAME "fov_forward" -# endif - -# define _ADOLC_VECTOR_ - -# if defined(_CHUNKED_) -# define ARGUMENT(indexi,l,i) argument[indexi][l+offset] -# define TAYLORS(indexd,l,i) taylors[indexd][l+offset] -# else -# define ARGUMENT(indexi,l,i) argument[indexi][l] -# define TAYLORS(indexd,l,i) taylors[indexd][l] -# endif + #if defined(_ABS_NORM_) + #define GENERATED_FILENAME "fov_pl_forward" + #elif defined(_ABS_NORM_SIG_) + #define GENERATED_FILENAME "fov_pl_sig_forward" + #if defined(_MSC_VER) && _MSC_VER < 180 + #define fmin __min + #define fmax __max + #endif + #else + #define GENERATED_FILENAME "fov_forward" + #endif + + #define _ADOLC_VECTOR_ + + #if defined(_CHUNKED_) + #define ARGUMENT(indexi, l, i) argument[indexi][l + offset] + #define TAYLORS(indexd, l, i) taylors[indexd][l + offset] + #else + #define ARGUMENT(indexi, l, i) argument[indexi][l] + #define TAYLORS(indexd, l, i) taylors[indexd][l] + #endif /*--------------------------------------------------------------------------*/ #elif defined(_HOS_) -# define GENERATED_FILENAME "hos_forward" + #define GENERATED_FILENAME "hos_forward" -# define _HIGHER_ORDER_ + #define _HIGHER_ORDER_ -# define ARGUMENT(indexi,l,i) argument[indexi][i] -# define TAYLORS(indexd,l,i) taylors[indexd][i] + #define ARGUMENT(indexi, l, i) argument[indexi][i] + #define TAYLORS(indexd, l, i) taylors[indexd][i] /*--------------------------------------------------------------------------*/ #elif defined(_HOV_) -# define GENERATED_FILENAME "hov_forward" + #define GENERATED_FILENAME "hov_forward" -# define _ADOLC_VECTOR_ -# define _HIGHER_ORDER_ + #define _ADOLC_VECTOR_ + #define _HIGHER_ORDER_ -# define ARGUMENT(indexi,l,i) argument[indexi][l][i] -# define TAYLORS(indexd,l,i) taylors[indexd][l][i] + #define ARGUMENT(indexi, l, i) argument[indexi][l][i] + #define TAYLORS(indexd, l, i) taylors[indexd][l][i] /*--------------------------------------------------------------------------*/ #elif defined(_HOV_WK_) -# define GENERATED_FILENAME "hov_wk_forward" + #define GENERATED_FILENAME "hov_wk_forward" -# define _ADOLC_VECTOR_ -# define _HIGHER_ORDER_ + #define _ADOLC_VECTOR_ + #define _HIGHER_ORDER_ -# define ARGUMENT(indexi,l,i) argument[indexi][l][i] -# define TAYLORS(indexd,l,i) taylors[indexd][l][i] + #define ARGUMENT(indexi, l, i) argument[indexi][l][i] + #define TAYLORS(indexd, l, i) taylors[indexd][l][i] /*--------------------------------------------------------------------------*/ #elif defined(_INT_FOR_) -# if defined(_TIGHT_) -# define GENERATED_FILENAME "int_forward_t" -# endif -# if defined(_NTIGHT_) -# define GENERATED_FILENAME "int_forward_s" -# endif -# define ARGUMENT(indexi,l,i) argument[indexi][l] -# define TAYLORS(indexd,l,i) taylors[indexd][l] + #if defined(_TIGHT_) + #define GENERATED_FILENAME "int_forward_t" + #endif + #if defined(_NTIGHT_) + #define GENERATED_FILENAME "int_forward_s" + #endif + #define ARGUMENT(indexi, l, i) argument[indexi][l] + #define TAYLORS(indexd, l, i) taylors[indexd][l] /*--------------------------------------------------------------------------*/ #elif defined(_INDO_) void copy_index_domain(int res, int arg, locint **ind_dom); @@ -151,73 +150,71 @@ void merge_2_index_domains(int res, int arg, locint **ind_dom); void combine_2_index_domains(int res, int arg1, int arg2, locint **ind_dom); void merge_3_index_domains(int res, int arg1, int arg2, locint **ind_dom); -# define NUMNNZ 20 -# define FMIN_ADOLC(x,y) ((y 1) \ - write_taylors(res,(keep-1),k,p); \ - } \ - } -#else -#if defined(_ADOLC_VECTOR_) /* otherwise no keep */ -#define IF_KEEP_TAYLOR_CLOSE -#define IF_KEEP_WRITE_TAYLOR(res,keep,k,p) -#else /* _ZOS_, _FOS_, _HOS_ */ -#define IF_KEEP_TAYLOR_CLOSE \ -if (keep){\ - fprintf(DIAG_OUT,"Otherwise succeeding reverse sweep will fail!\n");\ - taylor_close(false);\ -} -#if defined(_ZOS_) -#define IF_KEEP_WRITE_TAYLOR(res,keep,k,p) \ - { \ - UPDATE_TAYLORWRITTEN(keep) \ - if (keep) \ - ADOLC_WRITE_SCAYLOR(dp_T0[res]); \ - } -#else -#if defined(_FOS_) -#define IF_KEEP_WRITE_TAYLOR(res,keep,k,p) \ - { \ - UPDATE_TAYLORWRITTEN(keep) \ - if (keep) \ - { \ - ADOLC_WRITE_SCAYLOR(dp_T0[res]); \ - if (keep > 1) \ - ADOLC_WRITE_SCAYLOR(dp_T[res]); \ - } \ - } -#else -#if defined(_HOS_) -#define IF_KEEP_WRITE_TAYLOR(res,keep,k,p) \ - { \ - UPDATE_TAYLORWRITTEN(keep) \ - if (keep) \ - { \ - ADOLC_WRITE_SCAYLOR(dp_T0[res]); \ - if (keep > 1) \ - write_taylor(res,keep-1); \ - } \ - } -#endif -#endif -#endif -#endif -#endif + #if defined(_HOV_WK_) /* keep in this vector mode */ + #define IF_KEEP_TAYLOR_CLOSE \ + if (keep) { \ + fprintf(DIAG_OUT, "Succeeding reverse sweep will fail!\n"); \ + taylor_close(false); \ + } + #define IF_KEEP_WRITE_TAYLOR(res, keep, k, p) \ + { \ + UPDATE_TAYLORWRITTEN(keep *k *p) \ + if (keep) { \ + ADOLC_WRITE_SCAYLOR(dp_T0[res]); \ + if (keep > 1) \ + write_taylors(res, (keep - 1), k, p); \ + } \ + } + #else + #if defined(_ADOLC_VECTOR_) /* otherwise no keep */ + #define IF_KEEP_TAYLOR_CLOSE + #define IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + #else /* _ZOS_, _FOS_, _HOS_ */ + #define IF_KEEP_TAYLOR_CLOSE \ + if (keep) { \ + fprintf(DIAG_OUT, \ + "Otherwise succeeding reverse sweep will fail!\n"); \ + taylor_close(false); \ + } + #if defined(_ZOS_) + #define IF_KEEP_WRITE_TAYLOR(res, keep, k, p) \ + { \ + UPDATE_TAYLORWRITTEN(keep) \ + if (keep) \ + ADOLC_WRITE_SCAYLOR(dp_T0[res]); \ + } + #else + #if defined(_FOS_) + #define IF_KEEP_WRITE_TAYLOR(res, keep, k, p) \ + { \ + UPDATE_TAYLORWRITTEN(keep) \ + if (keep) { \ + ADOLC_WRITE_SCAYLOR(dp_T0[res]); \ + if (keep > 1) \ + ADOLC_WRITE_SCAYLOR(dp_T[res]); \ + } \ + } + #else + #if defined(_HOS_) + #define IF_KEEP_WRITE_TAYLOR(res, keep, k, p) \ + { \ + UPDATE_TAYLORWRITTEN(keep) \ + if (keep) { \ + ADOLC_WRITE_SCAYLOR(dp_T0[res]); \ + if (keep > 1) \ + write_taylor(res, keep - 1); \ + } \ + } + #endif + #endif + #endif + #endif + #endif -#else /* no _KEEP_ */ -#define IF_KEEP_TAYLOR_CLOSE -#define IF_KEEP_WRITE_TAYLOR(res,keep,k,p) +#else /* no _KEEP_ */ + #define IF_KEEP_TAYLOR_CLOSE + #define IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #endif /*--------------------------------------------------------------------------*/ /* access to variables */ #if !defined(_ZOS_) -#if defined(_FOS_) -#define TRES *Tres -#define TARG *Targ -#define TARG1 *Targ1 -#define TARG2 *Targ2 -#define TQO *Tqo - -#define TRES_INC *Tres -#define TARG_INC *Targ -#define TARG1_INC *Targ1 -#define TARG2_INC *Targ2 -#define TQO_INC *Tqo - -#define TRES_DEC *Tres -#define TARG_DEC *Targ -#define TARG1_DEC *Targ1 -#define TARG2_DEC *Targ2 -#define TQO_DEC *Tqo - -#define TRES_FOINC *Tres -#define TARG_FOINC *Targ -#define TARG1_FOINC *Targ1 -#define TARG2_FOINC *Targ2 -#define TQO_FOINC *Tqo - -#define TRES_FODEC *Tres -#define DEC_TRES_FO -#define TARG_FODEC *Targ -#define TARG1_FODEC *Targ1 -#define TARG2_FODEC *Targ2 -#define TQO_FODEC *Tqo - -#define ASSIGN_T(a,b) a = &b; - -#else -#if defined(_INT_FOR_) -#define TRES *Tres -#define TARG *Targ -#define TARG1 *Targ1 -#define TARG2 *Targ2 -#define TQO *Tqo - -#define TRES_INC *Tres++ -#define TARG_INC *Targ++ -#define TARG1_INC *Targ1++ -#define TARG2_INC *Targ2++ -#define TQO_INC *Tqo++ - -#define TRES_DEC *Tres-- -#define TARG_DEC *Targ-- -#define TARG1_DEC *Targ1-- -#define TARG2_DEC *Targ2-- -#define TQO_DEC *Tqo-- - -#define TRES_FOINC *Tres++ -#define TARG_FOINC *Targ++ -#define TARG1_FOINC *Targ1++ -#define TARG2_FOINC *Targ2++ -#define TQO_FOINC *Tqo++ - -#define TRES_FODEC *Tres-- -#define TARG_FODEC *Targ-- -#define TARG1_FODEC *Targ1-- -#define TARG2_FODEC *Targ2-- -#define TQO_FODEC *Tqo-- - - -#define ASSIGN_T(a,b) a = b; - -#else /* _HOS_, _FOV_, _HOV_, _HOV_WK */ -#define TRES *Tres -#define TARG *Targ -#define TARG1 *Targ1 -#define TARG2 *Targ2 -#define TQO *Tqo - -#define TRES_INC *Tres++ -#define TARG_INC *Targ++ -#define TARG1_INC *Targ1++ -#define TARG2_INC *Targ2++ -#define TQO_INC *Tqo++ - -#define TRES_DEC *Tres-- -#define TARG_DEC *Targ-- -#define TARG1_DEC *Targ1-- -#define TARG2_DEC *Targ2-- -#define TQO_DEC *Tqo-- - -#if defined(_FOV_) -#define TRES_FOINC *Tres++ -#define TARG_FOINC *Targ++ -#define TARG1_FOINC *Targ1++ -#define TARG2_FOINC *Targ2++ -#define TQO_FOINC *Tqo++ - -#define TRES_FODEC *Tres -#define DEC_TRES_FO Tres--; -#define TARG_FODEC *Targ-- -#define TARG1_FODEC *Targ1-- -#define TARG2_FODEC *Targ2-- -#define TQO_FODEC *Tqo-- -#else /* _HOS_, _HOV_, _HOV_WK */ -#define TRES_FOINC *Tres -#define TARG_FOINC *Targ -#define TARG1_FOINC *Targ1 -#define TARG2_FOINC *Targ2 -#define TQO_FOINC *Tqo - -#define TRES_FODEC *Tres -#define DEC_TRES_FO -#define TARG_FODEC *Targ -#define TARG1_FODEC *Targ1 -#define TARG2_FODEC *Targ2 -#define TQO_FODEC *Tqo -#endif -#endif - -#define ASSIGN_T(a,b) a = b; -#endif + #if defined(_FOS_) + #define TRES *Tres + #define TARG *Targ + #define TARG1 *Targ1 + #define TARG2 *Targ2 + #define TQO *Tqo + + #define TRES_INC *Tres + #define TARG_INC *Targ + #define TARG1_INC *Targ1 + #define TARG2_INC *Targ2 + #define TQO_INC *Tqo + + #define TRES_DEC *Tres + #define TARG_DEC *Targ + #define TARG1_DEC *Targ1 + #define TARG2_DEC *Targ2 + #define TQO_DEC *Tqo + + #define TRES_FOINC *Tres + #define TARG_FOINC *Targ + #define TARG1_FOINC *Targ1 + #define TARG2_FOINC *Targ2 + #define TQO_FOINC *Tqo + + #define TRES_FODEC *Tres + #define DEC_TRES_FO + #define TARG_FODEC *Targ + #define TARG1_FODEC *Targ1 + #define TARG2_FODEC *Targ2 + #define TQO_FODEC *Tqo + + #define ASSIGN_T(a, b) a = &b; + + #else + #if defined(_INT_FOR_) + #define TRES *Tres + #define TARG *Targ + #define TARG1 *Targ1 + #define TARG2 *Targ2 + #define TQO *Tqo + + #define TRES_INC *Tres++ + #define TARG_INC *Targ++ + #define TARG1_INC *Targ1++ + #define TARG2_INC *Targ2++ + #define TQO_INC *Tqo++ + + #define TRES_DEC *Tres-- + #define TARG_DEC *Targ-- + #define TARG1_DEC *Targ1-- + #define TARG2_DEC *Targ2-- + #define TQO_DEC *Tqo-- + + #define TRES_FOINC *Tres++ + #define TARG_FOINC *Targ++ + #define TARG1_FOINC *Targ1++ + #define TARG2_FOINC *Targ2++ + #define TQO_FOINC *Tqo++ + + #define TRES_FODEC *Tres-- + #define TARG_FODEC *Targ-- + #define TARG1_FODEC *Targ1-- + #define TARG2_FODEC *Targ2-- + #define TQO_FODEC *Tqo-- + + #define ASSIGN_T(a, b) a = b; + + #else /* _HOS_, _FOV_, _HOV_, _HOV_WK */ + #define TRES *Tres + #define TARG *Targ + #define TARG1 *Targ1 + #define TARG2 *Targ2 + #define TQO *Tqo + + #define TRES_INC *Tres++ + #define TARG_INC *Targ++ + #define TARG1_INC *Targ1++ + #define TARG2_INC *Targ2++ + #define TQO_INC *Tqo++ + + #define TRES_DEC *Tres-- + #define TARG_DEC *Targ-- + #define TARG1_DEC *Targ1-- + #define TARG2_DEC *Targ2-- + #define TQO_DEC *Tqo-- + + #if defined(_FOV_) + #define TRES_FOINC *Tres++ + #define TARG_FOINC *Targ++ + #define TARG1_FOINC *Targ1++ + #define TARG2_FOINC *Targ2++ + #define TQO_FOINC *Tqo++ + + #define TRES_FODEC *Tres + #define DEC_TRES_FO Tres--; + #define TARG_FODEC *Targ-- + #define TARG1_FODEC *Targ1-- + #define TARG2_FODEC *Targ2-- + #define TQO_FODEC *Tqo-- + #else /* _HOS_, _HOV_, _HOV_WK */ + #define TRES_FOINC *Tres + #define TARG_FOINC *Targ + #define TARG1_FOINC *Targ1 + #define TARG2_FOINC *Targ2 + #define TQO_FOINC *Tqo + + #define TRES_FODEC *Tres + #define DEC_TRES_FO + #define TARG_FODEC *Targ + #define TARG1_FODEC *Targ1 + #define TARG2_FODEC *Targ2 + #define TQO_FODEC *Tqo + #endif + #endif + + #define ASSIGN_T(a, b) a = b; + #endif #endif - /*--------------------------------------------------------------------------*/ /* loop stuff */ #if defined(_ADOLC_VECTOR_) -#define FOR_0_LE_l_LT_p for (int l=0; l=0; l--) -#if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) -#define FIRSTSIGN_P(x,y) firstsign(p,&(x),y) -#define COPYTAYL_P(x,y) FOR_0_LE_l_LT_p x[l] = y[l] -#define EXT_FIRSTSIGN_P(sigx,sigd,x,y) ext_firstsign(sigx,sigd,p,&(x),y) -#define EXT_FIRSTSIGN2_P(sigx,x,y) ext_firstsign2(sigx,p,&(x),y) -#endif -#else -#if defined(_INT_FOR_) -#define FOR_0_LE_l_LT_p for (int l=0; l=0; l--) -#else -#define FOR_0_LE_l_LT_p -#define FOR_p_GT_l_GE_0 -#if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) -#define FIRSTSIGN_P(x,y) firstsign(1,&(x),y) -#define COPYTAYL_P(x,y) x = *y -#define EXT_FIRSTSIGN_P(sigx,sigd,x,y) ext_firstsign(sigx,sigd,1,&(x),y) -#define EXT_FIRSTSIGN2_P(sigx,x,y) ext_firstsign2(sigx,1,&(x),y) -#endif -#endif + #define FOR_0_LE_l_LT_p for (int l = 0; l < p; l++) + #define FOR_p_GT_l_GE_0 for (int l = p - 1; l >= 0; l--) + #if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) + #define FIRSTSIGN_P(x, y) firstsign(p, &(x), y) + #define COPYTAYL_P(x, y) FOR_0_LE_l_LT_p x[l] = y[l] + #define EXT_FIRSTSIGN_P(sigx, sigd, x, y) \ + ext_firstsign(sigx, sigd, p, &(x), y) + #define EXT_FIRSTSIGN2_P(sigx, x, y) ext_firstsign2(sigx, p, &(x), y) + #endif +#else + #if defined(_INT_FOR_) + #define FOR_0_LE_l_LT_p for (int l = 0; l < p; l++) + #define FOR_p_GT_l_GE_0 for (int l = p - 1; l >= 0; l--) + #else + #define FOR_0_LE_l_LT_p + #define FOR_p_GT_l_GE_0 + #if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) + #define FIRSTSIGN_P(x, y) firstsign(1, &(x), y) + #define COPYTAYL_P(x, y) x = *y + #define EXT_FIRSTSIGN_P(sigx, sigd, x, y) \ + ext_firstsign(sigx, sigd, 1, &(x), y) + #define EXT_FIRSTSIGN2_P(sigx, x, y) ext_firstsign2(sigx, 1, &(x), y) + #endif + #endif #endif #if defined(_HIGHER_ORDER_) -#define FOR_0_LE_i_LT_k for (int i=0; i=0; i--) + #define FOR_0_LE_i_LT_k for (int i = 0; i < k; i++) + #define FOR_k_GT_i_GE_0 for (int i = k - 1; i >= 0; i--) #else -#define FOR_0_LE_i_LT_k for (int i=0; i<1; i++) -#define FOR_k_GT_i_GE_0 for (int i=0; i>=0; i--) + #define FOR_0_LE_i_LT_k for (int i = 0; i < 1; i++) + #define FOR_k_GT_i_GE_0 for (int i = 0; i >= 0; i--) #endif #if defined(_HOV_) -# define FOR_0_LE_l_LT_pk for (int l=0; ldp_x, m, edfct->dp_y) -# define ADOLC_EXT_FCT_IARR_COMPLETE \ + #define _EXTERN_ 1 + #define ADOLC_EXT_FCT_POINTER zos_forward + #define ADOLC_EXT_FCT_IARR_POINTER zos_forward_iArr + #define ADOLC_EXT_FCT_COMPLETE zos_forward(n, edfct->dp_x, m, edfct->dp_y) + #define ADOLC_EXT_FCT_IARR_COMPLETE \ zos_forward_iArr(iArrLength, iArr, n, edfct->dp_x, m, edfct->dp_y) -# define ADOLC_EXT_FCT_V2_COMPLETE \ - zos_forward(iArrLength, iArr, nin, nout, (int*)insz, edfct2->x, (int*)outsz, edfct2->y, edfct2->context) -# define ADOLC_EXT_COPY_TAYLORS(dest,src) + #define ADOLC_EXT_FCT_V2_COMPLETE \ + zos_forward(iArrLength, iArr, nin, nout, (int *)insz, edfct2->x, \ + (int *)outsz, edfct2->y, edfct2->context) + #define ADOLC_EXT_COPY_TAYLORS(dest, src) #endif - /* FOS_FORWARD */ + /* FOS_FORWARD */ #if defined(_FOS_) -# define _EXTERN_ 1 -# define ADOLC_EXT_FCT_POINTER fos_forward -# define ADOLC_EXT_FCT_IARR_POINTER fos_forward_iArr -# define ADOLC_EXT_FCT_COMPLETE \ + #define _EXTERN_ 1 + #define ADOLC_EXT_FCT_POINTER fos_forward + #define ADOLC_EXT_FCT_IARR_POINTER fos_forward_iArr + #define ADOLC_EXT_FCT_COMPLETE \ fos_forward(n, edfct->dp_x, edfct->dp_X, m, edfct->dp_y, edfct->dp_Y) -# define ADOLC_EXT_FCT_IARR_COMPLETE \ - fos_forward_iArr(iArrLength, iArr, n, edfct->dp_x, edfct->dp_X, m, edfct->dp_y, edfct->dp_Y) -# define ADOLC_EXT_POINTER_X edfct->dp_X -# define ADOLC_EXT_POINTER_Y edfct->dp_Y -# define ADOLC_EXT_FCT_V2_COMPLETE \ - fos_forward(iArrLength, iArr, nin, nout, (int*)insz, edfct2->x, edfct2->xp, (int*)outsz, edfct2->y, edfct2->yp, edfct2->context) -# define ADOLC_EXT_V2_POINTER_X edfct2->xp -# define ADOLC_EXT_V2_POINTER_Y edfct2->yp -# define ADOLC_EXT_COPY_TAYLORS(dest,src) dest=src -# define ADOLC_EXT_COPY_TAYLORS_BACK(dest,src) src=dest -#endif - /* FOV_FORWARD */ + #define ADOLC_EXT_FCT_IARR_COMPLETE \ + fos_forward_iArr(iArrLength, iArr, n, edfct->dp_x, edfct->dp_X, m, \ + edfct->dp_y, edfct->dp_Y) + #define ADOLC_EXT_POINTER_X edfct->dp_X + #define ADOLC_EXT_POINTER_Y edfct->dp_Y + #define ADOLC_EXT_FCT_V2_COMPLETE \ + fos_forward(iArrLength, iArr, nin, nout, (int *)insz, edfct2->x, \ + edfct2->xp, (int *)outsz, edfct2->y, edfct2->yp, \ + edfct2->context) + #define ADOLC_EXT_V2_POINTER_X edfct2->xp + #define ADOLC_EXT_V2_POINTER_Y edfct2->yp + #define ADOLC_EXT_COPY_TAYLORS(dest, src) dest = src + #define ADOLC_EXT_COPY_TAYLORS_BACK(dest, src) src = dest +#endif + /* FOV_FORWARD */ #if defined(_FOV_) -# define _EXTERN_ 1 -# define ADOLC_EXT_FCT_POINTER fov_forward -# define ADOLC_EXT_FCT_IARR_POINTER fov_forward_iArr -# define ADOLC_EXT_FCT_COMPLETE \ - fov_forward(n, edfct->dp_x,p, edfct->dpp_X, m, edfct->dp_y, edfct->dpp_Y) -# define ADOLC_EXT_FCT_IARR_COMPLETE \ - fov_forward_iArr(iArrLength, iArr, n, edfct->dp_x,p, edfct->dpp_X, m, edfct->dp_y, edfct->dpp_Y) -# define ADOLC_EXT_POINTER_X edfct->dpp_X -# define ADOLC_EXT_POINTER_Y edfct->dpp_Y -# define ADOLC_EXT_FCT_V2_COMPLETE \ - fov_forward(iArrLength, iArr, nin, nout, (int*)insz, edfct2->x, p, edfct2->Xp, (int*)outsz, edfct2->y, edfct2->Yp, edfct2->context) -# define ADOLC_EXT_V2_POINTER_X edfct2->Xp -# define ADOLC_EXT_V2_POINTER_Y edfct2->Yp -# define ADOLC_EXT_COPY_TAYLORS(dest,src) dest=src -# define ADOLC_EXT_COPY_TAYLORS_BACK(dest,src) + #define _EXTERN_ 1 + #define ADOLC_EXT_FCT_POINTER fov_forward + #define ADOLC_EXT_FCT_IARR_POINTER fov_forward_iArr + #define ADOLC_EXT_FCT_COMPLETE \ + fov_forward(n, edfct->dp_x, p, edfct->dpp_X, m, edfct->dp_y, edfct->dpp_Y) + #define ADOLC_EXT_FCT_IARR_COMPLETE \ + fov_forward_iArr(iArrLength, iArr, n, edfct->dp_x, p, edfct->dpp_X, m, \ + edfct->dp_y, edfct->dpp_Y) + #define ADOLC_EXT_POINTER_X edfct->dpp_X + #define ADOLC_EXT_POINTER_Y edfct->dpp_Y + #define ADOLC_EXT_FCT_V2_COMPLETE \ + fov_forward(iArrLength, iArr, nin, nout, (int *)insz, edfct2->x, p, \ + edfct2->Xp, (int *)outsz, edfct2->y, edfct2->Yp, \ + edfct2->context) + #define ADOLC_EXT_V2_POINTER_X edfct2->Xp + #define ADOLC_EXT_V2_POINTER_Y edfct2->Yp + #define ADOLC_EXT_COPY_TAYLORS(dest, src) dest = src + #define ADOLC_EXT_COPY_TAYLORS_BACK(dest, src) #endif #if defined(_EXTERN_) - locint n, m; - ext_diff_fct *edfct; - ext_diff_fct_v2 *edfct2; - int loop,oloop; - int iArrLength; - int *iArr; - int ext_retc; - int nin, nout; - locint *insz, *outsz; + locint n, m; + ext_diff_fct *edfct; + ext_diff_fct_v2 *edfct2; + int loop, oloop; + int iArrLength; + int *iArr; + int ext_retc; + int nin, nout; + locint *insz, *outsz; #endif #if defined(_ABS_NORM_) - short sig; + short sig; #endif #ifdef ADOLC_AMPI_SUPPORT - MPI_Op op; - void *buf, *rbuf; - int count, rcount; - MPI_Datatype datatype, rtype; - int src; - int tag; - enum AMPI_PairedWith_E pairedWith; - MPI_Comm comm; - MPI_Status status; - struct AMPI_Request_S request; + MPI_Op op; + void *buf, *rbuf; + int count, rcount; + MPI_Datatype datatype, rtype; + int src; + int tag; + enum AMPI_PairedWith_E pairedWith; + MPI_Comm comm; + MPI_Status status; + struct AMPI_Request_S request; #endif - locint qq; + locint qq; - ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_THREAD_NUMBER; #if defined(ADOLC_DEBUG) - /****************************************************************************/ - /* DEBUG MESSAGES */ - fprintf(DIAG_OUT,"Call of %s(..) with tag: %d, n: %d, m %d,\n", - GENERATED_FILENAME, tnum, indcheck, depcheck); -#if defined(_KEEP_) - fprintf(DIAG_OUT," keep: %d\n", keep); -#endif -#if defined(_HIGHER_ORDER_) - fprintf(DIAG_OUT," degree: %d\n",gdegree); -#endif -#if defined(_ADOLC_VECTOR_) - fprintf(DIAG_OUT," p: %d\n\n",p); -#endif - -#endif + /****************************************************************************/ + /* DEBUG MESSAGES */ + fprintf(DIAG_OUT, "Call of %s(..) with tag: %d, n: %d, m %d,\n", + GENERATED_FILENAME, tnum, indcheck, depcheck); + #if defined(_KEEP_) + fprintf(DIAG_OUT, " keep: %d\n", keep); + #endif + #if defined(_HIGHER_ORDER_) + fprintf(DIAG_OUT, " degree: %d\n", gdegree); + #endif + #if defined(_ADOLC_VECTOR_) + fprintf(DIAG_OUT, " p: %d\n\n", p); + #endif + +#endif + + /****************************************************************************/ + /* INITs */ + + /* Set up stuff for the tape */ + ADOLC_OPENMP_GET_THREAD_NUMBER; + + /* Initialize the Forward Sweep */ + + init_for_sweep(tnum); + + if ((depcheck != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS]) || + (indcheck != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS])) { + fprintf(DIAG_OUT, + "ADOL-C error: forward sweep on tape %d aborted!\n" + "Number of dependent(%u) and/or independent(%u) variables passed" + " to forward is\ninconsistent with number " + "recorded on tape (%zu, %zu) \n", + tnum, depcheck, indcheck, + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS], + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } +#if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) + if (!ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) { + fprintf(DIAG_OUT, + "ADOL-C error: tape %d was not created compatible " + "with %s\n Please call enableMinMaxUsingAbs() " + "before trace_on(%d)\n", + tnum, __FUNCTION__, tnum); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + #if defined(_ABS_NORM_SIG_) || defined(_INDOPRO_) + if (swcheck != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]) { + fprintf(DIAG_OUT, + "ADOL-C error: forward sweep on tape %d aborted!\n" + "Number of switches(%u) passed" + " to forward is\ninconsistent with number " + "recorded on tape (%zu) \n", + tnum, swcheck, ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + #endif +#endif + /****************************************************************************/ + /* MEMORY ALLOCATION */ + /* olvo 980626 has to be revised for common blocks */ + + /*--------------------------------------------------------------------------*/ +#if !defined(_NTIGHT_) + dp_T0 = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); + ADOLC_CURRENT_TAPE_INFOS.dp_T0 = dp_T0; + + if (ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) { + if (ADOLC_CURRENT_TAPE_INFOS.signature == NULL) { + signature = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]); + ADOLC_CURRENT_TAPE_INFOS.signature = signature; + } else + signature = ADOLC_CURRENT_TAPE_INFOS.signature; + } + + ADOLC_CURRENT_TAPE_INFOS.dpp_T = &dp_T0; + ADOLC_CURRENT_TAPE_INFOS.numTay = 0; + ADOLC_CURRENT_TAPE_INFOS.gDegree = 0; + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_ZOS_FORWARD; +#endif /* !_NTIGHT_ */ +#if defined(_ZOS_) /* ZOS */ + + #if defined(_KEEP_) + if (keep > 1) { + fprintf(DIAG_OUT, "\n ADOL-C error: zero order scalar forward cannot save" + " more\nthan zero order taylor coefficients!\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + #endif + #if defined(_KEEP_) + if (keep) { + const size_t taylbuf = ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; + + taylor_begin(taylbuf, keep - 1); + } + #endif + + /*--------------------------------------------------------------------------*/ +#else /* FOS */ + #if defined(_FOS_) + #if defined(_KEEP_) + if (keep > 2) { + fprintf(DIAG_OUT, "\n ADOL-C error: first order scalar forward cannot save" + " more \nthan first order taylor coefficients!\n"); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + #endif + dp_T = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); + ADOLC_CURRENT_TAPE_INFOS.dpp_T = &dp_T; + ADOLC_CURRENT_TAPE_INFOS.numTay = 1; + ADOLC_CURRENT_TAPE_INFOS.gDegree = 1; + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOS_FORWARD; + #define TAYLOR_BUFFER dp_T + #if defined(_KEEP_) + if (keep) { + const size_t taylbuf = ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; + taylor_begin(taylbuf, keep - 1); + } + #endif - /****************************************************************************/ - /* INITs */ + /*--------------------------------------------------------------------------*/ + #else /* INF_FOR */ + #if defined(_INT_FOR_) + up_T = myalloc2_ulong(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p); + #define TAYLOR_BUFFER up_T + + /*--------------------------------------------------------------------------*/ + #else /* INDOPRO */ + #if defined(_INDO_) + #if defined(_INDOPRO_) + /* index domains */ + ind_dom = (locint **)malloc(sizeof(locint *) * + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); + max_ind_dom = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; + + for (int i = 0; i < max_ind_dom; i++) { + ind_dom[i] = (locint *)malloc(sizeof(locint) * (NUMNNZ + 2)); + ind_dom[i][0] = 0; + ind_dom[i][1] = NUMNNZ; + } + #if defined(_ABS_NORM_) + indexd = swcheck; + #endif + #endif + #if defined(_NONLIND_) + maxopind = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_OPERATIONS] + + ADOLC_CURRENT_TAPE_INFOS.stats[NUM_EQ_PROD]; + fod = (struct IndexElement *)malloc(sizeof(struct IndexElement) * maxopind); + nonl_dom = + (struct IndexElement *)malloc(sizeof(struct IndexElement) * indcheck); + arg_index = (locint *)malloc(sizeof(locint) * + (ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES])); + opind = 0; + sod = (struct IndexElement_sod *)malloc(sizeof(struct IndexElement_sod) * + indcheck); + + for (int i = 0; i < indcheck; i++) { + sod[i].entry = 0; + sod[i].left = NULL; + nonl_dom[i].entry = indcheck + 2; + nonl_dom[i].left = NULL; + nonl_dom[i].right = NULL; + } + #endif + #if defined(_NONLIND_OLD_) + + nonl_dom = (locint **)malloc(sizeof(locint *) * indcheck); + for (int i = 0; i < indcheck; i++) { + nonl_dom[i] = (locint *)malloc(sizeof(locint) * (NUMNNZ + 2)); + nonl_dom[i][0] = 0; + nonl_dom[i][1] = NUMNNZ; + } + #endif + + /*--------------------------------------------------------------------------*/ + #else /* FOV */ + #if defined(_FOV_) + dpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p); + ADOLC_CURRENT_TAPE_INFOS.dpp_T = dpp_T; + ADOLC_CURRENT_TAPE_INFOS.numTay = p; + ADOLC_CURRENT_TAPE_INFOS.gDegree = 1; + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOV_FORWARD; + #define TAYLOR_BUFFER dpp_T + dp_Ttemp = myalloc1(p); + #define T_TEMP dp_Ttemp; + + /*--------------------------------------------------------------------------*/ + #else /* HOS */ + #if defined(_HOS_) + dpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], k); + ADOLC_CURRENT_TAPE_INFOS.dpp_T = dpp_T; + ADOLC_CURRENT_TAPE_INFOS.numTay = 1; + ADOLC_CURRENT_TAPE_INFOS.gDegree = k; + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_HOS_FORWARD; + #define TAYLOR_BUFFER dpp_T + dp_z = myalloc1(k); + dp_Ttemp = myalloc1(k); + #define T_TEMP dp_Ttemp; + #if defined(_KEEP_) + if (keep) { + const size_t taylbuf = ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; + taylor_begin(taylbuf, keep - 1); + } + #endif - /* Set up stuff for the tape */ - ADOLC_OPENMP_GET_THREAD_NUMBER; + /*--------------------------------------------------------------------------*/ + #else /* HOV and HOV_WK */ + dpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p * k); + ADOLC_CURRENT_TAPE_INFOS.dpp_T = dpp_T; + ADOLC_CURRENT_TAPE_INFOS.numTay = p; + ADOLC_CURRENT_TAPE_INFOS.gDegree = k; + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_HOV_FORWARD; + #define TAYLOR_BUFFER dpp_T + dp_z = myalloc1(k); + dp_Ttemp = myalloc1(p * k); + #define T_TEMP dp_Ttemp; + #if defined(_KEEP_) + if (keep) { + const size_t taylbuf = ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; + taylor_begin(taylbuf, keep - 1); + } + #endif + #endif + #endif + #endif + #endif + #endif +#endif + /****************************************************************************/ + /* FORWARD SWEEP */ - /* Initialize the Forward Sweep */ +#if defined(ADOLC_DEBUG) + /* #include */ + int v = 0; + unsigned int countPerOperation[256], taylorPerOperation[256]; + memset(countPerOperation, 0, 1024); + memset(taylorPerOperation, 0, 1024); + #define UPDATE_TAYLORWRITTEN(X) taylorPerOperation[operation] += X; +#else + #define UPDATE_TAYLORWRITTEN(X) +#endif /* ADOLC_DEBUG */ - init_for_sweep(tnum); + operation = get_op_f(); +#if defined(ADOLC_DEBUG) + ++countPerOperation[operation]; +#endif /* ADOLC_DEBUG */ - if ( (depcheck != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS]) || - (indcheck != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]) ) { - fprintf(DIAG_OUT,"ADOL-C error: forward sweep on tape %d aborted!\n" - "Number of dependent(%u) and/or independent(%u) variables passed" - " to forward is\ninconsistent with number " - "recorded on tape (%zu, %zu) \n", tnum, - depcheck, indcheck, - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS], - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_INDEPENDENTS]); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } -#if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) - if (! ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX] ) { - fprintf(DIAG_OUT,"ADOL-C error: tape %d was not created compatible " - "with %s\n Please call enableMinMaxUsingAbs() " - "before trace_on(%d)\n", tnum, __FUNCTION__, tnum); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + while (operation != end_of_tape) { + + switch (operation) { + + /****************************************************************************/ + /* MARKERS + */ + + /*--------------------------------------------------------------------------*/ + case end_of_op: /* end_of_op */ + get_op_block_f(); + operation = get_op_f(); + /* Skip next operation, it's another end_of_op */ + break; + + /*--------------------------------------------------------------------------*/ + case end_of_int: /* end_of_int */ + get_loc_block_f(); + break; + + /*--------------------------------------------------------------------------*/ + case end_of_val: /* end_of_val */ + get_val_block_f(); + break; + /*--------------------------------------------------------------------------*/ + case start_of_tape: /* start_of_tape */ + case end_of_tape: /* end_of_tape */ + break; + + /****************************************************************************/ + /* COMPARISON + */ + + /*--------------------------------------------------------------------------*/ + case eq_zero: /* eq_zero */ + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + if (dp_T0[arg] != 0) { + if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) + fprintf(DIAG_OUT, + "ADOL-C Warning: Branch switch detected in comparison " + "(operator eq_zero).\n" + "Forward sweep aborted! Retaping recommended!\n"); + ret_c = -1; + operation = end_of_tape; + continue; } -#if defined(_ABS_NORM_SIG_) || defined(_INDOPRO_) - if (swcheck != ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]) { - fprintf(DIAG_OUT,"ADOL-C error: forward sweep on tape %d aborted!\n" - "Number of switches(%u) passed" - " to forward is\ninconsistent with number " - "recorded on tape (%zu) \n", tnum, - swcheck, - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); + ret_c = 0; +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case neq_zero: /* neq_zero */ + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + if (dp_T0[arg] == 0) { + if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) + fprintf(DIAG_OUT, + "ADOL-C Warning: Branch switch detected in comparison " + "(operator neq_zero).\n" + "Forward sweep aborted! Retaping recommended!\n"); + ret_c = -1; + operation = end_of_tape; + continue; } -#endif -#endif - /****************************************************************************/ - /* MEMORY ALLOCATION */ - /* olvo 980626 has to be revised for common blocks */ +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case le_zero: /* le_zero */ + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + if (dp_T0[arg] > 0) { + if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) + fprintf(DIAG_OUT, + "ADOL-C Warning: Branch switch detected in comparison " + "(operator le_zero).\n" + "Forward sweep aborted! Retaping recommended!\n"); + ret_c = -1; + operation = end_of_tape; + continue; + } + if (dp_T0[arg] == 0) + ret_c = 0; +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case gt_zero: /* gt_zero */ + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + if (dp_T0[arg] <= 0) { + if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) + fprintf(DIAG_OUT, + "ADOL-C Warning: Branch switch detected in comparison " + "(operator gt_zero).\n" + "Forward sweep aborted! Retaping recommended!\n"); + ret_c = -1; + operation = end_of_tape; + continue; + } +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case ge_zero: /* ge_zero */ + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + if (dp_T0[arg] < 0) { + if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) + fprintf(DIAG_OUT, + "ADOL-C Warning: Branch switch detected in comparison " + "(operator ge_zero).\n" + "Forward sweep aborted! Retaping recommended!\n"); + ret_c = -1; + operation = end_of_tape; + continue; + } + if (dp_T0[arg] == 0) + ret_c = 0; +#endif /* !_NTIGHT_ */ + break; + + /*--------------------------------------------------------------------------*/ + case lt_zero: /* lt_zero */ + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + if (dp_T0[arg] >= 0) { + if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) + fprintf(DIAG_OUT, + "ADOL-C Warning: Branch switch detected in comparison " + "(operator lt_zero).\n" + "Forward sweep aborted! Retaping recommended!\n"); + ret_c = -1; + operation = end_of_tape; + continue; + } +#endif /* !_NTIGHT_ */ + break; - /*--------------------------------------------------------------------------*/ -#if !defined(_NTIGHT_) - dp_T0 = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); - ADOLC_CURRENT_TAPE_INFOS.dp_T0 = dp_T0; + /****************************************************************************/ + /* ASSIGNMENTS + */ - if(ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) { - if (ADOLC_CURRENT_TAPE_INFOS.signature == NULL) { - signature = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]); - ADOLC_CURRENT_TAPE_INFOS.signature = signature; - } else - signature = ADOLC_CURRENT_TAPE_INFOS.signature; - } + /*--------------------------------------------------------------------------*/ + case assign_a: /* assign an adouble variable an assign_a */ + /* adouble value. (=) */ + arg = get_locint_f(); + res = get_locint_f(); - ADOLC_CURRENT_TAPE_INFOS.dpp_T = &dp_T0; - ADOLC_CURRENT_TAPE_INFOS.numTay = 0; - ADOLC_CURRENT_TAPE_INFOS.gDegree = 0; - ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_ZOS_FORWARD; + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + +#if !defined(_NTIGHT_) + dp_T0[res] = dp_T0[arg]; #endif /* !_NTIGHT_ */ -#if defined(_ZOS_) /* ZOS */ -#if defined(_KEEP_) - if (keep>1) { - fprintf(DIAG_OUT,"\n ADOL-C error: zero order scalar forward cannot save" - " more\nthan zero order taylor coefficients!\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } -#endif -#if defined(_KEEP_) - if (keep) { - const size_t taylbuf = ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; +#if defined(_INDO_) + #if defined(_INDOPRO_) + copy_index_domain(res, arg, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg]; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = TARG_INC; + #endif +#endif /* ALL_TOGETHER_AGAIN */ + break; - taylor_begin(taylbuf,keep-1); - } + /*--------------------------------------------------------------------------*/ + case assign_d: /* assign an adouble variable a assign_d */ + /* double value. (=) */ + res = get_locint_f(); +#if !defined(_NTIGHT_) + coval = #endif + get_val_f(); - /*--------------------------------------------------------------------------*/ -#else /* FOS */ -#if defined(_FOS_) -#if defined(_KEEP_) - if (keep>2) { - fprintf(DIAG_OUT,"\n ADOL-C error: first order scalar forward cannot save" - " more \nthan first order taylor coefficients!\n"); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } -#endif - dp_T = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); - ADOLC_CURRENT_TAPE_INFOS.dpp_T = &dp_T; - ADOLC_CURRENT_TAPE_INFOS.numTay = 1; - ADOLC_CURRENT_TAPE_INFOS.gDegree = 1; - ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOS_FORWARD; -# define TAYLOR_BUFFER dp_T -#if defined(_KEEP_) - if (keep) { - const size_t taylbuf = ADOLC_CURRENT_TAPE_INFOS.stats[TAY_BUFFER_SIZE]; - taylor_begin(taylbuf,keep-1); - } -#endif - - /*--------------------------------------------------------------------------*/ -#else /* INF_FOR */ -#if defined(_INT_FOR_) - up_T = myalloc2_ulong(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES],p); -#define TAYLOR_BUFFER up_T - - /*--------------------------------------------------------------------------*/ -#else /* INDOPRO */ -#if defined(_INDO_) -#if defined(_INDOPRO_) - /* index domains */ - ind_dom = (locint **) malloc(sizeof(locint*) * ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); - max_ind_dom = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; - - for(int i=0;i */ - int v = 0; - unsigned int countPerOperation[256], taylorPerOperation[256]; - memset(countPerOperation, 0, 1024); - memset(taylorPerOperation, 0, 1024); -# define UPDATE_TAYLORWRITTEN(X) taylorPerOperation[operation] += X; -#else -# define UPDATE_TAYLORWRITTEN(X) -#endif /* ADOLC_DEBUG */ - - operation=get_op_f(); -#if defined(ADOLC_DEBUG) - ++countPerOperation[operation]; -#endif /* ADOLC_DEBUG */ - - while (operation !=end_of_tape) { - - switch (operation) { - - - /****************************************************************************/ - /* MARKERS */ - - /*--------------------------------------------------------------------------*/ - case end_of_op: /* end_of_op */ - get_op_block_f(); - operation=get_op_f(); - /* Skip next operation, it's another end_of_op */ - break; - - /*--------------------------------------------------------------------------*/ - case end_of_int: /* end_of_int */ - get_loc_block_f(); - break; - - /*--------------------------------------------------------------------------*/ - case end_of_val: /* end_of_val */ - get_val_block_f(); - break; - /*--------------------------------------------------------------------------*/ - case start_of_tape: /* start_of_tape */ - case end_of_tape: /* end_of_tape */ - break; - - - /****************************************************************************/ - /* COMPARISON */ - - /*--------------------------------------------------------------------------*/ - case eq_zero: /* eq_zero */ - arg = get_locint_f(); - -#if !defined(_NTIGHT_) - if (dp_T0[arg] != 0) { - if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) - fprintf(DIAG_OUT, - "ADOL-C Warning: Branch switch detected in comparison " - "(operator eq_zero).\n" - "Forward sweep aborted! Retaping recommended!\n"); - ret_c = -1; - operation = end_of_tape; - continue; - } - ret_c = 0; -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case neq_zero: /* neq_zero */ - arg = get_locint_f(); - -#if !defined(_NTIGHT_) - if (dp_T0[arg] == 0) { - if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) - fprintf(DIAG_OUT, - "ADOL-C Warning: Branch switch detected in comparison " - "(operator neq_zero).\n" - "Forward sweep aborted! Retaping recommended!\n"); - ret_c = -1; - operation = end_of_tape; - continue; - } -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case le_zero: /* le_zero */ - arg = get_locint_f(); - -#if !defined(_NTIGHT_) - if (dp_T0[arg] > 0) { - if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) - fprintf(DIAG_OUT, - "ADOL-C Warning: Branch switch detected in comparison " - "(operator le_zero).\n" - "Forward sweep aborted! Retaping recommended!\n"); - ret_c = -1; - operation = end_of_tape; - continue; - } - if (dp_T0[arg] == 0) - ret_c = 0; -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case gt_zero: /* gt_zero */ - arg = get_locint_f(); - -#if !defined(_NTIGHT_) - if (dp_T0[arg] <= 0) { - if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) - fprintf(DIAG_OUT, - "ADOL-C Warning: Branch switch detected in comparison " - "(operator gt_zero).\n" - "Forward sweep aborted! Retaping recommended!\n"); - ret_c = -1; - operation = end_of_tape; - continue; - } -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case ge_zero: /* ge_zero */ - arg = get_locint_f(); - -#if !defined(_NTIGHT_) - if (dp_T0[arg] < 0) { - if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) - fprintf(DIAG_OUT, - "ADOL-C Warning: Branch switch detected in comparison " - "(operator ge_zero).\n" - "Forward sweep aborted! Retaping recommended!\n"); - ret_c = -1; - operation = end_of_tape; - continue; - } - if (dp_T0[arg] == 0) - ret_c = 0; -#endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case lt_zero: /* lt_zero */ - arg = get_locint_f(); - -#if !defined(_NTIGHT_) - if (dp_T0[arg] >= 0) { - if (ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) - fprintf(DIAG_OUT, - "ADOL-C Warning: Branch switch detected in comparison " - "(operator lt_zero).\n" - "Forward sweep aborted! Retaping recommended!\n"); - ret_c = -1; - operation = end_of_tape; - continue; - } -#endif /* !_NTIGHT_ */ - break; - - - /****************************************************************************/ - /* ASSIGNMENTS */ - - /*--------------------------------------------------------------------------*/ - case assign_a: /* assign an adouble variable an assign_a */ - /* adouble value. (=) */ - arg = get_locint_f(); - res = get_locint_f(); - - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - - -#if !defined(_NTIGHT_) - dp_T0[res] = dp_T0[arg]; -#endif /* !_NTIGHT_ */ - -#if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg]; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Targ,TAYLOR_BUFFER[arg]) - ASSIGN_T(Tres,TAYLOR_BUFFER[res]) - - FOR_0_LE_l_LT_pk - TRES_INC = TARG_INC; -#endif -#endif /* ALL_TOGETHER_AGAIN */ - break; - - /*--------------------------------------------------------------------------*/ - case assign_d: /* assign an adouble variable a assign_d */ - /* double value. (=) */ - res = get_locint_f(); -#if !defined(_NTIGHT_) - coval = -#endif - get_val_f(); - - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = coval; + dp_T0[res] = coval; #endif /* !_NTIGHT_ */ #if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[res][0]=0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - - FOR_0_LE_l_LT_pk - TRES_INC = 0; -#endif + #if defined(_INDOPRO_) + ind_dom[res][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[res] = opind++; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = 0; + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case neg_sign_p: - case recipr_p: - case assign_p: /* assign an adouble variable a assign_d */ - /* double value. (=) */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case neg_sign_p: + case recipr_p: + case assign_p: /* assign an adouble variable a assign_d */ + /* double value. (=) */ + arg = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; #endif - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - if (operation == recipr_p) - coval = 1.0/coval; - else if (operation == neg_sign_p) - coval = - coval; - dp_T0[res] = coval; + if (operation == recipr_p) + coval = 1.0 / coval; + else if (operation == neg_sign_p) + coval = -coval; + dp_T0[res] = coval; #endif /* !_NTIGHT_ */ #if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[res][0]=0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - - FOR_0_LE_l_LT_pk - TRES_INC = 0; -#endif + #if defined(_INDOPRO_) + ind_dom[res][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[res] = opind++; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = 0; + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case assign_d_zero: /* assign an adouble variable a assign_d_zero */ - /* double value. (0) (=) */ - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case assign_d_zero: /* assign an adouble variable a assign_d_zero */ + /* double value. (0) (=) */ + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = 0.0; + dp_T0[res] = 0.0; #endif /* !_NTIGHT_ */ #if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[res][0]=0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - - FOR_0_LE_l_LT_pk - TRES_INC = 0; -#endif + #if defined(_INDOPRO_) + ind_dom[res][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[res] = opind++; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = 0; + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case assign_d_one: /* assign an adouble variable a assign_d_one */ - /* double value. (1) (=) */ - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case assign_d_one: /* assign an adouble variable a assign_d_one */ + /* double value. (1) (=) */ + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = 1.0; + dp_T0[res] = 1.0; #endif /* !_NTIGHT_ */ #if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[res][0]=0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - - FOR_0_LE_l_LT_pk - TRES_INC = 0; - -#endif + #if defined(_INDOPRO_) + ind_dom[res][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[res] = opind++; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = 0; + + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case assign_ind: /* assign an adouble variable an assign_ind */ - /* independent double value (<<=) */ - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case assign_ind: /* assign an adouble variable an assign_ind */ + /* independent double value (<<=) */ + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = basepoint[indexi]; + dp_T0[res] = basepoint[indexi]; #endif /* !_NTIGHT_ */ #if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[res][0] = 1; - ind_dom[res][2] = indexi; -#endif -#if defined(_NONLIND_) - fod[opind].entry = indexi; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_INC = ARGUMENT(indexi,l,i); -#else - FOR_0_LE_l_LT_p - FOR_0_LE_i_LT_k - TRES_INC = ARGUMENT(indexi,l,i); -#endif -#endif + #if defined(_INDOPRO_) + ind_dom[res][0] = 1; + ind_dom[res][2] = indexi; + #endif + #if defined(_NONLIND_) + fod[opind].entry = indexi; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[res] = opind++; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_p TRES_INC = ARGUMENT(indexi, l, i); + #else + FOR_0_LE_l_LT_p FOR_0_LE_i_LT_k TRES_INC = ARGUMENT(indexi, l, i); + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - ++indexi; - break; + ++indexi; + break; - /*--------------------------------------------------------------------------*/ - case assign_dep: /* assign a float variable a assign_dep */ - /* dependent adouble value. (>>=) */ - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case assign_dep: /* assign a float variable a assign_dep */ + /* dependent adouble value. (>>=) */ + res = get_locint_f(); #if !defined(_INDO_) -#if !defined(_NTIGHT_) - if ( valuepoint != NULL ) - valuepoint[indexd] = dp_T0[res]; -#endif /* !_NTIGHT_ */ + #if !defined(_NTIGHT_) + if (valuepoint != NULL) + valuepoint[indexd] = dp_T0[res]; + #endif /* !_NTIGHT_ */ #endif #if defined(_INDO_) -#if defined(_INDOPRO_) && !defined(_NONLIND_OLD_) - if (ind_dom[res][0] != 0) { - crs[indexd] = (unsigned int*) malloc(sizeof(unsigned int) * (ind_dom[res][0]+1)); - crs[indexd][0] = ind_dom[res][0]; - for(l=1;l<=crs[indexd][0];l++) { - crs[indexd][l] = ind_dom[res][l+1]; - } - } - else { - crs[indexd] = (unsigned int*) malloc(sizeof(unsigned int)); - crs[indexd][0] =0; - } -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - -#ifdef _INT_FOR_ - if (taylors != 0 ) /* ??? question: why here? */ - FOR_0_LE_l_LT_p - TAYLORS(indexd,l,i) = TRES_INC; -#else - if (taylors != 0 ) /* ??? question: why here? */ - FOR_0_LE_l_LT_p - FOR_0_LE_i_LT_k - TAYLORS(indexd,l,i) = TRES_INC; -#endif -#endif + #if defined(_INDOPRO_) && !defined(_NONLIND_OLD_) + if (ind_dom[res][0] != 0) { + crs[indexd] = (unsigned int *)malloc(sizeof(unsigned int) * + (ind_dom[res][0] + 1)); + crs[indexd][0] = ind_dom[res][0]; + for (l = 1; l <= crs[indexd][0]; l++) { + crs[indexd][l] = ind_dom[res][l + 1]; + } + } else { + crs[indexd] = (unsigned int *)malloc(sizeof(unsigned int)); + crs[indexd][0] = 0; + } + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + #ifdef _INT_FOR_ + if (taylors != 0) /* ??? question: why here? */ + FOR_0_LE_l_LT_p TAYLORS(indexd, l, i) = TRES_INC; + #else + if (taylors != 0) /* ??? question: why here? */ + FOR_0_LE_l_LT_p FOR_0_LE_i_LT_k TAYLORS(indexd, l, i) = TRES_INC; + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - indexd++; - break; + indexd++; + break; + /****************************************************************************/ + /* OPERATION + + * ASSIGNMENT */ - /****************************************************************************/ - /* OPERATION + ASSIGNMENT */ - - /*--------------------------------------------------------------------------*/ - case eq_plus_d: /* Add a floating point to an eq_plus_d */ - /* adouble. (+=) */ - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_plus_d: /* Add a floating point to an eq_plus_d */ + /* adouble. (+=) */ + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] += coval; + dp_T0[res] += coval; #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_plus_p: /* Add a floating point to an eq_plus_p */ - /* adouble. (+=) */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_plus_p: /* Add a floating point to an eq_plus_p */ + /* adouble. (+=) */ + arg = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; #endif - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] += coval; + dp_T0[res] += coval; #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_plus_a: /* Add an adouble to another eq_plus_a */ - /* adouble. (+=) */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_plus_a: /* Add an adouble to another eq_plus_a */ + /* adouble. (+=) */ + arg = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] += dp_T0[arg]; + dp_T0[res] += dp_T0[arg]; #endif /* !_NTIGHT_ */ #if defined(_INDO_) -#if defined(_INDOPRO_) - merge_2_index_domains(res, arg, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[res]]; - fod[opind].right = &fod[arg_index[arg]]; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) - -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_pk - TRES_INC |= TARG_INC; -#else - FOR_0_LE_l_LT_pk - TRES_INC += TARG_INC; -#endif -#endif + #if defined(_INDOPRO_) + merge_2_index_domains(res, arg, ind_dom); + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[res]]; + fod[opind].right = &fod[arg_index[arg]]; + arg_index[res] = opind++; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_pk TRES_INC |= TARG_INC; + #else + FOR_0_LE_l_LT_pk TRES_INC += TARG_INC; + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_min_d: /* Subtract a floating point from an eq_min_d */ - /* adouble. (-=) */ - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_min_d: /* Subtract a floating point from an eq_min_d */ + /* adouble. (-=) */ + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] -= coval; + dp_T0[res] -= coval; #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_min_p: /* Subtract a floating point from an eq_min_p */ - /* adouble. (-=) */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_min_p: /* Subtract a floating point from an eq_min_p */ + /* adouble. (-=) */ + arg = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; #endif - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] -= coval; + dp_T0[res] -= coval; #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_min_a: /* Subtract an adouble from another eq_min_a */ - /* adouble. (-=) */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_min_a: /* Subtract an adouble from another eq_min_a */ + /* adouble. (-=) */ + arg = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] -= dp_T0[arg]; + dp_T0[res] -= dp_T0[arg]; #endif /* !_NTIGHT_ */ #if defined(_INDO_) -#if defined(_INDOPRO_) - merge_2_index_domains(res, arg, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[res]]; - fod[opind].right = &fod[arg_index[arg]]; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) - -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_pk - TRES_INC |= TARG_INC; -#else - FOR_0_LE_l_LT_pk - TRES_INC -= TARG_INC; -#endif -#endif + #if defined(_INDOPRO_) + merge_2_index_domains(res, arg, ind_dom); + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[res]]; + fod[opind].right = &fod[arg_index[arg]]; + arg_index[res] = opind++; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_pk TRES_INC |= TARG_INC; + #else + FOR_0_LE_l_LT_pk TRES_INC -= TARG_INC; + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_mult_d: /* Multiply an adouble by a eq_mult_d */ - /* floating point. (*=) */ - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_mult_d: /* Multiply an adouble by a eq_mult_d */ + /* floating point. (*=) */ + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] *= coval; + dp_T0[res] *= coval; #endif /* !_NTIGHT_ */ #if !defined(_INDO_) -#if !defined(_ZOS_) /* BREAK_ZOS */ -#if !defined( _INT_FOR_) + #if !defined(_ZOS_) /* BREAK_ZOS */ + #if !defined(_INT_FOR_) - FOR_0_LE_l_LT_pk - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + FOR_0_LE_l_LT_pk ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - FOR_0_LE_l_LT_pk - TRES_INC *= coval; -#endif -#endif + FOR_0_LE_l_LT_pk TRES_INC *= coval; + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_mult_p: /* Multiply an adouble by a eq_mult_p */ - /* floating point. (*=) */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_mult_p: /* Multiply an adouble by a eq_mult_p */ + /* floating point. (*=) */ + arg = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg]; #endif - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] *= coval; + dp_T0[res] *= coval; #endif /* !_NTIGHT_ */ #if !defined(_INDO_) -#if !defined(_ZOS_) /* BREAK_ZOS */ -#if !defined( _INT_FOR_) + #if !defined(_ZOS_) /* BREAK_ZOS */ + #if !defined(_INT_FOR_) - FOR_0_LE_l_LT_pk - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + FOR_0_LE_l_LT_pk ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - FOR_0_LE_l_LT_pk - TRES_INC *= coval; -#endif -#endif + FOR_0_LE_l_LT_pk TRES_INC *= coval; + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case eq_mult_a: /* Multiply one adouble by another eq_mult_a */ - /* (*=) */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case eq_mult_a: /* Multiply one adouble by another eq_mult_a */ + /* (*=) */ + arg = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if defined(_INDO_) -#if defined(_INDOPRO_) - merge_2_index_domains(res, arg, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[res]]; - fod[opind].right = &fod[arg_index[arg]]; - traverse_unary(&fod[arg_index[res]], nonl_dom, &fod[arg_index[arg]], indcheck+1,maxopind+2); - traverse_unary(&fod[arg_index[arg]], nonl_dom, &fod[arg_index[res]], indcheck+1,maxopind+2); - arg_index[res] = opind++; -#endif -#if defined(_NONLIND_OLD_) - extend_nonlinearity_domain_binary(res, arg, ind_dom, nonl_dom); -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) - - INC_pk_1(Tres) - INC_pk_1(Targ) - -#ifdef _INT_FOR_ - FOR_p_GT_l_GE_0 - TRES_FODEC |= TARG_DEC; -#else - FOR_p_GT_l_GE_0 - FOR_k_GT_i_GE_0 - { TRES_FODEC = dp_T0[res]*TARG_DEC + - TRES*dp_T0[arg]; - DEC_TRES_FO -#ifdef _HIGHER_ORDER_ - TresOP = Tres-i; - TargOP = Targ; - - for (int j=0;j0 */ -#endif /* _HIGHER_ORDER_ */ - } + #if defined(_INDOPRO_) + copy_index_domain(res, arg, ind_dom); + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[arg]]; + fod[opind].right = NULL; + traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, + maxopind + 2); + arg_index[res] = opind++; + #endif + #if defined(_NONLIND_OLD_) + extend_nonlinearity_domain_unary(arg, ind_dom, nonl_dom); + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_p TRES_FOINC = TARG_FOINC; + #else + FOR_0_LE_l_LT_p + FOR_0_LE_i_LT_k { /* olvo 980915 changed order to allow x = exp(x) */ + #if defined(_HIGHER_ORDER_) + zOP = dp_z + i; + (*zOP--) = (i + 1) * (*Targ); + #endif /* _HIGHER_ORDER_ */ + + TRES_FOINC = dp_T0[res] * TARG_INC; + + #if defined(_HIGHER_ORDER_) + TresOP = Tres - i; + + *Tres *= (i + 1); + for (int j = 0; j < i; j++) + *Tres += (*TresOP++) * (*zOP--); + *Tres++ /= (i + 1); /* important only for i>0 */ + #endif /* _HIGHER_ORDER_ */ + } -#endif -#endif + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case sin_op: /* sine operation sin_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case sin_op: /* sine operation sin_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(arg2,keep,k,p) /* olvo 980710 covalue */ - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(arg2, keep, k, p) /* olvo 980710 covalue */ + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - /* Note: always arg2 != arg1 */ - dp_T0[arg2] = cos(dp_T0[arg1]); - dp_T0[res] = sin(dp_T0[arg1]); + /* Note: always arg2 != arg1 */ + dp_T0[arg2] = cos(dp_T0[arg1]); + dp_T0[res] = sin(dp_T0[arg1]); #endif /* !_NTIGHT_ */ - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; #if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; - traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck+1,maxopind+2); - arg_index[res] = opind++; -#endif -#if defined(_NONLIND_OLD_) - extend_nonlinearity_domain_unary(arg1, ind_dom, nonl_dom); -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) - -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - { /* olvo 980923 changed order to allow x = sin(x) */ - TARG2_FOINC = TARG1; - TRES_FOINC = TARG1_FOINC; - } -#else - FOR_0_LE_l_LT_p - FOR_0_LE_i_LT_k - { /* olvo 980921 changed order to allow x = sin(x) */ -#if defined(_HIGHER_ORDER_) - zOP = dp_z+i; - (*zOP--) = (i+1) * (*Targ1); -#endif /* _HIGHER_ORDER_ */ - - /* Note: always arg2 != arg1 */ - TARG2_FOINC = -dp_T0[res] * TARG1; - TRES_FOINC = dp_T0[arg2] * TARG1_INC; - -#if defined(_HIGHER_ORDER_) - TresOP = Tres-i; - Targ2OP = Targ2-i; - - *Tres *= (i+1); - *Targ2 *= (i+1); - for (int j=0;j 0.0) { - r0 = make_nan(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else - if (TARG1 < 0.0) { - r0 = make_inf(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else { - r0 = 0.0; - Targ1++; - } - TRES = r0; - VEC_INC(Tres, k) - } else - if (dp_T0[arg1] == -1.0) - FOR_0_LE_l_LT_p - { FOR_0_LE_i_LT_k - if (TARG1 > 0.0) { - r0 = make_inf(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else - if (TARG1 < 0.0) { - r0 = make_nan(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else { - r0 = 0.0; - Targ1++; - } - TRES = r0; - VEC_INC(Tres, k) - } else - FOR_0_LE_l_LT_p { - FOR_0_LE_i_LT_k - { /* olvo 980921 changed order to allow x = asin(x) */ -#if defined(_HIGHER_ORDER_) - zOP = dp_z+i; - (*zOP--) = (i+1) * (*Targ1); -#endif /* _HIGHER_ORDER_ */ - - TRES_FOINC = dp_T0[arg2] * TARG1_INC; - -#if defined(_HIGHER_ORDER_) - Targ2OP = Targ2; - - *Tres *= (i+1); - for (int j=0;j 0.0) { + r0 = make_nan(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else if (TARG1 < 0.0) { + r0 = make_inf(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else { + r0 = 0.0; + Targ1++; + } + TRES = r0; + VEC_INC(Tres, k) + } + else if (dp_T0[arg1] == -1.0) + FOR_0_LE_l_LT_p { + FOR_0_LE_i_LT_k if (TARG1 > 0.0) { + r0 = make_inf(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else if (TARG1 < 0.0) { + r0 = make_nan(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else { + r0 = 0.0; + Targ1++; + } + TRES = r0; + VEC_INC(Tres, k) + } + else + FOR_0_LE_l_LT_p { + FOR_0_LE_i_LT_k { /* olvo 980921 changed order to allow x = asin(x) */ + #if defined(_HIGHER_ORDER_) + zOP = dp_z + i; + (*zOP--) = (i + 1) * (*Targ1); + #endif /* _HIGHER_ORDER_ */ + + TRES_FOINC = dp_T0[arg2] * TARG1_INC; + + #if defined(_HIGHER_ORDER_) + Targ2OP = Targ2; + + *Tres *= (i + 1); + for (int j = 0; j < i; j++) + *Tres += (*Targ2OP++) * (*zOP--); + *Tres++ /= (i + 1); + #endif /* _HIGHER_ORDER_ */ + } + HOV_INC(Targ2, k) + } + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case acos_op: /* acos_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case acos_op: /* acos_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = acos(dp_T0[arg1]); + dp_T0[res] = acos(dp_T0[arg1]); #endif /* !_NTIGHT_ */ - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; #if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; - traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck+1,maxopind+2); - arg_index[res] = opind++; -#endif -#if defined(_NONLIND_OLD_) - extend_nonlinearity_domain_unary(arg1, ind_dom, nonl_dom); -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_FOINC = TARG1_FOINC; -#else - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) - - if (dp_T0[arg1] == 1.0) - FOR_0_LE_l_LT_p - { FOR_0_LE_i_LT_k - if (TARG1 > 0.0) { - r0 = make_nan(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else - if (TARG1 < 0.0) { - r0 = -make_inf(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else { - r0 = 0.0; - Targ1++; - } - TRES = r0; - VEC_INC(Tres, k) - } else - if (dp_T0[arg1] == -1.0) - FOR_0_LE_l_LT_p - { FOR_0_LE_i_LT_k - if (TARG1 > 0.0) { - r0 = -make_inf(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else - if (TARG1 < 0.0) { - r0 = make_nan(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else { - r0 = 0.0; - Targ1++; - } - TRES = r0; - VEC_INC(Tres, k) - } else - FOR_0_LE_l_LT_p { - FOR_0_LE_i_LT_k - { /* olvo 980921 changed order to allow x = acos(x) */ -#if defined(_HIGHER_ORDER_) - zOP = dp_z+i; - (*zOP--) = (i+1) * (*Targ1); -#endif /* _HIGHER_ORDER_ */ - - TRES_FOINC = dp_T0[arg2] * TARG1_INC; - -#if defined(_HIGHER_ORDER_) - Targ2OP = Targ2; - - *Tres *= (i+1); - for (int j=0;j 0.0) { + r0 = make_nan(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else if (TARG1 < 0.0) { + r0 = -make_inf(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else { + r0 = 0.0; + Targ1++; + } + TRES = r0; + VEC_INC(Tres, k) + } + else if (dp_T0[arg1] == -1.0) + FOR_0_LE_l_LT_p { + FOR_0_LE_i_LT_k if (TARG1 > 0.0) { + r0 = -make_inf(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else if (TARG1 < 0.0) { + r0 = make_nan(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else { + r0 = 0.0; + Targ1++; + } + TRES = r0; + VEC_INC(Tres, k) + } + else + FOR_0_LE_l_LT_p { + FOR_0_LE_i_LT_k { /* olvo 980921 changed order to allow x = acos(x) */ + #if defined(_HIGHER_ORDER_) + zOP = dp_z + i; + (*zOP--) = (i + 1) * (*Targ1); + #endif /* _HIGHER_ORDER_ */ + + TRES_FOINC = dp_T0[arg2] * TARG1_INC; + + #if defined(_HIGHER_ORDER_) + Targ2OP = Targ2; + + *Tres *= (i + 1); + for (int j = 0; j < i; j++) + *Tres += (*Targ2OP++) * (*zOP--); + *Tres++ /= (i + 1); + #endif /* _HIGHER_ORDER_ */ + } + HOV_INC(Targ2, k) + } + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case asinh_op: /* asinh_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case asinh_op: /* asinh_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = asinh(dp_T0[arg1]); + dp_T0[res] = asinh(dp_T0[arg1]); #endif /* !_NTIGHT_ */ - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; #if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; - traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck+1,maxopind+2); - arg_index[res] = opind++; -#endif -#if defined(_NONLIND_OLD_) - extend_nonlinearity_domain_unary(arg1, ind_dom, nonl_dom); -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_FOINC = TARG1_FOINC; -#else - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) - - FOR_0_LE_l_LT_p - { FOR_0_LE_i_LT_k - { /* olvo 980921 changed order to allow x = asinh(x) */ -#if defined(_HIGHER_ORDER_) - zOP = dp_z+i; - (*zOP--) = (i+1) * (*Targ1); -#endif /* _HIGHER_ORDER_ */ - - TRES_FOINC = dp_T0[arg2] * TARG1_INC; - -#if defined(_HIGHER_ORDER_) - Targ2OP = Targ2; - - *Tres *= (i+1); - for (int j=0;j 0.0) { - r0 = make_inf(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else - if (TARG1 < 0.0) { - r0 = make_nan(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else { - r0 = 0.0; - Targ1++; - } - TRES_INC = r0; -#if defined(_HIGHER_ORDER_) - for (int i=1;i 0.0) { + r0 = make_inf(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else if (TARG1 < 0.0) { + r0 = make_nan(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else { + r0 = 0.0; + Targ1++; + } + TRES_INC = r0; + #if defined(_HIGHER_ORDER_) + for (int i = 1; i < k; i++) + *Tres++ = make_nan(); + #endif /* _HIGHER_ORDER_ */ + } + else + FOR_0_LE_l_LT_p { + FOR_0_LE_i_LT_k { /* olvo 980921 changed order to allow x = acosh(x) + */ + #if defined(_HIGHER_ORDER_) + zOP = dp_z + i; + (*zOP--) = (i + 1) * (*Targ1); + #endif /* _HIGHER_ORDER_ */ + + TRES_FOINC = dp_T0[arg2] * TARG1_INC; + + #if defined(_HIGHER_ORDER_) + Targ2OP = Targ2; + + *Tres *= (i + 1); + for (int j = 0; j < i; j++) + *Tres += (*Targ2OP++) * (*zOP--); + *Tres++ /= (i + 1); + #endif /* _HIGHER_ORDER_ */ + } + HOV_INC(Targ2, k) + } + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case atanh_op: /* atanh_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case atanh_op: /* atanh_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = atanh(dp_T0[arg1]); + dp_T0[res] = atanh(dp_T0[arg1]); #endif /* !_NTIGHT_ */ - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; #if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; - traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck+1,maxopind+2); - arg_index[res] = opind++; -#endif -#if defined(_NONLIND_OLD_) - extend_nonlinearity_domain_unary(arg1, ind_dom, nonl_dom); -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_FOINC = TARG1_FOINC; -#else - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) - - if (dp_T0[arg1] == 1.0) - FOR_0_LE_l_LT_p - { FOR_0_LE_i_LT_k - if (TARG1 > 0.0) { - r0 = make_nan(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else - if (TARG1 < 0.0) { - r0 = make_inf(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else { - r0 = 0.0; - Targ1++; - } - TRES_INC = r0; -#if defined(_HIGHER_ORDER_) - for (int i=1;i 0.0) { - r0 = make_inf(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else - if (TARG1 < 0.0) { - r0 = make_nan(); - VEC_INC(Targ1, k-i) - BREAK_FOR_I - } else { - r0 = 0.0; - Targ1++; - } - TRES_INC = r0; -#if defined(_HIGHER_ORDER_) - for (int i=1;i 0.0) { + r0 = make_nan(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else if (TARG1 < 0.0) { + r0 = make_inf(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else { + r0 = 0.0; + Targ1++; + } + TRES_INC = r0; + #if defined(_HIGHER_ORDER_) + for (int i = 1; i < k; i++) + *Tres++ = make_nan(); + #endif /* _HIGHER_ORDER_ */ + } + else if (dp_T0[arg1] == -1.0) + FOR_0_LE_l_LT_p { + FOR_0_LE_i_LT_k if (TARG1 > 0.0) { + r0 = make_inf(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else if (TARG1 < 0.0) { + r0 = make_nan(); + VEC_INC(Targ1, k - i) + BREAK_FOR_I + } + else { + r0 = 0.0; + Targ1++; + } + TRES_INC = r0; + #if defined(_HIGHER_ORDER_) + for (int i = 1; i < k; i++) + *Tres++ = make_nan(); + #endif /* _HIGHER_ORDER_ */ + } + else + FOR_0_LE_l_LT_p { + FOR_0_LE_i_LT_k { /* olvo 980921 changed order to allow x = atanh(x) + */ + #if defined(_HIGHER_ORDER_) + zOP = dp_z + i; + (*zOP--) = (i + 1) * (*Targ1); + #endif /* _HIGHER_ORDER_ */ + + TRES_FOINC = dp_T0[arg2] * TARG1_INC; + + #if defined(_HIGHER_ORDER_) + Targ2OP = Targ2; + + *Tres *= (i + 1); + for (int j = 0; j < i; j++) + *Tres += (*Targ2OP++) * (*zOP--); + *Tres++ /= (i + 1); + #endif /* _HIGHER_ORDER_ */ + } + HOV_INC(Targ2, k) + } + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case erf_op: /* erf_op */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case erf_op: /* erf_op */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = erf(dp_T0[arg1]); + dp_T0[res] = erf(dp_T0[arg1]); #endif /* !_NTIGHT_ */ - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; #if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; - traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck+1,maxopind+2); - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1,TAYLOR_BUFFER[arg1]) -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_FOINC = TARG1_FOINC; -#else - ASSIGN_T(Targ2,TAYLOR_BUFFER[arg2]) - - FOR_0_LE_l_LT_p - { FOR_0_LE_i_LT_k - { /* olvo 980921 changed order to allow x = erf(x) */ -#if defined(_HIGHER_ORDER_) - zOP = dp_z+i; - (*zOP--) = (i+1) * (*Targ1); -#endif /* _HIGHER_ORDER_ */ - - TRES_FOINC = dp_T0[arg2] * TARG1_INC; - -#if defined(_HIGHER_ORDER_) - Targ2OP = Targ2; - - *Tres *= (i+1); - for (int j=0;j 1) + TRES_INC = 0; + if ((coval - i < 1) && (coval - i > 0)) + TRES_INC = make_inf(); + if (coval - i < 0) + TRES_INC = make_nan(); + } + } + } else { + if (coval == 1) { + FOR_0_LE_l_LT_pk TRES_INC = TARG_INC; + } else + /* coval is an int > 1 */ + /* the following is not efficient but at least it works */ + /* it reformulates x^n into x* ... *x n times */ + { + INC_pk_1(Targ) INC_pk_1(Tres) + + FOR_p_GT_l_GE_0 { + FOR_k_GT_i_GE_0 { + *Tres = 0; + DEC_TRES_FO + #if defined(_HIGHER_ORDER_) + if (i == k - 1) { + zOP = dp_z + k - 1; + for (int j = k - 1; j >= 0; j--) { + (*zOP--) = (*Targ--); + } + } + for (int j = 0; j < i; j++) { + *Tres += dp_z[j] * dp_z[i - j - 1]; + } + Tres--; + #endif /* _HIGHER_ORDER_ */ + } + } + for (int ii = 3; ii <= coval; ii++) { ASSIGN_T(Tres, TAYLOR_BUFFER[res]) ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + INC_pk_1(Targ) INC_pk_1(Tres) -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_FOINC = TARG_INC; -#else - if (T0arg == 0.0) { - if (coval <= 0.0) - FOR_0_LE_l_LT_pk - TRES_INC = make_nan(); - else { - /* coval not a whole number */ - if (coval - floor(coval) != 0) { - FOR_0_LE_l_LT_p - { - FOR_0_LE_i_LT_k - { - if (coval - i > 1) - TRES_INC = 0; - if ((coval - i < 1) && (coval - i > 0)) - TRES_INC = make_inf(); - if (coval - i < 0) - TRES_INC = make_nan(); - } - } - } else { - if (coval == 1) { - FOR_0_LE_l_LT_pk - TRES_INC = TARG_INC; - } else - /* coval is an int > 1 */ - /* the following is not efficient but at least it works */ - /* it reformulates x^n into x* ... *x n times */ - { - INC_pk_1(Targ) - INC_pk_1(Tres) - - FOR_p_GT_l_GE_0 - { - FOR_k_GT_i_GE_0 - { - *Tres = 0; - DEC_TRES_FO -#if defined(_HIGHER_ORDER_) - if (i == k-1) { - zOP = dp_z+k-1; - for (int j=k-1;j>=0;j--) { - (*zOP--) = (*Targ--); - } - } - for (int j=0;j 1) + TRES_INC = 0; + if ((coval - i < 1) && (coval - i > 0)) + TRES_INC = make_inf(); + if (coval - i < 0) + TRES_INC = make_nan(); + } + } + } else { + if (coval == 1) { + FOR_0_LE_l_LT_pk TRES_INC = TARG_INC; + } else + /* coval is an int > 1 */ + /* the following is not efficient but at least it works */ + /* it reformulates x^n into x* ... *x n times */ + { + INC_pk_1(Targ) INC_pk_1(Tres) + + FOR_p_GT_l_GE_0 { + FOR_k_GT_i_GE_0 { + *Tres = 0; + DEC_TRES_FO + #if defined(_HIGHER_ORDER_) + if (i == k - 1) { + zOP = dp_z + k - 1; + for (int j = k - 1; j >= 0; j--) { + (*zOP--) = (*Targ--); + } + } + for (int j = 0; j < i; j++) { + *Tres += dp_z[j] * dp_z[i - j - 1]; + } + Tres--; + #endif /* _HIGHER_ORDER_ */ + } + } + for (int ii = 3; ii <= coval; ii++) { ASSIGN_T(Tres, TAYLOR_BUFFER[res]) ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + INC_pk_1(Targ) INC_pk_1(Tres) -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_FOINC = TARG_INC; -#else - if (T0arg == 0.0) { - if (coval <= 0.0) - FOR_0_LE_l_LT_pk - TRES_INC = make_nan(); - else { - /* coval not a whole number */ - if (coval - floor(coval) != 0) { - FOR_0_LE_l_LT_p - { - FOR_0_LE_i_LT_k - { - if (coval - i > 1) - TRES_INC = 0; - if ((coval - i < 1) && (coval - i > 0)) - TRES_INC = make_inf(); - if (coval - i < 0) - TRES_INC = make_nan(); - } - } - } else { - if (coval == 1) { - FOR_0_LE_l_LT_pk - TRES_INC = TARG_INC; - } else - /* coval is an int > 1 */ - /* the following is not efficient but at least it works */ - /* it reformulates x^n into x* ... *x n times */ - { - INC_pk_1(Targ) - INC_pk_1(Tres) - - FOR_p_GT_l_GE_0 - { - FOR_k_GT_i_GE_0 - { - *Tres = 0; - DEC_TRES_FO -#if defined(_HIGHER_ORDER_) - if (i == k-1) { - zOP = dp_z+k-1; - for (int j=k-1;j>=0;j--) { - (*zOP--) = (*Targ--); - } - } - for (int j=0;j dp_T0[res] == 0.0 */ - { r0 = 0.0; - FOR_0_LE_i_LT_k - { if (TARG>0.0) { - r0 = make_inf(); - VEC_INC(Targ, k-i) - BREAK_FOR_I - } else - if (TARG<0.0) { - r0 = make_nan(); - VEC_INC(Targ, k-i) - BREAK_FOR_I - } else - Targ++; - } - } - else { - r0 = 0.5/dp_T0[res]; - } - Targ = TargOP; - -#if defined(_HIGHER_ORDER_) - int even = 1; -#endif - FOR_0_LE_i_LT_k - { TRES_FOINC = r0 * TARG_INC; -#if defined(_HIGHER_ORDER_) - TresOP = Tres-i; - TresOP2 = Tres-1; - - double x = 0; - for (int j=1;2*j-1 dp_T0[res] == 0.0 */ + { + r0 = 0.0; + FOR_0_LE_i_LT_k { + if (TARG > 0.0) { + r0 = make_inf(); + VEC_INC(Targ, k - i) + BREAK_FOR_I + } else if (TARG < 0.0) { + r0 = make_nan(); + VEC_INC(Targ, k - i) + BREAK_FOR_I + } else + Targ++; + } + } else { + r0 = 0.5 / dp_T0[res]; + } + Targ = TargOP; + + #if defined(_HIGHER_ORDER_) + int even = 1; + #endif + FOR_0_LE_i_LT_k { + TRES_FOINC = r0 * TARG_INC; + #if defined(_HIGHER_ORDER_) + TresOP = Tres - i; + TresOP2 = Tres - 1; + + double x = 0; + for (int j = 1; 2 * j - 1 < i; j++) + x += (*TresOP++) * (*TresOP2--); + x *= 2; + if (!even) + x += (*TresOP) * (*TresOP2); /* !!! */ + even = !even; + *Tres++ -= r0 * x; + #endif /* _HIGHER_ORDER_ */ + } + } + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case cbrt_op: /* cbrt_op */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case cbrt_op: /* cbrt_op */ + arg = get_locint_f(); + res = get_locint_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = cbrt(dp_T0[arg]); + dp_T0[res] = cbrt(dp_T0[arg]); #endif /* !_NTIGHT_ */ - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; + ADOLC_OPENMP_RESTORE_THREAD_NUMBER; #if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; - traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck+1,maxopind+2); - arg_index[res] = opind++; -#endif -#if defined(_NONLIND_OLD_) - extend_nonlinearity_domain_unary(arg, ind_dom, nonl_dom); -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_FOINC = TARG_INC; -#else - FOR_0_LE_l_LT_p - { TargOP = Targ; - if (dp_T0[arg] == 0.0) - /* Note: <=> dp_T0[res] == 0.0 */ - { r0 = 0.0; - FOR_0_LE_i_LT_k - { if (TARG>0.0) { - r0 = make_inf(); - VEC_INC(Targ, k-i) - BREAK_FOR_I - } else - if (TARG<0.0) { - r0 = make_nan(); - VEC_INC(Targ, k-i) - BREAK_FOR_I - } else - Targ++; - } - } - else { - r0 = 1.0/(3*dp_T0[res]*dp_T0[res]); - } - Targ = TargOP; - - FOR_0_LE_i_LT_k - { TRES_FOINC = r0 * TARG_INC; -#if defined(_HIGHER_ORDER_) - fprintf(DIAG_OUT, "ADOL-C error: higher order mode of cbrt not implemented yet\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* _HIGHER_ORDER_ */ - } - } -#endif -#endif + #if defined(_INDOPRO_) + copy_index_domain(res, arg, ind_dom); + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[arg]]; + fod[opind].right = NULL; + traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, + maxopind + 2); + arg_index[res] = opind++; + #endif + #if defined(_NONLIND_OLD_) + extend_nonlinearity_domain_unary(arg, ind_dom, nonl_dom); + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_p TRES_FOINC = TARG_INC; + #else + FOR_0_LE_l_LT_p { + TargOP = Targ; + if (dp_T0[arg] == 0.0) + /* Note: <=> dp_T0[res] == 0.0 */ + { + r0 = 0.0; + FOR_0_LE_i_LT_k { + if (TARG > 0.0) { + r0 = make_inf(); + VEC_INC(Targ, k - i) + BREAK_FOR_I + } else if (TARG < 0.0) { + r0 = make_nan(); + VEC_INC(Targ, k - i) + BREAK_FOR_I + } else + Targ++; + } + } else { + r0 = 1.0 / (3 * dp_T0[res] * dp_T0[res]); + } + Targ = TargOP; + + FOR_0_LE_i_LT_k { + TRES_FOINC = r0 * TARG_INC; + #if defined(_HIGHER_ORDER_) + fprintf( + DIAG_OUT, + "ADOL-C error: higher order mode of cbrt not implemented yet\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); + #endif /* _HIGHER_ORDER_ */ + } + } + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case gen_quad: /* gen_quad */ - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case gen_quad: /* gen_quad */ + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - if (get_val_f()!=dp_T0[arg1]) { - fprintf(DIAG_OUT, - "ADOL-C Warning: forward sweep aborted; tape invalid!\n"); - IF_KEEP_TAYLOR_CLOSE - end_sweep(); - return -2; - } + if (get_val_f() != dp_T0[arg1]) { + fprintf(DIAG_OUT, + "ADOL-C Warning: forward sweep aborted; tape invalid!\n"); + IF_KEEP_TAYLOR_CLOSE + end_sweep(); + return -2; + } #endif /* !_NTIGHT_ */ #if !defined(_NTIGHT_) - coval = -#endif - get_val_f(); + coval = +#endif + get_val_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - dp_T0[res] = coval; + dp_T0[res] = coval; #endif /* !_NTIGHT_ */ #if defined(_INDO_) - fprintf(DIAG_OUT, - "ADOL-C Warning: forward sweep aborted; sparse mode not available for gen_quad!\n"); - end_sweep(); - return -2; -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_FOINC = TARG1_FOINC; -#else - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) - - FOR_0_LE_l_LT_p - { FOR_0_LE_i_LT_k - { /* olvo 980922 changed order to allow x = gen_quad(x) */ -#if defined(_HIGHER_ORDER_) - zOP = dp_z+i; - (*zOP--) = (i+1) * (*Targ1); -#endif /* _HIGHER_ORDER_ */ - - TRES_FOINC = dp_T0[arg2] * TARG1_INC; - -#if defined(_HIGHER_ORDER_) - Targ2OP = Targ2; - - *Tres *= (i+1); - for (int j=0;j dp_T0[arg2]) { - if (coval) - MINDEC(ret_c,2); - } else - if (dp_T0[arg1] < dp_T0[arg2]) { - if (!coval) - MINDEC(ret_c,2); - } else - if (arg1 != arg2) - MINDEC(ret_c,1); + /* olvo/mitev 980721 return value (taken from below) */ + if (dp_T0[arg1] > dp_T0[arg2]) { + if (coval) + MINDEC(ret_c, 2); + } else if (dp_T0[arg1] < dp_T0[arg2]) { + if (!coval) + MINDEC(ret_c, 2); + } else if (arg1 != arg2) + MINDEC(ret_c, 1); #endif /* !_NTIGHT_ */ -#if defined (_INDO_) -#if defined (_INDOPRO_) -#if defined (_TIGHT_) - if (dp_T0[arg1] < dp_T0[arg2]) - copy_index_domain(res, arg1, ind_dom); - else { - if (dp_T0[arg1] > dp_T0[arg2]) - copy_index_domain(res, arg2, ind_dom); - else - combine_2_index_domains(res, arg1, arg2, ind_dom); - } -#else - combine_2_index_domains(res, arg1, arg2, ind_dom); -#endif -#endif -#if defined(_NONLIND_) -#ifdef _TIGHT_ - if (dp_T0[arg1] < dp_T0[arg2]) - { - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; - arg_index[res] = opind++; - } - else { - if (dp_T0[arg1] > dp_T0[arg2]) - { - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg2]]; - fod[opind].right = NULL; - arg_index[res] = opind++; - - } - else - { - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = &fod[arg_index[arg2]]; - arg_index[res] = opind++; - } - } -#else - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = &fod[arg_index[arg2]]; - arg_index[res] = opind++; - arg_index[res] = opind++; -#endif -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - -#ifdef _INT_FOR_ -#ifdef _TIGHT_ - Tqo = NULL; - if (dp_T0[arg1] > dp_T0[arg2]) - Tqo = Targ2; - else - if (dp_T0[arg1] < dp_T0[arg2]) - Tqo = Targ1; - - FOR_0_LE_l_LT_p - { Targ = Tqo; - if (Targ == NULL) /* e.g. T0[arg1] == T0[arg2] */ - { Targ1OP = Targ1; - Targ2OP = Targ2; - if (TARG1 > TARG2) - Targ = Targ2OP; - else - if (TARG1 < TARG2) - Targ = Targ1OP; - Targ1++; - Targ2++; - if (Targ == NULL) /* e.g. both are equal */ - Targ = Targ1OP; - } - - TRES_INC = TARG_INC; - - if (Tqo) - Tqo++; - } +#if defined(_INDO_) + #if defined(_INDOPRO_) + #if defined(_TIGHT_) + if (dp_T0[arg1] < dp_T0[arg2]) + copy_index_domain(res, arg1, ind_dom); + else { + if (dp_T0[arg1] > dp_T0[arg2]) + copy_index_domain(res, arg2, ind_dom); + else + combine_2_index_domains(res, arg1, arg2, ind_dom); + } + #else + combine_2_index_domains(res, arg1, arg2, ind_dom); + #endif + #endif + #if defined(_NONLIND_) + #ifdef _TIGHT_ + if (dp_T0[arg1] < dp_T0[arg2]) { + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[arg1]]; + fod[opind].right = NULL; + arg_index[res] = opind++; + } else { + if (dp_T0[arg1] > dp_T0[arg2]) { + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[arg2]]; + fod[opind].right = NULL; + arg_index[res] = opind++; + + } else { + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[arg1]]; + fod[opind].right = &fod[arg_index[arg2]]; + arg_index[res] = opind++; + } + } + #else + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[arg1]]; + fod[opind].right = &fod[arg_index[arg2]]; + arg_index[res] = opind++; + arg_index[res] = opind++; + #endif + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + #ifdef _INT_FOR_ + #ifdef _TIGHT_ + Tqo = NULL; + if (dp_T0[arg1] > dp_T0[arg2]) + Tqo = Targ2; + else if (dp_T0[arg1] < dp_T0[arg2]) + Tqo = Targ1; + + FOR_0_LE_l_LT_p { + Targ = Tqo; + if (Targ == NULL) /* e.g. T0[arg1] == T0[arg2] */ + { + Targ1OP = Targ1; + Targ2OP = Targ2; + if (TARG1 > TARG2) + Targ = Targ2OP; + else if (TARG1 < TARG2) + Targ = Targ1OP; + Targ1++; + Targ2++; + if (Targ == NULL) /* e.g. both are equal */ + Targ = Targ1OP; + } + + TRES_INC = TARG_INC; + + if (Tqo) + Tqo++; + } - dp_T0[res] = MIN_ADOLC(dp_T0[arg1], dp_T0[arg2]); -#endif /* _TIGHT_ */ -#ifdef _NTIGHT_ - TRES_INC = TARG1_INC | TARG2_INC; -#endif /* _NTIGHT_ */ -#else - Tqo = NULL; - if (dp_T0[arg1] > dp_T0[arg2]) - Tqo = Targ2; - else - if (dp_T0[arg1] < dp_T0[arg2]) - Tqo = Targ1; - - FOR_0_LE_l_LT_p - { Targ = Tqo; - if (Targ == NULL) /* e.g. dp_T0[arg1] == - dp_T0[arg2] */ - { Targ1OP = Targ1; - Targ2OP = Targ2; - FOR_0_LE_i_LT_k - { if (TARG1 > TARG2) { - Targ = Targ2OP; - VEC_INC(Targ1, k-i) - VEC_INC(Targ2, k-i) - BREAK_FOR_I - } else - if (TARG1 < TARG2) { - Targ = Targ1OP; - VEC_INC(Targ1, k-i) - VEC_INC(Targ2, k-i) - BREAK_FOR_I - } - Targ1++; - Targ2++; - } - if (Targ == NULL) /* e.g. both are equal */ - Targ = Targ1OP; - } + dp_T0[res] = MIN_ADOLC(dp_T0[arg1], dp_T0[arg2]); + #endif /* _TIGHT_ */ + #ifdef _NTIGHT_ + TRES_INC = TARG1_INC | TARG2_INC; + #endif /* _NTIGHT_ */ + #else + Tqo = NULL; + if (dp_T0[arg1] > dp_T0[arg2]) + Tqo = Targ2; + else if (dp_T0[arg1] < dp_T0[arg2]) + Tqo = Targ1; + + FOR_0_LE_l_LT_p { + Targ = Tqo; + if (Targ == + NULL) /* e.g. dp_T0[arg1] == + dp_T0[arg2] */ + { + Targ1OP = Targ1; + Targ2OP = Targ2; + FOR_0_LE_i_LT_k { + if (TARG1 > TARG2) { + Targ = Targ2OP; + VEC_INC(Targ1, k - i) + VEC_INC(Targ2, k - i) + BREAK_FOR_I + } else if (TARG1 < TARG2) { + Targ = Targ1OP; + VEC_INC(Targ1, k - i) + VEC_INC(Targ2, k - i) + BREAK_FOR_I + } + Targ1++; + Targ2++; + } + if (Targ == NULL) /* e.g. both are equal */ + Targ = Targ1OP; + } - FOR_0_LE_i_LT_k - TRES_INC = TARG_INC; + FOR_0_LE_i_LT_k TRES_INC = TARG_INC; - if (Tqo) { - VEC_INC(Tqo, k) - } - } -#endif -#endif + if (Tqo) { + VEC_INC(Tqo, k) + } + } + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ #if !defined(_NTIGHT_) - dp_T0[res] = - MIN_ADOLC( dp_T0[arg1], - dp_T0[arg2] ); + dp_T0[res] = MIN_ADOLC(dp_T0[arg1], dp_T0[arg2]); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case abs_val: /* abs_val */ - arg = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case abs_val: /* abs_val */ + arg = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) #if !defined(_NTIGHT_) - /* olvo 980923 changed order to allow x = min(x,y) etc. */ + /* olvo 980923 changed order to allow x = min(x,y) etc. */ - /* olvo/mitev 980721 ec n3l (taken from below) */ - if (dp_T0[arg] < 0.0) { - if (coval) - MINDEC(ret_c,2); - } else - if (dp_T0[arg] > 0.0) { - if (!coval) - MINDEC(ret_c,2); - } - if (ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) { - signature[switchnum] = dp_T0[arg]; -#if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) - swargs[switchnum] = dp_T0[arg]; -#endif - } + /* olvo/mitev 980721 ec n3l (taken from below) */ + if (dp_T0[arg] < 0.0) { + if (coval) + MINDEC(ret_c, 2); + } else if (dp_T0[arg] > 0.0) { + if (!coval) + MINDEC(ret_c, 2); + } + if (ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) { + signature[switchnum] = dp_T0[arg]; + #if defined(_ABS_NORM_) || defined(_ABS_NORM_SIG_) + swargs[switchnum] = dp_T0[arg]; + #endif + } #endif /* !_NTIGHT_ */ #if defined(_INDO_) -#if defined(_INDOPRO_) -#if defined(_ABS_NORM_) - if (ind_dom[arg][0] != 0) { - crs[switchnum] = (unsigned int*) malloc(sizeof(unsigned int)* (ind_dom[arg][0]+1)); - crs[switchnum][0] = ind_dom[arg][0]; - for(l=1;l 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - - copy_index_domain(res, arg1, ind_dom); - - } else { - if (coval > 0.0) - MINDEC(ret_c,2); - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); - dp_T0[res] = dp_T0[arg2]; - copy_index_domain(res, arg2, ind_dom); - } -#else - combine_2_index_domains(res, arg1, arg2, ind_dom); -#endif -#endif -#if defined (_NONLIND_) -#ifdef _TIGHT_ - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - - arg_index[res] = arg_index[arg1]; - } else { - if (coval > 0.0) - MINDEC(ret_c,2); - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); - dp_T0[res] = dp_T0[arg2]; - - arg_index[res] = arg_index[arg2]; - } - -#else - arg_index[res] = opind++; -#endif -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) -#endif /* ALL_TOGETHER_AGAIN */ + get_val_f(); -#ifdef _INT_FOR_ -#ifdef _TIGHT_ - coval = get_val_f(); - - if (dp_T0[arg] > 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - else - FOR_0_LE_l_LT_pk - TRES_INC = TARG2_INC; - - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else { - if (coval > 0.0) - MINDEC(ret_c,2); - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); - dp_T0[res] = dp_T0[arg2]; - } -#endif /* _TIGHT_ */ -#ifdef _NTIGHT_ - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC | TARG2_INC; -#endif /* _NTIGHT_ */ -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - if (dp_T0[arg] > 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - else - FOR_0_LE_l_LT_pk - TRES_INC = TARG2_INC; -#endif + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else { - if (coval > 0.0) - MINDEC(ret_c,2); - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); - dp_T0[res] = dp_T0[arg2]; - } -#endif -#endif /* ALL_TOGETHER_AGAIN */ - break; + /* olvo 980924 changed order to allow reflexive ops */ +#if defined(_INDO_) + #if defined(_INDOPRO_) + #if defined(_TIGHT_) + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + + copy_index_domain(res, arg1, ind_dom); + + } else { + if (coval > 0.0) + MINDEC(ret_c, 2); + if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + dp_T0[res] = dp_T0[arg2]; + copy_index_domain(res, arg2, ind_dom); + } + #else + combine_2_index_domains(res, arg1, arg2, ind_dom); + #endif + #endif + #if defined(_NONLIND_) + #ifdef _TIGHT_ + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + + arg_index[res] = arg_index[arg1]; + } else { + if (coval > 0.0) + MINDEC(ret_c, 2); + if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + dp_T0[res] = dp_T0[arg2]; + + arg_index[res] = arg_index[arg2]; + } - case cond_eq_assign: /* cond_eq_assign */ - arg = get_locint_f(); - arg1 = get_locint_f(); - arg2 = get_locint_f(); - res = get_locint_f(); -#if !defined(_NTIGHT_) - coval = -#endif - get_val_f(); - - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - - /* olvo 980924 changed order to allow reflexive ops */ -#if defined (_INDO_) -#if defined (_INDOPRO_) -#if defined (_TIGHT_) - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - - copy_index_domain(res, arg1, ind_dom); - - } else { - if (coval >= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg2]; - copy_index_domain(res, arg2, ind_dom); - } + #else + arg_index[res] = opind++; + #endif + #endif #else - combine_2_index_domains(res, arg1, arg2, ind_dom); -#endif -#endif -#if defined (_NONLIND_) -#ifdef _TIGHT_ - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - - arg_index[res] = arg_index[arg1]; - } else { - if (coval >= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg2]; - - arg_index[res] = arg_index[arg2]; - } + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) + #endif /* ALL_TOGETHER_AGAIN */ -#else - arg_index[res] = opind++; -#endif -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) -#endif /* ALL_TOGETHER_AGAIN */ + #ifdef _INT_FOR_ + #ifdef _TIGHT_ + coval = get_val_f(); -#ifdef _INT_FOR_ -#ifdef _TIGHT_ - coval = get_val_f(); - - if (dp_T0[arg] >= 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - else - FOR_0_LE_l_LT_pk - TRES_INC = TARG2_INC; - - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else { - if (coval >= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg2]; - } -#endif /* _TIGHT_ */ -#ifdef _NTIGHT_ - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC | TARG2_INC; -#endif /* _NTIGHT_ */ -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - if (dp_T0[arg] >= 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - else - FOR_0_LE_l_LT_pk - TRES_INC = TARG2_INC; -#endif - - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else { - if (coval >= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg2]; - } -#endif + if (dp_T0[arg] > 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + else + FOR_0_LE_l_LT_pk TRES_INC = TARG2_INC; + + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else { + if (coval > 0.0) + MINDEC(ret_c, 2); + if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + dp_T0[res] = dp_T0[arg2]; + } + #endif /* _TIGHT_ */ + #ifdef _NTIGHT_ + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC | TARG2_INC; + #endif /* _NTIGHT_ */ + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + if (dp_T0[arg] > 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + else + FOR_0_LE_l_LT_pk TRES_INC = TARG2_INC; + #endif + + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else { + if (coval > 0.0) + MINDEC(ret_c, 2); + if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + dp_T0[res] = dp_T0[arg2]; + } + #endif #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /*--------------------------------------------------------------------------*/ - case cond_assign_s: /* cond_assign_s */ - arg = get_locint_f(); - arg1 = get_locint_f(); - res = get_locint_f(); + case cond_eq_assign: /* cond_eq_assign */ + arg = get_locint_f(); + arg1 = get_locint_f(); + arg2 = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) - /* olvo 980924 changed order to allow reflexive ops */ + /* olvo 980924 changed order to allow reflexive ops */ #if defined(_INDO_) -#if defined(_INDOPRO_) -#ifdef _TIGHT_ - if (dp_T0[arg] > 0) - copy_index_domain(res, arg1, ind_dom); -#else - merge_2_index_domains(res, arg1, ind_dom); -#endif -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg1]; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) -#endif /* ALL_TOGETHER_AGAIN */ + #if defined(_INDOPRO_) + #if defined(_TIGHT_) + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + + copy_index_domain(res, arg1, ind_dom); + + } else { + if (coval >= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg2]; + copy_index_domain(res, arg2, ind_dom); + } + #else + combine_2_index_domains(res, arg1, arg2, ind_dom); + #endif + #endif + #if defined(_NONLIND_) + #ifdef _TIGHT_ + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + + arg_index[res] = arg_index[arg1]; + } else { + if (coval >= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg2]; + + arg_index[res] = arg_index[arg2]; + } -#ifdef _INT_FOR_ -#ifdef _TIGHT_ - coval = get_val_f(); - - if (dp_T0[arg] > 0) -#endif /* _TIGHT_ */ - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - -#ifdef _TIGHT_ - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); -#endif /* _TIGHT_ */ + #else + arg_index[res] = opind++; + #endif + #endif #else -#if !defined(_ZOS_) /* BREAK_ZOS */ - if (dp_T0[arg] > 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; -#endif - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); -#endif -#endif /* ALL_TOGETHER_AGAIN */ - break; + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) + #endif /* ALL_TOGETHER_AGAIN */ + + #ifdef _INT_FOR_ + #ifdef _TIGHT_ + coval = get_val_f(); + if (dp_T0[arg] >= 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + else + FOR_0_LE_l_LT_pk TRES_INC = TARG2_INC; + + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else { + if (coval >= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg2]; + } + #endif /* _TIGHT_ */ + #ifdef _NTIGHT_ + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC | TARG2_INC; + #endif /* _NTIGHT_ */ + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + if (dp_T0[arg] >= 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + else + FOR_0_LE_l_LT_pk TRES_INC = TARG2_INC; + #endif + + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else { + if (coval >= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg2]; + } + #endif +#endif /* ALL_TOGETHER_AGAIN */ + break; - case cond_eq_assign_s: /* cond_eq_assign_s */ - arg = get_locint_f(); - arg1 = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case cond_assign_s: /* cond_assign_s */ + arg = get_locint_f(); + arg1 = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) - /* olvo 980924 changed order to allow reflexive ops */ + /* olvo 980924 changed order to allow reflexive ops */ #if defined(_INDO_) -#if defined(_INDOPRO_) -#ifdef _TIGHT_ - if (dp_T0[arg] >= 0) - copy_index_domain(res, arg1, ind_dom); -#else - merge_2_index_domains(res, arg1, ind_dom); -#endif -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg1]; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + #if defined(_INDOPRO_) + #ifdef _TIGHT_ + if (dp_T0[arg] > 0) + copy_index_domain(res, arg1, ind_dom); + #else + merge_2_index_domains(res, arg1, ind_dom); + #endif + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg1]; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + #endif /* ALL_TOGETHER_AGAIN */ + + #ifdef _INT_FOR_ + #ifdef _TIGHT_ + coval = get_val_f(); + + if (dp_T0[arg] > 0) + #endif /* _TIGHT_ */ + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + + #ifdef _TIGHT_ + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + #endif /* _TIGHT_ */ + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + if (dp_T0[arg] > 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + #endif + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + #endif #endif /* ALL_TOGETHER_AGAIN */ + break; -#ifdef _INT_FOR_ -#ifdef _TIGHT_ - coval = get_val_f(); - - if (dp_T0[arg] >= 0) -#endif /* _TIGHT_ */ - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - -#ifdef _TIGHT_ - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } -#endif /* _TIGHT_ */ -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - if (dp_T0[arg] >= 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; -#endif - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } + case cond_eq_assign_s: /* cond_eq_assign_s */ + arg = get_locint_f(); + arg1 = get_locint_f(); + res = get_locint_f(); +#if !defined(_NTIGHT_) + coval = #endif -#endif /* ALL_TOGETHER_AGAIN */ - break; + get_val_f(); - /*--------------------------------------------------------------------------*/ - /* NEW CONDITIONALS */ - /*--------------------------------------------------------------------------*/ -#if defined(ADOLC_ADVANCED_BRANCHING) - case neq_a_a: - case eq_a_a: - case le_a_a: - case ge_a_a: - case lt_a_a: - case gt_a_a: - case neq_a_p: - case eq_a_p: - case le_a_p: - case ge_a_p: - case lt_a_p: - case gt_a_p: -#if !defined(_NTIGHT_) - coval = -#endif - get_val_f(); - arg = get_locint_f(); - arg1 = get_locint_f(); - res = get_locint_f(); -#if !defined(_NTIGHT_) - { - revreal retval = -1; - const char* opname = ""; - switch (operation) { - case neq_a_a: - retval = (revreal)(dp_T0[arg] != dp_T0[arg1]); - opname = "neq_a_a"; - break; - case eq_a_a: - retval = (revreal)(dp_T0[arg] == dp_T0[arg1]); - opname = "eq_a_a"; - break; - case ge_a_a: - retval = (revreal)(dp_T0[arg] >= dp_T0[arg1]); - opname = "ge_a_a"; - break; - case le_a_a: - retval = (revreal)(dp_T0[arg] <= dp_T0[arg1]); - opname = "le_a_a"; - break; - case gt_a_a: - retval = (revreal)(dp_T0[arg] > dp_T0[arg1]); - opname = "gt_a_a"; - break; - case lt_a_a: - retval = (revreal)(dp_T0[arg] < dp_T0[arg1]); - opname = "lt_a_a"; - break; - case neq_a_p: - retval = (revreal)(dp_T0[arg] != ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); - opname = "neq_a_p"; - break; - case eq_a_p: - retval = (revreal)(dp_T0[arg] == ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); - opname = "eq_a_p"; - break; - case ge_a_p: - retval = (revreal)(dp_T0[arg] >= ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); - opname = "ge_a_p"; - break; - case le_a_p: - retval = (revreal)(dp_T0[arg] <= ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); - opname = "le_a_p"; - break; - case gt_a_p: - retval = (revreal)(dp_T0[arg] > ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); - opname = "gt_a_p"; - break; - case lt_a_p: - retval = (revreal)(dp_T0[arg] < ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); - opname = "lt_a_p"; - break; - } - if (retval != coval && ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) - fprintf(DIAG_OUT, - "ADOL-C Warning: Branch switch detected in comparison " - "(operator %s).\n" - "Results may be unpredictable! Retaping recommended!\n",opname); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p); - dp_T0[res] = retval; - } -#endif -#if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[res][0]=0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) - FOR_0_LE_l_LT_pk - TRES_INC = 0; -#endif + /* olvo 980924 changed order to allow reflexive ops */ +#if defined(_INDO_) + #if defined(_INDOPRO_) + #ifdef _TIGHT_ + if (dp_T0[arg] >= 0) + copy_index_domain(res, arg1, ind_dom); + #else + merge_2_index_domains(res, arg1, ind_dom); + #endif + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg1]; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + #endif /* ALL_TOGETHER_AGAIN */ + + #ifdef _INT_FOR_ + #ifdef _TIGHT_ + coval = get_val_f(); + + if (dp_T0[arg] >= 0) + #endif /* _TIGHT_ */ + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + + #ifdef _TIGHT_ + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } + #endif /* _TIGHT_ */ + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + if (dp_T0[arg] >= 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + #endif + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } + #endif #endif /* ALL_TOGETHER_AGAIN */ + break; - break; + /*--------------------------------------------------------------------------*/ + /* NEW CONDITIONALS */ + /*--------------------------------------------------------------------------*/ +#if defined(ADOLC_ADVANCED_BRANCHING) + case neq_a_a: + case eq_a_a: + case le_a_a: + case ge_a_a: + case lt_a_a: + case gt_a_a: + case neq_a_p: + case eq_a_p: + case le_a_p: + case ge_a_p: + case lt_a_p: + case gt_a_p: + #if !defined(_NTIGHT_) + coval = + #endif + get_val_f(); + arg = get_locint_f(); + arg1 = get_locint_f(); + res = get_locint_f(); + #if !defined(_NTIGHT_) + { + revreal retval = -1; + const char *opname = ""; + switch (operation) { + case neq_a_a: + retval = (revreal)(dp_T0[arg] != dp_T0[arg1]); + opname = "neq_a_a"; + break; + case eq_a_a: + retval = (revreal)(dp_T0[arg] == dp_T0[arg1]); + opname = "eq_a_a"; + break; + case ge_a_a: + retval = (revreal)(dp_T0[arg] >= dp_T0[arg1]); + opname = "ge_a_a"; + break; + case le_a_a: + retval = (revreal)(dp_T0[arg] <= dp_T0[arg1]); + opname = "le_a_a"; + break; + case gt_a_a: + retval = (revreal)(dp_T0[arg] > dp_T0[arg1]); + opname = "gt_a_a"; + break; + case lt_a_a: + retval = (revreal)(dp_T0[arg] < dp_T0[arg1]); + opname = "lt_a_a"; + break; + case neq_a_p: + retval = + (revreal)(dp_T0[arg] != + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); + opname = "neq_a_p"; + break; + case eq_a_p: + retval = + (revreal)(dp_T0[arg] == + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); + opname = "eq_a_p"; + break; + case ge_a_p: + retval = + (revreal)(dp_T0[arg] >= + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); + opname = "ge_a_p"; + break; + case le_a_p: + retval = + (revreal)(dp_T0[arg] <= + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); + opname = "le_a_p"; + break; + case gt_a_p: + retval = + (revreal)(dp_T0[arg] > + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); + opname = "gt_a_p"; + break; + case lt_a_p: + retval = + (revreal)(dp_T0[arg] < + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]); + opname = "lt_a_p"; + break; + } + if (retval != coval && ADOLC_GLOBAL_TAPE_VARS.branchSwitchWarning) + fprintf(DIAG_OUT, + "ADOL-C Warning: Branch switch detected in comparison " + "(operator %s).\n" + "Results may be unpredictable! Retaping recommended!\n", + opname); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p); + dp_T0[res] = retval; + } + #endif + #if defined(_INDO_) + #if defined(_INDOPRO_) + ind_dom[res][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[res] = opind++; + #endif + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = 0; + #endif + #endif /* ALL_TOGETHER_AGAIN */ + + break; #endif /* ADVANCED_BRANCHING */ - /*--------------------------------------------------------------------------*/ - case subscript: + /*--------------------------------------------------------------------------*/ + case subscript: #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); - arg = get_locint_f(); - { + get_val_f(); + arg = get_locint_f(); + { #if !defined(_NTIGHT_) - size_t idx, numvar = (size_t)trunc(fabs(coval)); - locint vectorloc; - vectorloc = -#endif - get_locint_f(); - res = get_locint_f(); -#if !defined(_NTIGHT_) - idx = (size_t)trunc(fabs(dp_T0[arg])); - if (idx >= numvar) - fprintf(DIAG_OUT, "ADOL-C warning: index out of bounds while subscripting n=%zu, idx=%zu\n", numvar, idx); - arg1 = vectorloc+idx; - IF_KEEP_WRITE_TAYLOR(res,keep,k,p); - dp_T0[res] = dp_T0[arg1]; -#if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg1]; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Targ1,TAYLOR_BUFFER[arg1]) - ASSIGN_T(Tres,TAYLOR_BUFFER[res]) - - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active subscripting does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + size_t idx, numvar = (size_t)trunc(fabs(coval)); + locint vectorloc; + vectorloc = +#endif + get_locint_f(); + res = get_locint_f(); +#if !defined(_NTIGHT_) + idx = (size_t)trunc(fabs(dp_T0[arg])); + if (idx >= numvar) + fprintf(DIAG_OUT, + "ADOL-C warning: index out of bounds while subscripting " + "n=%zu, idx=%zu\n", + numvar, idx); + arg1 = vectorloc + idx; + IF_KEEP_WRITE_TAYLOR(res, keep, k, p); + dp_T0[res] = dp_T0[arg1]; + #if defined(_INDO_) + #if defined(_INDOPRO_) + copy_index_domain(res, arg1, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg1]; + #endif + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active subscripting does not work in " + "safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - } - break; + } + break; - case subscript_ref: + case subscript_ref: #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); - arg = get_locint_f(); - { + get_val_f(); + arg = get_locint_f(); + { #if !defined(_NTIGHT_) - size_t idx, numvar = (size_t)trunc(fabs(coval)); - locint vectorloc; - vectorloc = + size_t idx, numvar = (size_t)trunc(fabs(coval)); + locint vectorloc; + vectorloc = #endif - get_locint_f(); - res = get_locint_f(); -#if !defined(_NTIGHT_) - idx = (size_t)trunc(fabs(dp_T0[arg])); - if (idx >= numvar) - fprintf(DIAG_OUT, "ADOL-C warning: index out of bounds while subscripting (ref) n=%zu, idx=%zu\n", numvar, idx); - arg1 = vectorloc+idx; - IF_KEEP_WRITE_TAYLOR(res,keep,k,p); - dp_T0[res] = arg1; -#else - fprintf(DIAG_OUT, "ADOL-C error: active subscripting does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif - } - break; - - case ref_copyout: - arg = get_locint_f(); - res = get_locint_f(); + get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - arg1 = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p); - dp_T0[res] = dp_T0[arg1]; -#if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg1]; -#endif + idx = (size_t)trunc(fabs(dp_T0[arg])); + if (idx >= numvar) + fprintf(DIAG_OUT, + "ADOL-C warning: index out of bounds while subscripting " + "(ref) n=%zu, idx=%zu\n", + numvar, idx); + arg1 = vectorloc + idx; + IF_KEEP_WRITE_TAYLOR(res, keep, k, p); + dp_T0[res] = arg1; #else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Targ1,TAYLOR_BUFFER[arg1]) - ASSIGN_T(Tres,TAYLOR_BUFFER[res]) - - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; + fprintf(DIAG_OUT, "ADOL-C error: active subscripting does not work in " + "safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + } + break; + + case ref_copyout: + arg = get_locint_f(); + res = get_locint_f(); +#if !defined(_NTIGHT_) + arg1 = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p); + dp_T0[res] = dp_T0[arg1]; + #if defined(_INDO_) + #if defined(_INDOPRO_) + copy_index_domain(res, arg1, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg1]; + #endif + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - case ref_incr_a: - arg = get_locint_f(); + case ref_incr_a: + arg = get_locint_f(); #if !defined(_NTIGHT_) - arg1 = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(arg1,keep,k,p); - dp_T0[arg1]++; + arg1 = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(arg1, keep, k, p); + dp_T0[arg1]++; #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif + break; + + case ref_decr_a: + arg = get_locint_f(); +#if !defined(_NTIGHT_) + arg1 = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(arg1, keep, k, p); + dp_T0[arg1]--; +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif + break; + + case ref_assign_d: + arg = get_locint_f(); +#if !defined(_NTIGHT_) + coval = #endif - break; + get_val_f(); - case ref_decr_a: - arg = get_locint_f(); -#if !defined(_NTIGHT_) - arg1 = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(arg1,keep,k,p); - dp_T0[arg1]--; -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif - break; - - case ref_assign_d: - arg = get_locint_f(); -#if !defined(_NTIGHT_) - coval = -#endif - get_val_f(); - -#if !defined(_NTIGHT_) - arg1 = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(arg1,keep,k,p) - dp_T0[arg1] = coval; -#if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[arg1][0] = 0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[arg1] = opind++; -#endif -#else -#if !defined(_ZOS_) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - - FOR_0_LE_l_LT_pk - TARG1_INC = 0; -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif - break; - - case ref_assign_p: - arg = get_locint_f(); - res = get_locint_f(); -#if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[res]; -#endif - -#if !defined(_NTIGHT_) - arg1 = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(arg1,keep,k,p) - dp_T0[arg1] = coval; -#if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[arg1][0] = 0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[arg1] = opind++; -#endif -#else -#if !defined(_ZOS_) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - - FOR_0_LE_l_LT_pk - TARG1_INC = 0; -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif - break; - - case ref_assign_d_zero: - arg = get_locint_f(); - -#if !defined(_NTIGHT_) - arg1 = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(arg1,keep,k,p) - dp_T0[arg1] = 0.0; -#if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[arg1][0] = 0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[arg1] = opind++; -#endif -#else -#if !defined(_ZOS_) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - - FOR_0_LE_l_LT_pk - TARG1_INC = 0; -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif - break; - - case ref_assign_d_one: - arg = get_locint_f(); - -#if !defined(_NTIGHT_) - arg1 = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(arg1,keep,k,p) - dp_T0[arg1] = 1.0; -#if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[arg1][0] = 0; -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[arg1] = opind++; -#endif -#else -#if !defined(_ZOS_) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - - FOR_0_LE_l_LT_pk - TARG1_INC = 0; -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif - break; - - case ref_assign_a: /* assign an adouble variable an assign_a */ - /* adouble value. (=) */ - arg = get_locint_f(); - res = get_locint_f(); - -#if !defined(_NTIGHT_) - arg1 = (size_t)trunc(fabs(dp_T0[res])); - IF_KEEP_WRITE_TAYLOR(arg1,keep,k,p) - dp_T0[arg1] = dp_T0[arg]; -#if defined(_INDO_) -#if defined(_INDOPRO_) - copy_index_domain(arg1, arg, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[arg1] = arg_index[arg]; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Targ,TAYLOR_BUFFER[arg]) - ASSIGN_T(Targ1,TAYLOR_BUFFER[arg1]) - - FOR_0_LE_l_LT_pk - TARG1_INC = TARG_INC; -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); +#if !defined(_NTIGHT_) + arg1 = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(arg1, keep, k, p) + dp_T0[arg1] = coval; + #if defined(_INDO_) + #if defined(_INDOPRO_) + ind_dom[arg1][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[arg1] = opind++; + #endif + #else + #if !defined(_ZOS_) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + + FOR_0_LE_l_LT_pk TARG1_INC = 0; + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif + break; + + case ref_assign_p: + arg = get_locint_f(); + res = get_locint_f(); +#if !defined(_NTIGHT_) + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[res]; +#endif + +#if !defined(_NTIGHT_) + arg1 = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(arg1, keep, k, p) + dp_T0[arg1] = coval; + #if defined(_INDO_) + #if defined(_INDOPRO_) + ind_dom[arg1][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[arg1] = opind++; + #endif + #else + #if !defined(_ZOS_) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + + FOR_0_LE_l_LT_pk TARG1_INC = 0; + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif + break; + + case ref_assign_d_zero: + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + arg1 = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(arg1, keep, k, p) + dp_T0[arg1] = 0.0; + #if defined(_INDO_) + #if defined(_INDOPRO_) + ind_dom[arg1][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[arg1] = opind++; + #endif + #else + #if !defined(_ZOS_) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + + FOR_0_LE_l_LT_pk TARG1_INC = 0; + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif + break; + + case ref_assign_d_one: + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + arg1 = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(arg1, keep, k, p) + dp_T0[arg1] = 1.0; + #if defined(_INDO_) + #if defined(_INDOPRO_) + ind_dom[arg1][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[arg1] = opind++; + #endif + #else + #if !defined(_ZOS_) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + + FOR_0_LE_l_LT_pk TARG1_INC = 0; + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif + break; + + case ref_assign_a: /* assign an adouble variable an assign_a */ + /* adouble value. (=) */ + arg = get_locint_f(); + res = get_locint_f(); + +#if !defined(_NTIGHT_) + arg1 = (size_t)trunc(fabs(dp_T0[res])); + IF_KEEP_WRITE_TAYLOR(arg1, keep, k, p) + dp_T0[arg1] = dp_T0[arg]; + #if defined(_INDO_) + #if defined(_INDOPRO_) + copy_index_domain(arg1, arg, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[arg1] = arg_index[arg]; + #endif + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + + FOR_0_LE_l_LT_pk TARG1_INC = TARG_INC; + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - break; - - case ref_assign_ind: /* assign an adouble variable an assign_ind */ - /* independent double value (<<=) */ - arg = get_locint_f(); - - -#if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] = basepoint[indexi]; -#if defined(_INDO_) -#if defined(_INDOPRO_) - ind_dom[res][0] = 1; - ind_dom[res][2] = indexi; -#endif -#if defined(_NONLIND_) - fod[opind].entry = indexi; - fod[opind].left = NULL; - fod[opind].right = NULL; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_p - TRES_INC = ARGUMENT(indexi,l,i); -#else - FOR_0_LE_l_LT_p - FOR_0_LE_i_LT_k - TRES_INC = ARGUMENT(indexi,l,i); -#endif -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + break; + + case ref_assign_ind: /* assign an adouble variable an assign_ind */ + /* independent double value (<<=) */ + arg = get_locint_f(); + +#if !defined(_NTIGHT_) + res = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] = basepoint[indexi]; + #if defined(_INDO_) + #if defined(_INDOPRO_) + ind_dom[res][0] = 1; + ind_dom[res][2] = indexi; + #endif + #if defined(_NONLIND_) + fod[opind].entry = indexi; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[res] = opind++; + #endif + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_p TRES_INC = ARGUMENT(indexi, l, i); + #else + FOR_0_LE_l_LT_p FOR_0_LE_i_LT_k TRES_INC = ARGUMENT(indexi, l, i); + #endif + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - ++indexi; - break; + ++indexi; + break; - case ref_eq_plus_d: /* Add a floating point to an eq_plus_d */ - /* adouble. (+=) */ - arg = get_locint_f(); + case ref_eq_plus_d: /* Add a floating point to an eq_plus_d */ + /* adouble. (+=) */ + arg = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); - + get_val_f(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] += coval; + res = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] += coval; #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - /*--------------------------------------------------------------------------*/ - case ref_eq_plus_p: /* Add a floating point to an eq_plus_p */ - /* adouble. (+=) */ - arg1 = get_locint_f(); - arg = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case ref_eq_plus_p: /* Add a floating point to an eq_plus_p */ + /* adouble. (+=) */ + arg1 = get_locint_f(); + arg = get_locint_f(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; #endif #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] += coval; + res = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] += coval; #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case ref_eq_plus_a: /* Add an adouble to another eq_plus_a */ - /* adouble. (+=) */ - arg = get_locint_f(); - arg1 = get_locint_f(); - -#if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg1])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] += dp_T0[arg]; -#if defined(_INDO_) -#if defined(_INDOPRO_) - merge_2_index_domains(res, arg, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[res]]; - fod[opind].right = &fod[arg_index[arg]]; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) - -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_pk - TRES_INC |= TARG_INC; -#else - FOR_0_LE_l_LT_pk - TRES_INC += TARG_INC; -#endif -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + break; + + /*--------------------------------------------------------------------------*/ + case ref_eq_plus_a: /* Add an adouble to another eq_plus_a */ + /* adouble. (+=) */ + arg = get_locint_f(); + arg1 = get_locint_f(); + +#if !defined(_NTIGHT_) + res = (size_t)trunc(fabs(dp_T0[arg1])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] += dp_T0[arg]; + #if defined(_INDO_) + #if defined(_INDOPRO_) + merge_2_index_domains(res, arg, ind_dom); + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[res]]; + fod[opind].right = &fod[arg_index[arg]]; + arg_index[res] = opind++; + #endif + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_pk TRES_INC |= TARG_INC; + #else + FOR_0_LE_l_LT_pk TRES_INC += TARG_INC; + #endif + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - case ref_eq_min_d: /* Subtract a floating point from an eq_min_d */ - /* adouble. (-=) */ - arg = get_locint_f(); + case ref_eq_min_d: /* Subtract a floating point from an eq_min_d */ + /* adouble. (-=) */ + arg = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] -= coval; + res = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] -= coval; #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; + break; - case ref_eq_min_p: /* Subtract a floating point from an eq_min_p */ - /* adouble. (-=) */ - arg1 = get_locint_f(); - arg = get_locint_f(); + case ref_eq_min_p: /* Subtract a floating point from an eq_min_p */ + /* adouble. (-=) */ + arg1 = get_locint_f(); + arg = get_locint_f(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; #endif #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] -= coval; + res = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] -= coval; #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* !_NTIGHT_ */ - break; - - /*--------------------------------------------------------------------------*/ - case ref_eq_min_a: /* Subtract an adouble from another eq_min_a */ - /* adouble. (-=) */ - arg = get_locint_f(); - arg1 = get_locint_f(); - -#if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg1])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] -= dp_T0[arg]; -#if defined(_INDO_) -#if defined(_INDOPRO_) - merge_2_index_domains(res, arg, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[res]]; - fod[opind].right = &fod[arg_index[arg]]; - arg_index[res] = opind++; -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) - -#ifdef _INT_FOR_ - FOR_0_LE_l_LT_pk - TRES_INC |= TARG_INC; -#else - FOR_0_LE_l_LT_pk - TRES_INC -= TARG_INC; -#endif -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + break; + + /*--------------------------------------------------------------------------*/ + case ref_eq_min_a: /* Subtract an adouble from another eq_min_a */ + /* adouble. (-=) */ + arg = get_locint_f(); + arg1 = get_locint_f(); + +#if !defined(_NTIGHT_) + res = (size_t)trunc(fabs(dp_T0[arg1])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] -= dp_T0[arg]; + #if defined(_INDO_) + #if defined(_INDOPRO_) + merge_2_index_domains(res, arg, ind_dom); + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[res]]; + fod[opind].right = &fod[arg_index[arg]]; + arg_index[res] = opind++; + #endif + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_pk TRES_INC |= TARG_INC; + #else + FOR_0_LE_l_LT_pk TRES_INC -= TARG_INC; + #endif + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - case ref_eq_mult_d: /* Multiply an adouble by a eq_mult_d */ - /* floating point. (*=) */ - arg = get_locint_f(); + case ref_eq_mult_d: /* Multiply an adouble by a eq_mult_d */ + /* floating point. (*=) */ + arg = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] *= coval; -#if !defined(_INDO_) -#if !defined(_ZOS_) /* BREAK_ZOS */ -#if !defined( _INT_FOR_) + res = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] *= coval; + #if !defined(_INDO_) + #if !defined(_ZOS_) /* BREAK_ZOS */ + #if !defined(_INT_FOR_) - FOR_0_LE_l_LT_pk - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + FOR_0_LE_l_LT_pk ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - FOR_0_LE_l_LT_pk - TRES_INC *= coval; -#endif -#endif -#endif + FOR_0_LE_l_LT_pk TRES_INC *= coval; + #endif + #endif + #endif #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - case ref_eq_mult_p: /* Multiply an adouble by a eq_mult_p */ - /* floating point. (*=) */ - arg1 = get_locint_f(); - arg = get_locint_f(); + case ref_eq_mult_p: /* Multiply an adouble by a eq_mult_p */ + /* floating point. (*=) */ + arg1 = get_locint_f(); + arg = get_locint_f(); #if !defined(_NTIGHT_) - coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; + coval = ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[arg1]; #endif #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - dp_T0[res] *= coval; -#if !defined(_INDO_) -#if !defined(_ZOS_) /* BREAK_ZOS */ -#if !defined( _INT_FOR_) + res = (size_t)trunc(fabs(dp_T0[arg])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + dp_T0[res] *= coval; + #if !defined(_INDO_) + #if !defined(_ZOS_) /* BREAK_ZOS */ + #if !defined(_INT_FOR_) - FOR_0_LE_l_LT_pk - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + FOR_0_LE_l_LT_pk ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - FOR_0_LE_l_LT_pk - TRES_INC *= coval; -#endif -#endif -#endif + FOR_0_LE_l_LT_pk TRES_INC *= coval; + #endif + #endif + #endif #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - break; - - case ref_eq_mult_a: /* Multiply one adouble by another eq_mult_a */ - /* (*=) */ - arg = get_locint_f(); - arg1 = get_locint_f(); - -#if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg1])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) -#if defined(_INDO_) -#if defined(_INDOPRO_) - merge_2_index_domains(res, arg, ind_dom); -#endif -#if defined(_NONLIND_) - fod[opind].entry = maxopind+2; - fod[opind].left = &fod[arg_index[res]]; - fod[opind].right = &fod[arg_index[arg]]; - traverse_unary(&fod[arg_index[res]], nonl_dom, &fod[arg_index[arg]], indcheck+1,maxopind+2); - traverse_unary(&fod[arg_index[arg]], nonl_dom, &fod[arg_index[res]], indcheck+1,maxopind+2); - arg_index[res] = opind++; -#endif -#if defined(_NONLIND_OLD_) - extend_nonlinearity_domain_binary(res, arg, ind_dom, nonl_dom); -#endif -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) - - INC_pk_1(Tres) - INC_pk_1(Targ) - -#ifdef _INT_FOR_ - FOR_p_GT_l_GE_0 - TRES_FODEC |= TARG_DEC; -#else - FOR_p_GT_l_GE_0 - FOR_k_GT_i_GE_0 - { TRES_FODEC = dp_T0[res]*TARG_DEC + - TRES*dp_T0[arg]; - DEC_TRES_FO -#ifdef _HIGHER_ORDER_ - TresOP = Tres-i; - TargOP = Targ; - - for (int j=0;j 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg1]; -#endif - } else { - if (coval > 0.0) - MINDEC(ret_c,2); - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); - dp_T0[res] = dp_T0[arg2]; - -#if defined(_INDOPRO_) - copy_index_domain(res, arg2, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg2]; -#endif - } -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) -#endif /* ALL_TOGETHER_AGAIN */ - -#ifdef _INT_FOR_ - coval = get_val_f(); - - if (dp_T0[arg] > 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - else - FOR_0_LE_l_LT_pk - TRES_INC = TARG2_INC; - - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else { - if (coval > 0.0) - MINDEC(ret_c,2); - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); - dp_T0[res] = dp_T0[arg2]; - } - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC | TARG2_INC; -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - if (dp_T0[arg] > 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - else - FOR_0_LE_l_LT_pk - TRES_INC = TARG2_INC; -#endif - - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else { - if (coval > 0.0) - MINDEC(ret_c,2); - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); - dp_T0[res] = dp_T0[arg2]; - } -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* ALL_TOGETHER_AGAIN */ - } - break; - - case ref_cond_eq_assign: /* cond_eq_assign */ - arg = get_locint_f(); - arg1 = get_locint_f(); - arg2 = get_locint_f(); - { -#if !defined(_NTIGHT_) - locint ref = -#endif - get_locint_f(); -#if !defined(_NTIGHT_) - coval = -#endif - get_val_f(); -#if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[ref])); - - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) - - /* olvo 980924 changed order to allow reflexive ops */ -#if defined(_INDO_) - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg1]; -#endif - } else { - if (coval >= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg2]; - -#if defined(_INDOPRO_) - copy_index_domain(res, arg2, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg2]; -#endif - } -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) - ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) -#endif /* ALL_TOGETHER_AGAIN */ - -#ifdef _INT_FOR_ - coval = get_val_f(); - - if (dp_T0[arg] >= 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - else - FOR_0_LE_l_LT_pk - TRES_INC = TARG2_INC; - - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else { - if (coval >= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg2]; - } - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC | TARG2_INC; -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - if (dp_T0[arg] >= 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; - else - FOR_0_LE_l_LT_pk - TRES_INC = TARG2_INC; -#endif - - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else { - if (coval >= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg2]; - } -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); -#endif /* ALL_TOGETHER_AGAIN */ - } - break; + } - case ref_cond_assign_s: /* cond_assign_s */ - arg = get_locint_f(); - arg1 = get_locint_f(); - arg2 = get_locint_f(); + break; + + case vec_dot: + arg1 = get_locint_f(); + arg2 = get_locint_f(); + size = get_locint_f(); + res = get_locint_f(); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p); #if !defined(_NTIGHT_) - coval = + dp_T0[res] = 0; #endif - get_val_f(); - +#if defined(_INDO_) + #if defined(_INDOPRO_) + ind_dom[res][0] = 0; + #endif + #if defined(_NONLIND_) + fod[opind].entry = maxopind + 2; + fod[opind].left = NULL; + fod[opind].right = NULL; + arg_index[res] = opind++; + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + + FOR_0_LE_l_LT_pk TRES_INC = 0; + #endif +#endif /* ALL_TOGETHER_AGAIN */ + for (qq = 0; qq < size; qq++) { +#if defined(_INDO_) + #if defined(_INDOPRO_) + merge_3_index_domains(res, arg1 + qq, arg2 + qq, ind_dom); + #endif + #if defined(_NONLIND_) + // operation: v = v+u*w + // first step: z = u*w, index domains + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[arg1 + qq]]; + fod[opind].right = &fod[arg_index[arg2 + qq]]; + // first step: z = u*w, + traverse_unary(&fod[arg_index[arg1 + qq]], nonl_dom, &fod[opind], + indcheck + 1, maxopind + 2); + traverse_unary(&fod[arg_index[arg2 + qq]], nonl_dom, &fod[opind], + indcheck + 1, maxopind + 2); + opind++; + // second step: v = v+z, index domains + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[res]]; + fod[opind].right = &fod[opind - 1]; + // second step: v = v+z, + arg_index[res] = opind++; + #endif + #if defined(_NONLIND_OLD_) + extend_nonlinearity_domain_binary(arg1 + qq, arg2 + qq, ind_dom, + nonl_dom); + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1 + qq]) + ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2 + qq]) + + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_p TRES_FOINC |= TARG2_INC | TARG1_INC; + #else + /* olvo 980915 now in reverse order to allow x = x*x etc. */ + INC_pk_1(Tres) INC_pk_1(Targ1) INC_pk_1(Targ2) + + FOR_p_GT_l_GE_0 FOR_k_GT_i_GE_0 { + TRES_FODEC += + dp_T0[arg1 + qq] * TARG2_DEC + TARG1_DEC * dp_T0[arg2 + qq]; + DEC_TRES_FO + #if defined(_HIGHER_ORDER_) + Targ1OP = Targ1 - i + 1; + Targ2OP = Targ2; + + for (int j = 0; j < i; j++) + *Tres += (*Targ1OP++) * (*Targ2OP--); + Tres--; + #endif /* _HIGHER_ORDER_ */ + } + #endif + #endif +#endif /* ALL_TOGETHER_AGAIN */ #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg2])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + dp_T0[res] += dp_T0[arg1 + qq] * dp_T0[arg2 + qq]; +#endif /* !_NTIGHT_ */ + } + break; - /* olvo 980924 changed order to allow reflexive ops */ + case vec_axpy: + arg = get_locint_f(); + arg1 = get_locint_f(); + arg2 = get_locint_f(); + size = get_locint_f(); + res = get_locint_f(); + + for (qq = 0; qq < size; qq++) { + IF_KEEP_WRITE_TAYLOR(res + qq, keep, k, p); #if defined(_INDO_) - if (dp_T0[arg] > 0) { -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg1]; -#endif - } -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + #if defined(_INDOPRO_) + combine_2_index_domains(res + qq, arg, arg1 + qq, ind_dom); + merge_2_index_domains(res + qq, arg2 + qq, ind_dom); + #endif + #if defined(_NONLIND_) + // operation: v = u*w + y + // first step: z = u*w, index domains + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[arg_index[arg]]; + fod[opind].right = &fod[arg_index[arg1 + qq]]; + // first step: z = u*w, + traverse_unary(&fod[arg_index[arg]], nonl_dom, &fod[opind], + indcheck + 1, maxopind + 2); + traverse_unary(&fod[arg_index[arg1 + qq]], nonl_dom, &fod[opind], + indcheck + 1, maxopind + 2); + opind++; + // second step: v = z+y, index domains + fod[opind].entry = maxopind + 2; + fod[opind].left = &fod[opind - 1]; + fod[opind].right = &fod[arg_index[arg2 + qq]]; + // second step: v = v+z, + arg_index[res + qq] = opind++; + #endif + #if defined(_NONLIND_OLD_) + extend_nonlinearity_domain_binary(arg, arg1 + qq, ind_dom, nonl_dom); + #endif +#else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Targ, TAYLOR_BUFFER[arg]) + ASSIGN_T(Tres, TAYLOR_BUFFER[res + qq]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1 + qq]) + ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2 + qq]) + #ifdef _INT_FOR_ + FOR_0_LE_l_LT_p TRES_FOINC = TARG2_INC | TARG1_INC | TARG_INC; + #else + INC_pk_1(Tres) INC_pk_1(Targ) INC_pk_1(Targ1) INC_pk_1(Targ2) + FOR_p_GT_l_GE_0 FOR_k_GT_i_GE_0 { + TRES_FODEC = + dp_T0[arg] * TARG1_DEC + TARG_DEC * dp_T0[arg1 + qq] + TARG2_DEC; + DEC_TRES_FO + #if defined(_HIGHER_ORDER_) + Targ1OP = Targ - i + 1; + Targ2OP = Targ1; + + for (int j = 0; j < i; j++) { + *Tres += (*Targ1OP++) * (*Targ2OP--); + } + Tres--; + #endif /* _HIGHER_ORDER_ */ + } + #endif + #endif #endif /* ALL_TOGETHER_AGAIN */ +#if !defined(_NTIGHT_) + dp_T0[res + qq] = dp_T0[arg] * dp_T0[arg1 + qq] + dp_T0[arg2 + qq]; +#endif /* !_NTIGHT_ */ + } + break; -#ifdef _INT_FOR_ - coval = get_val_f(); - - if (dp_T0[arg] > 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; + case ref_cond_assign: /* cond_assign */ + arg = get_locint_f(); + arg1 = get_locint_f(); + arg2 = get_locint_f(); + { +#if !defined(_NTIGHT_) + locint ref = +#endif + get_locint_f(); +#if !defined(_NTIGHT_) + coval = +#endif + get_val_f(); +#if !defined(_NTIGHT_) + res = (size_t)trunc(fabs(dp_T0[ref])); + + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + + /* olvo 980924 changed order to allow reflexive ops */ + #if defined(_INDO_) + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + + #if defined(_INDOPRO_) + copy_index_domain(res, arg1, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg1]; + #endif + } else { + if (coval > 0.0) + MINDEC(ret_c, 2); + if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + dp_T0[res] = dp_T0[arg2]; + + #if defined(_INDOPRO_) + copy_index_domain(res, arg2, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg2]; + #endif + } + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) + #endif /* ALL_TOGETHER_AGAIN */ + + #ifdef _INT_FOR_ + coval = get_val_f(); + + if (dp_T0[arg] > 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + else + FOR_0_LE_l_LT_pk TRES_INC = TARG2_INC; + + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else { + if (coval > 0.0) + MINDEC(ret_c, 2); + if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + dp_T0[res] = dp_T0[arg2]; + } + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC | TARG2_INC; + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + if (dp_T0[arg] > 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + else + FOR_0_LE_l_LT_pk TRES_INC = TARG2_INC; + #endif + + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else { + if (coval > 0.0) + MINDEC(ret_c, 2); + if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + dp_T0[res] = dp_T0[arg2]; + } + #endif + #endif +#else + fprintf(DIAG_OUT, + "ADOL-C error: active vector element referencing does not work " + "in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); +#endif /* ALL_TOGETHER_AGAIN */ + } + break; - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - if (dp_T0[arg] > 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; -#endif - if (dp_T0[arg] > 0) { - if (coval <= 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } else - if (dp_T0[arg] == 0) - MINDEC(ret_c,0); -#endif -#endif -#else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + case ref_cond_eq_assign: /* cond_eq_assign */ + arg = get_locint_f(); + arg1 = get_locint_f(); + arg2 = get_locint_f(); + { +#if !defined(_NTIGHT_) + locint ref = +#endif + get_locint_f(); +#if !defined(_NTIGHT_) + coval = +#endif + get_val_f(); +#if !defined(_NTIGHT_) + res = (size_t)trunc(fabs(dp_T0[ref])); + + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) + + /* olvo 980924 changed order to allow reflexive ops */ + #if defined(_INDO_) + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + + #if defined(_INDOPRO_) + copy_index_domain(res, arg1, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg1]; + #endif + } else { + if (coval >= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg2]; + + #if defined(_INDOPRO_) + copy_index_domain(res, arg2, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg2]; + #endif + } + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + ASSIGN_T(Targ2, TAYLOR_BUFFER[arg2]) + #endif /* ALL_TOGETHER_AGAIN */ + + #ifdef _INT_FOR_ + coval = get_val_f(); + + if (dp_T0[arg] >= 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + else + FOR_0_LE_l_LT_pk TRES_INC = TARG2_INC; + + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else { + if (coval >= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg2]; + } + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC | TARG2_INC; + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + if (dp_T0[arg] >= 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + else + FOR_0_LE_l_LT_pk TRES_INC = TARG2_INC; + #endif + + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else { + if (coval >= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg2]; + } + #endif + #endif +#else + fprintf(DIAG_OUT, + "ADOL-C error: active vector element referencing does not work " + "in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - break; + } + break; - case ref_cond_eq_assign_s: /* cond_eq_assign_s */ - arg = get_locint_f(); - arg1 = get_locint_f(); - arg2 = get_locint_f(); + case ref_cond_assign_s: /* cond_assign_s */ + arg = get_locint_f(); + arg1 = get_locint_f(); + arg2 = get_locint_f(); #if !defined(_NTIGHT_) - coval = + coval = #endif - get_val_f(); + get_val_f(); #if !defined(_NTIGHT_) - res = (size_t)trunc(fabs(dp_T0[arg2])); - IF_KEEP_WRITE_TAYLOR(res,keep,k,p) + res = (size_t)trunc(fabs(dp_T0[arg2])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) - /* olvo 980924 changed order to allow reflexive ops */ -#if defined(_INDO_) - if (dp_T0[arg] >= 0) { -#if defined(_INDOPRO_) - copy_index_domain(res, arg1, ind_dom); -#endif -#if defined(_NONLIND_) - arg_index[res] = arg_index[arg1]; -#endif - } -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - ASSIGN_T(Tres, TAYLOR_BUFFER[res]) - ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + /* olvo 980924 changed order to allow reflexive ops */ + #if defined(_INDO_) + if (dp_T0[arg] > 0) { + #if defined(_INDOPRO_) + copy_index_domain(res, arg1, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg1]; + #endif + } + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + #endif /* ALL_TOGETHER_AGAIN */ + + #ifdef _INT_FOR_ + coval = get_val_f(); + + if (dp_T0[arg] > 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + if (dp_T0[arg] > 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + #endif + if (dp_T0[arg] > 0) { + if (coval <= 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } else if (dp_T0[arg] == 0) + MINDEC(ret_c, 0); + #endif + #endif +#else + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ + break; -#ifdef _INT_FOR_ - coval = get_val_f(); + case ref_cond_eq_assign_s: /* cond_eq_assign_s */ + arg = get_locint_f(); + arg1 = get_locint_f(); + arg2 = get_locint_f(); +#if !defined(_NTIGHT_) + coval = +#endif + get_val_f(); - if (dp_T0[arg] >= 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; +#if !defined(_NTIGHT_) + res = (size_t)trunc(fabs(dp_T0[arg2])); + IF_KEEP_WRITE_TAYLOR(res, keep, k, p) - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } -#else -#if !defined(_ZOS_) /* BREAK_ZOS */ - if (dp_T0[arg] >= 0) - FOR_0_LE_l_LT_pk - TRES_INC = TARG1_INC; -#endif - if (dp_T0[arg] >= 0) { - if (coval < 0.0) - MINDEC(ret_c,2); - dp_T0[res] = dp_T0[arg1]; - } -#endif -#endif + /* olvo 980924 changed order to allow reflexive ops */ + #if defined(_INDO_) + if (dp_T0[arg] >= 0) { + #if defined(_INDOPRO_) + copy_index_domain(res, arg1, ind_dom); + #endif + #if defined(_NONLIND_) + arg_index[res] = arg_index[arg1]; + #endif + } + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + ASSIGN_T(Tres, TAYLOR_BUFFER[res]) + ASSIGN_T(Targ1, TAYLOR_BUFFER[arg1]) + #endif /* ALL_TOGETHER_AGAIN */ + + #ifdef _INT_FOR_ + coval = get_val_f(); + + if (dp_T0[arg] >= 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } + #else + #if !defined(_ZOS_) /* BREAK_ZOS */ + if (dp_T0[arg] >= 0) + FOR_0_LE_l_LT_pk TRES_INC = TARG1_INC; + #endif + if (dp_T0[arg] >= 0) { + if (coval < 0.0) + MINDEC(ret_c, 2); + dp_T0[res] = dp_T0[arg1]; + } + #endif + #endif #else - fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does not work in safe mode, please use tight mode\n"); - adolc_exit(-2,"",__func__,__FILE__,__LINE__); + fprintf(DIAG_OUT, "ADOL-C error: active vector element referencing does " + "not work in safe mode, please use tight mode\n"); + adolc_exit(-2, "", __func__, __FILE__, __LINE__); #endif /* ALL_TOGETHER_AGAIN */ - break; + break; - /****************************************************************************/ - /* REMAINING STUFF */ + /****************************************************************************/ + /* REMAINING + * STUFF */ - /*--------------------------------------------------------------------------*/ - case take_stock_op: /* take_stock_op */ - size = get_locint_f(); - res = get_locint_f(); + /*--------------------------------------------------------------------------*/ + case take_stock_op: /* take_stock_op */ + size = get_locint_f(); + res = get_locint_f(); #if !defined(_NTIGHT_) - d = + d = #endif - get_val_v_f(size); + get_val_v_f(size); - for (ls=0;lsADOLC_EXT_FCT_POINTER==NULL) - fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); - if (n>0) { - if (edfct->dp_x==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#if !defined(_ZOS_) - if (ADOLC_EXT_POINTER_X==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#endif - } - if (m>0) { - if (edfct->dp_y==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#if !defined(_ZOS_) - if (ADOLC_EXT_POINTER_Y==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#endif - } - - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; - for (loop=0; loopdp_x_changes) { - IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); - } - edfct->dp_x[loop]=dp_T0[arg]; -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_POINTER_X[loop],TAYLOR_BUFFER[arg]); -#endif - ++arg; - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; - for (loop=0; loopdp_y_priorRequired) { - IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); - } - edfct->dp_y[loop]=dp_T0[arg]; -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_POINTER_Y[loop],TAYLOR_BUFFER[arg]); -#endif - ++arg; - } - - ext_retc = edfct->ADOLC_EXT_FCT_COMPLETE; - MINDEC(ret_c, ext_retc); - - res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; - for (loop=0; loopdp_x[loop]; -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_POINTER_X[loop],TAYLOR_BUFFER[res]); -#endif - ++res; - } - res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; - for (loop=0; loopdp_y[loop]; -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_POINTER_Y[loop],TAYLOR_BUFFER[res]); -#endif - ++res; - } + case ext_diff: /* extern differentiated function */ + ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_f(); + n = get_locint_f(); + m = get_locint_f(); + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for = get_locint_f(); + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for = get_locint_f(); + ADOLC_CURRENT_TAPE_INFOS.cpIndex = get_locint_f(); + edfct = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + + if (edfct->ADOLC_EXT_FCT_POINTER == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); + if (n > 0) { + if (edfct->dp_x == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #if !defined(_ZOS_) + if (ADOLC_EXT_POINTER_X == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #endif + } + if (m > 0) { + if (edfct->dp_y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #if !defined(_ZOS_) + if (ADOLC_EXT_POINTER_Y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #endif + } - break; - - case ext_diff_iArr: /* extern differentiated function */ - iArrLength=get_locint_f(); - iArr=malloc(iArrLength*sizeof(int)); - for (loop=0;loopADOLC_EXT_FCT_IARR_POINTER==NULL) - fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); - if (n>0) { - if (edfct->dp_x==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#if !defined(_ZOS_) - if (ADOLC_EXT_POINTER_X==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#endif - } - if (m>0) { - if (edfct->dp_y==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#if !defined(_ZOS_) - if (ADOLC_EXT_POINTER_Y==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#endif - } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; + for (loop = 0; loop < n; ++loop) { + if (edfct->dp_x_changes) { + IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); + } + edfct->dp_x[loop] = dp_T0[arg]; + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_POINTER_X[loop], TAYLOR_BUFFER[arg]); + #endif + ++arg; + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; + for (loop = 0; loop < m; ++loop) { + if (edfct->dp_y_priorRequired) { + IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); + } + edfct->dp_y[loop] = dp_T0[arg]; + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_POINTER_Y[loop], TAYLOR_BUFFER[arg]); + #endif + ++arg; + } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; - for (loop=0; loopdp_x_changes) { - IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); - } - edfct->dp_x[loop]=dp_T0[arg]; -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_POINTER_X[loop],TAYLOR_BUFFER[arg]); -#endif - ++arg; - } - arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; - for (loop=0; loopdp_y_priorRequired) { - IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); - } - edfct->dp_y[loop]=dp_T0[arg]; -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_POINTER_Y[loop],TAYLOR_BUFFER[arg]); -#endif - ++arg; - } + ext_retc = edfct->ADOLC_EXT_FCT_COMPLETE; + MINDEC(ret_c, ext_retc); + + res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; + for (loop = 0; loop < n; ++loop) { + dp_T0[res] = edfct->dp_x[loop]; + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_POINTER_X[loop], + TAYLOR_BUFFER[res]); + #endif + ++res; + } + res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; + for (loop = 0; loop < m; ++loop) { + dp_T0[res] = edfct->dp_y[loop]; + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_POINTER_Y[loop], + TAYLOR_BUFFER[res]); + #endif + ++res; + } - ext_retc = edfct->ADOLC_EXT_FCT_IARR_COMPLETE; - MINDEC(ret_c, ext_retc); + break; + + case ext_diff_iArr: /* extern differentiated function */ + iArrLength = get_locint_f(); + iArr = malloc(iArrLength * sizeof(int)); + for (loop = 0; loop < iArrLength; ++loop) + iArr[loop] = get_locint_f(); + get_locint_f(); /* iArrLength again */ + ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_f(); + n = get_locint_f(); + m = get_locint_f(); + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for = get_locint_f(); + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for = get_locint_f(); + ADOLC_CURRENT_TAPE_INFOS.cpIndex = get_locint_f(); + edfct = get_ext_diff_fct(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + + if (edfct->ADOLC_EXT_FCT_IARR_POINTER == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); + if (n > 0) { + if (edfct->dp_x == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #if !defined(_ZOS_) + if (ADOLC_EXT_POINTER_X == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #endif + } + if (m > 0) { + if (edfct->dp_y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #if !defined(_ZOS_) + if (ADOLC_EXT_POINTER_Y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #endif + } - res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; - for (loop=0; loopdp_x[loop]; -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_POINTER_X[loop],TAYLOR_BUFFER[res]); -#endif - ++res; - } - res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; - for (loop=0; loopdp_y[loop]; -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_POINTER_Y[loop],TAYLOR_BUFFER[res]); -#endif - ++res; - } - free((void*)iArr); iArr=0; - break; - case ext_diff_v2: - ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index=get_locint_f(); - iArrLength = get_locint_f(); - iArr = malloc(iArrLength*sizeof(int)); - for (loop=0;loopADOLC_EXT_FCT_POINTER==NULL) - fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); - if (nin>0) { - if (edfct2->x == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#if !defined(_ZOS_) - if (ADOLC_EXT_V2_POINTER_X==NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#endif - } - if (nout>0) { - if (edfct2->y == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#if !defined(_ZOS_) - if (ADOLC_EXT_V2_POINTER_Y == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); -#endif - } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; + for (loop = 0; loop < n; ++loop) { + if (edfct->dp_x_changes) { + IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); + } + edfct->dp_x[loop] = dp_T0[arg]; + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_POINTER_X[loop], TAYLOR_BUFFER[arg]); + #endif + ++arg; + } + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; + for (loop = 0; loop < m; ++loop) { + if (edfct->dp_y_priorRequired) { + IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); + } + edfct->dp_y[loop] = dp_T0[arg]; + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_POINTER_Y[loop], TAYLOR_BUFFER[arg]); + #endif + ++arg; + } - for(oloop=0;oloopx[oloop][0],&dp_T0[arg],insz[oloop]*sizeof(double)); - for(loop=0;loopdp_x_changes) { - IF_KEEP_WRITE_TAYLOR(arg,keep,k,p); - } -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_V2_POINTER_X[oloop][loop],TAYLOR_BUFFER[arg]); -#endif - ++arg; - } - } - for(oloop=0;oloopy[oloop][0],&dp_T0[arg],outsz[oloop]*sizeof(double)); - for(loop=0;loopdp_y_priorRequired) { - IF_KEEP_WRITE_TAYLOR(arg,keep,k,p); - } -#if !defined(_ZOS_) - ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_V2_POINTER_Y[oloop][loop],TAYLOR_BUFFER[arg]); -#endif + ext_retc = edfct->ADOLC_EXT_FCT_IARR_COMPLETE; + MINDEC(ret_c, ext_retc); + + res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_for; + for (loop = 0; loop < n; ++loop) { + dp_T0[res] = edfct->dp_x[loop]; + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_POINTER_X[loop], + TAYLOR_BUFFER[res]); + #endif + ++res; + } + res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_for; + for (loop = 0; loop < m; ++loop) { + dp_T0[res] = edfct->dp_y[loop]; + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_POINTER_Y[loop], + TAYLOR_BUFFER[res]); + #endif + ++res; + } + free((void *)iArr); + iArr = 0; + break; + case ext_diff_v2: + ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_f(); + iArrLength = get_locint_f(); + iArr = malloc(iArrLength * sizeof(int)); + for (loop = 0; loop < iArrLength; ++loop) + iArr[loop] = get_locint_f(); + get_locint_f(); /* iArrLength again */ + nin = get_locint_f(); + nout = get_locint_f(); + insz = malloc(2 * (nin + nout) * sizeof(locint)); + outsz = insz + nin; + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = outsz + nout; + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = outsz + nout + nin; + for (loop = 0; loop < nin; ++loop) { + insz[loop] = get_locint_f(); + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[loop] = get_locint_f(); + } + for (loop = 0; loop < nout; ++loop) { + outsz[loop] = get_locint_f(); + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2[loop] = get_locint_f(); + } + get_locint_f(); /* nin again */ + get_locint_f(); /* nout again */ + edfct2 = get_ext_diff_fct_v2(ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index); + if (edfct2->ADOLC_EXT_FCT_POINTER == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); + if (nin > 0) { + if (edfct2->x == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #if !defined(_ZOS_) + if (ADOLC_EXT_V2_POINTER_X == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #endif + } + if (nout > 0) { + if (edfct2->y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #if !defined(_ZOS_) + if (ADOLC_EXT_V2_POINTER_Y == NULL) + fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); + #endif + } - ++arg; - } - } - ext_retc = edfct2->ADOLC_EXT_FCT_V2_COMPLETE; - MINDEC(ret_c,ext_retc); + for (oloop = 0; oloop < nin; ++oloop) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[oloop]; + memcpy(&edfct2->x[oloop][0], &dp_T0[arg], insz[oloop] * sizeof(double)); + for (loop = 0; loop < insz[oloop]; ++loop) { + if (edfct2->dp_x_changes) { + IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); + } + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_V2_POINTER_X[oloop][loop], + TAYLOR_BUFFER[arg]); + #endif + ++arg; + } + } + for (oloop = 0; oloop < nout; ++oloop) { + arg = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2[oloop]; + memcpy(&edfct2->y[oloop][0], &dp_T0[arg], + outsz[oloop] * sizeof(double)); + for (loop = 0; loop < outsz[oloop]; ++loop) { + if (edfct2->dp_y_priorRequired) { + IF_KEEP_WRITE_TAYLOR(arg, keep, k, p); + } + #if !defined(_ZOS_) + ADOLC_EXT_COPY_TAYLORS(ADOLC_EXT_V2_POINTER_Y[oloop][loop], + TAYLOR_BUFFER[arg]); + #endif - for(oloop=0;oloopx[oloop][0],insz[oloop]*sizeof(double)); -#if !defined(_ZOS_) - for(loop=0;loopADOLC_EXT_FCT_V2_COMPLETE; + MINDEC(ret_c, ext_retc); + + for (oloop = 0; oloop < nin; ++oloop) { + res = ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2[oloop]; + memcpy(&dp_T0[res], &edfct2->x[oloop][0], insz[oloop] * sizeof(double)); + #if !defined(_ZOS_) + for (loop = 0; loop < insz[oloop]; ++loop) { + ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_V2_POINTER_X[oloop][loop], + TAYLOR_BUFFER[res]); + ++res; + } + #endif + } - for(oloop=0;oloopy[oloop][0],outsz[oloop]*sizeof(double)); -#if !defined(_ZOS_) - for(loop=0;loopy[oloop][0], + outsz[oloop] * sizeof(double)); + #if !defined(_ZOS_) + for (loop = 0; loop < outsz[oloop]; ++loop) { + ADOLC_EXT_COPY_TAYLORS_BACK(ADOLC_EXT_V2_POINTER_Y[oloop][loop], + TAYLOR_BUFFER[res]); + ++res; + } + #endif + } - free(insz); - free(iArr); - insz = 0; - iArr = 0; - outsz = 0; - ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = 0; - ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = 0; - break; + free(insz); + free(iArr); + insz = 0; + iArr = 0; + outsz = 0; + ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = 0; + ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = 0; + break; #endif #ifdef ADOLC_MEDIPACK_SUPPORT - /*--------------------------------------------------------------------------*/ - case medi_call: { - locint mediIndex = get_locint_f(); - short tapeId = ADOLC_CURRENT_TAPE_INFOS.tapeID; - -#if defined(_ZOS_) - mediCallHandlePrimal(tapeId, mediIndex, dp_T0); -#elif defined(_FOS_) - mediCallHandleForward(tapeId, mediIndex, dp_T0, &TAYLOR_BUFFER, 1); -#elif defined(_FOV_) - mediCallHandleForward(tapeId, mediIndex, dp_T0, TAYLOR_BUFFER, p); -#endif - break; - } + /*--------------------------------------------------------------------------*/ + case medi_call: { + locint mediIndex = get_locint_f(); + short tapeId = ADOLC_CURRENT_TAPE_INFOS.tapeID; + + #if defined(_ZOS_) + mediCallHandlePrimal(tapeId, mediIndex, dp_T0); + #elif defined(_FOS_) + mediCallHandleForward(tapeId, mediIndex, dp_T0, &TAYLOR_BUFFER, 1); + #elif defined(_FOV_) + mediCallHandleForward(tapeId, mediIndex, dp_T0, TAYLOR_BUFFER, p); + #endif + break; + } #endif #ifdef ADOLC_AMPI_SUPPORT - /*--------------------------------------------------------------------------*/ - case ampi_send: { - ADOLC_TLM_AMPI_Send(buf, - count, - datatype, - src, - tag, - pairedWith, - comm); - break; - } - case ampi_recv: { - ADOLC_TLM_AMPI_Recv(buf, - count, - datatype, - src, - tag, - pairedWith, - comm, - &status); - break; - } - case ampi_isend: { - ADOLC_TLM_AMPI_Isend(buf, - count, - datatype, - src, - tag, - pairedWith, - comm, + /*--------------------------------------------------------------------------*/ + case ampi_send: { + ADOLC_TLM_AMPI_Send(buf, count, datatype, src, tag, pairedWith, comm); + break; + } + case ampi_recv: { + ADOLC_TLM_AMPI_Recv(buf, count, datatype, src, tag, pairedWith, comm, + &status); + break; + } + case ampi_isend: { + ADOLC_TLM_AMPI_Isend(buf, count, datatype, src, tag, pairedWith, comm, &request); - break; - } - case ampi_irecv: { - ADOLC_TLM_AMPI_Irecv(buf, - count, - datatype, - src, - tag, - pairedWith, - comm, + break; + } + case ampi_irecv: { + ADOLC_TLM_AMPI_Irecv(buf, count, datatype, src, tag, pairedWith, comm, &request); - break; - } - case ampi_wait: { - ADOLC_TLM_AMPI_Wait(&request, - &status); - break; - } - case ampi_barrier: { - ADOLC_TLM_AMPI_Barrier(comm); - break; - } - case ampi_gather: { - ADOLC_TLM_AMPI_Gather(buf, - count, - datatype, - rbuf, - rcount, - rtype, - src, + break; + } + case ampi_wait: { + ADOLC_TLM_AMPI_Wait(&request, &status); + break; + } + case ampi_barrier: { + ADOLC_TLM_AMPI_Barrier(comm); + break; + } + case ampi_gather: { + ADOLC_TLM_AMPI_Gather(buf, count, datatype, rbuf, rcount, rtype, src, comm); - break; - } - case ampi_scatter: { - ADOLC_TLM_AMPI_Scatter(rbuf, - rcount, - rtype, - buf, - count, - datatype, - src, + break; + } + case ampi_scatter: { + ADOLC_TLM_AMPI_Scatter(rbuf, rcount, rtype, buf, count, datatype, src, comm); - break; - } - case ampi_allgather: { - ADOLC_TLM_AMPI_Allgather(buf, - count, - datatype, - rbuf, - rcount, - rtype, - comm); - break; - } - case ampi_gatherv: { - ADOLC_TLM_AMPI_Gatherv(buf, - count, - datatype, - rbuf, - NULL, - NULL, - rtype, - src, + break; + } + case ampi_allgather: { + ADOLC_TLM_AMPI_Allgather(buf, count, datatype, rbuf, rcount, rtype, comm); + break; + } + case ampi_gatherv: { + ADOLC_TLM_AMPI_Gatherv(buf, count, datatype, rbuf, NULL, NULL, rtype, src, comm); - break; - } - case ampi_scatterv: { - ADOLC_TLM_AMPI_Scatterv(rbuf, - NULL, - NULL, - rtype, - buf, - count, - datatype, - src, - comm); - break; - } - case ampi_allgatherv: { - ADOLC_TLM_AMPI_Allgatherv(buf, - count, - datatype, - rbuf, - NULL, - NULL, - rtype, + break; + } + case ampi_scatterv: { + ADOLC_TLM_AMPI_Scatterv(rbuf, NULL, NULL, rtype, buf, count, datatype, + src, comm); + break; + } + case ampi_allgatherv: { + ADOLC_TLM_AMPI_Allgatherv(buf, count, datatype, rbuf, NULL, NULL, rtype, comm); - break; - } - case ampi_bcast: { - ADOLC_TLM_AMPI_Bcast(buf, - count, - datatype, - src, - comm); - break; - } - case ampi_reduce: { - ADOLC_TLM_AMPI_Reduce(buf, - rbuf, - count, - datatype, - op, - src, - comm); - break; - } - case ampi_allreduce: { - ADOLC_TLM_AMPI_Allreduce(buf, - rbuf, - count, - datatype, - op, - comm); - break; - } + break; + } + case ampi_bcast: { + ADOLC_TLM_AMPI_Bcast(buf, count, datatype, src, comm); + break; + } + case ampi_reduce: { + ADOLC_TLM_AMPI_Reduce(buf, rbuf, count, datatype, op, src, comm); + break; + } + case ampi_allreduce: { + ADOLC_TLM_AMPI_Allreduce(buf, rbuf, count, datatype, op, comm); + break; + } #endif - /*--------------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------*/ - default: /* default */ - /* Die here, we screwed up */ + default: /* default */ + /* Die here, we screwed up */ - fprintf(DIAG_OUT,"ADOL-C fatal error in " GENERATED_FILENAME " (" - __FILE__ - ") : no such operation %d\n", operation); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - break; + fprintf(DIAG_OUT, + "ADOL-C fatal error in " GENERATED_FILENAME " (" __FILE__ + ") : no such operation %d\n", + operation); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + break; - } /* endswitch */ + } /* endswitch */ - /* Read the next operation */ - operation=get_op_f(); + /* Read the next operation */ + operation = get_op_f(); #if defined(ADOLC_DEBUG) - ++countPerOperation[operation]; + ++countPerOperation[operation]; #endif /* ADOLC_DEBUG */ - } /* endwhile */ - + } /* endwhile */ #if defined(ADOLC_DEBUG) - printf("\nTape contains:\n"); - for (v = 0; v < 256; ++v) - if (countPerOperation[v] > 0) - printf("operation %3d: %6d time(s) - %6d taylors written (%10.2f per operation)\n", v, countPerOperation[v], taylorPerOperation[v], (double)taylorPerOperation[v] / (double)countPerOperation[v]); - printf("\n"); + printf("\nTape contains:\n"); + for (v = 0; v < 256; ++v) + if (countPerOperation[v] > 0) + printf("operation %3d: %6d time(s) - %6d taylors written (%10.2f per " + "operation)\n", + v, countPerOperation[v], taylorPerOperation[v], + (double)taylorPerOperation[v] / (double)countPerOperation[v]); + printf("\n"); #endif /* ADOLC_DEBUG */ #if defined(_KEEP_) - if (keep) - taylor_close(true); + if (keep) + taylor_close(true); #endif /* clean up */ -#if !defined (_NTIGHT_) - free(dp_T0); +#if !defined(_NTIGHT_) + free(dp_T0); #endif /* !_NTIGHT_ */ #if !defined(_INDO_) -#if !defined(_ZOS_) -# if defined(_FOS_) - free(dp_T); -# else -#if !defined (_INT_FOR_) - myfree2(dpp_T); - free(dp_Ttemp); -#endif /* !_NTIGHT_ */ -#endif -#endif + #if !defined(_ZOS_) + #if defined(_FOS_) + free(dp_T); + #else + #if !defined(_INT_FOR_) + myfree2(dpp_T); + free(dp_Ttemp); + #endif /* !_NTIGHT_ */ + #endif + #endif #endif #if defined(_HIGHER_ORDER_) - free(dp_z); + free(dp_z); #endif - ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; - end_sweep(); - + ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; + end_sweep(); #if defined(_INDO_) -#if defined(_INDOPRO_) - for(int i=0;ientry; - temp1 = temp->left; - free(temp); - temp = temp1; - } + #if defined(_INDOPRO_) + for (int i = 0; i < max_ind_dom; i++) { + free(ind_dom[i]); + } + free(ind_dom); + #endif + #if defined(_NONLIND_) + for (int i = 0; i < indcheck; i++) { + traverse_crs(&nonl_dom[i], &sod[i], indcheck + 1); + free_tree(&nonl_dom[i], indcheck + 1); + crs[i] = (unsigned int *)malloc(sizeof(unsigned int) * (sod[i].entry + 1)); + crs[i][0] = sod[i].entry; + temp = sod[i].left; + for (int ii = 1; ii <= sod[i].entry; ii++) { + crs[i][ii] = temp->entry; + temp1 = temp->left; + free(temp); + temp = temp1; } + } - free(sod); - free(nonl_dom); - free(fod); - free(arg_index); + free(sod); + free(nonl_dom); + free(fod); + free(arg_index); -#endif -#if defined(_NONLIND_OLD_) + #endif + #if defined(_NONLIND_OLD_) - for(int i=0; i < indcheck; i++) { - crs[i] = (unsigned int*) malloc(sizeof(unsigned int) * (nonl_dom[i][0]+1)); - crs[i][0] = nonl_dom[i][0]; - for(l=1; l < crs[i][0]+1; l++) - crs[i][l] = nonl_dom[i][l+1]; - free(nonl_dom[i]); - } - free(nonl_dom); + for (int i = 0; i < indcheck; i++) { + crs[i] = + (unsigned int *)malloc(sizeof(unsigned int) * (nonl_dom[i][0] + 1)); + crs[i][0] = nonl_dom[i][0]; + for (l = 1; l < crs[i][0] + 1; l++) + crs[i][l] = nonl_dom[i][l + 1]; + free(nonl_dom[i]); + } + free(nonl_dom); + #endif #endif -#endif - return ret_c; + return ret_c; } - /****************************************************************************/ #if defined(_ZOS_) && defined(_ABS_NORM_) int get_num_switches(short tapeID) { - int nswitch; - ADOLC_OPENMP_THREAD_NUMBER; - ADOLC_OPENMP_GET_THREAD_NUMBER; - - init_for_sweep(tapeID); - if (!ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) { - fprintf(DIAG_OUT,"ADOL-C error: tape %d was not created compatible " - "with %s\n Please call enableMinMaxUsingAbs() " - "before trace_on(%d)\n", tapeID, __FUNCTION__, tapeID); - adolc_exit(-1,"",__func__,__FILE__,__LINE__); - } - nswitch = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]; - end_sweep(); - return nswitch; + int nswitch; + ADOLC_OPENMP_THREAD_NUMBER; + ADOLC_OPENMP_GET_THREAD_NUMBER; + + init_for_sweep(tapeID); + if (!ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) { + fprintf(DIAG_OUT, + "ADOL-C error: tape %d was not created compatible " + "with %s\n Please call enableMinMaxUsingAbs() " + "before trace_on(%d)\n", + tapeID, __FUNCTION__, tapeID); + adolc_exit(-1, "", __func__, __FILE__, __LINE__); + } + nswitch = ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]; + end_sweep(); + return nswitch; } #endif #if defined(_ABS_NORM_) && defined(_FOV_) -short firstsign(int p, double *u, double* du) { - int i=0; - short tmp; - tmp=((*u)>1e-12)?1.0:(((*u)<-1e-12)?-1.0:0.0); - while(i

0.0)?1.0:((du[i]<0.0)?-1.0:0.0); - i++; - } - return tmp; +short firstsign(int p, double *u, double *du) { + int i = 0; + short tmp; + tmp = ((*u) > 1e-12) ? 1.0 : (((*u) < -1e-12) ? -1.0 : 0.0); + while (i < p && tmp == 0.0) { + tmp = (du[i] > 0.0) ? 1.0 : ((du[i] < 0.0) ? -1.0 : 0.0); + i++; + } + return tmp; } #elif defined(_ABS_NORM_SIG_) && defined(_FOV_) -short ext_firstsign(double sigbase, double sigdir, int p, double *u, double* du) { - if (sigbase == 0 && sigdir > 0) { - du[0] = fmax(0,du[0]); - *u = 0; - } - else if (sigbase == 0 && sigdir < 0) { - du[0] = fmin(0,du[0]); - *u =0; - } - else if (sigbase == 0 && sigdir == 0) { - du[0] = 0; - *u = 0; - } - return firstsign(p,u,du); +short ext_firstsign(double sigbase, double sigdir, int p, double *u, + double *du) { + if (sigbase == 0 && sigdir > 0) { + du[0] = fmax(0, du[0]); + *u = 0; + } else if (sigbase == 0 && sigdir < 0) { + du[0] = fmin(0, du[0]); + *u = 0; + } else if (sigbase == 0 && sigdir == 0) { + du[0] = 0; + *u = 0; + } + return firstsign(p, u, du); } -short ext_firstsign2(double sigbase, int p, double *u, double* du) { - if (sigbase == 0) - *u=0; - return firstsign(p,u,du); +short ext_firstsign2(double sigbase, int p, double *u, double *du) { + if (sigbase == 0) + *u = 0; + return firstsign(p, u, du); } #endif /****************************************************************************/ @@ -6801,315 +6612,276 @@ short ext_firstsign2(double sigbase, int p, double *u, double* du) { /*--------------------------------------------------------------------------*/ /* operations on index domains */ -#if defined(_TIGHT_) + #if defined(_TIGHT_) void copy_index_domain(int res, int arg, locint **ind_dom) { - int i; - - if (ind_dom[arg][0] > ind_dom[res][1]) - { - free(ind_dom[res]); - ind_dom[res] = (locint *) malloc(sizeof(locint) * 2*(ind_dom[arg][0]+1)); - ind_dom[res][1] = 2*ind_dom[arg][0]; - } + int i; + if (ind_dom[arg][0] > ind_dom[res][1]) { + free(ind_dom[res]); + ind_dom[res] = (locint *)malloc(sizeof(locint) * 2 * (ind_dom[arg][0] + 1)); + ind_dom[res][1] = 2 * ind_dom[arg][0]; + } - for(i=2;ileft != NULL) - { - free_tree(tree->left,num); - } - if (tree->right != NULL) - { - free_tree(tree->right,num); - } - { - if (tree->entry == num) - free(tree); - - } - + #if defined(_TIGHT_) + +void free_tree(IndexElement *tree, int num) { + + if (tree->left != NULL) { + free_tree(tree->left, num); + } + if (tree->right != NULL) { + free_tree(tree->right, num); + } + { + if (tree->entry == num) + free(tree); + } } -void traverse_crs(IndexElement* tree, IndexElement_sod* sod, int num) -{ +void traverse_crs(IndexElement *tree, IndexElement_sod *sod, int num) { IndexElement_sod *temp, *temp1; - if (tree->left != NULL) - { - traverse_crs(tree->left, sod, num); - } - if (tree->right != NULL) - { - traverse_crs(tree->right, sod, num); - } - if (tree->entry < num) - { - temp = sod->left; - if (temp == NULL) - { - temp = (struct IndexElement_sod*) malloc(sizeof(struct IndexElement_sod)); - temp->left = NULL; - temp->entry = tree->entry; - sod->entry++; - sod->left=temp; - } - else - { - while ((temp->entry < tree->entry) && (temp->left != NULL)) - { - temp1 = temp; - temp = temp->left; - } - if (temp->left == NULL) - { - if(temp->entry < tree->entry) - { - temp->left = (struct IndexElement_sod*) malloc(sizeof(struct IndexElement_sod)); - temp = temp->left; - temp->left = NULL; - temp->entry = tree->entry; - sod->entry++; - } - if(temp->entry > tree->entry) - { - temp->left = (struct IndexElement_sod*) malloc(sizeof(struct IndexElement_sod)); - temp->left->entry = temp->entry; - temp->left->left = NULL; - temp->entry = tree->entry; - sod->entry++; - } - } - else - { - if (temp->entry > tree->entry) - { - temp1 = (struct IndexElement_sod*) malloc(sizeof(struct IndexElement_sod)); - temp1->left = temp->left; - temp1->entry = temp->entry; - temp->entry = tree->entry; - temp->left=temp1; - sod->entry++; - } - - } - } + if (tree->left != NULL) { + traverse_crs(tree->left, sod, num); + } + if (tree->right != NULL) { + traverse_crs(tree->right, sod, num); + } + if (tree->entry < num) { + temp = sod->left; + if (temp == NULL) { + temp = (struct IndexElement_sod *)malloc(sizeof(struct IndexElement_sod)); + temp->left = NULL; + temp->entry = tree->entry; + sod->entry++; + sod->left = temp; + } else { + while ((temp->entry < tree->entry) && (temp->left != NULL)) { + temp1 = temp; + temp = temp->left; + } + if (temp->left == NULL) { + if (temp->entry < tree->entry) { + temp->left = (struct IndexElement_sod *)malloc( + sizeof(struct IndexElement_sod)); + temp = temp->left; + temp->left = NULL; + temp->entry = tree->entry; + sod->entry++; + } + if (temp->entry > tree->entry) { + temp->left = (struct IndexElement_sod *)malloc( + sizeof(struct IndexElement_sod)); + temp->left->entry = temp->entry; + temp->left->left = NULL; + temp->entry = tree->entry; + sod->entry++; + } + } else { + if (temp->entry > tree->entry) { + temp1 = (struct IndexElement_sod *)malloc( + sizeof(struct IndexElement_sod)); + temp1->left = temp->left; + temp1->entry = temp->entry; + temp->entry = tree->entry; + temp->left = temp1; + sod->entry++; + } + } } + } } -void traverse_unary(IndexElement* tree, IndexElement* nonl_dom, IndexElement* fodi, int num, int maxopind) -{ +void traverse_unary(IndexElement *tree, IndexElement *nonl_dom, + IndexElement *fodi, int num, int maxopind) { IndexElement *temp; - if (tree->left != NULL) - { - traverse_unary(tree->left, nonl_dom, fodi, num, maxopind); - if (tree->right != NULL) - { - traverse_unary(tree->right, nonl_dom, fodi, num, maxopind); - } - } - else - { - if(tree->entryright = fodi; - temp->left = nonl_dom[tree->entry].left; - temp->entry= num; - nonl_dom[tree->entry].left = temp; - } + if (tree->left != NULL) { + traverse_unary(tree->left, nonl_dom, fodi, num, maxopind); + if (tree->right != NULL) { + traverse_unary(tree->right, nonl_dom, fodi, num, maxopind); + } + } else { + if (tree->entry < maxopind) { + temp = (struct IndexElement *)malloc(sizeof(struct IndexElement)); + temp->right = fodi; + temp->left = nonl_dom[tree->entry].left; + temp->entry = num; + nonl_dom[tree->entry].left = temp; } + } } -#endif + #endif #endif #if defined(_NONLIND_OLD_) -#if defined(_TIGHT_) + #if defined(_TIGHT_) -void extend_nonlinearity_domain_binary_step -(int arg1, int arg2, locint **ind_dom, locint **nonl_dom) -{ - int index,num,num1, num2, i,j,k,l,m; +void extend_nonlinearity_domain_binary_step(int arg1, int arg2, + locint **ind_dom, + locint **nonl_dom) { + int index, num, num1, num2, i, j, k, l, m; locint *temp_nonl, *index_nonl_dom; num = ind_dom[arg2][0]; - for(m=2;m num2) - num2 = num1+num; - - temp_nonl = (locint*) malloc(sizeof(locint)*(num2+2)); - temp_nonl[1] = num2; - - i = 2; - k = 2; - j = 2; - num1 +=2; - num2 = num+2; - while ((i num2) + num2 = num1 + num; + + temp_nonl = (locint *)malloc(sizeof(locint) * (num2 + 2)); + temp_nonl[1] = num2; + + i = 2; + k = 2; + j = 2; + num1 += 2; + num2 = num + 2; + while ((i < num1) && (j < num2)) { + if (ind_dom[arg2][j] < index_nonl_dom[i]) /* < */ { + temp_nonl[k] = ind_dom[arg2][j]; + j++; + k++; + } else { + if (ind_dom[arg2][j] == index_nonl_dom[i]) /* == */ { + temp_nonl[k] = ind_dom[arg2][j]; + j++; + k++; + i++; + } else { + temp_nonl[k] = index_nonl_dom[i]; + i++; + k++; + } + } + } + for (l = j; l < num2; l++) { + temp_nonl[k] = ind_dom[arg2][l]; + k++; + } + for (l = i; l < num1; l++) { + temp_nonl[k] = index_nonl_dom[l]; + k++; + } + temp_nonl[0] = k - 2; + free((char *)nonl_dom[index]); + nonl_dom[index] = temp_nonl; } + } } -void extend_nonlinearity_domain_unary -(int arg, locint **ind_dom, locint **nonl_dom) { - extend_nonlinearity_domain_binary_step(arg, arg, ind_dom, nonl_dom); +void extend_nonlinearity_domain_unary(int arg, locint **ind_dom, + locint **nonl_dom) { + extend_nonlinearity_domain_binary_step(arg, arg, ind_dom, nonl_dom); } -void extend_nonlinearity_domain_binary -(int arg1, int arg2, locint **ind_dom, locint **nonl_dom) { - extend_nonlinearity_domain_binary_step(arg1, arg2, ind_dom, nonl_dom); - extend_nonlinearity_domain_binary_step(arg2, arg1, ind_dom, nonl_dom); +void extend_nonlinearity_domain_binary(int arg1, int arg2, locint **ind_dom, + locint **nonl_dom) { + extend_nonlinearity_domain_binary_step(arg1, arg2, ind_dom, nonl_dom); + extend_nonlinearity_domain_binary_step(arg2, arg1, ind_dom, nonl_dom); } - -#endif + #endif #endif END_C_DECLS diff --git a/ADOL-C/src/zos_forward.c b/ADOL-C/src/zos_forward.c index 977573ec5..8aa34844a 100644 --- a/ADOL-C/src/zos_forward.c +++ b/ADOL-C/src/zos_forward.c @@ -4,17 +4,16 @@ Revision: $Id$ Contents: zos_forward (zero-order-scalar forward mode) - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _ZOS_ 1 +#define _ZOS_ 1 #define _KEEP_ 1 #include #undef _KEEP_ #undef _ZOS_ - diff --git a/ADOL-C/src/zos_pl_forward.c b/ADOL-C/src/zos_pl_forward.c index f43c2cb6f..3bd20f959 100644 --- a/ADOL-C/src/zos_pl_forward.c +++ b/ADOL-C/src/zos_pl_forward.c @@ -5,17 +5,16 @@ Contents: zos_forward (zero-order-scalar abs-normal forward mode) Copyright (c) Kshitij Kulshreshtha - + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ----------------------------------------------------------------------------*/ -#define _ZOS_ 1 +#define _ZOS_ 1 #define _KEEP_ 1 #define _ABS_NORM_ 1 #include #undef _ABS_NORM_ #undef _KEEP_ #undef _ZOS_ - diff --git a/ADOL-C/swig/adolc_all_in.hpp b/ADOL-C/swig/adolc_all_in.hpp index 9895661d5..809fcee3b 100644 --- a/ADOL-C/swig/adolc_all_in.hpp +++ b/ADOL-C/swig/adolc_all_in.hpp @@ -3,15 +3,15 @@ File: adolc_all_in.h Revision: $Id$ Contents: Provides all C/C++ interfaces of ADOL-C. - NOTICE: ALL C/C++ headers will be included DEPENDING ON - whether the source code is plain C or C/C++ code. - + NOTICE: ALL C/C++ headers will be included DEPENDING ON + whether the source code is plain C or C/C++ code. + Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ #include diff --git a/ADOL-C/swig/adubswigfuncs.hpp b/ADOL-C/swig/adubswigfuncs.hpp index 8424e8bf7..f8bd76fef 100644 --- a/ADOL-C/swig/adubswigfuncs.hpp +++ b/ADOL-C/swig/adubswigfuncs.hpp @@ -3,15 +3,15 @@ File: adubswigfuncs.h Revision: $Id$ Contents: Provides all C/C++ interfaces of ADOL-C. - NOTICE: ALL C/C++ headers will be included DEPENDING ON - whether the source code is plain C or C/C++ code. - + NOTICE: ALL C/C++ headers will be included DEPENDING ON + whether the source code is plain C or C/C++ code. + Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes - recipient's acceptance of the terms of the accompanying license file. - + Any use, reproduction, or distribution of the software constitutes + recipient's acceptance of the terms of the accompanying license file. + ----------------------------------------------------------------------------*/ #ifndef ADUBSWIGFUNCS_H #define ADUBSWIGFUNCS_H @@ -20,155 +20,155 @@ #if defined(SWIG) -/*--------------------------------------------------------------------------*/ -/* Comparison */ -#if defined(ADOLC_ADVANCED_BRANCHING) -adub* operator != ( const badouble&, const badouble& ); -adub* operator == ( const badouble&, const badouble& ); -adub* operator <= ( const badouble&, const badouble& ); -adub* operator >= ( const badouble&, const badouble& ); -adub* operator > ( const badouble&, const badouble& ); -adub* operator < ( const badouble&, const badouble& ); -adub* operator != ( const pdouble&, const badouble&); -adub* operator != ( const badouble&, const pdouble&); -adub* operator == ( const pdouble&, const badouble&); -adub* operator == ( const badouble&, const pdouble&); -adub* operator <= ( const pdouble&, const badouble&); -adub* operator <= ( const badouble&, const pdouble&); -adub* operator >= ( const pdouble&, const badouble&); -adub* operator >= ( const badouble&, const pdouble&); -adub* operator > ( const pdouble&, const badouble&); -adub* operator > ( const badouble&, const pdouble&); -adub* operator < ( const pdouble&, const badouble&); -adub* operator < ( const badouble&, const pdouble&); -#endif + /*--------------------------------------------------------------------------*/ + /* Comparison */ + #if defined(ADOLC_ADVANCED_BRANCHING) +adub *operator!=(const badouble &, const badouble &); +adub *operator==(const badouble &, const badouble &); +adub *operator<=(const badouble &, const badouble &); +adub *operator>=(const badouble &, const badouble &); +adub *operator>(const badouble &, const badouble &); +adub *operator<(const badouble &, const badouble &); +adub *operator!=(const pdouble &, const badouble &); +adub *operator!=(const badouble &, const pdouble &); +adub *operator==(const pdouble &, const badouble &); +adub *operator==(const badouble &, const pdouble &); +adub *operator<=(const pdouble &, const badouble &); +adub *operator<=(const badouble &, const pdouble &); +adub *operator>=(const pdouble &, const badouble &); +adub *operator>=(const badouble &, const pdouble &); +adub *operator>(const pdouble &, const badouble &); +adub *operator>(const badouble &, const pdouble &); +adub *operator<(const pdouble &, const badouble &); +adub *operator<(const badouble &, const pdouble &); + #endif /*--------------------------------------------------------------------------*/ /* sign operators */ -adub* operator + ( const badouble& x ); -adub* operator - ( const badouble& x ); -adub* operator - ( const pdouble&); +adub *operator+(const badouble &x); +adub *operator-(const badouble &x); +adub *operator-(const pdouble &); /*--------------------------------------------------------------------------*/ /* binary operators */ -adub* operator + ( const badouble&, const badouble& ); -adub* operator + ( double, const badouble& ); -adub* operator + ( const badouble&, double ); -adub* operator - ( const badouble&, const badouble& ); -adub* operator - ( const badouble&, double ); -adub* operator - ( double, const badouble& ); -adub* operator * ( const badouble&, const badouble& ); -adub* operator * ( double, const badouble& ); -adub* operator * ( const badouble&, double ); -adub* operator / ( const badouble&, double ); -adub* operator / ( const badouble&, const badouble& ); -adub* operator / ( double, const badouble& ); -adub* operator + ( const pdouble&, const badouble&); -adub* operator + ( const pdouble&, double); -adub* operator + ( double, const pdouble&); -adub* operator + ( const badouble&, const pdouble&); -adub* operator - ( const badouble&, const pdouble&); -adub* operator - ( const pdouble&, double ); -adub* operator - ( double, const pdouble& ); -adub* operator - ( const pdouble&, const badouble& ); -adub* operator * ( const badouble&, const pdouble&); -adub* operator * ( const pdouble&, const badouble& ); -adub* operator * ( const pdouble&, double ); -adub* operator * ( double, const pdouble& ); -adub* recipr( const pdouble& ); -adub* operator / ( const badouble&, const pdouble& ); -adub* operator / ( double, const pdouble& ); -adub* operator / ( const pdouble&, double ); -adub* operator / ( const pdouble&, const badouble& ); +adub *operator+(const badouble &, const badouble &); +adub *operator+(double, const badouble &); +adub *operator+(const badouble &, double); +adub *operator-(const badouble &, const badouble &); +adub *operator-(const badouble &, double); +adub *operator-(double, const badouble &); +adub *operator*(const badouble &, const badouble &); +adub *operator*(double, const badouble &); +adub *operator*(const badouble &, double); +adub *operator/(const badouble &, double); +adub *operator/(const badouble &, const badouble &); +adub *operator/(double, const badouble &); +adub *operator+(const pdouble &, const badouble &); +adub *operator+(const pdouble &, double); +adub *operator+(double, const pdouble &); +adub *operator+(const badouble &, const pdouble &); +adub *operator-(const badouble &, const pdouble &); +adub *operator-(const pdouble &, double); +adub *operator-(double, const pdouble &); +adub *operator-(const pdouble &, const badouble &); +adub *operator*(const badouble &, const pdouble &); +adub *operator*(const pdouble &, const badouble &); +adub *operator*(const pdouble &, double); +adub *operator*(double, const pdouble &); +adub *recipr(const pdouble &); +adub *operator/(const badouble &, const pdouble &); +adub *operator/(double, const pdouble &); +adub *operator/(const pdouble &, double); +adub *operator/(const pdouble &, const badouble &); /*--------------------------------------------------------------------------*/ /* unary operators */ -adub* exp ( const badouble& ); -adub* log ( const badouble& ); -adub* sqrt ( const badouble& ); -adub* sin ( const badouble& ); -adub* cos ( const badouble& ); -adub* tan ( const badouble& ); -adub* asin ( const badouble& ); -adub* acos ( const badouble& ); -adub* atan ( const badouble& ); +adub *exp(const badouble &); +adub *log(const badouble &); +adub *sqrt(const badouble &); +adub *sin(const badouble &); +adub *cos(const badouble &); +adub *tan(const badouble &); +adub *asin(const badouble &); +adub *acos(const badouble &); +adub *atan(const badouble &); /*--------------------------------------------------------------------------*/ /* special operators (friends) */ /* no internal use of condassign: */ -adub* pow ( const badouble&, double ); -adub* log10 ( const badouble& ); -adub* pow ( const badouble&, const pdouble& ); +adub *pow(const badouble &, double); +adub *log10(const badouble &); +adub *pow(const badouble &, const pdouble &); /* Additional ANSI C standard Math functions Added by DWJ on 8/6/90 */ -adub* sinh ( const badouble& ); -adub* cosh ( const badouble& ); -adub* tanh ( const badouble& ); -adub* asinh ( const badouble& ); -adub* acosh ( const badouble& ); -adub* atanh ( const badouble& ); -adub* erf ( const badouble& ); -adub* erfc ( const badouble& ); - -adub* fabs ( const badouble& ); -adub* ceil ( const badouble& ); -adub* floor ( const badouble& ); - -adub* fmax ( const badouble&, const badouble& ); -adub* fmax ( double, const badouble& ); -adub* fmax ( const badouble&, double ); -adub* fmin ( const badouble&, const badouble& ); -adub* fmin ( double, const badouble& ); -adub* fmin ( const badouble&, double ); -adub* fmax ( const pdouble&, const badouble& ); -adub* fmax ( const badouble&, const pdouble& ); -adub* fmin ( const pdouble&, const badouble& ); -adub* fmin ( const badouble&, const pdouble& ); - -adub* ldexp ( const badouble&, int ); -adub* frexp ( const badouble&, int* ); - -adub* exp ( const pdouble& ); -adub* log ( const pdouble& ); -adub* sqrt ( const pdouble& ); -adub* sin ( const pdouble& ); -adub* cos ( const pdouble& ); -adub* tan ( const pdouble& ); -adub* asin ( const pdouble& ); -adub* acos ( const pdouble& ); -adub* atan ( const pdouble& ); - -adub* pow ( const pdouble&, double ); -adub* log10 ( const pdouble& ); - -adub* sinh ( const pdouble& ); -adub* cosh ( const pdouble& ); -adub* tanh ( const pdouble& ); -adub* asinh ( const pdouble& ); -adub* acosh ( const pdouble& ); -adub* atanh ( const pdouble& ); -adub* erf ( const pdouble& ); -adub* erfc ( const pdouble& ); - -adub* fabs ( const pdouble& ); -adub* ceil ( const pdouble& ); -adub* floor ( const pdouble& ); - -adub* fmax ( const pdouble&, const pdouble& ); -adub* fmax ( double, const pdouble& ); -adub* fmax ( const pdouble&, double ); -adub* fmin ( const pdouble&, const pdouble& ); -adub* fmin ( double, const pdouble& ); -adub* fmin ( const pdouble&, double ); - -adub* ldexp ( const pdouble&, int ); -adub* frexp ( const pdouble&, int* ); +adub *sinh(const badouble &); +adub *cosh(const badouble &); +adub *tanh(const badouble &); +adub *asinh(const badouble &); +adub *acosh(const badouble &); +adub *atanh(const badouble &); +adub *erf(const badouble &); +adub *erfc(const badouble &); + +adub *fabs(const badouble &); +adub *ceil(const badouble &); +adub *floor(const badouble &); + +adub *fmax(const badouble &, const badouble &); +adub *fmax(double, const badouble &); +adub *fmax(const badouble &, double); +adub *fmin(const badouble &, const badouble &); +adub *fmin(double, const badouble &); +adub *fmin(const badouble &, double); +adub *fmax(const pdouble &, const badouble &); +adub *fmax(const badouble &, const pdouble &); +adub *fmin(const pdouble &, const badouble &); +adub *fmin(const badouble &, const pdouble &); + +adub *ldexp(const badouble &, int); +adub *frexp(const badouble &, int *); + +adub *exp(const pdouble &); +adub *log(const pdouble &); +adub *sqrt(const pdouble &); +adub *sin(const pdouble &); +adub *cos(const pdouble &); +adub *tan(const pdouble &); +adub *asin(const pdouble &); +adub *acos(const pdouble &); +adub *atan(const pdouble &); + +adub *pow(const pdouble &, double); +adub *log10(const pdouble &); + +adub *sinh(const pdouble &); +adub *cosh(const pdouble &); +adub *tanh(const pdouble &); +adub *asinh(const pdouble &); +adub *acosh(const pdouble &); +adub *atanh(const pdouble &); +adub *erf(const pdouble &); +adub *erfc(const pdouble &); + +adub *fabs(const pdouble &); +adub *ceil(const pdouble &); +adub *floor(const pdouble &); + +adub *fmax(const pdouble &, const pdouble &); +adub *fmax(double, const pdouble &); +adub *fmax(const pdouble &, double); +adub *fmin(const pdouble &, const pdouble &); +adub *fmin(double, const pdouble &); +adub *fmin(const pdouble &, double); + +adub *ldexp(const pdouble &, int); +adub *frexp(const pdouble &, int *); /*--------------------------------------------------------------------------*/ -adub* adolc_vec_dot(const adouble*const, const adouble*const, locint); +adub *adolc_vec_dot(const adouble *const, const adouble *const, locint); -pdouble* mkparam(double pval); -pdouble* getparam(locint index); +pdouble *mkparam(double pval); +pdouble *getparam(locint index); #endif #endif diff --git a/ADOL-C/swig/matrixmemory.hpp b/ADOL-C/swig/matrixmemory.hpp index be85e2048..d056bf020 100644 --- a/ADOL-C/swig/matrixmemory.hpp +++ b/ADOL-C/swig/matrixmemory.hpp @@ -2,12 +2,12 @@ ADOL-C -- Automatic Differentiation by Overloading in C++ File: matrixmemory.hpp Revision: $Id$ - Contents: C allocation of arrays of doubles in several dimensions + Contents: C allocation of arrays of doubles in several dimensions Copyright (c) Kshitij Kulshreshtha This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. --------------------------------------------------------------------------*/ @@ -16,46 +16,51 @@ /*--------------------------------------------------------------------------*/ template -static inline char* populate_dpp_with_contigdata(Type ***const pointer, char *const memory, - int n, int m, Type *const data) { - char* tmp; - Type **tmp1; Type *tmp2; - int i,j; - tmp = (char*)memory; - tmp1 = (Type**) memory; - *pointer = tmp1; - tmp = (char*)(tmp1+n); - tmp2 = data; - for (i=0;i -static inline char* populate_dppp_with_contigdata(Type ****const pointer, char *const memory, - int n, int m, int p, Type *const data) { - char* tmp; - Type ***tmp1; Type **tmp2; Type *tmp3; - int i,j; - tmp = (char*) memory; - tmp1 = (Type***) memory; - *pointer = tmp1; - tmp = (char*)(tmp1+n); - tmp2 = (Type**)tmp; - for(i=0; i #include "pydirectors.hpp" +#include class PyEDFwrap : public EDFobject { protected: - PyEDF* pyobj; + PyEDF *pyobj; + public: - PyEDFwrap() : EDFobject() {} - virtual ~PyEDFwrap() {} - void setPyObj(PyEDF* o) { pyobj = o; } - int function(int n, double *x, int m, double* y) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }; - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; + PyEDFwrap() : EDFobject() {} + virtual ~PyEDFwrap() {} + void setPyObj(PyEDF *o) { pyobj = o; } + int function(int n, double *x, int m, double *y) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}; + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; #ifdef SWIGPY_USE_CAPSULE - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; #else - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); #endif - //args = Py_BuildValue("OOOO:PyEDFobject_function",no,xa,mo,ya); - args = PyTuple_Pack(4,no,xa,mo,ya); - rc = pyobj->function(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(no); - Py_DECREF(mo); - return rc; - } - int zos_forward(int n, double *x, int m, double* y) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }; - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; + // args = Py_BuildValue("OOOO:PyEDFobject_function",no,xa,mo,ya); + args = PyTuple_Pack(4, no, xa, mo, ya); + rc = pyobj->function(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(no); + Py_DECREF(mo); + return rc; + } + int zos_forward(int n, double *x, int m, double *y) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}; + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; #ifdef SWIGPY_USE_CAPSULE - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; #else - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); #endif - //args = Py_BuildValue("OOOO:PyEDFobject_function",no,xa,mo,ya); - args = PyTuple_Pack(4,no,xa,mo,ya); - rc = pyobj->zos_forward(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(no); - Py_DECREF(mo); - return rc; - } - int fos_forward(int n, double *x, double *xp, int m, double *y, double *yp) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }; - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* xpa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)xp); - PyObject* ypa = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)yp); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *xpaa = (PyArrayObject*) xpa, *ypaa = (PyArrayObject*) ypa; + // args = Py_BuildValue("OOOO:PyEDFobject_function",no,xa,mo,ya); + args = PyTuple_Pack(4, no, xa, mo, ya); + rc = pyobj->zos_forward(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(no); + Py_DECREF(mo); + return rc; + } + int fos_forward(int n, double *x, double *xp, int m, double *y, double *yp) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}; + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *xpa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)xp); + PyObject *ypa = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)yp); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *xpaa = (PyArrayObject *)xpa, *ypaa = (PyArrayObject *)ypa; #ifdef SWIGPY_USE_CAPSULE - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capxp = PyCapsule_New((void*)(xp), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capyp = PyCapsule_New((void*)(yp), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capxp = PyCapsule_New((void *)(xp), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capyp = PyCapsule_New((void *)(yp), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); - PyObject* capxp = PyCObject_FromVoidPtr((void*)(xp), NULL); - PyObject* capyp = PyCObject_FromVoidPtr((void*)(yp), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); + PyObject *capxp = PyCObject_FromVoidPtr((void *)(xp), NULL); + PyObject *capyp = PyCObject_FromVoidPtr((void *)(yp), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; - PyArray_BASE(xpaa) = capxp; - PyArray_BASE(ypaa) = capyp; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; + PyArray_BASE(xpaa) = capxp; + PyArray_BASE(ypaa) = capyp; #else - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); - PyArray_SetBaseObject(xpaa,capxp); - PyArray_SetBaseObject(ypaa,capyp); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); + PyArray_SetBaseObject(xpaa, capxp); + PyArray_SetBaseObject(ypaa, capyp); #endif - args = PyTuple_Pack(6,no,xa,xpa,mo,ya,ypa); - rc = pyobj->fos_forward(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(xpaa); - Py_DECREF(ypaa); - Py_DECREF(no); - Py_DECREF(mo); - return rc; - } - int fov_forward(int n, double *x, int p, double **Xp, int m, double *y, double **Yp) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }; - npy_intp inp[2] = { n,p }, outp[2] = { m,p }; - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* xpa = PyArray_SimpleNewFromData(2,inp,NPY_DOUBLE,(void*)&Xp[0][0]); - PyObject* ypa = PyArray_SimpleNewFromData(2,outp,NPY_DOUBLE,(void*)&Yp[0][0]); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyObject* po = PyInt_FromLong((long int)p); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *xpaa = (PyArrayObject*) xpa, *ypaa = (PyArrayObject*) ypa; + args = PyTuple_Pack(6, no, xa, xpa, mo, ya, ypa); + rc = pyobj->fos_forward(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(xpaa); + Py_DECREF(ypaa); + Py_DECREF(no); + Py_DECREF(mo); + return rc; + } + int fov_forward(int n, double *x, int p, double **Xp, int m, double *y, + double **Yp) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}; + npy_intp inp[2] = {n, p}, outp[2] = {m, p}; + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *xpa = + PyArray_SimpleNewFromData(2, inp, NPY_DOUBLE, (void *)&Xp[0][0]); + PyObject *ypa = + PyArray_SimpleNewFromData(2, outp, NPY_DOUBLE, (void *)&Yp[0][0]); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyObject *po = PyInt_FromLong((long int)p); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *xpaa = (PyArrayObject *)xpa, *ypaa = (PyArrayObject *)ypa; #ifdef SWIGPY_USE_CAPSULE - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capxp = PyCapsule_New((void*)(Xp), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capyp = PyCapsule_New((void*)(Yp), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capxp = PyCapsule_New((void *)(Xp), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capyp = PyCapsule_New((void *)(Yp), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); - PyObject* capxp = PyCObject_FromVoidPtr((void*)(Xp), NULL); - PyObject* capyp = PyCObject_FromVoidPtr((void*)(Yp), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); + PyObject *capxp = PyCObject_FromVoidPtr((void *)(Xp), NULL); + PyObject *capyp = PyCObject_FromVoidPtr((void *)(Yp), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; - PyArray_BASE(xpaa) = capxp; - PyArray_BASE(ypaa) = capyp; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; + PyArray_BASE(xpaa) = capxp; + PyArray_BASE(ypaa) = capyp; #else - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); - PyArray_SetBaseObject(xpaa,capxp); - PyArray_SetBaseObject(ypaa,capyp); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); + PyArray_SetBaseObject(xpaa, capxp); + PyArray_SetBaseObject(ypaa, capyp); #endif - args = PyTuple_Pack(7,no,xa,po,xpa,mo,ya,ypa); - rc = pyobj->fov_forward(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(xpaa); - Py_DECREF(ypaa); - Py_DECREF(no); - Py_DECREF(mo); - Py_DECREF(po); - return rc; - } - int fos_reverse(int m, double *U, int n, double *Z, double *x, double *y) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }; - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* ua = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)U); - PyObject* za = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)Z); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *uaa = (PyArrayObject*) ua, *zaa = (PyArrayObject*) za; + args = PyTuple_Pack(7, no, xa, po, xpa, mo, ya, ypa); + rc = pyobj->fov_forward(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(xpaa); + Py_DECREF(ypaa); + Py_DECREF(no); + Py_DECREF(mo); + Py_DECREF(po); + return rc; + } + int fos_reverse(int m, double *U, int n, double *Z, double *x, double *y) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}; + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *ua = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)U); + PyObject *za = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)Z); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *uaa = (PyArrayObject *)ua, *zaa = (PyArrayObject *)za; #ifdef SWIGPY_USE_CAPSULE - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capu = PyCapsule_New((void*)(U), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capz = PyCapsule_New((void*)(Z), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capu = PyCapsule_New((void *)(U), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capz = PyCapsule_New((void *)(Z), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); - PyObject* capu = PyCObject_FromVoidPtr((void*)(U), NULL); - PyObject* capz = PyCObject_FromVoidPtr((void*)(Z), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); + PyObject *capu = PyCObject_FromVoidPtr((void *)(U), NULL); + PyObject *capz = PyCObject_FromVoidPtr((void *)(Z), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; - PyArray_BASE(uaa) = capu; - PyArray_BASE(zaa) = capz; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; + PyArray_BASE(uaa) = capu; + PyArray_BASE(zaa) = capz; #else - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); - PyArray_SetBaseObject(uaa,capu); - PyArray_SetBaseObject(zaa,capz); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); + PyArray_SetBaseObject(uaa, capu); + PyArray_SetBaseObject(zaa, capz); #endif - args = PyTuple_Pack(6,mo,ua,no,za,xa,ya); - rc = pyobj->fos_reverse(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(uaa); - Py_DECREF(zaa); - Py_DECREF(no); - Py_DECREF(mo); - return rc; - } - int fov_reverse(int m, int q, double **U, int n, double **Z, double *x, double *y) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }; - npy_intp inq[2] = { n,q }, outq[2] = { m,q }; - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* ua = PyArray_SimpleNewFromData(1,outq,NPY_DOUBLE,(void*)&U[0][0]); - PyObject* za = PyArray_SimpleNewFromData(1,inq,NPY_DOUBLE,(void*)&Z[0][0]); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyObject* qo = PyInt_FromLong((long int)q); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *uaa = (PyArrayObject*) ua, *zaa = (PyArrayObject*) za; + args = PyTuple_Pack(6, mo, ua, no, za, xa, ya); + rc = pyobj->fos_reverse(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(uaa); + Py_DECREF(zaa); + Py_DECREF(no); + Py_DECREF(mo); + return rc; + } + int fov_reverse(int m, int q, double **U, int n, double **Z, double *x, + double *y) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}; + npy_intp inq[2] = {n, q}, outq[2] = {m, q}; + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *ua = + PyArray_SimpleNewFromData(1, outq, NPY_DOUBLE, (void *)&U[0][0]); + PyObject *za = + PyArray_SimpleNewFromData(1, inq, NPY_DOUBLE, (void *)&Z[0][0]); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyObject *qo = PyInt_FromLong((long int)q); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *uaa = (PyArrayObject *)ua, *zaa = (PyArrayObject *)za; #ifdef SWIGPY_USE_CAPSULE - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capu = PyCapsule_New((void*)(U), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capz = PyCapsule_New((void*)(Z), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capu = PyCapsule_New((void *)(U), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capz = PyCapsule_New((void *)(Z), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); - PyObject* capu = PyCObject_FromVoidPtr((void*)(U), NULL); - PyObject* capz = PyCObject_FromVoidPtr((void*)(Z), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); + PyObject *capu = PyCObject_FromVoidPtr((void *)(U), NULL); + PyObject *capz = PyCObject_FromVoidPtr((void *)(Z), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; - PyArray_BASE(uaa) = capu; - PyArray_BASE(zaa) = capz; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; + PyArray_BASE(uaa) = capu; + PyArray_BASE(zaa) = capz; #else - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); - PyArray_SetBaseObject(uaa,capu); - PyArray_SetBaseObject(zaa,capz); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); + PyArray_SetBaseObject(uaa, capu); + PyArray_SetBaseObject(zaa, capz); #endif - args = PyTuple_Pack(7,mo,qo,ua,no,za,xa,ya); - rc = pyobj->fov_reverse(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(uaa); - Py_DECREF(zaa); - Py_DECREF(no); - Py_DECREF(mo); - Py_DECREF(qo); - return rc; - } - int call(int n, adouble *xa, int m, adouble *ya) { - return EDFobject::call(n,xa,m,ya); - } - int call(int n, advector& x, int m, advector& y) { - return EDFobject::call(n,x,m,y); - } + args = PyTuple_Pack(7, mo, qo, ua, no, za, xa, ya); + rc = pyobj->fov_reverse(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(uaa); + Py_DECREF(zaa); + Py_DECREF(no); + Py_DECREF(mo); + Py_DECREF(qo); + return rc; + } + int call(int n, adouble *xa, int m, adouble *ya) { + return EDFobject::call(n, xa, m, ya); + } + int call(int n, advector &x, int m, advector &y) { + return EDFobject::call(n, x, m, y); + } }; PyEDF::PyEDF() { - cobj = new PyEDFwrap(); - cobj->setPyObj(this); + cobj = new PyEDFwrap(); + cobj->setPyObj(this); } -PyEDF::~PyEDF() { - delete cobj; -} +PyEDF::~PyEDF() { delete cobj; } int PyEDF::call(int n, adouble *xa, int m, adouble *ya) { - return cobj->call(n,xa,m,ya); + return cobj->call(n, xa, m, ya); } -int PyEDF::call(int n, advector& x, int m, advector& y) { - return cobj->call(n,x,m,y); +int PyEDF::call(int n, advector &x, int m, advector &y) { + return cobj->call(n, x, m, y); } class PyEDF_iArr_wrap : public EDFobject_iArr { protected: - PyEDF_iArr* pyobj; + PyEDF_iArr *pyobj; + public: - PyEDF_iArr_wrap() : EDFobject_iArr() {} - virtual ~PyEDF_iArr_wrap() {} - void setPyObj(PyEDF_iArr* o) { pyobj = o; } - int function(int iArrLen, int* iArr, int n, double *x, int m, double* y) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }, arrsz[1] = { iArrLen }; - PyObject* iar = PyArray_SimpleNewFromData(1,arrsz,NPY_INT,(void*)iArr); - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyObject* ial = PyInt_FromLong((long int)iArrLen); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *iara = (PyArrayObject*) iar; + PyEDF_iArr_wrap() : EDFobject_iArr() {} + virtual ~PyEDF_iArr_wrap() {} + void setPyObj(PyEDF_iArr *o) { pyobj = o; } + int function(int iArrLen, int *iArr, int n, double *x, int m, double *y) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}, arrsz[1] = {iArrLen}; + PyObject *iar = PyArray_SimpleNewFromData(1, arrsz, NPY_INT, (void *)iArr); + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyObject *ial = PyInt_FromLong((long int)iArrLen); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *iara = (PyArrayObject *)iar; #ifdef SWIGPY_USE_CAPSULE - PyObject* capiar = PyCapsule_New((void*)(iArr), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capiar = PyCapsule_New((void *)(iArr), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capiar = PyCObject_FromVoidPtr((void*)(iArr), NULL); - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); + PyObject *capiar = PyCObject_FromVoidPtr((void *)(iArr), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(iara) = capiar; - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; + PyArray_BASE(iara) = capiar; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; #else - PyArray_SetBaseObject(iara,capiar); - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); + PyArray_SetBaseObject(iara, capiar); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); #endif - //args = Py_BuildValue("OOOO:PyEDFobject_function",no,xa,mo,ya); - args = PyTuple_Pack(6,ial,iar,no,xa,mo,ya); - rc = pyobj->function(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(iara); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(no); - Py_DECREF(mo); - Py_DECREF(ial); - return rc; - } - int zos_forward(int iArrLen, int* iArr, int n, double *x, int m, double* y) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }, arrsz[1] = { iArrLen }; - PyObject* iar = PyArray_SimpleNewFromData(1,arrsz,NPY_INT,(void*)iArr); - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyObject* ial = PyInt_FromLong((long int)iArrLen); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *iara = (PyArrayObject*) iar; + // args = Py_BuildValue("OOOO:PyEDFobject_function",no,xa,mo,ya); + args = PyTuple_Pack(6, ial, iar, no, xa, mo, ya); + rc = pyobj->function(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(iara); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(no); + Py_DECREF(mo); + Py_DECREF(ial); + return rc; + } + int zos_forward(int iArrLen, int *iArr, int n, double *x, int m, double *y) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}, arrsz[1] = {iArrLen}; + PyObject *iar = PyArray_SimpleNewFromData(1, arrsz, NPY_INT, (void *)iArr); + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyObject *ial = PyInt_FromLong((long int)iArrLen); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *iara = (PyArrayObject *)iar; #ifdef SWIGPY_USE_CAPSULE - PyObject* capiar = PyCapsule_New((void*)(iArr), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capiar = PyCapsule_New((void *)(iArr), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capiar = PyCObject_FromVoidPtr((void*)(iArr), NULL); - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); + PyObject *capiar = PyCObject_FromVoidPtr((void *)(iArr), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(iara) = capiar; - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; + PyArray_BASE(iara) = capiar; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; #else - PyArray_SetBaseObject(iara,capiar); - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); + PyArray_SetBaseObject(iara, capiar); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); #endif - //args = Py_BuildValue("OOOO:PyEDFobject_function",no,xa,mo,ya); - args = PyTuple_Pack(6,ial,iar,no,xa,mo,ya); - rc = pyobj->zos_forward(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(iara); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(no); - Py_DECREF(mo); - Py_DECREF(ial); - return rc; - } - int fos_forward(int iArrLen, int* iArr, int n, double *x, double *xp, int m, double *y, double *yp) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }, arrsz[1] = { iArrLen }; - PyObject* iar = PyArray_SimpleNewFromData(1,arrsz,NPY_INT,(void*)iArr); - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* xpa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)xp); - PyObject* ypa = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)yp); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyObject* ial = PyInt_FromLong((long int)iArrLen); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *xpaa = (PyArrayObject*) xpa, *ypaa = (PyArrayObject*) ypa; - PyArrayObject *iara = (PyArrayObject*) iar; + // args = Py_BuildValue("OOOO:PyEDFobject_function",no,xa,mo,ya); + args = PyTuple_Pack(6, ial, iar, no, xa, mo, ya); + rc = pyobj->zos_forward(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(iara); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(no); + Py_DECREF(mo); + Py_DECREF(ial); + return rc; + } + int fos_forward(int iArrLen, int *iArr, int n, double *x, double *xp, int m, + double *y, double *yp) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}, arrsz[1] = {iArrLen}; + PyObject *iar = PyArray_SimpleNewFromData(1, arrsz, NPY_INT, (void *)iArr); + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *xpa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)xp); + PyObject *ypa = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)yp); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyObject *ial = PyInt_FromLong((long int)iArrLen); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *xpaa = (PyArrayObject *)xpa, *ypaa = (PyArrayObject *)ypa; + PyArrayObject *iara = (PyArrayObject *)iar; #ifdef SWIGPY_USE_CAPSULE - PyObject* capiar = PyCapsule_New((void*)(iArr), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capxp = PyCapsule_New((void*)(xp), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capyp = PyCapsule_New((void*)(yp), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capiar = PyCapsule_New((void *)(iArr), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capxp = PyCapsule_New((void *)(xp), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capyp = PyCapsule_New((void *)(yp), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capiar = PyCObject_FromVoidPtr((void*)(iArr), NULL); - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); - PyObject* capxp = PyCObject_FromVoidPtr((void*)(xp), NULL); - PyObject* capyp = PyCObject_FromVoidPtr((void*)(yp), NULL); + PyObject *capiar = PyCObject_FromVoidPtr((void *)(iArr), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); + PyObject *capxp = PyCObject_FromVoidPtr((void *)(xp), NULL); + PyObject *capyp = PyCObject_FromVoidPtr((void *)(yp), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(iara) = capiar; - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; - PyArray_BASE(xpaa) = capxp; - PyArray_BASE(ypaa) = capyp; + PyArray_BASE(iara) = capiar; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; + PyArray_BASE(xpaa) = capxp; + PyArray_BASE(ypaa) = capyp; #else - PyArray_SetBaseObject(iara,capiar); - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); - PyArray_SetBaseObject(xpaa,capxp); - PyArray_SetBaseObject(ypaa,capyp); + PyArray_SetBaseObject(iara, capiar); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); + PyArray_SetBaseObject(xpaa, capxp); + PyArray_SetBaseObject(ypaa, capyp); #endif - args = PyTuple_Pack(8,ial,iar,no,xa,xpa,mo,ya,ypa); - rc = pyobj->fos_forward(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(iara); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(xpaa); - Py_DECREF(ypaa); - Py_DECREF(no); - Py_DECREF(mo); - Py_DECREF(ial); - return rc; - } - int fov_forward(int iArrLen, int* iArr, int n, double *x, int p, double **Xp, int m, double *y, double **Yp) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }, arrsz[1] = { iArrLen }; - npy_intp inp[2] = { n,p }, outp[2] = { m,p }; - PyObject* iar = PyArray_SimpleNewFromData(1,arrsz,NPY_INT,(void*)iArr); - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* xpa = PyArray_SimpleNewFromData(2,inp,NPY_DOUBLE,(void*)&Xp[0][0]); - PyObject* ypa = PyArray_SimpleNewFromData(2,outp,NPY_DOUBLE,(void*)&Yp[0][0]); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyObject* po = PyInt_FromLong((long int)p); - PyObject* ial = PyInt_FromLong((long int)iArrLen); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *xpaa = (PyArrayObject*) xpa, *ypaa = (PyArrayObject*) ypa; - PyArrayObject *iara = (PyArrayObject*) iar; + args = PyTuple_Pack(8, ial, iar, no, xa, xpa, mo, ya, ypa); + rc = pyobj->fos_forward(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(iara); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(xpaa); + Py_DECREF(ypaa); + Py_DECREF(no); + Py_DECREF(mo); + Py_DECREF(ial); + return rc; + } + int fov_forward(int iArrLen, int *iArr, int n, double *x, int p, double **Xp, + int m, double *y, double **Yp) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}, arrsz[1] = {iArrLen}; + npy_intp inp[2] = {n, p}, outp[2] = {m, p}; + PyObject *iar = PyArray_SimpleNewFromData(1, arrsz, NPY_INT, (void *)iArr); + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *xpa = + PyArray_SimpleNewFromData(2, inp, NPY_DOUBLE, (void *)&Xp[0][0]); + PyObject *ypa = + PyArray_SimpleNewFromData(2, outp, NPY_DOUBLE, (void *)&Yp[0][0]); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyObject *po = PyInt_FromLong((long int)p); + PyObject *ial = PyInt_FromLong((long int)iArrLen); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *xpaa = (PyArrayObject *)xpa, *ypaa = (PyArrayObject *)ypa; + PyArrayObject *iara = (PyArrayObject *)iar; #ifdef SWIGPY_USE_CAPSULE - PyObject* capiar = PyCapsule_New((void*)(iArr), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capxp = PyCapsule_New((void*)(Xp), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capyp = PyCapsule_New((void*)(Yp), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capiar = PyCapsule_New((void *)(iArr), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capxp = PyCapsule_New((void *)(Xp), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capyp = PyCapsule_New((void *)(Yp), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capiar = PyCObject_FromVoidPtr((void*)(iArr), NULL); - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); - PyObject* capxp = PyCObject_FromVoidPtr((void*)(Xp), NULL); - PyObject* capyp = PyCObject_FromVoidPtr((void*)(Yp), NULL); + PyObject *capiar = PyCObject_FromVoidPtr((void *)(iArr), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); + PyObject *capxp = PyCObject_FromVoidPtr((void *)(Xp), NULL); + PyObject *capyp = PyCObject_FromVoidPtr((void *)(Yp), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(iara) = capiar; - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; - PyArray_BASE(xpaa) = capxp; - PyArray_BASE(ypaa) = capyp; + PyArray_BASE(iara) = capiar; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; + PyArray_BASE(xpaa) = capxp; + PyArray_BASE(ypaa) = capyp; #else - PyArray_SetBaseObject(iara,capiar); - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); - PyArray_SetBaseObject(xpaa,capxp); - PyArray_SetBaseObject(ypaa,capyp); + PyArray_SetBaseObject(iara, capiar); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); + PyArray_SetBaseObject(xpaa, capxp); + PyArray_SetBaseObject(ypaa, capyp); #endif - args = PyTuple_Pack(9,ial,iar,no,xa,po,xpa,mo,ya,ypa); - rc = pyobj->fov_forward(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(iara); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(xpaa); - Py_DECREF(ypaa); - Py_DECREF(no); - Py_DECREF(mo); - Py_DECREF(po); - Py_DECREF(ial); - return rc; - } - int fos_reverse(int iArrLen, int* iArr, int m, double *U, int n, double *Z, double *x, double *y) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }, arrsz[1] = { iArrLen }; - PyObject* iar = PyArray_SimpleNewFromData(1,arrsz,NPY_INT,(void*)iArr); - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* ua = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)U); - PyObject* za = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)Z); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyObject* ial = PyInt_FromLong((long int)iArrLen); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *uaa = (PyArrayObject*) ua, *zaa = (PyArrayObject*) za; - PyArrayObject *iara = (PyArrayObject*) iar; + args = PyTuple_Pack(9, ial, iar, no, xa, po, xpa, mo, ya, ypa); + rc = pyobj->fov_forward(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(iara); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(xpaa); + Py_DECREF(ypaa); + Py_DECREF(no); + Py_DECREF(mo); + Py_DECREF(po); + Py_DECREF(ial); + return rc; + } + int fos_reverse(int iArrLen, int *iArr, int m, double *U, int n, double *Z, + double *x, double *y) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}, arrsz[1] = {iArrLen}; + PyObject *iar = PyArray_SimpleNewFromData(1, arrsz, NPY_INT, (void *)iArr); + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *ua = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)U); + PyObject *za = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)Z); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyObject *ial = PyInt_FromLong((long int)iArrLen); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *uaa = (PyArrayObject *)ua, *zaa = (PyArrayObject *)za; + PyArrayObject *iara = (PyArrayObject *)iar; #ifdef SWIGPY_USE_CAPSULE - PyObject* capiar = PyCapsule_New((void*)(iArr), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capu = PyCapsule_New((void*)(U), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capz = PyCapsule_New((void*)(Z), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capiar = PyCapsule_New((void *)(iArr), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capu = PyCapsule_New((void *)(U), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capz = PyCapsule_New((void *)(Z), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capiar = PyCObject_FromVoidPtr((void*)(iArr), NULL); - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); - PyObject* capu = PyCObject_FromVoidPtr((void*)(U), NULL); - PyObject* capz = PyCObject_FromVoidPtr((void*)(Z), NULL); + PyObject *capiar = PyCObject_FromVoidPtr((void *)(iArr), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); + PyObject *capu = PyCObject_FromVoidPtr((void *)(U), NULL); + PyObject *capz = PyCObject_FromVoidPtr((void *)(Z), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(iara) = capiar; - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; - PyArray_BASE(uaa) = capu; - PyArray_BASE(zaa) = capz; + PyArray_BASE(iara) = capiar; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; + PyArray_BASE(uaa) = capu; + PyArray_BASE(zaa) = capz; #else - PyArray_SetBaseObject(iara,capiar); - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); - PyArray_SetBaseObject(uaa,capu); - PyArray_SetBaseObject(zaa,capz); + PyArray_SetBaseObject(iara, capiar); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); + PyArray_SetBaseObject(uaa, capu); + PyArray_SetBaseObject(zaa, capz); #endif - args = PyTuple_Pack(8,ial,iar,mo,ua,no,za,xa,ya); - rc = pyobj->fos_reverse(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(iara); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(uaa); - Py_DECREF(zaa); - Py_DECREF(no); - Py_DECREF(mo); - Py_DECREF(ial); - return rc; - } - int fov_reverse(int iArrLen, int* iArr, int m, int q, double **U, int n, double **Z, double *x, double *y) { - PyObject* args = NULL; - int rc; - npy_intp in[1] = { n }, out[1] = { m }, arrsz[1] = { iArrLen }; - npy_intp inq[2] = { n,q }, outq[2] = { m,q }; - PyObject* iar = PyArray_SimpleNewFromData(1,arrsz,NPY_INT,(void*)iArr); - PyObject* xa = PyArray_SimpleNewFromData(1,in,NPY_DOUBLE,(void*)x); - PyObject* ya = PyArray_SimpleNewFromData(1,out,NPY_DOUBLE,(void*)y); - PyObject* ua = PyArray_SimpleNewFromData(1,outq,NPY_DOUBLE,(void*)&U[0][0]); - PyObject* za = PyArray_SimpleNewFromData(1,inq,NPY_DOUBLE,(void*)&Z[0][0]); - PyObject* no = PyInt_FromLong((long int)n); - PyObject* mo = PyInt_FromLong((long int)m); - PyObject* qo = PyInt_FromLong((long int)q); - PyObject* ial = PyInt_FromLong((long int)iArrLen); - PyArrayObject *xaa = (PyArrayObject*) xa, *yaa = (PyArrayObject*) ya; - PyArrayObject *uaa = (PyArrayObject*) ua, *zaa = (PyArrayObject*) za; - PyArrayObject *iara = (PyArrayObject*) iar; + args = PyTuple_Pack(8, ial, iar, mo, ua, no, za, xa, ya); + rc = pyobj->fos_reverse(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(iara); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(uaa); + Py_DECREF(zaa); + Py_DECREF(no); + Py_DECREF(mo); + Py_DECREF(ial); + return rc; + } + int fov_reverse(int iArrLen, int *iArr, int m, int q, double **U, int n, + double **Z, double *x, double *y) { + PyObject *args = NULL; + int rc; + npy_intp in[1] = {n}, out[1] = {m}, arrsz[1] = {iArrLen}; + npy_intp inq[2] = {n, q}, outq[2] = {m, q}; + PyObject *iar = PyArray_SimpleNewFromData(1, arrsz, NPY_INT, (void *)iArr); + PyObject *xa = PyArray_SimpleNewFromData(1, in, NPY_DOUBLE, (void *)x); + PyObject *ya = PyArray_SimpleNewFromData(1, out, NPY_DOUBLE, (void *)y); + PyObject *ua = + PyArray_SimpleNewFromData(1, outq, NPY_DOUBLE, (void *)&U[0][0]); + PyObject *za = + PyArray_SimpleNewFromData(1, inq, NPY_DOUBLE, (void *)&Z[0][0]); + PyObject *no = PyInt_FromLong((long int)n); + PyObject *mo = PyInt_FromLong((long int)m); + PyObject *qo = PyInt_FromLong((long int)q); + PyObject *ial = PyInt_FromLong((long int)iArrLen); + PyArrayObject *xaa = (PyArrayObject *)xa, *yaa = (PyArrayObject *)ya; + PyArrayObject *uaa = (PyArrayObject *)ua, *zaa = (PyArrayObject *)za; + PyArrayObject *iara = (PyArrayObject *)iar; #ifdef SWIGPY_USE_CAPSULE - PyObject* capiar = PyCapsule_New((void*)(iArr), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capx = PyCapsule_New((void*)(x), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capy = PyCapsule_New((void*)(y), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capu = PyCapsule_New((void*)(U), SWIGPY_CAPSULE_NAME, NULL); - PyObject* capz = PyCapsule_New((void*)(Z), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capiar = PyCapsule_New((void *)(iArr), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capx = PyCapsule_New((void *)(x), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capy = PyCapsule_New((void *)(y), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capu = PyCapsule_New((void *)(U), SWIGPY_CAPSULE_NAME, NULL); + PyObject *capz = PyCapsule_New((void *)(Z), SWIGPY_CAPSULE_NAME, NULL); #else - PyObject* capiar = PyCObject_FromVoidPtr((void*)(iArr), NULL); - PyObject* capx = PyCObject_FromVoidPtr((void*)(x), NULL); - PyObject* capy = PyCObject_FromVoidPtr((void*)(y), NULL); - PyObject* capu = PyCObject_FromVoidPtr((void*)(U), NULL); - PyObject* capz = PyCObject_FromVoidPtr((void*)(Z), NULL); + PyObject *capiar = PyCObject_FromVoidPtr((void *)(iArr), NULL); + PyObject *capx = PyCObject_FromVoidPtr((void *)(x), NULL); + PyObject *capy = PyCObject_FromVoidPtr((void *)(y), NULL); + PyObject *capu = PyCObject_FromVoidPtr((void *)(U), NULL); + PyObject *capz = PyCObject_FromVoidPtr((void *)(Z), NULL); #endif #if NPY_API_VERSION < 0x00000007 - PyArray_BASE(iara) = capiar; - PyArray_BASE(xaa) = capx; - PyArray_BASE(yaa) = capy; - PyArray_BASE(uaa) = capu; - PyArray_BASE(zaa) = capz; + PyArray_BASE(iara) = capiar; + PyArray_BASE(xaa) = capx; + PyArray_BASE(yaa) = capy; + PyArray_BASE(uaa) = capu; + PyArray_BASE(zaa) = capz; #else - PyArray_SetBaseObject(iara,capiar); - PyArray_SetBaseObject(xaa,capx); - PyArray_SetBaseObject(yaa,capy); - PyArray_SetBaseObject(uaa,capu); - PyArray_SetBaseObject(zaa,capz); + PyArray_SetBaseObject(iara, capiar); + PyArray_SetBaseObject(xaa, capx); + PyArray_SetBaseObject(yaa, capy); + PyArray_SetBaseObject(uaa, capu); + PyArray_SetBaseObject(zaa, capz); #endif - args = PyTuple_Pack(9,ial,iar,mo,qo,ua,no,za,xa,ya); - rc = pyobj->fov_reverse(args); - if (PyErr_Occurred()) rc = -1; - Py_DECREF(args); - Py_DECREF(iara); - Py_DECREF(xaa); - Py_DECREF(yaa); - Py_DECREF(uaa); - Py_DECREF(zaa); - Py_DECREF(no); - Py_DECREF(mo); - Py_DECREF(qo); - Py_DECREF(ial); - return rc; - } - int call(int iArrLen, int* iArr, int n, adouble *xa, int m, adouble *ya) { - return EDFobject_iArr::call(iArrLen,iArr,n,xa,m,ya); - } - int call(int iArrLen, int* iArr, int n, advector& x, int m, advector& y) { - return EDFobject_iArr::call(iArrLen,iArr,n,x,m,y); - } - int call(int iArrLen, PyObject* pyarr, int n, advector& x, int m, advector& y) { - int rc; - PyArrayObject *array2 = NULL; - int is_new_object2 = 0; - npy_intp size[1] = { - iArrLen - }; - int *iArr = NULL; - array2 = obj_to_array_contiguous_allow_conversion(pyarr, - NPY_INT, - &is_new_object2); - if (!array2 || !require_dimensions(array2, 1) || - !require_size(array2, size, 1)) SWIG_fail; - iArr = (int*) array_data(array2); - rc = call(iArrLen,iArr,n,x,m,y); - if (is_new_object2 && array2) { - Py_DECREF(array2); - } - return rc; - fail: - if (is_new_object2 && array2) { - Py_DECREF(array2); - } - return -1; - } -}; - -PyEDF_iArr::PyEDF_iArr() { - cobj = new PyEDF_iArr_wrap(); - cobj->setPyObj(this); -} - -PyEDF_iArr::~PyEDF_iArr() { - delete cobj; -} - -int PyEDF_iArr::call(int iArrLen, int* iArr, int n, adouble *xa, int m, adouble *ya) { - return cobj->call(iArrLen,iArr,n,xa,m,ya); -} -int PyEDF_iArr::call(int iArrLen, int* iArr, int n, advector& x, int m, advector& y) { - return cobj->call(iArrLen,iArr,n,x,m,y); -} -int PyEDF_iArr::call(int iArrLen, PyObject* pyarr, int n, advector& x, int m, advector& y) { + args = PyTuple_Pack(9, ial, iar, mo, qo, ua, no, za, xa, ya); + rc = pyobj->fov_reverse(args); + if (PyErr_Occurred()) + rc = -1; + Py_DECREF(args); + Py_DECREF(iara); + Py_DECREF(xaa); + Py_DECREF(yaa); + Py_DECREF(uaa); + Py_DECREF(zaa); + Py_DECREF(no); + Py_DECREF(mo); + Py_DECREF(qo); + Py_DECREF(ial); + return rc; + } + int call(int iArrLen, int *iArr, int n, adouble *xa, int m, adouble *ya) { + return EDFobject_iArr::call(iArrLen, iArr, n, xa, m, ya); + } + int call(int iArrLen, int *iArr, int n, advector &x, int m, advector &y) { + return EDFobject_iArr::call(iArrLen, iArr, n, x, m, y); + } + int call(int iArrLen, PyObject *pyarr, int n, advector &x, int m, + advector &y) { int rc; PyArrayObject *array2 = NULL; int is_new_object2 = 0; - npy_intp size[1] = { - iArrLen - }; + npy_intp size[1] = {iArrLen}; int *iArr = NULL; - array2 = obj_to_array_contiguous_allow_conversion(pyarr, - NPY_INT, + array2 = obj_to_array_contiguous_allow_conversion(pyarr, NPY_INT, &is_new_object2); if (!array2 || !require_dimensions(array2, 1) || - !require_size(array2, size, 1)) SWIG_fail; - iArr = (int*) array_data(array2); - rc = cobj->call(iArrLen,iArr,n,x,m,y); + !require_size(array2, size, 1)) + SWIG_fail; + iArr = (int *)array_data(array2); + rc = call(iArrLen, iArr, n, x, m, y); if (is_new_object2 && array2) { - Py_DECREF(array2); + Py_DECREF(array2); } return rc; fail: if (is_new_object2 && array2) { - Py_DECREF(array2); + Py_DECREF(array2); } return -1; + } +}; + +PyEDF_iArr::PyEDF_iArr() { + cobj = new PyEDF_iArr_wrap(); + cobj->setPyObj(this); +} + +PyEDF_iArr::~PyEDF_iArr() { delete cobj; } + +int PyEDF_iArr::call(int iArrLen, int *iArr, int n, adouble *xa, int m, + adouble *ya) { + return cobj->call(iArrLen, iArr, n, xa, m, ya); +} +int PyEDF_iArr::call(int iArrLen, int *iArr, int n, advector &x, int m, + advector &y) { + return cobj->call(iArrLen, iArr, n, x, m, y); +} +int PyEDF_iArr::call(int iArrLen, PyObject *pyarr, int n, advector &x, int m, + advector &y) { + int rc; + PyArrayObject *array2 = NULL; + int is_new_object2 = 0; + npy_intp size[1] = {iArrLen}; + int *iArr = NULL; + array2 = + obj_to_array_contiguous_allow_conversion(pyarr, NPY_INT, &is_new_object2); + if (!array2 || !require_dimensions(array2, 1) || + !require_size(array2, size, 1)) + SWIG_fail; + iArr = (int *)array_data(array2); + rc = cobj->call(iArrLen, iArr, n, x, m, y); + if (is_new_object2 && array2) { + Py_DECREF(array2); + } + return rc; +fail: + if (is_new_object2 && array2) { + Py_DECREF(array2); + } + return -1; } #endif diff --git a/ADOL-C/test/fminmax.cpp b/ADOL-C/test/fminmax.cpp index 3dde4e997..3b1254baa 100644 --- a/ADOL-C/test/fminmax.cpp +++ b/ADOL-C/test/fminmax.cpp @@ -1,12 +1,11 @@ #include -int main(int, char **) -{ - double x = 3, y = 4; - double a,b; +int main(int, char **) { + double x = 3, y = 4; + double a, b; - a = fmax(x, y); - b = fmin(x, y); + a = fmax(x, y); + b = fmin(x, y); - return 0; + return 0; } diff --git a/ADOL-C/test/powexam.cpp b/ADOL-C/test/powexam.cpp index e671fb638..52965d7a7 100644 --- a/ADOL-C/test/powexam.cpp +++ b/ADOL-C/test/powexam.cpp @@ -4,18 +4,18 @@ Revision: $Id: powexam.cpp 42 2009-07-15 18:37:17Z awalther $ Contents: computation of n-th power for testing - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include /* use of ALL ADOL-C interfaces */ +#include /* use of ALL ADOL-C interfaces */ #include using namespace std; @@ -23,78 +23,77 @@ using namespace std; /****************************************************************************/ /* ADOUBLE ROUTINE */ adouble power(adouble x, int n) { - adouble z = 1; + adouble z = 1; - if (n>0) /* Recursion and branches */ - { int nh = n/2; /* that do not depend on */ - z = power(x,nh); /* adoubles are fine !!!! */ - z *= z; - if (2*nh != n) - z *= x; - return z; - } /* end if */ - else { - if (n==0) /* The local adouble z dies */ - return z; /* as it goes out of scope. */ - else - return 1/power(x,-n); - } /* end else */ + if (n > 0) /* Recursion and branches */ + { + int nh = n / 2; /* that do not depend on */ + z = power(x, nh); /* adoubles are fine !!!! */ + z *= z; + if (2 * nh != n) + z *= x; + return z; + } /* end if */ + else { + if (n == 0) /* The local adouble z dies */ + return z; /* as it goes out of scope. */ + else + return 1 / power(x, -n); + } /* end else */ } /* end power */ /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int i,tag = 1; - int n; + int i, tag = 1; + int n; - cout << "COMPUTATION OF N-TH POWER (ADOL-C Documented Example)\n\n"; - cout << "monomial degree=5 \n"; /* input the desired degree */ - n = 5; - /* allocations and initializations */ - double** X; - double** Y; - X = myalloc2(1,n+4); - Y = myalloc2(1,n+4); - X[0][0] = 0.5; /* function value = 0. coefficient */ - X[0][1] = 1.0; /* first derivative = 1. coefficient */ - for(i=0; i>= Y[0][0]; /* only one dependent adouble */ - trace_off(); /* no global adouble has died */ - /* end of active section */ - double u[1]; /* weighting vector */ - double maxerr = 0; - u[0]=1; /* for reverse call */ - for(i=0; i maxerr) - maxerr = abs(Y[0][i]-y.value()); - } - else { - Z[0][i] = Z[0][i-1]/i; /* scale derivative to Taylorcoeff. */ - cout << Y[0][i] << " - " << Z[0][i] << " = " << Y[0][i]-Z[0][i] - << " (should be 0)\n"; - if (abs( Y[0][i]-Z[0][i]) > maxerr) - maxerr = abs(Y[0][i]-y.value()); - } - reverse(tag,1,1,i,u,Z); /* evaluate the (i+1)-st deriv. */ - } /* end for */ + adouble y, x; /* declare active variables */ + /* beginning of active section */ + trace_on(tag); /* tag = 1 and keep = 0 */ + x <<= X[0][0]; /* only one independent var */ + y = power(x, n); /* actual function call */ + y >>= Y[0][0]; /* only one dependent adouble */ + trace_off(); /* no global adouble has died */ + /* end of active section */ + double u[1]; /* weighting vector */ + double maxerr = 0; + u[0] = 1; /* for reverse call */ + for (i = 0; i < n + 2; i++) /* note that keep = i+1 in call */ + { + forward(tag, 1, 1, i, i + 1, X, Y); /* evaluate the i-the derivative */ + if (i == 0) { + cout << Y[0][i] << " - " << y.value() << " = " << Y[0][i] - y.value() + << " (should be 0)\n"; + if (abs(Y[0][i] - y.value()) > maxerr) + maxerr = abs(Y[0][i] - y.value()); + } else { + Z[0][i] = Z[0][i - 1] / i; /* scale derivative to Taylorcoeff. */ + cout << Y[0][i] << " - " << Z[0][i] << " = " << Y[0][i] - Z[0][i] + << " (should be 0)\n"; + if (abs(Y[0][i] - Z[0][i]) > maxerr) + maxerr = abs(Y[0][i] - y.value()); + } + reverse(tag, 1, 1, i, u, Z); /* evaluate the (i+1)-st deriv. */ + } /* end for */ - if (maxerr < 10e-8) - printf("TEST PASSED\n"); + if (maxerr < 10e-8) + printf("TEST PASSED\n"); - return 1; + return 1; } /* end main */ - diff --git a/ADOL-C/test/speelpenning.cpp b/ADOL-C/test/speelpenning.cpp index 900f2c177..82fc480af 100644 --- a/ADOL-C/test/speelpenning.cpp +++ b/ADOL-C/test/speelpenning.cpp @@ -4,21 +4,21 @@ Revision: $Id: speelpenning.cpp 42 2009-07-15 18:37:17Z awalther $ Contents: speelpennings example for testing - Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, - Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel - + Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, + Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel + This file is part of ADOL-C. This software is provided as open source. - Any use, reproduction, or distribution of the software constitutes + Any use, reproduction, or distribution of the software constitutes recipient's acceptance of the terms of the accompanying license file. - + ---------------------------------------------------------------------------*/ /****************************************************************************/ /* INCLUDES */ -#include // use of active doubles -#include // use of "Easy to Use" drivers +#include // use of active doubles +#include // use of "Easy to Use" drivers // gradient(.) and hessian(.) -#include // use of taping +#include // use of taping #include using namespace std; @@ -29,58 +29,57 @@ using namespace std; /****************************************************************************/ /* MAIN PROGRAM */ int main() { - int n,i,j; - size_t tape_stats[STAT_SIZE]; + int n, i, j; + size_t tape_stats[STAT_SIZE]; - cout << "SPEELPENNINGS PRODUCT (ADOL-C Documented Example)\n\n"; - cout << "number of independent variables = 100 \n"; - n = 100; + cout << "SPEELPENNINGS PRODUCT (ADOL-C Documented Example)\n\n"; + cout << "number of independent variables = 100 \n"; + n = 100; - double *xp = new double[n]; - double yp = 0.0; - adouble *x = new adouble[n]; - adouble y = 1; + double *xp = new double[n]; + double yp = 0.0; + adouble *x = new adouble[n]; + adouble y = 1; - for(i=0; i>= yp; - delete[] x; - trace_off(); - - tapestats(1,tape_stats); // reading of tape statistics - cout<<"maxlive "<j) // lower half of hessian - errh += fabs(H[i][j]-g[i]/xp[j]); - } // end for + trace_on(1); // tag = 1, keep = 0 by default + for (i = 0; i < n; i++) { + x[i] <<= xp[i]; // or x <<= xp outside the loop + y *= x[i]; + } // end for + y >>= yp; + delete[] x; + trace_off(); + + tapestats(1, tape_stats); // reading of tape statistics + cout << "maxlive " << tape_stats[NUM_MAX_LIVES] << "\n"; + // ..... print other tape stats + + double *g = new double[n]; + gradient(1, n, xp, g); // gradient evaluation + + double **H = (double **)malloc(n * sizeof(double *)); + for (i = 0; i < n; i++) + H[i] = (double *)malloc((i + 1) * sizeof(double)); + hessian(1, n, xp, H); // H equals (n-1)g since g is + double errg = 0; // homogeneous of degree n-1. + double errh = 0; + for (i = 0; i < n; i++) + errg += fabs(g[i] - yp / xp[i]); // vanishes analytically. + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i > j) // lower half of hessian + errh += fabs(H[i][j] - g[i] / xp[j]); } // end for - cout << yp-1/(1.0+n) << " error in function \n"; - cout << errg <<" error in gradient \n"; - cout << errh <<" consistency check \n"; - - if ((errg < 10e-8) && (errh < 10e-8)) - printf("TEST PASSED\n"); - - return 1; -} // end main + } // end for + cout << yp - 1 / (1.0 + n) << " error in function \n"; + cout << errg << " error in gradient \n"; + cout << errh << " consistency check \n"; + if ((errg < 10e-8) && (errh < 10e-8)) + printf("TEST PASSED\n"); + + return 1; +} // end main diff --git a/MSVisualStudio/v14/nosparse/config.h b/MSVisualStudio/v14/nosparse/config.h index 4b575cfda..17e10b27c 100644 --- a/MSVisualStudio/v14/nosparse/config.h +++ b/MSVisualStudio/v14/nosparse/config.h @@ -136,7 +136,7 @@ #define HAVE__BOOL 1 /* Define to the sub-directory in which libtool stores uninstalled libraries. - */ + */ #define LT_OBJDIR ".libs/" /* Name of package */ diff --git a/MSVisualStudio/v14/sparse/config.h b/MSVisualStudio/v14/sparse/config.h index 181c48f3d..de32e811c 100644 --- a/MSVisualStudio/v14/sparse/config.h +++ b/MSVisualStudio/v14/sparse/config.h @@ -136,7 +136,7 @@ #define HAVE__BOOL 1 /* Define to the sub-directory in which libtool stores uninstalled libraries. - */ + */ #define LT_OBJDIR ".libs/" /* Name of package */ diff --git a/MSVisualStudio/v14/x64/nosparse/config.h b/MSVisualStudio/v14/x64/nosparse/config.h index a3db7390a..597434bd6 100644 --- a/MSVisualStudio/v14/x64/nosparse/config.h +++ b/MSVisualStudio/v14/x64/nosparse/config.h @@ -136,7 +136,7 @@ #define HAVE__BOOL 1 /* Define to the sub-directory in which libtool stores uninstalled libraries. - */ + */ #define LT_OBJDIR ".libs/" /* Name of package */ diff --git a/MSVisualStudio/v14/x64/sparse/config.h b/MSVisualStudio/v14/x64/sparse/config.h index 367c3c572..cd637b489 100644 --- a/MSVisualStudio/v14/x64/sparse/config.h +++ b/MSVisualStudio/v14/x64/sparse/config.h @@ -136,7 +136,7 @@ #define HAVE__BOOL 1 /* Define to the sub-directory in which libtool stores uninstalled libraries. - */ + */ #define LT_OBJDIR ".libs/" /* Name of package */