[ADOL-C] inverse_tensor_eval memory error

Andrea Walther andrea.walther at uni-paderborn.de
Fri Aug 4 02:14:09 EDT 2017


Dear Brad,

thanks for the hint!

we will have a look at it as soon as possible.

Best regards

Andrea

Am 03.08.2017 um 20:32 schrieb Brad Bell:
> I have am trying to run a simple example using inverse_tensor_eval. To 
> be specific
>      F(z) = sin(z)
> I have been unable to figure out why I am getting memory errors when I 
> run the
> code included below. When I run it in valgrind, I get the following output:
> ================================================================================================= 
> 
> build>valgrind ./adolc
> ==29183== Memcheck, a memory error detector
> ==29183== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
> ==29183== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright 
> info
> ==29183== Command: ./adolc
> ==29183==
> ==29183== Invalid free() / delete / delete[] / realloc()
> ==29183==    at 0x4C2ED4A: free (vg_replace_malloc.c:530)
> ==29183==    by 0x4F8B731: inverse_tensor_eval (taylor.c:741)
> ==29183==    by 0x401094: main (adolc.cpp:37)
> ==29183==  Address 0x699cf38 is 8 bytes inside a block of size 32 alloc'd
> ==29183==    at 0x4C2FA50: calloc (vg_replace_malloc.c:711)
> ==29183==    by 0x4E63FA5: myalloc2 (adalloc.c:125)
> ==29183==    by 0x4F8B1B5: inverse_tensor_eval (taylor.c:688)
> ==29183==    by 0x401094: main (adolc.cpp:37)
> ==29183==
> ==29183== Invalid free() / delete / delete[] / realloc()
> ==29183==    at 0x4C2ED4A: free (vg_replace_malloc.c:530)
> ==29183==    by 0x4F8B74C: inverse_tensor_eval (taylor.c:743)
> ==29183==    by 0x401094: main (adolc.cpp:37)
> ==29183==  Address 0x699cf98 is 8 bytes inside a block of size 32 alloc'd
> ==29183==    at 0x4C2FA50: calloc (vg_replace_malloc.c:711)
> ==29183==    by 0x4E63FA5: myalloc2 (adalloc.c:125)
> ==29183==    by 0x4F8B1D2: inverse_tensor_eval (taylor.c:689)
> ==29183==    by 0x401094: main (adolc.cpp:37)
> ==29183==
> tensor[0][0] = 0.523599
> tensor[0][1] = 1.1547
> tensor[0][2] = 0.7698
> z = 0.523599
> zp = 1.1547
> zpp = 0.7698
> adolc: Done
> ==29183==
> ==29183== HEAP SUMMARY:
> ==29183==     in use at exit: 1,094 bytes in 20 blocks
> ==29183==   total heap usage: 107 allocs, 89 frees, 19,481,090 bytes 
> allocated
> ==29183==
> ==29183== LEAK SUMMARY:
> ==29183==    definitely lost: 104 bytes in 6 blocks
> ==29183==    indirectly lost: 8 bytes in 1 blocks
> ==29183==      possibly lost: 0 bytes in 0 blocks
> ==29183==    still reachable: 982 bytes in 13 blocks
> ==29183==         suppressed: 0 bytes in 0 blocks
> ==29183== Rerun with --leak-check=full to see details of leaked memory
> ==29183==
> ==29183== For counts of detected and suppressed errors, rerun with: -v
> ==29183== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
> build>
> ================================================================================================= 
> 
> # include <adolc/adolc.h>
> int main(void)
> {
>      int n = 1;    // number of independent and dependent variables
>      int d = 2;    // highest order derivative
>      int p = 1;    // number of directions
>      int size = 3; // [(p + d) choose d] = (p+d-0) *...* (p+1) / (1 
> *...* d)
>      //
>      double* S[1];      // seed matrix S[n][p]
>      S[0] = new double[p];
>      //
>      double* tensor[1]; // partials of z w.r.t x tensor[n][size]
>      tensor[0] = new double[size];
> 
>      // Set Seed matrix to identity
>      S[0][0] = 1.0;
> 
>      // independent and dependent variables
>      adouble az[1], ay[1]; // az[n], ay[n]
>      double  z[1],  y[1];  //  z[n],  y[n]
> 
>      // record operations for y = F(z) = sin(z)
>      short int tag = 1;     // tape identifier
>      trace_on(tag);         // start recording
>      z[0]  = 1.0;           // value during recording
>      az[0] <<= z[0];        // independent variable
>      ay[0] = sin(az[0]);    // function evaluation
>      ay[0] >>= y[0];        // dependent variable
>      trace_off();           // turn off recording
> 
>      // evaluate inverse of F at x0
>      double x0 = 0.5;            // argument for inverse
>      z[0]      = std::asin(x0);  // F^-1 (x0) = z0
>      inverse_tensor_eval(tag, n, d, p, z, tensor, S);
> 
>      // print tensor
>      for(int j = 0; j < size; j++)
>      {   std::cout << "tensor[0][" << j << "] = " << tensor[0][j] << "\n";
>      }
> 
>      // derivative of F^-1 (x0)  =  1.0 / sqrt( 1 - x0 * x0 )
>      double zp = 1.0 / std::sqrt(1.0 - x0 * x0 );
> 
>      // second derivative of F^-1 (x0)  =  x0 / sqrt( 1 - x0 * x0 )^3
>      double zpp = x0 * zp * zp * zp;
> 
>      // print derivatives for z
>      std::cout << "z = " << z[0] << "\n";
>      std::cout << "zp = " << zp << "\n";
>      std::cout << "zpp = " << zpp << "\n";
>      //
>      delete [] S[0];
>      delete [] tensor[0];
>      //
>      std::cout << "adolc: Done\n";
>      return 0;
> }
> 
> _______________________________________________
> ADOL-C mailing list
> ADOL-C at list.coin-or.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_adol-2Dc&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=sszAvj5-wJal_YaNkOXa8y4Mts3w-L-xYDXwPYeYptQ&m=eI6wsRAC-v0R8vwRH9XGHzd6xQ3BcC-chdkcdB4kWYo&s=taZPyAvFLleFWuqkK2QcIVoqzT2WsGBZEm3jk310N9o&e= 
> 

-- 
Prof. Dr. Andrea Walther
Lehrstuhl fuer Mathematik und ihre Anwendungen
Institut fuer Mathematik
Universitaet Paderborn
Warburger Str. 100
33098 Paderborn

Email: andrea.walther at uni-paderborn.de
Phone: ++49 5251 602721
Fax:   ++49 5251 603728

**********



More information about the ADOL-C mailing list