Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit f4e679c

Browse files
wibraunOpenModelica-Hudson
authored andcommitted
added jacobian timings to linear and non-linear solver
1 parent 0db7959 commit f4e679c

12 files changed

+65
-8
lines changed

SimulationRuntime/c/simulation/solver/kinsolSolver.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ int nlsDenseJac(long int N, N_Vector vecX, N_Vector vecFX, DlsMat Jac, void *use
331331

332332
long int i,j;
333333

334+
/* performance measurement */
335+
rt_ext_tp_tick(&nlsData->jacobianTimeClock);
336+
334337
for(i = 0; i < N; i++)
335338
{
336339
xsave = x[i];
@@ -357,6 +360,11 @@ int nlsDenseJac(long int N, N_Vector vecX, N_Vector vecFX, DlsMat Jac, void *use
357360
infoStreamPrint(LOG_NLS_JAC, 0, "##KINSOL## omc dense matrix.");
358361
PrintMat(Jac);
359362
}
363+
364+
/* performance measurement and statistics */
365+
nlsData->jacobianTime += rt_ext_tp_tock(&(nlsData->jacobianTimeClock));
366+
nlsData->numberOfJEval++;
367+
360368
return 0;
361369
}
362370

@@ -414,6 +422,9 @@ int nlsSparseJac(N_Vector vecX, N_Vector vecFX, SlsMat Jac, void *userData, N_Ve
414422
long int i,j,ii;
415423
int nth = 0;
416424

425+
/* performance measurement */
426+
rt_ext_tp_tick(&nlsData->jacobianTimeClock);
427+
417428
/* reset matrix */
418429
SlsSetToZero(Jac);
419430

@@ -460,6 +471,11 @@ int nlsSparseJac(N_Vector vecX, N_Vector vecFX, SlsMat Jac, void *userData, N_Ve
460471
nlsKinsolJacSumSparse(Jac);
461472
messageClose(LOG_NLS_JAC);
462473
}
474+
475+
/* performance measurement and statistics */
476+
nlsData->jacobianTime += rt_ext_tp_tock(&(nlsData->jacobianTimeClock));
477+
nlsData->numberOfJEval++;
478+
463479
return 0;
464480
}
465481

SimulationRuntime/c/simulation/solver/linearSolverKlu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ solveKlu(DATA *data, threadData_t *threadData, int sysNumber)
181181
DATA_KLU* solverData = (DATA_KLU*)systemData->solverData;
182182

183183
int i, j, status = 0, success = 0, n = systemData->size, eqSystemNumber = systemData->equationIndex, indexes[2] = {1,eqSystemNumber};
184+
double tmpJacEvalTime;
184185

185186
infoStreamPrintWithEquationIndexes(LOG_LS, 0, indexes, "Start solving Linear System %d (size %d) at time %g with Klu Solver",
186187
eqSystemNumber, (int) systemData->size,
@@ -218,8 +219,9 @@ solveKlu(DATA *data, threadData_t *threadData, int sysNumber)
218219
memcpy(solverData->work, systemData->x, sizeof(double)*solverData->n_row);
219220
residual_wrapper(solverData->work, systemData->b, dataAndThreadData, sysNumber);
220221
}
221-
222-
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", rt_ext_tp_tock(&(solverData->timeClock)));
222+
tmpJacEvalTime = rt_ext_tp_tock(&(solverData->timeClock));
223+
systemData->jacobianTime += tmpJacEvalTime;
224+
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", tmpJacEvalTime);
223225

224226
if (ACTIVE_STREAM(LOG_LS_V))
225227
{

SimulationRuntime/c/simulation/solver/linearSolverLapack.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ int solveLapack(DATA *data, threadData_t *threadData, int sysNumber)
169169
int eqSystemNumber = systemData->equationIndex;
170170
int indexes[2] = {1,eqSystemNumber};
171171
_omc_scalar residualNorm = 0;
172+
double tmpJacEvalTime;
172173

173174
infoStreamPrintWithEquationIndexes(LOG_LS, 0, indexes, "Start solving Linear System %d (size %d) at time %g with Lapack Solver",
174175
eqSystemNumber, (int) systemData->size,
@@ -205,7 +206,9 @@ int solveLapack(DATA *data, threadData_t *threadData, int sysNumber)
205206
_omc_copyVector(solverData->work, solverData->x);
206207
wrapper_fvec_lapack(solverData->work, solverData->b, &iflag, dataAndThreadData, sysNumber);
207208
}
208-
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", rt_ext_tp_tock(&(solverData->timeClock)));
209+
tmpJacEvalTime = rt_ext_tp_tock(&(solverData->timeClock));
210+
systemData->jacobianTime += tmpJacEvalTime;
211+
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", tmpJacEvalTime);
209212

210213
/* Log A*x=b */
211214
if(ACTIVE_STREAM(LOG_LS_V)){

SimulationRuntime/c/simulation/solver/linearSolverLis.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ solveLis(DATA *data, threadData_t *threadData, int sysNumber)
203203
LIS_INT err;
204204

205205
int indexes[2] = {1,eqSystemNumber};
206+
double tmpJacEvalTime;
206207
infoStreamPrintWithEquationIndexes(LOG_LS, 0, indexes, "Start solving Linear System %d (size %d) at time %g with Lis Solver",
207208
eqSystemNumber, (int) systemData->size,
208209
data->localData[0]->timeValue);
@@ -243,8 +244,9 @@ solveLis(DATA *data, threadData_t *threadData, int sysNumber)
243244
err = lis_vector_set_value(LIS_INS_VALUE, i, systemData->b[i], solverData->b);
244245
}
245246
}
246-
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", rt_ext_tp_tock(&(solverData->timeClock)));
247-
247+
tmpJacEvalTime = rt_ext_tp_tock(&(solverData->timeClock));
248+
systemData->jacobianTime += tmpJacEvalTime;
249+
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", tmpJacEvalTime);
248250

249251
rt_ext_tp_tick(&(solverData->timeClock));
250252
err = lis_solve(solverData->A,solverData->b,solverData->x,solverData->solver);

SimulationRuntime/c/simulation/solver/linearSolverTotalPivot.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ int solveTotalPivot(DATA *data, threadData_t *threadData, int sysNumber)
395395
* We want to look it up among all equations. */
396396
/* int eqSystemNumber = systemData->equationIndex; */
397397
int success = 1;
398+
double tmpJacEvalTime;
398399

399400
infoStreamPrintWithEquationIndexes(LOG_LS, 0, indexes, "Start solving Linear System %d (size %d) at time %g with Total Pivot Solver",
400401
eqSystemNumber, (int) systemData->size,
@@ -429,7 +430,9 @@ int solveTotalPivot(DATA *data, threadData_t *threadData, int sysNumber)
429430
/* calculate vector b (rhs) -> -b is last column of matrix Ab */
430431
wrapper_fvec_totalpivot(systemData->x, solverData->Ab + n*n, dataAndThreadData, sysNumber);
431432
}
432-
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", rt_ext_tp_tock(&(solverData->timeClock)));
433+
tmpJacEvalTime = rt_ext_tp_tock(&(solverData->timeClock));
434+
systemData->jacobianTime += tmpJacEvalTime;
435+
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", tmpJacEvalTime);
433436
debugMatrixDoubleLS(LOG_LS_V,"LGS: matrix Ab",solverData->Ab, n, n+1);
434437

435438
rt_ext_tp_tick(&(solverData->timeClock));

SimulationRuntime/c/simulation/solver/linearSolverUmfpack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ solveUmfPack(DATA *data, threadData_t *threadData, int sysNumber)
197197

198198
int i, j, status = UMFPACK_OK, success = 0, ni=0, n = systemData->size, eqSystemNumber = systemData->equationIndex, indexes[2] = {1,eqSystemNumber};
199199
int casualTearingSet = systemData->strictTearingFunctionCall != NULL;
200+
double tmpJacEvalTime;
200201

201202
infoStreamPrintWithEquationIndexes(LOG_LS, 0, indexes, "Start solving Linear System %d (size %d) at time %g with UMFPACK Solver",
202203
eqSystemNumber, (int) systemData->size,
@@ -235,8 +236,9 @@ solveUmfPack(DATA *data, threadData_t *threadData, int sysNumber)
235236
memcpy(solverData->work, systemData->x, sizeof(double)*solverData->n_row);
236237
wrapper_fvec_umfpack(solverData->work, systemData->b, dataAndThreadData, sysNumber);
237238
}
238-
239-
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", rt_ext_tp_tock(&(solverData->timeClock)));
239+
tmpJacEvalTime = rt_ext_tp_tock(&(solverData->timeClock));
240+
systemData->jacobianTime += tmpJacEvalTime;
241+
infoStreamPrint(LOG_LS, 0, "### %f time to set Matrix A and vector b.", tmpJacEvalTime);
240242

241243
if (ACTIVE_STREAM(LOG_LS_V))
242244
{

SimulationRuntime/c/simulation/solver/linearSystem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ void printLinearSystemSolvingStatistics(DATA *data, int sysNumber, int logLevel)
264264
(((double) linsys[sysNumber].nnz) / ((double)(linsys[sysNumber].size*linsys[sysNumber].size)))*100 );
265265
infoStreamPrint(logLevel, 0, " number of calls : %ld", linsys[sysNumber].numberOfCall);
266266
infoStreamPrint(logLevel, 0, " average time per call : %g", linsys[sysNumber].totalTime/linsys[sysNumber].numberOfCall);
267+
infoStreamPrint(logLevel, 0, " time of jacobian evaluations : %g", linsys[sysNumber].jacobianTime);
267268
infoStreamPrint(logLevel, 0, " total time : %g", linsys[sysNumber].totalTime);
268269
messageClose(logLevel);
269270
}

