Changeset 3357


Ignore:
Timestamp:
Sep 25, 2014 6:13:01 AM (6 years ago)
Author:
bradbell
Message:
  1. Move bug/cache.sh to test_more/cache.cpp.
  2. Fix warnings.

create_cache.hpp: fix bug in setting and using user_i_var.

Location:
branches/cache
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/cache/cppad/local/create_cache.hpp

    r3356 r3357  
    7575                CPPAD_ASSERT_ARG_BEFORE_RESULT(op, arg, num_var, cache2var, i_var);
    7676
     77                user_i_var     = i_var;
    7778                if( op == UserOp )
    7879                {       in_user_atomic = ! in_user_atomic;
    7980                        if( in_user_atomic )
    8081                                user_i_var     = i_var + size_t( arg[3] );
    81                         else
    82                                 user_i_var     = i_var;
    8382                }
    8483                //
     
    8685                for(size_t i_arg = 0; i_arg < n_arg; i_arg++)
    8786                {       if( arg_is_variable(op, arg, i_arg) )
    88                                 last_use[ arg[i_arg] ] = i_var;
     87                                last_use[ arg[i_arg] ] = user_i_var;
    8988                }
    9089        }
     
    9594
    9695        // initialize cache mapping and available list as empty
    97         pod_vector<addr_t> var2cache;
     96        pod_vector<addr_t> variable2cache;
    9897        std::list<addr_t> available;
    9998        std::list<addr_t>::iterator itr;
    10099
    101100        // compute the cache index corresponding to each variable index
    102         var2cache.extend(num_var); // resize(num_var) because starts at zero size
     101        // resize(num_var) because constructed with zero size
     102        variable2cache.extend(num_var);
    103103        size_t i_cache = num_var;
    104104        size_t i_last  = 0;
     
    106106        {       if( available.empty() )
    107107                        available.push_front(i_cache++);
    108                 var2cache[i_var] = available.front();
     108                variable2cache[i_var] = available.front();
    109109                available.pop_front();
    110110
    111111                while( i_last < num_var && last_use[ order[i_last] ] <= i_var )
    112                 {       available.push_back( var2cache[ order[i_last++] ] );
    113                 }
    114         }
    115         size_t num_cache = i_cache - num_var;
     112                {       available.push_back( variable2cache[ order[i_last++] ] );
     113                }
     114        }
     115        size_t number_cache = i_cache - num_var;
    116116
    117117        // temporary printing of result
    118         std::cout << "num_cache = " << num_cache << std::endl;
     118        std::cout << "number_cache = " << number_cache << std::endl;
    119119        std::cout << "i_var, last_use, cache" << std::endl;
    120120        for(i_var = 0; i_var < num_var; i_var++)
    121121        {       std::cout << i_var << ", ";
    122122                std::cout << last_use[i_var] << ", ";
    123                 std::cout << var2cache[i_var] << std::endl;
     123                std::cout << variable2cache[i_var] << std::endl;
    124124        }
    125125
     
    169169                for(size_t i_arg = 0; i_arg < n_arg; i_arg++)
    170170                {       if( arg_is_variable(op, arg, i_arg) )
    171                                 rec.PutArg( var2cache[ arg[i_arg] ] );
     171                                rec.PutArg( variable2cache[ arg[i_arg] ] );
    172172                        else
    173173                                rec.PutArg( arg[i_arg] );
     
    180180
    181181        // set the cache information for this recording
    182         num_cache_ = num_cache;
     182        num_cache_ = number_cache;
    183183        last_use_  = last_use;
    184184        order_     = order;
    185         var2cache_ = var2cache;
     185        var2cache_ = variable2cache;
    186186
    187187        return;
    188 };
     188}
    189189
    190190
     
    199199        size_t r = 0;
    200200        capacity_order(c, r);
     201
     202        return;
    201203}
    202204
  • branches/cache/makefile.am

    r3338 r3357  
    150150        cppad/local/bool_fun.hpp \
    151151        cppad/local/bool_valued.hpp \
    152         cppad/local/cache.hpp \
     152        cppad/local/cache_info.hpp \
    153153        cppad/local/capacity_order.hpp \
    154154        cppad/local/checkpoint.hpp \
     
    163163        cppad/local/cppad_assert.hpp \
    164164        cppad/local/cppad_colpack.hpp \
     165        cppad/local/create_cache.hpp \
    165166        cppad/local/cskip_op.hpp \
    166167        cppad/local/csum_op.hpp \
  • branches/cache/test_more/CMakeLists.txt

    r3301 r3357  
    7676        atan2.cpp
    7777        base_alloc.cpp
     78        cache.cpp
    7879        check_simple_vector.cpp
    7980        checkpoint.cpp
  • branches/cache/test_more/cache.cpp

    r3356 r3357  
    1 #! /bin/bash -e
    2 # $Id$
    3 # -----------------------------------------------------------------------------
    4 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
    5 #
    6 # CppAD is distributed under multiple licenses. This distribution is under
    7 # the terms of the
    8 #                     Eclipse Public License Version 1.0.
    9 #
    10 # A copy of this license is included in the COPYING file of this distribution.
    11 # Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
    12 # -----------------------------------------------------------------------------
    13 #!/bin/bash -e
    14 #
    15 echo "Script for testing cache feature: Under Construction"
    16 #
    17 if [ ! -e build ]
    18 then
    19         mkdir build
    20 fi
    21 cd build
    22 if [ ! -e ../../cppad/configure.hpp ]
    23 then
    24         cmake ../..
    25 fi
    26 #
    27 echo "$0"
    28 name=`echo $0 | sed -e 's|.*/||' -e 's|\..*||'`
    29 echo "create $name.cpp"
    30 cat << EOF > $name.cpp
    31 // BEGIN PROGRAM
     1/* $Id$ */
     2/* --------------------------------------------------------------------------
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
     4
     5CppAD is distributed under multiple licenses. This distribution is under
     6the terms of the
     7                    Eclipse Public License Version 1.0.
     8
     9A copy of this license is included in the COPYING file of this distribution.
     10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
     11-------------------------------------------------------------------------- */
    3212# include <cppad/cppad.hpp>
    3313
    3414// Test routine
    35 bool test_cache(void)
     15bool cache(void)
    3616{       bool ok = true;
    3717        size_t i, j, ell;
     
    10888        return ok;
    10989}
    110 int main(void)
    111 {       bool ok = test_cache();
    112         std::cout << "OK = " << ok << std::endl;
    113         return int(! ok);
    114 }
    115 EOF
    116 echo "g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name"
    117 g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name
    118 #
    119 echo "./$name"
    120 ./$name
  • branches/cache/test_more/makefile.am

    r3301 r3357  
    100100        atan2.cpp \
    101101        base_alloc.cpp \
     102        cache.hpp \
    102103        check_simple_vector.cpp \
    103104        checkpoint.cpp \
  • branches/cache/test_more/test_more.cpp

    r3301 r3357  
    3030extern bool base_adolc(void);
    3131extern bool base_alloc_test(void);
     32extern bool cache(void);
    3233extern bool check_simple_vector(void);
    3334extern bool checkpoint(void);
     
    141142        ok &= Run( Atan,            "Atan"           );
    142143        ok &= Run( atan2,           "atan2"          );
     144        ok &= Run( cache,            "cache"         );
    143145        ok &= Run( check_simple_vector, "check_simple_vector" );
    144146        ok &= Run( checkpoint,      "checkpoint"     );
Note: See TracChangeset for help on using the changeset viewer.