source: trunk/ADOL-C/src/param.cpp @ 748

Last change on this file since 748 was 748, checked in by kulshres, 15 months ago

Merge branch 'activity' of 'gitclone' into 'svn'

The following commits were merged:
commit fc84dcabde90416ff32e8b08a06b7dad775e06bf
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Aug 4 10:36:17 2017 +0200

more debugging activity analysis

sign of coval is important in all cases, so I can't change it only
in one case.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit b5f80a477d085d84c67ee71e2cf84ce6d926b858
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Aug 3 18:24:40 2017 +0200

correct some sign changes

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e8642818244e33f0a4204fdffa936cc7195fc5bc
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Aug 3 14:57:46 2017 +0200

add activity tracking to parameters

parameters are always active since they can be changed after tracing
is complete using set_param_vec, just like independent variables.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit ae9f196ebbf225cd9a5e62e26266c2cbbbc8a5b2
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 2 17:58:15 2017 +0200

add activity tracking to conditional assignments

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit c4b610de2500e949271d3bf60f04b5d34a229807
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Jul 31 13:50:05 2017 +0200

simplify some operations during activity tracking

especially assignment from adub. make that equivalent to construction
from adub, by stealing rhs location. The problem with not stealing that
location would be to restore rhs previous activity before rhs was created
so that we can replace lhs into the previous operation. Since we don't have
a way of recreating activities from before, it's better to steal the
location of rhs and free the lhs location for reuse later.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 8e2ad08100254ee4309209d6c807928d6cab94ee
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jul 28 14:06:30 2017 +0200

add activity checking code in the operators and functions for adouble

conditional assignments do not track activity at the moment. Next step
is to make the parameters active too.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit b8b6411ba29892d10d36bfe7a4d2abcbeb59ff67
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jul 28 13:59:36 2017 +0200

add a buffer in globalTapeVars to track activity of live variables

it is managed by the StoreManager? class for allocation and deallocation

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 569a7f28227991f8029e89b989c6f04415e8bd1a
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jul 28 13:58:32 2017 +0200

Add option to enable activity tracking in adouble class

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