SimulationRuntime/c/simulation/solver/nonlinearSolverHomotopy.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,10 @@ static int wrapper_fvec_der(DATA_HOMOTOPY* solverData, double* x, double* fJac)
858858
{
859859
int i;
860860
int jacobianIndex = (&(solverData->data->simulationInfo->nonlinearSystemData[solverData->sysNumber]))->jacobianIndex;
861+
NONLINEAR_SYSTEM_DATA* nonlinsys = &(solverData->data->simulationInfo->nonlinearSystemData[solverData->sysNumber]);
862+
863+
/* performance measurement */
864+
rt_ext_tp_tick(&nonlinsys->jacobianTimeClock);
861865

862866
/* calculate jacobian */
863867
if(jacobianIndex != -1)
@@ -883,6 +887,9 @@ static int wrapper_fvec_der(DATA_HOMOTOPY* solverData, double* x, double* fJac)
883887
debugDouble(LOG_NLS_JAC_TEST,"relative error between analytical and numerical jacobian = ", vecMaxNorm(n*n, solverData->debug_fJac));
884888
messageClose(LOG_NLS_JAC_TEST);
885889
}
890+
/* performance measurement and statistics */
891+
nonlinsys->jacobianTime += rt_ext_tp_tock(&(nonlinsys->jacobianTimeClock));
892+
nonlinsys->numberOfJEval++;
886893

