Changeset 2341


Ignore:
Timestamp:
Apr 6, 2012 2:42:00 PM (8 years ago)
Author:
bradbell
Message:
  1. Deprecate memory_leak and replace it by thread_alloc::free_all.
  1. Move the special case of examples and tests that use example/base_alloc.hpp

to after memory check because it causes static memory to be allocated
by thread_alloc.hpp (for the value nan).

  1. Remove tracking of static memory allocation in examples

(no longer necessary).

dir_copy.sh: script that moves changes from one machine to another.

Location:
trunk
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/cppad/memory_leak.hpp

    r2339 r2341  
    2828$index check, memory leak$$
    2929$index static, memory leak check$$
     30
     31$head Deprecated$$
     32$index deprecated, memory leak$$
     33This routine has been deprecated.
     34You should instead use the routine $cref ta_free_all$$.
    3035
    3136$head Syntax$$
  • trunk/cppad/thread_alloc.hpp

    r2340 r2341  
    804804
    805805        \return
    806         pointer to the beginning of the memory allocted for use.
     806        pointer to the beginning of the memory allocated for use.
    807807        */
    808808        static void* get_memory(size_t min_bytes, size_t& cap_bytes)
     
    14931493                thread_alloc::return_memory( reinterpret_cast<void*>(array) );
    14941494        }
     1495/* -----------------------------------------------------------------------
     1496$begin ta_free_all$$
     1497$spell
     1498        alloc
     1499        bool
     1500        inuse
     1501$$
     1502
     1503$section Free All Memory That Was Allocated for Use by thread_alloc$$
     1504
     1505$index free, all thread_alloc$$
     1506$index thread_alloc, free all$$
     1507
     1508$head Syntax$$
     1509$icode%ok% = thread_alloc::free_all()%$$.
     1510
     1511$head Purpose$$
     1512Returns all memory that was used by $code thread_alloc$$ to the system.
     1513
     1514$head ok$$
     1515The return value $icode ok$$ has prototype
     1516$codei%
     1517        bool %ok%
     1518%$$
     1519Its value will be $code true$$ if all the memory can be freed.
     1520This requires that for all $icode thread$$ indices, there is no memory
     1521$cref/inuse/ta_inuse/$$; i.e.,
     1522$codei%
     1523        0 == thread_alloc::inuse(%thread%)
     1524%$$
     1525Otherwise, the return value will be false.
     1526
     1527$head Example$$
     1528$cref/thread_alloc.cpp/$$
     1529$end
     1530*/
     1531        /*!
     1532        Return to the system all thread_alloc memory that is not currently inuse.
     1533
     1534        \return
     1535        If no \c thread_alloc memory is currently inuse,
     1536        all memory is returned to the system and the return value is true.
     1537        Otherwise the return value is false.
     1538        */
     1539        static bool free_all(void)
     1540        {       bool ok = true;
     1541                size_t thread = CPPAD_MAX_NUM_THREADS;
     1542                while(thread--)
     1543                {       ok &= inuse(thread) == 0;
     1544                        free_available(thread);
     1545                }
     1546                return ok;
     1547        }
    14951548};
    14961549
  • trunk/cppad_ipopt/example/example.cpp

    r2005 r2341  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    5757        using std::endl;
    5858        assert( ok || (Run_error_count > 0) );
    59         if( CppAD::memory_leak() )
     59        if( CppAD::thread_alloc::free_all() )
     60        {       Run_ok_count++;
     61                cout << "OK:    " << "No memory leak detected" << endl;
     62        }
     63        else
    6064        {       ok = false;
    6165                Run_error_count++;
    6266                cout << "Error: " << "memory leak detected" << endl;
    63         }
    64         else
    65         {       Run_ok_count++;
    66                 cout << "OK:    " << "No memory leak detected" << endl;
    6767        }
    6868        // convert int(size_t) to avoid warning on _MSC_VER systems
  • trunk/cppad_ipopt/test/test_more.cpp

    r2005 r2341  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    6060        assert( ok || (Run_error_count > 0) );
    6161
    62         if( CppAD::memory_leak() )
     62        if( CppAD::thread_alloc::free_all() )
     63        {       Run_ok_count++;
     64                cout << "OK:    " << "No memory leak detected" << endl;
     65        }
     66        else
    6367        {       ok = false;
    6468                Run_error_count++;
    6569                cout << "Error: " << "memory leak detected" << endl;
    66         }
    67         else
    68         {       Run_ok_count++;
    69                 cout << "OK:    " << "No memory leak detected" << endl;
    7070        }
    7171        // convert int(size_t) to avoid warning on _MSC_VER systems
  • trunk/example/base_require.cpp

    r2284 r2341  
    4949        size_t inuse_before = thread_alloc::inuse(thread);
    5050
    51         // Make sure static memory correspoding to isnan is allocated
    52         // (which may be used by CppAD forward mode for error checking).
    53         CppAD::isnan( base_alloc(0.) );
    54         CppAD::isnan( ad_base_alloc(0.) );
    55 
    56         // now determine if we need to inform memory_leak of this memory
    57         // (or if it had been previously allocated)
    58         size_t inuse_after = thread_alloc::inuse(thread);
    59         if( inuse_after > inuse_before )
    60                 CppAD::memory_leak( inuse_after - inuse_before );
    61 
    6251        // y = x^2
    6352        size_t n = 1, m = 2;
  • trunk/example/example.cpp

    r2333 r2341  
    4949# include <string>
    5050
    51 // memory leak utility
    52 # include <cppad/memory_leak.hpp>
     51// memory utility
     52# include <cppad/thread_alloc.hpp>
    5353
    5454// external complied tests
     
    220220        ok &= Run( Atan,              "Atan"             );
    221221        ok &= Run( Atan2,             "Atan2"            );
    222         ok &= Run( base_require,      "base_require"     );
    223222        ok &= Run( BenderQuad,        "BenderQuad"       );
    224223        ok &= Run( BoolFun,           "BoolFun"          );
     
    336335        using std::endl;
    337336        assert( ok || (Run_error_count > 0) );
    338         if( CppAD::memory_leak() )
     337        if( CppAD::thread_alloc::free_all() )
     338        {       Run_ok_count++;
     339                cout << "OK:    " << "No memory leak detected" << endl;
     340        }
     341        else
    339342        {       ok = false;
    340343                Run_error_count++;
    341344                cout << "Error: " << "memory leak detected" << endl;
    342345        }
    343         else
    344         {       Run_ok_count++;
    345                 cout << "OK:    " << "No memory leak detected" << endl;
    346         }
     346        // Run base_require after memory leak check because base_alloc.hpp uses
     347        // thread_alloc to allocate memory for static copies of nan.
     348        ok &= Run( base_require,      "base_require"     );
    347349        // convert int(size_t) to avoid warning on _MSC_VER systems
    348350        if( ok )
  • trunk/example/thread_alloc.cpp

    r2291 r2341  
    4646        size_t thread;
    4747
    48         // check that no memory is initilaly inuse or available
    49         ok &= ! CppAD::memory_leak();
     48        // check that no memory is initilaly inuse
     49        ok &= thread_alloc::free_all();
    5050
    5151        // amount of static memory used by thread zero
    52         size_t static_inuse = thread_alloc::inuse(0);
     52        size_t static_inuse = 0;
    5353
    5454        // repeatedly allocate enough memory for at least two size_t values.
     
    113113        size_t thread = thread_alloc::thread_num();
    114114        ok &= thread == 0;
    115         ok &= ! CppAD::memory_leak();
    116         size_t static_inuse = thread_alloc::inuse(0);
     115        ok &= thread_alloc::free_all();
     116        size_t static_inuse = 0;
    117117
    118118        // initial allocation of an array
  • trunk/multi_thread/thread_test.cpp

    r2302 r2341  
    298298                        ok        = simple_ad();
    299299                else    ok        = team_example();
    300                 if( CppAD::memory_leak() )
     300                if( thread_alloc::free_all() )
     301                        cout << "free_all      = true;"  << endl;
     302                else
    301303                {       ok = false;
    302                         cout << "memory_leak   = true;" << endl;
     304                        cout << "free_all      = false;" << endl;
    303305                }
    304                 else cout << "memory_leak   = false;" << endl;
    305306                if( ok )
    306                 {       cout << "OK            = true;"  << endl;
    307                         exit(0);
    308                 }
    309                 else
    310                 {       cout << "OK            = false;" << endl;
    311                         exit(1);
    312                 }
     307                        cout << "OK            = true;"  << endl;
     308                else cout << "OK            = false;" << endl;
     309                return ! ok;
    313310        }
    314311
     
    408405        cout << "];" << endl;
    409406        //
    410         if( CppAD::memory_leak() )
     407        if( thread_alloc::free_all() )
     408                cout << "free_all      = true;"  << endl;
     409        else
    411410        {       ok = false;
    412                 cout << "memory_leak   = true;"  << endl;
    413         }
    414         else cout << "memory_leak   = false;" << endl;
    415         //
     411                cout << "free_all      = false;" << endl;
     412        }
    416413        if( ok )
    417414                cout << "OK            = true;"  << endl;
  • trunk/omh/deprecated.omh

    r2192 r2341  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    2323        cppad/local/omp_max_thread.hpp%
    2424        cppad/track_new_del.hpp%
    25         omh/omp_alloc.omh
     25        omh/omp_alloc.omh%
     26        cppad/memory_leak.hpp
    2627%$$
    2728
  • trunk/omh/library.omh

    r2192 r2341  
    11$Id$
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    5353
    5454        cppad/vector.hpp%
    55         omh/thread_alloc.omh%
    56         cppad/memory_leak.hpp
     55        omh/thread_alloc.omh
    5756%$$
    5857
  • trunk/omh/whats_new_12.omh

    r2339 r2341  
    4343
    4444$head 04-06$$
     45$list number$$
    4546A change was made to the way that the tapes were managed to reduce
    4647false sharing during $cref/multi-threading/multi_thread/$$.
    4748Because of this change, it is now suggest that the user call
    4849$cref parallel_ad$$ after the multi-threading section of the program.
     50$lnext
     51The routine $cref ta_free_all$$ was created to make it easier
     52to manage memory and the routine $cref memory_leak$$
     53was deprecated.
     54$lend
    4955
    5056$head 04-05$$
  • trunk/speed/example/example.cpp

    r2192 r2341  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    109109        ok &= Run(speed_test,             "speed_test"    );
    110110        ok &= Run(time_test,               "time_test"    );
     111        assert( ok || (Run_error_count > 0) );
    111112
    112113        // check for memory leak in previous calculations
    113         if( CppAD::memory_leak() )
     114        if( ! CppAD::thread_alloc::free_all() )
     115        {       ok = false;
    114116                cout << "Error: memroy leak detected" << endl;
     117        }
    115118
    116         assert( ok || (Run_error_count > 0) );
    117119        if( ok )
    118120        {       cout << "All " << int(Run_ok_count) << " tests passed ";
  • trunk/speed/main.cpp

    r2233 r2341  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    2323# include <cppad/poly.hpp>
    2424# include <cppad/track_new_del.hpp>
    25 # include <cppad/memory_leak.hpp>
     25# include <cppad/thread_alloc.hpp>
    2626
    2727# ifdef SPEED_ADOLC
     
    543543        size_sparse_jacobian.resize(0);
    544544        // check for memory leak
    545         if( CppAD::memory_leak() )
     545        if( CppAD::thread_alloc::free_all() )
     546        {       Run_ok_count++;
     547                cout << "No memory leak detected" << endl;
     548        }
     549        else
    546550        {       ok = false;
    547551                Run_error_count++;
    548552                cout << "Memory leak detected" << endl;
    549553        }
    550         else
    551         {       Run_ok_count++;
    552                 cout << "No memory leak detected" << endl;
    553         }
    554554# endif
    555555        return static_cast<int>( ! ok );
  • trunk/test_more/base_alloc.cpp

    r2284 r2341  
    1818        typedef CppAD::AD<base_alloc> my_ad;
    1919
    20         // check the amount of memory inuse by this thread (thread zero)
    21         size_t thread = thread_alloc::thread_num();
    22         ok &= thread == 0;
    23         size_t inuse_before = thread_alloc::inuse(thread);
    24 
    25         // set static memory correspoding to isnan
    26         CppAD::isnan( base_alloc(0.) );
    27         CppAD::isnan( my_ad(0.) );
    28 
    29         // now determine if we need to inform memory_leak of this memory
    30         // (or if it had been previously allocated)
    31         size_t inuse_after = thread_alloc::inuse(thread);
    32         if( inuse_after > inuse_before )
    33                 CppAD::memory_leak( inuse_after - inuse_before );
    34        
    3520        // y = x^2
    3621        CppAD::vector<my_ad>   a_x, a_y;
  • trunk/test_more/test_more.cpp

    r2333 r2341  
    1515
    1616// memory leak checker
    17 # include <cppad/memory_leak.hpp>
     17# include <cppad/thread_alloc.hpp>
    1818
    1919// various examples / tests
     
    133133        ok &= Run( Atan,            "Atan"           );
    134134        ok &= Run( Atan2,           "Atan2"          );
    135         ok &= Run( base_alloc_test, "base_alloc"     );
    136135        ok &= Run( check_simple_vector, "check_simple_vector" );
    137136        ok &= Run( Compare,         "Compare"        );
     
    207206        using std::endl;
    208207        assert( ok || (Run_error_count > 0) );
    209         if( CppAD::memory_leak() )
     208        if( CppAD::thread_alloc::free_all() )
     209        {       Run_ok_count++;
     210                cout << "OK:    " << "No memory leak detected" << endl;
     211        }
     212        else
    210213        {       ok = false;
    211214                Run_error_count++;
    212215                cout << "Error: " << "memory leak detected" << endl;
    213216        }
    214         else
    215         {       Run_ok_count++;
    216                 cout << "OK:    " << "No memory leak detected" << endl;
    217         }
     217        // Run base_require after memory leak check because base_alloc.hpp uses
     218        // thread_alloc to allocate memory for static copies of nan.
     219        ok &= Run( base_alloc_test, "base_alloc"     );
    218220        // convert int(size_t) to avoid warning on _MSC_VER systems
    219221        if( ok )
Note: See TracChangeset for help on using the changeset viewer.