1 #include "util.h" 2 3 #include "glbopts.h" 4 #include "linsys.h" 5 #include "scs_matrix.h" 6 7 /* return milli-seconds */ 8 #if (defined NOTIMER) 9 SCS(tic)10void SCS(tic)(SCS(timer) * t) { 11 } SCS(tocq)12scs_float SCS(tocq)(SCS(timer) * t) { 13 return NAN; 14 } 15 16 #elif (defined _WIN32 || _WIN64 || defined _WINDLL) 17 SCS(tic)18void SCS(tic)(SCS(timer) * t) { 19 QueryPerformanceFrequency(&t->freq); 20 QueryPerformanceCounter(&t->tic); 21 } 22 SCS(tocq)23scs_float SCS(tocq)(SCS(timer) * t) { 24 QueryPerformanceCounter(&t->toc); 25 return (1e3 * (t->toc.QuadPart - t->tic.QuadPart) / 26 (scs_float)t->freq.QuadPart); 27 } 28 29 #elif (defined __APPLE__) 30 #include <stdint.h> 31 SCS(tic)32void SCS(tic)(SCS(timer) * t) { 33 /* read current clock cycles */ 34 t->tic = mach_absolute_time(); 35 } 36 SCS(tocq)37scs_float SCS(tocq)(SCS(timer) * t) { 38 uint64_t duration; /* elapsed time in clock cycles*/ 39 40 t->toc = mach_absolute_time(); 41 duration = t->toc - t->tic; 42 43 /*conversion from clock cycles to nanoseconds*/ 44 mach_timebase_info(&(t->tinfo)); 45 duration *= t->tinfo.numer; 46 duration /= t->tinfo.denom; 47 48 return (scs_float)duration / 1e6; 49 } 50 51 #else 52 SCS(tic)53void SCS(tic)(SCS(timer) * t) { 54 clock_gettime(CLOCK_MONOTONIC, &t->tic); 55 } 56 SCS(tocq)57scs_float SCS(tocq)(SCS(timer) * t) { 58 struct timespec temp; 59 60 clock_gettime(CLOCK_MONOTONIC, &t->toc); 61 62 if ((t->toc.tv_nsec - t->tic.tv_nsec) < 0) { 63 temp.tv_sec = t->toc.tv_sec - t->tic.tv_sec - 1; 64 temp.tv_nsec = 1e9 + t->toc.tv_nsec - t->tic.tv_nsec; 65 } else { 66 temp.tv_sec = t->toc.tv_sec - t->tic.tv_sec; 67 temp.tv_nsec = t->toc.tv_nsec - t->tic.tv_nsec; 68 } 69 return (scs_float)temp.tv_sec * 1e3 + (scs_float)temp.tv_nsec / 1e6; 70 } 71 72 #endif 73 SCS(free_data)74void SCS(free_data)(ScsData *d, ScsCone *k, ScsSettings *stgs) { 75 if (d) { 76 scs_free(d->b); 77 scs_free(d->c); 78 if (d->A) { 79 SCS(free_scs_matrix)(d->A); 80 } 81 if (d->P) { 82 SCS(free_scs_matrix)(d->P); 83 } 84 scs_free(d); 85 } 86 if (k) { 87 scs_free(k->bu); 88 scs_free(k->bl); 89 scs_free(k->q); 90 scs_free(k->s); 91 scs_free(k->p); 92 scs_free(k); 93 } 94 if (stgs) { 95 scs_free(stgs); 96 } 97 } 98 SCS(free_sol)99void SCS(free_sol)(ScsSolution *sol) { 100 if (sol) { 101 scs_free(sol->x); 102 scs_free(sol->y); 103 scs_free(sol->s); 104 scs_free(sol); 105 } 106 } 107 108 /* assumes stgs already allocated memory */ SCS(set_default_settings)109void SCS(set_default_settings)(ScsSettings *stgs) { 110 /* These constants are defined in include/glbopts.h */ 111 stgs->max_iters = MAX_ITERS; 112 stgs->eps_abs = EPS_ABS; 113 stgs->eps_rel = EPS_REL; 114 stgs->eps_infeas = EPS_INFEAS; 115 stgs->alpha = ALPHA; 116 stgs->rho_x = RHO_X; 117 stgs->scale = SCALE; 118 stgs->verbose = VERBOSE; 119 stgs->normalize = NORMALIZE; 120 stgs->warm_start = WARM_START; 121 stgs->acceleration_lookback = ACCELERATION_LOOKBACK; 122 stgs->acceleration_interval = ACCELERATION_INTERVAL; 123 stgs->adaptive_scale = ADAPTIVE_SCALE; 124 stgs->write_data_filename = WRITE_DATA_FILENAME; 125 stgs->log_csv_filename = LOG_CSV_FILENAME; 126 stgs->time_limit_secs = TIME_LIMIT_SECS; 127 } 128