Commit 42bba82b authored by Mike Kremer's avatar Mike Kremer
Browse files

Integrated reservation and release of unique tape ids in order to prevent...

Integrated reservation and release of unique tape ids in order to prevent adol-c from crashing when surpassing the maximum number of tape ids.

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@212 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent e31d42c2
......@@ -64,13 +64,14 @@ public:
function_evaluated_(false),
use_tape_(true),
constant_hessian_evaluated_(false),
tape_(TapeIDSingleton::Instance()->uniqueTapeID()) {
tape_(static_cast<short int>(TapeIDSingleton::Instance()->requestId())) {
for(size_t i = 0; i < 11; ++i) tape_stats_[i] = 0;
}
/// Destructor
virtual ~NConstraintInterfaceAD() {
TapeIDSingleton::Instance()->releaseId(static_cast<size_t>(tape_));
}
/**
......
......@@ -66,7 +66,7 @@ public:
dense_hessian_(NULL),
function_evaluated_(false),
use_tape_(true),
tape_(TapeIDSingleton::Instance()->uniqueTapeID()) {
tape_(static_cast<short int>(TapeIDSingleton::Instance()->requestId())) {
for(size_t i = 0; i < 11; ++i) tape_stats_[i] = 0;
}
......@@ -80,6 +80,8 @@ public:
}
delete[] dense_hessian_;
}
TapeIDSingleton::Instance()->releaseId(static_cast<size_t>(tape_));
}
// ================================================
......
......@@ -8,28 +8,49 @@
#ifndef TAPEIDSINGLETON_HPP_
#define TAPEIDSINGLETON_HPP_
#include <string>
#include <vector>
#include <cassert>
class TapeIDSingleton {
public:
static TapeIDSingleton* Instance() {
if(reference_ == NULL) {
reference_ = new TapeIDSingleton();
}
return reference_;
}
short int uniqueTapeID() {
short int id = tape_count_;
++tape_count_;
size_t requestId() {
// Test if previously requested id is available again
const size_t n = ids_.size();
for(size_t i = 0; i < n; ++i) {
if(!ids_[i]) {
ids_[i] = true;
return i;
}
}
// Request new id at the end of array
size_t id = ids_.size();
ids_.push_back(true);
return id;
}
void releaseId(const size_t _i) {
assert(_i < ids_.size());
ids_[_i] = false;
}
private:
TapeIDSingleton() : tape_count_(0) {}
TapeIDSingleton() {}
TapeIDSingleton(const TapeIDSingleton&) {}
~TapeIDSingleton() {}
static TapeIDSingleton* reference_;
short int tape_count_;
std::vector<bool> ids_;
};
#endif /* TAPEIDSINGLETON_HPP_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment