27 #include <iostream.hpp>
30 #if defined (__WAT32__)
39 typedef __int64 ssize_t;
48 #include <sys/types.h>
55 #include <sys/types.h>
59 #if defined(__NDPX__ )
61 int LSEEK(
int,
int,
int);
62 int read(
int,
char*,
int);
69 void _far * _cdecl _farptr_norm(
void _far *);
70 void _far * _cdecl _farptr_fromlong(
unsigned long);
71 long _cdecl _farptr_tolong(
void _far *);
74 #if !defined(OPT_LIB) || defined(_MSC_VER)
82 cerr <<
"Error: No instance of gradient data structure.\n";
100 cerr <<
"nvar != gradient_structure::NVAR in gradcalc" <<
endl;
101 cerr <<
" nvar = " << nvar <<
endl;
102 cerr <<
" gradient_structure::NVAR = " <<
NVAR
104 cerr <<
" in " __FILE__ <<
endl;
117 if (g.
size() <
static_cast<unsigned int>(nvar))
119 cerr <<
"gradient vector size is less than the number of variables.\n";
127 LSEEK(_GRADFILE_PTR,0L,SEEK_CUR);
132 cerr <<
"warning -- calling gradcalc when no calculations generating"
133 <<
endl <<
"derivative information have occurred" <<
endl;
161 #ifdef FAST_ASSEMBLER
177 }
while (break_flag);
185 cout <<
"Offset in file at end of gradcalc is " << ttmp
186 <<
" bytes from the beginning\n";
192 for (
int i = 0; i < nvar; ++i)
194 *pgi = *(*paddressi);
225 void* temp_ptr =
nullptr;
226 unsigned long bytes_needed =
230 if ( (temp_ptr = farmalloc(bytes_needed) ) == 0)
233 if ((temp_ptr = (
void *)malloc(bytes_needed)) == 0)
237 save_var_file_flag=1;
238 cerr <<
"insufficient memory to allocate space for ARRAY_MEMBLOCK"
239 <<
" save buffer " <<
endl;
241 if (save_var_file_flag==0)
245 #ifndef USE_ASSEMBLER
253 unsigned long int max_move=50000;
254 unsigned long int left_to_move=bytes_needed;
257 while(left_to_move > max_move)
259 memcpy((
char*)dest,(
char*)src,max_move);
260 left_to_move-=max_move;
264 memcpy((
char*)dest,(
char*)src,left_to_move);
279 unsigned long int max_move=500;
280 unsigned long int left_to_move=bytes_needed;
281 while(left_to_move > max_move)
283 write(_VARSSAV_PTR,(
char*)src,max_move);
284 left_to_move-=max_move;
296 unsigned long bytes_needed =
301 #ifndef USE_ASSEMBLER
309 unsigned long max_move=50000;
311 long int left_to_move=bytes_needed;
314 while(left_to_move > max_move)
316 memcpy((
char*)dest,(
char*)src,max_move);
317 left_to_move-=max_move;
321 memcpy((
char*)dest,(
char*)src,left_to_move);
330 #if defined(OPT_LIB) && !defined(_MSC_VER)
337 unsigned long int max_move=50000;
339 long int left_to_move=bytes_needed;
340 while(left_to_move > max_move)
343 left_to_move-=max_move;
374 LSEEK(_GRADFILE_PTR,0L,SEEK_SET);
386 double* dep_addr,
double* ind_addr1)
408 void test_the_pointer(
void)
indvar_offset_list * INDVAR_LIST
void set_gradient_stack1(void(*func)(void), double *dep_addr, double *ind_addr1)
Sets the gradient stack entry for a function or operator with a single independent variable...
void read(const test_smartlist &, void *, int nsize)
double * ind_addr1
Pointer to first independent variable.
void memcpy(test_smartlist &dest, void *source, const size_t nsize)
memcpy for test_smartlist
void gradcalc(int nvar, const dvector &g)
Compute the gradient from the data stored in the global gradient_structure.
Vector of double precision numbers.
int indexmin() const
Get minimum valid index.
static int no_derivatives
void save_variables()
Save variables to a buffer.
static unsigned long ARRAY_MEMBLOCK_SIZE
Holds derivative information for arithmetic operators and math library functions. ...
void write_grad_stack_buffer()
void gradcalc(int nvar, const dvector &g)
unsigned long int get_last_offset()
humungous_pointer ARRAY_MEMBLOCK_BASE
prnstream & endl(prnstream &)
size_t PREVIOUS_TOTAL_BYTES
unsigned long int get_max_last_offset()
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
humungous_pointer ARRAY_MEMBLOCK_SAVE
static _THREAD gradient_structure * _instance
void initialize(void)
Initialze all elements of dvector to zero.
grad_stack_entry * ptr_first
void restore_variables()
Restore variables from buffer.
unsigned int size() const
Get number of elements in array.
void save_variables()
Save variables to a buffer.
void write(const test_smartlist &, void *, int nsize)
int read_grad_stack_buffer(OFF_T &lpos)
Description not yet available.
void restore_variables()
Restore variables from buffer.
void reset_gradient_stack(void)
Rewind buffer.
void save_arrays()
Compute the gradient from the data stored in the global gradient_structure.
static _THREAD grad_stack * GRAD_STACK1
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
void free()
Description not yet available.
grad_stack_entry * ptr_last
void(* func)(void)
< Pointer to function (if any) to be used for derivative calculation
Description not yet available.
double * dep_addr
Pointer to dependent variable.