[PPL-devel] [GIT] ppl/ppl(master): The deterministic timeout facilities are in the C language interface.
Enea Zaffanella
zaffanella at cs.unipr.it
Sun Jul 12 18:40:06 CEST 2009
Module: ppl/ppl
Branch: master
Commit: e6ed324723fa3ef52c2e80f1ebdc8c7361b7aca3
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=e6ed324723fa3ef52c2e80f1ebdc8c7361b7aca3
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Sun Jul 12 18:36:43 2009 +0200
The deterministic timeout facilities are in the C language interface.
---
interfaces/C/ppl_c_header.h | 39 ++++++++++++++++++++
interfaces/C/ppl_c_implementation_common.cc | 52 +++++++++++++++++++++++++++
src/globals.types.hh | 2 +
3 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/interfaces/C/ppl_c_header.h b/interfaces/C/ppl_c_header.h
index a9fc702..2834a15 100644
--- a/interfaces/C/ppl_c_header.h
+++ b/interfaces/C/ppl_c_header.h
@@ -382,6 +382,45 @@ ppl_set_timeout PPL_PROTO((unsigned time));
int
ppl_reset_timeout PPL_PROTO((void));
+/*! \brief
+ Sets a threshold for computations whose completion could require
+ an exponential amount of time.
+
+ \param weight
+ The maximum computational weight allowed.
+ It must be strictly greater than zero.
+
+ Computations taking exponential time will be interrupted some time
+ after reaching the \p weight complexity threshold. If the computation
+ is interrupted that way, the interrupted function will return error code
+ <code>PPL_TIMEOUT_EXCEPTION</code>.
+ Otherwise, if the computation completes without being interrupted,
+ then the deterministic timeout should be reset by calling
+ <code>ppl_reset_deterministic_timeout()</code>.
+
+ \note
+ This "timeout" checking functionality is said to be \e deterministic
+ because it is not based on actual elapsed time. Its behavior will
+ only depend on (some of the) computations performed in the PPL library
+ and it will be otherwise independent from the computation environment
+ (CPU, operating system, compiler, etc.).
+
+ \warning
+ The weight mechanism is under alpha testing. In particular,
+ there is still no clear relation between the weight threshold and
+ the actual computational complexity. As a consequence, client
+ applications should be ready to reconsider the tuning of these
+ weight thresholds when upgrading to newer version of the PPL.
+*/
+int
+ppl_set_deterministic_timeout PPL_PROTO((unsigned weight));
+
+/*! \brief
+ Resets the deterministic timeout so that the computation is not interrupted.
+*/
+int
+ppl_reset_deterministic_timeout PPL_PROTO((void));
+
/*@}*/ /* Timeout Handling */
/*! \defgroup Datatypes Library Datatypes
diff --git a/interfaces/C/ppl_c_implementation_common.cc b/interfaces/C/ppl_c_implementation_common.cc
index d061695..0e6c509 100644
--- a/interfaces/C/ppl_c_implementation_common.cc
+++ b/interfaces/C/ppl_c_implementation_common.cc
@@ -97,6 +97,12 @@ notify_error(enum ppl_enum_error_code code, const char* description) {
Parma_Watchdog_Library::Watchdog* p_timeout_object = 0;
+typedef
+Parma_Watchdog_Library::Threshold_Watcher
+<Parma_Polyhedra_Library::Weightwatch_Traits> Weightwatch;
+
+Weightwatch* p_deterministic_timeout_object = 0;
+
#endif // PPL_WATCHDOG_LIBRARY_ENABLED
void
@@ -110,6 +116,17 @@ reset_timeout() {
#endif // PPL_WATCHDOG_LIBRARY_ENABLED
}
+void
+reset_deterministic_timeout() {
+#ifdef PPL_WATCHDOG_LIBRARY_ENABLED
+ if (p_deterministic_timeout_object) {
+ delete p_deterministic_timeout_object;
+ p_deterministic_timeout_object = 0;
+ abandon_expensive_computations = 0;
+ }
+#endif // PPL_WATCHDOG_LIBRARY_ENABLED
+}
+
} // namespace C
} // namespace Interfaces
@@ -119,6 +136,11 @@ reset_timeout() {
using namespace Parma_Polyhedra_Library;
using namespace Parma_Polyhedra_Library::Interfaces::C;
+#ifdef PPL_WATCHDOG_LIBRARY_ENABLED
+template <> Weightwatch::Initialize
+Weightwatch::init = Weightwatch::Initialize();
+#endif // PPL_WATCHDOG_LIBRARY_ENABLED
+
unsigned int PPL_POLY_CON_RELATION_IS_DISJOINT;
unsigned int PPL_POLY_CON_RELATION_STRICTLY_INTERSECTS;
unsigned int PPL_POLY_CON_RELATION_IS_INCLUDED;
@@ -232,6 +254,36 @@ ppl_reset_timeout(void) try {
CATCH_ALL
int
+ppl_set_deterministic_timeout(unsigned weight) try {
+#ifndef PPL_WATCHDOG_LIBRARY_ENABLED
+ const char* what = "PPL C interface error:\n"
+ "ppl_set_deterministic_timeout: the PPL Watchdog library is not enabled.";
+ throw std::runtime_error(what);
+#else
+ // In case a deterministic timeout was already set.
+ reset_deterministic_timeout();
+ static timeout_exception e;
+ p_deterministic_timeout_object
+ = new Weightwatch(weight, abandon_expensive_computations, e);
+ return 0;
+#endif // PPL_WATCHDOG_LIBRARY_ENABLED
+}
+CATCH_ALL
+
+int
+ppl_reset_deterministic_timeout(void) try {
+#ifndef PPL_WATCHDOG_LIBRARY_ENABLED
+ const char* what = "PPL C interface error:\n"
+ "ppl_reset_deterministic_timeout: the PPL Watchdog library is not enabled.";
+ throw std::runtime_error(what);
+#else
+ reset_deterministic_timeout();
+ return 0;
+#endif // PPL_WATCHDOG_LIBRARY_ENABLED
+}
+CATCH_ALL
+
+int
ppl_set_rounding_for_PPL(void) try {
set_rounding_for_PPL();
return 0;
diff --git a/src/globals.types.hh b/src/globals.types.hh
index 569f965..a6d7058 100644
--- a/src/globals.types.hh
+++ b/src/globals.types.hh
@@ -152,6 +152,8 @@ enum Bounded_Integer_Type_Overflow {
OVERFLOW_IMPOSSIBLE
};
+struct Weightwatch_Traits;
+
} // namespace Parma_Polyhedra_Library
#endif // !defined(PPL_globals_types_hh)
More information about the PPL-devel
mailing list