1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
// FILE xsplit_data.cc : Implementation of member functions for class ff_data
//////////////////////////////////////////////////////////////////////////
//
// Copyright 1990-2012 Marcus Mo
//
// This file is part of the eclib package.
//
// eclib is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
//
// eclib is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// along with eclib; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
//
//////////////////////////////////////////////////////////////////////////
// Include headers
#include "eclib/logger.h"
#include "eclib/xsplit_data.h"
#include "eclib/xsplit.h"
/**
* ff_data()
*
* Main constructor.
* Simply initiates private variables.
*/
ff_data::ff_data( form_finder* ff )
: ff_( ff ),
status_( INTERNAL ),
depth_( 0 ),
subdim_( 0 ),
eigenvalue_( 0 ),
eiglist_(),
nest_( NULL ),
conjmat_(),
the_opmat_(),
parent_( NULL ),
numChildren_( 0 ) {}
/**
* ~ff_data()
*
* Destructor.
* Only delete the objects which this instance created.
* Prevents destruction of objects which may still be required
* by others, especially when running concurrently.
*/
ff_data::~ff_data() {
// Delete dynamically created objects
delete nest_;
nest_ = NULL;
}
#ifdef ECLIB_MULTITHREAD
/**
* operator()
*
* Overloaded operator(). Required for object to be passed to
* job queue. Task is to scan test eignvalues to identify
* newforms, or whether further recursion is necessary.
*/
void ff_data::operator()() {
// Call go_down() on current node, passing through its parent
// to keep interface consistent with original.
ff_ -> go_down( *(this->parent_), eigenvalue_, 0 );
#ifdef ECLIB_MULTITHREAD_DEBUG
ECLOG(1) << "Executing node (eig=" << eigenvalue_ << " depth=" <<depth_ << ")" << endl;
#endif
// Call find() on current node
if( subdim_ > 0 ) ff_ -> find( *this );
// Call go_up() only if this branch has ended
if( status_ != INTERNAL || subdim_ == 0 ) ff_ -> go_up( *this );
#ifdef ECLIB_MULTITHREAD_DEBUG
ECLOG(1) << "Completed node (eig=" << eigenvalue_ << " depth=" <<depth_ << " status=" << status_ << ")" << endl;
#endif
}
#endif
/**
* status()
*
* Return status of current node.
*/
nodestatus ff_data::status() {
return status_;
}
/**
* submats()
*
* Returns relevant subspace of current depth.
*/
ssubspace* ff_data::submats() {
return nest_;
}
/**
* depth()
*
* Returns current depth.
*/
long ff_data::depth() {
return depth_;
}
/**
* subdim()
*
* Return subdimension
*/
long ff_data::subdim() {
return subdim_;
}
/**
* eig()
*
* Returns eigenvalue corresponding to current instance of class.
*/
long ff_data::eig() {
return eigenvalue_;
}
/**
* eiglist()
*
* Build sequence of eigenvalues for current node by traversing up the tree.
* If an eiglist has already been computed, we simply return it to
* avoid accessing more nodes than necessary.
*/
vector< long > ff_data::eiglist() {
// Return precomputed eiglist if available
if( !eiglist_.empty() ) return eiglist_;
// Root node (depth==0). Return empty vector.
if( parent_ == NULL ) return vector< long >();
// Else, we concatenate lists from further up the tree.
eiglist_ = parent_ -> eiglist();
eiglist_.push_back( eigenvalue_ );
return eiglist_;
}
/**
* child()
*
* Returns pointer to child w.r.t. given eigenvalue.
*/
ff_data* ff_data::child( long eig ) {
return children_[ map(eig) ];
}
/**
* numCompleteChildren()
*
* Returns number of completed children for current node.
*/
int ff_data::numCompleteChildren() {
int completeCount = 0;
vector< childstatus >::iterator it;
for( it = completedChildren_.begin(); it != completedChildren_.end(); it++ ) {
if( *it != NOT_COMPLETE ) completeCount++;
}
return completeCount;
}
/**
* complete()
*
* Return true if all children complete.
*/
bool ff_data::complete() {
return ( numCompleteChildren() == numChildren_ ) ? true : false;
}
/**
* setStatus()
*
* Store status of current node.
*/
void ff_data::setStatus( nodestatus s ) {
status_ = s;
}
/**
* increaseDepth()
*
* Increases current depth. First check delta is positive.
*/
void ff_data::increaseDepth( long delta ) {
assert( delta > 0 );
depth_ += delta;
}
/**
* decreaseDepth()
*
* Decrease current depth. First check delta is positive.
*/
void ff_data::decreaseDepth( long delta ) {
assert( delta > 0 );
depth_ -= delta;
}
/**
* increaseSubmatUsage()
*
* Locked counter increment method.
*/
void ff_data::increaseSubmatUsage() {
#ifdef ECLIB_MULTITHREAD
boost::mutex::scoped_lock lock( submat_lock_ );
#endif
#ifdef ECLIB_MULTITHREAD_DEBUG
ECLOG(2) << "Increasing submat usage from " << submatUsage_ << " to " << submatUsage_+1
<< " for node eig=" << eigenvalue_ << " depth=" << depth_ << endl;
#endif
++submatUsage_;
}
/**
* storeBplus()
*
* Copies given vector into object storage.
* Use vec class overloaded operator=.
*/
void ff_data::storeBplus( vec bp ) {
bplus_ = bp;
}
/**
* storeBminus()
*
* Copies given vector into object storage.
* Use vec class overloaded operator=.
*/
void ff_data::storeBminus( vec bm ) {
bminus_ = bm;
}
/**
* addChild()
*
* Adds a new data node to the children vector.
*/
void ff_data::addChild( long eig, ff_data &child ) {
child.setParent( this );
child.setEigenvalue( eig );
children_[map(eig)] = &child;
}
/**
* eraseChild()
*
* Calls the destructor for the data node corresponding to given eigenvalue.
*/
void ff_data::eraseChild( long eig ) {
eraseChild( map(eig) );
}
/**
* eraseChild()
*
* Overloaded method. Main method for destroying children.
*/
void ff_data::eraseChild( int idx ) {
#ifdef ECLIB_MULTITHREAD_DEBUG
ECLOG(2) << "Deleting node (eig=" << children_[idx]->eigenvalue_
<< " depth=" << depth_+1 << " status=" << children_[idx]->status_ << ")" << endl;
#endif
delete children_[ idx ];
children_[ idx ] = NULL;
completedChildren_[ idx ] = DESTROYED;
}
/**
* setParent()
*
* Stores pointer to parent data node.
*/
void ff_data::setParent( ff_data *parent ) {
parent_ = parent;
}
/**
* setEigenvalue()
*
* Stores eigenvalue.
*/
void ff_data::setEigenvalue( long eig ) {
eigenvalue_ = eig;
}
/**
* numChildren()
*
* Store number of children and resize vectors to correct size.
*/
void ff_data::numChildren( int size ) {
numChildren_ = size;
children_.resize( size, NULL );
completedChildren_.resize( size, NOT_COMPLETE );
}
/**
* childStatus()
*
* Sets value in map to 'flag', given a child node.
* Monitors how many of a nodes children have completed.
*/
void ff_data::childStatus( long eig, childstatus flag ) {
#ifdef ECLIB_MULTITHREAD
boost::mutex::scoped_lock lock( childComplete_lock_ );
#endif
completedChildren_[map(eig)] = flag;
}
/**
* eraseCompletedChldren()
*
* Loops through containers and destroying completed children.
*/
void ff_data::eraseCompletedChildren() {
if( numChildren_ > 0 ) {
for( int i = 0; i < numChildren_; i++ ) {
if( completedChildren_[i] == COMPLETE ) eraseChild( i );
}
}
}
/**
* map()
*
* Hash function to map given eigenvalue
* to an index value. Removes dependancy on unordered_map.
*/
int ff_data::map( long eig ) {
if( numChildren_ == 2 ) {
return ( eig == 1 ) ? eig : 0;
} else {
return eig + ( numChildren_ - 1 ) * 0.5;
}
}
// end of XSPLIT_DATA.CC
|