Codebase list cppad / 8f05fc0
New upstream version 2019.02.00.4 Barak A. Pearlmutter 4 years ago
9 changed file(s) with 131 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
1717 /new.*/
1818 # directory that is ignored by master, but not by gh-pages
1919 /doc/
20 /dev/
2021 # ----------------------------------------------------------------------------
2122 # specific extensions in top direcotry
2223 /*.err
2424 endif()
2525 #
2626 # cppad_version is used by version.sh to get the version number.
27 SET(cppad_version "20190200.3")
27 SET(cppad_version "20190200.4")
2828 SET(cppad_url "http://www.coin-or.org/CppAD" )
2929 SET(cppad_description "Differentiation of C++ Algorithms" )
3030 #
00 #! /bin/bash -e
11 # -----------------------------------------------------------------------------
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
2 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
33 #
44 # CppAD is distributed under the terms of the
55 # Eclipse Public License Version 2.0.
164164 # Run automated checks for the form bin/check_*.sh with a few exceptions.
165165 list=`ls bin/check_* | sed \
166166 -e '/check_all.sh/d' \
167 -e '/check_doxygen.sh/d' \
167168 -e '/check_jenkins.sh/d' \
168169 -e '/check_svn_dist.sh/d'`
169170 # ~/devel/check_copyright.sh not included in batch_edit branch
1010 # -----------------------------------------------------------------------------
1111 dnl Process this file with autoconf to produce a configure script.
1212 dnl package version bug-report
13 AC_INIT([cppad], [20190200.3], [cppad@list.coin-or.org])
13 AC_INIT([cppad], [20190200.4], [cppad@list.coin-or.org])
1414 AM_SILENT_RULES([no])
1515
1616 dnl By defalut disable maintainer mode when running configure;
6161
6262 $comment bin/version assumes that : follows cppad version number here$$
6363 $section
64 cppad-20190200.3: A C++ Algorithmic Differentiation Package$$
64 cppad-20190200.4: A C++ Algorithmic Differentiation Package$$
6565
6666 $comment =================================================================== $$
6767 $align middle$$
00 # ifndef CPPAD_CORE_CHKPOINT_TWO_CHKPOINT_TWO_HPP
11 # define CPPAD_CORE_CHKPOINT_TWO_CHKPOINT_TWO_HPP
22 /* --------------------------------------------------------------------------
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
44
55 CppAD is distributed under the terms of the
66 Eclipse Public License Version 2.0.
152152 void allocate_member(size_t thread)
153153 { CPPAD_ASSERT_UNKNOWN( use_in_parallel_ );
154154 if( member_[thread] == CPPAD_NULL )
155 { // Other threds have copy of corresponding informaiton.
155 { // allocaate raw memory
156 size_t min_bytes = sizeof(member_struct);
157 size_t num_bytes;
158 void* v_ptr = thread_alloc::get_memory(min_bytes, num_bytes);
159 // convert to member_struct*
160 member_[thread] = reinterpret_cast<member_struct*>(v_ptr);
161 // call member_struct constructor
162 new( member_[thread] ) member_struct;
163 //
164 // The thread has a copy of corresponding informaiton.
156165 member_[thread]->g_ = g_;
157166 member_[thread]->ag_ = ag_;
158167 }
163172 /// free member_ for this thread
164173 void free_member(size_t thread)
165174 { if( member_[thread] != CPPAD_NULL )
166 { delete member_[thread];
175 { // call destructor
176 member_[thread]->~member_struct();
177 // return raw m,emory to available pool for this thread
178 void* v_ptr = reinterpret_cast<void*>(member_[thread]);
179 thread_alloc::return_memory(v_ptr);
180 // mark member for this thread as not allocated
167181 member_[thread] = CPPAD_NULL;
168182 }
169183 return;
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
2222 perfer_reverse.cpp
2323 multi_atomic.cpp
2424 multi_checkpoint.cpp
25 multi_chkpoint_two.cpp
2526 )
2627 set_compile_flags(
2728 test_more_${name} "${cppad_debug_which}" "${source_list}"
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
1515 extern bool prefer_reverse(void);
1616 extern bool multi_atomic(void);
1717 extern bool multi_checkpoint(void);
18 extern bool multi_chkpoint_two(void);
1819
1920 int main(void)
2021 { std::string group = "test_more/cppad_for_tmb";
2627 Run( implicit_ctor, "implicit_ctor" );
2728 Run( prefer_reverse, "prefer_reverse" );
2829 Run( multi_atomic, "multi_atomic" );
29 Run( multi_checkpoint, "multi_checkpoint" );
30 Run( multi_chkpoint_two, "multi_chkpoint_two" );
3031
3132 // check for memory leak
3233 bool memory_ok = CppAD::thread_alloc::free_all();
0 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
2
3 CppAD is distributed under the terms of the
4 Eclipse Public License Version 2.0.
5
6 This Source Code may also be made available under the following
7 Secondary License when the conditions for such availability set forth
8 in the Eclipse Public License, Version 2.0 are satisfied:
9 GNU General Public License, Version 2.0 or later.
10 ---------------------------------------------------------------------------- */
11 # include <cppad/cppad.hpp>
12 # include <omp.h>
13
14 namespace {
15
16 typedef CPPAD_TESTVECTOR(double) d_vector;
17 typedef CPPAD_TESTVECTOR( CppAD::AD<double> ) ad_vector;
18
19
20 // algorithm that we are checkpoingint
21 const size_t length_of_sum_ = 5000;
22 void long_sum_algo(const ad_vector& ax, ad_vector& ay)
23 { ay[0] = 0.0;
24 for(size_t i = 0; i < length_of_sum_; ++i)
25 ay[0] += ax[0];
26 return;
27 }
28 // inform CppAD if we are in parallel mode
29 bool in_parallel(void)
30 { return omp_in_parallel() != 0; }
31 //
32 // inform CppAD of the current thread number
33 size_t thread_num(void)
34 { return static_cast<size_t>( omp_get_thread_num() ); }
35
36 }
37
38 // multi_thread_chkpoint_two
39 bool multi_chkpoint_two(void)
40 { bool ok = true;
41
42 // OpenMP setup
43 size_t num_threads = 4; // number of threads
44 omp_set_dynamic(0); // turn off dynamic thread adjustment
45 omp_set_num_threads( int(num_threads) ); // set number of OMP threads
46
47 // check that multi-threading is possible on this machine
48 if( omp_get_max_threads() < 2 )
49 { std::cout << "This machine does not support multi-threading: ";
50 }
51
52 // create ADFun corresponding to long_sum_algo
53 size_t n(1), m(1);
54 ad_vector ax(n), ay(m);
55 ax[0] = 2.0;
56 CppAD::Independent(ax);
57 long_sum_algo(ax, ay);
58 CppAD::ADFun<double> fun(ax, ay);
59
60 // create chkpoint_two version of algorithm
61 const char* name = "long_sum";
62 bool internal_bool = false;
63 bool use_hes_sparsity = false;
64 bool use_base2ad = false;
65 bool use_in_parallel = true;
66 CppAD::chkpoint_two<double> chk_fun( fun, name,
67 internal_bool, use_hes_sparsity, use_base2ad, use_in_parallel
68 );
69 // setup for using CppAD in paralle mode
70 CppAD::thread_alloc::parallel_setup(num_threads, in_parallel, thread_num);
71 CppAD::thread_alloc::hold_memory(true);
72 CppAD::parallel_ad<double>();
73
74 // place to hold result for each thread
75 d_vector y(num_threads);
76 for(size_t thread = 0; thread < num_threads; thread++)
77 y[thread] = 0.0;
78
79 # pragma omp parallel for
80 for(int thread = 0; thread < int(num_threads); thread++)
81 { ad_vector au(n), av(m);
82 au[0] = 1.0;
83 CppAD::Independent(au);
84 chk_fun(au, av);
85 CppAD::ADFun<double> f(au, av);
86 //
87 d_vector x(n), v(m);
88 x[0] = double( thread + 1 );
89 v = f.Forward(0, x);
90 //
91 // this assigment has false sharing; i.e., will case cache resets
92 // (conversion avoids boost vector conversion warning)
93 y[size_t(thread)] = v[0];
94 }
95
96 // check the results
97 for(size_t thread = 0; thread < num_threads; thread++)
98 { double check = double( length_of_sum_ * (thread + 1) );
99 ok &= check == y[thread];
100 }
101 return ok;
102 }