From 8bf275cca0bd9561460aceb37ebf258ec666b852 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 19 Dec 2024 19:24:38 +0100 Subject: [PATCH 01/69] rename to cpp --- ADOL-C/include/adolc/interfaces.h | 10 +++++----- ADOL-C/src/fo_rev.c | 2 +- ADOL-C/src/{fos_pl_reverse.c => fos_pl_reverse.cpp} | 2 +- ADOL-C/src/fos_pl_sig_reverse.c | 2 +- ADOL-C/src/{fos_reverse.c => fos_reverse.cpp} | 2 +- ADOL-C/src/{fov_reverse.c => fov_reverse.cpp} | 2 +- ADOL-C/src/{int_reverse_s.c => int_reverse_s.cpp} | 2 +- ADOL-C/src/{int_reverse_t.c => int_reverse_t.cpp} | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) rename ADOL-C/src/{fos_pl_reverse.c => fos_pl_reverse.cpp} (96%) rename ADOL-C/src/{fos_reverse.c => fos_reverse.cpp} (96%) rename ADOL-C/src/{fov_reverse.c => fov_reverse.cpp} (96%) rename ADOL-C/src/{int_reverse_s.c => int_reverse_s.cpp} (96%) rename ADOL-C/src/{int_reverse_t.c => int_reverse_t.cpp} (96%) diff --git a/ADOL-C/include/adolc/interfaces.h b/ADOL-C/include/adolc/interfaces.h index d5b9fbfdd..867ac8542 100644 --- a/ADOL-C/include/adolc/interfaces.h +++ b/ADOL-C/include/adolc/interfaces.h @@ -13,9 +13,9 @@ fov_forward.c hov_forward.c hov_wk_forward.c - fo_rev.c for - fos_reverse.c - fov_reverse.c + fo_rev.cpp for + fos_reverse.cpp + fov_reverse.cpp ho_rev.c for hos_reverse.c hos_ov_reverse.c @@ -352,7 +352,7 @@ ADOLC_DLL_EXPORT int nonl_ind_old_forward_tight(short, int, int, const double *, /*--------------------------------------------------------------------------*/ /* FOS */ /* fos_reverse(tag, m, n, u[m], z[n]) */ -/* (defined in fo_rev.c) */ +/* (defined in fo_rev.cpp) */ ADOLC_DLL_EXPORT int fos_reverse(short, int, int, double *, double *); /* now pack the arrays into vectors for Fortran calling */ @@ -394,7 +394,7 @@ ADOLC_DLL_EXPORT fint hos_ov_reverse_(fint *, fint *, fint *, fint *, fint *, /*--------------------------------------------------------------------------*/ /* FOV */ /* fov_reverse(tag, m, n, p, U[p][m], Z[p][n]) */ -/* (defined in fo_rev.c) */ +/* (defined in fo_rev.cpp) */ ADOLC_DLL_EXPORT int fov_reverse(short, int, int, int, double **, double **); /* now pack the arrays into vectors for Fortran calling */ diff --git a/ADOL-C/src/fo_rev.c b/ADOL-C/src/fo_rev.c index de3cdd2b2..18b0e35f2 100644 --- a/ADOL-C/src/fo_rev.c +++ b/ADOL-C/src/fo_rev.c @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: fo_rev.c + File: fo_rev.cpp Revision: $Id$ Contents: Contains the routines : fos_reverse (first-order-scalar reverse mode) : define _FOS_ diff --git a/ADOL-C/src/fos_pl_reverse.c b/ADOL-C/src/fos_pl_reverse.cpp similarity index 96% rename from ADOL-C/src/fos_pl_reverse.c rename to ADOL-C/src/fos_pl_reverse.cpp index 2cb80abc7..f67e8e80b 100644 --- a/ADOL-C/src/fos_pl_reverse.c +++ b/ADOL-C/src/fos_pl_reverse.cpp @@ -14,6 +14,6 @@ #define _FOS_ 1 #define _ABS_NORM_ 1 -#include +#include #undef _ABS_NORM_ #undef _FOS_ diff --git a/ADOL-C/src/fos_pl_sig_reverse.c b/ADOL-C/src/fos_pl_sig_reverse.c index d8e2372dd..d654d8bd0 100644 --- a/ADOL-C/src/fos_pl_sig_reverse.c +++ b/ADOL-C/src/fos_pl_sig_reverse.c @@ -14,6 +14,6 @@ #define _FOS_ 1 #define _ABS_NORM_SIG_ 1 -#include +#include <> #undef _ABS_NORM_SIG_ #undef _FOS_ diff --git a/ADOL-C/src/fos_reverse.c b/ADOL-C/src/fos_reverse.cpp similarity index 96% rename from ADOL-C/src/fos_reverse.c rename to ADOL-C/src/fos_reverse.cpp index 9b5a3daf1..e45c69eb6 100644 --- a/ADOL-C/src/fos_reverse.c +++ b/ADOL-C/src/fos_reverse.cpp @@ -14,5 +14,5 @@ ----------------------------------------------------------------------------*/ #define _FOS_ 1 -#include +#include #undef _FOS_ diff --git a/ADOL-C/src/fov_reverse.c b/ADOL-C/src/fov_reverse.cpp similarity index 96% rename from ADOL-C/src/fov_reverse.c rename to ADOL-C/src/fov_reverse.cpp index d48b0a6bf..b9b82073f 100644 --- a/ADOL-C/src/fov_reverse.c +++ b/ADOL-C/src/fov_reverse.cpp @@ -14,5 +14,5 @@ ----------------------------------------------------------------------------*/ #define _FOV_ 1 -#include +#include #undef _FOV_ diff --git a/ADOL-C/src/int_reverse_s.c b/ADOL-C/src/int_reverse_s.cpp similarity index 96% rename from ADOL-C/src/int_reverse_s.c rename to ADOL-C/src/int_reverse_s.cpp index 3fc4900b8..4be24b263 100644 --- a/ADOL-C/src/int_reverse_s.c +++ b/ADOL-C/src/int_reverse_s.cpp @@ -13,6 +13,6 @@ ----------------------------------------------------------------------------*/ #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.cpp similarity index 96% rename from ADOL-C/src/int_reverse_t.c rename to ADOL-C/src/int_reverse_t.cpp index e1cfde9c0..0d2603703 100644 --- a/ADOL-C/src/int_reverse_t.c +++ b/ADOL-C/src/int_reverse_t.cpp @@ -13,6 +13,6 @@ ----------------------------------------------------------------------------*/ #define _INT_REV_ 1 #define _TIGHT_ 1 -#include +#include #undef _INT_REV_ #undef _TIGHT_ From 79cef77db83324408c4278c634fbc29af8007900 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 19 Dec 2024 19:27:42 +0100 Subject: [PATCH 02/69] rename to cpp --- ADOL-C/src/CMakeLists.txt | 10 +++++----- ADOL-C/src/{fo_rev.c => fo_rev.cpp} | 0 2 files changed, 5 insertions(+), 5 deletions(-) rename ADOL-C/src/{fo_rev.c => fo_rev.cpp} (100%) diff --git a/ADOL-C/src/CMakeLists.txt b/ADOL-C/src/CMakeLists.txt index 7f63d5b58..084375bd8 100644 --- a/ADOL-C/src/CMakeLists.txt +++ b/ADOL-C/src/CMakeLists.txt @@ -16,15 +16,15 @@ target_sources(adolc PRIVATE forward_partx.c fos_forward.c fos_pl_forward.c - fos_pl_reverse.c + fos_pl_reverse.cpp fos_pl_sig_forward.c - fos_reverse.c + fos_reverse.cpp fov_forward.c fov_offset_forward.c fov_pl_sig_forward.c fos_pl_sig_reverse.c fov_pl_forward.c - fov_reverse.c + fov_reverse.cpp hos_forward.c hos_ov_reverse.c hos_reverse.c @@ -36,8 +36,8 @@ target_sources(adolc PRIVATE indopro_forward_t.c int_forward_s.c int_forward_t.c - int_reverse_s.c - int_reverse_t.c + int_reverse_s.cpp + int_reverse_t.cpp interfaces.cpp interfacesf.c medipacksupport.cpp diff --git a/ADOL-C/src/fo_rev.c b/ADOL-C/src/fo_rev.cpp similarity index 100% rename from ADOL-C/src/fo_rev.c rename to ADOL-C/src/fo_rev.cpp From 0d0898dc0f85a82b1d4f01a3db0ffdba02f18302 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 19 Dec 2024 19:32:01 +0100 Subject: [PATCH 03/69] update some types and init all ptrs --- ADOL-C/src/fo_rev.cpp | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/ADOL-C/src/fo_rev.cpp b/ADOL-C/src/fo_rev.cpp index 18b0e35f2..75f74abd8 100644 --- a/ADOL-C/src/fo_rev.cpp +++ b/ADOL-C/src/fo_rev.cpp @@ -313,19 +313,26 @@ int int_reverse_safe( /*--------------------------------------------------------------------------*/ /* Adjoint stuff */ #ifdef _FOS_ - revreal *rp_A; + double *rp_A = nullptr; #endif #ifdef _FOV_ - revreal **rpp_A, *Aqo; + double **rpp_A = nullptr; + double *Aqo = nullptr; #endif #if !defined(_NTIGHT_) - revreal *rp_T; + double *rp_T = nullptr; #endif /* !_NTIGHT_ */ #if !defined _INT_REV_ - revreal *Ares, *Aarg, *Aarg1, *Aarg2; + double *Ares = nullptr; + double *Aarg = nullptr; + double *Aarg1 = nullptr; + double *Aarg2 = nullptr; #else - unsigned long int **upp_A; - unsigned long int *Ares, *Aarg, *Aarg1, *Aarg2; + size_t **upp_A = nullptr; + size_t *Ares = nullptr; + size_t *Aarg = nullptr; + size_t *Aarg1 = nullptr; + size_t *Aarg2 = nullptr; #endif /*--------------------------------------------------------------------------*/ @@ -374,25 +381,28 @@ int int_reverse_safe( #endif #if !defined(_INT_REV_) locint n, m; - ext_diff_fct *edfct; - ext_diff_fct_v2 *edfct2; + ext_diff_fct *edfct = nullptr; + ext_diff_fct_v2 *edfct2 = nullptr; int iArrLength; - int *iArr; + int *iArr = nullptr; int loop, oloop; int ext_retc; int oldTraceFlag; - locint *insz, *outsz, nin, nout; + locint *insz = nullptr; + locint *outsz = nullptr; + locint nin, nout; #endif #ifdef ADOLC_AMPI_SUPPORT MPI_Op op; - void *buf, *rbuf; + void *buf = nullptr; + void *rbuf = nullptr; int count, rcount; MPI_Datatype datatype, rtype; int src; int tag; enum AMPI_PairedWith_E pairedWith; MPI_Comm comm; - MPI_Status *status; + MPI_Status *status = nullptr; struct AMPI_Request_S request; #endif From b2623d3adc7ec375e079e53d9684d4fca5df36af Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 19 Dec 2024 20:13:18 +0100 Subject: [PATCH 04/69] replace malloc and free --- ADOL-C/src/fo_rev.cpp | 66 ++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/ADOL-C/src/fo_rev.cpp b/ADOL-C/src/fo_rev.cpp index 75f74abd8..b3adb0d88 100644 --- a/ADOL-C/src/fo_rev.cpp +++ b/ADOL-C/src/fo_rev.cpp @@ -462,15 +462,9 @@ int int_reverse_safe( /*--------------------------------------------------------------------------*/ #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); + rp_A = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); 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); + rp_T = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOS_REVERSE; #ifdef _ABS_NORM_ memset(results, 0, sizeof(double) * (indep + swchk)); @@ -490,22 +484,13 @@ int int_reverse_safe( /*--------------------------------------------------------------------------*/ #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); + rpp_A = new double *[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]]; + Aqo = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * p); 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); + rp_T = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOV_REVERSE; #define ADJOINT_BUFFER rpp_A #define ADJOINT_BUFFER_ARG_L rpp_A[arg][l] @@ -523,10 +508,7 @@ int int_reverse_safe( 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); + rp_T = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); #endif #define ADJOINT_BUFFER upp_A #define ADJOINT_BUFFER_ARG_L upp_A[arg][l] @@ -2998,7 +2980,7 @@ int int_reverse_safe( 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)); + iArr = new int[iArrLength]; for (loop = iArrLength - 1; loop >= 0; --loop) iArr[loop] = get_locint_r(); get_locint_r(); /* get it again */ @@ -3073,7 +3055,7 @@ int int_reverse_safe( case ext_diff_v2: nout = get_locint_r(); nin = get_locint_r(); - insz = malloc(2 * (nin + nout) * sizeof(locint)); + insz = new locint[2 * (nin + nout)]; outsz = insz + nin; ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = outsz + nout; ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = outsz + nout + nin; @@ -3088,7 +3070,7 @@ int int_reverse_safe( get_locint_r(); /* nout again */ get_locint_r(); /* nin again */ iArrLength = get_locint_r(); - iArr = malloc(iArrLength * sizeof(int)); + iArr = new int[iArrLength]; for (loop = iArrLength - 1; loop >= 0; --loop) iArr[loop] = get_locint_r(); get_locint_r(); /* iArrLength again */ @@ -3170,11 +3152,11 @@ int int_reverse_safe( } } ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; - free(iArr); - free(insz); - insz = 0; - iArr = 0; - outsz = 0; + delete iArr; + delete insz; + insz = nullptr; + iArr = nullptr; + outsz = nullptr; ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = 0; ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = 0; break; @@ -3274,18 +3256,26 @@ int int_reverse_safe( } /* endwhile */ /* clean up */ -#if !defined(_INT_REV_) - free(rp_T); -#endif #ifdef _FOS_ - free(rp_A); + myfree1(rp_A); + myfree1(rp_T); + ADOLC_CURRENT_TAPE_INFOS.rp_T = nullptr; + ADOLC_CURRENT_TAPE_INFOS.rp_A = nullptr; #endif #ifdef _FOV_ - free(Aqo); - myfree2(rpp_A); + myfree1(Aqo); + delete[] rpp_A; + myfree1(rp_T); + ADOLC_CURRENT_TAPE_INFOS.rp_T = nullptr; + ADOLC_CURRENT_TAPE_INFOS.rpp_A = nullptr; #endif #ifdef _INT_REV_ free(upp_A); +#ifdef _TIGHT_ + ADOLC_CURRENT_TAPE_INFOS.upp_A = nullptr; + myfree1(rp_T); + ADOLC_CURRENT_TAPE_INFOS.rp_T = nullptr; +#endif #endif ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; From 83b1c8a1bdb92ce56d70e1f1f49e6b798a2484ea Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 19 Dec 2024 20:13:59 +0100 Subject: [PATCH 05/69] rename to cpp --- ADOL-C/src/{fos_pl_sig_reverse.c => fos_pl_sig_reverse.cpp} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ADOL-C/src/{fos_pl_sig_reverse.c => fos_pl_sig_reverse.cpp} (96%) diff --git a/ADOL-C/src/fos_pl_sig_reverse.c b/ADOL-C/src/fos_pl_sig_reverse.cpp similarity index 96% rename from ADOL-C/src/fos_pl_sig_reverse.c rename to ADOL-C/src/fos_pl_sig_reverse.cpp index d654d8bd0..04625d013 100644 --- a/ADOL-C/src/fos_pl_sig_reverse.c +++ b/ADOL-C/src/fos_pl_sig_reverse.cpp @@ -14,6 +14,6 @@ #define _FOS_ 1 #define _ABS_NORM_SIG_ 1 -#include <> +#include #undef _ABS_NORM_SIG_ #undef _FOS_ From 1fa3e1910ec565b81305db17d1f0b089369a42da Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 19 Dec 2024 20:14:28 +0100 Subject: [PATCH 06/69] rename to cpp --- ADOL-C/src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADOL-C/src/CMakeLists.txt b/ADOL-C/src/CMakeLists.txt index 084375bd8..3a3c8c305 100644 --- a/ADOL-C/src/CMakeLists.txt +++ b/ADOL-C/src/CMakeLists.txt @@ -22,7 +22,7 @@ target_sources(adolc PRIVATE fov_forward.c fov_offset_forward.c fov_pl_sig_forward.c - fos_pl_sig_reverse.c + fos_pl_sig_reverse.cpp fov_pl_forward.c fov_reverse.cpp hos_forward.c From 8ed77e903c307e326902858a411ab6b558a0c0b2 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 19 Dec 2024 20:15:54 +0100 Subject: [PATCH 07/69] remove tmp variable that caused the error: cannot jump from switch statement to this case label --- ADOL-C/src/fo_rev.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ADOL-C/src/fo_rev.cpp b/ADOL-C/src/fo_rev.cpp index b3adb0d88..7f5e6a468 100644 --- a/ADOL-C/src/fo_rev.cpp +++ b/ADOL-C/src/fo_rev.cpp @@ -1789,9 +1789,8 @@ int int_reverse_safe( } switchnum--; #elif defined(_ABS_NORM_SIG_) - revreal aTmp = *Ares; ARES_INC = 0.0; - AARG_INC += siggrad[switchnum] * aTmp; + AARG_INC += siggrad[switchnum] * (*Ares); switchnum--; #else #if !defined(_NTIGHT_) From d8336273cddaec2dc110912d370fa24a85d8b785 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 08:17:57 +0100 Subject: [PATCH 08/69] rename to cpp --- ADOL-C/include/adolc/externfcts.h | 4 ++-- ADOL-C/include/adolc/interfaces.h | 22 +++++++++---------- ADOL-C/src/CMakeLists.txt | 6 ++--- ADOL-C/src/{ho_rev.c => ho_rev.cpp} | 2 +- .../{hos_ov_reverse.c => hos_ov_reverse.cpp} | 4 ++-- ADOL-C/src/{hos_reverse.c => hos_reverse.cpp} | 4 ++-- ADOL-C/src/{hov_reverse.c => hov_reverse.cpp} | 4 ++-- CMakeLists.txt | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) rename ADOL-C/src/{ho_rev.c => ho_rev.cpp} (99%) rename ADOL-C/src/{hos_ov_reverse.c => hos_ov_reverse.cpp} (91%) rename ADOL-C/src/{hos_reverse.c => hos_reverse.cpp} (93%) rename ADOL-C/src/{hov_reverse.c => hov_reverse.cpp} (93%) diff --git a/ADOL-C/include/adolc/externfcts.h b/ADOL-C/include/adolc/externfcts.h index cdc7f5a6a..416719309 100644 --- a/ADOL-C/include/adolc/externfcts.h +++ b/ADOL-C/include/adolc/externfcts.h @@ -168,7 +168,7 @@ typedef struct ext_diff_fct { ADOLC_ext_fct_iArr_fov_reverse *fov_reverse_iArr; /** * higher order scalar reverse for external functions is currently not - * implemented in ho_rev.c + * implemented in ho_rev.cpp */ ADOLC_ext_fct_hos_reverse *hos_reverse; ADOLC_ext_fct_iArr_hos_reverse *hos_reverse_iArr; @@ -177,7 +177,7 @@ typedef struct ext_diff_fct { /** * higher order vector reverse for external functions is currently not - * implemented in ho_rev.c + * implemented in ho_rev.cpp */ ADOLC_ext_fct_hov_reverse *hov_reverse; ADOLC_ext_fct_iArr_hov_reverse *hov_reverse_iArr; diff --git a/ADOL-C/include/adolc/interfaces.h b/ADOL-C/include/adolc/interfaces.h index 867ac8542..240867706 100644 --- a/ADOL-C/include/adolc/interfaces.h +++ b/ADOL-C/include/adolc/interfaces.h @@ -16,12 +16,12 @@ fo_rev.cpp for fos_reverse.cpp fov_reverse.cpp - ho_rev.c for - hos_reverse.c - hos_ov_reverse.c - hov_reverse.c - hos_ti_reverse.c - hov_ti_reverse.c + ho_rev.cpp for + hos_reverse.cpp + hos_ov_reverse.cpp + hov_reverse.cpp + hos_ti_reverse.cpp + hov_ti_reverse.cpp interfacesC.C interfacesf.c @@ -362,7 +362,7 @@ ADOLC_DLL_EXPORT fint fos_reverse_(fint *, fint *, fint *, fdouble *, /*--------------------------------------------------------------------------*/ /* HOS */ /* hos_reverse(tag, m, n, d, u[m], Z[n][d+1]) */ -/* (defined in ho_rev.c) */ +/* (defined in ho_rev.cpp) */ ADOLC_DLL_EXPORT int hos_reverse(short, int, int, int, const double *, double **); @@ -373,7 +373,7 @@ ADOLC_DLL_EXPORT fint hos_reverse_(fint *, fint *, fint *, fint *, fdouble *, /*--------------------------------------------------------------------------*/ /* HOS_TI */ /* hos_ti_reverse(tag, m, n, d, U[m][d+1], Z[n][d+1]) */ -/* (defined in ho_rev.c) */ +/* (defined in ho_rev.cpp) */ ADOLC_DLL_EXPORT int hos_ti_reverse(short, int, int, int, double **, double **); /* now pack the arrays into vectors for Fortran calling */ @@ -383,7 +383,7 @@ ADOLC_DLL_EXPORT fint hos_ti_reverse_(fint *, fint *, fint *, fint *, 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) */ +/* (defined in ho_rev.cpp) */ ADOLC_DLL_EXPORT int hos_ov_reverse(short, int, int, int, int, double **, double ***); @@ -404,7 +404,7 @@ ADOLC_DLL_EXPORT fint fov_reverse_(fint *, fint *, fint *, fint *, 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) */ +/* (defined in ho_rev.cpp) */ ADOLC_DLL_EXPORT int hov_reverse(short, int, int, int, int, double **, double ***, short **); @@ -415,7 +415,7 @@ ADOLC_DLL_EXPORT fint hov_reverse_(fint *, fint *, fint *, fint *, fint *, /*--------------------------------------------------------------------------*/ /* 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) */ +/* (defined in ho_rev.cpp) */ ADOLC_DLL_EXPORT int hov_ti_reverse(short, int, int, int, int, double ***, double ***, short **); diff --git a/ADOL-C/src/CMakeLists.txt b/ADOL-C/src/CMakeLists.txt index 3a3c8c305..9ee23ff3d 100644 --- a/ADOL-C/src/CMakeLists.txt +++ b/ADOL-C/src/CMakeLists.txt @@ -26,10 +26,10 @@ target_sources(adolc PRIVATE fov_pl_forward.c fov_reverse.cpp hos_forward.c - hos_ov_reverse.c - hos_reverse.c + hos_ov_reverse.cpp + hos_reverse.cpp hov_forward.c - hov_reverse.c + hov_reverse.cpp hov_wk_forward.c indopro_forward_pl.c indopro_forward_s.c diff --git a/ADOL-C/src/ho_rev.c b/ADOL-C/src/ho_rev.cpp similarity index 99% rename from ADOL-C/src/ho_rev.c rename to ADOL-C/src/ho_rev.cpp index b201118f0..1c4dcadb5 100644 --- a/ADOL-C/src/ho_rev.c +++ b/ADOL-C/src/ho_rev.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: ho_rev.c + File: ho_rev.cpp Revision: $Id$ Contents: Contains the routines : hos_reverse (higher-order-scalar reverse mode): diff --git a/ADOL-C/src/hos_ov_reverse.c b/ADOL-C/src/hos_ov_reverse.cpp similarity index 91% rename from ADOL-C/src/hos_ov_reverse.c rename to ADOL-C/src/hos_ov_reverse.cpp index d0eac78bd..1bab2c82e 100644 --- a/ADOL-C/src/hos_ov_reverse.c +++ b/ADOL-C/src/hos_ov_reverse.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: drivers/drivers.h + File: hos_ov_reverse.cpp Revision: $Id$ Contents: hos_ov_reverse (higher-order-scalar reverse mode on vectors) @@ -13,5 +13,5 @@ ----------------------------------------------------------------------------*/ #define _HOS_OV_ 1 -#include +#include #undef _HOS_OV_ diff --git a/ADOL-C/src/hos_reverse.c b/ADOL-C/src/hos_reverse.cpp similarity index 93% rename from ADOL-C/src/hos_reverse.c rename to ADOL-C/src/hos_reverse.cpp index 6e0f19e09..3bcc91f3b 100644 --- a/ADOL-C/src/hos_reverse.c +++ b/ADOL-C/src/hos_reverse.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: hos_reverse.c + File: hos_reverse.cpp Revision: $Id$ Contents: hos_reverse (higher-order-scalar reverse mode) @@ -14,5 +14,5 @@ ----------------------------------------------------------------------------*/ #define _HOS_ 1 -#include +#include #undef _HOS_ diff --git a/ADOL-C/src/hov_reverse.c b/ADOL-C/src/hov_reverse.cpp similarity index 93% rename from ADOL-C/src/hov_reverse.c rename to ADOL-C/src/hov_reverse.cpp index 905eeae27..4c460b5d0 100644 --- a/ADOL-C/src/hov_reverse.c +++ b/ADOL-C/src/hov_reverse.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: hov_reverse.c + File: hov_reverse.cpp Revision: $Id$ Contents: hov_reverse (higher-order-vector reverse mode) @@ -14,5 +14,5 @@ ----------------------------------------------------------------------------*/ #define _HOV_ 1 -#include +#include #undef _HOV_ diff --git a/CMakeLists.txt b/CMakeLists.txt index 3beaf3cd8..9555036f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ target_include_directories(adolc # Set an include directory for the internally used library headers. # -# This includes the files uni5_for.c, fo_rev.c, and ho_rev.c. Even though +# This includes the files uni5_for.c, fo_rev.cpp, and ho_rev.cpp. Even though # they end with .c, they are used like header files. Together with some # preprocessor trickery this is an old-fashioned way to do generic programming. target_include_directories(adolc From f9a0ec5043ea75f54b5565062ccf8606c4178391 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 08:25:26 +0100 Subject: [PATCH 09/69] rm malloc and free --- ADOL-C/src/ho_rev.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 1c4dcadb5..9b225897b 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -3249,8 +3249,8 @@ int hov_ti_reverse(short tnum, /* tape id */ /* 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); + double **dpp_U = new double *[m]; + double **dpp_Z = new double *[n]; if (edfct->ADOLC_EXT_FCT_POINTER == NULL) fail(ADOLC_EXT_DIFF_NULLPOINTER_FUNCTION); @@ -3342,8 +3342,8 @@ int hov_ti_reverse(short tnum, /* tape id */ } ADOLC_CURRENT_TAPE_INFOS.traceFlag = oldTraceFlag; - free(dpp_Z); - free(dpp_U); + delete[] dpp_Z; + delete[] dpp_U; break; } From 8dec56fa213486b90b0797fff32c4f3ca1b61f36 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 08:57:51 +0100 Subject: [PATCH 10/69] fix macro that caused an error due to uninitialized variables --- ADOL-C/src/ho_rev.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 9b225897b..8defef30c 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -200,7 +200,7 @@ results Taylor-Jacobians ------------ Taylor Jacobians #define FOR_0_LE_l_LT_p for (int l = 0; l < p; l++) #define FOR_p_GT_l_GE_0 /* why ? not used here */ #else -#define FOR_0_LE_l_LT_p +#define FOR_0_LE_l_LT_p for (int l = 0; l < p; l++) #define FOR_p_GT_l_GE_0 /* why ? not used here */ #endif @@ -375,8 +375,17 @@ int hov_ti_reverse(short tnum, /* tape id */ const int k1 = k + 1; revreal comp; -#ifdef _ADOLC_VECTOR_ +#ifdef _HOV_ const int p = nrows; + 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; +#else + const int q = 1; + const int p = 1; #endif /****************************************************************************/ @@ -395,17 +404,6 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; -#elif _HOS_OV_ - const int p = nrows; - const int pk1 = p * k1; - const int q = p; -#else - const int q = 1; -#endif - ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; @@ -2088,7 +2086,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Aarg, rpp_A[arg]) Targ = rpp_T[arg]; - FOR_0_LE_l_LT_q { + for (int l = 0; l < q; ++l) { x[l] = 0.0; jj[l] = 0; for (int i = 0; i < k; i++) @@ -3300,7 +3298,7 @@ int hov_ti_reverse(short tnum, /* tape id */ res = ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_rev; // Ares = A[res]; for (int loop = 0; loop < m; ++loop) { - FOR_0_LE_l_LT_q { + for (int l = 0; l < q; ++l) { // ADJOINT_BUFFER_RES_L = 0.; /* \bar{v}_i = 0 !!! */ // rpp_T[res][l] = 0.0; rpp_A[res][l] = 0.0; From bb72694b1b3d093b6e7b767189f8abb6a72b8455 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 08:59:25 +0100 Subject: [PATCH 11/69] replace loop macro --- ADOL-C/src/ho_rev.cpp | 1018 ++++++++++++++++++++--------------------- 1 file changed, 507 insertions(+), 511 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 8defef30c..6daece4da 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -192,17 +192,6 @@ results Taylor-Jacobians ------------ Taylor Jacobians /*--------------------------------------------------------------------------*/ /* loop stuff */ -#ifdef _ADOLC_VECTOR_ -#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 < p; l++) -#define FOR_p_GT_l_GE_0 /* why ? not used here */ -#else -#define FOR_0_LE_l_LT_p for (int l = 0; l < p; l++) -#define FOR_p_GT_l_GE_0 /* why ? not used here */ -#endif #ifdef _HOV_ #define FOR_0_LE_l_LT_pk1 for (int l = 0; l < pk1; l++) @@ -656,19 +645,19 @@ int hov_ti_reverse(short tnum, /* tape id */ 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 < k; i++) { /* ! no temporary */ - AARG_INC += ARES; + for (int l = 0; l < p; l++) + 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; + } } - } GET_TAYL(res, k, p) break; @@ -721,7 +710,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Ares, rpp_A[res]) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { #ifdef _HOV_ if (nonzero) /* ??? question: why here? */ nonzero[l][indexi] = (int)ARES; @@ -743,7 +732,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Ares, rpp_A[res]) ASSIGN_A(Aarg, rpp_A[res]) /* just a helpful pointers */ - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { ARES_INC_O; dc = -1; for (int i = 0; i < k; i++) { @@ -789,17 +778,17 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; - } + for (int l = 0; l < p; l++) + 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; @@ -832,17 +821,17 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; - } + for (int l = 0; l < p; l++) + 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; @@ -855,7 +844,8 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Ares, rpp_A[res]) - FOR_0_LE_l_LT_p if (0 == ARES_INC) + for (int l = 0; l < p; l++) + if (0 == ARES_INC) HOV_INC(Ares, k) else for (int i = 0; i < k; i++) ARES_INC *= coval; GET_TAYL(res, k, p) @@ -870,7 +860,8 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Ares, rpp_A[res]) - FOR_0_LE_l_LT_p if (0 == ARES_INC) + for (int l = 0; l < p; l++) + if (0 == ARES_INC) HOV_INC(Ares, k) else for (int i = 0; i < k; i++) ARES_INC *= coval; GET_TAYL(res, k, p) @@ -890,7 +881,7 @@ int hov_ti_reverse(short tnum, /* tape id */ Tres = rpp_T[res]; Targ = rpp_T[arg]; - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg, k1) HOV_INC(Ares, k1) @@ -937,25 +928,25 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG1_INC += aTmp; - AARG2_INC += aTmp; + 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; @@ -972,21 +963,21 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG_INC += aTmp; + 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; @@ -1001,21 +992,21 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG_INC += aTmp; + 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; @@ -1031,25 +1022,25 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg1, k1) + HOV_INC(Aarg2, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG1_INC += aTmp; - AARG2_INC -= aTmp; + 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; @@ -1064,21 +1055,21 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG_INC -= aTmp; + 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; @@ -1104,51 +1095,52 @@ int hov_ti_reverse(short tnum, /* tape id */ /* 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. + for (int l = 0; l < p; l++) + 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. */ - 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) - } + 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; /*--------------------------------------------------------------------------*/ @@ -1171,7 +1163,7 @@ int hov_ti_reverse(short tnum, /* tape id */ deconv1(k, Targ1, Targ2, Tres); #endif - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { #if defined(_HOS_OV_) deconv1(k, Targ1, Targ2, Tres); #endif @@ -1220,7 +1212,7 @@ int hov_ti_reverse(short tnum, /* tape id */ inconv1(k, Targ1, Targ2, Tres); #endif - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { #if defined(_HOS_OV_) inconv1(k, Targ1, Targ2, Tres); #endif @@ -1259,21 +1251,21 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG_INC += coval * aTmp; + 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; @@ -1289,21 +1281,21 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG_INC += coval * aTmp; + 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; @@ -1329,7 +1321,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -1383,7 +1375,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg, k1) @@ -1431,7 +1423,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg, k1) @@ -1471,21 +1463,21 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG_INC += aTmp; + 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; @@ -1498,21 +1490,21 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Ares, k1) + HOV_INC(Aarg, k1) + } else { + double aTmp = ARES; ARES_INC = 0.0; - AARG_INC -= aTmp; + 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; @@ -1531,7 +1523,7 @@ int hov_ti_reverse(short tnum, /* tape id */ Tres = rpp_T[res]; Targ = rpp_T[arg]; - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg, k1) HOV_INC(Ares, k1) @@ -1563,7 +1555,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Aarg1, rpp_A[arg1]) Targ2 = rpp_T[arg2]; - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg1, k1) HOV_INC(Ares, k1) @@ -1597,7 +1589,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Aarg1, rpp_A[arg1]) Targ2 = rpp_T[arg2]; - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg1, k1) HOV_INC(Ares, k1) @@ -1640,7 +1632,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Aarg1, rpp_A[arg1]) Targ2 = rpp_T[arg2]; - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg1, k1) HOV_INC(Ares, k1) @@ -1672,7 +1664,7 @@ int hov_ti_reverse(short tnum, /* tape id */ Targ = rpp_T[arg]; VEC_COMPUTED_INIT - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg, k1) HOV_INC(Ares, k1) @@ -1714,78 +1706,78 @@ int hov_ti_reverse(short tnum, /* tape id */ } 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); + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) } else { - if (coval <= 0.0) { + 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++) { - Aarg[i] = make_nan(); - Ares[i] = 0; + rp_Ttemp[i] *= coval; + /* printf(" EPS i %d %f\n",i,rp_Ttemp[i]); */ } + inconv0(k, Ares, rp_Ttemp, Aarg); } else { - /* coval not a whole number */ - if (coval - floor(coval) != 0) { + if (coval <= 0.0) { for (int i = 0; i < k; i++) { - if (coval - 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; - } + 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; + /* 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; + } + 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 { - /* 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]; + 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 + VEC_COMPUTED_END - HOV_INC(Ares, k) - HOV_INC(Aarg, k) - HOS_OV_INC(Tres, k) - HOS_OV_INC(Targ, k) - } + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + HOS_OV_INC(Targ, k) + } GET_TAYL(res, k, p) break; @@ -1810,78 +1802,78 @@ int hov_ti_reverse(short tnum, /* tape id */ } 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); + for (int l = 0; l < p; l++) + if (0 == ARES) { + HOV_INC(Aarg, k1) + HOV_INC(Ares, k1) } else { - if (coval <= 0.0) { + 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++) { - Aarg[i] = make_nan(); - Ares[i] = 0; + rp_Ttemp[i] *= coval; + /* printf(" EPS i %d %f\n",i,rp_Ttemp[i]); */ } + inconv0(k, Ares, rp_Ttemp, Aarg); } else { - /* coval not a whole number */ - if (coval - floor(coval) != 0) { + if (coval <= 0.0) { for (int i = 0; i < k; i++) { - if (coval - 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; - } + 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; + /* 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; + } + 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 { - /* 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]; + 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 + VEC_COMPUTED_END - HOV_INC(Ares, k) - HOV_INC(Aarg, k) - HOS_OV_INC(Tres, k) - HOS_OV_INC(Targ, k) - } + HOV_INC(Ares, k) + HOV_INC(Aarg, k) + HOS_OV_INC(Tres, k) + HOS_OV_INC(Targ, k) + } GET_TAYL(res, k, p) break; @@ -1896,26 +1888,26 @@ int hov_ti_reverse(short tnum, /* tape id */ 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) - } + for (int l = 0; l < p; l++) + 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; @@ -1942,23 +1934,23 @@ int hov_ti_reverse(short tnum, /* tape id */ 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) - } + for (int l = 0; l < p; l++) + 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; @@ -1987,7 +1979,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(AP2, Ares) if (Targ1[0] > Targ2[0]) { - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval) && (*AP2)) MINDEC(ret_c, 2); HOV_INC(AP2, k1) @@ -1995,7 +1987,7 @@ int hov_ti_reverse(short tnum, /* tape id */ AP1 = Aarg2; arg = 0; } else if (Targ1[0] < Targ2[0]) { - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((!coval) && (*AP2)) MINDEC(ret_c, 2); HOV_INC(AP2, k1) @@ -2006,7 +1998,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* seems to influence the return value */ for (int i = 1; i < k; i++) { if (Targ1[i] > Targ2[i]) { - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (*AP2) MINDEC(ret_c, 1); HOV_INC(AP2, k1) @@ -2014,7 +2006,7 @@ int hov_ti_reverse(short tnum, /* tape id */ AP1 = Aarg2; arg = i + 1; } else if (Targ1[i] < Targ2[i]) { - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (*AP2) MINDEC(ret_c, 1); HOV_INC(AP2, k1) @@ -2027,7 +2019,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } if (AP1 != NULL) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(AP1, k1) HOV_INC(Ares, k1); @@ -2048,7 +2040,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } else /* both are identical */ { - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg1, k1) HOV_INC(Aarg2, k1) @@ -2100,7 +2092,7 @@ int hov_ti_reverse(short tnum, /* tape id */ HOS_OV_INC(Targ, k) } Targ = rpp_T[arg]; - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg, k1) HOV_INC(Ares, k1) @@ -2145,20 +2137,20 @@ int hov_ti_reverse(short tnum, /* tape id */ 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); + for (int l = 0; l < p; l++) + 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) } - HOV_INC(Aarg, k) - } break; /*--------------------------------------------------------------------------*/ @@ -2174,20 +2166,20 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + 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) } - HOV_INC(Aarg, k) - } break; /****************************************************************************/ @@ -2212,7 +2204,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* olvo 980925 changed code a little bit */ if (*Targ > 0.0) { if (res != arg1) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -2229,7 +2221,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval <= 0.0) && (ARES)) MINDEC(ret_c, 2); HOV_INC(Ares, k1) @@ -2237,7 +2229,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } else /* TARG <= 0.0 */ { if (res != arg2) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg2, k1) @@ -2263,7 +2255,7 @@ int hov_ti_reverse(short tnum, /* tape id */ HOV_INC(Aarg1, k1) } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (ARES) { if (*Targ == 0.0) /* we are at the tie */ { @@ -2297,7 +2289,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* olvo 980925 changed code a little bit */ if (*Targ >= 0.0) { if (res != arg1) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -2314,7 +2306,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval < 0.0) && (ARES)) MINDEC(ret_c, 2); HOV_INC(Ares, k1) @@ -2322,7 +2314,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } else /* TARG < 0.0 */ { if (res != arg2) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg2, k1) @@ -2341,7 +2333,7 @@ int hov_ti_reverse(short tnum, /* tape id */ HOV_INC(Aarg1, k1) } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (ARES) { if (coval < 0.0) MINDEC(ret_c, 2); @@ -2369,7 +2361,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* olvo 980925 changed code a little bit */ if (*Targ == 0.0) /* we are at the tie */ { - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (ARES) AARG1 = 5.0; HOV_INC(Aarg1, k1) @@ -2378,7 +2370,7 @@ int hov_ti_reverse(short tnum, /* tape id */ MINDEC(ret_c, 0); } else if (*Targ > 0.0) { if (res != arg1) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -2395,7 +2387,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval <= 0.0) && (ARES)) MINDEC(ret_c, 2); HOV_INC(Ares, k1) @@ -2417,7 +2409,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* olvo 980925 changed code a little bit */ if (*Targ >= 0.0) { if (res != arg1) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -2434,7 +2426,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval < 0.0) && (ARES)) MINDEC(ret_c, 2); HOV_INC(Ares, k1) @@ -2489,19 +2481,19 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + 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; @@ -2549,19 +2541,19 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; + for (int l = 0; l < p; l++) + 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; @@ -2619,19 +2611,19 @@ int hov_ti_reverse(short tnum, /* tape id */ 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 < k; i++) { /* ! no temporary */ - AARG_INC += ARES; + for (int l = 0; l < p; l++) + 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; + } } - } GET_TAYL(res, k, p) break; @@ -2643,7 +2635,7 @@ int hov_ti_reverse(short tnum, /* tape id */ res = (size_t)trunc(fabs(*Targ1)); ASSIGN_A(Ares, rpp_A[res]) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { #ifdef _HOV_ if (nonzero) /* ??? question: why here? */ nonzero[l][indexi] = (int)ARES; @@ -2688,17 +2680,17 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; - } + for (int l = 0; l < p; l++) + 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; @@ -2734,17 +2726,17 @@ int hov_ti_reverse(short tnum, /* tape id */ 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; - } + for (int l = 0; l < p; l++) + 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; @@ -2758,7 +2750,8 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Ares, rpp_A[res]) - FOR_0_LE_l_LT_p if (0 == ARES_INC) + for (int l = 0; l < p; l++) + if (0 == ARES_INC) HOV_INC(Ares, k) else for (int i = 0; i < k; i++) ARES_INC *= coval; GET_TAYL(res, k, p) @@ -2774,7 +2767,8 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Ares, rpp_A[res]) - FOR_0_LE_l_LT_p if (0 == ARES_INC) + for (int l = 0; l < p; l++) + if (0 == ARES_INC) HOV_INC(Ares, k) else for (int i = 0; i < k; i++) ARES_INC *= coval; GET_TAYL(res, k, p) @@ -2795,7 +2789,7 @@ int hov_ti_reverse(short tnum, /* tape id */ Tres = rpp_T[res]; Targ = rpp_T[arg]; - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg, k1) HOV_INC(Ares, k1) @@ -2831,19 +2825,19 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Aarg, rpp_A[arg + qq]) ASSIGN_A(Ares, rpp_A[res + qq]) - 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; + for (int l = 0; l < p; l++) + 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; + } } - } GET_TAYL(res + qq, k, p) } @@ -2861,7 +2855,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ASSIGN_A(Aarg1, rpp_A[arg1 + qq]) Targ1 = rpp_T[arg1 + qq]; Targ2 = rpp_T[arg2 + qq]; - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Aarg1, k1) HOV_INC(Aarg2, k1) @@ -2954,7 +2948,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* olvo 980925 changed code a little bit */ if (*Targ > 0.0) { if (res != arg1) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -2971,7 +2965,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval <= 0.0) && (ARES)) MINDEC(ret_c, 2); HOV_INC(Ares, k1) @@ -2979,7 +2973,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } else /* TARG <= 0.0 */ { if (res != arg2) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg2, k1) @@ -3005,7 +2999,7 @@ int hov_ti_reverse(short tnum, /* tape id */ HOV_INC(Aarg1, k1) } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (ARES) { if (*Targ == 0.0) /* we are at the tie */ { @@ -3043,7 +3037,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* olvo 980925 changed code a little bit */ if (*Targ >= 0.0) { if (res != arg1) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -3060,7 +3054,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval < 0.0) && (ARES)) MINDEC(ret_c, 2); HOV_INC(Ares, k1) @@ -3068,7 +3062,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } else /* TARG < 0.0 */ { if (res != arg2) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg2, k1) @@ -3087,7 +3081,7 @@ int hov_ti_reverse(short tnum, /* tape id */ HOV_INC(Aarg1, k1) } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (ARES) { if (coval < 0.0) MINDEC(ret_c, 2); @@ -3117,7 +3111,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* olvo 980925 changed code a little bit */ if (*Targ == 0.0) /* we are at the tie */ { - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (ARES) AARG1 = 5.0; HOV_INC(Aarg1, k1) @@ -3126,7 +3120,7 @@ int hov_ti_reverse(short tnum, /* tape id */ MINDEC(ret_c, 0); } else if (*Targ > 0.0) { if (res != arg1) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -3143,7 +3137,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval <= 0.0) && (ARES)) MINDEC(ret_c, 2); HOV_INC(Ares, k1) @@ -3169,7 +3163,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* olvo 980925 changed code a little bit */ if (*Targ >= 0.0) { if (res != arg1) - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if (0 == ARES) { HOV_INC(Ares, k1) HOV_INC(Aarg1, k1) @@ -3186,7 +3180,7 @@ int hov_ti_reverse(short tnum, /* tape id */ } } else - FOR_0_LE_l_LT_p { + for (int l = 0; l < p; l++) { if ((coval < 0.0) && (ARES)) MINDEC(ret_c, 2); HOV_INC(Ares, k1) @@ -3222,7 +3216,9 @@ int hov_ti_reverse(short tnum, /* tape id */ 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 l = 0; l < p; l++) + for (int i = 0; i < k1; i++) + AARG1_INC = 0.0; } for (int j = arg1; j <= arg2; j++) From 2aa4176d17385e0a08df32a05994b1140f887514 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 09:00:22 +0100 Subject: [PATCH 12/69] rm code; belongs to the fov_forward mode --- ADOL-C/src/ho_rev.cpp | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 6daece4da..9d0e6d56c 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -120,30 +120,7 @@ results Taylor-Jacobians ------------ Taylor Jacobians /*--------------------------------------------------------------------------*/ /* 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; - -#elif _HOS_OV_ +#if _HOS_OV_ #define ARES *Ares #define AARG *Aarg #define AARG1 *Aarg1 From 53289dd19c10ed2d78e90f4b1e3712a282d420c5 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 09:01:24 +0100 Subject: [PATCH 13/69] rm unused macros --- ADOL-C/src/ho_rev.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 9d0e6d56c..67cda3e84 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -141,7 +141,6 @@ results Taylor-Jacobians ------------ Taylor Jacobians #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 < q; l++) #else /* _FOV_, _HOS_, _HOV_ */ #define ARES *Ares @@ -164,7 +163,6 @@ results Taylor-Jacobians ------------ Taylor Jacobians #define ASSIGN_A(a, b) a = b; #define HOS_OV_ASSIGN_A(Aqo, Atemp) -#define FOR_0_LE_l_LT_q int l = 0; #endif /*--------------------------------------------------------------------------*/ From 6f131da1343384f6a3a5f041e63acaf4bcbe7a72 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 10:29:56 +0100 Subject: [PATCH 14/69] init ptrs --- ADOL-C/src/ho_rev.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 67cda3e84..b5f94c211 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -319,20 +319,34 @@ int hov_ti_reverse(short tnum, /* tape id */ int indexi = 0, indexd = 0; /* other necessary variables */ - double *x; - int *jj; + double *x = nullptr; + int *jj = nullptr; int taycheck; int numdep, numind; /*----------------------------------------------------------------------*/ /* Taylor stuff */ - revreal *Tres, *Targ, *Targ1, *Targ2, *Tqo, *rp_Ttemp, *rp_Ttemp2; - revreal **rpp_T; + double *Tres = nullptr; + double *Targ = nullptr; + double *Targ1 = nullptr; + double *Targ2 = nullptr; + double *Tqo = nullptr; + double *rp_Ttemp = nullptr; + double *rp_Ttemp2 = nullptr; + double **rpp_T = nullptr; /*----------------------------------------------------------------------*/ /* Adjoint stuff */ - revreal *Ares, *Aarg = NULL, *Aarg1, *Aarg2, *Aqo, *rp_Atemp, *rp_Atemp2; - revreal **rpp_A, *AP1, *AP2; + double *Ares = nullptr; + double *Aarg = nullptr; + double *Aarg1 = nullptr; + double *Aarg2 = nullptr; + double *Aqo = nullptr; + double *rp_Atemp = nullptr; + double *rp_Atemp2 = nullptr; + double **rpp_A = nullptr; + double *AP1 = nullptr; + double *AP2 = nullptr; /*----------------------------------------------------------------------*/ const int k = degre + 1; From baaa398a2b1f42105c2c23e0e6ba9219d6ae8f8d Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 17:09:54 +0100 Subject: [PATCH 15/69] rm variable because this is the same as myalloc2 --- ADOL-C/src/fo_rev.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ADOL-C/src/fo_rev.cpp b/ADOL-C/src/fo_rev.cpp index 7f5e6a468..edbe7aa5f 100644 --- a/ADOL-C/src/fo_rev.cpp +++ b/ADOL-C/src/fo_rev.cpp @@ -317,7 +317,6 @@ int int_reverse_safe( #endif #ifdef _FOV_ double **rpp_A = nullptr; - double *Aqo = nullptr; #endif #if !defined(_NTIGHT_) double *rp_T = nullptr; @@ -484,11 +483,7 @@ int int_reverse_safe( /*--------------------------------------------------------------------------*/ #else #if defined _FOV_ /* FOV */ - rpp_A = new double *[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]]; - Aqo = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * p); - for (j = 0; j < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; j++) { - rpp_A[j] = Aqo + j * p; - } + rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p); ADOLC_CURRENT_TAPE_INFOS.rpp_A = rpp_A; rp_T = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_FOV_REVERSE; @@ -3262,8 +3257,7 @@ int int_reverse_safe( ADOLC_CURRENT_TAPE_INFOS.rp_A = nullptr; #endif #ifdef _FOV_ - myfree1(Aqo); - delete[] rpp_A; + myfree2(rpp_A); myfree1(rp_T); ADOLC_CURRENT_TAPE_INFOS.rp_T = nullptr; ADOLC_CURRENT_TAPE_INFOS.rpp_A = nullptr; From f40dd6ab211348737662bd17a225463e0dc10800 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 17:24:25 +0100 Subject: [PATCH 16/69] rm macro and corresponding variable which was basically useless --- ADOL-C/src/ho_rev.cpp | 66 ++++++++----------------------------------- 1 file changed, 12 insertions(+), 54 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index b5f94c211..1f5490c16 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -125,19 +125,16 @@ results Taylor-Jacobians ------------ Taylor Jacobians #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; @@ -147,22 +144,18 @@ results Taylor-Jacobians ------------ Taylor Jacobians #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, Atemp) #endif /*--------------------------------------------------------------------------*/ @@ -341,7 +334,6 @@ int hov_ti_reverse(short tnum, /* tape id */ double *Aarg = nullptr; double *Aarg1 = nullptr; double *Aarg2 = nullptr; - double *Aqo = nullptr; double *rp_Atemp = nullptr; double *rp_Atemp2 = nullptr; double **rpp_A = nullptr; @@ -419,18 +411,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /*----------------------------------------------------------------------*/ #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 < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; i++) { - rpp_A[i] = Aqo; - Aqo += k1; - } + rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], k1); rpp_T = (revreal **)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * sizeof(revreal *)); if (rpp_T == NULL) @@ -453,18 +434,7 @@ int hov_ti_reverse(short tnum, /* tape id */ int oldTraceFlag; /*----------------------------------------------------------------------*/ #elif _HOV_ /* HOV */ - 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] * pk1 * - sizeof(revreal)); - if (Aqo == NULL) - fail(ADOLC_MALLOC_FAILED); - for (int i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; i++) { - rpp_A[i] = Aqo; - Aqo += pk1; - } + rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], pk1); rpp_T = (revreal **)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * sizeof(revreal *)); if (rpp_T == NULL) @@ -483,18 +453,7 @@ int hov_ti_reverse(short tnum, /* tape id */ ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_HOV_REVERSE; /*----------------------------------------------------------------------*/ #elif _HOS_OV_ /* HOS_OV */ - 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] * pk1 * - sizeof(revreal)); - if (Aqo == NULL) - fail(ADOLC_MALLOC_FAILED); - for (int i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; i++) { - rpp_A[i] = Aqo; - Aqo += pk1; - } + rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], pk1); rpp_T = (revreal **)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * sizeof(revreal *)); if (rpp_T == NULL) @@ -866,7 +825,6 @@ int hov_ti_reverse(short tnum, /* tape id */ 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]; @@ -883,14 +841,13 @@ int hov_ti_reverse(short tnum, /* tape id */ if (arg != res) { inconv(k, Ares, Tres, Aarg); for (int i = 0; i < k; i++) - ARES_INC = AQO_INC; + ARES_INC = *rp_Atemp++; } else for (int i = 0; i < k; i++) - ARES_INC = 2.0 * AQO_INC; + ARES_INC = 2.0 * *rp_Atemp++; HOV_INC(Aarg, k) HOS_OV_INC(Tres, k) HOS_OV_INC(Targ, k) - HOS_OV_ASSIGN_A(Aqo, rp_Atemp) } } break; @@ -2774,7 +2731,6 @@ int hov_ti_reverse(short tnum, /* tape id */ 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]; @@ -2791,14 +2747,13 @@ int hov_ti_reverse(short tnum, /* tape id */ if (arg != res) { inconv(k, Ares, Tres, Aarg); for (int i = 0; i < k; i++) - ARES_INC = AQO_INC; + ARES_INC = *rp_Atemp++; } else for (int i = 0; i < k; i++) - ARES_INC = 2.0 * AQO_INC; + ARES_INC = 2.0 * *rp_Atemp; HOV_INC(Aarg, k) HOS_OV_INC(Tres, k) HOS_OV_INC(Targ, k) - HOS_OV_ASSIGN_A(Aqo, rp_Atemp) } } break; @@ -3364,8 +3319,11 @@ int hov_ti_reverse(short tnum, /* tape id */ /* clean up */ free((char *)*rpp_T); free((char *)rpp_T); - free(*rpp_A); - free(rpp_A); + ADOLC_CURRENT_TAPE_INFOS.rpp_T = nullptr; + + myfree2(rpp_A); + ADOLC_CURRENT_TAPE_INFOS.rpp_A = nullptr; + free(rp_Ttemp); free(rp_Ttemp2); free(rp_Atemp); From 39d842297560c5a35a9fa8d5d1eb62de1ac06954 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 17:39:38 +0100 Subject: [PATCH 17/69] change ptr arithmetic to array indexing; rm not needed ptr and use myalloc2 --- ADOL-C/src/ho_rev.cpp | 53 ++++++++----------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 1f5490c16..856257058 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -323,7 +323,6 @@ int hov_ti_reverse(short tnum, /* tape id */ double *Targ = nullptr; double *Targ1 = nullptr; double *Targ2 = nullptr; - double *Tqo = nullptr; double *rp_Ttemp = nullptr; double *rp_Ttemp2 = nullptr; double **rpp_T = nullptr; @@ -412,18 +411,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /*----------------------------------------------------------------------*/ #ifdef _HOS_ /* HOS */ rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], k1); - rpp_T = (revreal **)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * - sizeof(revreal *)); - if (rpp_T == NULL) - fail(ADOLC_MALLOC_FAILED); - Tqo = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * k * - sizeof(revreal)); - if (Tqo == NULL) - fail(ADOLC_MALLOC_FAILED); - for (int i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; i++) { - rpp_T[i] = Tqo; - Tqo += k; - } + rpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], k); rp_Atemp = (revreal *)malloc(k1 * sizeof(revreal)); rp_Atemp2 = (revreal *)malloc(k1 * sizeof(revreal)); rp_Ttemp2 = (revreal *)malloc(k * sizeof(revreal)); @@ -435,18 +423,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /*----------------------------------------------------------------------*/ #elif _HOV_ /* HOV */ rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], pk1); - rpp_T = (revreal **)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * - sizeof(revreal *)); - if (rpp_T == NULL) - fail(ADOLC_MALLOC_FAILED); - Tqo = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * k * - sizeof(revreal)); - if (Tqo == NULL) - fail(ADOLC_MALLOC_FAILED); - for (int i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; i++) { - rpp_T[i] = Tqo; - Tqo += k; - } + rpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], k); rp_Atemp = (revreal *)malloc(pk1 * sizeof(revreal)); rp_Atemp2 = (revreal *)malloc(pk1 * sizeof(revreal)); rp_Ttemp2 = (revreal *)malloc(k * sizeof(revreal)); @@ -454,18 +431,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /*----------------------------------------------------------------------*/ #elif _HOS_OV_ /* HOS_OV */ rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], pk1); - rpp_T = (revreal **)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * - sizeof(revreal *)); - if (rpp_T == NULL) - fail(ADOLC_MALLOC_FAILED); - Tqo = (revreal *)malloc(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES] * p * - k * sizeof(revreal)); - if (Tqo == NULL) - fail(ADOLC_MALLOC_FAILED); - for (int i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]; i++) { - rpp_T[i] = Tqo; - Tqo += p * k; - } + rpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p * k); rp_Atemp = (revreal *)malloc(pk1 * sizeof(revreal)); rp_Atemp2 = (revreal *)malloc(pk1 * sizeof(revreal)); rp_Ttemp2 = (revreal *)malloc(p * k * sizeof(revreal)); @@ -841,10 +807,10 @@ int hov_ti_reverse(short tnum, /* tape id */ if (arg != res) { inconv(k, Ares, Tres, Aarg); for (int i = 0; i < k; i++) - ARES_INC = *rp_Atemp++; + ARES_INC = rp_Atemp[i]; } else for (int i = 0; i < k; i++) - ARES_INC = 2.0 * *rp_Atemp++; + ARES_INC = 2.0 * rp_Atemp[i]; HOV_INC(Aarg, k) HOS_OV_INC(Tres, k) HOS_OV_INC(Targ, k) @@ -2747,10 +2713,10 @@ int hov_ti_reverse(short tnum, /* tape id */ if (arg != res) { inconv(k, Ares, Tres, Aarg); for (int i = 0; i < k; i++) - ARES_INC = *rp_Atemp++; + ARES_INC = rp_Atemp[i]; } else for (int i = 0; i < k; i++) - ARES_INC = 2.0 * *rp_Atemp; + ARES_INC = 2.0 * rp_Atemp[i]; HOV_INC(Aarg, k) HOS_OV_INC(Tres, k) HOS_OV_INC(Targ, k) @@ -2858,7 +2824,7 @@ int hov_ti_reverse(short tnum, /* tape id */ inconv(k, rp_Atemp, Targ1, Aarg); inconv(k, rp_Atemp, Targ, Aarg1); for (int i = 0; i < k; i++) - AARG2_INC += *rp_Atemp++; + AARG2_INC += rp_Atemp[i]; HOV_INC(Ares, k) HOV_INC(Aarg, k) @@ -3317,8 +3283,7 @@ int hov_ti_reverse(short tnum, /* tape id */ #endif /* ADOLC_DEBUG */ /* clean up */ - free((char *)*rpp_T); - free((char *)rpp_T); + myfree2(rpp_T); ADOLC_CURRENT_TAPE_INFOS.rpp_T = nullptr; myfree2(rpp_A); From 1065ffe24d65be84bd6ca8ed1f5c8267c2f9bfdb Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 17:42:42 +0100 Subject: [PATCH 18/69] replace malloc with myalloc --- ADOL-C/src/ho_rev.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 856257058..483579818 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -412,29 +412,29 @@ int hov_ti_reverse(short tnum, /* tape id */ #ifdef _HOS_ /* HOS */ rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], k1); rpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], k); - rp_Atemp = (revreal *)malloc(k1 * sizeof(revreal)); - rp_Atemp2 = (revreal *)malloc(k1 * sizeof(revreal)); - rp_Ttemp2 = (revreal *)malloc(k * sizeof(revreal)); + rp_Atemp = myalloc1(k1); + rp_Atemp2 = myalloc1(k1); + rp_Ttemp2 = myalloc1(k); ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_HOS_REVERSE; locint n, m; - ext_diff_fct *edfct; + ext_diff_fct *edfct = nullptr; int oldTraceFlag; /*----------------------------------------------------------------------*/ #elif _HOV_ /* HOV */ rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], pk1); rpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], k); - rp_Atemp = (revreal *)malloc(pk1 * sizeof(revreal)); - rp_Atemp2 = (revreal *)malloc(pk1 * sizeof(revreal)); - rp_Ttemp2 = (revreal *)malloc(k * sizeof(revreal)); + rp_Atemp = myalloc1(pk1); + rp_Atemp2 = myalloc1(pk1); + rp_Ttemp2 = myalloc1(k); ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_HOV_REVERSE; /*----------------------------------------------------------------------*/ #elif _HOS_OV_ /* HOS_OV */ rpp_A = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], pk1); rpp_T = myalloc2(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p * k); - rp_Atemp = (revreal *)malloc(pk1 * sizeof(revreal)); - rp_Atemp2 = (revreal *)malloc(pk1 * sizeof(revreal)); - rp_Ttemp2 = (revreal *)malloc(p * k * sizeof(revreal)); + rp_Atemp = myalloc1(pk1); + rp_Atemp2 = myalloc1(pk1); + rp_Ttemp2 = myalloc1(p * k); ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_HOV_REVERSE; #endif rp_Ttemp = (revreal *)malloc(k * sizeof(revreal)); @@ -3289,10 +3289,10 @@ int hov_ti_reverse(short tnum, /* tape id */ myfree2(rpp_A); ADOLC_CURRENT_TAPE_INFOS.rpp_A = nullptr; - free(rp_Ttemp); - free(rp_Ttemp2); - free(rp_Atemp); - free(rp_Atemp2); + myfree1(rp_Ttemp); + myfree1(rp_Ttemp2); + myfree1(rp_Atemp); + myfree1(rp_Atemp2); free((char *)jj); free((char *)x); From f2ad91a4a9d88af507ac0e8d7df22efcd9000dc2 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 17:47:44 +0100 Subject: [PATCH 19/69] change malloc to myalloc; and jj to ulong --- ADOL-C/src/ho_rev.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index 483579818..a3d44d72f 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -313,7 +313,7 @@ int hov_ti_reverse(short tnum, /* tape id */ /* other necessary variables */ double *x = nullptr; - int *jj = nullptr; + size_t *jj = nullptr; int taycheck; int numdep, numind; @@ -437,15 +437,9 @@ int hov_ti_reverse(short tnum, /* tape id */ rp_Ttemp2 = myalloc1(p * k); ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_HOV_REVERSE; #endif - rp_Ttemp = (revreal *)malloc(k * sizeof(revreal)); - if (rp_Ttemp == NULL) - fail(ADOLC_MALLOC_FAILED); - if (rp_Ttemp2 == NULL) - fail(ADOLC_MALLOC_FAILED); + rp_Ttemp = myalloc1(k); x = myalloc1(q); - jj = (int *)malloc(q * sizeof(int)); - if (jj == NULL) - fail(ADOLC_MALLOC_FAILED); + jj = myalloc1_ulong(q); /************************************************************************/ /* TAYLOR INITIALIZATION */ @@ -3294,8 +3288,8 @@ int hov_ti_reverse(short tnum, /* tape id */ myfree1(rp_Atemp); myfree1(rp_Atemp2); - free((char *)jj); - free((char *)x); + myfree1_ulong(jj); + myfree1(x); ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; end_sweep(); From 68e37c7db3826e5a56a89a35343ceadd5997e413 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 20:03:45 +0100 Subject: [PATCH 20/69] rename to cpp --- ADOL-C/boost-test/uni5_for.cpp | 2 +- ADOL-C/include/adolc/externfcts.h | 4 +- ADOL-C/include/adolc/interfaces.h | 32 +++++++------- ADOL-C/src/CMakeLists.txt | 42 +++++++++---------- ADOL-C/src/{fos_forward.c => fos_forward.cpp} | 2 +- .../{fos_pl_forward.c => fos_pl_forward.cpp} | 4 +- ...l_sig_forward.c => fos_pl_sig_forward.cpp} | 4 +- ADOL-C/src/{fov_forward.c => fov_forward.cpp} | 4 +- ...ffset_forward.c => fov_offset_forward.cpp} | 4 +- .../{fov_pl_forward.c => fov_pl_forward.cpp} | 4 +- ...l_sig_forward.c => fov_pl_sig_forward.cpp} | 4 +- ADOL-C/src/{hos_forward.c => hos_forward.cpp} | 4 +- ADOL-C/src/{hov_forward.c => hov_forward.cpp} | 4 +- .../{hov_wk_forward.c => hov_wk_forward.cpp} | 4 +- ...ro_forward_pl.c => indopro_forward_pl.cpp} | 4 +- ...opro_forward_s.c => indopro_forward_s.cpp} | 4 +- ...opro_forward_t.c => indopro_forward_t.cpp} | 4 +- .../{int_forward_s.c => int_forward_s.cpp} | 4 +- .../{int_forward_t.c => int_forward_t.cpp} | 4 +- ...ind_forward_s.c => nonl_ind_forward_s.cpp} | 4 +- ...ind_forward_t.c => nonl_ind_forward_t.cpp} | 4 +- ...forward_s.c => nonl_ind_old_forward_s.cpp} | 4 +- ...forward_t.c => nonl_ind_old_forward_t.cpp} | 4 +- ADOL-C/src/{uni5_for.c => uni5_for.cpp} | 2 +- ADOL-C/src/{zos_forward.c => zos_forward.cpp} | 4 +- .../{zos_pl_forward.c => zos_pl_forward.cpp} | 4 +- CMakeLists.txt | 2 +- 27 files changed, 83 insertions(+), 83 deletions(-) rename ADOL-C/src/{fos_forward.c => fos_forward.cpp} (96%) rename ADOL-C/src/{fos_pl_forward.c => fos_pl_forward.cpp} (92%) rename ADOL-C/src/{fos_pl_sig_forward.c => fos_pl_sig_forward.cpp} (92%) rename ADOL-C/src/{fov_forward.c => fov_forward.cpp} (93%) rename ADOL-C/src/{fov_offset_forward.c => fov_offset_forward.cpp} (92%) rename ADOL-C/src/{fov_pl_forward.c => fov_pl_forward.cpp} (92%) rename ADOL-C/src/{fov_pl_sig_forward.c => fov_pl_sig_forward.cpp} (92%) rename ADOL-C/src/{hos_forward.c => hos_forward.cpp} (93%) rename ADOL-C/src/{hov_forward.c => hov_forward.cpp} (93%) rename ADOL-C/src/{hov_wk_forward.c => hov_wk_forward.cpp} (91%) rename ADOL-C/src/{indopro_forward_pl.c => indopro_forward_pl.cpp} (92%) rename ADOL-C/src/{indopro_forward_s.c => indopro_forward_s.cpp} (92%) rename ADOL-C/src/{indopro_forward_t.c => indopro_forward_t.cpp} (92%) rename ADOL-C/src/{int_forward_s.c => int_forward_s.cpp} (92%) rename ADOL-C/src/{int_forward_t.c => int_forward_t.cpp} (92%) rename ADOL-C/src/{nonl_ind_forward_s.c => nonl_ind_forward_s.cpp} (91%) rename ADOL-C/src/{nonl_ind_forward_t.c => nonl_ind_forward_t.cpp} (91%) rename ADOL-C/src/{nonl_ind_old_forward_s.c => nonl_ind_old_forward_s.cpp} (92%) rename ADOL-C/src/{nonl_ind_old_forward_t.c => nonl_ind_old_forward_t.cpp} (92%) rename ADOL-C/src/{uni5_for.c => uni5_for.cpp} (99%) rename ADOL-C/src/{zos_forward.c => zos_forward.cpp} (93%) rename ADOL-C/src/{zos_pl_forward.c => zos_pl_forward.cpp} (92%) diff --git a/ADOL-C/boost-test/uni5_for.cpp b/ADOL-C/boost-test/uni5_for.cpp index e3e19b2d8..4910cb32d 100644 --- a/ADOL-C/boost-test/uni5_for.cpp +++ b/ADOL-C/boost-test/uni5_for.cpp @@ -1,6 +1,6 @@ /* -File for explicit testing functions from uni5_for.c file. +File for explicit testing functions from uni5_for.cpp file. */ #define BOOST_TEST_DYN_LINK diff --git a/ADOL-C/include/adolc/externfcts.h b/ADOL-C/include/adolc/externfcts.h index 416719309..a52b34984 100644 --- a/ADOL-C/include/adolc/externfcts.h +++ b/ADOL-C/include/adolc/externfcts.h @@ -144,13 +144,13 @@ typedef struct ext_diff_fct { ADOLC_ext_fct_iArr_fov_forward *fov_forward_iArr; /** * higher order scalar forward for external functions is currently not - * implemented in uni5_for.c + * implemented in uni5_for.cpp */ 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 + * implemented in uni5_for.cpp */ ADOLC_ext_fct_hov_forward *hov_forward; ADOLC_ext_fct_iArr_hov_forward *hov_forward_iArr; diff --git a/ADOL-C/include/adolc/interfaces.h b/ADOL-C/include/adolc/interfaces.h index 240867706..958e157dd 100644 --- a/ADOL-C/include/adolc/interfaces.h +++ b/ADOL-C/include/adolc/interfaces.h @@ -6,13 +6,13 @@ reverse calls (C++, C and Fortran callable C functions). Functions prototyped here are defined in the files - uni5_for.c for - zos_forward.c - fos_forward.c - hos_forward.c - fov_forward.c - hov_forward.c - hov_wk_forward.c + uni5_for.cpp for + zos_forward.cpp + fos_forward.cpp + hos_forward.cpp + fov_forward.cpp + hov_forward.cpp + hov_wk_forward.cpp fo_rev.cpp for fos_reverse.cpp fov_reverse.cpp @@ -182,12 +182,12 @@ BEGIN_C_DECLS /*--------------------------------------------------------------------------*/ /* ZOS */ /* zos_forward(tag, m, n, keep, x[n], y[m]) */ -/* (defined in uni5_for.c) */ +/* (defined in uni5_for.cpp) */ 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) */ +/* (no keep, defined in uni5_for.cpp, but not supported in ADOL-C 1.8) */ 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]) */ @@ -199,12 +199,12 @@ ADOLC_DLL_EXPORT int zos_forward_partx(short, int, int, int *, double **, /*--------------------------------------------------------------------------*/ /* FOS */ /* fos_forward(tag, m, n, keep, x[n], X[n], y[m], Y[m]) */ -/* (defined in uni5_for.c) */ +/* (defined in uni5_for.cpp) */ 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) */ +/* (no keep, defined in uni5_for.cpp, but not supported in ADOL-C 1.8) */ ADOLC_DLL_EXPORT int fos_forward_nk(short, int, int, const double *, const double *, double *, double *); @@ -216,12 +216,12 @@ ADOLC_DLL_EXPORT int fos_forward_partx(short, int, int, int *, double ***, /*--------------------------------------------------------------------------*/ /* HOS */ /* hos_forward(tag, m, n, d, keep, x[n], X[n][d], y[m], Y[m][d]) */ -/* (defined in uni5_for.c) */ +/* (defined in uni5_for.cpp) */ 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) */ +/* (no keep, defined in uni5_for.cpp, but not supported in ADOL-C 1.8) */ ADOLC_DLL_EXPORT int hos_forward_nk(short, int, int, int, const double *, double **, double *, double **); @@ -237,7 +237,7 @@ ADOLC_DLL_EXPORT fint hos_forward_(fint *, fint *, fint *, fint *, fint *, /*--------------------------------------------------------------------------*/ /* FOV */ /* fov_forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]) */ -/* (defined in uni5_for.c) */ +/* (defined in uni5_for.cpp) */ 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, @@ -256,7 +256,7 @@ ADOLC_DLL_EXPORT int fov_forward_partx(short, int, int, int *, int, 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) */ +/* (defined in uni5_for.cpp) */ ADOLC_DLL_EXPORT int hov_forward(short, int, int, int, int, const double *, double ***, double *, double ***); @@ -273,7 +273,7 @@ ADOLC_DLL_EXPORT int hov_forward_partx(short, int, int, int *, int, int, /*--------------------------------------------------------------------------*/ /* 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) */ +/* (defined in uni5_for.cpp) */ ADOLC_DLL_EXPORT int hov_wk_forward(short, int, int, int, int, int, const double *, double ***, double *, double ***); diff --git a/ADOL-C/src/CMakeLists.txt b/ADOL-C/src/CMakeLists.txt index 9ee23ff3d..45e02511d 100644 --- a/ADOL-C/src/CMakeLists.txt +++ b/ADOL-C/src/CMakeLists.txt @@ -14,45 +14,45 @@ target_sources(adolc PRIVATE fixpoint.cpp fortutils.c forward_partx.c - fos_forward.c - fos_pl_forward.c + fos_forward.cpp + fos_pl_forward.cpp fos_pl_reverse.cpp - fos_pl_sig_forward.c + fos_pl_sig_forward.cpp fos_reverse.cpp - fov_forward.c - fov_offset_forward.c - fov_pl_sig_forward.c + fov_forward.cpp + fov_offset_forward.cpp + fov_pl_sig_forward.cpp fos_pl_sig_reverse.cpp - fov_pl_forward.c + fov_pl_forward.cpp fov_reverse.cpp - hos_forward.c + hos_forward.cpp hos_ov_reverse.cpp hos_reverse.cpp - hov_forward.c + hov_forward.cpp hov_reverse.cpp - hov_wk_forward.c - indopro_forward_pl.c - indopro_forward_s.c - indopro_forward_t.c - int_forward_s.c - int_forward_t.c + hov_wk_forward.cpp + indopro_forward_pl.cpp + indopro_forward_s.cpp + indopro_forward_t.cpp + int_forward_s.cpp + int_forward_t.cpp int_reverse_s.cpp int_reverse_t.cpp interfaces.cpp interfacesf.c medipacksupport.cpp - nonl_ind_forward_s.c - nonl_ind_forward_t.c - nonl_ind_old_forward_s.c - nonl_ind_old_forward_t.c + nonl_ind_forward_s.cpp + nonl_ind_forward_t.cpp + nonl_ind_old_forward_s.cpp + nonl_ind_old_forward_t.cpp param.cpp revolve.c rpl_malloc.c storemanager.cpp tape_handling.cpp taping.c - zos_forward.c - zos_pl_forward.c + zos_forward.cpp + zos_pl_forward.cpp ) add_subdirectory(drivers) diff --git a/ADOL-C/src/fos_forward.c b/ADOL-C/src/fos_forward.cpp similarity index 96% rename from ADOL-C/src/fos_forward.c rename to ADOL-C/src/fos_forward.cpp index 69edc6d59..ccc886152 100644 --- a/ADOL-C/src/fos_forward.c +++ b/ADOL-C/src/fos_forward.cpp @@ -14,6 +14,6 @@ ----------------------------------------------------------------------------*/ #define _FOS_ 1 #define _KEEP_ 1 -#include +#include #undef _KEEP_ #undef _FOS_ diff --git a/ADOL-C/src/fos_pl_forward.c b/ADOL-C/src/fos_pl_forward.cpp similarity index 92% rename from ADOL-C/src/fos_pl_forward.c rename to ADOL-C/src/fos_pl_forward.cpp index deddf41ec..1de01d8d9 100644 --- a/ADOL-C/src/fos_pl_forward.c +++ b/ADOL-C/src/fos_pl_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: fos_an_forward.c + File: fos_an_forward.cpp Revision: $Id$ Contents: fos_an_forward (first-order-scalar abs-normal forward mode) @@ -14,6 +14,6 @@ #define _FOS_ 1 #undef _KEEP_ #define _ABS_NORM_ 1 -#include +#include #undef _ABS_NORM_ #undef _FOS_ diff --git a/ADOL-C/src/fos_pl_sig_forward.c b/ADOL-C/src/fos_pl_sig_forward.cpp similarity index 92% rename from ADOL-C/src/fos_pl_sig_forward.c rename to ADOL-C/src/fos_pl_sig_forward.cpp index f06a396cb..9ba6b44db 100644 --- a/ADOL-C/src/fos_pl_sig_forward.c +++ b/ADOL-C/src/fos_pl_sig_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: fos_an_forward.c + File: fos_an_forward.cpp Revision: $Id$ Contents: fos_an_forward (first-order-scalar abs-normal forward mode) @@ -14,6 +14,6 @@ #define _FOS_ 1 #undef _KEEP_ #define _ABS_NORM_SIG_ 1 -#include +#include #undef _ABS_NORM_SIG_ #undef _FOS_ diff --git a/ADOL-C/src/fov_forward.c b/ADOL-C/src/fov_forward.cpp similarity index 93% rename from ADOL-C/src/fov_forward.c rename to ADOL-C/src/fov_forward.cpp index c0d5c02be..7f69aa7e9 100644 --- a/ADOL-C/src/fov_forward.c +++ b/ADOL-C/src/fov_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: fov_forward.c + File: fov_forward.cpp Revision: $Id$ Contents: fov_forward (first-order-vector forward mode) @@ -14,5 +14,5 @@ ----------------------------------------------------------------------------*/ #define _FOV_ 1 #undef _KEEP_ -#include +#include #undef _FOV_ diff --git a/ADOL-C/src/fov_offset_forward.c b/ADOL-C/src/fov_offset_forward.cpp similarity index 92% rename from ADOL-C/src/fov_offset_forward.c rename to ADOL-C/src/fov_offset_forward.cpp index 57592aec1..c40d44aa0 100644 --- a/ADOL-C/src/fov_offset_forward.c +++ b/ADOL-C/src/fov_offset_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: fov_offset_forward.c + File: fov_offset_forward.cpp Revision: $Id$ Contents: fov_offset_forward (first-order-vector forward mode with p-offset in arguments and taylors) @@ -15,6 +15,6 @@ #define _FOV_ 1 #define _CHUNKED_ #undef _KEEP_ -#include +#include #undef _CHUNKED_ #undef _FOV_ diff --git a/ADOL-C/src/fov_pl_forward.c b/ADOL-C/src/fov_pl_forward.cpp similarity index 92% rename from ADOL-C/src/fov_pl_forward.c rename to ADOL-C/src/fov_pl_forward.cpp index f3795f36e..1e8f8b594 100644 --- a/ADOL-C/src/fov_pl_forward.c +++ b/ADOL-C/src/fov_pl_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: fov_an_forward.c + File: fov_pl_forward.cpp Revision: $Id$ Contents: fov_an_forward (first-order-vector abs-normal forward mode) @@ -14,6 +14,6 @@ #define _FOV_ 1 #undef _KEEP_ #define _ABS_NORM_ 1 -#include +#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.cpp similarity index 92% rename from ADOL-C/src/fov_pl_sig_forward.c rename to ADOL-C/src/fov_pl_sig_forward.cpp index 941281453..0998e496d 100644 --- a/ADOL-C/src/fov_pl_sig_forward.c +++ b/ADOL-C/src/fov_pl_sig_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: fov_an_forward.c + File: fov_an_forward.cpp Revision: $Id$ Contents: fov_an_forward (first-order-vector abs-normal forward mode) @@ -14,6 +14,6 @@ #define _FOV_ 1 #undef _KEEP_ #define _ABS_NORM_SIG_ 1 -#include +#include #undef _ABS_NORM_SIG_ #undef _FOV_ diff --git a/ADOL-C/src/hos_forward.c b/ADOL-C/src/hos_forward.cpp similarity index 93% rename from ADOL-C/src/hos_forward.c rename to ADOL-C/src/hos_forward.cpp index 1946ebfe4..4ccbd4dae 100644 --- a/ADOL-C/src/hos_forward.c +++ b/ADOL-C/src/hos_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: hos_forward.c + File: hos_forward.cpp Revision: $Id$ Contents: hos_forward (higher-order-scalar forward mode) @@ -14,6 +14,6 @@ ----------------------------------------------------------------------------*/ #define _HOS_ 1 #define _KEEP_ 1 -#include +#include #undef _KEEP_ #undef _HOS_ diff --git a/ADOL-C/src/hov_forward.c b/ADOL-C/src/hov_forward.cpp similarity index 93% rename from ADOL-C/src/hov_forward.c rename to ADOL-C/src/hov_forward.cpp index 201276ea1..b67b5c082 100644 --- a/ADOL-C/src/hov_forward.c +++ b/ADOL-C/src/hov_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: hov_forward.c + File: hov_forward.cpp Revision: $Id$ Contents: hov_forward (higher-order-vector forward mode) @@ -14,5 +14,5 @@ ----------------------------------------------------------------------------*/ #define _HOV_ 1 #undef _KEEP_ -#include +#include #undef _HOV_ diff --git a/ADOL-C/src/hov_wk_forward.c b/ADOL-C/src/hov_wk_forward.cpp similarity index 91% rename from ADOL-C/src/hov_wk_forward.c rename to ADOL-C/src/hov_wk_forward.cpp index 2982385bb..1ab8c5c84 100644 --- a/ADOL-C/src/hov_wk_forward.c +++ b/ADOL-C/src/hov_wk_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: hov_wk_forward.c + File: hov_wk_forward.cpp Revision: $Id$ Contents: hov_wk_forward (higher-order-vector forward mode with keep) @@ -13,6 +13,6 @@ ----------------------------------------------------------------------------*/ #define _HOV_WK_ 1 #define _KEEP_ 1 -#include +#include #undef _KEEP_ #undef _HOV_WK_ diff --git a/ADOL-C/src/indopro_forward_pl.c b/ADOL-C/src/indopro_forward_pl.cpp similarity index 92% rename from ADOL-C/src/indopro_forward_pl.c rename to ADOL-C/src/indopro_forward_pl.cpp index ea484cc6e..504601694 100644 --- a/ADOL-C/src/indopro_forward_pl.c +++ b/ADOL-C/src/indopro_forward_pl.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: indopro_forward_pl.c + File: indopro_forward_pl.cpp Revision: $Id$ Contents: indopro_forward_pl (index domains abs-normal forward mode) @@ -15,7 +15,7 @@ #define _INDOPRO_ 1 #define _NTIGHT_ 1 #define _ABS_NORM_ 1 -#include +#include #undef _ABS_NORM_ #undef _NTIGHT_ #undef _INDOPRO_ diff --git a/ADOL-C/src/indopro_forward_s.c b/ADOL-C/src/indopro_forward_s.cpp similarity index 92% rename from ADOL-C/src/indopro_forward_s.c rename to ADOL-C/src/indopro_forward_s.cpp index 173b27975..b464cb467 100644 --- a/ADOL-C/src/indopro_forward_s.c +++ b/ADOL-C/src/indopro_forward_s.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: int_forward_s.c + File: int_forward_s.cpp Revision: $Id$ Contents: int_forward (integer forward mode for bit pattern propagation) @@ -14,7 +14,7 @@ #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.cpp similarity index 92% rename from ADOL-C/src/indopro_forward_t.c rename to ADOL-C/src/indopro_forward_t.cpp index 9cbfa04f4..cc4b4434a 100644 --- a/ADOL-C/src/indopro_forward_t.c +++ b/ADOL-C/src/indopro_forward_t.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: int_forward_t.c + File: int_forward_t.cpp Revision: $Id$ Contents: int_forward (integer forward mode for bit pattern propagation) @@ -14,7 +14,7 @@ #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.cpp similarity index 92% rename from ADOL-C/src/int_forward_s.c rename to ADOL-C/src/int_forward_s.cpp index 1ac4a4022..dfc9eb967 100644 --- a/ADOL-C/src/int_forward_s.c +++ b/ADOL-C/src/int_forward_s.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: int_forward_s.c + File: int_forward_s.cpp Revision: $Id$ Contents: int_forward (integer forward mode safe for bit pattern propagation) @@ -13,6 +13,6 @@ ----------------------------------------------------------------------------*/ #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.cpp similarity index 92% rename from ADOL-C/src/int_forward_t.c rename to ADOL-C/src/int_forward_t.cpp index 31c44b1bc..5b360fd39 100644 --- a/ADOL-C/src/int_forward_t.c +++ b/ADOL-C/src/int_forward_t.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: int_forward_t.c + File: int_forward_t.cpp Revision: $Id$ Contents: int_forward (integer forward mode tight for bit pattern propagation) @@ -13,6 +13,6 @@ ----------------------------------------------------------------------------*/ #define _INT_FOR_ 1 #define _TIGHT_ 1 -#include +#include #undef _INT_FOR_ #undef _TIGHT_ diff --git a/ADOL-C/src/nonl_ind_forward_s.c b/ADOL-C/src/nonl_ind_forward_s.cpp similarity index 91% rename from ADOL-C/src/nonl_ind_forward_s.c rename to ADOL-C/src/nonl_ind_forward_s.cpp index e0f860249..7404dbbe2 100644 --- a/ADOL-C/src/nonl_ind_forward_s.c +++ b/ADOL-C/src/nonl_ind_forward_s.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: nonl_ind_forward_s.c + File: nonl_ind_forward_s.cpp Revision: $Id$ Contents: nonl_ind_forward_s (propagation of nonlinear index domains) @@ -14,7 +14,7 @@ #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.cpp similarity index 91% rename from ADOL-C/src/nonl_ind_forward_t.c rename to ADOL-C/src/nonl_ind_forward_t.cpp index ff127739e..62c2dc50a 100644 --- a/ADOL-C/src/nonl_ind_forward_t.c +++ b/ADOL-C/src/nonl_ind_forward_t.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: nonl_ind_forward_t.c + File: nonl_ind_forward_t.cpp Revision: $Id$ Contents: nonl_ind_forward_t (propagation of nonlinear index domains) @@ -14,7 +14,7 @@ #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.cpp similarity index 92% rename from ADOL-C/src/nonl_ind_old_forward_s.c rename to ADOL-C/src/nonl_ind_old_forward_s.cpp index a5f0c65ff..ad995e423 100644 --- a/ADOL-C/src/nonl_ind_old_forward_s.c +++ b/ADOL-C/src/nonl_ind_old_forward_s.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: nonl_ind_forward_s.c + File: nonl_ind_forward_s.cpp Revision: $Id$ Contents: nonl_ind_forward_s (propagation of nonlinear index domains) @@ -15,7 +15,7 @@ #define _NONLIND_OLD_ 1 #define _INDOPRO_ 1 #define _NTIGHT_ 1 -#include +#include #undef _INDO_ #undef _NONLIND_OLD_ #undef _INDOPRO_ diff --git a/ADOL-C/src/nonl_ind_old_forward_t.c b/ADOL-C/src/nonl_ind_old_forward_t.cpp similarity index 92% rename from ADOL-C/src/nonl_ind_old_forward_t.c rename to ADOL-C/src/nonl_ind_old_forward_t.cpp index 972e90669..98627c89b 100644 --- a/ADOL-C/src/nonl_ind_old_forward_t.c +++ b/ADOL-C/src/nonl_ind_old_forward_t.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: nonl_ind_forward_t.c + File: nonl_ind_forward_t.cpp Revision: $Id$ Contents: nonl_ind_forward_t (propagation of nonlinear index domains) @@ -15,7 +15,7 @@ #define _NONLIND_OLD_ 1 #define _INDOPRO_ 1 #define _TIGHT_ 1 -#include +#include #undef _INDO_ #undef _NONLIND_OLD_ #undef _INDOPRO_ diff --git a/ADOL-C/src/uni5_for.c b/ADOL-C/src/uni5_for.cpp similarity index 99% rename from ADOL-C/src/uni5_for.c rename to ADOL-C/src/uni5_for.cpp index a8699061b..24f397b53 100644 --- a/ADOL-C/src/uni5_for.c +++ b/ADOL-C/src/uni5_for.cpp @@ -1,7 +1,7 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: uni5_for.c + File: uni5_for.cpp Revision: $Id$ diff --git a/ADOL-C/src/zos_forward.c b/ADOL-C/src/zos_forward.cpp similarity index 93% rename from ADOL-C/src/zos_forward.c rename to ADOL-C/src/zos_forward.cpp index 8aa34844a..7d925d17b 100644 --- a/ADOL-C/src/zos_forward.c +++ b/ADOL-C/src/zos_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: zos_forward.c + File: zos_forward.cpp Revision: $Id$ Contents: zos_forward (zero-order-scalar forward mode) @@ -14,6 +14,6 @@ ----------------------------------------------------------------------------*/ #define _ZOS_ 1 #define _KEEP_ 1 -#include +#include #undef _KEEP_ #undef _ZOS_ diff --git a/ADOL-C/src/zos_pl_forward.c b/ADOL-C/src/zos_pl_forward.cpp similarity index 92% rename from ADOL-C/src/zos_pl_forward.c rename to ADOL-C/src/zos_pl_forward.cpp index 3bd20f959..8781d28d6 100644 --- a/ADOL-C/src/zos_pl_forward.c +++ b/ADOL-C/src/zos_pl_forward.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: zos_an_forward.c + File: zos_an_forward.cpp Revision: $Id$ Contents: zos_forward (zero-order-scalar abs-normal forward mode) @@ -14,7 +14,7 @@ #define _ZOS_ 1 #define _KEEP_ 1 #define _ABS_NORM_ 1 -#include +#include #undef _ABS_NORM_ #undef _KEEP_ #undef _ZOS_ diff --git a/CMakeLists.txt b/CMakeLists.txt index 9555036f9..cc94eb1c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ target_include_directories(adolc # Set an include directory for the internally used library headers. # -# This includes the files uni5_for.c, fo_rev.cpp, and ho_rev.cpp. Even though +# This includes the files uni5_for.cpp, fo_rev.cpp, and ho_rev.cpp. Even though # they end with .c, they are used like header files. Together with some # preprocessor trickery this is an old-fashioned way to do generic programming. target_include_directories(adolc From 8a7b2840bff3c661601fc2bb4b39d7c864a3ab8f Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 21:04:56 +0100 Subject: [PATCH 21/69] replace NULL with nullptr; change malloc to new or myalloc --- ADOL-C/src/uni5_for.cpp | 350 +++++++++++++++++++++------------------- 1 file changed, 182 insertions(+), 168 deletions(-) diff --git a/ADOL-C/src/uni5_for.cpp b/ADOL-C/src/uni5_for.cpp index 24f397b53..06669be6f 100644 --- a/ADOL-C/src/uni5_for.cpp +++ b/ADOL-C/src/uni5_for.cpp @@ -837,7 +837,7 @@ int hov_forward( #if !defined(_NTIGHT_) double coval = 0; - double *d = NULL; + double *d = nullptr; #endif int indexi = 0, indexd = 0; @@ -849,22 +849,22 @@ int hov_forward( int l = 0; int max_ind_dom; /* index domains */ - locint **ind_dom; + locint **ind_dom = nullptr; #endif #if defined(_NONLIND_) /* nonlinear interaction domains */ - locint *arg_index; - IndexElement *fod; - IndexElement *nonl_dom; - IndexElement_sod *sod; - IndexElement_sod *temp; - IndexElement_sod *temp1; + locint *arg_index = nullptr; + IndexElement *fod = nullptr; + IndexElement *nonl_dom = nullptr; + IndexElement_sod *sod = nullptr; + IndexElement_sod *temp = nullptr; + IndexElement_sod *temp1 = nullptr; int maxopind; int opind; #endif #if defined(_NONLIND_OLD_) /* nonlinear interaction domains */ - locint **nonl_dom; + locint **nonl_dom = nullptr; #endif #endif @@ -879,44 +879,57 @@ int hov_forward( #if defined(_INT_FOR_) #ifdef _TIGHT_ - double *dp_T0; + double *dp_T0 = nullptr; double y; #endif /* _TIGHT_ */ /* Taylor stuff */ - unsigned long int **up_T; + size_t **up_T = nullptr; - unsigned long int *Tres, *Targ, *Targ1, *Targ2; + size_t *Tres = nullptr; + size_t *Targ = nullptr; + size_t *Targ1 = nullptr; + size_t *Targ2 = nullptr; #ifdef _TIGHT_ - unsigned long int *Tqo; - unsigned long int *Targ1OP, *Targ2OP; + size_t *Tqo = nullptr; + size_t *Targ1OP = nullptr; + size_t *Targ2OP = nullptr; #endif #define T0res T0temp #else #if defined(_INDO_) #ifdef _TIGHT_ - double *dp_T0; + double *dp_T0 = nullptr; #endif /* _TIGHT_ */ #define T0res T0temp #define T0arg T0temp #else - double *dp_T0; + double *dp_T0 = nullptr; #if !defined(_ZOS_) #if defined(_FOS_) double *dp_T; #define T_TEMP Ttemp; #else - double *dp_Ttemp, **dpp_T; + double *dp_Ttemp = nullptr; + double **dpp_T = nullptr; #endif - double *Tres, *Targ, *Targ1, *Targ2, *Tqo; + double *Tres = nullptr; + double *Targ = nullptr; + double *Targ1 = nullptr; + double *Targ2 = nullptr; + double *Tqo = nullptr; #if defined(_HIGHER_ORDER_) - double *TresOP, *TresOP2, *zOP; - double *dp_z; -#endif - double *TargOP, *Targ1OP, *Targ2OP; + double *TresOP = nullptr; + double *TresOP2 = nullptr; + double *zOP = nullptr; + double *dp_z = nullptr; +#endif + double *TargOP = nullptr; + double *Targ1OP = nullptr; + double *Targ2OP = nullptr; double T0temp; #endif #define T0res T0temp @@ -995,14 +1008,15 @@ int hov_forward( #if defined(_EXTERN_) locint n, m; - ext_diff_fct *edfct; + ext_diff_fct *edfct = nullptr; ext_diff_fct_v2 *edfct2; int loop, oloop; int iArrLength; - int *iArr; + int *iArr = nullptr; int ext_retc; int nin, nout; - locint *insz, *outsz; + locint *insz = nullptr; + locint *outsz = nullptr; #endif #if defined(_ABS_NORM_) @@ -1011,7 +1025,8 @@ int hov_forward( #ifdef ADOLC_AMPI_SUPPORT MPI_Op op; - void *buf, *rbuf; + void *buf = nullptr; + void *rbuf = nullptr; int count, rcount; MPI_Datatype datatype, rtype; int src; @@ -1095,7 +1110,7 @@ int hov_forward( ADOLC_CURRENT_TAPE_INFOS.dp_T0 = dp_T0; if ((ADOLC_CURRENT_TAPE_INFOS.stats[NO_MIN_MAX]) && - (ADOLC_CURRENT_TAPE_INFOS.signature == NULL)) + (ADOLC_CURRENT_TAPE_INFOS.signature == nullptr)) ADOLC_CURRENT_TAPE_INFOS.signature = myalloc1(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_SWITCHES]); @@ -1145,7 +1160,7 @@ int hov_forward( #endif /*--------------------------------------------------------------------------*/ -#else /* INF_FOR */ +#else /* INT_FOR */ #if defined(_INT_FOR_) up_T = myalloc2_ulong(ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES], p); #define TAYLOR_BUFFER up_T @@ -1155,12 +1170,11 @@ int hov_forward( #if defined(_INDO_) #if defined(_INDOPRO_) /* index domains */ - ind_dom = (locint **)malloc(sizeof(locint *) * - ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]); + ind_dom = new 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] = new locint[NUMNNZ + 2]; ind_dom[i][0] = 0; ind_dom[i][1] = NUMNNZ; } @@ -1171,28 +1185,25 @@ int hov_forward( #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])); + fod = new IndexElement[maxopind]; + nonl_dom = new IndexElement[indcheck]; + arg_index = new locint[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_MAX_LIVES]]; opind = 0; - sod = (struct IndexElement_sod *)malloc(sizeof(struct IndexElement_sod) * - indcheck); + sod = new IndexElement_sod[indcheck]; for (int i = 0; i < indcheck; i++) { sod[i].entry = 0; - sod[i].left = NULL; + sod[i].left = nullptr; nonl_dom[i].entry = indcheck + 2; - nonl_dom[i].left = NULL; - nonl_dom[i].right = NULL; + nonl_dom[i].left = nullptr; + nonl_dom[i].right = nullptr; } #endif #if defined(_NONLIND_OLD_) - nonl_dom = (locint **)malloc(sizeof(locint *) * indcheck); + nonl_dom = new locint*[indcheck]; for (int i = 0; i < indcheck; i++) { - nonl_dom[i] = (locint *)malloc(sizeof(locint) * (NUMNNZ + 2)); + nonl_dom[i] = new locint[NUMNNZ + 2]; nonl_dom[i][0] = 0; nonl_dom[i][1] = NUMNNZ; } @@ -1471,8 +1482,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[res] = opind++; #endif #else @@ -1511,8 +1522,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[res] = opind++; #endif #else @@ -1541,8 +1552,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[res] = opind++; #endif #else @@ -1571,8 +1582,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[res] = opind++; #endif #else @@ -1603,8 +1614,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = indexi; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[res] = opind++; #endif #else @@ -1628,7 +1639,7 @@ int hov_forward( #if !defined(_INDO_) #if !defined(_NTIGHT_) - if (valuepoint != NULL) + if (valuepoint != nullptr) valuepoint[indexd] = dp_T0[res]; #endif /* !_NTIGHT_ */ #endif @@ -1636,14 +1647,13 @@ int hov_forward( #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] = new 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] = new unsigned int[1]; crs[indexd][0] = 0; } #endif @@ -2482,7 +2492,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -2553,7 +2563,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -2679,7 +2689,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -2743,7 +2753,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -2817,7 +2827,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -2889,7 +2899,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -2952,7 +2962,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3054,7 +3064,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3156,7 +3166,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3219,7 +3229,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3306,7 +3316,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3414,7 +3424,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3473,7 +3483,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3526,7 +3536,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3615,7 +3625,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3760,7 +3770,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3890,7 +3900,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -3974,7 +3984,7 @@ int hov_forward( #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; traverse_unary(&fod[opind], nonl_dom, &fod[opind], indcheck + 1, maxopind + 2); arg_index[res] = opind++; @@ -4141,13 +4151,13 @@ int hov_forward( if (dp_T0[arg1] < dp_T0[arg2]) { fod[opind].entry = maxopind + 2; fod[opind].left = &fod[arg_index[arg1]]; - fod[opind].right = NULL; + fod[opind].right = nullptr; 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; + fod[opind].right = nullptr; arg_index[res] = opind++; } else { @@ -4173,7 +4183,7 @@ int hov_forward( #ifdef _INT_FOR_ #ifdef _TIGHT_ - Tqo = NULL; + Tqo = nullptr; if (dp_T0[arg1] > dp_T0[arg2]) Tqo = Targ2; else if (dp_T0[arg1] < dp_T0[arg2]) @@ -4181,7 +4191,7 @@ int hov_forward( FOR_0_LE_l_LT_p { Targ = Tqo; - if (Targ == NULL) /* e.g. T0[arg1] == T0[arg2] */ + if (Targ == nullptr) /* e.g. T0[arg1] == T0[arg2] */ { Targ1OP = Targ1; Targ2OP = Targ2; @@ -4191,7 +4201,7 @@ int hov_forward( Targ = Targ1OP; Targ1++; Targ2++; - if (Targ == NULL) /* e.g. both are equal */ + if (Targ == nullptr) /* e.g. both are equal */ Targ = Targ1OP; } @@ -4207,7 +4217,7 @@ int hov_forward( TRES_INC = TARG1_INC | TARG2_INC; #endif /* _NTIGHT_ */ #else - Tqo = NULL; + Tqo = nullptr; if (dp_T0[arg1] > dp_T0[arg2]) Tqo = Targ2; else if (dp_T0[arg1] < dp_T0[arg2]) @@ -4216,7 +4226,7 @@ int hov_forward( FOR_0_LE_l_LT_p { Targ = Tqo; /* e.g. dp_T0[arg1] == dp_T0[arg2] */ - if (Targ == NULL) { + if (Targ == nullptr) { Targ1OP = Targ1; Targ2OP = Targ2; FOR_0_LE_i_LT_k { @@ -4235,7 +4245,7 @@ int hov_forward( Targ2++; } } - if (Targ == NULL) /* e.g. both are equal */ + if (Targ == nullptr) /* e.g. both are equal */ Targ = Targ1OP; } @@ -4287,14 +4297,13 @@ int hov_forward( #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] = new unsigned int[ind_dom[arg][0] + 1]; crs[switchnum][0] = ind_dom[arg][0]; for (l = 1; l < crs[switchnum][0]; l++) { crs[switchnum][l] = ind_dom[arg][l + 1]; } } else { - crs[switchnum] = (unsigned int *)malloc(sizeof(unsigned int)); + crs[switchnum] = new unsigned int[1]; crs[switchnum][0] = 0; } ind_dom[res][0] = 1; @@ -4342,7 +4351,7 @@ int hov_forward( FOR_0_LE_l_LT_p TRES_INC = fabs(dp_T0[arg] + TARG_INC) - fabs(dp_T0[arg]); #elif defined(_ABS_NORM_SIG_) double y; - if (sigdir == NULL) + if (sigdir == nullptr) y = EXT_FIRSTSIGN2_P(sigbase[switchnum], dp_T0[arg], Targ); else y = EXT_FIRSTSIGN_P(sigbase[switchnum], sigdir[switchnum], dp_T0[arg], @@ -4904,8 +4913,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[res] = opind++; #endif #else @@ -5071,8 +5080,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[arg1] = opind++; #endif #else @@ -5106,8 +5115,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[arg1] = opind++; #endif #else @@ -5137,8 +5146,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[arg1] = opind++; #endif #else @@ -5168,8 +5177,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[arg1] = opind++; #endif #else @@ -5232,8 +5241,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = indexi; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[res] = opind++; #endif #else @@ -5571,8 +5580,8 @@ int hov_forward( #endif #if defined(_NONLIND_) fod[opind].entry = maxopind + 2; - fod[opind].left = NULL; - fod[opind].right = NULL; + fod[opind].left = nullptr; + fod[opind].right = nullptr; arg_index[res] = opind++; #endif #else @@ -6088,21 +6097,21 @@ int hov_forward( 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) + if (edfct->ADOLC_EXT_FCT_POINTER == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); if (n > 0) { - if (edfct->dp_x == NULL) + if (edfct->dp_x == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #if !defined(_ZOS_) - if (ADOLC_EXT_POINTER_X == NULL) + if (ADOLC_EXT_POINTER_X == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #endif } if (m > 0) { - if (edfct->dp_y == NULL) + if (edfct->dp_y == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #if !defined(_ZOS_) - if (ADOLC_EXT_POINTER_Y == NULL) + if (ADOLC_EXT_POINTER_Y == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #endif } @@ -6156,7 +6165,7 @@ int hov_forward( case ext_diff_iArr: /* extern differentiated function */ iArrLength = get_locint_f(); - iArr = malloc(iArrLength * sizeof(int)); + iArr = new int[iArrLength]; for (loop = 0; loop < iArrLength; ++loop) iArr[loop] = get_locint_f(); get_locint_f(); /* iArrLength again */ @@ -6168,21 +6177,21 @@ int hov_forward( 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) + if (edfct->ADOLC_EXT_FCT_IARR_POINTER == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); if (n > 0) { - if (edfct->dp_x == NULL) + if (edfct->dp_x == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #if !defined(_ZOS_) - if (ADOLC_EXT_POINTER_X == NULL) + if (ADOLC_EXT_POINTER_X == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #endif } if (m > 0) { - if (edfct->dp_y == NULL) + if (edfct->dp_y == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #if !defined(_ZOS_) - if (ADOLC_EXT_POINTER_Y == NULL) + if (ADOLC_EXT_POINTER_Y == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #endif } @@ -6237,13 +6246,13 @@ int hov_forward( case ext_diff_v2: ADOLC_CURRENT_TAPE_INFOS.ext_diff_fct_index = get_locint_f(); iArrLength = get_locint_f(); - iArr = malloc(iArrLength * sizeof(int)); + iArr = new int[iArrLength]; 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)); + insz = new locint[2 * (nin + nout)]; outsz = insz + nin; ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = outsz + nout; ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = outsz + nout + nin; @@ -6258,21 +6267,21 @@ int hov_forward( 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) + if (edfct2->ADOLC_EXT_FCT_POINTER == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_DIFFFUNC); if (nin > 0) { - if (edfct2->x == NULL) + if (edfct2->x == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #if !defined(_ZOS_) - if (ADOLC_EXT_V2_POINTER_X == NULL) + if (ADOLC_EXT_V2_POINTER_X == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #endif } if (nout > 0) { - if (edfct2->y == NULL) + if (edfct2->y == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #if !defined(_ZOS_) - if (ADOLC_EXT_V2_POINTER_Y == NULL) + if (ADOLC_EXT_V2_POINTER_Y == nullptr) fail(ADOLC_EXT_DIFF_NULLPOINTER_ARGUMENT); #endif } @@ -6335,10 +6344,10 @@ int hov_forward( #endif } - free(insz); - free(iArr); - insz = 0; - iArr = 0; + delete insz; + delete iArr; + insz = nullptr; + iArr = nullptr; outsz = 0; ADOLC_CURRENT_TAPE_INFOS.lowestXLoc_ext_v2 = 0; ADOLC_CURRENT_TAPE_INFOS.lowestYLoc_ext_v2 = 0; @@ -6404,17 +6413,17 @@ int hov_forward( break; } case ampi_gatherv: { - ADOLC_TLM_AMPI_Gatherv(buf, count, datatype, rbuf, NULL, NULL, rtype, src, + ADOLC_TLM_AMPI_Gatherv(buf, count, datatype, rbuf, nullptr, nullptr, rtype, src, comm); break; } case ampi_scatterv: { - ADOLC_TLM_AMPI_Scatterv(rbuf, NULL, NULL, rtype, buf, count, datatype, + ADOLC_TLM_AMPI_Scatterv(rbuf, nullptr, nullptr, rtype, buf, count, datatype, src, comm); break; } case ampi_allgatherv: { - ADOLC_TLM_AMPI_Allgatherv(buf, count, datatype, rbuf, NULL, NULL, rtype, + ADOLC_TLM_AMPI_Allgatherv(buf, count, datatype, rbuf, nullptr, nullptr, rtype, comm); break; } @@ -6471,22 +6480,28 @@ int hov_forward( /* clean up */ #if !defined(_NTIGHT_) - free(dp_T0); + myfree1(dp_T0); + ADOLC_CURRENT_TAPE_INFOS.dpp_T = nullptr; + ADOLC_CURRENT_TAPE_INFOS.dp_T0 = nullptr; #endif /* !_NTIGHT_ */ #if !defined(_INDO_) #if !defined(_ZOS_) #if defined(_FOS_) - free(dp_T); + myfree1(dp_T); + ADOLC_CURRENT_TAPE_INFOS.dpp_T = nullptr; #else #if !defined(_INT_FOR_) myfree2(dpp_T); - free(dp_Ttemp); + ADOLC_CURRENT_TAPE_INFOS.dpp_T = nullptr; + myfree1(dp_Ttemp); +#elif + myfree2_ulong(up_T); #endif /* !_NTIGHT_ */ #endif #endif #endif #if defined(_HIGHER_ORDER_) - free(dp_z); + myfree1(dp_z); #endif ADOLC_CURRENT_TAPE_INFOS.workMode = ADOLC_NO_MODE; @@ -6495,15 +6510,15 @@ int hov_forward( #if defined(_INDO_) #if defined(_INDOPRO_) for (int i = 0; i < max_ind_dom; i++) { - free(ind_dom[i]); + delete ind_dom[i]; } - free(ind_dom); + delete[] 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] = new 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++) { @@ -6514,23 +6529,25 @@ int hov_forward( } } - free(sod); - free(nonl_dom); - free(fod); - free(arg_index); + delete sod; + delete nonl_dom; + delete fod; + delete arg_index; #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] = new 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++) { + delete nonl_dom[i]; + } + delete[] nonl_dom; #endif #endif @@ -6607,8 +6624,8 @@ 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)); + delete ind_dom[res]; + ind_dom[res] = new locint[2 * (ind_dom[arg][0] + 1)]; ind_dom[res][1] = 2 * ind_dom[arg][0]; } @@ -6636,7 +6653,7 @@ void merge_2_index_domains(int res, int arg, locint **ind_dom) { if (num2 < num1 + num) num2 = num1 + num; - temp_array = (locint *)malloc(sizeof(locint) * (num2 + 2)); + temp_array = new locint[num2 + 2]; temp_array[1] = num2; i = 2; @@ -6671,7 +6688,7 @@ void merge_2_index_domains(int res, int arg, locint **ind_dom) { k++; } temp_array[0] = k - 2; - free(ind_dom[res]); + delete ind_dom[res]; ind_dom[res] = temp_array; } } @@ -6698,10 +6715,10 @@ void merge_3_index_domains(int res, int arg1, int arg2, locint **ind_dom) { void free_tree(IndexElement *tree, int num) { - if (tree->left != NULL) { + if (tree->left != nullptr) { free_tree(tree->left, num); } - if (tree->right != NULL) { + if (tree->right != nullptr) { free_tree(tree->right, num); } { @@ -6713,46 +6730,43 @@ void traverse_crs(IndexElement *tree, IndexElement_sod *sod, int num) { IndexElement_sod *temp, *temp1; - if (tree->left != NULL) { + if (tree->left != nullptr) { traverse_crs(tree->left, sod, num); } - if (tree->right != NULL) { + if (tree->right != nullptr) { 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; + if (temp == nullptr) { + temp = new IndexElement_sod; + temp->left = nullptr; temp->entry = tree->entry; sod->entry++; sod->left = temp; } else { - while ((temp->entry < tree->entry) && (temp->left != NULL)) { + while ((temp->entry < tree->entry) && (temp->left != nullptr)) { temp1 = temp; temp = temp->left; } - if (temp->left == NULL) { + if (temp->left == nullptr) { if (temp->entry < tree->entry) { - temp->left = (struct IndexElement_sod *)malloc( - sizeof(struct IndexElement_sod)); + temp->left = new IndexElement_sod; temp = temp->left; - temp->left = NULL; + temp->left = nullptr; temp->entry = tree->entry; sod->entry++; } if (temp->entry > tree->entry) { - temp->left = (struct IndexElement_sod *)malloc( - sizeof(struct IndexElement_sod)); + temp->left = new IndexElement_sod; temp->left->entry = temp->entry; - temp->left->left = NULL; + temp->left->left = nullptr; temp->entry = tree->entry; sod->entry++; } } else { if (temp->entry > tree->entry) { - temp1 = (struct IndexElement_sod *)malloc( - sizeof(struct IndexElement_sod)); + temp1 = new IndexElement_sod; temp1->left = temp->left; temp1->entry = temp->entry; temp->entry = tree->entry; @@ -6768,14 +6782,14 @@ void traverse_unary(IndexElement *tree, IndexElement *nonl_dom, IndexElement *fodi, int num, int maxopind) { IndexElement *temp; - if (tree->left != NULL) { + if (tree->left != nullptr) { traverse_unary(tree->left, nonl_dom, fodi, num, maxopind); - if (tree->right != NULL) { + if (tree->right != nullptr) { traverse_unary(tree->right, nonl_dom, fodi, num, maxopind); } } else { if (tree->entry < maxopind) { - temp = (struct IndexElement *)malloc(sizeof(struct IndexElement)); + temp = new IndexElement; temp->right = fodi; temp->left = nonl_dom[tree->entry].left; temp->entry = num; @@ -6805,8 +6819,8 @@ void extend_nonlinearity_domain_binary_step(int arg1, int arg2, if (index_nonl_dom[0] == 0) /* empty list */ { if (index_nonl_dom[1] < num) { - free(index_nonl_dom); - index_nonl_dom = (locint *)malloc(sizeof(locint) * 2 * (num + 1)); + delete index_nonl_dom; + index_nonl_dom = new locint[2 * (num + 1)]; index_nonl_dom[1] = 2 * num; } for (i = 2; i < num + 2; i++) /* append index domain list of "arg" */ @@ -6819,7 +6833,7 @@ void extend_nonlinearity_domain_binary_step(int arg1, int arg2, if (num1 + num > num2) num2 = num1 + num; - temp_nonl = (locint *)malloc(sizeof(locint) * (num2 + 2)); + temp_nonl = new locint[num2 + 2]; temp_nonl[1] = num2; i = 2; @@ -6854,7 +6868,7 @@ void extend_nonlinearity_domain_binary_step(int arg1, int arg2, k++; } temp_nonl[0] = k - 2; - free((char *)nonl_dom[index]); + delete nonl_dom[index]; nonl_dom[index] = temp_nonl; } } From 53e0be5b50a5a93418b11759ab1f04e2fe82f9d7 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 20 Dec 2024 21:15:52 +0100 Subject: [PATCH 22/69] fix macro names that contain NULL; correct c linkage of forward declarations --- ADOL-C/src/uni5_for.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/ADOL-C/src/uni5_for.cpp b/ADOL-C/src/uni5_for.cpp index 06669be6f..bfb6fe98a 100644 --- a/ADOL-C/src/uni5_for.cpp +++ b/ADOL-C/src/uni5_for.cpp @@ -145,11 +145,12 @@ and _NTIGHT__ #define TAYLORS(indexd, l, i) taylors[indexd][l] /*--------------------------------------------------------------------------*/ #elif defined(_INDO_) +BEGIN_C_DECLS void copy_index_domain(int res, int arg, locint **ind_dom); 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); - +END_C_DECLS #define NUMNNZ 20 #define FMIN_ADOLC(x, y) ((y < x) ? y : x) @@ -178,11 +179,12 @@ typedef struct IndexElement_sod { struct IndexElement_sod *left; } IndexElement_sod; +BEGIN_C_DECLS void free_tree(IndexElement *nlf, int num); void traverse_crs(IndexElement *fod2, IndexElement_sod *sod, int num); void traverse_unary(IndexElement *fod, IndexElement *nonl_dom, IndexElement *fodi, int num, int maxopind); - +END_C_DECLS #if defined(_TIGHT_) #define GENERATED_FILENAME "nonl_ind_forward_t" #elif defined(_NTIGHT_) @@ -196,6 +198,7 @@ void traverse_unary(IndexElement *fod, IndexElement *nonl_dom, * (first element of the NID list) or the index of an independent variable. */ +BEGIN_C_DECLS void extend_nonlinearity_domain_binary_step(int arg1, int arg2, locint **ind_dom, locint **nonl_dom); @@ -203,7 +206,7 @@ void extend_nonlinearity_domain_unary(int arg, locint **ind_dom, locint **nonl_dom); void extend_nonlinearity_domain_binary(int arg1, int arg2, locint **ind_dom, locint **nonl_dom); - +END_C_DECLS #if defined(_TIGHT_) #define GENERATED_FILENAME "nonl_ind_old_forward_t" #endif @@ -4360,16 +4363,8 @@ int hov_forward( sigsw[switchnum] = y; FOR_0_LE_l_LT_p TRES_INC = y * TARG_INC; #else - double y = 0.0; - if (dp_T0[arg] != 0.0) { - if (dp_T0[arg] < 0.0) - y = -1.0; - else - y = 1.0; - } - FOR_0_LE_l_LT_p { - double x = y; + double x = dp_T0[arg] == 0.0 ? 0.0 : dp_T0[arg] < 0.0 ? -1.0 : 1.0; FOR_0_LE_i_LT_k { if ((x == 0.0) && (TARG != 0.0)) { MINDEC(ret_c, 1); @@ -6494,7 +6489,7 @@ int hov_forward( myfree2(dpp_T); ADOLC_CURRENT_TAPE_INFOS.dpp_T = nullptr; myfree1(dp_Ttemp); -#elif +#else myfree2_ulong(up_T); #endif /* !_NTIGHT_ */ #endif From de36c9010d4544b4d0054ea732ea3e68a549cd39 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 21 Dec 2024 21:12:41 +0100 Subject: [PATCH 23/69] format --- ADOL-C/src/uni5_for.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ADOL-C/src/uni5_for.cpp b/ADOL-C/src/uni5_for.cpp index bfb6fe98a..e41454cbf 100644 --- a/ADOL-C/src/uni5_for.cpp +++ b/ADOL-C/src/uni5_for.cpp @@ -1204,7 +1204,7 @@ int hov_forward( #endif #if defined(_NONLIND_OLD_) - nonl_dom = new locint*[indcheck]; + nonl_dom = new locint *[indcheck]; for (int i = 0; i < indcheck; i++) { nonl_dom[i] = new locint[NUMNNZ + 2]; nonl_dom[i][0] = 0; @@ -6408,18 +6408,18 @@ int hov_forward( break; } case ampi_gatherv: { - ADOLC_TLM_AMPI_Gatherv(buf, count, datatype, rbuf, nullptr, nullptr, rtype, src, - comm); + ADOLC_TLM_AMPI_Gatherv(buf, count, datatype, rbuf, nullptr, nullptr, + rtype, src, comm); break; } case ampi_scatterv: { - ADOLC_TLM_AMPI_Scatterv(rbuf, nullptr, nullptr, rtype, buf, count, datatype, - src, comm); + ADOLC_TLM_AMPI_Scatterv(rbuf, nullptr, nullptr, rtype, buf, count, + datatype, src, comm); break; } case ampi_allgatherv: { - ADOLC_TLM_AMPI_Allgatherv(buf, count, datatype, rbuf, nullptr, nullptr, rtype, - comm); + ADOLC_TLM_AMPI_Allgatherv(buf, count, datatype, rbuf, nullptr, nullptr, + rtype, comm); break; } case ampi_bcast: { @@ -6541,7 +6541,7 @@ int hov_forward( } for (int i = 0; i < indcheck; i++) { delete nonl_dom[i]; - } + } delete[] nonl_dom; #endif From 4a01b020050cafc15f4cc62a95974942813174c9 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 21 Dec 2024 21:13:13 +0100 Subject: [PATCH 24/69] try fix coverage error --- .github/workflows/coverage.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 2d0f63944..70435e5bd 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -10,6 +10,11 @@ jobs: - uses: actions/checkout@v4 + - name: Prepare for Coverage + run: | + find . -name '*.gcda' -o -name '*.gcno' -delete + make clean + - name: Install lcov run: | sudo apt-get update From d536e5f2e77335bca161f35cb890594d9ce98449 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 21 Dec 2024 21:17:06 +0100 Subject: [PATCH 25/69] ignore error --- .github/workflows/coverage.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 70435e5bd..28d2005d6 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -10,11 +10,6 @@ jobs: - uses: actions/checkout@v4 - - name: Prepare for Coverage - run: | - find . -name '*.gcda' -o -name '*.gcno' -delete - make clean - - name: Install lcov run: | sudo apt-get update @@ -48,9 +43,9 @@ jobs: - name: Generate coverage report run: | cd build - lcov --capture --directory . --output-file coverage.info + lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch lcov --remove coverage.info '/usr/*' 'boost/*' 'c++11/*' --output-file coverage.info - lcov --list coverage.info + lcov --list coverage.info # Upload coverage report to Codecov - name: Upload coverage to Codecov From 8459d9dd3987e12598d2ad8bed03752157048577 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 21 Dec 2024 21:22:42 +0100 Subject: [PATCH 26/69] rm boost-test --- .github/workflows/coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 28d2005d6..657f0fd6a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -5,7 +5,7 @@ name: Test Coverage jobs: run-coverage: name: Build - runs-on: ubuntu-latest + runs-on: ubuntu- steps: - uses: actions/checkout@v4 @@ -44,7 +44,7 @@ jobs: run: | cd build lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch - lcov --remove coverage.info '/usr/*' 'boost/*' 'c++11/*' --output-file coverage.info + lcov --remove coverage.info '/usr/*' 'boost/*' 'c++11/*' 'boost-test' --output-file coverage.info lcov --list coverage.info # Upload coverage report to Codecov From 3f075a71ae7e673b6886af188656687fe471eb62 Mon Sep 17 00:00:00 2001 From: TimSiebert1 <128799979+TimSiebert1@users.noreply.github.com> Date: Sun, 22 Dec 2024 08:17:11 +0100 Subject: [PATCH 27/69] Add Ubuntu latest, was accidentally deleted --- .github/workflows/coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 657f0fd6a..4231fd4c4 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -5,7 +5,7 @@ name: Test Coverage jobs: run-coverage: name: Build - runs-on: ubuntu- + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -55,4 +55,4 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} flags: unittests name: code-coverage-report - \ No newline at end of file + From 969e65cd15825d1aa3fbad309dab2ec18ad1b2d6 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 13:09:29 +0100 Subject: [PATCH 28/69] change unsinged long and unsigned lont to size_t --- .../additional_examples/sparse/jacpatexam.cpp | 3 +- ADOL-C/include/adolc/adalloc.h | 8 +- ADOL-C/include/adolc/interfaces.h | 18 ++-- ADOL-C/include/adolc/sparse/sparse_fo_rev.h | 17 ++-- ADOL-C/include/adolc/sparse/sparsedrivers.h | 2 +- ADOL-C/src/adalloc.c | 23 +++-- ADOL-C/src/fo_rev.cpp | 88 +++++++++---------- ADOL-C/src/sparse/sparse_fo_rev.cpp | 10 +-- ADOL-C/src/sparse/sparsedrivers.cpp | 20 ++--- ADOL-C/src/taping.c | 2 +- ADOL-C/src/taping_p.h | 2 +- ADOL-C/src/uni5_for.cpp | 12 +-- 12 files changed, 96 insertions(+), 109 deletions(-) diff --git a/ADOL-C/examples/additional_examples/sparse/jacpatexam.cpp b/ADOL-C/examples/additional_examples/sparse/jacpatexam.cpp index 94685dba6..94a600001 100644 --- a/ADOL-C/examples/additional_examples/sparse/jacpatexam.cpp +++ b/ADOL-C/examples/additional_examples/sparse/jacpatexam.cpp @@ -71,8 +71,7 @@ void eval_small(short tag, double *xp, double *yp) { } /*--------------------------------------------------------------------------*/ -const unsigned int NM = - 961; // PQ_STRIPMINE_MAX * 8*sizeof(unsigned long int) + 1 +const unsigned int NM = 961; // PQ_STRIPMINE_MAX * 8*sizeof(size_t) + 1 void eval_arrow_like_matrix(short tag, double *xp, double *yp) { unsigned int i, j; diff --git a/ADOL-C/include/adolc/adalloc.h b/ADOL-C/include/adolc/adalloc.h index 2ff4e3cc2..943db6a5f 100644 --- a/ADOL-C/include/adolc/adalloc.h +++ b/ADOL-C/include/adolc/adalloc.h @@ -44,16 +44,16 @@ ADOLC_DLL_EXPORT void myfreeI2(int, double **); 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); +ADOLC_DLL_EXPORT size_t *myalloc1_ulong(int); +ADOLC_DLL_EXPORT size_t **myalloc2_ulong(int, int); /****************************************************************************/ /* INTEGER VARIANT FOR BIT PATTERN PROPAGATION */ 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 **); +ADOLC_DLL_EXPORT void myfree1_ulong(size_t *); +ADOLC_DLL_EXPORT void myfree2_ulong(size_t **); END_C_DECLS diff --git a/ADOL-C/include/adolc/interfaces.h b/ADOL-C/include/adolc/interfaces.h index 958e157dd..6fc2c8f28 100644 --- a/ADOL-C/include/adolc/interfaces.h +++ b/ADOL-C/include/adolc/interfaces.h @@ -289,17 +289,15 @@ ADOLC_DLL_EXPORT fint hov_wk_forward_(fint *, fint *, fint *, fint *, fint *, /* 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, size_t **, + size_t **); /*--------------------------------------------------------------------------*/ /* 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 **); + size_t **, double *, size_t **); /****************************************************************************/ /* INDEX DOMAIN UTILITIES */ @@ -429,17 +427,15 @@ ADOLC_DLL_EXPORT fint hov_ti_reverse_(fint *, fint *, fint *, fint *, fint *, /* 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, size_t **, + size_t **); /*--------------------------------------------------------------------------*/ /* 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, size_t **, + size_t **); /*--------------------------------------------------------------------------*/ ADOLC_DLL_EXPORT int get_num_switches(short); diff --git a/ADOL-C/include/adolc/sparse/sparse_fo_rev.h b/ADOL-C/include/adolc/sparse/sparse_fo_rev.h index ef0b806bc..42941b1d2 100644 --- a/ADOL-C/include/adolc/sparse/sparse_fo_rev.h +++ b/ADOL-C/include/adolc/sparse/sparse_fo_rev.h @@ -24,7 +24,7 @@ package. /* */ /* nBV = number of Boolean Vectors to be packed */ /* (see Chapter Dependence Analysis, ADOL-C Documentation) */ -/* bits_per_long = 8*sizeof(unsigned long int) */ +/* bits_per_long = 8*sizeof(size_t) */ /* p = nBV / bits_per_long + ( (nBV % bits_per_long) != 0 ) */ /* */ /* For the full Jacobian matrix set */ @@ -36,24 +36,23 @@ package. /* */ /* 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 *, size_t **, + double *, size_t **, 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, size_t **, size_t **, + char = 0); /****************************************************************************/ /* REVERSE MODE, overloaded calls */ /* */ /* nBV = number of Boolean Vectors to be packed */ /* (see Chapter Dependence Analysis, ADOL-C Documentation) */ -/* bits_per_long = 8*sizeof(unsigned long int) */ +/* bits_per_long = 8*sizeof(size_t) */ /* q = nBV / bits_per_long + ( (nBV % bits_per_long) != 0 ) */ /* */ /* For the full Jacobian matrix set */ @@ -66,8 +65,8 @@ ADOLC_DLL_EXPORT int forward(short, int, int, int, unsigned long int **, /* */ /* 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, size_t **, size_t **, + char = 0); #endif diff --git a/ADOL-C/include/adolc/sparse/sparsedrivers.h b/ADOL-C/include/adolc/sparse/sparsedrivers.h index 1ab7d3487..6c7d9a207 100644 --- a/ADOL-C/include/adolc/sparse/sparsedrivers.h +++ b/ADOL-C/include/adolc/sparse/sparsedrivers.h @@ -93,7 +93,7 @@ ADOLC_DLL_EXPORT void get_HP(short tag, /* tape identification */ /* 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. 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(size_t) * 8 ) (block) variables at once */ #define PQ_STRIPMINE_MAX 30 diff --git a/ADOL-C/src/adalloc.c b/ADOL-C/src/adalloc.c index 7cc4da279..d79a4c15c 100644 --- a/ADOL-C/src/adalloc.c +++ b/ADOL-C/src/adalloc.c @@ -225,38 +225,35 @@ unsigned int *myalloc1_uint(int m) { } /* ------------------------------------------------------------------------- */ -unsigned long int *myalloc1_ulong(int m) { - unsigned long int *A = - (unsigned long int *)ADOLC_CALLOC(m, sizeof(unsigned long int)); +size_t *myalloc1_ulong(int m) { + size_t *A = (size_t *)ADOLC_CALLOC(m, sizeof(size_t)); if (A == NULL) { fprintf(DIAG_OUT, "ADOL-C error, " __FILE__ ":%i : \nmyalloc1_ulong cannot allocate %i bytes\n", - __LINE__, (int)(m * sizeof(unsigned long int))); + __LINE__, (int)(m * sizeof(size_t))); adolc_exit(-1, "", __func__, __FILE__, __LINE__); } /* endif */ return A; } /* ------------------------------------------------------------------------- */ -unsigned long int **myalloc2_ulong(int m, int n) { - unsigned long int *Adum = - (unsigned long int *)ADOLC_CALLOC(m * n, sizeof(unsigned long int)); - unsigned long int **A = - (unsigned long int **)ADOLC_CALLOC(m, sizeof(unsigned long int *)); +size_t **myalloc2_ulong(int m, int n) { + size_t *Adum = (size_t *)ADOLC_CALLOC(m * n, sizeof(size_t)); + size_t **A = (size_t **)ADOLC_CALLOC(m, sizeof(size_t *)); int i; if (Adum == NULL) { fprintf(DIAG_OUT, "ADOL-C error, " __FILE__ ":%i : \nmyalloc2_ulong cannot allocate %i bytes\n", - __LINE__, (int)(m * n * sizeof(unsigned long int))); + __LINE__, (int)(m * n * sizeof(size_t))); adolc_exit(-1, "", __func__, __FILE__, __LINE__); } /* endif */ if (A == NULL) { fprintf(DIAG_OUT, "ADOL-C error, " __FILE__ ":%i : \nmyalloc2_ulong cannot allocate %i bytes\n", - __LINE__, (int)(m * sizeof(unsigned long int *))); + __LINE__, (int)(m * sizeof(size_t *))); adolc_exit(-1, "", __func__, __FILE__, __LINE__); } /* endif */ for (i = 0; i < m; i++) { @@ -275,11 +272,11 @@ void myfree1_uint(unsigned int *A) { free((char *)A); } /* ------------------------------------------------------------------------ */ -void myfree1_ulong(unsigned long int *A) { free((char *)A); } +void myfree1_ulong(size_t *A) { free((char *)A); } /* ------------------------------------------------------------------------ */ -void myfree2_ulong(unsigned long int **A) { +void myfree2_ulong(size_t **A) { free((char *)*A); free((char *)A); } diff --git a/ADOL-C/src/fo_rev.cpp b/ADOL-C/src/fo_rev.cpp index edbe7aa5f..2596d8158 100644 --- a/ADOL-C/src/fo_rev.cpp +++ b/ADOL-C/src/fo_rev.cpp @@ -256,25 +256,23 @@ int fov_reverse(short tnum, /* tape id */ /****************************************************************************/ /* 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]*/ +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 */ + size_t **lagrange, /* domain weight vector[var][row](in)*/ + size_t **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]*/ +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 */ + size_t **lagrange, /* domain weight vector[var][row](in)*/ + size_t **results) /* matrix of coeff. vectors[var][row]*/ #else #error Neither _TIGHT_ nor _NTIGHT_ defined #endif @@ -917,7 +915,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG1_INC |= aTmp; AARG2_INC |= aTmp; @@ -948,7 +946,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -979,7 +977,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1007,7 +1005,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG1_INC |= aTmp; AARG2_INC |= aTmp; @@ -1038,7 +1036,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1069,7 +1067,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG2_INC |= aTmp; AARG1_INC |= aTmp; @@ -1152,7 +1150,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1182,7 +1180,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1218,7 +1216,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG1_INC |= aTmp; AARG2_INC |= aTmp; @@ -1254,7 +1252,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1293,7 +1291,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1323,7 +1321,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1348,7 +1346,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1377,7 +1375,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1403,7 +1401,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG1_INC |= aTmp; #else @@ -1431,7 +1429,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG1_INC |= aTmp; #else @@ -1470,7 +1468,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG1_INC |= aTmp; #else @@ -1499,7 +1497,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1534,7 +1532,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1574,7 +1572,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1606,7 +1604,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1638,7 +1636,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; #else @@ -1668,7 +1666,7 @@ int int_reverse_safe( FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG1_INC |= aTmp; #else @@ -1702,7 +1700,7 @@ int int_reverse_safe( if (TARG1 > TARG2) FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; #else revreal aTmp = *Ares; @@ -1719,7 +1717,7 @@ int int_reverse_safe( else if (TARG1 < TARG2) FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; #else revreal aTmp = *Ares; @@ -1736,7 +1734,7 @@ int int_reverse_safe( else { /* both are equal */ FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG2_INC |= aTmp; AARG1_INC |= aTmp; @@ -1754,7 +1752,7 @@ int int_reverse_safe( } #else FOR_0_LE_l_LT_p { - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG1_INC |= aTmp; AARG2_INC |= aTmp; @@ -1792,7 +1790,7 @@ int int_reverse_safe( if (TARG < 0.0) FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; #else revreal aTmp = *Ares; @@ -1809,7 +1807,7 @@ int int_reverse_safe( else if (TARG > 0.0) FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; #else revreal aTmp = *Ares; @@ -1826,7 +1824,7 @@ int int_reverse_safe( else FOR_0_LE_l_LT_p { #if defined(_INT_REV_) - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; #else revreal aTmp = *Ares; @@ -1837,7 +1835,7 @@ int int_reverse_safe( } #else FOR_0_LE_l_LT_p { - unsigned long int aTmp = *Ares; + size_t aTmp = *Ares; ARES_INC = 0; AARG_INC |= aTmp; } diff --git a/ADOL-C/src/sparse/sparse_fo_rev.cpp b/ADOL-C/src/sparse/sparse_fo_rev.cpp index 411006338..1f8038989 100644 --- a/ADOL-C/src/sparse/sparse_fo_rev.cpp +++ b/ADOL-C/src/sparse/sparse_fo_rev.cpp @@ -25,8 +25,8 @@ extern "C" void adolc_exit(int errorcode, const char *what, /****************************************************************************/ /* 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, size_t **X, double *y, + size_t **Y, char mode) /* forward(tag, m, n, p, x[n], X[n][p], y[m], Y[m][p], mode) */ { int rc = -1; @@ -51,8 +51,7 @@ int forward(short tag, int m, int n, int p, double *x, unsigned long int **X, /****************************************************************************/ /* 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, size_t **X, size_t **Y, char mode) /* forward(tag, m, n, p, X[n][p], Y[m][p], mode) */ { if (mode != 0) // not safe @@ -68,8 +67,7 @@ int forward(short tag, int m, int n, int p, unsigned long int **X, /* */ /* 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, size_t **U, size_t **Z, char mode) /* reverse(tag, m, n, q, U[q][m], Z[q][n]) */ { int rc = -1; diff --git a/ADOL-C/src/sparse/sparsedrivers.cpp b/ADOL-C/src/sparse/sparsedrivers.cpp index cce567a6d..925d68b71 100644 --- a/ADOL-C/src/sparse/sparsedrivers.cpp +++ b/ADOL-C/src/sparse/sparsedrivers.cpp @@ -722,8 +722,8 @@ int bit_vector_propagation( 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; + size_t value1, v; + size_t **seed = NULL, *s, **jac_bit_pat = NULL, *jac; unsigned char *indep_blocks_flags = NULL, *i_b_flags; double *valuepoint = NULL; @@ -749,10 +749,10 @@ int bit_vector_propagation( /* bit pattern parameters */ - /* 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 */ + /* number of bits in an size_t variable */ + bits_per_long = 8 * sizeof(size_t); + /* olvo 20000214 nl: inserted explicit cast to size_t */ + value1 = (size_t)1 << (bits_per_long - 1); /* 10000....0 */ /* =================================================== forward propagation */ if (forward_mode) { @@ -765,10 +765,10 @@ int bit_vector_propagation( /* indep partial derivatives for the whole Jacobian */ - /* number of unsigned longs to store the whole seed / Jacobian matrice */ + /* number of size_ts to store the whole seed / Jacobian matrice */ p_ind_bl_bp = indep / bits_per_long + ((indep % bits_per_long) != 0); - /* number of unsigned longs to store the seed / Jacobian strips */ + /* number of size_ts to store the seed / Jacobian strips */ if (p_ind_bl_bp <= PQ_STRIPMINE_MAX) { p_stripmine = p_ind_bl_bp; stripmined_calls = 1; @@ -891,10 +891,10 @@ int bit_vector_propagation( /* depen weight vectors for the whole Jacobian */ - /* number of unsigned longs to store the whole seed / Jacobian matrice */ + /* number of size_ts 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 */ + /* number of size_ts to store the seed / Jacobian strips */ if (q_dep_bl_bp <= PQ_STRIPMINE_MAX) { q_stripmine = q_dep_bl_bp; stripmined_calls = 1; diff --git a/ADOL-C/src/taping.c b/ADOL-C/src/taping.c index 6451952e7..853d5bdc3 100644 --- a/ADOL-C/src/taping.c +++ b/ADOL-C/src/taping.c @@ -472,7 +472,7 @@ void readConfigFile() { char *pos1 = NULL, *pos2 = NULL, *pos3 = NULL, *pos4 = NULL, *start = NULL, *end = NULL; int base; - unsigned long int number = 0; + size_t number = 0; char *path = NULL; int defdirsize = strlen(TAPE_DIR PATHSEPARATOR); tapeBaseNames[0] = duplicatestr(TAPE_DIR PATHSEPARATOR ADOLC_LOCATIONS_NAME); diff --git a/ADOL-C/src/taping_p.h b/ADOL-C/src/taping_p.h index fc37f1267..add41dfd6 100644 --- a/ADOL-C/src/taping_p.h +++ b/ADOL-C/src/taping_p.h @@ -281,7 +281,7 @@ typedef struct TapeInfos { revreal **rpp_T; revreal *rp_A; revreal **rpp_A; - unsigned long int **upp_A; + size_t **upp_A; /* extern diff. fcts */ locint ext_diff_fct_index; /* set by forward and reverse (from tape) */ diff --git a/ADOL-C/src/uni5_for.cpp b/ADOL-C/src/uni5_for.cpp index e41454cbf..b2acd359c 100644 --- a/ADOL-C/src/uni5_for.cpp +++ b/ADOL-C/src/uni5_for.cpp @@ -562,15 +562,15 @@ int int_forward_tight( int indcheck, /* consistency chk on # of independents */ int p, /* # of taylor series, bit pattern */ const double *basepoint, /* independent variable values (in)*/ - unsigned long int **argument, /* Taylor coeff. (in)*/ + size_t **argument, /* Taylor coeff. (in)*/ double *valuepoint, /* dependent variable values (out)*/ - unsigned long int **taylors) /* matrix of coefficient vectors(out)*/ + size_t **taylors) /* matrix of coefficient vectors(out)*/ /* int_forward_tight( tag, m, n, p, x[n], X[n][p], y[m], Y[m][p]), nBV = number of Boolean Vectors to be packed (see Chapter Dependence Analysis, ADOL-C - Documentation) bits_per_long = 8*sizeof(unsigned long int) p = nBV / + Documentation) bits_per_long = 8*sizeof(size_t) p = nBV / bits_per_long + ( (nBV % bits_per_long) != 0 ) The order of the indices in argument and taylors is [var][taylor] @@ -589,14 +589,14 @@ int int_forward_safe( int depcheck, /* consistency chk on # of dependents */ int indcheck, /* consistency chk on # of independents */ int p, /* # of taylor series, bit pattern */ - unsigned long int **argument, /* Taylor coeff. (in)*/ - unsigned long int **taylors) /* matrix of coefficient vectors (out)*/ + size_t **argument, /* Taylor coeff. (in)*/ + size_t **taylors) /* matrix of coefficient vectors (out)*/ /* int_forward_safe( tag, m, n, p, X[n][p], Y[m][p]), nBV = number of Boolean Vectors to be packed (see Chapter Dependence Analysis, ADOL-C Documentation) -bits_per_long = 8*sizeof(unsigned long int) +bits_per_long = 8*sizeof(size_t) p = nBV / bits_per_long + ( (nBV % bits_per_long) != 0 ) The order of the indices in argument and taylors is [var][taylor] From 2b161e8d86d42f2d53487a6f4646c9c06ed05221 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:02:15 +0100 Subject: [PATCH 29/69] rename to cpp --- ADOL-C/src/CMakeLists.txt | 2 +- CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ADOL-C/src/CMakeLists.txt b/ADOL-C/src/CMakeLists.txt index 45e02511d..d405e7ca6 100644 --- a/ADOL-C/src/CMakeLists.txt +++ b/ADOL-C/src/CMakeLists.txt @@ -50,7 +50,7 @@ target_sources(adolc PRIVATE rpl_malloc.c storemanager.cpp tape_handling.cpp - taping.c + taping.cpp zos_forward.cpp zos_pl_forward.cpp ) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc94eb1c8..18aeb442d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ target_include_directories(adolc # handle the options # ------------------ -set(UINT_TYPE uint32_t) +set(UINT_TYPE size_t) set(REAL_TYPE double) set(ADVBRANCH "#undef ADOLC_ADVANCED_BRANCHING") From 3190f97fae46ba97f05da3768d00fa39e46b9f27 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:02:54 +0100 Subject: [PATCH 30/69] add missing include --- ADOL-C/include/adolc/param.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ADOL-C/include/adolc/param.h b/ADOL-C/include/adolc/param.h index 57752a30d..7aa0ea937 100644 --- a/ADOL-C/include/adolc/param.h +++ b/ADOL-C/include/adolc/param.h @@ -14,6 +14,7 @@ #if !defined(ADOLC_PARAM_H) #define ADOLC_PARAM_H 1 +#include "adouble.h" #include "internal/common.h" #if defined(__cplusplus) From b5059a8d0322fc74b22a5854eed2ebe771660147 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:04:37 +0100 Subject: [PATCH 31/69] resolve type warning --- ADOL-C/src/advector.cpp | 10 +++++----- ADOL-C/src/fo_rev.cpp | 2 +- ADOL-C/src/ho_rev.cpp | 2 +- ADOL-C/src/storemanager.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ADOL-C/src/advector.cpp b/ADOL-C/src/advector.cpp index 48ef8065d..28ba9255c 100644 --- a/ADOL-C/src/advector.cpp +++ b/ADOL-C/src/advector.cpp @@ -29,11 +29,11 @@ adubref::adubref(locint lo, locint ref) { 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); + fprintf(DIAG_OUT, + "ADOL-C error: strange construction of an active" + " vector subscript reference\n(passed ref = %zu, stored refloc = " + "%zu)\n", + ref, refloc); adolc_exit(-2, "", __func__, __FILE__, __LINE__); } isInit = true; diff --git a/ADOL-C/src/fo_rev.cpp b/ADOL-C/src/fo_rev.cpp index 2596d8158..b53c820ce 100644 --- a/ADOL-C/src/fo_rev.cpp +++ b/ADOL-C/src/fo_rev.cpp @@ -2220,7 +2220,7 @@ int int_reverse_safe(short tnum, /* tape id */ if (arg1 != vectorloc + idx) { fprintf(DIAG_OUT, "ADOL-C error: indexed active position does not match " - "referenced position\nindexed = %zu, referenced = %d\n", + "referenced position\nindexed = %zu, referenced = %zu\n", vectorloc + idx, arg1); adolc_exit(-2, "", __func__, __FILE__, __LINE__); } diff --git a/ADOL-C/src/ho_rev.cpp b/ADOL-C/src/ho_rev.cpp index a3d44d72f..ddcf63ca5 100644 --- a/ADOL-C/src/ho_rev.cpp +++ b/ADOL-C/src/ho_rev.cpp @@ -2429,7 +2429,7 @@ int hov_ti_reverse(short tnum, /* tape id */ if (arg1 != vectorloc + idx) { fprintf(DIAG_OUT, "ADOL-C error: indexed active position does not match " - "referenced position\nindexed = %zu, referenced = %d\n", + "referenced position\nindexed = %zu, referenced = %zu\n", vectorloc + idx, arg1); adolc_exit(-2, "", __func__, __FILE__, __LINE__); } diff --git a/ADOL-C/src/storemanager.cpp b/ADOL-C/src/storemanager.cpp index 7eb732b1d..45c373258 100644 --- a/ADOL-C/src/storemanager.cpp +++ b/ADOL-C/src/storemanager.cpp @@ -152,7 +152,7 @@ void StoreManagerLocint::grow(size_t mingrow) { // encapsulate this error message fprintf(DIAG_OUT, "\nADOL-C error:\n"); fprintf(DIAG_OUT, - "maximal number (%d) of live active variables exceeded\n\n", + "maximal number (%zu) of live active variables exceeded\n\n", std::numeric_limits::max()); adolc_exit(-3, "", __func__, __FILE__, __LINE__); } From cd87fa1e0984dd8b1d8db10dcaed822150442cbe Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:05:30 +0100 Subject: [PATCH 32/69] rename to cpp --- ADOL-C/src/checkpointing.cpp | 2 +- ADOL-C/src/externfcts.cpp | 2 +- ADOL-C/src/taping.c | 2539 ---------------------------------- 3 files changed, 2 insertions(+), 2541 deletions(-) delete mode 100644 ADOL-C/src/taping.c diff --git a/ADOL-C/src/checkpointing.cpp b/ADOL-C/src/checkpointing.cpp index edffbca72..4b9f97f01 100644 --- a/ADOL-C/src/checkpointing.cpp +++ b/ADOL-C/src/checkpointing.cpp @@ -126,7 +126,7 @@ int checkpointing(CpInfos *cpInfos) { delete[] vals; // update taylor stack; same structure as in adouble.cpp + - // correction in taping.c + // correction in taping.cpp if (oldTraceFlag != 0) { ADOLC_CURRENT_TAPE_INFOS.numTays_Tape += cpInfos->n; if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors != 0) diff --git a/ADOL-C/src/externfcts.cpp b/ADOL-C/src/externfcts.cpp index bd2de55c3..b540b473b 100644 --- a/ADOL-C/src/externfcts.cpp +++ b/ADOL-C/src/externfcts.cpp @@ -182,7 +182,7 @@ void call_ext_fct_commonPrior(ext_diff_fct *edfct, int n, adouble *xa, int 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 */ + * adouble.cpp => correction in taping.cpp */ if (oldTraceFlag != 0) { if (edfct->dp_x_changes) diff --git a/ADOL-C/src/taping.c b/ADOL-C/src/taping.c deleted file mode 100644 index 853d5bdc3..000000000 --- a/ADOL-C/src/taping.c +++ /dev/null @@ -1,2539 +0,0 @@ -/*---------------------------------------------------------------------------- - ADOL-C -- Automatic Differentiation by Overloading in C++ - File: taping.c - Revision: $Id$ - 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, - 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 - recipient's acceptance of the terms of the accompanying license file. - -----------------------------------------------------------------------------*/ - -#include -#include - -#include "dvlparms.h" -#include "oplate.h" -#include "taping_p.h" - -#include -#include - -#ifdef ADOLC_AMPI_SUPPORT -#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 -#endif - -#ifndef S_ISDIR -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif - -/*--------------------------------------------------------------------------*/ -/* Tape identification (ADOLC & version check) */ -ADOLC_ID adolc_id; -/* first version with new tape structure - * => to work with older tapes use older ADOL-C version */ -#define ADOLC_NEW_TAPE_VERSION 2 -#define ADOLC_NEW_TAPE_SUBVERSION 5 -#define ADOLC_NEW_TAPE_PATCHLEVEL 3 - -/****************************************************************************/ -/****************************************************************************/ -/* HELP FUNCTIONS */ -/****************************************************************************/ -/****************************************************************************/ - -/*--------------------------------------------------------------------------*/ -/* additional infos used by fail() */ -int failAdditionalInfo1; -int failAdditionalInfo2; -locint failAdditionalInfo3; -locint failAdditionalInfo4; -void *failAdditionalInfo5; -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); -} - -/* 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; - } -} - -/* the base names of every tape type */ -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; - } - } -} - -/****************************************************************************/ -/* The subroutine get_fstr appends to the tape base name of type tapeType */ -/* the number fnum and ".tap" and returns a pointer to the resulting string.*/ -/* The result string must be freed be the caller! */ -/****************************************************************************/ -char *createFileName(short tapeID, int tapeType) { - char *numberString, *fileName, *extension = ".tap", *currPos; -#if defined(_OPENMP) - 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); -#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; - } -#endif /* _OPENMP */ - - /* malloc and create */ - fileNameLength = tapeBaseNameLength + numberStringLength + 5; -#if defined(_OPENMP) - 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; -#if defined(_OPENMP) - 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; - - free(numberString); -#if defined(_OPENMP) - if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) - free(threadNumberString); -#endif /* _OPENMP */ - - 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; -} - -#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; - size_t 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"); - } - } - } - } - fprintf(DIAG_OUT, "****************************************\n\n"); - fclose(configFile); - } - ADOLC_OPENMP_RESTORE_THREAD_NUMBER; -} - -/****************************************************************************/ -/****************************************************************************/ -/* VALUE STACK FUNCTIONS */ -/****************************************************************************/ -/****************************************************************************/ - -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) { - /* 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(); - } - /* 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); - } - } - ADOLC_CURRENT_TAPE_INFOS.traceFlag = 1; -} - -/****************************************************************************/ -/* record all remaining live variables on the value stack tape */ -/* - turns off trace_flag */ -/* - 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; -} - -/****************************************************************************/ -/* 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; -} - -/****************************************************************************/ -/* 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; - } - - 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 % - 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; -} - -/****************************************************************************/ -/* Writes the block of size depth of taylor coefficients from point loc to */ -/* the taylor buffer. If the buffer is filled, then it is written to the */ -/* 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; -} - -/****************************************************************************/ -/* Writes the block of size depth of taylor coefficients from point loc to */ -/* the taylor buffer. If the buffer is filled, then it is written to the */ -/* 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; - } -} - -/****************************************************************************/ -/* 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; -} - -/****************************************************************************/ -/* 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; -} - -/****************************************************************************/ -/* Puts a block of taylor coefficients from the value stack buffer to the */ -/* 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; - } -} - -/****************************************************************************/ -/* Puts a block of taylor coefficients from the value stack buffer to the */ -/* 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; - } -} - -/****************************************************************************/ -/* 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; -} - -/****************************************************************************/ -/****************************************************************************/ -/* NON-VALUE-STACK FUNCTIONS */ -/****************************************************************************/ -/****************************************************************************/ - -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]; -} - -/****************************************************************************/ -/* start_trace: (part of trace_on) */ -/* Initialization for the taping process. Does buffer allocation, sets */ -/* 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); - - /* 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 < 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_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_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; - } - - 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; - } -} - -/****************************************************************************/ -/* 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; - } - if (tapeInfos->signature != NULL) { - free(tapeInfos->signature); - tapeInfos->signature = NULL; - } -} - -/****************************************************************************/ -/* Tapestats: */ -/* Returns statistics on the tape tag with following meaning: */ -/* tape_stat[0] = # of independent variables. */ -/* tape_stat[1] = # of dependent variables. */ -/* tape_stat[2] = max # of live variables. */ -/* tape_stat[3] = value stack size. */ -/* tape_stat[4] = buffer size (# of chars, # of doubles, # of locints) */ -/* tape_stat[5] = # of operations. */ -/* tape_stat[6] = operation file access flag (1 = file in use, 0 otherwise) */ -/* tape_stat[7] = # of saved locations. */ -/* tape_stat[8] = location file access flag (1 = file in use, 0 otherwise) */ -/* tape_stat[9] = # of saved constant values. */ -/* 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; - - /* 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"); -} - -/****************************************************************************/ -/* 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]; -} - -/****************************************************************************/ -/* 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 = (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); -} - -/****************************************************************************/ -/* Overrides the parameters for the next evaluations. This will invalidate */ -/* 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(); -} - -/****************************************************************************/ -/* 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); - } - - 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); -} - -void skip_tracefile_cleanup(short tnum) { - 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; -#ifdef ADOLC_AMPI_SUPPORT - TAPE_AMPI_resetBottom(); -#endif -} - -/****************************************************************************/ -/* 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; -#ifdef ADOLC_AMPI_SUPPORT - TAPE_AMPI_resetTop(); -#endif -} - -/****************************************************************************/ -/* 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 */ -} - -/* --- Operations --- */ - -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; - } - /* 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; -} - -/****************************************************************************/ -/* Writes a block of operations onto hard disk and handles file creation, */ -/* 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) { -#if defined(ADOLC_DEBUG) - 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"); - } - } - - 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; -} - -/****************************************************************************/ -/* 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; -} - -/* --- Locations --- */ - -/****************************************************************************/ -/* Writes a block of locations onto hard disk and handles file creation, */ -/* 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"); - } - } - - 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; -} - -/****************************************************************************/ -/* 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); -} - -/* --- Values (Constants -- Real) --- */ - -/****************************************************************************/ -/* Writes a block of constants (real) onto hard disk and handles file */ -/* creation, removal, ... */ -/****************************************************************************/ -void put_vals_writeBlock(double *vals, locint numVals) { - 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; - ++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; - - for (i = 0; i < numVals; ++i) { - *ADOLC_CURRENT_TAPE_INFOS.currVal = vals[i]; - ++ADOLC_CURRENT_TAPE_INFOS.currVal; - } -} - -/****************************************************************************/ -/* Writes a block of constants (real) onto tape and handles file creation */ -/* 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"); - } - } - - 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; -} - -/****************************************************************************/ -/* 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; -} - -/****************************************************************************/ -/* Returns the number of free constants in the real tape. Ensures that it */ -/* 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; - } - 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 < 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; - } - } -} - -/****************************************************************************/ -/* Returns a pointer to the first element of a values vector and skips the */ -/* vector. -- Forward Mode -- */ -/****************************************************************************/ -double *get_val_v_f(locint size) { - 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; -} - -/****************************************************************************/ -/* Returns a pointer to the first element of a values vector and skips the */ -/* 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; -} - -/* --- Updates / Corrections --- */ - -/****************************************************************************/ -/* 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(); -} - -/****************************************************************************/ -/* Update locations tape to remove assignments involving temp. variables. */ -/* 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; - } - 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; - } - 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; - } - return 0; -} - -void enableBranchSwitchWarnings() { - 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; -} - -/****************************************************************************/ -/* UTILs */ -/****************************************************************************/ -double make_nan() { - 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; -} - -/****************************************************************************/ -/* DEBUG FUNCTIONS */ -#if defined(ADOLC_HARDDEBUG) - -/*--------------------------------------------------------------------------*/ -unsigned char get_op_f() { - 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; -} - -/*--------------------------------------------------------------------------*/ -unsigned char get_op_r() { - 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; -} - -/*--------------------------------------------------------------------------*/ -locint get_locint_f() { - 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; -} - -/*--------------------------------------------------------------------------*/ -locint get_locint_r() { - 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; -} - -/*--------------------------------------------------------------------------*/ -double get_val_f() { - 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; -} - -/*--------------------------------------------------------------------------*/ -double get_val_r() { - 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; -} - -#endif From b726ed97f01c3e686a678dec2fa98ae30c9103c6 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:06:10 +0100 Subject: [PATCH 33/69] resolve type warning --- ADOL-C/src/param.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADOL-C/src/param.cpp b/ADOL-C/src/param.cpp index 13c74aa76..a85e3bdbf 100644 --- a/ADOL-C/src/param.cpp +++ b/ADOL-C/src/param.cpp @@ -41,7 +41,7 @@ pdouble::pdouble(locint idx) { _idx = idx; } else { fprintf(DIAG_OUT, - "ADOL-C error: Parameter index %d out of bounds, " + "ADOL-C error: Parameter index %zu out of bounds, " "# existing parameters = %zu\n", idx, ADOLC_GLOBAL_TAPE_VARS.numparam); adolc_exit(-1, "", __func__, __FILE__, __LINE__); From 233d20533c9d410ceae45c94b269442b40438798 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:06:53 +0100 Subject: [PATCH 34/69] rename to cpp; solve char * issues and remove some mallocs --- ADOL-C/src/taping.cpp | 2540 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2540 insertions(+) create mode 100644 ADOL-C/src/taping.cpp diff --git a/ADOL-C/src/taping.cpp b/ADOL-C/src/taping.cpp new file mode 100644 index 000000000..6fadc1126 --- /dev/null +++ b/ADOL-C/src/taping.cpp @@ -0,0 +1,2540 @@ +/*---------------------------------------------------------------------------- + ADOL-C -- Automatic Differentiation by Overloading in C++ + File: taping.c + Revision: $Id$ + 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, + 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 + recipient's acceptance of the terms of the accompanying license file. + +----------------------------------------------------------------------------*/ + +#include +#include + +#include "dvlparms.h" +#include "oplate.h" +#include "taping_p.h" + +#include +#include + +#ifdef ADOLC_AMPI_SUPPORT +#include "ampi/ampi.h" +#include "ampi/tape/support.h" +#endif + +#if defined(_WINDOWS) && !__STDC__ +#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) +#endif + +/*--------------------------------------------------------------------------*/ +/* Tape identification (ADOLC & version check) */ +ADOLC_ID adolc_id; +/* first version with new tape structure + * => to work with older tapes use older ADOL-C version */ +#define ADOLC_NEW_TAPE_VERSION 2 +#define ADOLC_NEW_TAPE_SUBVERSION 5 +#define ADOLC_NEW_TAPE_PATCHLEVEL 3 + +/****************************************************************************/ +/****************************************************************************/ +/* HELP FUNCTIONS */ +/****************************************************************************/ +/****************************************************************************/ + +/*--------------------------------------------------------------------------*/ +/* additional infos used by fail() */ +int failAdditionalInfo1; +int failAdditionalInfo2; +locint failAdditionalInfo3; +locint failAdditionalInfo4; +void *failAdditionalInfo5; +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 (%zu) 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 = %zu\n" + " newStoreSize = %zu\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(%zu) and/or " + "independents(%zu)\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; + } +} + +/* the base names of every tape type */ +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; + } + } +} + +/****************************************************************************/ +/* The subroutine get_fstr appends to the tape base name of type tapeType */ +/* the number fnum and ".tap" and returns a pointer to the resulting string.*/ +/* The result string must be freed be the caller! */ +/****************************************************************************/ +char *createFileName(short tapeID, int tapeType) { + char *numberString = nullptr; + char *fileName = nullptr; + const char *extension = ".tap"; + char *currPos = nullptr; +#if defined(_OPENMP) + 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 = new char[numberStringLength + 1]; + if (numberString == NULL) + fail(ADOLC_MALLOC_FAILED); + snprintf(numberString, numberStringLength + 1, "%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; + } +#endif /* _OPENMP */ + + /* malloc and create */ + fileNameLength = tapeBaseNameLength + numberStringLength + 5; +#if defined(_OPENMP) + 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; +#if defined(_OPENMP) + 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; + + delete numberString; +#if defined(_OPENMP) + if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) + free(threadNumberString); +#endif /* _OPENMP */ + + 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 = new char[len + 1]; + 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; + size_t 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: %zu\n", + (locint)number); + } else if (strcmp(pos1 + 1, "LBUFSIZE") == 0) { + ADOLC_GLOBAL_TAPE_VARS.locationBufferSize = (locint)number; + fprintf(DIAG_OUT, "Found location buffer size: %zu\n", + (locint)number); + } else if (strcmp(pos1 + 1, "VBUFSIZE") == 0) { + ADOLC_GLOBAL_TAPE_VARS.valueBufferSize = (locint)number; + fprintf(DIAG_OUT, "Found value buffer size: %zu\n", (locint)number); + } else if (strcmp(pos1 + 1, "TBUFSIZE") == 0) { + ADOLC_GLOBAL_TAPE_VARS.taylorBufferSize = (locint)number; + fprintf(DIAG_OUT, "Found taylor buffer size: %zu\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 : %zu\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; +} + +/****************************************************************************/ +/****************************************************************************/ +/* VALUE STACK FUNCTIONS */ +/****************************************************************************/ +/****************************************************************************/ + +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) { + /* 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(); + } + /* 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); + } + } + ADOLC_CURRENT_TAPE_INFOS.traceFlag = 1; +} + +/****************************************************************************/ +/* record all remaining live variables on the value stack tape */ +/* - turns off trace_flag */ +/* - 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; +} + +/****************************************************************************/ +/* 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; +} + +/****************************************************************************/ +/* 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; + } + + 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 % + 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; +} + +/****************************************************************************/ +/* Writes the block of size depth of taylor coefficients from point loc to */ +/* the taylor buffer. If the buffer is filled, then it is written to the */ +/* 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; +} + +/****************************************************************************/ +/* Writes the block of size depth of taylor coefficients from point loc to */ +/* the taylor buffer. If the buffer is filled, then it is written to the */ +/* 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; + } +} + +/****************************************************************************/ +/* 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; +} + +/****************************************************************************/ +/* 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; +} + +/****************************************************************************/ +/* Puts a block of taylor coefficients from the value stack buffer to the */ +/* 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; + } +} + +/****************************************************************************/ +/* Puts a block of taylor coefficients from the value stack buffer to the */ +/* 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; + } +} + +/****************************************************************************/ +/* 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; +} + +/****************************************************************************/ +/****************************************************************************/ +/* NON-VALUE-STACK FUNCTIONS */ +/****************************************************************************/ +/****************************************************************************/ + +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]; +} + +/****************************************************************************/ +/* start_trace: (part of trace_on) */ +/* Initialization for the taping process. Does buffer allocation, sets */ +/* 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); + + /* 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) + delete ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore; + + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore = + new double[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]]; + + // 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 < 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_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_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; + } + + 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; + } +} + +/****************************************************************************/ +/* 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; + } + if (tapeInfos->signature != NULL) { + free(tapeInfos->signature); + tapeInfos->signature = NULL; + } +} + +/****************************************************************************/ +/* Tapestats: */ +/* Returns statistics on the tape tag with following meaning: */ +/* tape_stat[0] = # of independent variables. */ +/* tape_stat[1] = # of dependent variables. */ +/* tape_stat[2] = max # of live variables. */ +/* tape_stat[3] = value stack size. */ +/* tape_stat[4] = buffer size (# of chars, # of doubles, # of locints) */ +/* tape_stat[5] = # of operations. */ +/* tape_stat[6] = operation file access flag (1 = file in use, 0 otherwise) */ +/* tape_stat[7] = # of saved locations. */ +/* tape_stat[8] = location file access flag (1 = file in use, 0 otherwise) */ +/* tape_stat[9] = # of saved constant values. */ +/* 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; + + /* 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"); +} + +/****************************************************************************/ +/* 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]; +} + +/****************************************************************************/ +/* 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 = new double[tapeInfos->stats[NUM_PARAM]]; + 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); +} + +/****************************************************************************/ +/* Overrides the parameters for the next evaluations. This will invalidate */ +/* 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(); +} + +/****************************************************************************/ +/* 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); + } + + 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); +} + +void skip_tracefile_cleanup(short tnum) { + 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; +#ifdef ADOLC_AMPI_SUPPORT + TAPE_AMPI_resetBottom(); +#endif +} + +/****************************************************************************/ +/* 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; +#ifdef ADOLC_AMPI_SUPPORT + TAPE_AMPI_resetTop(); +#endif +} + +/****************************************************************************/ +/* 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 */ +} + +/* --- Operations --- */ + +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; + } + /* 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; +} + +/****************************************************************************/ +/* Writes a block of operations onto hard disk and handles file creation, */ +/* 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) { +#if defined(ADOLC_DEBUG) + 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"); + } + } + + 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; +} + +/****************************************************************************/ +/* 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; +} + +/* --- Locations --- */ + +/****************************************************************************/ +/* Writes a block of locations onto hard disk and handles file creation, */ +/* 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"); + } + } + + 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; +} + +/****************************************************************************/ +/* 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); +} + +/* --- Values (Constants -- Real) --- */ + +/****************************************************************************/ +/* Writes a block of constants (real) onto hard disk and handles file */ +/* creation, removal, ... */ +/****************************************************************************/ +void put_vals_writeBlock(double *vals, locint numVals) { + 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; + ++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; + + for (i = 0; i < numVals; ++i) { + *ADOLC_CURRENT_TAPE_INFOS.currVal = vals[i]; + ++ADOLC_CURRENT_TAPE_INFOS.currVal; + } +} + +/****************************************************************************/ +/* Writes a block of constants (real) onto tape and handles file creation */ +/* 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"); + } + } + + 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; +} + +/****************************************************************************/ +/* 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; +} + +/****************************************************************************/ +/* Returns the number of free constants in the real tape. Ensures that it */ +/* 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; + } + 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 < 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; + } + } +} + +/****************************************************************************/ +/* Returns a pointer to the first element of a values vector and skips the */ +/* vector. -- Forward Mode -- */ +/****************************************************************************/ +double *get_val_v_f(locint size) { + 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; +} + +/****************************************************************************/ +/* Returns a pointer to the first element of a values vector and skips the */ +/* 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; +} + +/* --- Updates / Corrections --- */ + +/****************************************************************************/ +/* 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(); +} + +/****************************************************************************/ +/* Update locations tape to remove assignments involving temp. variables. */ +/* 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; + } + 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; + } + 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; + } + return 0; +} + +void enableBranchSwitchWarnings() { + 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; +} + +/****************************************************************************/ +/* UTILs */ +/****************************************************************************/ +double make_nan() { + 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; +} + +/****************************************************************************/ +/* DEBUG FUNCTIONS */ +#if defined(ADOLC_HARDDEBUG) + +/*--------------------------------------------------------------------------*/ +unsigned char get_op_f() { + 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; +} + +/*--------------------------------------------------------------------------*/ +unsigned char get_op_r() { + 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; +} + +/*--------------------------------------------------------------------------*/ +locint get_locint_f() { + 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; +} + +/*--------------------------------------------------------------------------*/ +locint get_locint_r() { + 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; +} + +/*--------------------------------------------------------------------------*/ +double get_val_f() { + 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; +} + +/*--------------------------------------------------------------------------*/ +double get_val_r() { + 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; +} + +#endif From da1fff1a104fde078c382b5cab8d98ab2dfc8412 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:20:09 +0100 Subject: [PATCH 35/69] change malloc to new and free to delete --- ADOL-C/src/taping.cpp | 53 ++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/ADOL-C/src/taping.cpp b/ADOL-C/src/taping.cpp index 6fadc1126..142c08a10 100644 --- a/ADOL-C/src/taping.cpp +++ b/ADOL-C/src/taping.cpp @@ -365,8 +365,8 @@ void clearTapeBaseNames() { int i; for (i = 0; i < 4; i++) { if (tapeBaseNames[i]) { - free(tapeBaseNames[i]); - tapeBaseNames[i] = 0; + delete tapeBaseNames[i]; + tapeBaseNames[i] = nullptr; } } } @@ -411,7 +411,7 @@ char *createFileName(short tapeID, int tapeType) { else threadNumberStringLength = 0; ++threadNumberStringLength; - threadNumberString = malloc(sizeof(char) * (threadNumberStringLength + 2)); + threadNumberString = new char[threadNumerStringLength + 2]; if (threadNumberString == NULL) fail(ADOLC_MALLOC_FAILED); sprintf(threadNumberString, "%d", threadNumber); @@ -427,7 +427,7 @@ char *createFileName(short tapeID, int tapeType) { if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) fileNameLength += threadNameLength + threadNumberStringLength; #endif /* _OPENMP */ - fileName = (char *)malloc(sizeof(char) * fileNameLength); + fileName = new char[fileNameLength]; if (fileName == NULL) fail(ADOLC_MALLOC_FAILED); currPos = fileName; @@ -450,7 +450,7 @@ char *createFileName(short tapeID, int tapeType) { delete numberString; #if defined(_OPENMP) if (ADOLC_GLOBAL_TAPE_VARS.inParallelRegion == 1) - free(threadNumberString); + delete threadNumberString; #endif /* _OPENMP */ return fileName; @@ -549,9 +549,8 @@ void readConfigFile() { for (i = 0; i < 4; i++) { char *currpos; int fnamelen; - tapeBaseNames[i] = (char *)calloc(namelen[i] - defdirsize + - pathlen + pathseplen + 1, - sizeof(char)); + tapeBaseNames[i] = new char[namelen[i] - defdirsize + pathlen + + pathseplen + 1]; currpos = tapeBaseNames[i]; strncpy(currpos, path, pathlen); currpos += pathlen; @@ -734,8 +733,7 @@ void taylor_begin(uint bufferSize, int degreeSave) { /* initial setups */ if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) - ADOLC_CURRENT_TAPE_INFOS.tayBuffer = - (revreal *)malloc(sizeof(revreal) * bufferSize); + ADOLC_CURRENT_TAPE_INFOS.tayBuffer = new double[bufferSize]; if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) fail(ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED); @@ -1101,14 +1099,14 @@ void initTapeBuffers() { 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)); + ADOLC_CURRENT_TAPE_INFOS.opBuffer = + new unsigned char[ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]]; if (ADOLC_CURRENT_TAPE_INFOS.locBuffer == NULL) - ADOLC_CURRENT_TAPE_INFOS.locBuffer = (locint *)malloc( - ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE] * sizeof(locint)); + ADOLC_CURRENT_TAPE_INFOS.locBuffer = + new locint[ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]]; if (ADOLC_CURRENT_TAPE_INFOS.valBuffer == NULL) - ADOLC_CURRENT_TAPE_INFOS.valBuffer = (double *)malloc( - ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE] * sizeof(double)); + ADOLC_CURRENT_TAPE_INFOS.valBuffer = + new double[ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]]; if (ADOLC_CURRENT_TAPE_INFOS.opBuffer == NULL || ADOLC_CURRENT_TAPE_INFOS.locBuffer == NULL || ADOLC_CURRENT_TAPE_INFOS.valBuffer == NULL) @@ -1261,7 +1259,7 @@ void close_tape(int flag) { 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); + delete ADOLC_CURRENT_TAPE_INFOS.opBuffer; ADOLC_CURRENT_TAPE_INFOS.opBuffer = NULL; } else { ADOLC_CURRENT_TAPE_INFOS.numOps_Tape = @@ -1280,7 +1278,7 @@ void close_tape(int flag) { 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); + delete ADOLC_CURRENT_TAPE_INFOS.valBuffer; ADOLC_CURRENT_TAPE_INFOS.valBuffer = NULL; } else { ADOLC_CURRENT_TAPE_INFOS.numVals_Tape = @@ -1305,7 +1303,7 @@ void close_tape(int flag) { 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); + delete ADOLC_CURRENT_TAPE_INFOS.locBuffer; ADOLC_CURRENT_TAPE_INFOS.locBuffer = NULL; } else { ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape = @@ -1319,14 +1317,14 @@ void close_tape(int flag) { /* Free all resources used by a tape before overwriting the tape. */ /****************************************************************************/ void freeTapeResources(TapeInfos *tapeInfos) { - free(tapeInfos->opBuffer); + delete tapeInfos->opBuffer; tapeInfos->opBuffer = NULL; - free(tapeInfos->locBuffer); + delete tapeInfos->locBuffer; tapeInfos->locBuffer = NULL; - free(tapeInfos->valBuffer); + delete tapeInfos->valBuffer; tapeInfos->valBuffer = NULL; if (tapeInfos->tayBuffer != NULL) { - free(tapeInfos->tayBuffer); + delete tapeInfos->tayBuffer; tapeInfos->tayBuffer = NULL; --numTBuffersInUse; } @@ -1434,8 +1432,7 @@ static void read_params(TapeInfos *tapeInfos) { size_t np, ip, avail, rsize; if (tapeInfos->pTapeInfos.paramstore == NULL) tapeInfos->pTapeInfos.paramstore = new double[tapeInfos->stats[NUM_PARAM]]; - valBuffer = - (double *)malloc(tapeInfos->stats[VAL_BUFFER_SIZE] * sizeof(double)); + valBuffer = new double[tapeInfos->stats[VAL_BUFFER_SIZE]]; lastValP1 = valBuffer + tapeInfos->stats[VAL_BUFFER_SIZE]; if ((val_file = fopen(tapeInfos->pTapeInfos.val_fileName, "rb")) == NULL) fail(ADOLC_VALUE_TAPE_FOPEN_FAILED); @@ -1484,7 +1481,7 @@ static void read_params(TapeInfos *tapeInfos) { } } fclose(val_file); - free(valBuffer); + delete valBuffer; } /****************************************************************************/ @@ -1512,8 +1509,8 @@ void set_param_vec(short tag, size_t numparam, revreal *paramvec) { 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)); + ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore = + new double[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]]; for (i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; i++) ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore[i] = paramvec[i]; taylor_close(false); From 53f08c341e2870f8f6177f1145dab60626ad87f1 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:23:27 +0100 Subject: [PATCH 36/69] change NULL to nullptr --- ADOL-C/src/taping.cpp | 196 +++++++++++++++++++++--------------------- 1 file changed, 96 insertions(+), 100 deletions(-) diff --git a/ADOL-C/src/taping.cpp b/ADOL-C/src/taping.cpp index 142c08a10..b300c913e 100644 --- a/ADOL-C/src/taping.cpp +++ b/ADOL-C/src/taping.cpp @@ -148,7 +148,7 @@ void fail(int error) { "ADOL-C error: Failure to reallocate storage for " "adouble values!\n\n" " oldStore = %p\n" - " newStore = NULL\n" + " newStore = nullptr\n" " oldStoreSize = %zu\n" " newStoreSize = %zu\n\n" "Possible remedies :\n" @@ -218,7 +218,7 @@ void fail(int error) { break; case ADOLC_BUFFER_NULLPOINTER_FUNCTION: - fprintf(DIAG_OUT, "ADOL-C error: NULL pointer supplied in buffer " + fprintf(DIAG_OUT, "ADOL-C error: nullptr supplied in buffer " "handling.\n"); break; case ADOLC_BUFFER_INDEX_TO_LARGE: @@ -227,7 +227,7 @@ void fail(int error) { break; case ADOLC_EXT_DIFF_NULLPOINTER_STRUCT: - fprintf(DIAG_OUT, "ADOL-C error: Got null pointer as pointer to struct " + fprintf(DIAG_OUT, "ADOL-C error: Got nullptr as pointer to struct " " containing ext. diff. function information!\n"); break; case ADOLC_EXT_DIFF_WRONG_TAPESTATS: @@ -236,18 +236,17 @@ void fail(int error) { " 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 " + fprintf(DIAG_OUT, "ADOL-C error: Got nullptr 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!"); + " to work with (nullptr)\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"); + fprintf(DIAG_OUT, "ADOL-C error: Got at least one nullptr as argument to" + " extern differentiated function!\n"); break; case ADOLC_EXT_DIFF_WRONG_FUNCTION_INDEX: fprintf(DIAG_OUT, @@ -263,23 +262,20 @@ void fail(int error) { break; case ADOLC_CHECKPOINTING_CPINFOS_NULLPOINTER: - fprintf(DIAG_OUT, "ADOL-C error: Got null pointer as pointer to struct " + fprintf(DIAG_OUT, "ADOL-C error: Got nullptr 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"); + fprintf(DIAG_OUT, "ADOL-C error: Got nullptr 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"); + fprintf(DIAG_OUT, "ADOL-C error: Got nullptr 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"); + fprintf(DIAG_OUT, "ADOL-C error: Got nullptr 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"); @@ -382,7 +378,7 @@ char *createFileName(short tapeID, int tapeType) { const char *extension = ".tap"; char *currPos = nullptr; #if defined(_OPENMP) - char *threadName = "thread-", *threadNumberString = NULL; + char *threadName = "thread-", *threadNumberString = nullptr; int threadNumber, threadNumberStringLength = 0, threadNameLength = 0; #endif /* _OPENMP */ int tapeBaseNameLength, numberStringLength, fileNameLength; @@ -398,7 +394,7 @@ char *createFileName(short tapeID, int tapeType) { numberStringLength = 0; ++numberStringLength; numberString = new char[numberStringLength + 1]; - if (numberString == NULL) + if (numberString == nullptr) fail(ADOLC_MALLOC_FAILED); snprintf(numberString, numberStringLength + 1, "%d", tapeID); #if defined(_OPENMP) @@ -412,7 +408,7 @@ char *createFileName(short tapeID, int tapeType) { threadNumberStringLength = 0; ++threadNumberStringLength; threadNumberString = new char[threadNumerStringLength + 2]; - if (threadNumberString == NULL) + if (threadNumberString == nullptr) fail(ADOLC_MALLOC_FAILED); sprintf(threadNumberString, "%d", threadNumber); threadNumberString[threadNumberStringLength] = '_'; @@ -428,7 +424,7 @@ char *createFileName(short tapeID, int tapeType) { fileNameLength += threadNameLength + threadNumberStringLength; #endif /* _OPENMP */ fileName = new char[fileNameLength]; - if (fileName == NULL) + if (fileName == nullptr) fail(ADOLC_MALLOC_FAILED); currPos = fileName; strncpy(currPos, tapeBaseNames[tapeType], tapeBaseNameLength); @@ -468,13 +464,13 @@ static char *duplicatestr(const char *instr) { #define ADOLC_LINE_LENGTH 100 void readConfigFile() { - FILE *configFile = NULL; + FILE *configFile = nullptr; char inputLine[ADOLC_LINE_LENGTH + 1]; - char *pos1 = NULL, *pos2 = NULL, *pos3 = NULL, *pos4 = NULL, *start = NULL, - *end = NULL; + char *pos1 = nullptr, *pos2 = nullptr, *pos3 = nullptr, *pos4 = nullptr, + *start = nullptr, *end = nullptr; int base; size_t number = 0; - char *path = NULL; + char *path = nullptr; int defdirsize = strlen(TAPE_DIR PATHSEPARATOR); tapeBaseNames[0] = duplicatestr(TAPE_DIR PATHSEPARATOR ADOLC_LOCATIONS_NAME); tapeBaseNames[1] = duplicatestr(TAPE_DIR PATHSEPARATOR ADOLC_VALUES_NAME); @@ -489,7 +485,7 @@ void readConfigFile() { ADOLC_GLOBAL_TAPE_VARS.valueBufferSize = VBUFSIZE; ADOLC_GLOBAL_TAPE_VARS.taylorBufferSize = TBUFSIZE; ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers = TBUFNUM; - if ((configFile = fopen(".adolcrc", "r")) != NULL) { + if ((configFile = fopen(".adolcrc", "r")) != nullptr) { fprintf(DIAG_OUT, "\nFile .adolcrc found! => Try to parse it!\n"); fprintf(DIAG_OUT, "****************************************\n"); while (fgets(inputLine, ADOLC_LINE_LENGTH + 1, configFile) == inputLine) { @@ -503,19 +499,19 @@ void readConfigFile() { break; } pos1 = strchr(inputLine, '"'); - pos2 = NULL; - pos3 = NULL; - pos4 = NULL; - if (pos1 != NULL) { + pos2 = nullptr; + pos3 = nullptr; + pos4 = nullptr; + if (pos1 != nullptr) { pos2 = strchr(pos1 + 1, '"'); - if (pos2 != NULL) { + if (pos2 != nullptr) { pos3 = strchr(pos2 + 1, '"'); - if (pos3 != NULL) + if (pos3 != nullptr) pos4 = strchr(pos3 + 1, '"'); } } - if (pos4 == NULL) { - if (pos1 != NULL) + if (pos4 == nullptr) { + if (pos1 != nullptr) fprintf(DIAG_OUT, "ADOL-C warning: Malformed input line " "in .adolcrc ignored!\n"); } else { @@ -714,7 +710,7 @@ locint keep_stock() { void taylor_begin(uint bufferSize, int degreeSave) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer != nullptr) { #if defined(ADOLC_DEBUG) fprintf(DIAG_OUT, "\nADOL-C warning: !!! Taylor information for tape %d" @@ -726,16 +722,16 @@ void taylor_begin(uint bufferSize, int degreeSave) { if (numTBuffersInUse == ADOLC_GLOBAL_TAPE_VARS.maxNumberTaylorBuffers) fail(ADOLC_TAPING_TO_MANY_TAYLOR_BUFFERS); ++numTBuffersInUse; - if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName == nullptr) ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName = createFileName(ADOLC_CURRENT_TAPE_INFOS.tapeID, TAYLORS_TAPE); } /* initial setups */ - if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == nullptr) ADOLC_CURRENT_TAPE_INFOS.tayBuffer = new double[bufferSize]; - if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == nullptr) fail(ADOLC_TAPING_TBUFFER_ALLOCATION_FAILED); ADOLC_CURRENT_TAPE_INFOS.deg_save = degreeSave; if (degreeSave >= 0) @@ -758,15 +754,15 @@ void taylor_close(bool resetData) { 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.tay_file != nullptr) { 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.tay_file = nullptr; } return; } - if (ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.tay_file != nullptr) { if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors) put_tay_block(ADOLC_CURRENT_TAPE_INFOS.currTay); } else { @@ -784,7 +780,7 @@ void taylor_close(bool resetData) { ADOLC_CURRENT_TAPE_INFOS.stats[NUM_DEPENDENTS]; #if defined(ADOLC_DEBUG) - if (ADOLC_CURRENT_TAPE_INFOS.tay_file != NULL) + if (ADOLC_CURRENT_TAPE_INFOS.tay_file != nullptr) fprintf(DIAG_OUT, "\n ADOL-C debug: Taylor file of length %d bytes " "completed\n", @@ -812,7 +808,7 @@ void taylor_back(short tag, int *dep, int *ind, int *degree) { *ind = ADOLC_CURRENT_TAPE_INFOS.tay_numInds; *degree = ADOLC_CURRENT_TAPE_INFOS.deg_save; - if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.tayBuffer == nullptr) fail(ADOLC_REVERSE_NO_TAYLOR_STACK); ADOLC_CURRENT_TAPE_INFOS.nextBufferNumber = ADOLC_CURRENT_TAPE_INFOS.numTays_Tape / @@ -955,10 +951,10 @@ void put_tay_block(revreal *lastTayP1) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.tay_file == NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.tay_file == nullptr) { ADOLC_CURRENT_TAPE_INFOS.tay_file = fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.tay_fileName, "w+b"); - if (ADOLC_CURRENT_TAPE_INFOS.tay_file == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.tay_file == nullptr) fail(ADOLC_TAPING_TAYLOR_OPEN_FAILED); } number = lastTayP1 - ADOLC_CURRENT_TAPE_INFOS.tayBuffer; @@ -1098,18 +1094,18 @@ void initTapeBuffers() { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.opBuffer == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.opBuffer == nullptr) ADOLC_CURRENT_TAPE_INFOS.opBuffer = new unsigned char[ADOLC_CURRENT_TAPE_INFOS.stats[OP_BUFFER_SIZE]]; - if (ADOLC_CURRENT_TAPE_INFOS.locBuffer == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.locBuffer == nullptr) ADOLC_CURRENT_TAPE_INFOS.locBuffer = new locint[ADOLC_CURRENT_TAPE_INFOS.stats[LOC_BUFFER_SIZE]]; - if (ADOLC_CURRENT_TAPE_INFOS.valBuffer == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.valBuffer == nullptr) ADOLC_CURRENT_TAPE_INFOS.valBuffer = new double[ADOLC_CURRENT_TAPE_INFOS.stats[VAL_BUFFER_SIZE]]; - if (ADOLC_CURRENT_TAPE_INFOS.opBuffer == NULL || - ADOLC_CURRENT_TAPE_INFOS.locBuffer == NULL || - ADOLC_CURRENT_TAPE_INFOS.valBuffer == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.opBuffer == nullptr || + ADOLC_CURRENT_TAPE_INFOS.locBuffer == nullptr || + ADOLC_CURRENT_TAPE_INFOS.valBuffer == nullptr) fail(ADOLC_TAPING_BUFFER_ALLOCATION_FAILED); ADOLC_CURRENT_TAPE_INFOS.lastOpP1 = ADOLC_CURRENT_TAPE_INFOS.opBuffer + @@ -1165,7 +1161,7 @@ static void save_params() { 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) + if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore != nullptr) delete ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore; ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore = @@ -1235,7 +1231,7 @@ void stop_trace(int flag) { * "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.tay_file != nullptr) { ADOLC_CURRENT_TAPE_INFOS.stats[TAY_STACK_SIZE] /= 2; ADOLC_CURRENT_TAPE_INFOS.numTays_Tape /= 2; } @@ -1251,16 +1247,16 @@ 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 (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.op_file != nullptr) { 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) + if (ADOLC_CURRENT_TAPE_INFOS.op_file != nullptr) fclose(ADOLC_CURRENT_TAPE_INFOS.op_file); - ADOLC_CURRENT_TAPE_INFOS.op_file = NULL; + ADOLC_CURRENT_TAPE_INFOS.op_file = nullptr; ADOLC_CURRENT_TAPE_INFOS.stats[OP_FILE_ACCESS] = 1; delete ADOLC_CURRENT_TAPE_INFOS.opBuffer; - ADOLC_CURRENT_TAPE_INFOS.opBuffer = NULL; + ADOLC_CURRENT_TAPE_INFOS.opBuffer = nullptr; } else { ADOLC_CURRENT_TAPE_INFOS.numOps_Tape = ADOLC_CURRENT_TAPE_INFOS.currOp - ADOLC_CURRENT_TAPE_INFOS.opBuffer; @@ -1269,17 +1265,17 @@ void close_tape(int flag) { ADOLC_CURRENT_TAPE_INFOS.numOps_Tape; /* finish constants tape, close it, update stats */ - if (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { + if (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.val_file != nullptr) { 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) + if (ADOLC_CURRENT_TAPE_INFOS.val_file != nullptr) fclose(ADOLC_CURRENT_TAPE_INFOS.val_file); - ADOLC_CURRENT_TAPE_INFOS.val_file = NULL; + ADOLC_CURRENT_TAPE_INFOS.val_file = nullptr; ADOLC_CURRENT_TAPE_INFOS.stats[VAL_FILE_ACCESS] = 1; delete ADOLC_CURRENT_TAPE_INFOS.valBuffer; - ADOLC_CURRENT_TAPE_INFOS.valBuffer = NULL; + ADOLC_CURRENT_TAPE_INFOS.valBuffer = nullptr; } else { ADOLC_CURRENT_TAPE_INFOS.numVals_Tape = ADOLC_CURRENT_TAPE_INFOS.currVal - ADOLC_CURRENT_TAPE_INFOS.valBuffer; @@ -1288,7 +1284,7 @@ void close_tape(int flag) { 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 (flag != 0 || ADOLC_CURRENT_TAPE_INFOS.loc_file != nullptr) { if (ADOLC_CURRENT_TAPE_INFOS.currLoc != ADOLC_CURRENT_TAPE_INFOS.locBuffer) { put_loc_block(ADOLC_CURRENT_TAPE_INFOS.currLoc); @@ -1302,9 +1298,9 @@ void close_tape(int flag) { 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; + ADOLC_CURRENT_TAPE_INFOS.loc_file = nullptr; delete ADOLC_CURRENT_TAPE_INFOS.locBuffer; - ADOLC_CURRENT_TAPE_INFOS.locBuffer = NULL; + ADOLC_CURRENT_TAPE_INFOS.locBuffer = nullptr; } else { ADOLC_CURRENT_TAPE_INFOS.numLocs_Tape = ADOLC_CURRENT_TAPE_INFOS.currLoc - ADOLC_CURRENT_TAPE_INFOS.locBuffer; @@ -1318,35 +1314,35 @@ void close_tape(int flag) { /****************************************************************************/ void freeTapeResources(TapeInfos *tapeInfos) { delete tapeInfos->opBuffer; - tapeInfos->opBuffer = NULL; + tapeInfos->opBuffer = nullptr; delete tapeInfos->locBuffer; - tapeInfos->locBuffer = NULL; + tapeInfos->locBuffer = nullptr; delete tapeInfos->valBuffer; - tapeInfos->valBuffer = NULL; - if (tapeInfos->tayBuffer != NULL) { + tapeInfos->valBuffer = nullptr; + if (tapeInfos->tayBuffer != nullptr) { delete tapeInfos->tayBuffer; - tapeInfos->tayBuffer = NULL; + tapeInfos->tayBuffer = nullptr; --numTBuffersInUse; } - if (tapeInfos->op_file != NULL) { + if (tapeInfos->op_file != nullptr) { fclose(tapeInfos->op_file); - tapeInfos->op_file = NULL; + tapeInfos->op_file = nullptr; } - if (tapeInfos->loc_file != NULL) { + if (tapeInfos->loc_file != nullptr) { fclose(tapeInfos->loc_file); - tapeInfos->loc_file = NULL; + tapeInfos->loc_file = nullptr; } - if (tapeInfos->val_file != NULL) { + if (tapeInfos->val_file != nullptr) { fclose(tapeInfos->val_file); - tapeInfos->val_file = NULL; + tapeInfos->val_file = nullptr; } - if (tapeInfos->tay_file != NULL) { + if (tapeInfos->tay_file != nullptr) { fclose(tapeInfos->tay_file); - tapeInfos->tay_file = NULL; + tapeInfos->tay_file = nullptr; } - if (tapeInfos->signature != NULL) { + if (tapeInfos->signature != nullptr) { free(tapeInfos->signature); - tapeInfos->signature = NULL; + tapeInfos->signature = nullptrptr; } } @@ -1428,13 +1424,13 @@ 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; + double *valBuffer = nullptr, *currVal = nullptr, *lastValP1 = nullptr; size_t np, ip, avail, rsize; - if (tapeInfos->pTapeInfos.paramstore == NULL) + if (tapeInfos->pTapeInfos.paramstore == nullptr) tapeInfos->pTapeInfos.paramstore = new double[tapeInfos->stats[NUM_PARAM]]; valBuffer = new double[tapeInfos->stats[VAL_BUFFER_SIZE]]; lastValP1 = valBuffer + tapeInfos->stats[VAL_BUFFER_SIZE]; - if ((val_file = fopen(tapeInfos->pTapeInfos.val_fileName, "rb")) == NULL) + if ((val_file = fopen(tapeInfos->pTapeInfos.val_fileName, "rb")) == nullptr) fail(ADOLC_VALUE_TAPE_FOPEN_FAILED); number = (tapeInfos->stats[NUM_VALUES] / tapeInfos->stats[VAL_BUFFER_SIZE]) * tapeInfos->stats[VAL_BUFFER_SIZE]; @@ -1508,7 +1504,7 @@ void set_param_vec(short tag, size_t numparam, revreal *paramvec) { tag, numparam, ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]); adolc_exit(-1, "", __func__, __FILE__, __LINE__); } - if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore == NULL) + if (ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore == nullptr) ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.paramstore = new double[ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]]; for (i = 0; i < ADOLC_CURRENT_TAPE_INFOS.stats[NUM_PARAM]; i++) @@ -1531,7 +1527,7 @@ void read_tape_stats(TapeInfos *tapeInfos) { 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) + if ((loc_file = fopen(tapeInfos->pTapeInfos.loc_fileName, "rb")) == nullptr) fail(ADOLC_INTEGER_TAPE_FOPEN_FAILED); if (fread(&tape_ADOLC_ID, sizeof(ADOLC_ID), 1, loc_file) != 1) fail(ADOLC_INTEGER_TAPE_FREAD_FAILED); @@ -1807,17 +1803,17 @@ void init_rev_sweep(short tag) { void end_sweep() { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.op_file != nullptr) { fclose(ADOLC_CURRENT_TAPE_INFOS.op_file); - ADOLC_CURRENT_TAPE_INFOS.op_file = NULL; + ADOLC_CURRENT_TAPE_INFOS.op_file = nullptr; } - if (ADOLC_CURRENT_TAPE_INFOS.loc_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.loc_file != nullptr) { fclose(ADOLC_CURRENT_TAPE_INFOS.loc_file); - ADOLC_CURRENT_TAPE_INFOS.loc_file = NULL; + ADOLC_CURRENT_TAPE_INFOS.loc_file = nullptr; } - if (ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.val_file != nullptr) { fclose(ADOLC_CURRENT_TAPE_INFOS.val_file); - ADOLC_CURRENT_TAPE_INFOS.val_file = NULL; + ADOLC_CURRENT_TAPE_INFOS.val_file = nullptr; } if (ADOLC_CURRENT_TAPE_INFOS.deg_save > 0) releaseTape(); /* keep value stack */ @@ -1899,16 +1895,16 @@ void put_op_block(unsigned char *lastOpP1) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.op_file == NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.op_file == nullptr) { ADOLC_CURRENT_TAPE_INFOS.op_file = fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName, "rb"); - if (ADOLC_CURRENT_TAPE_INFOS.op_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.op_file != nullptr) { #if defined(ADOLC_DEBUG) 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; + ADOLC_CURRENT_TAPE_INFOS.op_file = nullptr; if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.op_fileName)) fprintf(DIAG_OUT, "ADOL-C warning: " "Unable to remove old tapefile\n"); @@ -2011,16 +2007,16 @@ void put_loc_block(locint *lastLocP1) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.loc_file == NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.loc_file == nullptr) { ADOLC_CURRENT_TAPE_INFOS.loc_file = fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName, "rb"); - if (ADOLC_CURRENT_TAPE_INFOS.loc_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.loc_file != nullptr) { #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; + ADOLC_CURRENT_TAPE_INFOS.loc_file = nullptr; if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.loc_fileName)) fprintf(DIAG_OUT, "ADOL-C warning: " "Unable to remove old tapefile!\n"); @@ -2167,16 +2163,16 @@ void put_val_block(double *lastValP1) { ADOLC_OPENMP_THREAD_NUMBER; ADOLC_OPENMP_GET_THREAD_NUMBER; - if (ADOLC_CURRENT_TAPE_INFOS.val_file == NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.val_file == nullptr) { ADOLC_CURRENT_TAPE_INFOS.val_file = fopen(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName, "rb"); - if (ADOLC_CURRENT_TAPE_INFOS.val_file != NULL) { + if (ADOLC_CURRENT_TAPE_INFOS.val_file != nullptr) { #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; + ADOLC_CURRENT_TAPE_INFOS.val_file = nullptr; if (remove(ADOLC_CURRENT_TAPE_INFOS.pTapeInfos.val_fileName)) fprintf(DIAG_OUT, "ADOL-C warning: " "Unable to remove old tapefile\n"); From 7bde580f2aa89cecb31d76a9b45c7d08262559fd Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:23:58 +0100 Subject: [PATCH 37/69] fix typo --- ADOL-C/src/taping.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADOL-C/src/taping.cpp b/ADOL-C/src/taping.cpp index b300c913e..251453373 100644 --- a/ADOL-C/src/taping.cpp +++ b/ADOL-C/src/taping.cpp @@ -1342,7 +1342,7 @@ void freeTapeResources(TapeInfos *tapeInfos) { } if (tapeInfos->signature != nullptr) { free(tapeInfos->signature); - tapeInfos->signature = nullptrptr; + tapeInfos->signature = nullptr; } } From 11b9cc74c429dce66e86bfc1d650b0aee50c51bb Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 17:32:44 +0100 Subject: [PATCH 38/69] replace the header with stddef which includes size_t definition --- ADOL-C/include/adolc/internal/adolc_settings.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADOL-C/include/adolc/internal/adolc_settings.h.in b/ADOL-C/include/adolc/internal/adolc_settings.h.in index ec9795861..73c22163f 100644 --- a/ADOL-C/include/adolc/internal/adolc_settings.h.in +++ b/ADOL-C/include/adolc/internal/adolc_settings.h.in @@ -18,7 +18,7 @@ #if !defined(ADOLC_ADOLC_SETTINGS_H) #define ADOLC_ADOLC_SETTINGS_H 1 -#include +#include /*--------------------------------------------------------------------------*/ /* ADOL-C data types */ From ece1dafbe43c22095072ad628f2bffc1a0206fe3 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 20:50:18 +0100 Subject: [PATCH 39/69] use right type in format --- ADOL-C/src/storemanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADOL-C/src/storemanager.cpp b/ADOL-C/src/storemanager.cpp index 45c373258..ceb9ef026 100644 --- a/ADOL-C/src/storemanager.cpp +++ b/ADOL-C/src/storemanager.cpp @@ -455,7 +455,7 @@ void StoreManagerLocintBlock::grow(size_t minGrow) { // encapsulate this error message fprintf(DIAG_OUT, "\nADOL-C error:\n"); fprintf(DIAG_OUT, - "maximal number (%u) of live active variables exceeded\n\n", + "maximal number (%zu) of live active variables exceeded\n\n", std::numeric_limits::max()); adolc_exit(-3, "", __func__, __FILE__, __LINE__); } From 8d9cac4b5d90de79d5cf621c7e8177bb7540b177 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 20:53:32 +0100 Subject: [PATCH 40/69] rename to cpp --- ADOL-C/src/CMakeLists.txt | 4 ++-- ADOL-C/src/{adalloc.c => adalloc.cpp} | 2 +- ADOL-C/src/{convolut.c => convolut.cpp} | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename ADOL-C/src/{adalloc.c => adalloc.cpp} (99%) rename ADOL-C/src/{convolut.c => convolut.cpp} (99%) diff --git a/ADOL-C/src/CMakeLists.txt b/ADOL-C/src/CMakeLists.txt index d405e7ca6..0fc3fcc9a 100644 --- a/ADOL-C/src/CMakeLists.txt +++ b/ADOL-C/src/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(adolc PRIVATE - adalloc.c + adalloc.cpp adouble.cpp adouble_tl.cpp adouble_tl_hov.cpp @@ -8,7 +8,7 @@ target_sources(adolc PRIVATE ampisupport.cpp ampisupportAdolc.cpp checkpointing.cpp - convolut.c + convolut.cpp externfcts.cpp externfcts2.cpp fixpoint.cpp diff --git a/ADOL-C/src/adalloc.c b/ADOL-C/src/adalloc.cpp similarity index 99% rename from ADOL-C/src/adalloc.c rename to ADOL-C/src/adalloc.cpp index d79a4c15c..6e3ef332f 100644 --- a/ADOL-C/src/adalloc.c +++ b/ADOL-C/src/adalloc.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: adalloc.c + File: adalloc.cpp Revision: $Id$ Contents: C allocation of arrays of doubles in several dimensions diff --git a/ADOL-C/src/convolut.c b/ADOL-C/src/convolut.cpp similarity index 99% rename from ADOL-C/src/convolut.c rename to ADOL-C/src/convolut.cpp index 993feb161..34f5b97b6 100644 --- a/ADOL-C/src/convolut.c +++ b/ADOL-C/src/convolut.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: convolute.c + File: convolute.cpp Revision: $Id$ Contents: Convolution routines (used by ho_rev.mc) From 45af1ab0acd236f3aa7e9a97605f21e80e297fdb Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sun, 22 Dec 2024 21:17:45 +0100 Subject: [PATCH 41/69] change to cpp --- ADOL-C/include/adolc/interfaces.h | 6 +++--- ADOL-C/src/CMakeLists.txt | 10 +++++----- ADOL-C/src/drivers/CMakeLists.txt | 14 +++++++------- ADOL-C/src/drivers/{drivers.c => drivers.cpp} | 2 +- ADOL-C/src/drivers/{driversf.c => driversf.cpp} | 2 +- .../src/drivers/{odedrivers.c => odedrivers.cpp} | 2 +- .../src/drivers/{odedriversf.c => odedriversf.cpp} | 2 +- ADOL-C/src/drivers/{psdrivers.c => psdrivers.cpp} | 4 +++- .../src/drivers/{psdriversf.c => psdriversf.cpp} | 2 +- ADOL-C/src/drivers/{taylor.c => taylor.cpp} | 4 ++-- ADOL-C/src/{fortutils.c => fortutils.cpp} | 2 +- ADOL-C/src/{forward_partx.c => forward_partx.cpp} | 2 +- ADOL-C/src/{interfacesf.c => interfacesf.cpp} | 2 +- ADOL-C/src/lie/{adolc_lie_c.c => adolc_lie_c.cpp} | 6 +++--- ADOL-C/src/{revolve.c => revolve.cpp} | 2 +- ADOL-C/src/{rpl_malloc.c => rpl_malloc.cpp} | 0 ADOL-C/src/tapedoc/{tapedoc.c => tapedoc.cpp} | 0 17 files changed, 32 insertions(+), 30 deletions(-) rename ADOL-C/src/drivers/{drivers.c => drivers.cpp} (99%) rename ADOL-C/src/drivers/{driversf.c => driversf.cpp} (99%) rename ADOL-C/src/drivers/{odedrivers.c => odedrivers.cpp} (99%) rename ADOL-C/src/drivers/{odedriversf.c => odedriversf.cpp} (98%) rename ADOL-C/src/drivers/{psdrivers.c => psdrivers.cpp} (99%) rename ADOL-C/src/drivers/{psdriversf.c => psdriversf.cpp} (98%) rename ADOL-C/src/drivers/{taylor.c => taylor.cpp} (99%) rename ADOL-C/src/{fortutils.c => fortutils.cpp} (98%) rename ADOL-C/src/{forward_partx.c => forward_partx.cpp} (99%) rename ADOL-C/src/{interfacesf.c => interfacesf.cpp} (99%) rename ADOL-C/src/lie/{adolc_lie_c.c => adolc_lie_c.cpp} (99%) rename ADOL-C/src/{revolve.c => revolve.cpp} (99%) rename ADOL-C/src/{rpl_malloc.c => rpl_malloc.cpp} (100%) rename ADOL-C/src/tapedoc/{tapedoc.c => tapedoc.cpp} (100%) diff --git a/ADOL-C/include/adolc/interfaces.h b/ADOL-C/include/adolc/interfaces.h index 6fc2c8f28..7ab5210b4 100644 --- a/ADOL-C/include/adolc/interfaces.h +++ b/ADOL-C/include/adolc/interfaces.h @@ -22,8 +22,8 @@ hov_reverse.cpp hos_ti_reverse.cpp hov_ti_reverse.cpp - interfacesC.C - interfacesf.c + interfacesc.cpp + interfacesf.cpp ADOL-C Abbreviations : zos : zero-order-scalar mode @@ -226,7 +226,7 @@ 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) */ +/* (defined in forward_partx.cpp) */ ADOLC_DLL_EXPORT int hos_forward_partx(short, int, int, int *, int, double ***, double **); diff --git a/ADOL-C/src/CMakeLists.txt b/ADOL-C/src/CMakeLists.txt index 0fc3fcc9a..425a9740a 100644 --- a/ADOL-C/src/CMakeLists.txt +++ b/ADOL-C/src/CMakeLists.txt @@ -12,8 +12,8 @@ target_sources(adolc PRIVATE externfcts.cpp externfcts2.cpp fixpoint.cpp - fortutils.c - forward_partx.c + fortutils.cpp + forward_partx.cpp fos_forward.cpp fos_pl_forward.cpp fos_pl_reverse.cpp @@ -39,15 +39,15 @@ target_sources(adolc PRIVATE int_reverse_s.cpp int_reverse_t.cpp interfaces.cpp - interfacesf.c + interfacesf.cpp medipacksupport.cpp nonl_ind_forward_s.cpp nonl_ind_forward_t.cpp nonl_ind_old_forward_s.cpp nonl_ind_old_forward_t.cpp param.cpp - revolve.c - rpl_malloc.c + revolve.cpp + rpl_malloc.cpp storemanager.cpp tape_handling.cpp taping.cpp diff --git a/ADOL-C/src/drivers/CMakeLists.txt b/ADOL-C/src/drivers/CMakeLists.txt index 2872af148..d366b8b1c 100644 --- a/ADOL-C/src/drivers/CMakeLists.txt +++ b/ADOL-C/src/drivers/CMakeLists.txt @@ -1,9 +1,9 @@ target_sources(adolc PRIVATE - drivers.c - driversf.c - odedrivers.c - odedriversf.c - psdrivers.c - psdriversf.c - taylor.c + drivers.cpp + driversf.cpp + odedrivers.cpp + odedriversf.cpp + psdrivers.cpp + psdriversf.cpp + taylor.cpp ) diff --git a/ADOL-C/src/drivers/drivers.c b/ADOL-C/src/drivers/drivers.cpp similarity index 99% rename from ADOL-C/src/drivers/drivers.c rename to ADOL-C/src/drivers/drivers.cpp index 0d942fc77..3c1c1549d 100644 --- a/ADOL-C/src/drivers/drivers.c +++ b/ADOL-C/src/drivers/drivers.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: drivers/drivers.c + File: drivers/drivers.cpp Revision: $Id$ Contents: Easy to use drivers for optimization and nonlinear equations (Implementation of the C/C++ callable interfaces). diff --git a/ADOL-C/src/drivers/driversf.c b/ADOL-C/src/drivers/driversf.cpp similarity index 99% rename from ADOL-C/src/drivers/driversf.c rename to ADOL-C/src/drivers/driversf.cpp index 52e79cc4f..57c52495e 100644 --- a/ADOL-C/src/drivers/driversf.c +++ b/ADOL-C/src/drivers/driversf.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: drivers/driversf.c + File: drivers/driversf.cpp Revision: $Id$ Contents: Easy to use drivers for optimization and nonlinear equations (Implementation of the Fortran callable interfaces). diff --git a/ADOL-C/src/drivers/odedrivers.c b/ADOL-C/src/drivers/odedrivers.cpp similarity index 99% rename from ADOL-C/src/drivers/odedrivers.c rename to ADOL-C/src/drivers/odedrivers.cpp index 85c5d854d..24fe207a3 100644 --- a/ADOL-C/src/drivers/odedrivers.c +++ b/ADOL-C/src/drivers/odedrivers.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: drivers/odedrivers.c + File: drivers/odedrivers.cpp Revision: $Id$ Contents: Easy to use drivers for ordinary differential equations (ODE) (with C and C++ callable interfaces including Fortran diff --git a/ADOL-C/src/drivers/odedriversf.c b/ADOL-C/src/drivers/odedriversf.cpp similarity index 98% rename from ADOL-C/src/drivers/odedriversf.c rename to ADOL-C/src/drivers/odedriversf.cpp index ec4a5256d..6894e519c 100644 --- a/ADOL-C/src/drivers/odedriversf.c +++ b/ADOL-C/src/drivers/odedriversf.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: drivers/odedriversf.c + File: drivers/odedriversf.cpp Revision: $Id$ Contents: Easy to use drivers for optimization and nonlinear equations (Implementation of the Fortran callable interfaces). diff --git a/ADOL-C/src/drivers/psdrivers.c b/ADOL-C/src/drivers/psdrivers.cpp similarity index 99% rename from ADOL-C/src/drivers/psdrivers.c rename to ADOL-C/src/drivers/psdrivers.cpp index e7ca9fdc3..fd75ade79 100644 --- a/ADOL-C/src/drivers/psdrivers.c +++ b/ADOL-C/src/drivers/psdrivers.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: drivers/psdrivers.c + File: drivers/psdrivers.cpp Revision: $Id$ Contents: Easy to use drivers for piecewise smooth functions (with C and C++ callable interfaces including Fortran @@ -167,3 +167,5 @@ int directional_active_gradient(short tag, /* trace identifier */ return 0; } + +END_C_DECLS \ No newline at end of file diff --git a/ADOL-C/src/drivers/psdriversf.c b/ADOL-C/src/drivers/psdriversf.cpp similarity index 98% rename from ADOL-C/src/drivers/psdriversf.c rename to ADOL-C/src/drivers/psdriversf.cpp index 6e66f1c13..eba59e65c 100644 --- a/ADOL-C/src/drivers/psdriversf.c +++ b/ADOL-C/src/drivers/psdriversf.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: drivers/psdrivers.c + File: drivers/psdrivers.cpp Revision: $Id$ Contents: Easy to use drivers for piecewise smooth functions (with C and C++ callable interfaces including Fortran diff --git a/ADOL-C/src/drivers/taylor.c b/ADOL-C/src/drivers/taylor.cpp similarity index 99% rename from ADOL-C/src/drivers/taylor.c rename to ADOL-C/src/drivers/taylor.cpp index 71e899fed..a41dc6253 100644 --- a/ADOL-C/src/drivers/taylor.c +++ b/ADOL-C/src/drivers/taylor.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: drivers/taylor.c + File: drivers/taylor.cpp Revision: $Id$ Contents: Easy to use drivers for the evaluation of higher order derivative tensors and inverse/impicit function differentiation @@ -513,7 +513,7 @@ int jac_solv(unsigned short tag, int n, const double *x, double *b, 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; + double bi; static double **Xhelp; static double **W; static double *xold; diff --git a/ADOL-C/src/fortutils.c b/ADOL-C/src/fortutils.cpp similarity index 98% rename from ADOL-C/src/fortutils.c rename to ADOL-C/src/fortutils.cpp index 1d6184383..03aef28e5 100644 --- a/ADOL-C/src/fortutils.c +++ b/ADOL-C/src/fortutils.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: fortutils.c + File: fortutils.cpp Revision: $Id$ Contents: Internal tools to handle Fortran arrays diff --git a/ADOL-C/src/forward_partx.c b/ADOL-C/src/forward_partx.cpp similarity index 99% rename from ADOL-C/src/forward_partx.c rename to ADOL-C/src/forward_partx.cpp index d5e239afb..a8e6df2a1 100644 --- a/ADOL-C/src/forward_partx.c +++ b/ADOL-C/src/forward_partx.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: forward_partx.c + File: forward_partx.cpp Revision: $Id$ Contents: diff --git a/ADOL-C/src/interfacesf.c b/ADOL-C/src/interfacesf.cpp similarity index 99% rename from ADOL-C/src/interfacesf.c rename to ADOL-C/src/interfacesf.cpp index fa79c8b6a..df1f8ab6c 100644 --- a/ADOL-C/src/interfacesf.c +++ b/ADOL-C/src/interfacesf.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: interfacesf.c + File: interfacesf.cpp Revision: $Id$ Contents: Genuine Fortran callable C Interfaces to ADOL-C forward & reverse calls. diff --git a/ADOL-C/src/lie/adolc_lie_c.c b/ADOL-C/src/lie/adolc_lie_c.cpp similarity index 99% rename from ADOL-C/src/lie/adolc_lie_c.c rename to ADOL-C/src/lie/adolc_lie_c.cpp index 4a482d7bc..72af2e8ff 100644 --- a/ADOL-C/src/lie/adolc_lie_c.c +++ b/ADOL-C/src/lie/adolc_lie_c.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: lie/adolc_lie_c.c + File: lie/adolc_lie_c.cpp Revision: $Id$ Contents: Implementation of functions for computation of Lie derivatives @@ -300,7 +300,7 @@ int lie_gradientcv(short Tape_F, short Tape_H, short n, short m, double *x0, 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 */ + accodec(n, 1.0, d - 1, A, B, 0); /* explanation in odedrivers.cpp */ /* prepare for input */ for (i = 0; i < n; i++) { @@ -444,7 +444,7 @@ int lie_covector(short int Tape_F, short int Tape_W, short int n, double *x0, Y[i][0] = y[i]; } - accodec(n, 1.0, d - 1, A, B, 0); /* explanation in odedrivers.c */ + accodec(n, 1.0, d - 1, A, B, 0); /* explanation in odedrivers.cpp */ acccov(n, d, B, Y, result); myfree2(X); diff --git a/ADOL-C/src/revolve.c b/ADOL-C/src/revolve.cpp similarity index 99% rename from ADOL-C/src/revolve.c rename to ADOL-C/src/revolve.cpp index 7f41d2e88..3c324b87a 100644 --- a/ADOL-C/src/revolve.c +++ b/ADOL-C/src/revolve.cpp @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------- ADOL-C -- Automatic Differentiation by Overloading in C++ - File: revolve.c + File: revolve.cpp Revision: $Id$ Contents: optimal binomial checkpointing adapted for ADOL-C diff --git a/ADOL-C/src/rpl_malloc.c b/ADOL-C/src/rpl_malloc.cpp similarity index 100% rename from ADOL-C/src/rpl_malloc.c rename to ADOL-C/src/rpl_malloc.cpp diff --git a/ADOL-C/src/tapedoc/tapedoc.c b/ADOL-C/src/tapedoc/tapedoc.cpp similarity index 100% rename from ADOL-C/src/tapedoc/tapedoc.c rename to ADOL-C/src/tapedoc/tapedoc.cpp From 2acf48cf731588143b19ba02509c332d37659f33 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Tue, 24 Dec 2024 11:37:26 +0100 Subject: [PATCH 42/69] change to nullptr --- ADOL-C/src/taping.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADOL-C/src/taping.cpp b/ADOL-C/src/taping.cpp index 251453373..4250c8269 100644 --- a/ADOL-C/src/taping.cpp +++ b/ADOL-C/src/taping.cpp @@ -355,7 +355,7 @@ void printError() { } /* the base names of every tape type */ -char *tapeBaseNames[4] = {0, 0, 0, 0}; +char *tapeBaseNames[4] = {nullptr, nullptr, nullptr, nullptr}; void clearTapeBaseNames() { int i; From 3dccda35064be94f496db7d549c6a9724635df42 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 2 Jan 2025 10:34:47 +0100 Subject: [PATCH 43/69] change structure --- ADOL-C/boost-test/CMakeLists.txt | 6 +- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 341 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 342 ++++++++++++++++++ ADOL-C/boost-test/{ => uni5_for}/uni5_for.cpp | 2 +- 4 files changed, 689 insertions(+), 2 deletions(-) create mode 100644 ADOL-C/boost-test/uni5_for/hov_forward.cpp create mode 100644 ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp rename ADOL-C/boost-test/{ => uni5_for}/uni5_for.cpp (99%) diff --git a/ADOL-C/boost-test/CMakeLists.txt b/ADOL-C/boost-test/CMakeLists.txt index 137d40de2..c07223e04 100644 --- a/ADOL-C/boost-test/CMakeLists.txt +++ b/ADOL-C/boost-test/CMakeLists.txt @@ -25,8 +25,12 @@ set(SOURCE_FILES traceSecOrderScalar.cpp traceSecOrderVector.cpp traceFixedPointScalarTests.cpp - uni5_for.cpp ) + +# Add all source files from uni5_for +file(GLOB UNI5_FOR_FILES "uni5_for/*.cpp") +list(APPEND SOURCE_FILES ${UNI5_FOR_FILES}) + add_executable(boost-test-adolc ${SOURCE_FILES}) target_include_directories(boost-test-adolc PRIVATE "${ADOLC_INCLUDE_DIR}") target_link_libraries(boost-test-adolc PRIVATE diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp new file mode 100644 index 000000000..d4ca8dbb9 --- /dev/null +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -0,0 +1,341 @@ + +/* +File for explicit testing functions from uni5_for.cpp file. +*/ + +#define BOOST_TEST_DYN_LINK +#include + +namespace tt = boost::test_tools; + +#include + +#include "../const.h" + +#include +#include +#include + +BOOST_AUTO_TEST_SUITE(test_hov_forward) +BOOST_AUTO_TEST_CASE(FmaxOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 2; + const size_t num_dirs = 3; + std::vector in{4.0, 3.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + trace_on(tag); + std::for_each(in.begin(), in.end(), [&, i = 0](int value) mutable { + indep[i] <<= in[i]; + i++; + }); + + // max(x^2, y^3) + adouble dep = fmax(pow(indep[0], 2), pow(indep[1], 3)); + + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[1][0][0] = 1.9; + + X[0][1][0] = 2.0; + X[1][1][0] = 3.0; + + X[0][2][0] = 1.0; + X[1][2][0] = -1.0; + + X[0][0][1] = -1.0; + X[1][0][1] = 1.0; + + X[0][1][1] = -2.0; + X[1][1][1] = -3.0; + + X[0][2][1] = -1.0; + X[1][2][1] = 1.0; + + /**************************** + TEST A < B + *****************************/ + std::vector test_in{4.0, 3.2}; + // max(x^2, y^3) + double test_out = std::fmax(std::pow(test_in[0], 2), std::pow(test_in[1], 3)); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + BOOST_TEST(Y[0][0][0] == 3 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 3 * std::pow(test_in[1], 2) * X[1][1][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][0] == 3 * std::pow(test_in[1], 2) * X[1][2][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][0][0] * X[1][0][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][0][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][1][0] * X[1][1][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][1][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][2][0] * X[1][2][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][2][1], + tt::tolerance(tol)); + + /************************** + TEST A > B + ***************************/ + + // test_in[0] = 4.0 + test_in[1] = 1.0; + // max(x^2, y^3) + test_out = std::fmax(std::pow(test_in[0], 2), std::pow(test_in[1], 3)); + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + BOOST_TEST(Y[0][0][0] == 2 * test_in[0] * X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2 * test_in[0] * X[0][1][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][2][0] == 2 * test_in[0] * X[0][2][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == 1.0 / 2.0 * 2.0 * X[0][0][0] * X[0][0][0] + + 2.0 * test_in[0] * X[0][0][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / 2.0 * 2.0 * X[0][1][0] * X[0][1][0] + + 2.0 * test_in[0] * X[0][1][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == 1.0 / 2.0 * 2.0 * X[0][2][0] * X[0][2][0] + + 2.0 * test_in[0] * X[0][2][1], + tt::tolerance(tol)); + + /************************** + TEST A == B + ***************************/ + + test_in[0] = 1.0; + test_in[1] = 1.0; + + // max(x^2, y^3) + test_out = std::fmax(std::pow(test_in[0], 2), std::pow(test_in[1], 3)); + + // A < B + X[0][0][0] = 1.0; + X[1][0][0] = 1.9; + + // A > B + X[0][1][0] = 3.0; + X[1][1][0] = 2.0; + + // A == B + X[0][2][0] = 1.0; + X[1][2][0] = 1.0; + + X[0][0][1] = -1.0; + X[1][0][1] = 1.0; + + X[0][1][1] = -2.0; + X[1][1][1] = -3.0; + + // A < B + X[0][2][1] = 1.0; + X[1][2][1] = 2.0; + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // A < B + BOOST_TEST(Y[0][0][0] == 3 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][0][0] * X[1][0][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][0][1], + tt::tolerance(tol)); + + // A < B + BOOST_TEST(Y[0][1][0] == 2 * test_in[0] * X[0][1][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / 2.0 * 2.0 * X[0][1][0] * X[0][1][0] + + 2.0 * test_in[0] * X[0][1][1], + tt::tolerance(tol)); + + // A == B, A < B + BOOST_TEST(Y[0][2][0] == 3 * std::pow(test_in[1], 2) * X[1][2][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][2][0] * X[1][2][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][2][1], + tt::tolerance(tol)); + + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(FminOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 2; + const size_t num_dirs = 3; + const short keep = 1; + std::vector in{4.0, 3.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + trace_on(tag); + std::for_each(in.begin(), in.end(), [&, i = 0](int value) mutable { + indep[i] <<= in[i]; + i++; + }); + + // max(x^2, y^3) + adouble dep = fmin(-pow(indep[0], 2), -pow(indep[1], 3)); + + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[1][0][0] = 1.9; + + X[0][1][0] = 2.0; + X[1][1][0] = 3.0; + + X[0][2][0] = 1.0; + X[1][2][0] = -1.0; + + X[0][0][1] = -1.0; + X[1][0][1] = 1.0; + + X[0][1][1] = -2.0; + X[1][1][1] = -3.0; + + X[0][2][1] = -1.0; + X[1][2][1] = 1.0; + + /**************************** + TEST A < B + *****************************/ + std::vector test_in{4.0, 3.2}; + // max(x^2, y^3) + double test_out = + std::fmin(-std::pow(test_in[0], 2), -std::pow(test_in[1], 3)); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + BOOST_TEST(Y[0][0][0] == -3 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == -3 * std::pow(test_in[1], 2) * X[1][1][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][0] == -3 * std::pow(test_in[1], 2) * X[1][2][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][0][0] * X[1][0][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][0][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][1][0] * X[1][1][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][1][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][2][0] * X[1][2][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][2][1], + tt::tolerance(tol)); + + /************************** + TEST A > B + ***************************/ + + // test_in[0] = 4.0 + test_in[1] = 1.0; + // max(x^2, y^3) + test_out = std::fmin(-std::pow(test_in[0], 2), -std::pow(test_in[1], 3)); + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + BOOST_TEST(Y[0][0][0] == -2 * test_in[0] * X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == -2 * test_in[0] * X[0][1][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][2][0] == -2 * test_in[0] * X[0][2][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == -1.0 / 2.0 * 2.0 * X[0][0][0] * X[0][0][0] - + 2.0 * test_in[0] * X[0][0][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == -1.0 / 2.0 * 2.0 * X[0][1][0] * X[0][1][0] - + 2.0 * test_in[0] * X[0][1][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == -1.0 / 2.0 * 2.0 * X[0][2][0] * X[0][2][0] - + 2.0 * test_in[0] * X[0][2][1], + tt::tolerance(tol)); + + /************************** + TEST A == B + ***************************/ + + test_in[0] = 1.0; + test_in[1] = 1.0; + + // max(x^2, y^3) + test_out = std::fmin(-std::pow(test_in[0], 2), -std::pow(test_in[1], 3)); + + // A < B + X[0][0][0] = 1.0; + X[1][0][0] = 1.9; + + // A > B + X[0][1][0] = 3.0; + X[1][1][0] = 2.0; + + // A == B + X[0][2][0] = 1.0; + X[1][2][0] = 1.0; + + X[0][0][1] = -1.0; + X[1][0][1] = 1.0; + + X[0][1][1] = -2.0; + X[1][1][1] = -3.0; + + // A < B + X[0][2][1] = 1.0; + X[1][2][1] = 2.0; + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // A < B + BOOST_TEST(Y[0][0][0] == -3 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][0][0] * X[1][0][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][0][1], + tt::tolerance(tol)); + + // A < B + BOOST_TEST(Y[0][1][0] == -2 * test_in[0] * X[0][1][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == -1.0 / 2.0 * 2.0 * X[0][1][0] * X[0][1][0] - + 2.0 * test_in[0] * X[0][1][1], + tt::tolerance(tol)); + + // A == B, A < B + BOOST_TEST(Y[0][2][0] == -3 * std::pow(test_in[1], 2) * X[1][2][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][2][0] * X[1][2][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][2][1], + tt::tolerance(tol)); + + myfree3(X); + myfree3(Y); +} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp new file mode 100644 index 000000000..f4cd9af80 --- /dev/null +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -0,0 +1,342 @@ + +/* +File for explicit testing functions from uni5_for.cpp file. +*/ + +#define BOOST_TEST_DYN_LINK +#include + +namespace tt = boost::test_tools; + +#include + +#include "../const.h" + +#include +#include +#include + +BOOST_AUTO_TEST_SUITE(test_hov_wk_forward) +BOOST_AUTO_TEST_CASE(FmaxOperator_HOV_WK_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 2; + const size_t num_dirs = 3; + const short keep = 1; + std::vector in{4.0, 3.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + trace_on(tag); + std::for_each(in.begin(), in.end(), [&, i = 0](int value) mutable { + indep[i] <<= in[i]; + i++; + }); + + // max(x^2, y^3) + adouble dep = fmax(pow(indep[0], 2), pow(indep[1], 3)); + + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[1][0][0] = 1.9; + + X[0][1][0] = 2.0; + X[1][1][0] = 3.0; + + X[0][2][0] = 1.0; + X[1][2][0] = -1.0; + + X[0][0][1] = -1.0; + X[1][0][1] = 1.0; + + X[0][1][1] = -2.0; + X[1][1][1] = -3.0; + + X[0][2][1] = -1.0; + X[1][2][1] = 1.0; + + /**************************** + TEST A < B + *****************************/ + std::vector test_in{4.0, 3.2}; + // max(x^2, y^3) + double test_out = std::fmax(std::pow(test_in[0], 2), std::pow(test_in[1], 3)); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + BOOST_TEST(Y[0][0][0] == 3 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 3 * std::pow(test_in[1], 2) * X[1][1][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][0] == 3 * std::pow(test_in[1], 2) * X[1][2][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][0][0] * X[1][0][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][0][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][1][0] * X[1][1][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][1][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][2][0] * X[1][2][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][2][1], + tt::tolerance(tol)); + + /************************** + TEST A > B + ***************************/ + + // test_in[0] = 4.0 + test_in[1] = 1.0; + // max(x^2, y^3) + test_out = std::fmax(std::pow(test_in[0], 2), std::pow(test_in[1], 3)); + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + BOOST_TEST(Y[0][0][0] == 2 * test_in[0] * X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2 * test_in[0] * X[0][1][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][2][0] == 2 * test_in[0] * X[0][2][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == 1.0 / 2.0 * 2.0 * X[0][0][0] * X[0][0][0] + + 2.0 * test_in[0] * X[0][0][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / 2.0 * 2.0 * X[0][1][0] * X[0][1][0] + + 2.0 * test_in[0] * X[0][1][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == 1.0 / 2.0 * 2.0 * X[0][2][0] * X[0][2][0] + + 2.0 * test_in[0] * X[0][2][1], + tt::tolerance(tol)); + + /************************** + TEST A == B + ***************************/ + + test_in[0] = 1.0; + test_in[1] = 1.0; + + // max(x^2, y^3) + test_out = std::fmax(std::pow(test_in[0], 2), std::pow(test_in[1], 3)); + + // A < B + X[0][0][0] = 1.0; + X[1][0][0] = 1.9; + + // A > B + X[0][1][0] = 3.0; + X[1][1][0] = 2.0; + + // A == B + X[0][2][0] = 1.0; + X[1][2][0] = 1.0; + + X[0][0][1] = -1.0; + X[1][0][1] = 1.0; + + X[0][1][1] = -2.0; + X[1][1][1] = -3.0; + + // A < B + X[0][2][1] = 1.0; + X[1][2][1] = 2.0; + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // A < B + BOOST_TEST(Y[0][0][0] == 3 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][0][0] * X[1][0][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][0][1], + tt::tolerance(tol)); + + // A < B + BOOST_TEST(Y[0][1][0] == 2 * test_in[0] * X[0][1][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / 2.0 * 2.0 * X[0][1][0] * X[0][1][0] + + 2.0 * test_in[0] * X[0][1][1], + tt::tolerance(tol)); + + // A == B, A < B + BOOST_TEST(Y[0][2][0] == 3 * std::pow(test_in[1], 2) * X[1][2][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == + 1.0 / 2.0 * 6.0 * test_in[1] * X[1][2][0] * X[1][2][0] + + 3.0 * std::pow(test_in[1], 2.0) * X[1][2][1], + tt::tolerance(tol)); + + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(FminOperator_HOV_WK_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 2; + const size_t num_dirs = 3; + const short keep = 1; + std::vector in{4.0, 3.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + trace_on(tag); + std::for_each(in.begin(), in.end(), [&, i = 0](int value) mutable { + indep[i] <<= in[i]; + i++; + }); + + // max(x^2, y^3) + adouble dep = fmin(-pow(indep[0], 2), -pow(indep[1], 3)); + + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[1][0][0] = 1.9; + + X[0][1][0] = 2.0; + X[1][1][0] = 3.0; + + X[0][2][0] = 1.0; + X[1][2][0] = -1.0; + + X[0][0][1] = -1.0; + X[1][0][1] = 1.0; + + X[0][1][1] = -2.0; + X[1][1][1] = -3.0; + + X[0][2][1] = -1.0; + X[1][2][1] = 1.0; + + /**************************** + TEST A < B + *****************************/ + std::vector test_in{4.0, 3.2}; + // max(x^2, y^3) + double test_out = + std::fmin(-std::pow(test_in[0], 2), -std::pow(test_in[1], 3)); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + BOOST_TEST(Y[0][0][0] == -3 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == -3 * std::pow(test_in[1], 2) * X[1][1][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][0] == -3 * std::pow(test_in[1], 2) * X[1][2][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][0][0] * X[1][0][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][0][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][1][0] * X[1][1][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][1][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][2][0] * X[1][2][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][2][1], + tt::tolerance(tol)); + + /************************** + TEST A > B + ***************************/ + + // test_in[0] = 4.0 + test_in[1] = 1.0; + // max(x^2, y^3) + test_out = std::fmin(-std::pow(test_in[0], 2), -std::pow(test_in[1], 3)); + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + BOOST_TEST(Y[0][0][0] == -2 * test_in[0] * X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == -2 * test_in[0] * X[0][1][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][2][0] == -2 * test_in[0] * X[0][2][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == -1.0 / 2.0 * 2.0 * X[0][0][0] * X[0][0][0] - + 2.0 * test_in[0] * X[0][0][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == -1.0 / 2.0 * 2.0 * X[0][1][0] * X[0][1][0] - + 2.0 * test_in[0] * X[0][1][1], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == -1.0 / 2.0 * 2.0 * X[0][2][0] * X[0][2][0] - + 2.0 * test_in[0] * X[0][2][1], + tt::tolerance(tol)); + + /************************** + TEST A == B + ***************************/ + + test_in[0] = 1.0; + test_in[1] = 1.0; + + // max(x^2, y^3) + test_out = std::fmin(-std::pow(test_in[0], 2), -std::pow(test_in[1], 3)); + + // A < B + X[0][0][0] = 1.0; + X[1][0][0] = 1.9; + + // A > B + X[0][1][0] = 3.0; + X[1][1][0] = 2.0; + + // A == B + X[0][2][0] = 1.0; + X[1][2][0] = 1.0; + + X[0][0][1] = -1.0; + X[1][0][1] = 1.0; + + X[0][1][1] = -2.0; + X[1][1][1] = -3.0; + + // A < B + X[0][2][1] = 1.0; + X[1][2][1] = 2.0; + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // A < B + BOOST_TEST(Y[0][0][0] == -3 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][0][0] * X[1][0][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][0][1], + tt::tolerance(tol)); + + // A < B + BOOST_TEST(Y[0][1][0] == -2 * test_in[0] * X[0][1][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == -1.0 / 2.0 * 2.0 * X[0][1][0] * X[0][1][0] - + 2.0 * test_in[0] * X[0][1][1], + tt::tolerance(tol)); + + // A == B, A < B + BOOST_TEST(Y[0][2][0] == -3 * std::pow(test_in[1], 2) * X[1][2][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][2][1] == + -1.0 / 2.0 * 6.0 * test_in[1] * X[1][2][0] * X[1][2][0] - + 3.0 * std::pow(test_in[1], 2.0) * X[1][2][1], + tt::tolerance(tol)); + + myfree3(X); + myfree3(Y); +} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for.cpp b/ADOL-C/boost-test/uni5_for/uni5_for.cpp similarity index 99% rename from ADOL-C/boost-test/uni5_for.cpp rename to ADOL-C/boost-test/uni5_for/uni5_for.cpp index 4910cb32d..29442c4ca 100644 --- a/ADOL-C/boost-test/uni5_for.cpp +++ b/ADOL-C/boost-test/uni5_for/uni5_for.cpp @@ -10,7 +10,7 @@ namespace tt = boost::test_tools; #include -#include "const.h" +#include "../const.h" #include #include From b3aac11818b0568e04cb49c52a569266be9cf29e Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 2 Jan 2025 12:37:20 +0100 Subject: [PATCH 44/69] test exp operator for hov_forward --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 96 +++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index d4ca8dbb9..ec167d758 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -183,7 +183,6 @@ BOOST_AUTO_TEST_CASE(FminOperator_HOV_Forward) { const size_t dim_in = 2; const size_t degree = 2; const size_t num_dirs = 3; - const short keep = 1; std::vector in{4.0, 3.2}; std::vector indep(dim_in); std::vector out(dim_out); @@ -338,4 +337,99 @@ BOOST_AUTO_TEST_CASE(FminOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(ExpOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{4.0}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // exp(x1^2) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = exp(pow(indep[0], 2)); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + + X[0][1][2] = -2.0; + + std::vector test_in{4.0}; + + // exp(x1^2) + double test_out = std::exp(std::pow(in[0], 2)); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * std::exp(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * std::exp(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][0], + tt::tolerance(tol)); + // second derivative + BOOST_TEST(Y[0][0][1] == 2.0 * std::exp(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][1] + + 1.0 / 2.0 * + (4 * std::exp(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2 * std::exp(std::pow(test_in[0], 2))) * + std::pow(X[0][0][0], 2), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == (2.0 * std::exp(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][1] + + 1.0 / 2.0 * + (4 * std::exp(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2 * std::exp(std::pow(test_in[0], 2))) * + std::pow(X[0][1][0], 2)), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 2.0 * std::exp(std::pow(test_in[0], 2)) * test_in[0] * X[0][0][2] + + (4 * std::exp(std::pow(test_in[0], 2)) * std::pow(test_in[0], 2) + + 2 * std::exp(std::pow(test_in[0], 2))) * + X[0][0][1] * X[0][0][0] + + 1.0 / 6.0 * + (8 * std::exp(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 3) + + 12 * std::exp(std::pow(test_in[0], 2)) * test_in[0]) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + + BOOST_TEST( + Y[0][1][2] == + 2.0 * std::exp(std::pow(test_in[0], 2)) * test_in[0] * X[0][1][2] + + (4 * std::exp(std::pow(test_in[0], 2)) * std::pow(test_in[0], 2) + + 2 * std::exp(std::pow(test_in[0], 2))) * + X[0][1][1] * X[0][1][0] + + 1.0 / 6.0 * + (8 * std::exp(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 3) + + 12 * std::exp(std::pow(test_in[0], 2)) * test_in[0]) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From cf3be7a2ae0d288e161666f13237d30f2fc2cb04 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 2 Jan 2025 12:39:11 +0100 Subject: [PATCH 45/69] test exp operator for hov_wk_forward --- ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index f4cd9af80..38638f2b9 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -339,4 +339,99 @@ BOOST_AUTO_TEST_CASE(FminOperator_HOV_WK_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(ExpOperator_HOV_WK_FORWARD) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{4.0}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // exp(x1^2) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = exp(pow(indep[0], 2)); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + + X[0][1][2] = -2.0; + + std::vector test_in{4.0}; + + // exp(x1^2) + double test_out = std::exp(std::pow(in[0], 2)); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * std::exp(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * std::exp(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][0], + tt::tolerance(tol)); + // second derivative + BOOST_TEST(Y[0][0][1] == 2.0 * std::exp(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][1] + + 1.0 / 2.0 * + (4 * std::exp(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2 * std::exp(std::pow(test_in[0], 2))) * + std::pow(X[0][0][0], 2), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == (2.0 * std::exp(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][1] + + 1.0 / 2.0 * + (4 * std::exp(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2 * std::exp(std::pow(test_in[0], 2))) * + std::pow(X[0][1][0], 2)), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 2.0 * std::exp(std::pow(test_in[0], 2)) * test_in[0] * X[0][0][2] + + (4 * std::exp(std::pow(test_in[0], 2)) * std::pow(test_in[0], 2) + + 2 * std::exp(std::pow(test_in[0], 2))) * + X[0][0][1] * X[0][0][0] + + 1.0 / 6.0 * + (8 * std::exp(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 3) + + 12 * std::exp(std::pow(test_in[0], 2)) * test_in[0]) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + + BOOST_TEST( + Y[0][1][2] == + 2.0 * std::exp(std::pow(test_in[0], 2)) * test_in[0] * X[0][1][2] + + (4 * std::exp(std::pow(test_in[0], 2)) * std::pow(test_in[0], 2) + + 2 * std::exp(std::pow(test_in[0], 2))) * + X[0][1][1] * X[0][1][0] + + 1.0 / 6.0 * + (8 * std::exp(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 3) + + 12 * std::exp(std::pow(test_in[0], 2)) * test_in[0]) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 20203eea4af76323c2ef2d53035cf93486cd85bf Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 3 Jan 2025 18:53:44 +0100 Subject: [PATCH 46/69] add test for multiplication --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index ec167d758..c5a5207b9 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -432,4 +432,130 @@ BOOST_AUTO_TEST_CASE(ExpOperator_HOV_Forward) { myfree3(Y); } +BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{-1.0, 1.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x1^2 * x2^3 + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], 2) * pow(indep[1], 3); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + X[0][1][2] = -2.0; + + X[1][1][0] = 2.1; + X[1][1][1] = -2.1; + X[1][1][2] = -2.1; + + std::vector test_in{-1.0, 1.5}; + + // x1^2 * x2^3 + double test_out = std::pow(test_in[0], 2) * std::pow(test_in[1], 3); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][0][0] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][1][0] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST( + Y[0][0][1] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][0][1] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][0][1] + + 1.0 / 2.0 * + (2.0 * std::pow(test_in[1], 3) * std::pow(X[0][0][1], 2) + + 12.0 * test_in[0] * std::pow(test_in[1], 2) * X[0][0][1] * + X[1][0][1] + + 6.0 * test_in[1] * std::pow(test_in[0], 2) * + std::pow(X[1][0][1], 2)), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][1] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][1][1] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][1][1] + + 1.0 / 2.0 * + (2.0 * std::pow(test_in[1], 3) * std::pow(X[0][1][0], 2) + + 12.0 * test_in[0] * std::pow(test_in[1], 2) * X[0][1][0] * + X[1][1][0] + + 6.0 * test_in[1] * std::pow(test_in[0], 2) * + std::pow(X[1][1][0], 2)), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][1][2] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][1][2] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][1][2] + + (2.0 * std::pow(test_in[1], 3) * X[0][1][0] + + 6.0 * test_in[0] * std::pow(test_in[1], 2) * X[1][1][0]) * + X[0][1][1] + + (6.0 * test_in[0] * std::pow(test_in[1], 2) * X[0][1][0] + + 6.0 * test_in[1] * std::pow(test_in[0], 2) * X[1][1][0]) * + X[1][1][1] + + 1.0 / 6.0 * + (18.0 * std::pow(test_in[1], 2) * X[1][1][0] * + X[0][1][0] * X[0][1][0] + + 36.0 * test_in[0] * test_in[1] * X[1][1][0] * + X[1][1][0] * X[0][1][0] + + 6.0 * std::pow(test_in[0], 2) * X[1][1][0] * + X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][2] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][0][2] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][0][2] + + (2.0 * std::pow(test_in[1], 3) * X[0][0][0] + + 6.0 * test_in[0] * std::pow(test_in[1], 2) * X[1][0][0]) * + X[0][0][1] + + (6.0 * test_in[0] * std::pow(test_in[1], 2) * X[0][0][0] + + 6.0 * test_in[1] * std::pow(test_in[0], 2) * X[1][0][0]) * + X[1][0][1] + + 1.0 / 6.0 * + (18.0 * std::pow(test_in[1], 2) * X[1][0][0] * + X[0][0][0] * X[0][0][0] + + 36.0 * test_in[0] * test_in[1] * X[1][0][0] * + X[1][0][0] * X[0][0][0] + + 6.0 * std::pow(test_in[0], 2) * X[1][0][0] * + X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 0460644a185072b3faab0ee523d146b0e2a61d7b Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 3 Jan 2025 18:55:10 +0100 Subject: [PATCH 47/69] add test for multiplication --- ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 38638f2b9..3811c84a8 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -434,4 +434,130 @@ BOOST_AUTO_TEST_CASE(ExpOperator_HOV_WK_FORWARD) { myfree3(X); myfree3(Y); } +BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{-1.0, 1.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x1^2 * x2^3 + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], 2) * pow(indep[1], 3); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + X[0][1][2] = -2.0; + + X[1][1][0] = 2.1; + X[1][1][1] = -2.1; + X[1][1][2] = -2.1; + + std::vector test_in{-1.0, 1.5}; + + // x1^2 * x2^3 + double test_out = std::pow(test_in[0], 2) * std::pow(test_in[1], 3); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][0][0] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][1][0] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST( + Y[0][0][1] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][0][1] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][0][1] + + 1.0 / 2.0 * + (2.0 * std::pow(test_in[1], 3) * std::pow(X[0][0][1], 2) + + 12.0 * test_in[0] * std::pow(test_in[1], 2) * X[0][0][1] * + X[1][0][1] + + 6.0 * test_in[1] * std::pow(test_in[0], 2) * + std::pow(X[1][0][1], 2)), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][1] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][1][1] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][1][1] + + 1.0 / 2.0 * + (2.0 * std::pow(test_in[1], 3) * std::pow(X[0][1][0], 2) + + 12.0 * test_in[0] * std::pow(test_in[1], 2) * X[0][1][0] * + X[1][1][0] + + 6.0 * test_in[1] * std::pow(test_in[0], 2) * + std::pow(X[1][1][0], 2)), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][1][2] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][1][2] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][1][2] + + (2.0 * std::pow(test_in[1], 3) * X[0][1][0] + + 6.0 * test_in[0] * std::pow(test_in[1], 2) * X[1][1][0]) * + X[0][1][1] + + (6.0 * test_in[0] * std::pow(test_in[1], 2) * X[0][1][0] + + 6.0 * test_in[1] * std::pow(test_in[0], 2) * X[1][1][0]) * + X[1][1][1] + + 1.0 / 6.0 * + (18.0 * std::pow(test_in[1], 2) * X[1][1][0] * + X[0][1][0] * X[0][1][0] + + 36.0 * test_in[0] * test_in[1] * X[1][1][0] * + X[1][1][0] * X[0][1][0] + + 6.0 * std::pow(test_in[0], 2) * X[1][1][0] * + X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][0][2] == + 2.0 * test_in[0] * std::pow(test_in[1], 3) * X[0][0][2] + + 3.0 * std::pow(test_in[1], 2) * std::pow(test_in[0], 2) * + X[1][0][2] + + (2.0 * std::pow(test_in[1], 3) * X[0][0][0] + + 6.0 * test_in[0] * std::pow(test_in[1], 2) * X[1][0][0]) * + X[0][0][1] + + (6.0 * test_in[0] * std::pow(test_in[1], 2) * X[0][0][0] + + 6.0 * test_in[1] * std::pow(test_in[0], 2) * X[1][0][0]) * + X[1][0][1] + + 1.0 / 6.0 * + (18.0 * std::pow(test_in[1], 2) * X[1][0][0] * + X[0][0][0] * X[0][0][0] + + 36.0 * test_in[0] * test_in[1] * X[1][0][0] * + X[1][0][0] * X[0][0][0] + + 6.0 * std::pow(test_in[0], 2) * X[1][0][0] * + X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From ee8d1962e7fc07ac176948b67aa75d1730bbf937 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 3 Jan 2025 19:14:56 +0100 Subject: [PATCH 48/69] add tests for addition and subtraction --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 175 +++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index c5a5207b9..fe7c8c7c8 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -558,4 +558,179 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { myfree3(Y); } +BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{-1.0, 1.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x1^2 + x2^3 + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], 2) + pow(indep[1], 3); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + X[0][1][2] = -2.0; + + X[1][1][0] = 2.1; + X[1][1][1] = -2.1; + X[1][1][2] = -2.1; + + std::vector test_in{-1.0, 1.5}; + + // x1^2 + x2^3 + double test_out = std::pow(test_in[0], 2) + std::pow(test_in[1], 3); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * test_in[0] * X[0][0][0] + + 3.0 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * test_in[0] * X[0][1][0] + + 3.0 * std::pow(test_in[1], 2) * X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 2.0 * test_in[0] * X[0][0][1] + + 3.0 * std::pow(test_in[1], 2) * X[1][0][1] + + 1.0 / 2.0 * + (2.0 * X[0][0][0] * X[0][0][0] + + 6.0 * test_in[1] * X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 2.0 * test_in[0] * X[0][1][1] + + 3.0 * std::pow(test_in[1], 2) * X[1][1][1] + + 1.0 / 2.0 * + (2.0 * X[0][1][0] * X[0][1][0] + + 6.0 * test_in[1] * X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 2.0 * test_in[0] * X[0][0][2] + + 3.0 * std::pow(test_in[1], 2) * X[1][0][2] + + 2.0 * X[0][0][0] * X[0][0][1] + + 6.0 * test_in[1] * X[1][0][0] * X[1][0][1] + + 1.0 / 6.0 * 6.0 * X[1][0][0] * X[1][0][0] * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 2.0 * test_in[0] * X[0][1][2] + + 3.0 * std::pow(test_in[1], 2) * X[1][1][2] + + 2.0 * X[0][1][0] * X[0][1][1] + + 6.0 * test_in[1] * X[1][1][0] * X[1][1][1] + + 1.0 / 6.0 * 6.0 * X[1][1][0] * X[1][1][0] * X[1][1][0], + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{-1.0, 1.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x1^2 - x2^3 + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], 2) - pow(indep[1], 3); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + X[0][1][2] = -2.0; + + X[1][1][0] = 2.1; + X[1][1][1] = -2.1; + X[1][1][2] = -2.1; + + std::vector test_in{-1.0, 1.5}; + + // x1^2 - x2^3 + double test_out = std::pow(test_in[0], 2) - std::pow(test_in[1], 3); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * test_in[0] * X[0][0][0] - + 3.0 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * test_in[0] * X[0][1][0] - + 3.0 * std::pow(test_in[1], 2) * X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 2.0 * test_in[0] * X[0][0][1] - + 3.0 * std::pow(test_in[1], 2) * X[1][0][1] + + 1.0 / 2.0 * + (2.0 * X[0][0][0] * X[0][0][0] - + 6.0 * test_in[1] * X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 2.0 * test_in[0] * X[0][1][1] - + 3.0 * std::pow(test_in[1], 2) * X[1][1][1] + + 1.0 / 2.0 * + (2.0 * X[0][1][0] * X[0][1][0] - + 6.0 * test_in[1] * X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 2.0 * test_in[0] * X[0][0][2] - + 3.0 * std::pow(test_in[1], 2) * X[1][0][2] + + 2.0 * X[0][0][0] * X[0][0][1] - + 6.0 * test_in[1] * X[1][0][0] * X[1][0][1] - + 1.0 / 6.0 * 6.0 * X[1][0][0] * X[1][0][0] * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 2.0 * test_in[0] * X[0][1][2] - + 3.0 * std::pow(test_in[1], 2) * X[1][1][2] + + 2.0 * X[0][1][0] * X[0][1][1] - + 6.0 * test_in[1] * X[1][1][0] * X[1][1][1] - + 1.0 / 6.0 * 6.0 * X[1][1][0] * X[1][1][0] * X[1][1][0], + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From e7bbcbd4293b5687bee015285000a94f67cb735d Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Fri, 3 Jan 2025 19:16:15 +0100 Subject: [PATCH 49/69] add tests for addition and subtraction --- ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 3811c84a8..4290e0b6e 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -560,4 +560,182 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{-1.0, 1.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x1^2 + x2^3 + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], 2) + pow(indep[1], 3); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + X[0][1][2] = -2.0; + + X[1][1][0] = 2.1; + X[1][1][1] = -2.1; + X[1][1][2] = -2.1; + + std::vector test_in{-1.0, 1.5}; + + // x1^2 + x2^3 + double test_out = std::pow(test_in[0], 2) + std::pow(test_in[1], 3); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * test_in[0] * X[0][0][0] + + 3.0 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * test_in[0] * X[0][1][0] + + 3.0 * std::pow(test_in[1], 2) * X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 2.0 * test_in[0] * X[0][0][1] + + 3.0 * std::pow(test_in[1], 2) * X[1][0][1] + + 1.0 / 2.0 * + (2.0 * X[0][0][0] * X[0][0][0] + + 6.0 * test_in[1] * X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 2.0 * test_in[0] * X[0][1][1] + + 3.0 * std::pow(test_in[1], 2) * X[1][1][1] + + 1.0 / 2.0 * + (2.0 * X[0][1][0] * X[0][1][0] + + 6.0 * test_in[1] * X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 2.0 * test_in[0] * X[0][0][2] + + 3.0 * std::pow(test_in[1], 2) * X[1][0][2] + + 2.0 * X[0][0][0] * X[0][0][1] + + 6.0 * test_in[1] * X[1][0][0] * X[1][0][1] + + 1.0 / 6.0 * 6.0 * X[1][0][0] * X[1][0][0] * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 2.0 * test_in[0] * X[0][1][2] + + 3.0 * std::pow(test_in[1], 2) * X[1][1][2] + + 2.0 * X[0][1][0] * X[0][1][1] + + 6.0 * test_in[1] * X[1][1][0] * X[1][1][1] + + 1.0 / 6.0 * 6.0 * X[1][1][0] * X[1][1][0] * X[1][1][0], + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{-1.0, 1.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x1^2 - x2^3 + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], 2) - pow(indep[1], 3); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + X[0][1][2] = -2.0; + + X[1][1][0] = 2.1; + X[1][1][1] = -2.1; + X[1][1][2] = -2.1; + + std::vector test_in{-1.0, 1.5}; + + // x1^2 - x2^3 + double test_out = std::pow(test_in[0], 2) - std::pow(test_in[1], 3); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * test_in[0] * X[0][0][0] - + 3.0 * std::pow(test_in[1], 2) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * test_in[0] * X[0][1][0] - + 3.0 * std::pow(test_in[1], 2) * X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 2.0 * test_in[0] * X[0][0][1] - + 3.0 * std::pow(test_in[1], 2) * X[1][0][1] + + 1.0 / 2.0 * + (2.0 * X[0][0][0] * X[0][0][0] - + 6.0 * test_in[1] * X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 2.0 * test_in[0] * X[0][1][1] - + 3.0 * std::pow(test_in[1], 2) * X[1][1][1] + + 1.0 / 2.0 * + (2.0 * X[0][1][0] * X[0][1][0] - + 6.0 * test_in[1] * X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 2.0 * test_in[0] * X[0][0][2] - + 3.0 * std::pow(test_in[1], 2) * X[1][0][2] + + 2.0 * X[0][0][0] * X[0][0][1] - + 6.0 * test_in[1] * X[1][0][0] * X[1][0][1] - + 1.0 / 6.0 * 6.0 * X[1][0][0] * X[1][0][0] * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 2.0 * test_in[0] * X[0][1][2] - + 3.0 * std::pow(test_in[1], 2) * X[1][1][2] + + 2.0 * X[0][1][0] * X[0][1][1] - + 6.0 * test_in[1] * X[1][1][0] * X[1][1][1] - + 1.0 / 6.0 * 6.0 * X[1][1][0] * X[1][1][0] * X[1][1][0], + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 006a4316659a91d8625ba56231b11988c1d92a23 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 4 Jan 2025 11:00:49 +0100 Subject: [PATCH 50/69] add test for div --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 134 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 135 ++++++++++++++++++ 2 files changed, 269 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index fe7c8c7c8..68bde0995 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -733,4 +733,138 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{-1.0, 1.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x1^2 / x2^3 + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], 2) / pow(indep[1], 3); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + X[0][1][2] = -2.0; + + X[1][1][0] = 2.1; + X[1][1][1] = -2.1; + X[1][1][2] = -2.1; + + std::vector test_in{-1.0, 1.5}; + + // x1^2 - x2^3 + double test_out = std::pow(test_in[0], 2) / std::pow(test_in[1], 3); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][0][0] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][1][0] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST( + Y[0][0][1] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][0][1] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][0][1] + + 1.0 / 2.0 * + ((2.0 / std::pow(test_in[1], 3) * X[0][0][0] - + 6 * test_in[0] / std::pow(test_in[1], 4) * X[1][0][0]) * + X[0][0][0] + + (-6 * test_in[0] / std::pow(test_in[1], 4) * X[0][0][0] + + 12.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 5) * + X[1][0][0]) * + X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][1] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][1][1] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][1][1] + + 1.0 / 2.0 * + ((2.0 / std::pow(test_in[1], 3) * X[0][1][0] - + 6 * test_in[0] / std::pow(test_in[1], 4) * X[1][1][0]) * + X[0][1][0] + + (-6 * test_in[0] / std::pow(test_in[1], 4) * X[0][1][0] + + 12.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 5) * + X[1][1][0]) * + X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][0][2] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][0][2] + + (2.0 / std::pow(test_in[1], 3) * X[0][0][0] - + 6.0 * test_in[0] / std::pow(test_in[1], 4) * X[1][0][0]) * + X[0][0][1] + + (-6.0 * test_in[0] / std::pow(test_in[1], 4) * X[0][0][0] + + 12.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 5) * + X[1][0][0]) * + X[1][0][1] + + 1.0 / 6.0 * + (-18.0 / std::pow(test_in[1], 4) * X[0][0][0] * + X[0][0][0] * X[1][0][0] + + 72.0 * test_in[0] / std::pow(test_in[1], 5) * + X[1][0][0] * X[1][0][0] * X[0][0][0] - + 60.0 * std::pow(test_in[0], 2) / + std::pow(test_in[1], 6) * X[1][0][0] * + X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][1][2] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][1][2] + + (2.0 / std::pow(test_in[1], 3) * X[0][1][0] - + 6.0 * test_in[0] / std::pow(test_in[1], 4) * X[1][1][0]) * + X[0][1][1] + + (-6.0 * test_in[0] / std::pow(test_in[1], 4) * X[0][1][0] + + 12.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 5) * + X[1][1][0]) * + X[1][1][1] + + 1.0 / 6.0 * + (-18.0 / std::pow(test_in[1], 4) * X[0][1][0] * + X[0][1][0] * X[1][1][0] + + 72.0 * test_in[0] / std::pow(test_in[1], 5) * + X[1][1][0] * X[1][1][0] * X[0][1][0] - + 60.0 * std::pow(test_in[0], 2) / + std::pow(test_in[1], 6) * X[1][1][0] * + X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 4290e0b6e..b78381ead 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -738,4 +738,139 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{-1.0, 1.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x1^2 / x2^3 + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], 2) / pow(indep[1], 3); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.0; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.0; + X[0][1][2] = -2.0; + + X[1][1][0] = 2.1; + X[1][1][1] = -2.1; + X[1][1][2] = -2.1; + + std::vector test_in{-1.0, 1.5}; + + // x1^2 - x2^3 + double test_out = std::pow(test_in[0], 2) / std::pow(test_in[1], 3); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][0][0] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][1][0] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST( + Y[0][0][1] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][0][1] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][0][1] + + 1.0 / 2.0 * + ((2.0 / std::pow(test_in[1], 3) * X[0][0][0] - + 6 * test_in[0] / std::pow(test_in[1], 4) * X[1][0][0]) * + X[0][0][0] + + (-6 * test_in[0] / std::pow(test_in[1], 4) * X[0][0][0] + + 12.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 5) * + X[1][0][0]) * + X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][1] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][1][1] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][1][1] + + 1.0 / 2.0 * + ((2.0 / std::pow(test_in[1], 3) * X[0][1][0] - + 6 * test_in[0] / std::pow(test_in[1], 4) * X[1][1][0]) * + X[0][1][0] + + (-6 * test_in[0] / std::pow(test_in[1], 4) * X[0][1][0] + + 12.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 5) * + X[1][1][0]) * + X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][0][2] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][0][2] + + (2.0 / std::pow(test_in[1], 3) * X[0][0][0] - + 6.0 * test_in[0] / std::pow(test_in[1], 4) * X[1][0][0]) * + X[0][0][1] + + (-6.0 * test_in[0] / std::pow(test_in[1], 4) * X[0][0][0] + + 12.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 5) * + X[1][0][0]) * + X[1][0][1] + + 1.0 / 6.0 * + (-18.0 / std::pow(test_in[1], 4) * X[0][0][0] * + X[0][0][0] * X[1][0][0] + + 72.0 * test_in[0] / std::pow(test_in[1], 5) * + X[1][0][0] * X[1][0][0] * X[0][0][0] - + 60.0 * std::pow(test_in[0], 2) / + std::pow(test_in[1], 6) * X[1][0][0] * + X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 2.0 * test_in[0] / std::pow(test_in[1], 3) * X[0][1][2] - + 3.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 4) * + X[1][1][2] + + (2.0 / std::pow(test_in[1], 3) * X[0][1][0] - + 6.0 * test_in[0] / std::pow(test_in[1], 4) * X[1][1][0]) * + X[0][1][1] + + (-6.0 * test_in[0] / std::pow(test_in[1], 4) * X[0][1][0] + + 12.0 * std::pow(test_in[0], 2) / std::pow(test_in[1], 5) * + X[1][1][0]) * + X[1][1][1] + + 1.0 / 6.0 * + (-18.0 / std::pow(test_in[1], 4) * X[0][1][0] * + X[0][1][0] * X[1][1][0] + + 72.0 * test_in[0] / std::pow(test_in[1], 5) * + X[1][1][0] * X[1][1][0] * X[0][1][0] - + 60.0 * std::pow(test_in[0], 2) / + std::pow(test_in[1], 6) * X[1][1][0] * + X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 6ebee73dccf3d8cb9ed60a69cf67bf4bbcbd7852 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 4 Jan 2025 11:02:56 +0100 Subject: [PATCH 51/69] rename test cases --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 9 +++++---- ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 68bde0995..da19577b2 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -432,7 +432,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_HOV_Forward) { myfree3(Y); } -BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { +BOOST_AUTO_TEST_CASE(MultOperator_HOV_Forward) { const int16_t tag = 0; const size_t dim_out = 1; const size_t dim_in = 2; @@ -558,7 +558,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { myfree3(Y); } -BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) { +BOOST_AUTO_TEST_CASE(AddOperator_HOV_Forward) { const int16_t tag = 0; const size_t dim_out = 1; const size_t dim_in = 2; @@ -646,7 +646,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) { myfree3(Y); } -BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { +BOOST_AUTO_TEST_CASE(SubOperator_HOV_Forward) { const int16_t tag = 0; const size_t dim_out = 1; const size_t dim_in = 2; @@ -734,7 +734,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { myfree3(Y); } -BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) { +BOOST_AUTO_TEST_CASE(DivOperator_HOV_Forward) { const int16_t tag = 0; const size_t dim_out = 1; const size_t dim_in = 2; @@ -867,4 +867,5 @@ BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) { myfree3(X); myfree3(Y); } + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index b78381ead..2e3b92830 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -434,7 +434,7 @@ BOOST_AUTO_TEST_CASE(ExpOperator_HOV_WK_FORWARD) { myfree3(X); myfree3(Y); } -BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { +BOOST_AUTO_TEST_CASE(MultOperator_HOV_Forward) { const int16_t tag = 0; const size_t dim_out = 1; const size_t dim_in = 2; @@ -561,7 +561,7 @@ BOOST_AUTO_TEST_CASE(MultOperator_FOV_Forward) { myfree3(Y); } -BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) { +BOOST_AUTO_TEST_CASE(AddOperator_HOV_Forward) { const int16_t tag = 0; const size_t dim_out = 1; const size_t dim_in = 2; @@ -650,7 +650,7 @@ BOOST_AUTO_TEST_CASE(AddOperator_FOV_Forward) { myfree3(Y); } -BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { +BOOST_AUTO_TEST_CASE(SubOperator_HOV_Forward) { const int16_t tag = 0; const size_t dim_out = 1; const size_t dim_in = 2; @@ -739,7 +739,7 @@ BOOST_AUTO_TEST_CASE(SubOperator_FOV_Forward) { myfree3(Y); } -BOOST_AUTO_TEST_CASE(DivOperator_FOV_Forward) { +BOOST_AUTO_TEST_CASE(DivOperator_HOV_Forward) { const int16_t tag = 0; const size_t dim_out = 1; const size_t dim_in = 2; From 9ab0571de5347ce70da045475665f75c2a52c0c0 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 4 Jan 2025 11:58:57 +0100 Subject: [PATCH 52/69] add test for tan --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 130 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 132 ++++++++++++++++++ 2 files changed, 262 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index da19577b2..dc72d9288 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -868,4 +868,134 @@ BOOST_AUTO_TEST_CASE(DivOperator_HOV_Forward) { myfree3(Y); } +BOOST_AUTO_TEST_CASE(TanOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // tan(x1^2) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = tan(pow(indep[0], 2)); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // tan(x1^2) + double test_out = std::tan(std::pow(test_in[0], 2)); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * test_in[0] / + std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * test_in[0] / + std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 2.0 * test_in[0] / + std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][0][1] + + 1.0 / 2.0 * + (2.0 * std::pow(std::cos(std::pow(test_in[0], 2)), 2) + + 8.0 * std::pow(test_in[0], 2) * + std::cos(std::pow(test_in[0], 2)) * + std::sin(std::pow(test_in[0], 2))) / + std::pow(std::cos(std::pow(test_in[0], 2)), 4) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 2.0 * test_in[0] / + std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][1][1] + + 1.0 / 2.0 * + (2.0 * std::pow(std::cos(std::pow(test_in[0], 2)), 2) + + 8.0 * std::pow(test_in[0], 2) * + std::cos(std::pow(test_in[0], 2)) * + std::sin(std::pow(test_in[0], 2))) / + std::pow(std::cos(std::pow(test_in[0], 2)), 4) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 2.0 * test_in[0] / std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][0][2] + + (2.0 * std::pow(std::cos(std::pow(test_in[0], 2)), 2) + + 8.0 * std::pow(test_in[0], 2) * + std::cos(std::pow(test_in[0], 2)) * + std::sin(std::pow(test_in[0], 2))) / + std::pow(std::cos(std::pow(test_in[0], 2)), 4) * X[0][0][0] * + X[0][0][1] + + 1.0 / 6.0 * + (96.0 * test_in[0] * std::sin(2.0 * std::pow(test_in[0], 2)) * + std::pow(std::cos(std::pow(test_in[0], 2)), 2) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 3) + + 256.0 * std::pow(test_in[0], 3) * + std::pow(std::cos(std::pow(test_in[0], 2)), 4) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 4) + + 128.0 * std::pow(test_in[0], 3) * + std::pow(std::sin(2.0 * std::pow(test_in[0], 2)), 2) * + std::pow(std::cos(std::pow(test_in[0], 2)), 2) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 4)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + 2.0 * test_in[0] / std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][1][2] + + (2.0 * std::pow(std::cos(std::pow(test_in[0], 2)), 2) + + 8.0 * std::pow(test_in[0], 2) * + std::cos(std::pow(test_in[0], 2)) * + std::sin(std::pow(test_in[0], 2))) / + std::pow(std::cos(std::pow(test_in[0], 2)), 4) * X[0][1][0] * + X[0][1][1] + + 1.0 / 6.0 * + (96.0 * test_in[0] * std::sin(2.0 * std::pow(test_in[0], 2)) * + std::pow(std::cos(std::pow(test_in[0], 2)), 2) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 3) + + 256.0 * std::pow(test_in[0], 3) * + std::pow(std::cos(std::pow(test_in[0], 2)), 4) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 4) + + 128.0 * std::pow(test_in[0], 3) * + std::pow(std::sin(2.0 * std::pow(test_in[0], 2)), 2) * + std::pow(std::cos(std::pow(test_in[0], 2)), 2) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 4)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 2e3b92830..3512a5d90 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -873,4 +873,136 @@ BOOST_AUTO_TEST_CASE(DivOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(TanOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // tan(x1^2) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = tan(pow(indep[0], 2)); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // tan(x1^2) + double test_out = std::tan(std::pow(test_in[0], 2)); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * test_in[0] / + std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * test_in[0] / + std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 2.0 * test_in[0] / + std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][0][1] + + 1.0 / 2.0 * + (2.0 * std::pow(std::cos(std::pow(test_in[0], 2)), 2) + + 8.0 * std::pow(test_in[0], 2) * + std::cos(std::pow(test_in[0], 2)) * + std::sin(std::pow(test_in[0], 2))) / + std::pow(std::cos(std::pow(test_in[0], 2)), 4) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 2.0 * test_in[0] / + std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][1][1] + + 1.0 / 2.0 * + (2.0 * std::pow(std::cos(std::pow(test_in[0], 2)), 2) + + 8.0 * std::pow(test_in[0], 2) * + std::cos(std::pow(test_in[0], 2)) * + std::sin(std::pow(test_in[0], 2))) / + std::pow(std::cos(std::pow(test_in[0], 2)), 4) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 2.0 * test_in[0] / std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][0][2] + + (2.0 * std::pow(std::cos(std::pow(test_in[0], 2)), 2) + + 8.0 * std::pow(test_in[0], 2) * + std::cos(std::pow(test_in[0], 2)) * + std::sin(std::pow(test_in[0], 2))) / + std::pow(std::cos(std::pow(test_in[0], 2)), 4) * X[0][0][0] * + X[0][0][1] + + 1.0 / 6.0 * + (96.0 * test_in[0] * std::sin(2.0 * std::pow(test_in[0], 2)) * + std::pow(std::cos(std::pow(test_in[0], 2)), 2) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 3) + + 256.0 * std::pow(test_in[0], 3) * + std::pow(std::cos(std::pow(test_in[0], 2)), 4) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 4) + + 128.0 * std::pow(test_in[0], 3) * + std::pow(std::sin(2.0 * std::pow(test_in[0], 2)), 2) * + std::pow(std::cos(std::pow(test_in[0], 2)), 2) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 4)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + 2.0 * test_in[0] / std::pow(std::cos(std::pow(test_in[0], 2)), 2) * + X[0][1][2] + + (2.0 * std::pow(std::cos(std::pow(test_in[0], 2)), 2) + + 8.0 * std::pow(test_in[0], 2) * + std::cos(std::pow(test_in[0], 2)) * + std::sin(std::pow(test_in[0], 2))) / + std::pow(std::cos(std::pow(test_in[0], 2)), 4) * X[0][1][0] * + X[0][1][1] + + 1.0 / 6.0 * + (96.0 * test_in[0] * std::sin(2.0 * std::pow(test_in[0], 2)) * + std::pow(std::cos(std::pow(test_in[0], 2)), 2) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 3) + + 256.0 * std::pow(test_in[0], 3) * + std::pow(std::cos(std::pow(test_in[0], 2)), 4) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 4) + + 128.0 * std::pow(test_in[0], 3) * + std::pow(std::sin(2.0 * std::pow(test_in[0], 2)), 2) * + std::pow(std::cos(std::pow(test_in[0], 2)), 2) / + std::pow(std::cos(2.0 * std::pow(test_in[0], 2)) + 1, + 4)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 6d37ee587222047ffd232682a1c1de467e1a2404 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 4 Jan 2025 12:12:41 +0100 Subject: [PATCH 53/69] add test for sin --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 95 ++++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 96 +++++++++++++++++++ 2 files changed, 191 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index dc72d9288..70a88283c 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -998,4 +998,99 @@ BOOST_AUTO_TEST_CASE(TanOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(SinOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // sin(x1^2) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = sin(pow(indep[0], 2)); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // sin(x1^2) + double test_out = std::sin(std::pow(test_in[0], 2)); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * std::cos(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * std::cos(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 2.0 * std::cos(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][1] + + 1.0 / 2.0 * + (-4.0 * std::sin(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2.0 * std::cos(std::pow(test_in[0], 2))) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 2.0 * std::cos(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][1] + + 1.0 / 2.0 * + (-4.0 * std::sin(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2.0 * std::cos(std::pow(test_in[0], 2))) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 2.0 * std::cos(std::pow(test_in[0], 2)) * test_in[0] * X[0][0][2] + + (-4.0 * std::sin(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2.0 * std::cos(std::pow(test_in[0], 2))) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * + (-12.0 * test_in[0] * std::sin(std::pow(test_in[0], 2)) - + 8.0 * std::pow(test_in[0], 3) * + std::cos(std::pow(test_in[0], 2))) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + 2.0 * std::cos(std::pow(test_in[0], 2)) * test_in[0] * X[0][1][2] + + (-4.0 * std::sin(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2.0 * std::cos(std::pow(test_in[0], 2))) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * + (-12.0 * test_in[0] * std::sin(std::pow(test_in[0], 2)) - + 8.0 * std::pow(test_in[0], 3) * + std::cos(std::pow(test_in[0], 2))) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 3512a5d90..8a1f09bd3 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -1005,4 +1005,100 @@ BOOST_AUTO_TEST_CASE(TanOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(SinOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // sin(x1^2) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = sin(pow(indep[0], 2)); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // sin(x1^2) + double test_out = std::sin(std::pow(test_in[0], 2)); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 2.0 * std::cos(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 2.0 * std::cos(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 2.0 * std::cos(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][1] + + 1.0 / 2.0 * + (-4.0 * std::sin(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2.0 * std::cos(std::pow(test_in[0], 2))) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 2.0 * std::cos(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][1] + + 1.0 / 2.0 * + (-4.0 * std::sin(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2.0 * std::cos(std::pow(test_in[0], 2))) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 2.0 * std::cos(std::pow(test_in[0], 2)) * test_in[0] * X[0][0][2] + + (-4.0 * std::sin(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2.0 * std::cos(std::pow(test_in[0], 2))) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * + (-12.0 * test_in[0] * std::sin(std::pow(test_in[0], 2)) - + 8.0 * std::pow(test_in[0], 3) * + std::cos(std::pow(test_in[0], 2))) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + 2.0 * std::cos(std::pow(test_in[0], 2)) * test_in[0] * X[0][1][2] + + (-4.0 * std::sin(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) + + 2.0 * std::cos(std::pow(test_in[0], 2))) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * + (-12.0 * test_in[0] * std::sin(std::pow(test_in[0], 2)) - + 8.0 * std::pow(test_in[0], 3) * + std::cos(std::pow(test_in[0], 2))) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 176f92cc3e17a853848e8254e0a545bc0f49172a Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Sat, 4 Jan 2025 12:18:18 +0100 Subject: [PATCH 54/69] add test for cos --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 95 ++++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 96 +++++++++++++++++++ 2 files changed, 191 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 70a88283c..1b13f04a9 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -1093,4 +1093,99 @@ BOOST_AUTO_TEST_CASE(SinOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(CosOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // cos(x1^2) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = cos(pow(indep[0], 2)); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // cos(x1^2) + double test_out = std::cos(std::pow(test_in[0], 2)); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == -2.0 * std::sin(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == -2.0 * std::sin(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == -2.0 * std::sin(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][1] + + 1.0 / 2.0 * + (-4.0 * std::cos(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) - + 2.0 * std::sin(std::pow(test_in[0], 2))) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == -2.0 * std::sin(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][1] + + 1.0 / 2.0 * + (-4.0 * std::cos(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) - + 2.0 * std::sin(std::pow(test_in[0], 2))) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + -2.0 * std::sin(std::pow(test_in[0], 2)) * test_in[0] * X[0][0][2] + + (-4.0 * std::cos(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) - + 2.0 * std::sin(std::pow(test_in[0], 2))) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * + (-12.0 * test_in[0] * std::cos(std::pow(test_in[0], 2)) + + 8.0 * std::pow(test_in[0], 3) * + std::sin(std::pow(test_in[0], 2))) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + -2.0 * std::sin(std::pow(test_in[0], 2)) * test_in[0] * X[0][1][2] + + (-4.0 * std::cos(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) - + 2.0 * std::sin(std::pow(test_in[0], 2))) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * + (-12.0 * test_in[0] * std::cos(std::pow(test_in[0], 2)) + + 8.0 * std::pow(test_in[0], 3) * + std::sin(std::pow(test_in[0], 2))) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 8a1f09bd3..8210d4f6d 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -1101,4 +1101,100 @@ BOOST_AUTO_TEST_CASE(SinOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(CosOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // cos(x1^2) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = cos(pow(indep[0], 2)); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // cos(x1^2) + double test_out = std::cos(std::pow(test_in[0], 2)); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == -2.0 * std::sin(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == -2.0 * std::sin(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == -2.0 * std::sin(std::pow(test_in[0], 2)) * + test_in[0] * X[0][0][1] + + 1.0 / 2.0 * + (-4.0 * std::cos(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) - + 2.0 * std::sin(std::pow(test_in[0], 2))) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == -2.0 * std::sin(std::pow(test_in[0], 2)) * + test_in[0] * X[0][1][1] + + 1.0 / 2.0 * + (-4.0 * std::cos(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) - + 2.0 * std::sin(std::pow(test_in[0], 2))) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + -2.0 * std::sin(std::pow(test_in[0], 2)) * test_in[0] * X[0][0][2] + + (-4.0 * std::cos(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) - + 2.0 * std::sin(std::pow(test_in[0], 2))) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * + (-12.0 * test_in[0] * std::cos(std::pow(test_in[0], 2)) + + 8.0 * std::pow(test_in[0], 3) * + std::sin(std::pow(test_in[0], 2))) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + -2.0 * std::sin(std::pow(test_in[0], 2)) * test_in[0] * X[0][1][2] + + (-4.0 * std::cos(std::pow(test_in[0], 2)) * + std::pow(test_in[0], 2) - + 2.0 * std::sin(std::pow(test_in[0], 2))) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * + (-12.0 * test_in[0] * std::cos(std::pow(test_in[0], 2)) + + 8.0 * std::pow(test_in[0], 3) * + std::sin(std::pow(test_in[0], 2))) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 3b2555dc42a78ee186c630cb0ac365076613f9bd Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Mon, 6 Jan 2025 09:03:35 +0100 Subject: [PATCH 55/69] add tests for sqrt --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 79 ++++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 80 +++++++++++++++++++ 2 files changed, 159 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 1b13f04a9..0568e7064 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -1188,4 +1188,83 @@ BOOST_AUTO_TEST_CASE(CosOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(SqrtOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // sqrt(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = sqrt(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // sqrt(x) + double test_out = std::sqrt(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][0][1] + + 1.0 / 2.0 * + (-1.0 / (4.0 * std::pow(test_in[0], 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][1][1] + + 1.0 / 2.0 * + (-1.0 / (4.0 * std::pow(test_in[0], 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][0][2] + + (-1.0 / (4.0 * std::pow(test_in[0], 3.0 / 2.0)) * + X[0][0][0] * X[0][0][1]) + + 1.0 / 6.0 * + (3.0 / (8.0 * std::pow(test_in[0], 5.0 / 2.0)) * + std::pow(X[0][0][0], 3)), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][1][2] + + (-1.0 / (4.0 * std::pow(test_in[0], 3.0 / 2.0)) * + X[0][1][0] * X[0][1][1]) + + 1.0 / 6.0 * + (3.0 / (8.0 * std::pow(test_in[0], 5.0 / 2.0)) * + std::pow(X[0][1][0], 3)), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 8210d4f6d..044b9fb1b 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -1197,4 +1197,84 @@ BOOST_AUTO_TEST_CASE(CosOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(SqrtOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // sqrt(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = sqrt(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // sqrt(x) + double test_out = std::sqrt(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][0][1] + + 1.0 / 2.0 * + (-1.0 / (4.0 * std::pow(test_in[0], 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][1][1] + + 1.0 / 2.0 * + (-1.0 / (4.0 * std::pow(test_in[0], 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][0][2] + + (-1.0 / (4.0 * std::pow(test_in[0], 3.0 / 2.0)) * + X[0][0][0] * X[0][0][1]) + + 1.0 / 6.0 * + (3.0 / (8.0 * std::pow(test_in[0], 5.0 / 2.0)) * + std::pow(X[0][0][0], 3)), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / (2.0 * std::sqrt(test_in[0])) * X[0][1][2] + + (-1.0 / (4.0 * std::pow(test_in[0], 3.0 / 2.0)) * + X[0][1][0] * X[0][1][1]) + + 1.0 / 6.0 * + (3.0 / (8.0 * std::pow(test_in[0], 5.0 / 2.0)) * + std::pow(X[0][1][0], 3)), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 06d3c640d3e8aa649817edd6b599ee3071f589e4 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Mon, 6 Jan 2025 09:11:15 +0100 Subject: [PATCH 56/69] add tests for log --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 71 ++++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 72 +++++++++++++++++++ 2 files changed, 143 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 0568e7064..9baa4902f 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -1267,4 +1267,75 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(LogOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // Log(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = log(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // log(x) + double test_out = std::log(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / test_in[0] * X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / test_in[0] * X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 1.0 / test_in[0] * X[0][0][1] + + 1.0 / 2.0 * + (-1.0 / std::pow(test_in[0], 2.0) * + X[0][0][0] * X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / test_in[0] * X[0][1][1] + + 1.0 / 2.0 * + (-1.0 / std::pow(test_in[0], 2.0) * + X[0][1][0] * X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == 1.0 / test_in[0] * X[0][0][2] + + (-1.0 / std::pow(test_in[0], 2.0) * X[0][0][0] * + X[0][0][1]) + + 1.0 / 6.0 * (2.0 / std::pow(test_in[0], 3.0)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == 1.0 / test_in[0] * X[0][1][2] + + (-1.0 / std::pow(test_in[0], 2.0) * X[0][1][0] * + X[0][1][1]) + + 1.0 / 6.0 * (2.0 / std::pow(test_in[0], 3.0)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 044b9fb1b..5d3d23187 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -1277,4 +1277,76 @@ BOOST_AUTO_TEST_CASE(SqrtOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(LogOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // Log(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = log(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // log(x) + double test_out = std::log(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / test_in[0] * X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / test_in[0] * X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 1.0 / test_in[0] * X[0][0][1] + + 1.0 / 2.0 * + (-1.0 / std::pow(test_in[0], 2.0) * + X[0][0][0] * X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / test_in[0] * X[0][1][1] + + 1.0 / 2.0 * + (-1.0 / std::pow(test_in[0], 2.0) * + X[0][1][0] * X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == 1.0 / test_in[0] * X[0][0][2] + + (-1.0 / std::pow(test_in[0], 2.0) * X[0][0][0] * + X[0][0][1]) + + 1.0 / 6.0 * (2.0 / std::pow(test_in[0], 3.0)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == 1.0 / test_in[0] * X[0][1][2] + + (-1.0 / std::pow(test_in[0], 2.0) * X[0][1][0] * + X[0][1][1]) + + 1.0 / 6.0 * (2.0 / std::pow(test_in[0], 3.0)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 810e6e058da3013caf4570e9405f443e3c4f6016 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Mon, 6 Jan 2025 09:28:21 +0100 Subject: [PATCH 57/69] add tests for cosh, sinh --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 142 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 144 ++++++++++++++++++ 2 files changed, 286 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 9baa4902f..bdd81aff9 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -1338,4 +1338,146 @@ BOOST_AUTO_TEST_CASE(LogOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(SinhOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // sinh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = sinh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // sinh(x) + double test_out = std::sinh(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == std::cosh(test_in[0]) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::cosh(test_in[0]) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + std::cosh(test_in[0]) * X[0][0][1] + + 1.0 / 2.0 * + (std::sinh(test_in[0]) * X[0][0][0] * X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + std::cosh(test_in[0]) * X[0][1][1] + + 1.0 / 2.0 * + (std::sinh(test_in[0]) * X[0][1][0] * X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == std::cosh(test_in[0]) * X[0][0][2] + + std::sinh(test_in[0]) * X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * std::cosh(test_in[0]) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == std::cosh(test_in[0]) * X[0][1][2] + + std::sinh(test_in[0]) * X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * std::cosh(test_in[0]) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(CoshOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // cosh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = cosh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // cosh(x) + double test_out = std::cosh(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == std::sinh(test_in[0]) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::sinh(test_in[0]) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + std::sinh(test_in[0]) * X[0][0][1] + + 1.0 / 2.0 * + (std::cosh(test_in[0]) * X[0][0][0] * X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + std::sinh(test_in[0]) * X[0][1][1] + + 1.0 / 2.0 * + (std::cosh(test_in[0]) * X[0][1][0] * X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == std::sinh(test_in[0]) * X[0][0][2] + + std::cosh(test_in[0]) * X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * std::sinh(test_in[0]) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == std::sinh(test_in[0]) * X[0][1][2] + + std::cosh(test_in[0]) * X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * std::sinh(test_in[0]) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 5d3d23187..37d83e339 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -1349,4 +1349,148 @@ BOOST_AUTO_TEST_CASE(LogOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(SinhOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // sinh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = sinh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // sinh(x) + double test_out = std::sinh(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == std::cosh(test_in[0]) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::cosh(test_in[0]) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + std::cosh(test_in[0]) * X[0][0][1] + + 1.0 / 2.0 * + (std::sinh(test_in[0]) * X[0][0][0] * X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + std::cosh(test_in[0]) * X[0][1][1] + + 1.0 / 2.0 * + (std::sinh(test_in[0]) * X[0][1][0] * X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == std::cosh(test_in[0]) * X[0][0][2] + + std::sinh(test_in[0]) * X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * std::cosh(test_in[0]) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == std::cosh(test_in[0]) * X[0][1][2] + + std::sinh(test_in[0]) * X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * std::cosh(test_in[0]) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(CoshOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // cosh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = cosh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // cosh(x) + double test_out = std::cosh(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == std::sinh(test_in[0]) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::sinh(test_in[0]) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + std::sinh(test_in[0]) * X[0][0][1] + + 1.0 / 2.0 * + (std::cosh(test_in[0]) * X[0][0][0] * X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + std::sinh(test_in[0]) * X[0][1][1] + + 1.0 / 2.0 * + (std::cosh(test_in[0]) * X[0][1][0] * X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == std::sinh(test_in[0]) * X[0][0][2] + + std::cosh(test_in[0]) * X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * std::sinh(test_in[0]) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == std::sinh(test_in[0]) * X[0][1][2] + + std::cosh(test_in[0]) * X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * std::sinh(test_in[0]) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From cba71f0f3c917f3bb13a96d65fad9c73d2d4a861 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Mon, 6 Jan 2025 09:55:09 +0100 Subject: [PATCH 58/69] add tests for tanh, asin, acos --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 258 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 260 ++++++++++++++++++ 2 files changed, 518 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index bdd81aff9..a4c2e3751 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -1480,4 +1480,262 @@ BOOST_AUTO_TEST_CASE(CoshOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(TanhOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // tanh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = tanh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // tanh(x) + double test_out = std::tanh(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][0][1] + + 1.0 / 2.0 * + (-2.0 * std::tanh(test_in[0]) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) * X[0][0][0] * + X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][1][1] + + 1.0 / 2.0 * + (-2.0 * std::tanh(test_in[0]) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) * X[0][1][0] * + X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][0][2] + + (-2.0 * std::tanh(test_in[0]) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) * X[0][0][0] * + X[0][0][1]) + + 1.0 / 6.0 * + (4.0 * std::pow(std::tanh(test_in[0]), 2) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) - + 2.0 / std::pow(std::cosh(test_in[0]), 4)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][1][2] + + (-2.0 * std::tanh(test_in[0]) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) * X[0][1][0] * + X[0][1][1]) + + 1.0 / 6.0 * + (4.0 * std::pow(std::tanh(test_in[0]), 2) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) - + 2.0 / std::pow(std::cosh(test_in[0]), 4)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} +BOOST_AUTO_TEST_CASE(AsinOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // asin(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = asin(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // asin(x) + double test_out = std::asin(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][1] + + 1.0 / 2.0 * + (test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][1] + + 1.0 / 2.0 * + (test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][2] + + (test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 5.0 / 2.0) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][2] + + (test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 5.0 / 2.0) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(AcosOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // acos(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = acos(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // acos(x) + double test_out = std::acos(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][2] + + (-test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][0][0] * X[0][0][1] + + -1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 5.0 / 2.0) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][2] + + (-test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][1][0] * X[0][1][1] + + -1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 5.0 / 2.0) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 37d83e339..15dbf573c 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -1493,4 +1493,264 @@ BOOST_AUTO_TEST_CASE(CoshOperator_HOV_Forward) { myfree3(X); myfree3(Y); } +BOOST_AUTO_TEST_CASE(TanhOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // tanh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = tanh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // tanh(x) + double test_out = std::tanh(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][0][1] + + 1.0 / 2.0 * + (-2.0 * std::tanh(test_in[0]) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) * X[0][0][0] * + X[0][0][0]), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][1][1] + + 1.0 / 2.0 * + (-2.0 * std::tanh(test_in[0]) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) * X[0][1][0] * + X[0][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][0][2] + + (-2.0 * std::tanh(test_in[0]) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) * X[0][0][0] * + X[0][0][1]) + + 1.0 / 6.0 * + (4.0 * std::pow(std::tanh(test_in[0]), 2) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) - + 2.0 / std::pow(std::cosh(test_in[0]), 4)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / std::pow(std::cosh(test_in[0]), 2) * X[0][1][2] + + (-2.0 * std::tanh(test_in[0]) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) * X[0][1][0] * + X[0][1][1]) + + 1.0 / 6.0 * + (4.0 * std::pow(std::tanh(test_in[0]), 2) * 1.0 / + std::pow(std::cosh(test_in[0]), 2) - + 2.0 / std::pow(std::cosh(test_in[0]), 4)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} +BOOST_AUTO_TEST_CASE(AsinOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // asin(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = asin(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // asin(x) + double test_out = std::asin(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][1] + + 1.0 / 2.0 * + (test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][1] + + 1.0 / 2.0 * + (test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][2] + + (test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 5.0 / 2.0) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][2] + + (test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 5.0 / 2.0) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(AcosOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // acos(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = acos(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // acos(x) + double test_out = std::acos(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][0][2] + + (-test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][0][0] * X[0][0][1] + + -1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 5.0 / 2.0) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + -1.0 / std::sqrt(1.0 - std::pow(test_in[0], 2)) * X[0][1][2] + + (-test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 3.0 / 2.0)) * + X[0][1][0] * X[0][1][1] + + -1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 5.0 / 2.0) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From b3c16a8be29c8fdcc5b70c2e67bfc96e2673c7ff Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Mon, 6 Jan 2025 10:09:48 +0100 Subject: [PATCH 59/69] add tests for atan, log10 --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 157 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 159 ++++++++++++++++++ 2 files changed, 316 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index a4c2e3751..43cce7927 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -1738,4 +1738,161 @@ BOOST_AUTO_TEST_CASE(AcosOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(AtanOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // atan(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = atan(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // atan(x) + double test_out = std::atan(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][0][1] + + 1.0 / 2.0 * (-2.0 * test_in[0]) / + std::pow(1.0 + std::pow(test_in[0], 2), 2) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][1][1] + + 1.0 / 2.0 * (-2.0 * test_in[0]) / + std::pow(1.0 + std::pow(test_in[0], 2), 2) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][0][2] + + (-2.0 * test_in[0]) / + std::pow(1.0 + std::pow(test_in[0], 2), 2) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * + ((6.0 * std::pow(test_in[0], 2) - 2.0) / + std::pow(1.0 + std::pow(test_in[0], 2), 3)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][1][2] + + (-2.0 * test_in[0]) / + std::pow(1.0 + std::pow(test_in[0], 2), 2) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * + ((6.0 * std::pow(test_in[0], 2) - 2.0) / + std::pow(1.0 + std::pow(test_in[0], 2), 3)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(Log10Operator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // log10(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = log10(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // log10(x) + double test_out = std::log10(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + const double log_2_10 = std::log(10); + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / (test_in[0] * log_2_10) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / (test_in[0] * log_2_10) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / (test_in[0] * log_2_10) * X[0][0][1] + + 1.0 / 2.0 * (-1.0 / (std::pow(test_in[0], 2) * log_2_10)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / (test_in[0] * log_2_10) * X[0][1][1] + + 1.0 / 2.0 * (-1.0 / (std::pow(test_in[0], 2) * log_2_10)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / (test_in[0] * log_2_10) * X[0][0][2] + + (-1.0 / (std::pow(test_in[0], 2) * log_2_10)) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * (2.0 / (std::pow(test_in[0], 3) * log_2_10)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / (test_in[0] * log_2_10) * X[0][1][2] + + (-1.0 / (std::pow(test_in[0], 2) * log_2_10)) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * (2.0 / (std::pow(test_in[0], 3) * log_2_10)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 15dbf573c..779cbc3d9 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -1753,4 +1753,163 @@ BOOST_AUTO_TEST_CASE(AcosOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(AtanOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // atan(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = atan(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // atan(x) + double test_out = std::atan(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][0][1] + + 1.0 / 2.0 * (-2.0 * test_in[0]) / + std::pow(1.0 + std::pow(test_in[0], 2), 2) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][1][1] + + 1.0 / 2.0 * (-2.0 * test_in[0]) / + std::pow(1.0 + std::pow(test_in[0], 2), 2) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][0][2] + + (-2.0 * test_in[0]) / + std::pow(1.0 + std::pow(test_in[0], 2), 2) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * + ((6.0 * std::pow(test_in[0], 2) - 2.0) / + std::pow(1.0 + std::pow(test_in[0], 2), 3)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / (1.0 + std::pow(test_in[0], 2)) * X[0][1][2] + + (-2.0 * test_in[0]) / + std::pow(1.0 + std::pow(test_in[0], 2), 2) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * + ((6.0 * std::pow(test_in[0], 2) - 2.0) / + std::pow(1.0 + std::pow(test_in[0], 2), 3)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(Log10Operator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // log10(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = log10(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // log10(x) + double test_out = std::log10(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + const double log_2_10 = std::log(10); + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / (test_in[0] * log_2_10) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / (test_in[0] * log_2_10) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / (test_in[0] * log_2_10) * X[0][0][1] + + 1.0 / 2.0 * (-1.0 / (std::pow(test_in[0], 2) * log_2_10)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / (test_in[0] * log_2_10) * X[0][1][1] + + 1.0 / 2.0 * (-1.0 / (std::pow(test_in[0], 2) * log_2_10)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == + 1.0 / (test_in[0] * log_2_10) * X[0][0][2] + + (-1.0 / (std::pow(test_in[0], 2) * log_2_10)) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * (2.0 / (std::pow(test_in[0], 3) * log_2_10)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == + 1.0 / (test_in[0] * log_2_10) * X[0][1][2] + + (-1.0 / (std::pow(test_in[0], 2) * log_2_10)) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * (2.0 / (std::pow(test_in[0], 3) * log_2_10)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From dffc98bad65f61ab8b9abc961ebe960050fba77e Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Mon, 6 Jan 2025 10:44:23 +0100 Subject: [PATCH 60/69] add acosh tests --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 180 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 182 ++++++++++++++++++ 2 files changed, 362 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 43cce7927..785dfa3c3 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -1895,4 +1895,184 @@ BOOST_AUTO_TEST_CASE(Log10Operator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(AsinhOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // asinh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = asinh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // asinh(x) + double test_out = std::asinh(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][0][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow(std::pow(test_in[0], 2) + 1, 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][1][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow(std::pow(test_in[0], 2) + 1, 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][0][2] + + (-test_in[0] / std::pow(std::pow(test_in[0], 2) + 1, 3.0 / 2.0)) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) - 1.0) / + (std::pow(std::pow(test_in[0], 2) + 1, 5.0 / 2.0)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][1][2] + + (-test_in[0] / std::pow(std::pow(test_in[0], 2) + 1, 3.0 / 2.0)) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) - 1.0) / + (std::pow(std::pow(test_in[0], 2) + 1, 5.0 / 2.0)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(AcoshOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{1.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // acosh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = acosh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{1.2}; + + // acosh(x) + double test_out = std::acosh(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][0][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow((test_in[0] - 1.0) * (test_in[0] + 1.0), + 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][1][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow((test_in[0] - 1.0) * (test_in[0] + 1.0), + 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][0][2] + + -test_in[0] / + std::pow((test_in[0] - 1.0) * (test_in[0] + 1.0), 3.0 / 2.0) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(std::pow(test_in[0], 2) - 1.0, 5.0 / 2.0) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][1][2] + + -test_in[0] / + std::pow((test_in[0] - 1.0) * (test_in[0] + 1.0), 3.0 / 2.0) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(std::pow(test_in[0], 2) - 1.0, 5.0 / 2.0) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 779cbc3d9..1d13d0fcf 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -1912,4 +1912,186 @@ BOOST_AUTO_TEST_CASE(Log10Operator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(AsinhOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.5}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // asinh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = asinh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.5}; + + // asinh(x) + double test_out = std::asinh(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][0][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow(std::pow(test_in[0], 2) + 1, 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][1][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow(std::pow(test_in[0], 2) + 1, 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][0][2] + + (-test_in[0] / std::pow(std::pow(test_in[0], 2) + 1, 3.0 / 2.0)) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) - 1.0) / + (std::pow(std::pow(test_in[0], 2) + 1, 5.0 / 2.0)) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + 1.0 / std::sqrt(std::pow(test_in[0], 2) + 1) * X[0][1][2] + + (-test_in[0] / std::pow(std::pow(test_in[0], 2) + 1, 3.0 / 2.0)) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) - 1.0) / + (std::pow(std::pow(test_in[0], 2) + 1, 5.0 / 2.0)) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(AcoshOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{1.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // acosh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = acosh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{1.2}; + + // acosh(x) + double test_out = std::acosh(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][0][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow((test_in[0] - 1.0) * (test_in[0] + 1.0), + 3.0 / 2.0)) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][1][1] + + 1.0 / 2.0 * + (-test_in[0] / + std::pow((test_in[0] - 1.0) * (test_in[0] + 1.0), + 3.0 / 2.0)) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][0][2] + + -test_in[0] / + std::pow((test_in[0] - 1.0) * (test_in[0] + 1.0), 3.0 / 2.0) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(std::pow(test_in[0], 2) - 1.0, 5.0 / 2.0) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + 1.0 / std::sqrt((test_in[0] + 1.0) * (test_in[0] - 1.0)) * + X[0][1][2] + + -test_in[0] / + std::pow((test_in[0] - 1.0) * (test_in[0] + 1.0), 3.0 / 2.0) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * (2.0 * std::pow(test_in[0], 2) + 1) / + std::pow(std::pow(test_in[0], 2) - 1.0, 5.0 / 2.0) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From b9009b1126b3be008632adb746487779fbca100c Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Mon, 6 Jan 2025 10:52:46 +0100 Subject: [PATCH 61/69] add atanh tests --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 79 ++++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 80 +++++++++++++++++++ 2 files changed, 159 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 785dfa3c3..cc140f7b8 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -2075,4 +2075,83 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(AtanhOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // atanh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = atanh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // atanh(x) + double test_out = std::atanh(test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][0][1] + + 1.0 / 2.0 * 2.0 * test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 2) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][1][1] + + 1.0 / 2.0 * 2.0 * test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 2) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][0][2] + + 2.0 * test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 2) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * 2.0 * + (3.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 3) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][1][2] + + 2.0 * test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 2) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * 2.0 * + (3.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 3) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 1d13d0fcf..386cf99ce 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -2094,4 +2094,84 @@ BOOST_AUTO_TEST_CASE(AcoshOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(AtanhOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // atanh(x) + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = atanh(indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // atanh(x) + double test_out = std::atanh(test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][0][1] + + 1.0 / 2.0 * 2.0 * test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 2) * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][1][1] + + 1.0 / 2.0 * 2.0 * test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 2) * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][0][2] + + 2.0 * test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 2) * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * 2.0 * + (3.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 3) * + std::pow(X[0][0][0], 3), + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == 1.0 / (1.0 - std::pow(test_in[0], 2)) * X[0][1][2] + + 2.0 * test_in[0] / + std::pow(1.0 - std::pow(test_in[0], 2), 2) * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * 2.0 * + (3.0 * std::pow(test_in[0], 2) + 1) / + std::pow(1.0 - std::pow(test_in[0], 2), 3) * + std::pow(X[0][1][0], 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 69bb045d3bd3cd71f961d912783232f27e016f64 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Tue, 7 Jan 2025 20:33:15 +0100 Subject: [PATCH 62/69] add test for prefix increment --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 57 +++++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 57 +++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index cc140f7b8..1ee85f566 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -2154,4 +2154,61 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(InclOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + adouble dep; + + // x + 1 + trace_on(tag); + indep[0] <<= in[0]; + dep = ++indep[0]; + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // x + 1 + double test_out = ++test_in[0]; + + // change the value back, since the operator increases test_in[0] + test_in[0] = 0.2; + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == X[0][0][1], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == X[0][1][1], tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == X[0][0][2], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == X[0][1][2], tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 386cf99ce..d0a651a7c 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -2174,4 +2174,61 @@ BOOST_AUTO_TEST_CASE(AtanhOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(InclOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + adouble dep; + + // x + 1 + trace_on(tag); + indep[0] <<= in[0]; + dep = ++indep[0]; + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // x + 1 + double test_out = ++test_in[0]; + + // change the value back, since the operator increases test_in[0] + test_in[0] = 0.2; + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == X[0][0][1], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == X[0][1][1], tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == X[0][0][2], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == X[0][1][2], tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From ce126d31d6bfcf9a5f846259658110f46acc6fc7 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Wed, 8 Jan 2025 10:26:34 +0100 Subject: [PATCH 63/69] add tests for decrement, sign+, sign- and atan2 --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 363 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 370 ++++++++++++++++++ 2 files changed, 733 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 1ee85f566..e538bdb1c 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -2211,4 +2211,367 @@ BOOST_AUTO_TEST_CASE(InclOperator_HOV_Forward) { myfree3(Y); } +BOOST_AUTO_TEST_CASE(DeclOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + adouble dep; + + // x - 1 + trace_on(tag); + indep[0] <<= in[0]; + dep = --indep[0]; + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // x - 1 + double test_out = --test_in[0]; + + // change the value back, since the operator increases test_in[0] + test_in[0] = 0.2; + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == X[0][0][1], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == X[0][1][1], tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == X[0][0][2], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == X[0][1][2], tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(SignPlusOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + adouble dep; + + // x + trace_on(tag); + indep[0] <<= in[0]; + dep = +indep[0]; + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // x + double test_out = +test_in[0]; + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == X[0][0][1], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == X[0][1][1], tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == X[0][0][2], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == X[0][1][2], tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(SignMinusOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + adouble dep; + + //-x + trace_on(tag); + indep[0] <<= in[0]; + dep = -indep[0]; + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // -x + double test_out = -test_in[0]; + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == -X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == -X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == -X[0][0][1], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == -X[0][1][1], tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == -X[0][0][2], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == -X[0][1][2], tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(Atan2Operator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.2, 0.4}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // atan2(x, y) + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = atan2(indep[0], indep[1]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.2; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + X[0][1][0] = 2.1; + X[0][1][1] = -2.2; + X[0][1][2] = -2.1; + + std::vector test_in{0.2, 0.4}; + + // atan2(x, y) + double test_out = std::atan2(test_in[0], test_in[1]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST( + Y[0][0][0] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][0][0] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][0] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][1][0] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST( + Y[0][0][1] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][0][1] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][0][1] + + 1.0 / 2.0 * + (-2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[0][0][0] * X[0][0][0] + + 2.0 * (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[1][0][0] * X[0][0][0] + + 2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][1] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][1][1] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][1][1] + + 1.0 / 2.0 * + (-2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[0][1][0] * X[0][1][0] + + 2.0 * (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[1][1][0] * X[0][1][0] + + 2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][0][2] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][0][2] + + (-2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[0][0][0] * X[0][0][1] + + (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][0][0] * X[0][0][1] + + (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][0][1] * X[0][0][0] + + 2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][0][0] * X[1][0][1]) + + 1.0 / 6.0 * + (-2.0 * test_in[1] * + (std::pow(test_in[1], 2) - + 3.0 * std::pow(test_in[0], 2)) * + std::pow(X[0][0][0], 3) - + 6.0 * test_in[0] * + (std::pow(test_in[0], 2) - + 3.0 * std::pow(test_in[1], 2)) * + std::pow(X[0][0][0], 2) * X[1][0][0] + + 6.0 * test_in[1] * + (std::pow(test_in[1], 2) - + 3.0 * std::pow(test_in[0], 2)) * + std::pow(X[1][0][0], 2) * X[0][0][0] + + 2.0 * test_in[0] * + (std::pow(test_in[0], 2) - + 3.0 * std::pow(test_in[1], 2)) * + std::pow(X[1][0][0], 3)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][1][2] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][1][2] + + (-2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[0][1][0] * X[0][1][1] + + (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][1][0] * X[0][1][1] + + (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][1][1] * X[0][1][0] + + 2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][1][0] * X[1][1][1]) + + 1.0 / 6.0 * + (-2.0 * test_in[1] * + (std::pow(test_in[1], 2) - + 3.0 * std::pow(test_in[0], 2)) * + std::pow(X[0][1][0], 3) - + 6.0 * test_in[0] * + (std::pow(test_in[0], 2) - + 3.0 * std::pow(test_in[1], 2)) * + std::pow(X[0][1][0], 2) * X[1][1][0] + + 6.0 * test_in[1] * + (std::pow(test_in[1], 2) - + 3.0 * std::pow(test_in[0], 2)) * + std::pow(X[1][1][0], 2) * X[0][1][0] + + 2.0 * test_in[0] * + (std::pow(test_in[0], 2) - + 3.0 * std::pow(test_in[1], 2)) * + std::pow(X[1][1][0], 3)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index d0a651a7c..3c2d335c9 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -2231,4 +2231,374 @@ BOOST_AUTO_TEST_CASE(InclOperator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(DeclOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + adouble dep; + + // x - 1 + trace_on(tag); + indep[0] <<= in[0]; + dep = --indep[0]; + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // x - 1 + double test_out = --test_in[0]; + + // change the value back, since the operator increases test_in[0] + test_in[0] = 0.2; + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == X[0][0][1], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == X[0][1][1], tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == X[0][0][2], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == X[0][1][2], tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(SignPlusOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + adouble dep; + + // x + trace_on(tag); + indep[0] <<= in[0]; + dep = +indep[0]; + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // x + double test_out = +test_in[0]; + + // change the value back, since the operator increases test_in[0] + test_in[0] = 0.2; + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == X[0][0][1], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == X[0][1][1], tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == X[0][0][2], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == X[0][1][2], tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(SignMinusOperator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + adouble dep; + + //-x + trace_on(tag); + indep[0] <<= in[0]; + dep = -indep[0]; + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // -x + double test_out = -test_in[0]; + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == -X[0][0][0], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == -X[0][1][0], tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == -X[0][0][1], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == -X[0][1][1], tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == -X[0][0][2], tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == -X[0][1][2], tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + +BOOST_AUTO_TEST_CASE(Atan2Operator_HOV_Forward) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.2, 0.4}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // atan2(x, y) + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = atan2(indep[0], indep[1]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[1][0][0] = 1.1; + X[1][0][1] = -1.1; + X[1][0][2] = 1.2; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + X[0][1][0] = 2.1; + X[0][1][1] = -2.2; + X[0][1][2] = -2.1; + + std::vector test_in{0.2, 0.4}; + + // atan2(x, y) + double test_out = std::atan2(test_in[0], test_in[1]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST( + Y[0][0][0] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][0][0] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][0] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][1][0] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST( + Y[0][0][1] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][0][1] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][0][1] + + 1.0 / 2.0 * + (-2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[0][0][0] * X[0][0][0] + + 2.0 * (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[1][0][0] * X[0][0][0] + + 2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][1] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][1][1] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][1][1] + + 1.0 / 2.0 * + (-2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[0][1][0] * X[0][1][0] + + 2.0 * (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[1][1][0] * X[0][1][0] + + 2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + + std::pow(test_in[1], 2), + 2) * + X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][0][2] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][0][2] + + (-2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[0][0][0] * X[0][0][1] + + (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][0][0] * X[0][0][1] + + (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][0][1] * X[0][0][0] + + 2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][0][0] * X[1][0][1]) + + 1.0 / 6.0 * + (-2.0 * test_in[1] * + (std::pow(test_in[1], 2) - + 3.0 * std::pow(test_in[0], 2)) * + std::pow(X[0][0][0], 3) - + 6.0 * test_in[0] * + (std::pow(test_in[0], 2) - + 3.0 * std::pow(test_in[1], 2)) * + std::pow(X[0][0][0], 2) * X[1][0][0] + + 6.0 * test_in[1] * + (std::pow(test_in[1], 2) - + 3.0 * std::pow(test_in[0], 2)) * + std::pow(X[1][0][0], 2) * X[0][0][0] + + 2.0 * test_in[0] * + (std::pow(test_in[0], 2) - + 3.0 * std::pow(test_in[1], 2)) * + std::pow(X[1][0][0], 3)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 3), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + test_in[1] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[0][1][2] - + test_in[0] / (std::pow(test_in[0], 2) + std::pow(test_in[1], 2)) * + X[1][1][2] + + (-2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[0][1][0] * X[0][1][1] + + (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][1][0] * X[0][1][1] + + (std::pow(test_in[0], 2) - std::pow(test_in[1], 2)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][1][1] * X[0][1][0] + + 2.0 * test_in[0] * test_in[1] / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 2) * + X[1][1][0] * X[1][1][1]) + + 1.0 / 6.0 * + (-2.0 * test_in[1] * + (std::pow(test_in[1], 2) - + 3.0 * std::pow(test_in[0], 2)) * + std::pow(X[0][1][0], 3) - + 6.0 * test_in[0] * + (std::pow(test_in[0], 2) - + 3.0 * std::pow(test_in[1], 2)) * + std::pow(X[0][1][0], 2) * X[1][1][0] + + 6.0 * test_in[1] * + (std::pow(test_in[1], 2) - + 3.0 * std::pow(test_in[0], 2)) * + std::pow(X[1][1][0], 2) * X[0][1][0] + + 2.0 * test_in[0] * + (std::pow(test_in[0], 2) - + 3.0 * std::pow(test_in[1], 2)) * + std::pow(X[1][1][0], 3)) / + std::pow(std::pow(test_in[0], 2) + std::pow(test_in[1], 2), + 3), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 65d8cf07031ae562529bb53388243feb37b3b05b Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Wed, 8 Jan 2025 14:38:00 +0100 Subject: [PATCH 64/69] Here we fix the bug where the currTay pointer was decremented twice, leading to a segfault. Before this fix, the macro-function ADOLC_GET_TAYLOR(arg) was called twice if we had situation like a = pow(a, n) where "a" is an adouble. In this case, the location of arg is the same as the location of res. Thus, to obtain the correct input value, we have to read the value of "currTay - 1", which stores the input value of "a" for pow(a, n). However, the function "adub pow(const badouble &x, double coval)" increments the "currTay" pointer once. The next operation would skip its input when calling "ADOLC_GET_TAYLOR" and the last operation (assign_ind) would access a non-valid pointer. --- ADOL-C/src/fo_rev.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADOL-C/src/fo_rev.cpp b/ADOL-C/src/fo_rev.cpp index b53c820ce..afcb20e22 100644 --- a/ADOL-C/src/fo_rev.cpp +++ b/ADOL-C/src/fo_rev.cpp @@ -1523,7 +1523,7 @@ int int_reverse_safe(short tnum, /* tape id */ /* olvo 980921 changed order to allow x=pow(x,n) */ r0 = TRES; if (arg == res) - ADOLC_GET_TAYLOR(arg); + TARG = *(ADOLC_CURRENT_TAPE_INFOS.currTay - 1); if (TARG == 0.0) r0 = 0.0; else From 616b728f2cb742df6afbb08f3d2c780b41d132c1 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Wed, 8 Jan 2025 14:58:17 +0100 Subject: [PATCH 65/69] add test for pow(a, x) --- ADOL-C/boost-test/traceOperatorVector.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ADOL-C/boost-test/traceOperatorVector.cpp b/ADOL-C/boost-test/traceOperatorVector.cpp index f87206217..e2e9bd6fe 100644 --- a/ADOL-C/boost-test/traceOperatorVector.cpp +++ b/ADOL-C/boost-test/traceOperatorVector.cpp @@ -1804,9 +1804,8 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Forward_1) { myfree1(y); myfree2(yd); } -/* -BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_1) -{ + +BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_1) { double a = 2.3, e = 3.5, aout; adouble ad; @@ -1829,12 +1828,11 @@ BOOST_AUTO_TEST_CASE(PowOperator_FOV_Reverse_1) 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(PowOperator_FOV_Forward_2) { double a = 2.3, b = 3.5, out; adouble ad, bd; From 697979bbb7ff1f3593be74bf21b42a702da45058 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Wed, 8 Jan 2025 15:03:01 +0100 Subject: [PATCH 66/69] add tests for a^x --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 71 ++++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 72 +++++++++++++++++++ 2 files changed, 143 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index e538bdb1c..6c506cc88 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -2574,4 +2574,75 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(Pow_Operator_HOV_Forward_1) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x^y + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = pow(indep[0], 3.2); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // x^y + double test_out = std::pow(test_in[0], 3.2); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == std::pow(test_in[0], 2.2) * 3.2 * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::pow(test_in[0], 2.2) * 3.2 * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == std::pow(test_in[0], 2.2) * 3.2 * X[0][0][1] + + 1.0 / 2.0 * std::pow(test_in[0], 1.2) * 7.04 * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == std::pow(test_in[0], 2.2) * 3.2 * X[0][1][1] + + 1.0 / 2.0 * std::pow(test_in[0], 1.2) * 7.04 * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == std::pow(test_in[0], 2.2) * 3.2 * X[0][0][2] + + std::pow(test_in[0], 1.2) * 7.04 * X[0][0][0] * + X[0][0][1] + + 1.0 / 6.0 * std::pow(test_in[0], 0.2) * 8.448 * + X[0][0][0] * X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == std::pow(test_in[0], 2.2) * 3.2 * X[0][1][2] + + std::pow(test_in[0], 1.2) * 7.04 * X[0][1][0] * + X[0][1][1] + + 1.0 / 6.0 * std::pow(test_in[0], 0.2) * 8.448 * + X[0][1][0] * X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 3c2d335c9..958bf4c34 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -2601,4 +2601,76 @@ BOOST_AUTO_TEST_CASE(Atan2Operator_HOV_Forward) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(Pow_Operator_HOV_Forward_1) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.2}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x^y + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = pow(indep[0], 3.2); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{0.2}; + + // x^y + double test_out = std::pow(test_in[0], 3.2); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == std::pow(test_in[0], 2.2) * 3.2 * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::pow(test_in[0], 2.2) * 3.2 * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == std::pow(test_in[0], 2.2) * 3.2 * X[0][0][1] + + 1.0 / 2.0 * std::pow(test_in[0], 1.2) * 7.04 * + X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == std::pow(test_in[0], 2.2) * 3.2 * X[0][1][1] + + 1.0 / 2.0 * std::pow(test_in[0], 1.2) * 7.04 * + X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == std::pow(test_in[0], 2.2) * 3.2 * X[0][0][2] + + std::pow(test_in[0], 1.2) * 7.04 * X[0][0][0] * + X[0][0][1] + + 1.0 / 6.0 * std::pow(test_in[0], 0.2) * 8.448 * + X[0][0][0] * X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == std::pow(test_in[0], 2.2) * 3.2 * X[0][1][2] + + std::pow(test_in[0], 1.2) * 7.04 * X[0][1][0] * + X[0][1][1] + + 1.0 / 6.0 * std::pow(test_in[0], 0.2) * 8.448 * + X[0][1][0] * X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From e6cdb5f36acb170c843b5c3f955c9f4689f97f20 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 9 Jan 2025 11:52:01 +0100 Subject: [PATCH 67/69] add test for adouble ^ adouble --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 150 +++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 151 ++++++++++++++++++ 2 files changed, 301 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index 6c506cc88..f99123534 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -2645,4 +2645,154 @@ BOOST_AUTO_TEST_CASE(Pow_Operator_HOV_Forward_1) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(PowOperator_HOV_Forward_2) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{0.2, 2.0}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x^y + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], indep[1]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + X[1][0][0] = 1.0; + X[1][0][1] = -1.0; + X[1][0][2] = 1.1; + + X[1][1][0] = 2.0; + X[1][1][1] = -2.1; + X[1][1][2] = -2.0; + + std::vector test_in{0.2, 2.0}; + + // x^y + double test_out = std::pow(test_in[0], test_in[1]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * + X[0][0][0] + + std::pow(test_in[0], test_in[1]) * + std::log(test_in[0]) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * + X[0][1][0] + + std::pow(test_in[0], test_in[1]) * + std::log(test_in[0]) * X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST( + Y[0][0][1] == + std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * X[0][0][1] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + X[1][0][1] + + 1.0 / 2.0 * + (std::pow(test_in[0], test_in[1] - 2.0) * (test_in[1] - 1.0) * + test_in[1] * X[0][0][0] * X[0][0][0] + + 2.0 * std::pow(test_in[0], test_in[1] - 1.0) * + (1.0 + test_in[1] * std::log(test_in[0])) * X[0][0][0] * + X[1][0][0] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + std::log(test_in[0]) * X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][1] == + std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * X[0][1][1] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + X[1][1][1] + + 1.0 / 2.0 * + (std::pow(test_in[0], test_in[1] - 2.0) * (test_in[1] - 1.0) * + test_in[1] * X[0][1][0] * X[0][1][0] + + 2.0 * std::pow(test_in[0], test_in[1] - 1.0) * + (1.0 + test_in[1] * std::log(test_in[0])) * X[0][1][0] * + X[1][1][0] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + std::log(test_in[0]) * X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * X[0][0][2] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + X[1][0][2] + + (std::pow(test_in[0], test_in[1] - 2.0) * (test_in[1] - 1.0) * + test_in[1] * X[0][0][0] * X[0][0][1] + + 2.0 * std::pow(test_in[0], test_in[1] - 1.0) * + (1.0 + test_in[1] * std::log(test_in[0])) * X[0][0][0] * + X[1][0][1] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + std::log(test_in[0]) * X[1][0][0] * X[1][0][1]) + + 1.0 / 6.0 * + ((test_in[1] - 2.0) * (test_in[1] - 1.0) * test_in[1] * + std::pow(test_in[0], test_in[1] - 3.0) * + std::pow(X[0][0][0], 3) + + 3.0 * std::pow(test_in[0], test_in[1] - 2.0) * + ((test_in[1] - 1.0) * test_in[1] * std::log(test_in[0]) + + 2.0 * test_in[1] - 1) * + X[0][0][0] * X[0][0][0] * X[1][0][0] + + 3.0 * std::pow(test_in[0], test_in[1] - 1.0) * + std::log(test_in[0]) * + (test_in[1] * std::log(test_in[0]) + 2.0) * X[0][0][0] * + X[1][0][0] * X[1][0][0] + + std::pow(test_in[0], test_in[1]) * + std::pow(std::log(test_in[0]), 3) * + std::pow(X[1][0][0], 3)), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * X[0][1][2] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + X[1][1][2] + + (std::pow(test_in[0], test_in[1] - 2.0) * (test_in[1] - 1.0) * + test_in[1] * X[0][1][0] * X[0][1][1] + + 2.0 * std::pow(test_in[0], test_in[1] - 1.0) * + (1.0 + test_in[1] * std::log(test_in[0])) * X[0][1][0] * + X[1][1][1] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + std::log(test_in[0]) * X[1][1][0] * X[1][1][1]) + + 1.0 / 6.0 * + ((test_in[1] - 2.0) * (test_in[1] - 1.0) * test_in[1] * + std::pow(test_in[0], test_in[1] - 3.0) * + std::pow(X[0][1][0], 3) + + 3.0 * std::pow(test_in[0], test_in[1] - 2.0) * + ((test_in[1] - 1.0) * test_in[1] * std::log(test_in[0]) + + 2.0 * test_in[1] - 1) * + X[0][1][0] * X[0][1][0] * X[1][1][0] + + 3.0 * std::pow(test_in[0], test_in[1] - 1.0) * + std::log(test_in[0]) * + (test_in[1] * std::log(test_in[0]) + 2.0) * X[0][1][0] * + X[1][1][0] * X[1][1][0] + + std::pow(test_in[0], test_in[1]) * + std::pow(std::log(test_in[0]), 3) * + std::pow(X[1][1][0], 3)), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 958bf4c34..6022282aa 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -2673,4 +2673,155 @@ BOOST_AUTO_TEST_CASE(Pow_Operator_HOV_Forward_1) { myfree3(X); myfree3(Y); } +BOOST_AUTO_TEST_CASE(PowOperator_HOV_Forward_2) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 2; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{0.2, 2.0}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x^y + trace_on(tag); + indep[0] <<= in[0]; + indep[1] <<= in[1]; + adouble dep = pow(indep[0], indep[1]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + X[1][0][0] = 1.0; + X[1][0][1] = -1.0; + X[1][0][2] = 1.1; + + X[1][1][0] = 2.0; + X[1][1][1] = -2.1; + X[1][1][2] = -2.0; + + std::vector test_in{0.2, 2.0}; + + // x^y + double test_out = std::pow(test_in[0], test_in[1]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + // first derivative + BOOST_TEST(Y[0][0][0] == std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * + X[0][0][0] + + std::pow(test_in[0], test_in[1]) * + std::log(test_in[0]) * X[1][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * + X[0][1][0] + + std::pow(test_in[0], test_in[1]) * + std::log(test_in[0]) * X[1][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST( + Y[0][0][1] == + std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * X[0][0][1] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + X[1][0][1] + + 1.0 / 2.0 * + (std::pow(test_in[0], test_in[1] - 2.0) * (test_in[1] - 1.0) * + test_in[1] * X[0][0][0] * X[0][0][0] + + 2.0 * std::pow(test_in[0], test_in[1] - 1.0) * + (1.0 + test_in[1] * std::log(test_in[0])) * X[0][0][0] * + X[1][0][0] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + std::log(test_in[0]) * X[1][0][0] * X[1][0][0]), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][1] == + std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * X[0][1][1] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + X[1][1][1] + + 1.0 / 2.0 * + (std::pow(test_in[0], test_in[1] - 2.0) * (test_in[1] - 1.0) * + test_in[1] * X[0][1][0] * X[0][1][0] + + 2.0 * std::pow(test_in[0], test_in[1] - 1.0) * + (1.0 + test_in[1] * std::log(test_in[0])) * X[0][1][0] * + X[1][1][0] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + std::log(test_in[0]) * X[1][1][0] * X[1][1][0]), + tt::tolerance(tol)); + + // third derivative + BOOST_TEST( + Y[0][0][2] == + std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * X[0][0][2] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + X[1][0][2] + + (std::pow(test_in[0], test_in[1] - 2.0) * (test_in[1] - 1.0) * + test_in[1] * X[0][0][0] * X[0][0][1] + + 2.0 * std::pow(test_in[0], test_in[1] - 1.0) * + (1.0 + test_in[1] * std::log(test_in[0])) * X[0][0][0] * + X[1][0][1] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + std::log(test_in[0]) * X[1][0][0] * X[1][0][1]) + + 1.0 / 6.0 * + ((test_in[1] - 2.0) * (test_in[1] - 1.0) * test_in[1] * + std::pow(test_in[0], test_in[1] - 3.0) * + std::pow(X[0][0][0], 3) + + 3.0 * std::pow(test_in[0], test_in[1] - 2.0) * + ((test_in[1] - 1.0) * test_in[1] * std::log(test_in[0]) + + 2.0 * test_in[1] - 1) * + X[0][0][0] * X[0][0][0] * X[1][0][0] + + 3.0 * std::pow(test_in[0], test_in[1] - 1.0) * + std::log(test_in[0]) * + (test_in[1] * std::log(test_in[0]) + 2.0) * X[0][0][0] * + X[1][0][0] * X[1][0][0] + + std::pow(test_in[0], test_in[1]) * + std::pow(std::log(test_in[0]), 3) * + std::pow(X[1][0][0], 3)), + tt::tolerance(tol)); + BOOST_TEST( + Y[0][1][2] == + std::pow(test_in[0], test_in[1] - 1.0) * test_in[1] * X[0][1][2] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + X[1][1][2] + + (std::pow(test_in[0], test_in[1] - 2.0) * (test_in[1] - 1.0) * + test_in[1] * X[0][1][0] * X[0][1][1] + + 2.0 * std::pow(test_in[0], test_in[1] - 1.0) * + (1.0 + test_in[1] * std::log(test_in[0])) * X[0][1][0] * + X[1][1][1] + + std::pow(test_in[0], test_in[1]) * std::log(test_in[0]) * + std::log(test_in[0]) * X[1][1][0] * X[1][1][1]) + + 1.0 / 6.0 * + ((test_in[1] - 2.0) * (test_in[1] - 1.0) * test_in[1] * + std::pow(test_in[0], test_in[1] - 3.0) * + std::pow(X[0][1][0], 3) + + 3.0 * std::pow(test_in[0], test_in[1] - 2.0) * + ((test_in[1] - 1.0) * test_in[1] * std::log(test_in[0]) + + 2.0 * test_in[1] - 1) * + X[0][1][0] * X[0][1][0] * X[1][1][0] + + 3.0 * std::pow(test_in[0], test_in[1] - 1.0) * + std::log(test_in[0]) * + (test_in[1] * std::log(test_in[0]) + 2.0) * X[0][1][0] * + X[1][1][0] * X[1][1][0] + + std::pow(test_in[0], test_in[1]) * + std::pow(std::log(test_in[0]), 3) * + std::pow(X[1][1][0], 3)), + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 3471a31d42d5b2e505743edb76026032ae621809 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 9 Jan 2025 12:00:22 +0100 Subject: [PATCH 68/69] add test for double ^ adouble --- ADOL-C/boost-test/uni5_for/hov_forward.cpp | 74 ++++++++++++++++++ ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp | 75 +++++++++++++++++++ 2 files changed, 149 insertions(+) diff --git a/ADOL-C/boost-test/uni5_for/hov_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_forward.cpp index f99123534..5bd290a6c 100644 --- a/ADOL-C/boost-test/uni5_for/hov_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_forward.cpp @@ -2795,4 +2795,78 @@ BOOST_AUTO_TEST_CASE(PowOperator_HOV_Forward_2) { myfree3(X); myfree3(Y); } + +BOOST_AUTO_TEST_CASE(PowOperator_HOV_Forward_3) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + std::vector in{2.1}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x^y + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = pow(1.5, indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{2.1}; + + // x^y + double test_out = std::pow(1.5, test_in[0]); + + hov_forward(tag, dim_out, dim_in, degree, num_dirs, test_in.data(), X, + out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + const double log_x = std::log(1.5); + // first derivative + BOOST_TEST(Y[0][0][0] == std::pow(1.5, test_in[0]) * log_x * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::pow(1.5, test_in[0]) * log_x * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == std::pow(1.5, test_in[0]) * log_x * X[0][0][1] + + 1.0 / 2.0 * std::pow(1.5, test_in[0]) * log_x * + log_x * X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == std::pow(1.5, test_in[0]) * log_x * X[0][1][1] + + 1.0 / 2.0 * std::pow(1.5, test_in[0]) * log_x * + log_x * X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == std::pow(1.5, test_in[0]) * log_x * X[0][0][2] + + std::pow(1.5, test_in[0]) * log_x * log_x * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * std::pow(1.5, test_in[0]) * log_x * + log_x * log_x * X[0][0][0] * X[0][0][0] * + X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == std::pow(1.5, test_in[0]) * log_x * X[0][1][2] + + std::pow(1.5, test_in[0]) * log_x * log_x * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * std::pow(1.5, test_in[0]) * log_x * + log_x * log_x * X[0][1][0] * X[0][1][0] * + X[0][1][0], + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp index 6022282aa..f4c575ed1 100644 --- a/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp +++ b/ADOL-C/boost-test/uni5_for/hov_wk_forward.cpp @@ -2824,4 +2824,79 @@ BOOST_AUTO_TEST_CASE(PowOperator_HOV_Forward_2) { myfree3(Y); } +BOOST_AUTO_TEST_CASE(PowOperator_HOV_Forward_3) { + const int16_t tag = 0; + const size_t dim_out = 1; + const size_t dim_in = 1; + const size_t degree = 3; + const size_t num_dirs = 2; + const short keep = 1; + std::vector in{2.1}; + std::vector indep(dim_in); + std::vector out(dim_out); + + // x^y + trace_on(tag); + indep[0] <<= in[0]; + adouble dep = pow(1.5, indep[0]); + dep >>= out[0]; + trace_off(); + + double ***X = myalloc3(dim_in, num_dirs, degree); + double ***Y = myalloc3(dim_out, num_dirs, degree); + + X[0][0][0] = 1.0; + X[0][0][1] = -1.0; + X[0][0][2] = 1.1; + + X[0][1][0] = 2.0; + X[0][1][1] = -2.1; + X[0][1][2] = -2.0; + + std::vector test_in{2.1}; + + // x^y + double test_out = std::pow(1.5, test_in[0]); + + hov_wk_forward(tag, dim_out, dim_in, degree, keep, num_dirs, test_in.data(), + X, out.data(), Y); + + BOOST_TEST(out[0] == test_out, tt::tolerance(tol)); + + const double log_x = std::log(1.5); + // first derivative + BOOST_TEST(Y[0][0][0] == std::pow(1.5, test_in[0]) * log_x * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][0] == std::pow(1.5, test_in[0]) * log_x * X[0][1][0], + tt::tolerance(tol)); + + // second derivative + BOOST_TEST(Y[0][0][1] == std::pow(1.5, test_in[0]) * log_x * X[0][0][1] + + 1.0 / 2.0 * std::pow(1.5, test_in[0]) * log_x * + log_x * X[0][0][0] * X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][1] == std::pow(1.5, test_in[0]) * log_x * X[0][1][1] + + 1.0 / 2.0 * std::pow(1.5, test_in[0]) * log_x * + log_x * X[0][1][0] * X[0][1][0], + tt::tolerance(tol)); + + // third derivative + BOOST_TEST(Y[0][0][2] == std::pow(1.5, test_in[0]) * log_x * X[0][0][2] + + std::pow(1.5, test_in[0]) * log_x * log_x * + X[0][0][0] * X[0][0][1] + + 1.0 / 6.0 * std::pow(1.5, test_in[0]) * log_x * + log_x * log_x * X[0][0][0] * X[0][0][0] * + X[0][0][0], + tt::tolerance(tol)); + BOOST_TEST(Y[0][1][2] == std::pow(1.5, test_in[0]) * log_x * X[0][1][2] + + std::pow(1.5, test_in[0]) * log_x * log_x * + X[0][1][0] * X[0][1][1] + + 1.0 / 6.0 * std::pow(1.5, test_in[0]) * log_x * + log_x * log_x * X[0][1][0] * X[0][1][0] * + X[0][1][0], + tt::tolerance(tol)); + myfree3(X); + myfree3(Y); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 29d60c0520ac4fb68a456700cbda4d4b3180b00e Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Thu, 9 Jan 2025 14:09:36 +0100 Subject: [PATCH 69/69] rename to cpp --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18aeb442d..4cfd78981 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ target_include_directories(adolc # Set an include directory for the internally used library headers. # # This includes the files uni5_for.cpp, fo_rev.cpp, and ho_rev.cpp. Even though -# they end with .c, they are used like header files. Together with some +# they end with .cpp, they are used like header files. Together with some # preprocessor trickery this is an old-fashioned way to do generic programming. target_include_directories(adolc PRIVATE