42 #include "Teuchos_Workspace.hpp"
52 default_workspace_store = default_workspace_store_in;
57 return default_workspace_store;
62 if( workspace_store ) {
64 <<
"\n*** Statistics for autmatic array workspace:"
65 <<
"\n Number of megabytes of preallocated workspace = "
67 <<
"\n Number of megabytes needed = "
69 <<
"\n Number of allocations using preallocated workspace = "
71 <<
"\n Number of dynamic allocations beyond preallocated workspace = "
77 <<
"\n*** Statistics for autmatic array workspace:"
78 <<
"\n No workspace storage was allocated!\n";
87 : workspace_begin_(NULL)
88 , workspace_end_(NULL)
90 , num_static_allocations_(0)
91 , num_dyn_allocations_(0)
92 , num_current_bytes_total_(0)
93 , num_max_bytes_needed_(0)
100 if(workspace_begin_)
delete [] workspace_begin_;
106 curr_ws_ptr_ != workspace_begin_, std::logic_error
107 ,
"WorkspaceStore::set_workspace_size(...) : Error, "
108 "You can not reset the workspace size when any RawWorkspace objects "
109 "are using workspace!" );
110 if(workspace_begin_)
delete [] workspace_begin_;
111 workspace_begin_ = ::new
char[num_bytes];
112 workspace_end_ = workspace_begin_ + num_bytes;
113 curr_ws_ptr_ = workspace_begin_;
114 num_static_allocations_ = 0;
115 num_dyn_allocations_ = 0;
116 num_current_bytes_total_= 0;
117 num_max_bytes_needed_ = 0;
125 workspace_store_ = workspace_store;
127 workspace_begin_ = ::new
char[num_bytes_in];
128 workspace_end_ = workspace_begin_ + num_bytes_in;
131 workspace_store_->num_dyn_allocations_++;
134 workspace_begin_ = workspace_store_->curr_ws_ptr_;
135 workspace_end_ = workspace_begin_ + num_bytes_in;
136 owns_memory_ =
false;
137 workspace_store_->curr_ws_ptr_ += num_bytes_in;
138 workspace_store_->num_static_allocations_++;
142 workspace_store_ = NULL;
143 workspace_begin_ = NULL;
144 workspace_end_ = NULL;
145 owns_memory_ =
false;
147 if(workspace_store_) {
148 workspace_store_->num_current_bytes_total_ += num_bytes_in;
149 if( workspace_store_->num_current_bytes_total_ > workspace_store_->num_max_bytes_needed_ )
150 workspace_store_->num_max_bytes_needed_ = workspace_store_->num_current_bytes_total_;
157 workspace_store_->num_current_bytes_total_ -= this->
num_bytes();
159 if(workspace_begin_)
delete [] workspace_begin_;
162 if(workspace_store_) {
164 workspace_store_->curr_ws_ptr_ != workspace_end_
165 ,
"RawWorkspace::~RawWorkspace(...): Error, "
166 "Invalid usage of RawWorkspace class, corrupted WorspaceStore object!" );
167 workspace_store_->curr_ws_ptr_ = workspace_begin_;
172 #ifdef __PGI // Should not have to define this since it should not be called!
173 void* RawWorkspace::operator
new(size_t)
TEUCHOSCORE_LIB_DLL_EXPORT void set_default_workspace_store(const Teuchos::RCP< WorkspaceStore > &default_workspace_store)
Set pointer to global workspace object.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
size_t num_bytes() const
Return the number of bytes of raw workspace.
~RawWorkspace()
Deallocate workspace.
WorkspaceStore(size_t num_bytes)
Workspace encapsulation class.
size_t num_max_bytes_needed() const
Return the maximum storage in bytes needed. This is the maximum total amount of * storage that was ne...
int num_dyn_allocations() const
Return the number of dynamic memory allocations granted thus far. This is the number of memory alloca...
#define TEUCHOS_TEST_FOR_TERMINATION(terminate_test, msg)
This macro is to be used instead of TEUCHOS_TEST_FOR_EXCEPTION() to report an error in situations whe...
int num_static_allocations() const
Return the number of static memory allocations granted thus far. This is the number of memory allocat...
Smart reference counting pointer class for automatic garbage collection.
void protected_initialize(size_t num_bytes)
size_t num_bytes_remaining() const
Return the number of bytes remaining currently.
size_t num_bytes_total() const
Return the total number of bytes that where initially allocated.
TEUCHOSCORE_LIB_DLL_EXPORT void print_memory_usage_stats(const WorkspaceStore *workspace_store, std::ostream &out)
Print statistics on memory usage.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
Get the global workspace object set by set_default_workspace_store().