Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011 #include "fvar.hpp"
00012 #ifdef __TURBOC__
00013 #pragma hdrstop
00014 #endif
00015 #include <limits.h>
00016
00021 void gradient_structure::check_set_error(const char* variable_name)
00022 {
00023 if (instances > 0)
00024 {
00025 cerr << "Error -- variable '" << variable_name <<"' must be set before\n"
00026 "declaration of gradient_structure object.\n";
00027 ad_exit(1);
00028 }
00029 }
00030
00036 void gradient_structure::set_RETURN_ARRAYS_SIZE(int i)
00037 {
00038 RETURN_ARRAYS_SIZE=i;
00039 }
00040
00046 void gradient_structure::set_NUM_RETURN_ARRAYS(int i)
00047 {
00048 check_set_error("NUM_RETURN_ARRAYS");
00049 NUM_RETURN_ARRAYS = i;
00050 }
00051
00057 void gradient_structure::set_ARRAY_MEMBLOCK_SIZE(unsigned long i)
00058 {
00059 cerr << " This is not the way to set the ARRAY_MEMBLOCK_SIZE -- sorry\n"
00060 " You set it by declaring the number of bytes you want in the\n";
00061 cerr << " declaration gradient_structure gs(num_bytes)\n"
00062 " in your program .. the default value is 100000L\n";
00063 ad_exit(1);
00064 check_set_error("ARRAY_MEMBLOCK_SIZE");
00065 }
00066
00072 #ifdef __BORLANDC__
00073 void gradient_structure::set_CMPDIF_BUFFER_SIZE(long int i)
00074 #else
00075 void gradient_structure::set_CMPDIF_BUFFER_SIZE(const size_t i)
00076 #endif
00077 {
00078 #ifdef __BORLANDC__
00079 if ( (unsigned long int) (LONG_MAX) < (unsigned long int)i)
00080 {
00081 long int max_size=LONG_MAX;
00082
00083 cerr << "\n\n It appears that the size you are setting for "
00084 "the\n CMPDIF_BUFFER is > " << LONG_MAX <<
00085 "This appears\n to be an error. The maximum size argument ";
00086 cerr << "for the function\n"
00087 "--- gradient_structure::set_CMPDIF_BUFFER_SIZE(long long int i) ---\n"
00088 "should probably be " << max_size << endl;
00089 }
00090 #else
00091 size_t max_size(LLONG_MAX);
00092 if (i > max_size)
00093 {
00094 cerr << "\n\n It appears that the size you are setting for "
00095 "the\n CMPDIF_BUFFER is > " << max_size <<
00096 "This appears\n to be an error. The maximum size argument ";
00097 cerr << "for the function\n"
00098 "--- gradient_structure::set_CMPDIF_BUFFER_SIZE(long long int i) ---\n"
00099 "should probably be " << max_size << endl;
00100 }
00101 #endif
00102 check_set_error("CMPDIF_BUFFER_SIZE");
00103 CMPDIF_BUFFER_SIZE = i;
00104 }
00105
00116 #ifdef __BORLANDC__
00117 void gradient_structure::set_GRADSTACK_BUFFER_SIZE(long int i)
00118 #else
00119 void gradient_structure::set_GRADSTACK_BUFFER_SIZE(const size_t i)
00120 #endif
00121 {
00122 #ifdef __BORLANDC__
00123 long int gs_size=(long int) (sizeof(grad_stack_entry));
00124
00125 if ( (unsigned long int) (LONG_MAX) < gs_size *i)
00126 {
00127 unsigned int max_size=LONG_MAX/gs_size;
00128
00129 cerr << "\n\n It appears that the size you are setting for "
00130 "the\n GRADSTACK_BUFFER is > " << LONG_MAX <<
00131 "This appears\n to be an error. The maximum size argument ";
00132 cerr << "for the function\n"
00133 "--- gradient_structure::set_GRADSTACK_BUFFER_SIZE(long long int i) ---\n"
00134 "should probably be " << max_size << endl;
00135 cerr << "Note: the Borland compiler limit is a long integer\n"
00136 " other compilers allow long long integers" << endl;
00137 cerr << "LONG_MAX = " << (unsigned long int) (LONG_MAX) << endl;
00138 cerr << " i = " << i << endl;
00139 cerr << " gs_size = " << gs_size << endl;
00140 cerr << " i*gs_size = " << i*gs_size << endl;
00141 }
00142 #else
00143 size_t max_size(LLONG_MAX);
00144 if (i > max_size)
00145 {
00146 cerr << "\n\n It appears that the size you are setting for "
00147 "the\n GRADSTACK_BUFFER is > " << max_size <<
00148 "This appears\n to be an error. The maximum size argument ";
00149
00150 size_t n = max_size / sizeof(grad_stack_entry);
00151 cerr << "for the function\n"
00152 "--- gradient_structure::set_GRADSTACK_BUFFER_SIZE(long long int i) ---\n"
00153 "should probably be " << max_size << endl;
00154 cerr << "LLONG_MAX = " << LLONG_MAX << endl;
00155 cerr << " n = " << n << endl;
00156 cerr << " i = " << i << endl;
00157 cerr << " total = " << max_size * i << endl;
00158 }
00159 #endif
00160 check_set_error("GRADSTACK_BUFFER_SIZE");
00161 GRADSTACK_BUFFER_SIZE = i;
00162 }
00163
00171 #ifdef __BORLANDC__
00172 void gradient_structure::set_GRADSTACK_BUFFER_BYTES(long int i)
00173 #else
00174 void gradient_structure::set_GRADSTACK_BUFFER_BYTES(const size_t i)
00175 #endif
00176 {
00177 #ifdef __BORLANDC__
00178 long int gs_size=(long int) (sizeof(grad_stack_entry));
00179
00180 if ( (unsigned long int) (LONG_MAX) < i)
00181 {
00182 unsigned int max_size=LONG_MAX;
00183
00184 cerr << "\n\n It appears that the size you are setting for "
00185 "the\n GRADSTACK_BUFFER is > " << LONG_MAX <<
00186 "This appears\n to be an error. The maximum size argument ";
00187 cerr << "for the function\n"
00188 "--- gradient_structure::set_GRADSTACK_BUFFER_BYTES(long int i) ---\n"
00189 "should probably be " << max_size << endl;
00190 cerr << "LONG_MAX = " << (unsigned long int) (LONG_MAX) << endl;
00191 cerr << " i = " << i << endl;
00192 cerr << "Note: the Borland compiler limit is a long integer\n"
00193 " other compilers allow long long integers" << endl;
00194 }
00195 #else
00196 size_t max_size(LLONG_MAX);
00197 if (i > max_size)
00198 {
00199 cerr << "\n\n It appears that the size you are setting for "
00200 "the\n GRADSTACK_BUFFER is > " << max_size <<
00201 "This appears\n to be an error. The maximum size argument ";
00202 cerr << "for the function\n"
00203 "--- gradient_structure::set_GRADSTACK_BUFFER_BYTES(long long int i) ---\n"
00204 "should probably be " << max_size << endl;
00205 cerr << "LLONG_MAX = " << LLONG_MAX << endl;
00206 cerr << " i = " << i << endl;
00207 }
00208 size_t gs_size = sizeof(grad_stack_entry);
00209 #endif
00210 check_set_error("GRADSTACK_BUFFER_SIZE");
00211 GRADSTACK_BUFFER_SIZE = i/gs_size;
00212 }
00213
00218 void gradient_structure::set_MAX_NVAR_OFFSET(unsigned int i)
00219 {
00220 check_set_error("MAX_NVAR_OFFSET");
00221 MAX_NVAR_OFFSET = i;
00222 }
00223
00228 void gradient_structure::set_MAX_DLINKS(int i)
00229 {
00230 check_set_error("MAX_DLINKS");
00231 MAX_DLINKS = i > 0 ? (unsigned int)i : 0;
00232 }