SuperSCS  1.3.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
util.h
Go to the documentation of this file.
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2017 Pantelis Sopasakis (https://alphaville.github.io),
5  * Krina Menounou (https://www.linkedin.com/in/krinamenounou),
6  * Panagiotis Patrinos (http://homes.esat.kuleuven.be/~ppatrino)
7  * Copyright (c) 2012 Brendan O'Donoghue (bodonoghue85@gmail.com)
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in all
17  * copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  *
27  */
28 #ifndef UTIL_H_GUARD
29 #define UTIL_H_GUARD
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #if !(defined _WIN32 || defined _WIN64 || defined _WINDLL || defined __APPLE__)
36 #ifdef _POSIX_C_SOURCE
37 #undef _POSIX_C_SOURCE
38 #endif
39 #define _POSIX_C_SOURCE 200112L
40 #endif
41 
42 #include <stdlib.h>
43 #include <stdarg.h>
44 #include "scs.h"
45 
46  /* timing code courtesy of A. Domahidi */
47 #if (defined NOTIMER)
48  typedef void *ScsTimer;
49 #elif(defined _WIN32 || defined _WIN64 || defined _WINDLL)
50  /* Use Windows QueryPerformanceCounter for timing */
51 #include <windows.h>
52 
53  struct scs_timer {
54  LARGE_INTEGER tic;
55  LARGE_INTEGER toc;
56  LARGE_INTEGER freq;
57  };
58 
59 #elif(defined __APPLE__)
60  /* Use MAC OSX mach_time for timing */
61 #include <mach/mach_time.h>
62 
63  struct scs_timer {
64  uint64_t tic;
65  uint64_t toc;
66  mach_timebase_info_data_t tinfo;
67  };
68 
69 #else
70 
71 #include <sys/time.h> /* Use POSIX clock_gettime() for timing on other machines */
72 #include <time.h>
73 
77  struct scs_timer {
78  struct timespec tic;
79  struct timespec toc;
80  };
81 
82 
83 #endif
84 
88  typedef struct scs_timer ScsTimer;
89 
90  /* these all return milli-seconds */
91 
96  void scs_tic(ScsTimer *timer);
111  scs_float scs_toc(ScsTimer *timer);
120  scs_float scs_strtoc(char *str, ScsTimer *timer);
131  scs_float scs_toc_quiet(ScsTimer *timer);
132 
137  void scs_print_cone_data(const ScsCone * RESTRICT cone);
142  void scs_print_data(const ScsData *data);
147  void scs_print_work(const ScsWork *work);
148 
156  void scs_print_array(
157  const scs_float * RESTRICT arr,
158  scs_int n,
159  const char *RESTRICT name);
160 
219 
234  void scs_set_restarted_broyden_settings(ScsData * RESTRICT data, scs_int broyden_memory);
235 
250  void scs_set_anderson_settings(ScsData * RESTRICT data, scs_int anderson_memory);
251 
267  void scs_set_tolerance(ScsData * RESTRICT data, scs_float tolerance);
268 
283  void scs_set_memory(ScsData * RESTRICT data, scs_int memory);
284 
292  void scs_free_sol(ScsSolution * RESTRICT sol);
293 
301  void scs_free_data(ScsData *RESTRICT data);
302 
307  void scs_free_cone(ScsCone *RESTRICT cone);
325  void scs_free_info(ScsInfo * RESTRICT info);
326 
347  int scs_special_print(scs_int print_mode,
348  FILE * RESTRICT __stream,
349  const char *RESTRICT __format, ...);
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 #endif
struct timespec toc
Definition: util.h:79
Terminating information.
Definition: scs.h:539
#define RESTRICT
Definition: glbopts.h:44
void scs_set_default_settings(ScsData *RESTRICT data)
Sets the settings to certain default values.
struct timespec tic
Definition: util.h:78
SCS timer structure.
Definition: util.h:77
scs_float scs_toc_quiet(ScsTimer *timer)
Stops the timer.
void scs_free_cone(ScsCone *RESTRICT cone)
void scs_set_anderson_settings(ScsData *RESTRICT data, scs_int anderson_memory)
void scs_tic(ScsTimer *timer)
Starts the timer.
int scs_int
Definition: glbopts.h:96
scs_float scs_strtoc(char *str, ScsTimer *timer)
Stops the timer and prints a custom message.
void scs_print_data(const ScsData *data)
Prints the content of a Data object.
void scs_free_data_cone(ScsData *RESTRICT d, ScsCone *RESTRICT k)
Frees the memory allocate of a Data and a Cone object.
Cone structure.
Definition: cones.h:48
void scs_set_tolerance(ScsData *RESTRICT data, scs_float tolerance)
void scs_free_info(ScsInfo *RESTRICT info)
Frees the memory allocated for an Info object.
void scs_print_array(const scs_float *RESTRICT arr, scs_int n, const char *RESTRICT name)
Prints an array.
void scs_free_data(ScsData *RESTRICT data)
void scs_set_restarted_broyden_settings(ScsData *RESTRICT data, scs_int broyden_memory)
double scs_float
Definition: glbopts.h:100
struct scs_timer ScsTimer
Definition: util.h:88
int scs_special_print(scs_int print_mode, FILE *RESTRICT __stream, const char *RESTRICT __format,...)
Custom print function for SCS.
void scs_print_cone_data(const ScsCone *RESTRICT cone)
Prints the content of a Cone object.
struct containing problem data
Definition: scs.h:254
Workspace for SCS.
Definition: scs.h:75
void scs_free_sol(ScsSolution *RESTRICT sol)
Frees the memory allocated for a Sol object.
void scs_set_memory(ScsData *RESTRICT data, scs_int memory)
void scs_print_work(const ScsWork *work)
Prints the content of a Work object.
scs_float scs_toc(ScsTimer *timer)
Stops the timer.
Primal-dual solution arrays.
Definition: scs.h:518