ADMB Documentation  11.1.1920
 All Classes Files Functions Variables Typedefs Friends Defines
gs_set.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: gs_set.cpp 1714 2014-03-01 00:45:28Z 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(long long int 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 (LLONG_MAX < i)
00092   {
00093     cerr << "\n\n It appears that the size you are setting for "
00094       "the\n CMPDIF_BUFFER is > " <<  LLONG_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  " << LLONG_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(long long int 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   long long max_size = LLONG_MAX / sizeof(grad_stack_entry);
00143   if (LLONG_MAX < i)
00144   {
00145     cerr << "\n\n It appears that the size you are setting for "
00146       "the\n GRADSTACK_BUFFER is > " << LLONG_MAX <<
00147       "This appears\n to be an error. The maximum size argument ";
00148     cerr << "for the function\n"
00149       "--- gradient_structure::set_GRADSTACK_BUFFER_SIZE(long long int i) ---\n"
00150       "should probably be  " << max_size << endl;
00151     cerr << "LLONG_MAX = " << LLONG_MAX << endl;
00152     cerr << " i = " << i << endl;
00153     cerr << " max_size = " << max_size << endl;
00154     cerr << " total = " << max_size * i << endl;
00155   }
00156 #endif
00157   check_set_error("GRADSTACK_BUFFER_SIZE");
00158   GRADSTACK_BUFFER_SIZE = i;
00159 }
00160 
00168 #ifdef __BORLANDC__
00169 void gradient_structure::set_GRADSTACK_BUFFER_BYTES(long int i)
00170 #else
00171 void gradient_structure::set_GRADSTACK_BUFFER_BYTES(long long int i)
00172 #endif
00173 {
00174 #ifdef __BORLANDC__
00175   long int gs_size=(long int) (sizeof(grad_stack_entry));
00176 
00177   if ( (unsigned long int) (LONG_MAX) < i)
00178   {
00179     unsigned int max_size=LONG_MAX;
00180 
00181     cerr << "\n\n It appears that the size you are setting for "
00182       "the\n GRADSTACK_BUFFER is > " << LONG_MAX <<
00183       "This appears\n to be an error. The maximum size argument ";
00184     cerr << "for the function\n"
00185       "--- gradient_structure::set_GRADSTACK_BUFFER_BYTES(long int i) ---\n"
00186       "should probably be  " << max_size << endl;
00187     cerr << "LONG_MAX = " << (unsigned long int) (LONG_MAX) << endl;
00188     cerr << " i = " << i << endl;
00189     cerr << "Note: the Borland compiler limit is a long integer\n"
00190       "      other compilers allow long long integers" << endl;
00191   }
00192 #else
00193   if (LLONG_MAX < i)
00194   {
00195     long long int max_size=LLONG_MAX;
00196 
00197     cerr << "\n\n It appears that the size you are setting for "
00198       "the\n GRADSTACK_BUFFER is > " << LLONG_MAX <<
00199       "This appears\n to be an error. The maximum size argument ";
00200     cerr << "for the function\n"
00201      "--- gradient_structure::set_GRADSTACK_BUFFER_BYTES(long long int i) ---\n"
00202       "should probably be  " << max_size << endl;
00203     cerr << "LLONG_MAX = " << LLONG_MAX << endl;
00204     cerr << " i = " << i << endl;
00205   }
00206   long long int gs_size=(long long int)sizeof(grad_stack_entry);
00207 #endif
00208   check_set_error("GRADSTACK_BUFFER_SIZE");
00209   GRADSTACK_BUFFER_SIZE = i/gs_size;
00210 }
00211 
00216 void gradient_structure::set_MAX_NVAR_OFFSET(unsigned int i)
00217 {
00218   check_set_error("MAX_NVAR_OFFSET");
00219   MAX_NVAR_OFFSET = i;
00220 }
00221 
00226 void gradient_structure::set_MAX_DLINKS(int i)
00227 {
00228   check_set_error("MAX_DLINKS");
00229   MAX_DLINKS = i > 0 ? i : 0;
00230 }