Browse Source

Add intermittent progress updates to numerical solution (sparse engine).

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@5263 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 14 years ago
parent
commit
7725e3b89c
  1. 12
      prism/include/prism.h
  2. 46
      prism/src/sparse/PS_JOR.cc
  3. 14
      prism/src/sparse/PS_NondetBoundedUntil.cc
  4. 14
      prism/src/sparse/PS_NondetInstReward.cc
  5. 43
      prism/src/sparse/PS_NondetReachReward.cc
  6. 43
      prism/src/sparse/PS_NondetUntil.cc
  7. 44
      prism/src/sparse/PS_Power.cc
  8. 14
      prism/src/sparse/PS_ProbBoundedUntil.cc
  9. 14
      prism/src/sparse/PS_ProbCumulReward.cc
  10. 14
      prism/src/sparse/PS_ProbInstReward.cc
  11. 40
      prism/src/sparse/PS_ProbTransient.cc
  12. 12
      prism/src/sparse/PS_SOR.cc
  13. 41
      prism/src/sparse/PS_StochBoundedUntil.cc
  14. 40
      prism/src/sparse/PS_StochCumulReward.cc
  15. 40
      prism/src/sparse/PS_StochTransient.cc

12
prism/include/prism.h

@ -24,6 +24,10 @@
//
//==============================================================================
#ifndef PRISM_H
#define PRISM_H
//------------------------------------------------------------------------------
#include <jni.h>
// Flags for building Windows DLLs
@ -48,4 +52,12 @@ EXPORT void get_string_array_from_java(JNIEnv *env, jobject strings_list, jstrin
EXPORT void release_string_array_from_java(JNIEnv *env, jstring *strings_jstrings, const char **strings, jint size);
EXPORT FoxGlynnWeights fox_glynn(double q_tmax, double underflow, double overflow, double accuracy);
// Global constants
// Delay between occasional updates for slow processes, e.g. numerical solution (milliseconds)
const int UPDATE_DELAY = 1000;
//------------------------------------------------------------------------------
#endif
//------------------------------------------------------------------------------

46
prism/src/sparse/PS_JOR.cc

@ -35,6 +35,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -84,7 +85,7 @@ jdouble omega // omega (over-relaxation parameter)
double time_taken, time_for_setup, time_for_iters;
// misc
int i, j, l, h, iters;
double d, kb, kbt;
double d, x, sup_norm, kb, kbt;
bool done;
// exception handling around whole function
@ -200,6 +201,7 @@ jdouble omega // omega (over-relaxation parameter)
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
iters = 0;
@ -210,9 +212,6 @@ jdouble omega // omega (over-relaxation parameter)
iters++;
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *row_counts;
@ -267,36 +266,29 @@ jdouble omega // omega (over-relaxation parameter)
}
// check convergence
// (note: doing outside loop means may not need to check all elements)
switch (term_crit) {
case TERM_CRIT_ABSOLUTE:
done = true;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i]) > term_crit_param) {
done = false;
break;
}
sup_norm = 0.0;
for (i = 0; i < n; i++) {
x = fabs(soln2[i] - soln[i]);
if (term_crit == TERM_CRIT_RELATIVE) {
x /= soln2[i];
}
break;
case TERM_CRIT_RELATIVE:
if (x > sup_norm) sup_norm = x;
}
if (sup_norm < term_crit_param) {
done = true;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i])/soln2[i] > term_crit_param) {
done = false;
break;
}
}
break;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d: max %sdiff=%f", iters, (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, ", %.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
soln2 = tmpsoln;
}
// stop clocks

14
prism/src/sparse/PS_NondetBoundedUntil.cc

@ -35,6 +35,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -135,6 +136,7 @@ jboolean min // min or max probabilities (true = min, false = max)
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
PS_PrintToMainLog(env, "\nStarting iterations...\n");
@ -142,9 +144,6 @@ jboolean min // min or max probabilities (true = min, false = max)
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 0; iters < bound; iters++) {
// PS_PrintToMainLog(env, "iter %d\n", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros = ndsm->non_zeros;
unsigned char *row_counts = ndsm->row_counts;
@ -178,12 +177,17 @@ jboolean min // min or max probabilities (true = min, false = max)
soln2[i] = (h1 > l1) ? d1 : yes_vec[i];
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, bound);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

