/*!\brief Execution function for threads in a thread pool. // // This function is executed by any thread managed by a thread pool. */ void Thread::run() { // Checking the thread pool handle BLAZE_INTERNAL_ASSERT( pool_, "Uninitialized pool handle detected" ); // Executing scheduled tasks while( pool_->executeTask() ) {} // Setting the termination flag terminated_ = true; }
/*!\brief Commits the current log message to the log file. // // \return void // // This function commits the current log message to the log file. The function is automatically // called at the end of a log section, but can also be used manually in order to intermediately // commit log messages, for instance in the case of nested log sections. */ void LogSection::commit() { // Early exit in case the log message is empty if( message_.str().empty() ) return; std::string line; std::ostringstream oss; // Writing the log level information switch( level_ ) { case inactive: oss << "[INACTIVE]"; break; case error : oss << "[ERROR ]"; break; case warning : oss << "[WARNING ]"; break; case info : oss << "[INFO ]"; break; case progress: oss << "[PROGRESS]"; break; case debug : oss << "[DEBUG ]"; break; case detail : oss << "[DETAIL ]"; break; default: BLAZE_INTERNAL_ASSERT( false, "Unknown logging level" ); break; } // Writing the elapsed time const time_t elapsed( theSystemClock()->elapsed() ); const time_t hours ( elapsed / time_t( 3600 ) ); const time_t minutes( ( elapsed % time_t( 3600 ) ) / time_t( 60 ) ); const time_t seconds( elapsed % time_t( 60 ) ); oss << boost::format( "[%03d:%02d:%02d] " ) % hours % minutes % seconds; // Commiting the log message std::getline( message_, line ); oss << line << "\n"; while( std::getline( message_, line ) ) { if( !line.empty() ) oss << " " << line << "\n"; } // Adding an additional spacing line if( spacing ) oss << "\n"; // Logging the formated log message boost::shared_ptr<Logger> logger( Logger::instance() ); logger->log( oss.str() ); // Resetting the message buffer message_.str( "" ); message_.clear(); }
/*!\brief TODO // // \param A TODO // \param b TODO // \param x TODO // \return TODO // \exception std::invalid_argument Invalid matrix size. // \exception std::invalid_argument Invalid right-hand side vector size. // // TODO: description // TODO: problem formulation \f$ A \cdot x + b = 0 \f$ !! */ bool GaussianElimination::solve( const CMatMxN& A, const VecN& b, VecN& x ) { if( A.rows() != A.columns() ) throw std::invalid_argument( "Invalid matrix size" ); if( A.rows() != b.size() ) throw std::invalid_argument( "Invalid right-hand side vector size" ); const size_t n( b.size() ); // Allocating helper data A_ = A; b_ = -b; x.resize( n, false ); size_t pi, pj; lastPrecision_ = real(0); // Initializing the pivot vector DynamicVector<size_t> p( n ); for( size_t j=0; j<n; ++j ) { p[j] = j; } // Performing the Gaussian elimination for( size_t j=0; j<n; ++j ) { size_t max( j ); real max_val( std::fabs( A_(p[max],j) ) ); // Partial search for pivot for( size_t i=j+1; i<n; ++i ) { if( std::fabs( A_(p[i],j) ) > max_val ) { max = i; max_val = std::fabs( A_(p[max],j) ); } } // Swapping rows such the pivot lies on the diagonal std::swap( p[max], p[j] ); pj = p[j]; if( !isDefault( A_(pj,j) ) ) { // Eliminating the column below the diagonal for( size_t i=j+1; i<n; ++i ) { pi = p[i]; const real f = A_(pi,j) / A_(pj,j); reset( A_(pi,j) ); for( size_t k=j+1; k<n; ++k ) { A_(pi,k) -= A_(pj,k) * f; } b_[pi] -= b_[pj] * f; } } else { // Asserting that the column is zero below the diagonal for( size_t i=j+1; i<n; ++i ) { BLAZE_INTERNAL_ASSERT( isDefault( A_(p[i],j) ), "Fatal error in Gaussian elimination" ); } } } // Performing the backward substitution for( size_t i=n-1; i<n; --i ) { pi = p[i]; real rhs = b_[pi]; for( size_t j=i+1; j<n; ++j ) { rhs -= x[j] * A_(pi,j); } if( std::fabs( A_(pi,i) ) > accuracy ) { x[i] = rhs / A_(pi,i); } else { // This will introduce errors in the solution reset( x[i] ); lastPrecision_ = max( lastPrecision_, std::fabs( rhs ) ); } } BLAZE_LOG_DEBUG_SECTION( log ) { if( lastPrecision_ < threshold_ ) log << " Solved the linear system using Gaussian elimination."; else log << BLAZE_YELLOW << " WARNING: Did not solve the linear system within accuracy. (" << lastPrecision_ << ")" << BLAZE_OLDCOLOR; } lastIterations_ = 1; return lastPrecision_ < threshold_; }