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 "scip/mem.h"
36 #include "scip/pub_message.h"
37 #include "scip/scip_mem.h"
38 #include "scip/set.h"
39 #include "scip/stat.h"
40 #include "scip/struct_mem.h"
41 #include "scip/struct_scip.h"
42 
43 /** returns block memory to use at the current time
44  *
45  * @return the block memory to use at the current time.
46  */
48  SCIP* scip /**< SCIP data structure */
49  )
50 {
51  assert(scip != NULL);
52  assert(scip->set != NULL);
53  assert(scip->mem != NULL);
54 
55  return scip->mem->probmem;
56 }
57 
58 /** returns buffer memory for short living temporary objects
59  *
60  * @return the buffer memory for short living temporary objects
61  */
63  SCIP* scip /**< SCIP data structure */
64  )
65 {
66  assert(scip != NULL);
67  assert(scip->mem != NULL);
68 
69  return scip->mem->buffer;
70 }
71 
72 /** returns clean buffer memory for short living temporary objects initialized to all zero
73  *
74  * @return the buffer memory for short living temporary objects initialized to all zero
75  */
77  SCIP* scip /**< SCIP data structure */
78  )
79 {
80  assert(scip != NULL);
81  assert(scip->mem != NULL);
82 
83  return scip->mem->cleanbuffer;
84 }
85 
86 /** returns the total number of bytes used in block and buffer memory
87  *
88  * @return the total number of bytes used in block and buffer memory.
89  */
91  SCIP* scip /**< SCIP data structure */
92  )
93 {
94  assert(scip != NULL);
95 
96  return SCIPmemGetUsed(scip->mem);
97 }
98 
99 /** returns the total number of bytes in block and buffer memory
100  *
101  * @return the total number of bytes in block and buffer memory.
102  */
104  SCIP* scip /**< SCIP data structure */
105  )
106 {
107  assert(scip != NULL);
108 
109  return SCIPmemGetTotal(scip->mem);
110 }
111 
112 /** returns the estimated number of bytes used by external software, e.g., the LP solver
113  *
114  * @return the estimated number of bytes used by external software, e.g., the LP solver.
115  */
117  SCIP* scip /**< SCIP data structure */
118  )
119 {
120  assert(scip != NULL);
121 
122  return SCIPstatGetMemExternEstim(scip->stat);
123 }
124 
125 /** calculate memory size for dynamically allocated arrays
126  *
127  * @return the memory size for dynamically allocated arrays.
128  */
130  SCIP* scip, /**< SCIP data structure */
131  int num /**< minimum number of entries to store */
132  )
133 {
134  assert(scip != NULL);
135 
136  return SCIPsetCalcMemGrowSize(scip->set, num);
137 }
138 
139 /** extends a dynamically allocated block memory array to be able to store at least the given number of elements;
140  * use SCIPensureBlockMemoryArray() define to call this method!
141  *
142  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
143  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
144  */
146  SCIP* scip, /**< SCIP data structure */
147  void** arrayptr, /**< pointer to dynamically sized array */
148  size_t elemsize, /**< size in bytes of each element in array */
149  int* arraysize, /**< pointer to current array size */
150  int minsize /**< required minimal array size */
151  )
152 {
153  assert(scip != NULL);
154  assert(arrayptr != NULL);
155  assert(elemsize > 0);
156  assert(arraysize != NULL);
157 
158  if( minsize > *arraysize )
159  {
160  int newsize;
161 
162  newsize = SCIPsetCalcMemGrowSize(scip->set, minsize);
163  SCIP_ALLOC( BMSreallocBlockMemorySize(SCIPblkmem(scip), arrayptr, *arraysize * elemsize, newsize * elemsize) );
164  *arraysize = newsize;
165  }
166 
167  return SCIP_OKAY;
168 }
169 
170 /** prints output about used memory */
172  SCIP* scip /**< SCIP data structure */
173  )
174 {
175  assert(scip != NULL);
176  assert(scip->mem != NULL);
177  assert(scip->set != NULL);
178 
180 
181  SCIPmessagePrintInfo(scip->messagehdlr, "\nParameter Block Memory (%p):\n", scip->mem->setmem);
183 
184  SCIPmessagePrintInfo(scip->messagehdlr, "\nSolution Block Memory (%p):\n", scip->mem->probmem);
186 
187  SCIPmessagePrintInfo(scip->messagehdlr, "\nMemory Buffers:\n");
189 
190  SCIPmessagePrintInfo(scip->messagehdlr, "\nClean Memory Buffers:\n");
192 }
SCIP_STAT * stat
Definition: struct_scip.h:69
#define NULL
Definition: def.h:253
BMS_BUFMEM * cleanbuffer
Definition: struct_mem.h:42
public methods for memory management
BMS_BUFMEM * buffer
Definition: struct_mem.h:41
SCIP_Longint SCIPmemGetUsed(SCIP_MEM *mem)
Definition: mem.c:87
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
Definition: set.c:5503
#define BMSdisplayBlockMemory(mem)
Definition: memory.h:469
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:90
SCIP_Longint SCIPgetMemTotal(SCIP *scip)
Definition: scip_mem.c:103
SCIP_MEM * mem
Definition: struct_scip.h:61
methods for block memory pools and memory buffers
#define BMSdisplayMemory()
Definition: memory.h:144
internal methods for global SCIP settings
SCIP main data structure.
BMS_BLKMEM * setmem
Definition: struct_mem.h:39
void SCIPmessagePrintInfo(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
Definition: message.c:584
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip_mem.c:129
#define BMSreallocBlockMemorySize(mem, ptr, oldsize, newsize)
Definition: memory.h:445
SCIP_RETCODE SCIPensureBlockMemoryArray_call(SCIP *scip, void **arrayptr, size_t elemsize, int *arraysize, int minsize)
Definition: scip_mem.c:145
datastructures for block memory pools and memory buffers
BMS_BUFMEM * SCIPbuffer(SCIP *scip)
Definition: scip_mem.c:62
void BMSprintBufferMemory(BMS_BUFMEM *buffer)
Definition: memory.c:3118
BMS_BLKMEM * probmem
Definition: struct_mem.h:40
SCIP_Longint SCIPmemGetTotal(SCIP_MEM *mem)
Definition: mem.c:98
void SCIPprintMemoryDiagnostic(SCIP *scip)
Definition: scip_mem.c:171
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:65
internal methods for problem statistics
BMS_BUFMEM * SCIPcleanbuffer(SCIP *scip)
Definition: scip_mem.c:76
SCIP_Longint SCIPstatGetMemExternEstim(SCIP_STAT *stat)
Definition: stat.c:633
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:47
#define SCIP_Longint
Definition: def.h:149
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:116
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:427
#define SCIP_ALLOC(x)
Definition: def.h:376