File size: 22.5 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     param.cpp
4 Revision: $Id$
5 Contents: class for parameter dependent functions
6 
7 Copyright (c) Kshitij Kulshreshtha
8
9 This file is part of ADOL-C. This software is provided as open source.
10 Any use, reproduction, or distribution of the software constitutes
11 recipient's acceptance of the terms of the accompanying license file.
12
13----------------------------------------------------------------------------*/
14
15
16#include "oplate.h"
17#include "taping_p.h"
18#include "dvlparms.h"
19#include <adolc/adouble.h>
20
21#include <limits>
22
23pdouble::pdouble(double pval) {
24    ADOLC_OPENMP_THREAD_NUMBER;
25    ADOLC_OPENMP_GET_THREAD_NUMBER;
26
27    _val = pval;
28    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
29        _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc();
30        ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = _val;
31    } else {
32        _idx = std::numeric_limits<locint>::max();
33    }
34}
35
36pdouble::pdouble(locint idx) {
37    ADOLC_OPENMP_THREAD_NUMBER;
38    ADOLC_OPENMP_GET_THREAD_NUMBER;
39   
40    if (idx < ADOLC_GLOBAL_TAPE_VARS.numparam) {
41        _val = ADOLC_GLOBAL_TAPE_VARS.pStore[idx];
42        _idx = idx;
43    } else {
44        fprintf(DIAG_OUT, "ADOL-C error: Parameter index %d out of bounds, "
45                "# existing parameters = %zu\n", idx, 
46                ADOLC_GLOBAL_TAPE_VARS.numparam);
47        adolc_exit(-1,"",__func__,__FILE__,__LINE__);
48    }
49}
50
51pdouble mkparam(double pval) {
52    locint _idx;
53    ADOLC_OPENMP_THREAD_NUMBER;
54    ADOLC_OPENMP_GET_THREAD_NUMBER;
55
56    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
57        _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc();
58        ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = pval;
59    } else {
60        return pval;
61    }
62    return _idx;
63}
64
65pdouble getparam(locint index) {
66    return index;
67}
68
69locint mkparam_idx(double pval) {
70    locint _idx;
71    ADOLC_OPENMP_THREAD_NUMBER;
72    ADOLC_OPENMP_GET_THREAD_NUMBER;
73    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
74        _idx = ADOLC_GLOBAL_TAPE_VARS.paramStoreMgrPtr->next_loc();
75        ADOLC_GLOBAL_TAPE_VARS.pStore[_idx] = pval;
76    } else {
77        fprintf(DIAG_OUT, "ADOL-C error: cannot define indexed parameter "
78                "while tracing is turned off!\n");
79        adolc_exit(-1,"",__func__,__FILE__,__LINE__);
80    }
81    return _idx;
82}
83
84pdouble::operator adub() const {
85    locint location;
86    ADOLC_OPENMP_THREAD_NUMBER;
87    ADOLC_OPENMP_GET_THREAD_NUMBER;
88
89    location = next_loc();
90    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
91        put_op(assign_p);
92        ADOLC_PUT_LOCINT(_idx);
93        ADOLC_PUT_LOCINT(location);
94
95        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
96        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
97            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]);
98    }
99    ADOLC_GLOBAL_TAPE_VARS.store[location] = _val;
100#if defined(ADOLC_TRACK_ACTIVITY)
101    ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true;
102#endif
103    return location;
104}
105
106badouble& badouble::operator = (const pdouble& p) {
107    locint loc;
108    ADOLC_OPENMP_THREAD_NUMBER;
109    ADOLC_OPENMP_GET_THREAD_NUMBER;
110
111    loc = this->loc();
112    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
113        put_op(assign_p);
114        ADOLC_PUT_LOCINT(p._idx);
115        ADOLC_PUT_LOCINT(loc);
116
117        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
118        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
119            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc]);
120    }
121    ADOLC_GLOBAL_TAPE_VARS.store[loc] = p._val;
122#if defined(ADOLC_TRACK_ACTIVITY)
123    ADOLC_GLOBAL_TAPE_VARS.actStore[loc] = true;
124#endif
125    return *this;
126}
127
128adouble& adouble::operator = (const pdouble& p) {
129    this->loc();
130    (*this).badouble::operator=(p);
131    return (*this);
132}
133
134adubref& adubref::operator = (const pdouble& p) {
135    ADOLC_OPENMP_THREAD_NUMBER;
136    ADOLC_OPENMP_GET_THREAD_NUMBER;
137    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
138        put_op(ref_assign_p);
139        ADOLC_PUT_LOCINT(p._idx);
140        ADOLC_PUT_LOCINT(location);
141       
142        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
143        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
144            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]);
145    }
146    ADOLC_GLOBAL_TAPE_VARS.store[refloc] = p._val;
147#if defined(ADOLC_TRACK_ACTIVITY)
148    ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true;
149#endif
150    return *this;
151}
152
153badouble& badouble::operator += (const pdouble& p) {
154    locint loc;
155    ADOLC_OPENMP_THREAD_NUMBER;
156    ADOLC_OPENMP_GET_THREAD_NUMBER;
157
158    loc = this->loc();
159    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
160        put_op(eq_plus_p);
161        ADOLC_PUT_LOCINT(p._idx);
162        ADOLC_PUT_LOCINT(loc);
163       
164        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
165        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
166            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc]);
167    }
168
169    ADOLC_GLOBAL_TAPE_VARS.store[loc] += p._val;
170#if defined(ADOLC_TRACK_ACTIVITY)
171    ADOLC_GLOBAL_TAPE_VARS.actStore[loc] = true;
172#endif
173    return *this;   
174}
175
176adubref& adubref::operator += (const pdouble& p) {
177    ADOLC_OPENMP_THREAD_NUMBER;
178    ADOLC_OPENMP_GET_THREAD_NUMBER;
179
180    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
181        put_op(ref_eq_plus_p);
182        ADOLC_PUT_LOCINT(p._idx);
183        ADOLC_PUT_LOCINT(location);
184
185        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
186        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
187            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]);
188    }
189
190    ADOLC_GLOBAL_TAPE_VARS.store[refloc] += p._val;
191#if defined(ADOLC_TRACK_ACTIVITY)
192    ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true;
193#endif
194    return *this;
195}
196
197badouble& badouble::operator -= (const pdouble& p) {
198    ADOLC_OPENMP_THREAD_NUMBER;
199    ADOLC_OPENMP_GET_THREAD_NUMBER;
200    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_min_d,loc(),coval);
201        put_op(eq_min_p);
202        ADOLC_PUT_LOCINT(p._idx);
203        ADOLC_PUT_LOCINT(loc());
204
205        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
206        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
207            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]);
208    }
209
210    ADOLC_GLOBAL_TAPE_VARS.store[loc()] -= p._val;
211#if defined(ADOLC_TRACK_ACTIVITY)
212    ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true;
213#endif
214    return *this;
215}
216
217adubref& adubref::operator -= (const pdouble& p) {
218    ADOLC_OPENMP_THREAD_NUMBER;
219    ADOLC_OPENMP_GET_THREAD_NUMBER;
220    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_min_d,location,coval);
221        put_op(ref_eq_min_p);
222        ADOLC_PUT_LOCINT(p._idx);
223        ADOLC_PUT_LOCINT(location);
224
225        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
226        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
227            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]);
228    }
229
230    ADOLC_GLOBAL_TAPE_VARS.store[refloc] -= p._val;
231#if defined(ADOLC_TRACK_ACTIVITY)
232    ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true;
233#endif
234    return *this;
235}
236
237badouble& badouble::operator *= (const pdouble& p) {
238    ADOLC_OPENMP_THREAD_NUMBER;
239    ADOLC_OPENMP_GET_THREAD_NUMBER;
240    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_mult_d,loc(),coval);
241        put_op(eq_mult_p);
242        ADOLC_PUT_LOCINT(p._idx);       // = coval
243        ADOLC_PUT_LOCINT(loc()); // = res
244
245        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
246        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
247            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[loc()]);
248    }
249
250    ADOLC_GLOBAL_TAPE_VARS.store[loc()] *= p._val;
251#if defined(ADOLC_TRACK_ACTIVITY)
252    ADOLC_GLOBAL_TAPE_VARS.actStore[loc()] = true;
253#endif
254    return *this;
255}
256
257adubref& adubref::operator *= (const pdouble& p) {
258    ADOLC_OPENMP_THREAD_NUMBER;
259    ADOLC_OPENMP_GET_THREAD_NUMBER;
260    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_d_same_arg(eq_mult_d,location,coval);
261        put_op(ref_eq_mult_p);
262        ADOLC_PUT_LOCINT(p._idx);
263        ADOLC_PUT_LOCINT(location);
264
265        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
266        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
267            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[refloc]);
268    }
269
270    ADOLC_GLOBAL_TAPE_VARS.store[refloc] *= p._val;
271#if defined(ADOLC_TRACK_ACTIVITY)
272    ADOLC_GLOBAL_TAPE_VARS.actStore[refloc] = true;
273#endif
274    return *this;
275}
276
277adub operator + (const badouble& a, const pdouble& p) {
278    ADOLC_OPENMP_THREAD_NUMBER;
279    ADOLC_OPENMP_GET_THREAD_NUMBER;
280    locint locat = next_loc();
281
282    /* olvo 980708 test coval to be zero */
283    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc());
284#if defined(ADOLC_TRACK_ACTIVITY)
285        if (! ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()] ) {
286            locint tmploc = a.loc();
287            double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()];
288            if (temp == 0.0) {
289                put_op(assign_d_zero);
290                ADOLC_PUT_LOCINT(tmploc);
291            } else if (temp == 1.0) {
292                put_op(assign_d_one);
293                ADOLC_PUT_LOCINT(tmploc);
294            } else {
295                put_op(assign_d);
296                ADOLC_PUT_LOCINT(tmploc);
297                ADOLC_PUT_VAL(temp);
298            }
299
300            ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
301            if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
302                ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]);
303        }
304#endif
305        put_op(plus_a_p);
306        ADOLC_PUT_LOCINT(a.loc());
307        ADOLC_PUT_LOCINT(p._idx);
308        ADOLC_PUT_LOCINT(locat);
309
310        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
311        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
312            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
313    }
314   
315    ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] + p._val;
316#if defined(ADOLC_TRACK_ACTIVITY)
317    ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true;
318#endif
319    return locat;
320}
321
322adub operator - (const badouble& a, const pdouble& p) {
323    ADOLC_OPENMP_THREAD_NUMBER;
324    ADOLC_OPENMP_GET_THREAD_NUMBER;
325    locint locat = next_loc();
326
327    /* olvo 980708 test coval to be zero */
328    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc());
329#if defined(ADOLC_TRACK_ACTIVITY)
330        if (! ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()] ) {
331            locint tmploc = a.loc();
332            double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()];
333            if (temp == 0.0) {
334                put_op(assign_d_zero);
335                ADOLC_PUT_LOCINT(tmploc);
336            } else if (temp == 1.0) {
337                put_op(assign_d_one);
338                ADOLC_PUT_LOCINT(tmploc);
339            } else {
340                put_op(assign_d);
341                ADOLC_PUT_LOCINT(tmploc);
342                ADOLC_PUT_VAL(temp);
343            }
344
345            ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
346            if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
347                ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]);
348        }
349#endif
350        put_op(min_a_p);
351        ADOLC_PUT_LOCINT(a.loc());
352        ADOLC_PUT_LOCINT(p._idx);
353        ADOLC_PUT_LOCINT(locat);
354
355        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
356        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
357            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
358    }
359   
360    ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] - p._val;
361#if defined(ADOLC_TRACK_ACTIVITY)
362    ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true;
363#endif
364    return locat;
365}
366
367adub operator * (const badouble& a, const pdouble& p) {
368    ADOLC_OPENMP_THREAD_NUMBER;
369    ADOLC_OPENMP_GET_THREAD_NUMBER;
370    locint locat = next_loc();
371
372    /* olvo 980708 test coval to be zero */
373    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc());
374#if defined(ADOLC_TRACK_ACTIVITY)
375        if (! ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()] ) {
376            locint tmploc = a.loc();
377            double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()];
378            if (temp == 0.0) {
379                put_op(assign_d_zero);
380                ADOLC_PUT_LOCINT(tmploc);
381            } else if (temp == 1.0) {
382                put_op(assign_d_one);
383                ADOLC_PUT_LOCINT(tmploc);
384            } else {
385                put_op(assign_d);
386                ADOLC_PUT_LOCINT(tmploc);
387                ADOLC_PUT_VAL(temp);
388            }
389
390            ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
391            if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
392                ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]);
393        }
394#endif
395        put_op(mult_a_p);
396        ADOLC_PUT_LOCINT(a.loc());
397        ADOLC_PUT_LOCINT(p._idx);
398        ADOLC_PUT_LOCINT(locat);
399
400        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
401        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
402            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
403    }
404   
405    ADOLC_GLOBAL_TAPE_VARS.store[locat] = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()] * p._val;
406#if defined(ADOLC_TRACK_ACTIVITY)
407    ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true;
408#endif
409    return locat;
410}
411
412adub operator / (const pdouble& p, const badouble& a) {
413    ADOLC_OPENMP_THREAD_NUMBER;
414    ADOLC_OPENMP_GET_THREAD_NUMBER;
415    locint locat = next_loc();
416
417    /* olvo 980708 test coval to be zero */
418    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(plus_d_a,locat,coval,y.loc());
419#if defined(ADOLC_TRACK_ACTIVITY)
420        if (! ADOLC_GLOBAL_TAPE_VARS.actStore[a.loc()] ) {
421            locint tmploc = a.loc();
422            double temp = ADOLC_GLOBAL_TAPE_VARS.store[a.loc()];
423            if (temp == 0.0) {
424                put_op(assign_d_zero);
425                ADOLC_PUT_LOCINT(tmploc);
426            } else if (temp == 1.0) {
427                put_op(assign_d_one);
428                ADOLC_PUT_LOCINT(tmploc);
429            } else {
430                put_op(assign_d);
431                ADOLC_PUT_LOCINT(tmploc);
432                ADOLC_PUT_VAL(temp);
433            }
434
435            ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
436            if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
437                ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]);
438        }
439#endif
440        put_op(div_p_a);
441        ADOLC_PUT_LOCINT(a.loc());
442        ADOLC_PUT_LOCINT(p._idx);
443        ADOLC_PUT_LOCINT(locat);
444
445        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
446        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
447            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
448    }
449   
450    ADOLC_GLOBAL_TAPE_VARS.store[locat] = p._val/ADOLC_GLOBAL_TAPE_VARS.store[a.loc()];
451#if defined(ADOLC_TRACK_ACTIVITY)
452    ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true;
453#endif
454    return locat;   
455}
456
457adub pow( const badouble& x, const pdouble& p) {
458    ADOLC_OPENMP_THREAD_NUMBER;
459    ADOLC_OPENMP_GET_THREAD_NUMBER;
460    locint locat = next_loc();
461
462    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) { // old: write_args_d_a(pow_op,locat,cocval,x.loc());
463#if defined(ADOLC_TRACK_ACTIVITY)
464        if (! ADOLC_GLOBAL_TAPE_VARS.actStore[x.loc()] ) {
465            locint tmploc = x.loc();
466            double temp = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()];
467            if (temp == 0.0) {
468                put_op(assign_d_zero);
469                ADOLC_PUT_LOCINT(tmploc);
470            } else if (temp == 1.0) {
471                put_op(assign_d_one);
472                ADOLC_PUT_LOCINT(tmploc);
473            } else {
474                put_op(assign_d);
475                ADOLC_PUT_LOCINT(tmploc);
476                ADOLC_PUT_VAL(temp);
477            }
478
479            ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
480            if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
481                ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[tmploc]);
482        }
483#endif
484        put_op(pow_op_p);
485        ADOLC_PUT_LOCINT(x.loc()); // = arg
486        ADOLC_PUT_LOCINT(p._idx);         // = coval
487        ADOLC_PUT_LOCINT(locat);      // = res
488
489        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
490        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
491            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
492    }
493
494    ADOLC_GLOBAL_TAPE_VARS.store[locat] =
495        ADOLC_MATH_NSP::pow(ADOLC_GLOBAL_TAPE_VARS.store[x.loc()],p._val);
496#if defined(ADOLC_TRACK_ACTIVITY)
497    ADOLC_GLOBAL_TAPE_VARS.actStore[locat] = true;
498#endif
499    ADOLC_OPENMP_RESTORE_THREAD_NUMBER;
500    return locat;
501}
502adub recipr( const pdouble& p) {
503    locint location;
504    ADOLC_OPENMP_THREAD_NUMBER;
505    ADOLC_OPENMP_GET_THREAD_NUMBER;
506
507    location = next_loc();
508    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
509        put_op(recipr_p);
510        ADOLC_PUT_LOCINT(p._idx);
511        ADOLC_PUT_LOCINT(location);
512
513        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
514        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
515            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]);
516    }
517    ADOLC_GLOBAL_TAPE_VARS.store[location] = 1.0/p._val;
518#if defined(ADOLC_TRACK_ACTIVITY)
519    ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true;
520#endif
521    return location;
522}
523
524adub operator - (const pdouble& p) {
525    locint location;
526    ADOLC_OPENMP_THREAD_NUMBER;
527    ADOLC_OPENMP_GET_THREAD_NUMBER;
528
529    location = next_loc();
530    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
531        put_op(neg_sign_p);
532        ADOLC_PUT_LOCINT(p._idx);
533        ADOLC_PUT_LOCINT(location);
534
535        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
536        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
537            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[location]);
538    }
539    ADOLC_GLOBAL_TAPE_VARS.store[location] = -p._val;
540#if defined(ADOLC_TRACK_ACTIVITY)
541    ADOLC_GLOBAL_TAPE_VARS.actStore[location] = true;
542#endif
543    return location;
544}
545
546adouble pow( const pdouble& p, const badouble& y) {
547    adouble a1, a2, ret;
548    double vx = p._val;
549    double vy = y.getValue();
550    if (!(vx > 0)) { 
551        if (vx < 0 || vy >= 0)
552            fprintf(DIAG_OUT,"\nADOL-C message: exponent of zero/negative basis deactivated\n");
553        else
554            fprintf(DIAG_OUT,"\nADOL-C message: negative exponent and zero basis deactivated\n");
555    }
556    condassign(a1, -y, (adouble) ADOLC_MATH_NSP::pow(vx,vy), pow(p,vy));
557    condassign(a2, fabs(adub(p)), pow(p, vy), a1);
558    condassign(ret, p, exp(y*log(adub(p))),a2);
559
560    return ret;
561}
562
563#if defined(ADOLC_ADVANCED_BRANCHING)
564adub operator != (const badouble& x, const pdouble& y) {
565    ADOLC_OPENMP_THREAD_NUMBER;
566    ADOLC_OPENMP_GET_THREAD_NUMBER;
567    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()];
568    double yval = y._val;
569    double res = (double)(xval != yval);
570    locint locat = next_loc();
571    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
572        put_op(neq_a_p);
573        ADOLC_PUT_LOCINT(x.loc()); // arg
574        ADOLC_PUT_LOCINT(y._idx); // arg1
575        ADOLC_PUT_VAL(res);           // check for branch switch
576        ADOLC_PUT_LOCINT(locat);      // res
577
578        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
579        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
580            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
581    }
582    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
583    return locat;
584}
585/*--------------------------------------------------------------------------*/
586adub operator == (const badouble& x, const pdouble& y) {
587    ADOLC_OPENMP_THREAD_NUMBER;
588    ADOLC_OPENMP_GET_THREAD_NUMBER;
589    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()];
590    double yval = y._val;
591    double res = (double)(xval == yval);
592    locint locat = next_loc();
593    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
594        put_op(eq_a_p);
595        ADOLC_PUT_LOCINT(x.loc()); // arg
596        ADOLC_PUT_LOCINT(y._idx); // arg1
597        ADOLC_PUT_VAL(res);           // check for branch switch
598        ADOLC_PUT_LOCINT(locat);      // res
599
600        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
601        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
602            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
603    }
604    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
605    return locat;
606}
607/*--------------------------------------------------------------------------*/
608adub operator <= (const badouble& x, const pdouble& y) {
609    ADOLC_OPENMP_THREAD_NUMBER;
610    ADOLC_OPENMP_GET_THREAD_NUMBER;
611    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()];
612    double yval = y._val;
613    double res = (double)(xval <= yval);
614    locint locat = next_loc();
615    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
616        put_op(le_a_p);
617        ADOLC_PUT_LOCINT(x.loc()); // arg
618        ADOLC_PUT_LOCINT(y._idx); // arg1
619        ADOLC_PUT_VAL(res);           // check for branch switch
620        ADOLC_PUT_LOCINT(locat);      // res
621
622        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
623        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
624            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
625    }
626    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
627    return locat;
628}
629/*--------------------------------------------------------------------------*/
630adub operator >= (const badouble& x, const pdouble& y) {
631    ADOLC_OPENMP_THREAD_NUMBER;
632    ADOLC_OPENMP_GET_THREAD_NUMBER;
633    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()];
634    double yval = y._val;
635    double res = (double)(xval >= yval);
636    locint locat = next_loc();
637    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
638        put_op(ge_a_p);
639        ADOLC_PUT_LOCINT(x.loc()); // arg
640        ADOLC_PUT_LOCINT(y._idx); // arg1
641        ADOLC_PUT_VAL(res);           // check for branch switch
642        ADOLC_PUT_LOCINT(locat);      // res
643
644        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
645        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
646            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
647    }
648    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
649    return locat;
650}
651/*--------------------------------------------------------------------------*/
652adub operator > (const badouble& x, const pdouble& y) {
653    ADOLC_OPENMP_THREAD_NUMBER;
654    ADOLC_OPENMP_GET_THREAD_NUMBER;
655    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()];
656    double yval = y._val;
657    double res = (double)(xval > yval);
658    locint locat = next_loc();
659    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
660        put_op(gt_a_p);
661        ADOLC_PUT_LOCINT(x.loc()); // arg
662        ADOLC_PUT_LOCINT(y._idx); // arg1
663        ADOLC_PUT_VAL(res);           // check for branch switch
664        ADOLC_PUT_LOCINT(locat);      // res
665
666        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
667        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
668            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
669    }
670    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
671    return locat;
672}
673/*--------------------------------------------------------------------------*/
674adub operator < (const badouble& x, const pdouble& y) {
675    ADOLC_OPENMP_THREAD_NUMBER;
676    ADOLC_OPENMP_GET_THREAD_NUMBER;
677    double xval = ADOLC_GLOBAL_TAPE_VARS.store[x.loc()];
678    double yval = y._val;
679    double res = (double)(xval < yval);
680    locint locat = next_loc();
681    if (ADOLC_CURRENT_TAPE_INFOS.traceFlag) {
682        put_op(lt_a_p);
683        ADOLC_PUT_LOCINT(x.loc()); // arg
684        ADOLC_PUT_LOCINT(y._idx); // arg1
685        ADOLC_PUT_VAL(res);           // check for branch switch
686        ADOLC_PUT_LOCINT(locat);      // res
687
688        ++ADOLC_CURRENT_TAPE_INFOS.numTays_Tape;
689        if (ADOLC_CURRENT_TAPE_INFOS.keepTaylors)
690            ADOLC_WRITE_SCAYLOR(ADOLC_GLOBAL_TAPE_VARS.store[locat]);
691    }
692    ADOLC_GLOBAL_TAPE_VARS.store[locat] = res;
693    return locat;
694}
695#endif
Note: See TracBrowser for help on using the repository browser.