Scippy

SCIP

Solving Constraint Integer Programs

scip_mem.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_mem.c
17  * @brief public methods for memory management
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  * @author Gerald Gamrath
21  * @author Robert Lion Gottwald
22  * @author Stefan Heinz
23  * @author Gregor Hendel
24  * @author Thorsten Koch
25  * @author Alexander Martin
26  * @author Marc Pfetsch
27  * @author Michael Winkler
28  * @author Kati Wolter
29  *
30  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
31  */
32 
33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34 
35 #include <ctype.h>
36 #include <stdarg.h>
37 #include <assert.h>
38 #include <string.h>
39 #if defined(_WIN32) || defined(_WIN64)
40 #else
41 #include <strings.h> /*lint --e{766}*/
42 #endif
43 
44 
45 #include "lpi/lpi.h"
46 #include "nlpi/exprinterpret.h"
47 #include "nlpi/nlpi.h"
48 #include "scip/benders.h"
49 #include "scip/benderscut.h"
50 #include "scip/branch.h"
51 #include "scip/branch_nodereopt.h"
52 #include "scip/clock.h"
53 #include "scip/compr.h"
54 #include "scip/concsolver.h"
55 #include "scip/concurrent.h"
56 #include "scip/conflict.h"
57 #include "scip/conflictstore.h"
58 #include "scip/cons.h"
59 #include "scip/cons_linear.h"
60 #include "scip/cutpool.h"
61 #include "scip/cuts.h"
62 #include "scip/debug.h"
63 #include "scip/def.h"
64 #include "scip/dialog.h"
65 #include "scip/dialog_default.h"
66 #include "scip/disp.h"
67 #include "scip/event.h"
68 #include "scip/heur.h"
69 #include "scip/heur_ofins.h"
70 #include "scip/heur_reoptsols.h"
72 #include "scip/heuristics.h"
73 #include "scip/history.h"
74 #include "scip/implics.h"
75 #include "scip/interrupt.h"
76 #include "scip/lp.h"
77 #include "scip/mem.h"
78 #include "scip/message_default.h"
79 #include "scip/misc.h"
80 #include "scip/nlp.h"
81 #include "scip/nodesel.h"
82 #include "scip/paramset.h"
83 #include "scip/presol.h"
84 #include "scip/presolve.h"
85 #include "scip/pricer.h"
86 #include "scip/pricestore.h"
87 #include "scip/primal.h"
88 #include "scip/prob.h"
89 #include "scip/prop.h"
90 #include "scip/reader.h"
91 #include "scip/relax.h"
92 #include "scip/reopt.h"
93 #include "scip/retcode.h"
94 #include "scip/scipbuildflags.h"
95 #include "scip/scipcoreplugins.h"
96 #include "scip/scipgithash.h"
97 #include "scip/sepa.h"
98 #include "scip/sepastore.h"
99 #include "scip/set.h"
100 #include "scip/sol.h"
101 #include "scip/solve.h"
102 #include "scip/stat.h"
103 #include "scip/syncstore.h"
104 #include "scip/table.h"
105 #include "scip/tree.h"
106 #include "scip/var.h"
107 #include "scip/visual.h"
108 #include "xml/xml.h"
109 
110 #include "scip/scip_mem.h"
111 
112 #include "scip/pub_message.h"
113 
114 
115 /* In debug mode, we include the SCIP's structure in scip.c, such that no one can access
116  * this structure except the interface methods in scip.c.
117  * In optimized mode, the structure is included in scip.h, because some of the methods
118  * are implemented as defines for performance reasons (e.g. the numerical comparisons)
119  */
120 #ifndef NDEBUG
121 #include "scip/struct_scip.h"
122 #endif
123 
124 /** returns block memory to use at the current time
125  *
126  * @return the block memory to use at the current time.
127  */
129  SCIP* scip /**< SCIP data structure */
130  )
131 {
132  assert(scip != NULL);
133  assert(scip->set != NULL);
134  assert(scip->mem != NULL);
135 
136  return scip->mem->probmem;
137 }
138 
139 /** returns buffer memory for short living temporary objects
140  *
141  * @return the buffer memory for short living temporary objects
142  */
144  SCIP* scip /**< SCIP data structure */
145  )
146 {
147  assert(scip != NULL);
148  assert(scip->mem != NULL);
149 
150  return scip->mem->buffer;
151 }
152 
153 /** returns clean buffer memory for short living temporary objects initialized to all zero
154  *
155  * @return the buffer memory for short living temporary objects initialized to all zero
156  */
158  SCIP* scip /**< SCIP data structure */
159  )
160 {
161  assert(scip != NULL);
162  assert(scip->mem != NULL);
163 
164  return scip->mem->cleanbuffer;
165 }
166 
167 /** returns the total number of bytes used in block and buffer memory
168  *
169  * @return the total number of bytes used in block and buffer memory.
170  */
172  SCIP* scip /**< SCIP data structure */
173  )
174 {
175  assert(scip != NULL);
176 
177  return SCIPmemGetUsed(scip->mem);
178 }
179 
180 /** returns the total number of bytes in block and buffer memory
181  *
182  * @return the total number of bytes in block and buffer memory.
183  */
185  SCIP* scip /**< SCIP data structure */
186  )
187 {
188  assert(scip != NULL);
189 
190  return SCIPmemGetTotal(scip->mem);
191 }
192 
193 /** returns the estimated number of bytes used by external software, e.g., the LP solver
194  *
195  * @return the estimated number of bytes used by external software, e.g., the LP solver.
196  */
198  SCIP* scip /**< SCIP data structure */
199  )
200 {
201  assert(scip != NULL);
202 
203  return SCIPstatGetMemExternEstim(scip->stat);
204 }
205 
206 /** calculate memory size for dynamically allocated arrays
207  *
208  * @return the memory size for dynamically allocated arrays.
209  */
211  SCIP* scip, /**< SCIP data structure */
212  int num /**< minimum number of entries to store */
213  )
214 {
215  assert(scip != NULL);
216 
217  return SCIPsetCalcMemGrowSize(scip->set, num);
218 }
219 
220 /** extends a dynamically allocated block memory array to be able to store at least the given number of elements;
221  * use SCIPensureBlockMemoryArray() define to call this method!
222  *
223  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
224  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
225  */
227  SCIP* scip, /**< SCIP data structure */
228  void** arrayptr, /**< pointer to dynamically sized array */
229  size_t elemsize, /**< size in bytes of each element in array */
230  int* arraysize, /**< pointer to current array size */
231  int minsize /**< required minimal array size */
232  )
233 {
234  assert(scip != NULL);
235  assert(arrayptr != NULL);
236  assert(elemsize > 0);
237  assert(arraysize != NULL);
238 
239  if( minsize > *arraysize )
240  {
241  int newsize;
242 
243  newsize = SCIPsetCalcMemGrowSize(scip->set, minsize);
244  SCIP_ALLOC( BMSreallocBlockMemorySize(SCIPblkmem(scip), arrayptr, *arraysize * elemsize, newsize * elemsize) );
245  *arraysize = newsize;
246  }
247 
248  return SCIP_OKAY;
249 }
250 
251 /** prints output about used memory */
253  SCIP* scip /**< SCIP data structure */
254  )
255 {
256  assert(scip != NULL);
257  assert(scip->mem != NULL);
258  assert(scip->set != NULL);
259 
261 
262  SCIPmessagePrintInfo(scip->messagehdlr, "\nParameter Block Memory (%p):\n", scip->mem->setmem);
264 
265  SCIPmessagePrintInfo(scip->messagehdlr, "\nSolution Block Memory (%p):\n", scip->mem->probmem);
267 
268  SCIPmessagePrintInfo(scip->messagehdlr, "\nMemory Buffers:\n");
270 
271  SCIPmessagePrintInfo(scip->messagehdlr, "\nClean Memory Buffers:\n");
273 }
internal methods for separators
SCIP_STAT * stat
Definition: struct_scip.h:69
#define NULL
Definition: def.h:246
internal methods for managing events
default message handler
trivialnegation primal heuristic
internal methods for storing primal CIP solutions
BMS_BUFMEM * cleanbuffer
Definition: struct_mem.h:42
methods to interpret (evaluate) an expression tree "fast"
internal methods for branch and bound tree
public methods for memory management
BMS_BUFMEM * buffer
Definition: struct_mem.h:41
SCIP_Longint SCIPmemGetUsed(SCIP_MEM *mem)
Definition: mem.c:87
methods for implications, variable bounds, and cliques
internal methods for clocks and timing issues
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip_mem.c:210
internal methods for NLPI solver interfaces
interface methods for specific LP solvers
internal methods for displaying statistics tables
methods for the aggregation rows
internal methods for Benders&#39; decomposition
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
methods commonly used by primal heuristics
internal methods for branching rules and branching candidate storage
int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
Definition: set.c:5503
datastructures for concurrent solvers
#define BMSdisplayBlockMemory(mem)
Definition: memory.h:468
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:128
internal methods for handling parameter settings
methods for creating output for visualization tools (VBC, BAK)
nodereopt branching rule
internal methods for LP management
SCIP_RETCODE SCIPensureBlockMemoryArray_call(SCIP *scip, void **arrayptr, size_t elemsize, int *arraysize, int minsize)
Definition: scip_mem.c:226
internal methods for branching and inference history
internal methods for collecting primal CIP solutions and primal informations
internal methods for propagators
void SCIPprintMemoryDiagnostic(SCIP *scip)
Definition: scip_mem.c:252
SCIP_MEM * mem
Definition: struct_scip.h:61
BMS_BUFMEM * SCIPbuffer(SCIP *scip)
Definition: scip_mem.c:143
git hash methods
internal methods for storing and manipulating the main problem
methods for block memory pools and memory buffers
#define BMSdisplayMemory()
Definition: memory.h:143
register additional core functionality that is designed as plugins
internal methods for presolvers
internal methods for NLP management
internal miscellaneous methods
internal methods for node selectors and node priority queues
internal methods for variable pricers
internal methods for global SCIP settings
internal methods for storing conflicts
SCIP main data structure.
BMS_BLKMEM * setmem
Definition: struct_mem.h:39
void SCIPmessagePrintInfo(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
Definition: message.c:584
BMS_BUFMEM * SCIPcleanbuffer(SCIP *scip)
Definition: scip_mem.c:157
internal methods for storing priced variables
internal methods for relaxators
internal methods for storing separated cuts
methods commonly used for presolving
methods for catching the user CTRL-C interrupt
internal methods for problem variables
data structures and methods for collecting reoptimization information
the function declarations for the synchronization store
internal methods for user interface dialog
#define BMSreallocBlockMemorySize(mem, ptr, oldsize, newsize)
Definition: memory.h:444
internal methods for input file readers
methods for debugging
reoptsols primal heuristic
internal methods for storing cuts in a cut pool
Constraint handler for linear constraints in their most general form, .
helper functions for concurrent scip solvers
internal methods for return codes for SCIP methods
SCIP_Longint SCIPgetMemTotal(SCIP *scip)
Definition: scip_mem.c:184
void BMSprintBufferMemory(BMS_BUFMEM *buffer)
Definition: memory.c:3122
BMS_BLKMEM * probmem
Definition: struct_mem.h:40
internal methods for conflict analysis
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:171
internal methods for tree compressions
internal methods for main solving loop and node processing
SCIP_Longint SCIPmemGetTotal(SCIP_MEM *mem)
Definition: mem.c:98
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:197
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:65
default user interface dialog
internal methods for problem statistics
SCIP_Longint SCIPstatGetMemExternEstim(SCIP_STAT *stat)
Definition: stat.c:633
internal methods for constraints and constraint handlers
#define SCIP_Longint
Definition: def.h:142
declarations for XML parsing
build flags methods
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:426
internal methods for primal heuristics
#define SCIP_ALLOC(x)
Definition: def.h:369
internal methods for Benders&#39; decomposition cuts
internal methods for displaying runtime statistics
OFINS - Objective Function Induced Neighborhood Search - a primal heuristic for reoptimization.