887894
return 0;
888895
}

SimulationRuntime/c/simulation/solver/nonlinearSolverHybrd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ static int wrapper_fvec_hybrj(const integer* n, const double* x, double* f, doub
352352
if(ACTIVE_STREAM(LOG_NLS_RES))
353353
infoStreamPrint(LOG_NLS_RES, 0, "-- begin calculating jacobian --");
354354

355+
/* performance measurement */
356+
rt_ext_tp_tick(&systemData->jacobianTimeClock);
357+
355358
/* call apropreated jacobian function */
356359
if(systemData->jacobianIndex != -1){
357360
integer iflagtmp = 1;
@@ -385,6 +388,11 @@ static int wrapper_fvec_hybrj(const integer* n, const double* x, double* f, doub
385388
/* reset residual function again */
386389
if(continuous)
387390
data->simulationInfo->solveContinuous = 1;
391+
392+
/* performance measurement and statistics */
393+
systemData->jacobianTime += rt_ext_tp_tock(&(systemData->jacobianTimeClock));
394+
systemData->numberOfJEval++;
395+
388396
break;
389397

390398
default:

SimulationRuntime/c/simulation/solver/nonlinearSolverNewton.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ int wrapper_fvec_newton(int* n, double* x, double* fvec, void* userdata, int fj)
139139
if (fj) {
140140
(data->simulationInfo->nonlinearSystemData[currentSys].residualFunc)(dataAndThreadData, x, fvec, iflag);
141141
} else {
142+
/* performance measurement */
143+
rt_ext_tp_tick(&systemData->jacobianTimeClock);
144+
142145
if(systemData->jacobianIndex != -1) {
143146
getAnalyticalJacobianNewton(data, uData->threadData, solverData->fjac, currentSys);
144147
} else {
@@ -166,6 +169,9 @@ int wrapper_fvec_newton(int* n, double* x, double* fvec, void* userdata, int fj)
166169
x[i] = xsave;
167170
}
168171
}
172+
/* performance measurement and statistics */
173+
systemData->jacobianTime += rt_ext_tp_tock(&(systemData->jacobianTimeClock));
174+
systemData->numberOfJEval++;
169175
}
170176
return *iflag;
171177
}

0 commit comments

Comments
 (0)