14
prism/src/sparse/PS_NondetInstReward.cc

@ -35,6 +35,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -118,6 +119,7 @@ jlong __jlongpointer in
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
PS_PrintToMainLog(env, "\nStarting iterations...\n");
@ -125,9 +127,6 @@ jlong __jlongpointer in
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 0; iters < bound; iters++) {
// PS_PrintToMainLog(env, "iter %d\n", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros = ndsm->non_zeros;
unsigned char *row_counts = ndsm->row_counts;
@ -172,14 +171,19 @@ jlong __jlongpointer in
soln2[i] = (h1 > l1) ? d1 : 0;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, bound);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%i: %f\n", iters, get_first_from_bdd(ddman, soln, init, rvars, num_rvars, odd));
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

43
prism/src/sparse/PS_NondetReachReward.cc

@ -102,7 +102,7 @@ jboolean min // min or max probabilities (true = min, false = max)
int num_actions;
// misc
int i, j, k, k_r, l1, h1, l2, h2, l2_r, h2_r, iters;
double d1, d2, kb, kbt;
double d1, d2, x, sup_norm, kb, kbt;
bool done, first;
// exception handling around whole function
@ -222,6 +222,7 @@ jboolean min // min or max probabilities (true = min, false = max)
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
iters = 0;
@ -261,9 +262,6 @@ jboolean min // min or max probabilities (true = min, false = max)
iters++;
// PS_PrintToMainLog(env, "iter %d\n", iters);
// start3 = util_cpu_time();
// do matrix multiplication and min/max
h1 = h2 = h2_r = 0;
// loop through states
@ -321,28 +319,23 @@ jboolean min // min or max probabilities (true = min, false = max)
}
// check convergence
// (note: doing outside loop means may not need to check all elements)
switch (term_crit) {
case TERM_CRIT_ABSOLUTE:
done = true;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i]) > term_crit_param) {
done = false;
break;
}
sup_norm = 0.0;
for (i = 0; i < n; i++) {
x = fabs(soln2[i] - soln[i]);
if (term_crit == TERM_CRIT_RELATIVE) {
x /= soln2[i];
}
break;
case TERM_CRIT_RELATIVE:
if (x > sup_norm) sup_norm = x;
}
if (sup_norm < term_crit_param) {
done = true;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i])/soln2[i] > term_crit_param) {
done = false;
break;
}
}
break;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d: max %sdiff=%f", iters, (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, ", %.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
@ -352,8 +345,6 @@ jboolean min // min or max probabilities (true = min, false = max)
// if we're done, but adversary generation is required, go round once more
if (done && adv) adv_loop = !adv_loop;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// Traverse matrix to extract adversary

43
prism/src/sparse/PS_NondetUntil.cc

@ -96,7 +96,7 @@ jboolean min // min or max probabilities (true = min, false = max)
int num_actions;
// misc
int i, j, k, l1, h1, l2, h2, iters;
double d1, d2, kb, kbt;
double d1, d2, x, sup_norm, kb, kbt;
bool done, first;
// exception handling around whole function
@ -200,6 +200,7 @@ jboolean min // min or max probabilities (true = min, false = max)
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
iters = 0;
@ -230,9 +231,6 @@ jboolean min // min or max probabilities (true = min, false = max)
iters++;
// PS_PrintToMainLog(env, "iter %d\n", iters);
// start3 = util_cpu_time();
// do matrix multiplication and min/max
h1 = h2 = 0;
for (i = 0; i < n; i++) {
@ -274,36 +272,29 @@ jboolean min // min or max probabilities (true = min, false = max)
}
// check convergence
// (note: doing outside loop means may not need to check all elements)
switch (term_crit) {
case TERM_CRIT_ABSOLUTE:
done = true;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i]) > term_crit_param) {
done = false;
break;
}
sup_norm = 0.0;
for (i = 0; i < n; i++) {
x = fabs(soln2[i] - soln[i]);
if (term_crit == TERM_CRIT_RELATIVE) {
x /= soln2[i];
}
break;
case TERM_CRIT_RELATIVE:
if (x > sup_norm) sup_norm = x;
}
if (sup_norm < term_crit_param) {
done = true;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i])/soln2[i] > term_crit_param) {
done = false;
break;
}
}
break;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d: max %sdiff=%f", iters, (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, ", %.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// Traverse matrix to extract adversary

