diff --git a/src/storage/dd/sylvan/InternalSylvanDdManager.cpp b/src/storage/dd/sylvan/InternalSylvanDdManager.cpp index f79e62277..06fcd57bb 100644 --- a/src/storage/dd/sylvan/InternalSylvanDdManager.cpp +++ b/src/storage/dd/sylvan/InternalSylvanDdManager.cpp @@ -1,127 +1,148 @@ -#include "src/storage/dd/sylvan/InternalSylvanDdManager.h" - -#include - -#include "src/settings/SettingsManager.h" -#include "src/settings/modules/SylvanSettings.h" - -#include "src/utility/constants.h" -#include "src/utility/macros.h" -#include "src/exceptions/NotSupportedException.h" - -namespace storm { - namespace dd { - uint_fast64_t InternalDdManager::numberOfInstances = 0; - - // It is important that the variable pairs start at an even offset, because sylvan assumes this to be true for - // some operations. - uint_fast64_t InternalDdManager::nextFreeVariableIndex = 0; - - uint_fast64_t findLargestPowerOfTwoFitting(uint_fast64_t number) { - for (uint_fast64_t index = 0; index < 64; ++index) { - if ((number & (1ull << (63 - index))) != 0) { - return 63 - index; - } - } - return 0; - } - - InternalDdManager::InternalDdManager() { - if (numberOfInstances == 0) { - // Initialize lace: auto-detect number of workers. - lace_init(storm::settings::getModule().getNumberOfThreads(), 1000000); - lace_startup(0, 0, 0); - - // Each node takes 24 bytes and the maximal memory is specified in megabytes. - uint_fast64_t totalNodesToStore = storm::settings::getModule().getMaximalMemory() * 1024 * 1024 / 24; - - // Compute the power of two that still fits within the total numbers to store. - uint_fast64_t powerOfTwo = findLargestPowerOfTwoFitting(totalNodesToStore); - - sylvan::Sylvan::initPackage(1ull << std::max(16ull, powerOfTwo > 24 ? powerOfTwo - 8 : 0ull), 1ull << (powerOfTwo - 1), 1ull << std::max(16ull, powerOfTwo > 24 ? powerOfTwo - 12 : 0ull), 1ull << (powerOfTwo - 1)); - sylvan::Sylvan::initBdd(1); - sylvan::Sylvan::initMtbdd(); - } - ++numberOfInstances; - } - - InternalDdManager::~InternalDdManager() { - --numberOfInstances; - if (numberOfInstances == 0) { - // Enable this to print the sylvan statistics to a file. -// FILE* filePointer = fopen("sylvan.stats", "w"); -// sylvan_stats_report(filePointer, 0); -// fclose(filePointer); - - sylvan::Sylvan::quitPackage(); - lace_exit(); - } - } - - InternalBdd InternalDdManager::getBddOne() const { - return InternalBdd(this, sylvan::Bdd::bddOne()); - } - - template<> - InternalAdd InternalDdManager::getAddOne() const { - return InternalAdd(this, sylvan::Mtbdd::doubleTerminal(storm::utility::one())); - } - - template<> - InternalAdd InternalDdManager::getAddOne() const { - return InternalAdd(this, sylvan::Mtbdd::int64Terminal(storm::utility::one())); - } - - InternalBdd InternalDdManager::getBddZero() const { - return InternalBdd(this, sylvan::Bdd::bddZero()); - } - - template<> - InternalAdd InternalDdManager::getAddZero() const { - return InternalAdd(this, sylvan::Mtbdd::doubleTerminal(storm::utility::zero())); - } - - template<> - InternalAdd InternalDdManager::getAddZero() const { - return InternalAdd(this, sylvan::Mtbdd::int64Terminal(storm::utility::zero())); - } - - template<> - InternalAdd InternalDdManager::getConstant(double const& value) const { - return InternalAdd(this, sylvan::Mtbdd::doubleTerminal(value)); - } - - template<> - InternalAdd InternalDdManager::getConstant(uint_fast64_t const& value) const { - return InternalAdd(this, sylvan::Mtbdd::int64Terminal(value)); - } - - std::pair, InternalBdd> InternalDdManager::createNewDdVariablePair() { - InternalBdd first = InternalBdd(this, sylvan::Bdd::bddVar(nextFreeVariableIndex)); - InternalBdd second = InternalBdd(this, sylvan::Bdd::bddVar(nextFreeVariableIndex + 1)); - nextFreeVariableIndex += 2; - return std::make_pair(first, second); - } - - void InternalDdManager::allowDynamicReordering(bool value) { - STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); - } - - bool InternalDdManager::isDynamicReorderingAllowed() const { - STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); - } - - void InternalDdManager::triggerReordering() { - STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); - } - - template InternalAdd InternalDdManager::getAddOne() const; - template InternalAdd InternalDdManager::getAddOne() const; - - template InternalAdd InternalDdManager::getAddZero() const; - template InternalAdd InternalDdManager::getAddZero() const; - - template InternalAdd InternalDdManager::getConstant(double const& value) const; - template InternalAdd InternalDdManager::getConstant(uint_fast64_t const& value) const; - } +#include "src/storage/dd/sylvan/InternalSylvanDdManager.h" + +#include + +#include "src/settings/SettingsManager.h" +#include "src/settings/modules/SylvanSettings.h" + +#include "src/utility/constants.h" +#include "src/utility/macros.h" +#include "src/exceptions/NotSupportedException.h" + +namespace storm { + namespace dd { + uint_fast64_t InternalDdManager::numberOfInstances = 0; + + // It is important that the variable pairs start at an even offset, because sylvan assumes this to be true for + // some operations. + uint_fast64_t InternalDdManager::nextFreeVariableIndex = 0; + + uint_fast64_t findLargestPowerOfTwoFitting(uint_fast64_t number) { + for (uint_fast64_t index = 0; index < 64; ++index) { + if ((number & (1ull << (63 - index))) != 0) { + return 63 - index; + } + } + return 0; + } + + InternalDdManager::InternalDdManager() { + if (numberOfInstances == 0) { + // Initialize lace: auto-detect number of workers. + lace_init(storm::settings::getModule().getNumberOfThreads(), 1000000); + lace_startup(0, 0, 0); + + // Each node takes 24 bytes and the maximal memory is specified in megabytes. + uint_fast64_t totalNodesToStore = storm::settings::getModule().getMaximalMemory() * 1024 * 1024 / 24; + + // Compute the power of two that still fits within the total numbers to store. + uint_fast64_t powerOfTwo = findLargestPowerOfTwoFitting(totalNodesToStore); + + sylvan::Sylvan::initPackage(1ull << std::max(16ull, powerOfTwo > 24 ? powerOfTwo - 8 : 0ull), 1ull << (powerOfTwo - 1), 1ull << std::max(16ull, powerOfTwo > 24 ? powerOfTwo - 12 : 0ull), 1ull << (powerOfTwo - 1)); + sylvan::Sylvan::initBdd(1); + sylvan::Sylvan::initMtbdd(); + } + ++numberOfInstances; + } + + InternalDdManager::~InternalDdManager() { + --numberOfInstances; + if (numberOfInstances == 0) { + // Enable this to print the sylvan statistics to a file. +// FILE* filePointer = fopen("sylvan.stats", "w"); +// sylvan_stats_report(filePointer, 0); +// fclose(filePointer); + + sylvan::Sylvan::quitPackage(); + lace_exit(); + } + } + + InternalBdd InternalDdManager::getBddOne() const { + return InternalBdd(this, sylvan::Bdd::bddOne()); + } + + template<> + InternalAdd InternalDdManager::getAddOne() const { + return InternalAdd(this, sylvan::Mtbdd::doubleTerminal(storm::utility::one())); + } + + template<> + InternalAdd InternalDdManager::getAddOne() const { + return InternalAdd(this, sylvan::Mtbdd::int64Terminal(storm::utility::one())); + } + +#ifdef STORM_HAVE_CARL + template<> + InternalAdd InternalDdManager::getAddOne() const { + return InternalAdd(this, sylvan::Mtbdd::terminal(sylvan_storm_rational_function_get_type(), storm::utility::one())); + } +#endif + + InternalBdd InternalDdManager::getBddZero() const { + return InternalBdd(this, sylvan::Bdd::bddZero()); + } + + template<> + InternalAdd InternalDdManager::getAddZero() const { + return InternalAdd(this, sylvan::Mtbdd::doubleTerminal(storm::utility::zero())); + } + + template<> + InternalAdd InternalDdManager::getAddZero() const { + return InternalAdd(this, sylvan::Mtbdd::int64Terminal(storm::utility::zero())); + } + +#ifdef STORM_HAVE_CARL + template<> + InternalAdd InternalDdManager::getAddZero() const { + return InternalAdd(this, sylvan::Mtbdd::terminal(sylvan_storm_rational_function_get_type(), storm::utility::zero())); + } +#endif + + template<> + InternalAdd InternalDdManager::getConstant(double const& value) const { + return InternalAdd(this, sylvan::Mtbdd::doubleTerminal(value)); + } + + template<> + InternalAdd InternalDdManager::getConstant(uint_fast64_t const& value) const { + return InternalAdd(this, sylvan::Mtbdd::int64Terminal(value)); + } + +#ifdef STORM_HAVE_CARL + template<> + InternalAdd InternalDdManager::getConstant(storm::RationalFunction const& value) const { + return InternalAdd(this, sylvan::Mtbdd::terminal(sylvan_storm_rational_function_get_type(), storm::utility::zero())); + } +#endif + + std::pair, InternalBdd> InternalDdManager::createNewDdVariablePair() { + InternalBdd first = InternalBdd(this, sylvan::Bdd::bddVar(nextFreeVariableIndex)); + InternalBdd second = InternalBdd(this, sylvan::Bdd::bddVar(nextFreeVariableIndex + 1)); + nextFreeVariableIndex += 2; + return std::make_pair(first, second); + } + + void InternalDdManager::allowDynamicReordering(bool value) { + STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); + } + + bool InternalDdManager::isDynamicReorderingAllowed() const { + STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); + } + + void InternalDdManager::triggerReordering() { + STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Operation is not supported by sylvan."); + } + + template InternalAdd InternalDdManager::getAddOne() const; + template InternalAdd InternalDdManager::getAddOne() const; + + template InternalAdd InternalDdManager::getAddZero() const; + template InternalAdd InternalDdManager::getAddZero() const; + + template InternalAdd InternalDdManager::getConstant(double const& value) const; + template InternalAdd InternalDdManager::getConstant(uint_fast64_t const& value) const; + } } \ No newline at end of file diff --git a/src/storage/dd/sylvan/InternalSylvanDdManager.h b/src/storage/dd/sylvan/InternalSylvanDdManager.h index 55be0581f..0618b0dbe 100644 --- a/src/storage/dd/sylvan/InternalSylvanDdManager.h +++ b/src/storage/dd/sylvan/InternalSylvanDdManager.h @@ -1,132 +1,148 @@ -#ifndef STORM_STORAGE_DD_SYLVAN_INTERNALSYLVANDDMANAGER_H_ -#define STORM_STORAGE_DD_SYLVAN_INTERNALSYLVANDDMANAGER_H_ - -#include "src/storage/dd/DdType.h" -#include "src/storage/dd/InternalDdManager.h" - -#include "src/storage/dd/sylvan/InternalSylvanBdd.h" -#include "src/storage/dd/sylvan/InternalSylvanAdd.h" - -namespace storm { - namespace dd { - template - class InternalAdd; - - template - class InternalBdd; - - template<> - class InternalDdManager { - public: - friend class InternalBdd; - - template - friend class InternalAdd; - - /*! - * Creates a new internal manager for Sylvan DDs. - */ - InternalDdManager(); - - /*! - * Destroys the internal manager. - */ - ~InternalDdManager(); - - /*! - * Retrieves a BDD representing the constant one function. - * - * @return A BDD representing the constant one function. - */ - InternalBdd getBddOne() const; - - /*! - * Retrieves an ADD representing the constant one function. - * - * @return An ADD representing the constant one function. - */ - template - InternalAdd getAddOne() const; - - /*! - * Retrieves a BDD representing the constant zero function. - * - * @return A BDD representing the constant zero function. - */ - InternalBdd getBddZero() const; - - /*! - * Retrieves an ADD representing the constant zero function. - * - * @return An ADD representing the constant zero function. - */ - template - InternalAdd getAddZero() const; - - /*! - * Retrieves an ADD representing the constant function with the given value. - * - * @return An ADD representing the constant function with the given value. - */ - template - InternalAdd getConstant(ValueType const& value) const; - - /*! - * Creates a new pair of DD variables and returns the two cubes as a result. - * - * @return The two cubes belonging to the DD variables. - */ - std::pair, InternalBdd> createNewDdVariablePair(); - - /*! - * Sets whether or not dynamic reordering is allowed for the DDs managed by this manager. - * - * @param value If set to true, dynamic reordering is allowed and forbidden otherwise. - */ - void allowDynamicReordering(bool value); - - /*! - * Retrieves whether dynamic reordering is currently allowed. - * - * @return True iff dynamic reordering is currently allowed. - */ - bool isDynamicReorderingAllowed() const; - - /*! - * Triggers a reordering of the DDs managed by this manager. - */ - void triggerReordering(); - - private: - // A counter for the number of instances of this class. This is used to determine when to initialize and - // quit the sylvan. This is because Sylvan does not know the concept of managers but implicitly has a - // 'global' manager. - static uint_fast64_t numberOfInstances; - - // The index of the next free variable index. This needs to be shared across all instances since the sylvan - // manager is implicitly 'global'. - static uint_fast64_t nextFreeVariableIndex; - }; - - template<> - InternalAdd InternalDdManager::getAddOne() const; - - template<> - InternalAdd InternalDdManager::getAddOne() const; - - template<> - InternalAdd InternalDdManager::getAddZero() const; - - template<> - InternalAdd InternalDdManager::getAddZero() const; - - template<> - InternalAdd InternalDdManager::getConstant(double const& value) const; - - template<> - InternalAdd InternalDdManager::getConstant(uint_fast64_t const& value) const; - - } -} - +#ifndef STORM_STORAGE_DD_SYLVAN_INTERNALSYLVANDDMANAGER_H_ +#define STORM_STORAGE_DD_SYLVAN_INTERNALSYLVANDDMANAGER_H_ + +#include "src/storage/dd/DdType.h" +#include "src/storage/dd/InternalDdManager.h" + +#include "src/storage/dd/sylvan/InternalSylvanBdd.h" +#include "src/storage/dd/sylvan/InternalSylvanAdd.h" + +#include "src/adapters/CarlAdapter.h" + +namespace storm { + namespace dd { + template + class InternalAdd; + + template + class InternalBdd; + + template<> + class InternalDdManager { + public: + friend class InternalBdd; + + template + friend class InternalAdd; + + /*! + * Creates a new internal manager for Sylvan DDs. + */ + InternalDdManager(); + + /*! + * Destroys the internal manager. + */ + ~InternalDdManager(); + + /*! + * Retrieves a BDD representing the constant one function. + * + * @return A BDD representing the constant one function. + */ + InternalBdd getBddOne() const; + + /*! + * Retrieves an ADD representing the constant one function. + * + * @return An ADD representing the constant one function. + */ + template + InternalAdd getAddOne() const; + + /*! + * Retrieves a BDD representing the constant zero function. + * + * @return A BDD representing the constant zero function. + */ + InternalBdd getBddZero() const; + + /*! + * Retrieves an ADD representing the constant zero function. + * + * @return An ADD representing the constant zero function. + */ + template + InternalAdd getAddZero() const; + + /*! + * Retrieves an ADD representing the constant function with the given value. + * + * @return An ADD representing the constant function with the given value. + */ + template + InternalAdd getConstant(ValueType const& value) const; + + /*! + * Creates a new pair of DD variables and returns the two cubes as a result. + * + * @return The two cubes belonging to the DD variables. + */ + std::pair, InternalBdd> createNewDdVariablePair(); + + /*! + * Sets whether or not dynamic reordering is allowed for the DDs managed by this manager. + * + * @param value If set to true, dynamic reordering is allowed and forbidden otherwise. + */ + void allowDynamicReordering(bool value); + + /*! + * Retrieves whether dynamic reordering is currently allowed. + * + * @return True iff dynamic reordering is currently allowed. + */ + bool isDynamicReorderingAllowed() const; + + /*! + * Triggers a reordering of the DDs managed by this manager. + */ + void triggerReordering(); + + private: + // A counter for the number of instances of this class. This is used to determine when to initialize and + // quit the sylvan. This is because Sylvan does not know the concept of managers but implicitly has a + // 'global' manager. + static uint_fast64_t numberOfInstances; + + // The index of the next free variable index. This needs to be shared across all instances since the sylvan + // manager is implicitly 'global'. + static uint_fast64_t nextFreeVariableIndex; + }; + + template<> + InternalAdd InternalDdManager::getAddOne() const; + + template<> + InternalAdd InternalDdManager::getAddOne() const; + +#ifdef STORM_HAVE_CARL + template<> + InternalAdd InternalDdManager::getAddOne() const; +#endif + + template<> + InternalAdd InternalDdManager::getAddZero() const; + + template<> + InternalAdd InternalDdManager::getAddZero() const; + +#ifdef STORM_HAVE_CARL + template<> + InternalAdd InternalDdManager::getAddZero() const; +#endif + + template<> + InternalAdd InternalDdManager::getConstant(double const& value) const; + + template<> + InternalAdd InternalDdManager::getConstant(uint_fast64_t const& value) const; + +#ifdef STORM_HAVE_CARL + template<> + InternalAdd InternalDdManager::getConstant(storm::RationalNumber const& value) const; +#endif + } +} + #endif /* STORM_STORAGE_DD_SYLVAN_INTERNALSYLVANDDMANAGER_H_ */ \ No newline at end of file diff --git a/src/utility/sylvan.h b/src/utility/sylvan.h index ccaffe097..1dd236609 100644 --- a/src/utility/sylvan.h +++ b/src/utility/sylvan.h @@ -1,15 +1,16 @@ -#ifndef STORM_STORAGE_DD_SYLVAN_SYLVAN_H_ -#define STORM_STORAGE_DD_SYLVAN_SYLVAN_H_ - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wextra-semi" -#pragma clang diagnostic ignored "-Wzero-length-array" -#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#pragma clang diagnostic ignored "-Wdeprecated-register" -#pragma clang diagnostic ignored "-Wc99-extensions" - -#include "sylvan_obj.hpp" - -#pragma clang diagnostic pop - +#ifndef STORM_STORAGE_DD_SYLVAN_SYLVAN_H_ +#define STORM_STORAGE_DD_SYLVAN_SYLVAN_H_ + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wextra-semi" +#pragma clang diagnostic ignored "-Wzero-length-array" +#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#pragma clang diagnostic ignored "-Wdeprecated-register" +#pragma clang diagnostic ignored "-Wc99-extensions" + +#include "sylvan_obj.hpp" +#include "sylvan_storm_rational_function.h" + +#pragma clang diagnostic pop + #endif /* STORM_STORAGE_DD_SYLVAN_SYLVAN_H_ */ \ No newline at end of file