ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gs_set.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include "fvar.hpp"
12 #ifdef __TURBOC__
13  #pragma hdrstop
14 #endif
15 #include <limits.h>
16 
21 void gradient_structure::check_set_error(const char* variable_name)
22 {
23  if (instances > 0)
24  {
25  cerr << "Error -- variable '" << variable_name <<"' must be set before\n"
26  "declaration of gradient_structure object.\n";
27  ad_exit(1);
28  }
29 }
30 
37 {
39 }
40 
47 {
48  check_set_error("NUM_RETURN_ARRAYS");
50 }
51 
58 {
59  cerr << " This is not the way to set the ARRAY_MEMBLOCK_SIZE -- sorry\n"
60  " You set it by declaring the number of bytes you want in the\n";
61  cerr << " declaration gradient_structure gs(num_bytes)\n"
62  " in your program .. the default value is 100000L\n";
63  ad_exit(1);
64  check_set_error("ARRAY_MEMBLOCK_SIZE");
65 }
66 
72 #ifdef __BORLANDC__
74 #else
76 #endif
77 {
78 #ifdef __BORLANDC__
79  if ( (unsigned long int) (LONG_MAX) < (unsigned long int)i)
80  {
81  long int max_size=LONG_MAX;
82 
83  cerr << "\n\n It appears that the size you are setting for "
84  "the\n CMPDIF_BUFFER is > " << LONG_MAX <<
85  "This appears\n to be an error. The maximum size argument ";
86  cerr << "for the function\n"
87  "--- gradient_structure::set_CMPDIF_BUFFER_SIZE(long long int i) ---\n"
88  "should probably be " << max_size << endl;
89  }
90 #else
91  size_t max_size(LLONG_MAX);
92  if (i > max_size)
93  {
94  cerr << "\n\n It appears that the size you are setting for "
95  "the\n CMPDIF_BUFFER is > " << max_size <<
96  "This appears\n to be an error. The maximum size argument ";
97  cerr << "for the function\n"
98  "--- gradient_structure::set_CMPDIF_BUFFER_SIZE(long long int i) ---\n"
99  "should probably be " << max_size << endl;
100  }
101 #endif
102  check_set_error("CMPDIF_BUFFER_SIZE");
103  CMPDIF_BUFFER_SIZE = i;
104 }
105 
116 #ifdef __BORLANDC__
118 #else
120 #endif
121 {
122 #ifdef __BORLANDC__
123  long int gs_size=(long int) (sizeof(grad_stack_entry));
124 
125  if ( (unsigned long int) (LONG_MAX) < gs_size *i)
126  {
127  unsigned int max_size=LONG_MAX/gs_size;
128 
129  cerr << "\n\n It appears that the size you are setting for "
130  "the\n GRADSTACK_BUFFER is > " << LONG_MAX <<
131  "This appears\n to be an error. The maximum size argument ";
132  cerr << "for the function\n"
133  "--- gradient_structure::set_GRADSTACK_BUFFER_SIZE(long long int i) ---\n"
134  "should probably be " << max_size << endl;
135  cerr << "Note: the Borland compiler limit is a long integer\n"
136  " other compilers allow long long integers" << endl;
137  cerr << "LONG_MAX = " << (unsigned long int) (LONG_MAX) << endl;
138  cerr << " i = " << i << endl;
139  cerr << " gs_size = " << gs_size << endl;
140  cerr << " i*gs_size = " << i*gs_size << endl;
141  }
142 #else
143  size_t max_size(LLONG_MAX);
144  if (i > max_size)
145  {
146  cerr << "\n\n It appears that the size you are setting for "
147  "the\n GRADSTACK_BUFFER is > " << max_size <<
148  "This appears\n to be an error. The maximum size argument ";
149 
150  size_t n = max_size / sizeof(grad_stack_entry);
151  cerr << "for the function\n"
152  "--- gradient_structure::set_GRADSTACK_BUFFER_SIZE(long long int i) ---\n"
153  "should probably be " << max_size << endl;
154  cerr << "LLONG_MAX = " << LLONG_MAX << endl;
155  cerr << " n = " << n << endl;
156  cerr << " i = " << i << endl;
157  cerr << " total = " << max_size * i << endl;
158  }
159 #endif
160  check_set_error("GRADSTACK_BUFFER_SIZE");
161  GRADSTACK_BUFFER_SIZE = i;
162 }
163 
171 #ifdef __BORLANDC__
173 #else
175 #endif
176 {
177 #ifdef __BORLANDC__
178  long int gs_size=(long int) (sizeof(grad_stack_entry));
179 
180  if ( (unsigned long int) (LONG_MAX) < i)
181  {
182  unsigned int max_size=LONG_MAX;
183 
184  cerr << "\n\n It appears that the size you are setting for "
185  "the\n GRADSTACK_BUFFER is > " << LONG_MAX <<
186  "This appears\n to be an error. The maximum size argument ";
187  cerr << "for the function\n"
188  "--- gradient_structure::set_GRADSTACK_BUFFER_BYTES(long int i) ---\n"
189  "should probably be " << max_size << endl;
190  cerr << "LONG_MAX = " << (unsigned long int) (LONG_MAX) << endl;
191  cerr << " i = " << i << endl;
192  cerr << "Note: the Borland compiler limit is a long integer\n"
193  " other compilers allow long long integers" << endl;
194  }
195 #else
196  size_t max_size(LLONG_MAX);
197  if (i > max_size)
198  {
199  cerr << "\n\n It appears that the size you are setting for "
200  "the\n GRADSTACK_BUFFER is > " << max_size <<
201  "This appears\n to be an error. The maximum size argument ";
202  cerr << "for the function\n"
203  "--- gradient_structure::set_GRADSTACK_BUFFER_BYTES(long long int i) ---\n"
204  "should probably be " << max_size << endl;
205  cerr << "LLONG_MAX = " << LLONG_MAX << endl;
206  cerr << " i = " << i << endl;
207  }
208  size_t gs_size = sizeof(grad_stack_entry);
209 #endif
210  check_set_error("GRADSTACK_BUFFER_SIZE");
211  GRADSTACK_BUFFER_SIZE = i/gs_size;
212 }
213 
219 {
220  check_set_error("MAX_NVAR_OFFSET");
221  MAX_NVAR_OFFSET = i;
222 }
223 
229 {
230  check_set_error("MAX_DLINKS");
231  MAX_DLINKS = i > 0 ? (unsigned int)i : 0;
232 }
static void set_ARRAY_MEMBLOCK_SIZE(unsigned long i)
Set the the maximum amount of memory (in bytes) available for the autodif variable type container cla...
Definition: gs_set.cpp:57
static void set_GRADSTACK_BUFFER_SIZE(const size_t i)
Set the number of entries contained in the buffer that, in turn, contains the information necessary f...
Definition: gs_set.cpp:119
Holds derivative information for arithmetic operators and math library functions. ...
Definition: fvar.hpp:894
exitptr ad_exit
Definition: gradstrc.cpp:53
static unsigned int NUM_RETURN_ARRAYS
static void check_set_error(const char *variable_name)
Produce error if gradient structure hasn&#39;t been set.
Definition: gs_set.cpp:21
static void set_NUM_RETURN_ARRAYS(unsigned int i)
Set the maximum allowable depth of nesting of functions that return autodif variable types...
Definition: gs_set.cpp:46
static unsigned int MAX_NVAR_OFFSET
static unsigned int RETURN_ARRAYS_SIZE
static void set_MAX_NVAR_OFFSET(unsigned int i)
Set the the maximum number of independent variables that can be used.
Definition: gs_set.cpp:218
prnstream & endl(prnstream &)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static void set_CMPDIF_BUFFER_SIZE(const size_t i)
Set the size in bytes of the buffer used to contain the information generated by the &quot;precompiled&quot; de...
Definition: gs_set.cpp:75
static void set_GRADSTACK_BUFFER_BYTES(const size_t i)
Set (in bytes) the number of entries contained in the buffer used for calculating derivatives...
Definition: gs_set.cpp:174
static void set_RETURN_ARRAYS_SIZE(unsigned int i)
Set the return arrays size controlling the amount of complexity that one line of arithmetic can have...
Definition: gs_set.cpp:36
static unsigned int MAX_DLINKS
static void set_MAX_DLINKS(int i)
Set the maximum number of dvariable objects that can be in scope at one time.
Definition: gs_set.cpp:228