ADMB Documentation  11.1.2490
 All Classes Files Functions Variables Typedefs Friends Defines
gs_set.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: gs_set.cpp 2422 2014-09-29 19:27:29Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
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   if (i > ULONG_MAX)
00092   {
00093     cerr << "\n\n It appears that the size you are setting for "
00094       "the\n CMPDIF_BUFFER is > " <<  ULONG_MAX <<
00095       "This appears\n to be an error. The maximum size argument ";
00096     cerr << "for the function\n"
00097       "--- gradient_structure::set_CMPDIF_BUFFER_SIZE(long long int i) ---\n"
00098       "should probably be  " << ULONG_MAX << endl;
00099   }
00100 #endif
00101   check_set_error("CMPDIF_BUFFER_SIZE");
00102   CMPDIF_BUFFER_SIZE = i;
00103 }
00104 
00115 #ifdef __BORLANDC__
00116 void gradient_structure::set_GRADSTACK_BUFFER_SIZE(long int i)
00117 #else
00118 void gradient_structure::set_GRADSTACK_BUFFER_SIZE(const size_t i)
00119 #endif
00120 {
00121 #ifdef __BORLANDC__
00122   long int gs_size=(long int) (sizeof(grad_stack_entry));
00123 
00124   if ( (unsigned long int) (LONG_MAX) < gs_size *i)
00125   {
00126     unsigned int max_size=LONG_MAX/gs_size;
00127 
00128     cerr << "\n\n It appears that the size you are setting for "
00129       "the\n GRADSTACK_BUFFER is > " << LONG_MAX <<
00130       "This appears\n to be an error. The maximum size argument ";
00131     cerr << "for the function\n"
00132       "--- gradient_structure::set_GRADSTACK_BUFFER_SIZE(long long int i) ---\n"
00133       "should probably be  " << max_size << endl;
00134     cerr << "Note: the Borland compiler limit is a long integer\n"
00135       "      other compilers allow long long integers" << endl;
00136     cerr << "LONG_MAX = " << (unsigned long int) (LONG_MAX) << endl;
00137     cerr << " i = " << i << endl;
00138     cerr << " gs_size = " << gs_size << endl;
00139     cerr << " i*gs_size = " << i*gs_size << endl;
00140   }
00141 #else
00142   if (i > ULONG_MAX)
00143   {
00144     cerr << "\n\n It appears that the size you are setting for "
00145       "the\n GRADSTACK_BUFFER is > " << ULONG_MAX <<
00146       "This appears\n to be an error. The maximum size argument ";
00147 
00148     size_t max_size = size_t(ULONG_MAX) / sizeof(grad_stack_entry);
00149     cerr << "for the function\n"
00150       "--- gradient_structure::set_GRADSTACK_BUFFER_SIZE(long long int i) ---\n"
00151       "should probably be  " << max_size << endl;
00152     cerr << "ULONG_MAX = " << ULONG_MAX << endl;
00153     cerr << " i = " << i << endl;
00154     cerr << " max_size = " << max_size << endl;
00155     cerr << " total = " << max_size * i << endl;
00156   }
00157 #endif
00158   check_set_error("GRADSTACK_BUFFER_SIZE");
00159   GRADSTACK_BUFFER_SIZE = i;
00160 }
00161 
00169 #ifdef __BORLANDC__
00170 void gradient_structure::set_GRADSTACK_BUFFER_BYTES(long int i)
00171 #else
00172 void gradient_structure::set_GRADSTACK_BUFFER_BYTES(const size_t i)
00173 #endif
00174 {
00175 #ifdef __BORLANDC__
00176   long int gs_size=(long int) (sizeof(grad_stack_entry));
00177 
00178   if ( (unsigned long int) (LONG_MAX) < i)
00179   {
00180     unsigned int max_size=LONG_MAX;
00181 
00182     cerr << "\n\n It appears that the size you are setting for "
00183       "the\n GRADSTACK_BUFFER is > " << LONG_MAX <<
00184       "This appears\n to be an error. The maximum size argument ";
00185     cerr << "for the function\n"
00186       "--- gradient_structure::set_GRADSTACK_BUFFER_BYTES(long int i) ---\n"
00187       "should probably be  " << max_size << endl;
00188     cerr << "LONG_MAX = " << (unsigned long int) (LONG_MAX) << endl;
00189     cerr << " i = " << i << endl;
00190     cerr << "Note: the Borland compiler limit is a long integer\n"
00191       "      other compilers allow long long integers" << endl;
00192   }
00193 #else
00194   if (i > ULONG_MAX)
00195   {
00196     size_t max_size = ULONG_MAX;
00197 
00198     cerr << "\n\n It appears that the size you are setting for "
00199       "the\n GRADSTACK_BUFFER is > " << ULONG_MAX <<
00200       "This appears\n to be an error. The maximum size argument ";
00201     cerr << "for the function\n"
00202      "--- gradient_structure::set_GRADSTACK_BUFFER_BYTES(long long int i) ---\n"
00203       "should probably be  " << max_size << endl;
00204     cerr << "ULONG_MAX = " << ULONG_MAX << endl;
00205     cerr << " i = " << i << endl;
00206   }
00207   size_t gs_size = sizeof(grad_stack_entry);
00208 #endif
00209   check_set_error("GRADSTACK_BUFFER_SIZE");
00210   GRADSTACK_BUFFER_SIZE = i/gs_size;
00211 }
00212 
00217 void gradient_structure::set_MAX_NVAR_OFFSET(unsigned int i)
00218 {
00219   check_set_error("MAX_NVAR_OFFSET");
00220   MAX_NVAR_OFFSET = i;
00221 }
00222 
00227 void gradient_structure::set_MAX_DLINKS(int i)
00228 {
00229   check_set_error("MAX_DLINKS");
00230   MAX_DLINKS = i > 0 ? (unsigned int)i : 0;
00231 }