QPALM
A proximal augmented Lagrangian method for QPs.
global_opts.h
Go to the documentation of this file.
1 
11 #ifndef GLOBAL_OPTS_H
12 # define GLOBAL_OPTS_H
13 
14 # ifdef __cplusplus
15 extern "C" {
16 # endif /* ifdef __cplusplus */
17 
18 
19 #ifdef USE_LADEL
20 #include "ladel.h"
21 typedef ladel_double c_float;
22 typedef ladel_int c_int;
24 #elif defined USE_CHOLMOD
25 #include "cholmod.h"
26 
31 #ifdef DLONG
32 #define Real double
33 #define Int SuiteSparse_long
34 #define Int_max SuiteSparse_long_max
35 #define CHOLMOD(name) cholmod_l_ ## name
36 
37 #define ITYPE CHOLMOD_LONG
38 #define DTYPE CHOLMOD_DOUBLE
39 #define ID SuiteSparse_long_id
40 #else
41 
42 #ifndef DINT
43 #define DINT
44 #endif
45 //#define INT
46 //#define DOUBLE
47 
48 #define Real double
49 #define Int int
50 #define Int_max INT_MAX
51 #define CHOLMOD(name) cholmod_ ## name
52 #define ITYPE CHOLMOD_INT
53 #define DTYPE CHOLMOD_DOUBLE
54 #define ID "%d"
55 
56 /* GPU acceleration is not available for the int version of CHOLMOD */
57 #undef GPU_BLAS
58 
59 #endif
60 
61 typedef Real c_float;
62 typedef Int c_int;
64 #endif /* USE_CHOLMOD */
65 
74 # include <stdlib.h>
75 
84 # ifdef MATLAB
85  # include "mex.h"
86 static void* c_calloc(size_t num, size_t size) {
87  void *m = mxCalloc(num, size);
88  mexMakeMemoryPersistent(m);
89  return m;
90 }
91 
92 static void* c_malloc(size_t size) {
93  void *m = mxMalloc(size);
94 
95  mexMakeMemoryPersistent(m);
96  return m;
97 }
98 
99 static void* c_realloc(void *ptr, size_t size) {
100  void *m = mxRealloc(ptr, size);
101 
102  mexMakeMemoryPersistent(m);
103  return m;
104 }
105 
106  # define c_free mxFree
107 # elif defined PYTHON
108 
109 // Define memory allocation for python. Note that in Python 2 memory manager
110 // Calloc is not implemented
111  # include <Python.h>
112  # define c_malloc PyMem_Malloc
113  # if PY_MAJOR_VERSION >= 3
114  # define c_calloc PyMem_Calloc
115  # else /* if PY_MAJOR_VERSION >= 3 */
116 static void* c_calloc(size_t num, size_t size) {
117  void *m = PyMem_Malloc(num * size);
118 
119  memset(m, 0, num * size);
120  return m;
121 }
122 
123  # endif /* if PY_MAJOR_VERSION >= 3 */
124 
125  # define c_free PyMem_Free
126  # define c_realloc PyMem_Realloc
127 # else /* if not MATLAB of Python */
128  # define c_malloc malloc
129  # define c_calloc calloc
130  # define c_free free
131  # define c_realloc realloc
133 # endif /* ifdef MATLAB */
134 
140 /* PRINTING */
141 # ifdef PRINTING
142 # include <stdio.h>
143 # include <string.h>
144 
145 # ifdef MATLAB
146 # define c_print mexPrintf
147 
148 # elif defined PYTHON
149 # include <Python.h>
150 # define c_print(...) {PyGILState_STATE gstate; gstate = PyGILState_Ensure(); PySys_WriteStdout(__VA_ARGS__); PyGILState_Release(gstate);}
151 # elif defined R_LANG
152 # include <R_ext/Print.h>
153 # define c_print Rprintf
154 # else /* ifdef MATLAB */
155 # define c_print printf
156 # endif /* ifdef MATLAB */
157 
158 // Print error macro
159 # define c_eprint(...) c_print("ERROR in %s: ", __FUNCTION__); c_print( \
160  __VA_ARGS__); c_print("\n");
161 
162 # endif /* ifdef PRINTING */
163 
164 
169 # ifndef c_absval
170 # define c_absval(x) (((x) < 0) ? -(x) : (x))
171 # endif /* ifndef c_absval */
172 
173 # ifndef c_max
174 # define c_max(a, b) (((a) > (b)) ? (a) : (b))
175 # endif /* ifndef c_max */
176 
177 # ifndef c_min
178 # define c_min(a, b) (((a) < (b)) ? (a) : (b))
179 # endif /* ifndef c_min */
180 
181 # ifndef mod
182 # define mod(a,b) ((((a)%(b))+(b))%(b))
183 #endif
184 
185 #include <math.h>
186 # define c_sqrt sqrt
190 # ifdef __cplusplus
191 }
192 # endif /* ifdef __cplusplus */
193 
194 #endif /* ifndef GLOBAL_OPTS_H */
#define c_malloc
custom malloc
Definition: global_opts.h:128
#define c_calloc
custom calloc
Definition: global_opts.h:129
#define c_realloc
custom realloc
Definition: global_opts.h:131
ladel_int c_int
type for integer numbers
Definition: global_opts.h:22
ladel_double c_float
type for floating point numbers
Definition: global_opts.h:21