44
prism/src/sparse/PS_Power.cc

@ -35,6 +35,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -82,7 +83,7 @@ jboolean transpose // transpose A? (i.e. solve xA=x not Ax=x?)
double time_taken, time_for_setup, time_for_iters;
// misc
int i, j, l, h, iters;
double d, kb, kbt;
double d, x, sup_norm, kb, kbt;
bool done;
// exception handling around whole function
@ -152,6 +153,7 @@ jboolean transpose // transpose A? (i.e. solve xA=x not Ax=x?)
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
iters = 0;
@ -162,9 +164,6 @@ jboolean transpose // transpose A? (i.e. solve xA=x not Ax=x?)
iters++;
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *row_counts;
@ -213,36 +212,29 @@ jboolean transpose // transpose A? (i.e. solve xA=x not Ax=x?)
}
// check convergence
// (note: doing outside loop means may not need to check all elements)
switch (term_crit) {
case TERM_CRIT_ABSOLUTE:
done = true;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i]) > term_crit_param) {
done = false;
break;
}
sup_norm = 0.0;
for (i = 0; i < n; i++) {
x = fabs(soln2[i] - soln[i]);
if (term_crit == TERM_CRIT_RELATIVE) {
x /= soln2[i];
}
break;
case TERM_CRIT_RELATIVE:
if (x > sup_norm) sup_norm = x;
}
if (sup_norm < term_crit_param) {
done = true;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i])/soln2[i] > term_crit_param) {
done = false;
break;
}
}
break;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d: max %sdiff=%f", iters, (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, ", %.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

14
prism/src/sparse/PS_ProbBoundedUntil.cc

@ -35,6 +35,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -154,6 +155,7 @@ jint bound // time bound
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
PS_PrintToMainLog(env, "\nStarting iterations...\n");
@ -161,9 +163,6 @@ jint bound // time bound
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 0; iters < bound; iters++) {
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *row_counts;
@ -212,12 +211,17 @@ jint bound // time bound
soln2[i] = d;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, bound);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

14
prism/src/sparse/PS_ProbCumulReward.cc

@ -35,6 +35,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -158,6 +159,7 @@ jint bound // time bound
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
PS_PrintToMainLog(env, "\nStarting iterations...\n");
@ -165,9 +167,6 @@ jint bound // time bound
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 0; iters < bound; iters++) {
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *row_counts;
@ -214,12 +213,17 @@ jint bound // time bound
soln2[i] = d;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, bound);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

14
prism/src/sparse/PS_ProbInstReward.cc

@ -35,6 +35,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -124,6 +125,7 @@ jint bound // time bound
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
PS_PrintToMainLog(env, "\nStarting iterations...\n");
@ -131,9 +133,6 @@ jint bound // time bound
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 0; iters < bound; iters++) {
// PS_PrintToMainLog(env, "iter %d\n", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *row_counts;
@ -180,12 +179,17 @@ jint bound // time bound
soln2[i] = d;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, bound);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

40
prism/src/sparse/PS_ProbTransient.cc

@ -77,7 +77,7 @@ jint time // time
// misc
bool done;
int i, j, l, h, iters;
double d, kb, kbt;
double d, x, sup_norm, kb, kbt;
// exception handling around whole function
try {
@ -127,6 +127,7 @@ jint time // time
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
iters = 0;
@ -136,9 +137,6 @@ jint time // time
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 0; iters < time && !done; iters++) {
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *col_counts;
@ -186,34 +184,32 @@ jint time // time
}
// check for steady state convergence
// (note: doing outside loop means may not need to check all elements)
if (do_ss_detect) switch (term_crit) {
case TERM_CRIT_ABSOLUTE:
done = true;
if (do_ss_detect) {
sup_norm = 0.0;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i]) > term_crit_param) {
done = false;
break;
x = fabs(soln2[i] - soln[i]);
if (term_crit == TERM_CRIT_RELATIVE) {
x /= soln2[i];
}
if (x > sup_norm) sup_norm = x;
}
break;
case TERM_CRIT_RELATIVE:
done = true;
for (i = 0; i < n; i++) {
if (fabs((soln2[i] - soln[i])/soln2[i]) > term_crit_param) {
done = false;
break;
}
if (sup_norm < term_crit_param) {
done = true;
}
break;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, time);
if (do_ss_detect) PS_PrintToMainLog(env, "max %sdiff=%f, ", (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
soln2 = tmpsoln;
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

12
prism/src/sparse/PS_SOR.cc

@ -35,6 +35,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -200,6 +201,7 @@ jboolean forwards // forwards or backwards?
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start iterations
iters = 0;
@ -210,9 +212,6 @@ jboolean forwards // forwards or backwards?
iters++;
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
sup_norm = 0.0;
// store local copies of stuff
@ -285,7 +284,12 @@ jboolean forwards // forwards or backwards?
done = true;
}
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d: max %sdiff=%f", iters, (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, ", %.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
}
// stop clocks

