QPALM 1.2.4
Proximal Augmented Lagrangian method for Quadratic Programs
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1/**
2 * @file util.h
3 * @author Ben Hermans
4 * @brief Utility functions.
5 * @details This file contains some utility functions, to copy the settings,
6 * to update the solver status, to print information and to time the algorithm.
7 */
8#ifndef UTIL_H
9#define UTIL_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <qpalm/types.h>
16#include <qpalm/constants.h>
17
18
19/**********************
20* Utility Functions *
21**********************/
22
23/**
24 * Copy settings creating a new settings structure.
25 * @warning This function uses malloc.
26 * @param settings Settings to be copied
27 * @return New settings structure
28 */
30
31
32/**
33 * Custom string copy to avoid string.h library.
34 * @param dest Destination string
35 * @param source Source string
36 */
37void c_strcpy(char dest[],
38 const char source[]);
39
40
41/**
42 * Update solver status (value and string).
43 * @param info QPALMInfo
44 * @param status_val New status value
45 */
46void update_status(QPALMInfo *info,
47 c_int status_val);
48
49
50/**********************
51* Print Functions *
52**********************/
53
54#ifdef QPALM_PRINTING
55
56/**
57 * Print the header with QPALM version number and fields.
58 */
59void print_header(void);
60
61/**
62 * Print information about the current iteration. (Residuals, stepsize and objective value)
63 * @param iter The current iteration number
64 * @param work Workspace
65 */
66void print_iteration(c_int iter, QPALMWorkspace *work);
67
68/**
69 * Print final message as a box with info. (Final residuals, objective function, runtime)
70 * @param work Workspace
71 */
73
74#endif // QPALM_PRINTING
75
76
77/*********************************
78* Timer Structs and Functions * *
79*********************************/
80
81# ifdef QPALM_TIMING
82
83/*! \cond PRIVATE */
84
85// Windows
86# ifdef _WIN32
87
88 // Some R packages clash with elements
89 // of the windows.h header, so use a
90 // slimmer version for conflict avoidance
91 # ifdef R_LANG
92 #define NOGDI
93 # endif
94
95# include <windows.h>
96
97struct QPALM_TIMER {
98 LARGE_INTEGER tic;
99 LARGE_INTEGER toc;
100 LARGE_INTEGER freq;
101};
102
103// Mac
104# elif defined __APPLE__
105
106# include <mach/mach_time.h>
107
108/* Use MAC OSX mach_time for timing */
109struct QPALM_TIMER {
110 uint64_t tic;
111 uint64_t toc;
112 mach_timebase_info_data_t tinfo;
113};
114
115// Mac
116# elif defined __MACH__
117
118# include <mach/mach_time.h>
119
120/* Use MAC OSX mach_time for timing */
121struct QPALM_TIMER {
122 uint64_t tic;
123 uint64_t toc;
124 mach_timebase_info_data_t tinfo;
125};
126
127// Linux
128# elif defined __linux__ // ifdef _WIN32
129
130# include <time.h>
131# include <sys/time.h>
132
133struct QPALM_TIMER {
134 struct timespec tic;
135 struct timespec toc;
136};
137
138// FreeBSD
139# elif defined __FreeBSD__ // ifdef _WIN32
140
141# include <time.h>
142# include <sys/time.h>
143
144struct QPALM_TIMER {
145 struct timespec tic;
146 struct timespec toc;
147};
148
149# endif // ifdef _WIN32
150
151/*! \endcond */
152
153
154/**
155 * Start timer.
156 * @param t Timer object
157 */
159
160/**
161 * Report time in seconds since last call to qpalm_tic.
162 * @param t Timer object
163 * @return Reported time in seconds
164 */
166
167# endif /* END #ifdef QPALM_TIMING */
168
169
170# ifdef __cplusplus
171}
172# endif
173
174#endif /* ifndef UTIL_H */
Constants used in QPALM.
ladel_int c_int
type for integer numbers
Definition global_opts.h:42
ladel_double c_float
type for floating point numbers
Definition global_opts.h:41
Solver return information.
Definition types.h:81
Settings struct.
Definition types.h:124
QPALM Workspace.
Definition types.h:204
Internal data structures used in QPALM.
struct QPALM_TIMER QPALMTimer
QPALM Timer for statistics.
Definition types.h:60
QPALMSettings * copy_settings(const QPALMSettings *settings)
Copy settings creating a new settings structure.
Definition util.c:25
void update_status(QPALMInfo *info, c_int status_val)
Update solver status (value and string).
Definition util.c:62
void print_iteration(c_int iter, QPALMWorkspace *work)
Print information about the current iteration.
Definition util.c:117
c_float qpalm_toc(QPALMTimer *t)
Report time in seconds since last call to qpalm_tic.
void c_strcpy(char dest[], const char source[])
Custom string copy to avoid string.h library.
Definition util.c:19
void qpalm_tic(QPALMTimer *t)
Start timer.
void print_header(void)
Print the header with QPALM version number and fields.
Definition util.c:111
void print_final_message(QPALMWorkspace *work)
Print final message as a box with info.
Definition util.c:125