scs_int solveLinSys(const AMatrix * A, const Settings * stgs, Priv * p, scs_float * b, const scs_float * s, scs_int iter) { /* returns solution to linear system */ /* Ax = b with solution stored in b */ tic(&linsysTimer); LDLSolve(b, b, p->L, p->D, p->P, p->bp); totalSolveTime += tocq(&linsysTimer); #if EXTRAVERBOSE > 0 scs_printf("linsys solve time: %1.2es\n", tocq(&linsysTimer) / 1e3); #endif return 0; }
Work * scs_init(Data * d, Cone * k, Info * info) { Work * w; timer initTimer; if (!d || !k || !info) { scs_printf("ERROR: Missing Data, Cone or Info input\n"); return NULL; } #ifdef EXTRAVERBOSE printData(d); printConeData(k); #endif #ifndef NOVALIDATE if (validate(d, k) < 0) { scs_printf("ERROR: Validation returned failure\n"); return NULL; } #endif tic(&initTimer); w = initWork(d, k); /* strtoc("init", &initTimer); */ info->setupTime = tocq(&initTimer); if (d->VERBOSE) { scs_printf("Setup time: %1.2es\n", info->setupTime / 1e3); } return w; }
int main(int argc, char **argv) { int num_iters; #if (NUMTESTS > 0) int i; double time; double time_per; #endif set_defaults(); setup_indexing(); load_default_data(); /* Solve problem instance for the record. */ settings.verbose = 1; num_iters = solve(); #ifndef ZERO_LIBRARY_MODE #if (NUMTESTS > 0) /* Now solve multiple problem instances for timing purposes. */ settings.verbose = 0; tic(); for (i = 0; i < NUMTESTS; i++) { solve(); } time = tocq(); printf("Timed %d solves over %.3f seconds.\n", NUMTESTS, time); time_per = time / NUMTESTS; if (time_per > 1) { printf("Actual time taken per solve: %.3g s.\n", time_per); } else if (time_per > 1e-3) { printf("Actual time taken per solve: %.3g ms.\n", 1e3*time_per); } else { printf("Actual time taken per solve: %.3g us.\n", 1e6*time_per); } #endif #endif return 0; }
idxint scs_solve(Work * w, Data * d, Cone * k, Sol * sol, Info * info) { idxint i; timer solveTimer; struct residuals r; if (!d || !k || !sol || !info || !w || !d->b || !d->c) { scs_printf("ERROR: NULL input\n"); return FAILURE; } tic(&solveTimer); info->statusVal = 0; /* not yet converged */ updateWork(d, w, sol); if (d->VERBOSE) printHeader(d, w, k); /* scs: */ for (i = 0; i < d->MAX_ITERS; ++i) { memcpy(w->u_prev, w->u, (d->n + d->m + 1) * sizeof(pfloat)); if (projectLinSys(d, w, i) < 0) return failureDefaultReturn(d, w, sol, info, "error in projectLinSys"); if (projectCones(d, w, k, i) < 0) return failureDefaultReturn(d, w, sol, info, "error in projectCones"); updateDualVars(d, w); if ((info->statusVal = converged(d, w, &r, i)) != 0) break; if (i % PRINT_INTERVAL == 0) { if (d->VERBOSE) { printSummary(i, &r, &solveTimer); #ifdef EXTRAVERBOSE scs_printf("Norm u = %4f, ", calcNorm(w->u, d->n + d->m + 1)); scs_printf("Norm u_t = %4f, ", calcNorm(w->u_t, d->n + d->m + 1)); scs_printf("Norm v = %4f, ", calcNorm(w->v, d->n + d->m + 1)); scs_printf("tau = %4f, ", w->u[d->n + d->m]); scs_printf("kappa = %4f, ", w->v[d->n + d->m]); scs_printf("|u - u_prev| = %4f, ", calcNormDiff(w->u, w->u_prev, d->n + d->m + 1)); scs_printf("|u - u_t| = %4f\n", calcNormDiff(w->u, w->u_t, d->n + d->m + 1)); #endif } } } if (d->VERBOSE) { printSummary(i, &r, &solveTimer); } setSolution(d, w, sol, info); /* populate info */ info->iter = i; getInfo(d, w, sol, info); info->solveTime = tocq(&solveTimer); if (d->VERBOSE) printFooter(d, w, info); /* un-normalize sol, b, c but not A */ if (d->NORMALIZE) unNormalizeSolBC(d, w, sol); return info->statusVal; }
static void printSummary(idxint i, struct residuals *r, timer * solveTimer) { scs_printf("%*i|", (int) strlen(HEADER[0]), (int) i); scs_printf("%*.2e ", (int) HSPACE, r->resPri); scs_printf("%*.2e ", (int) HSPACE, r->resDual); scs_printf("%*.2e ", (int) HSPACE, r->relGap); scs_printf("%*.2e ", (int) HSPACE, r->cTx); scs_printf("%*.2e ", (int) HSPACE, -r->bTy); scs_printf("%*.2e ", (int) HSPACE, r->kap / r->tau); scs_printf("%*.2e ", (int) HSPACE, tocq(solveTimer) / 1e3); scs_printf("\n"); #ifdef MATLAB_MEX_FILE mexEvalString("drawnow;"); #endif }
scs_int solveLinSys(const AMatrix * A, const Settings * stgs, Priv * p, scs_float * b, const scs_float * s, scs_int iter) { scs_int cgIts; scs_float cgTol = calcNorm(b, A->n) * (iter < 0 ? CG_BEST_TOL : CG_MIN_TOL / POWF((scs_float) iter + 1, stgs->cg_rate)); tic(&linsysTimer); /* solves Mx = b, for x but stores result in b */ /* s contains warm-start (if available) */ accumByAtrans(A, p, &(b[A->n]), b); /* solves (I+A'A)x = b, s warm start, solution stored in b */ cgIts = pcg(A, stgs, p, s, b, A->n, MAX(cgTol, CG_BEST_TOL)); scaleArray(&(b[A->n]), -1, A->m); accumByA(A, p, b, &(b[A->n])); if (iter >= 0) { totCgIts += cgIts; } totalSolveTime += tocq(&linsysTimer); #if EXTRAVERBOSE > 0 scs_printf("linsys solve time: %1.2es\n", tocq(&linsysTimer) / 1e3); #endif return 0; }
static void transpose(const AMatrix * A, Priv * p) { scs_int * Ci = p->At->i; scs_int * Cp = p->At->p; scs_float * Cx = p->At->x; scs_int m = A->m; scs_int n = A->n; scs_int * Ap = A->p; scs_int * Ai = A->i; scs_float * Ax = A->x; scs_int i, j, q, *z, c1, c2; #if EXTRAVERBOSE > 0 timer transposeTimer; scs_printf("transposing A\n"); tic(&transposeTimer); #endif z = scs_calloc(m, sizeof(scs_int)); for (i = 0; i < Ap[n]; i++) z[Ai[i]]++; /* row counts */ cs_cumsum(Cp, z, m); /* row pointers */ for (j = 0; j < n; j++) { c1 = Ap[j]; c2 = Ap[j + 1]; for (i = c1; i < c2; i++) { q = z[Ai[i]]; Ci[q] = j; /* place A(i,j) as entry C(j,i) */ Cx[q] = Ax[i]; z[Ai[i]]++; } } scs_free(z); #if EXTRAVERBOSE > 0 scs_printf("finished transposing A, time: %1.2es\n", tocq(&transposeTimer) / 1e3); #endif }