source: trunk/ADOL-C/examples/additional_examples/timing/sfunc_experimental.cpp @ 171

Last change on this file since 171 was 171, checked in by kulshres, 9 years ago

Squashed merge branch 'master' of 'gitclone' into svn

  • 'master' of 'gitclone': (84 commits) adjust example makefiles and include paths get rid of the symlink in the src subdirectory

details of the commits:
commit c9e4bc332d2363f737fc2e8a8fcfc2e43ddb9d15
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:43:47 2010 +0200

adjust example makefiles and include paths

include paths in example sources were wrong for some time now
simplify makefile rules too, there is really no need for checking SPARSE
adjust include paths in makefiles.

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

commit e6e1963e41e097fd5b4a79cd1611c12f6868dc94
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:41:25 2010 +0200

get rid of the symlink in the src subdirectory

windows doesn't like symlinks and make infinite depth directories
we now create a symlink for build in the directory parallel to src
adjust all makefiles.am accordingly for build

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

  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     sfunc_experimental.cpp
4 Revision: $Id: sfunc_experimental.cpp 171 2010-10-04 13:57:19Z kulshres $
5 Contents: function module containing an experimental function
6 
7   Each << function module >> contains:
8         
9     (1) const char* const controlFileName
10     (2) int indepDim;
11     (3) void initProblemParameters( void )
12     (4) void initIndependents( double* indeps )
13     (5) double originalScalarFunction( double* indeps )
14     (6) double tapingScalarFunction( int tag, double* indeps )   
15 
16 Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz,
17               Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel
18 
19 This file is part of ADOL-C. This software is provided as open source.
20 Any use, reproduction, or distribution of the software constitutes
21 recipient's acceptance of the terms of the accompanying license file.
22 
23---------------------------------------------------------------------------*/
24#define _SFUNC_EXPERIMENTAL_C_
25
26
27/****************************************************************************/
28/*                                                                 INCLUDES */
29#include <adolc/adolc.h>
30
31#include <time.h>
32#include <cmath>
33
34
35/****************************************************************************/
36/*                                                         GLOBAL VARIABLES */
37
38/*--------------------------------------------------------------------------*/
39/*                                                        Control file name */
40const char* controlFileName = "experimental.ctrl";
41
42/*--------------------------------------------------------------------------*/
43/*                                                               Dimensions */
44int indepDim;
45
46/*--------------------------------------------------------------------------*/
47/*                                       Other problem dependent parameters */
48//#define CODE sqrt(indeps[i])
49#define CODE sin(indeps[i])
50//#define CODE indeps[i]*indeps[i]
51
52
53/****************************************************************************/
54/*                                                  INIT PROBLEM PARAMETERS */
55void initProblemParameters( void ) {
56    fprintf(stdout,"EXPERIMENTAL EXAMPLE (ADOL-C Example)\n\n");
57    if (indepDim <= 0) {
58        fprintf(stdout,"    number of independent variables = ? ");
59        fscanf(stdin,"%d",&indepDim);
60        fprintf(stdout,"\n");
61    }
62}
63
64
65/****************************************************************************/
66/*                                                        INITIALIZE INDEPs */
67void initIndependents( double* indeps ) {
68    int i;
69    for (i=0; i<indepDim; i++)
70        indeps[i] = (i+1.0)/(2.0+i);
71}
72
73
74/****************************************************************************/
75/*                                                 ORIGINAL SCALAR FUNCTION */
76
77/*--------------------------------------------------------------------------*/
78/*                                                    experimental function */
79double experimental( int dim, double* indeps ) {
80    int i;
81    double y = 1.0;
82    for (i=0; i<dim; i++)
83        y += CODE;
84    return y;
85}
86
87/*--------------------------------------------------------------------------*/
88/*                                                   The interface function */
89double originalScalarFunction( double* indeps ) {
90    return experimental(indepDim, indeps);
91}
92
93
94/****************************************************************************/
95/*                                                   TAPING SCALAR FUNCTION */
96
97/*--------------------------------------------------------------------------*/
98/*                                             active experimental function */
99adouble activeExperimental( int dim, adouble* indeps ) {
100    int i;
101    adouble y = 1.0;
102    for (i=0; i<dim; i++)
103        y += CODE;
104    return y;
105}
106
107/*--------------------------------------------------------------------------*/
108/*                                                   The interface function */
109double tapingScalarFunction( int tag, double* indeps ) {
110    int i;
111    trace_on(tag);
112    adouble* activeIndeps = new adouble[indepDim];
113    adouble* aIP = activeIndeps;
114    double*  iP  = indeps;
115    for (i=0; i<indepDim; i++)
116        *aIP++ <<= *iP++;
117    adouble ares = activeExperimental(indepDim, activeIndeps);
118    double res = 0;
119    ares >>= res;
120    trace_off();
121    return res;
122}
123
124#undef _SFUNC_EXPERIMENTAL_C_
125
126
127
128
129
130
131
Note: See TracBrowser for help on using the repository browser.