41
prism/src/sparse/PS_StochBoundedUntil.cc

@ -36,6 +36,7 @@
#include "sparse.h"
#include "PrismSparseGlob.h"
#include "jnipointer.h"
#include "prism.h"
#include <new>
//------------------------------------------------------------------------------
@ -87,7 +88,7 @@ jlong __jlongpointer mu // probs for multiplying
bool done;
int j, l, h;
long i, iters, num_iters;
double d, x, max_diag, weight, kb, kbt, unif, term_crit_param_unif;
double d, x, sup_norm, max_diag, weight, kb, kbt, unif, term_crit_param_unif;
// exception handling around whole function
try {
@ -212,6 +213,7 @@ jlong __jlongpointer mu // probs for multiplying
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start transient analysis
done = false;
@ -226,9 +228,6 @@ jlong __jlongpointer mu // probs for multiplying
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 1; (iters <= fgw.right) && !done; iters++) {
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *row_counts;
@ -276,26 +275,18 @@ jlong __jlongpointer mu // probs for multiplying
}
// check for steady state convergence
// (note: doing outside loop means may not need to check all elements)
if (do_ss_detect) switch (term_crit) {
case TERM_CRIT_ABSOLUTE:
done = true;
if (do_ss_detect) {
sup_norm = 0.0;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i]) > term_crit_param_unif) {
done = false;
break;
x = fabs(soln2[i] - soln[i]);
if (term_crit == TERM_CRIT_RELATIVE) {
x /= soln2[i];
}
if (x > sup_norm) sup_norm = x;
}
break;
case TERM_CRIT_RELATIVE:
done = true;
for (i = 0; i < n; i++) {
if (fabs((soln2[i] - soln[i])/soln2[i]) > term_crit_param_unif) {
done = false;
break;
}
if (sup_norm < term_crit_param_unif) {
done = true;
}
break;
}
// special case when finished early (steady-state detected)
@ -316,6 +307,14 @@ jlong __jlongpointer mu // probs for multiplying
break;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, fgw.right);
if (do_ss_detect) PS_PrintToMainLog(env, "max %sdiff=%f, ", (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
@ -325,8 +324,6 @@ jlong __jlongpointer mu // probs for multiplying
if (iters >= fgw.left) {
for (i = 0; i < n; i++) sum[i] += fgw.weights[iters-fgw.left] * soln[i];
}
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

40
prism/src/sparse/PS_StochCumulReward.cc

@ -85,7 +85,7 @@ jdouble time // time bound
bool done;
int j, l, h;
long i, iters, num_iters;
double d, max_diag, weight, kb, kbt, unif, term_crit_param_unif;
double d, x, sup_norm, max_diag, weight, kb, kbt, unif, term_crit_param_unif;
// exception handling around whole function
try {
@ -220,6 +220,7 @@ jdouble time // time bound
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start transient analysis
done = false;
@ -236,9 +237,6 @@ jdouble time // time bound
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 1; (iters <= fgw.right) && !done; iters++) {
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *row_counts;
@ -286,26 +284,18 @@ jdouble time // time bound
}
// check for steady state convergence
// (note: doing outside loop means may not need to check all elements)
if (do_ss_detect) switch (term_crit) {
case TERM_CRIT_ABSOLUTE:
done = true;
if (do_ss_detect) {
sup_norm = 0.0;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i]) > term_crit_param_unif) {
done = false;
break;
x = fabs(soln2[i] - soln[i]);
if (term_crit == TERM_CRIT_RELATIVE) {
x /= soln2[i];
}
if (x > sup_norm) sup_norm = x;
}
break;
case TERM_CRIT_RELATIVE:
done = true;
for (i = 0; i < n; i++) {
if (fabs((soln2[i] - soln[i])/soln2[i]) > term_crit_param_unif) {
done = false;
break;
}
if (sup_norm < term_crit_param_unif) {
done = true;
}
break;
}
// special case when finished early (steady-state detected)
@ -327,6 +317,14 @@ jdouble time // time bound
break;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, fgw.right);
if (do_ss_detect) PS_PrintToMainLog(env, "max %sdiff=%f, ", (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
@ -338,8 +336,6 @@ jdouble time // time bound
} else {
for (i = 0; i < n; i++) sum[i] += fgw.weights[iters-fgw.left] * soln[i];
}
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

40
prism/src/sparse/PS_StochTransient.cc

@ -81,7 +81,7 @@ jdouble time // time bound
bool done;
int j, l, h;
long i, iters, num_iters;
double d, max_diag, weight, kb, kbt, unif, term_crit_param_unif;
double d, x, sup_norm, max_diag, weight, kb, kbt, unif, term_crit_param_unif;
// exception handling around whole function
try {
@ -192,6 +192,7 @@ jdouble time // time bound
stop = util_cpu_time();
time_for_setup = (double)(stop - start2)/1000;
start2 = stop;
start3 = stop;
// start transient analysis
done = false;
@ -206,9 +207,6 @@ jdouble time // time bound
// note that we ignore max_iters as we know how any iterations _should_ be performed
for (iters = 1; (iters <= fgw.right) && !done; iters++) {
// PS_PrintToMainLog(env, "Iteration %d: ", iters);
// start3 = util_cpu_time();
// store local copies of stuff
double *non_zeros;
unsigned char *col_counts;
@ -256,26 +254,18 @@ jdouble time // time bound
}
// check for steady state convergence
// (note: doing outside loop means may not need to check all elements)
if (do_ss_detect) switch (term_crit) {
case TERM_CRIT_ABSOLUTE:
done = true;
if (do_ss_detect) {
sup_norm = 0.0;
for (i = 0; i < n; i++) {
if (fabs(soln2[i] - soln[i]) > term_crit_param_unif) {
done = false;
break;
x = fabs(soln2[i] - soln[i]);
if (term_crit == TERM_CRIT_RELATIVE) {
x /= soln2[i];
}
if (x > sup_norm) sup_norm = x;
}
break;
case TERM_CRIT_RELATIVE:
done = true;
for (i = 0; i < n; i++) {
if (fabs((soln2[i] - soln[i])/soln2[i]) > term_crit_param_unif) {
done = false;
break;
}
if (sup_norm < term_crit_param_unif) {
done = true;
}
break;
}
// special case when finished early (steady-state detected)
@ -296,6 +286,14 @@ jdouble time // time bound
break;
}
// print occasional status update
if ((util_cpu_time() - start3) > UPDATE_DELAY) {
PS_PrintToMainLog(env, "Iteration %d (of %d): ", iters, fgw.right);
if (do_ss_detect) PS_PrintToMainLog(env, "max %sdiff=%f, ", (term_crit == TERM_CRIT_RELATIVE)?"relative ":"", sup_norm);
PS_PrintToMainLog(env, "%.2f sec so far\n", ((double)(util_cpu_time() - start2)/1000));
start3 = util_cpu_time();
}
// prepare for next iteration
tmpsoln = soln;
soln = soln2;
@ -305,8 +303,6 @@ jdouble time // time bound
if (iters >= fgw.left) {
for (i = 0; i < n; i++) sum[i] += fgw.weights[iters-fgw.left] * soln[i];
}
// PS_PrintToMainLog(env, "%.2f %.2f sec\n", ((double)(util_cpu_time() - start3)/1000), ((double)(util_cpu_time() - start2)/1000)/iters);
}
// stop clocks

Loading…
Cancel
Save