21 #if defined(THREAD_SAFE)
22 pthread_mutex_t mutex_return_arrays = PTHREAD_MUTEX_INITIALIZER;
29 #if defined(__TURBOC__)
38 #include <iostream.hpp>
39 int _cdecl farfree(
void _far *ptr);
40 void _far * _cdecl farmalloc(
unsigned long size);
48 typedef int (*
fptr) (
const char * format, ...) ;
57 ad_printf(
" Exception -- error code %d\n",ierr);
60 #if defined(USE_EXCEPTIONS)
72 #if (defined(NO_DERIVS))
101 long int _farptr_tolong(
void *) ;
175 size_t k = strlen(s);
194 #if defined(USE_VECTOR_SHAPE_POOL)
225 cerr <<
"Wrong number of options to -mdl -- must be 1"
226 " you have " << nopt <<
endl;
236 assert(
sizeof(
char) == 1);
240 assert(
sizeof(
dlink) == 2 *
sizeof(
double));
242 const size_t size = 2 *
sizeof(double) * (numlinks + 1);
243 char* tmp1 = (
char*)malloc(size *
sizeof(
char));
246 cerr <<
"Error[" << __FILE__ <<
":" << __LINE__
247 <<
"]: unable to allocate memory.\n";
253 tmp1+=2*
sizeof(double);
257 int& nlinks=(
int&)GRAD_LIST->
nlinks;
259 for (
unsigned int i=1;i<=numlinks;i++)
264 tmp1+=2*
sizeof(double);
310 static_cast<unsigned long int>(_size - remainder);
318 cerr <<
"Usage -ndv option needs integer -- ignored" <<
endl;
325 cerr <<
"Usage -ndv option needs positive integer -- ignored"
348 cerr <<
" In gradient_structure::gradient_structure()\n";
361 void* temp_ptr = NULL;
363 if ((temp_ptr = farmalloc(ARRAY_MEMBLOCK_SIZE)) == 0)
365 if ((temp_ptr = (
void*)malloc(ARRAY_MEMBLOCK_SIZE)) == 0)
368 cerr <<
"insufficient memory to allocate space for ARRAY_MEMBLOCKa\n";
386 cout <<
"_GRAD_STACK1= "<< _farptr_tolong(
_GRAD_STACK1)<<
"\n";
406 cerr <<
"Wrong number of options to -mno -- must be 1"
407 " you have " << nopt <<
endl;
480 #if defined(THREAD_SAFE)
481 pthread_mutex_lock(&mutex_return_arrays);
487 cerr <<
" Overflow in RETURN_ARRAYS stack -- Increase NUM_RETURN_ARRAYS\n";
488 cerr <<
" There may be a RETURN_ARRAYS_INCREMENT()\n";
489 cerr <<
" which is not matched by a RETURN_ARRAYS_DECREMENT()\n";
496 #if defined(THREAD_SAFE)
497 pthread_mutex_unlock(&mutex_return_arrays);
513 #if defined(THREAD_SAFE)
514 pthread_mutex_lock(&mutex_return_arrays);
518 cerr <<
" Error -- RETURN_ARRAYS_PTR is 0 \n";
519 cerr <<
" There must be a RETURN_ARRAYS_DECREMENT()\n";
520 cerr <<
" which is not matched by a RETURN_ARRAYS_INCREMENT()\n";
530 #if defined(THREAD_SAFE)
531 pthread_mutex_unlock(&mutex_return_arrays);
597 cerr <<
"Trying to close stream referenced by a NULL pointer\n"
598 " in ~gradient_structure\n";
617 cerr <<
"Trying to delete a NULL pointer in ~gradient_structure" <<
endl;
628 cerr <<
" Error trying to allocate " << s <<
"\n";
633 #if defined(NO_DERIVS)
683 "gradient_structure::set_NUM_DEPENDENT_VARIABLES(int i)"
684 <<
endl <<
" value of i must be >= 1" <<
endl;
indvar_offset_list * INDVAR_LIST
static int NUM_DEPENDENT_VARIABLES
grad_stack_entry * true_ptr_first
static void set_NO_DERIVATIVES(void)
Disable accumulation of derivative information.
void RETURN_ARRAYS_DECREMENT(void)
Decrements gradient_structure::RETURN_ARRAYS_PTR.
virtual ~gradient_structure()
Destructor.
dependent_variables_information * DEPVARS_INFO
void create(const unsigned int size)
Allocate array of gradient_structure instances with size elements.
Description not yet available.
static int no_derivatives
static unsigned long ARRAY_MEMBLOCK_SIZE
void memory_allocate_error(const char *s, void *ptr)
Description not yet available.
static long int USE_FOR_HESSIAN
friend void cleanup_temporary_files()
Close gradient and variable files and free gradient structure memory.
char lastchar(char *)
Description not yet available.
static unsigned int NUM_RETURN_ARRAYS
static unsigned int MAX_NVAR_OFFSET
int atoi(adstring &s)
Returns a integer converted from input s.
void allocate_dvariable_space()
Description not yet available.
Holds the data for the prevariable class.
humungous_pointer ARRAY_MEMBLOCK_BASE
static unsigned int RETURN_ARRAYS_SIZE
size_t totalbytes(void)
Description not yet available.
prnstream & endl(prnstream &)
void null_ptr_err_message(void)
Outputs null error message.
static dvariable * next_RETURN_PTR()
size_t PREVIOUS_TOTAL_BYTES
void RETURN_ARRAYS_INCREMENT()
size_t NUM_GRADSTACK_BYTES_WRITTEN()
Description not yet available.
void clean()
Delete gradient_structure instances.
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static gradient_structure * reset(gradient_structure *)
static _THREAD gradient_structure * _instance
dvariable ** RETURN_PTR_CONTAINER
void adjust(const size_t)
Description not yet available.
Description not yet available.
gradient_structure * set(const unsigned int id)
Set _instance of gradient_structure from instances with id.
int option_match(int argc, char *argv[], const char *string)
Checks if the program has been invoked with a particular command line argument ("string").
static _THREAD DF_FILE * fp
static void set_YES_SAVE_VARIABLES_VALUES()
Description not yet available.
static void set_NUM_DEPENDENT_VARIABLES(int i)
Description not yet available.
dvariable ** RETURN_ARRAYS
static int Hybrid_bounded_flag
static void set_NO_SAVE_VARIABLES_VALUES()
Description not yet available.
unsigned int RETURN_ARRAYS_PTR
void fill_ad_random_part(void)
int(* fptr)(const char *format,...)
static void set_YES_DERIVATIVES(void)
Enable accumulation of derivative information.
void RETURN_ARRAYS_DECREMENT()
static unsigned int MAX_DLINKS
void RETURN_ARRAYS_INCREMENT(void)
Increments gradient_structure::RETURN_ARRAYS_PTR.
static size_t GRADSTACK_BUFFER_SIZE
static _THREAD grad_stack * GRAD_STACK1
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
Fundamental data type for reverse mode automatic differentiation.
int ad_printf(FILE *stream, const char *format, Args...args)
gradient_structure ** gradients
grad_stack * _GRAD_STACK1
void cleanup_temporary_files()
Close gradient and variable files and free gradient structure memory.
unsigned int gradients_size
static size_t CMPDIF_BUFFER_SIZE