Commit 084edda971dd4b29f03b404a4ad558af4a9995cc

Authored by Jürgen Knödlseder
1 parent ab79d3e5

Put more logger code in OpenMP critical zones

Showing 1 changed file with 25 additions and 14 deletions
src/app/GLog.cpp
... ... @@ -206,6 +206,7 @@ GLog& GLog::operator<<(GLog& log)
206 206 // If log object has an open file then append the log buffer to this
207 207 // buffer
208 208 if (log.m_file == NULL) {
  209 + #pragma omp critical(GLog_insert_logger)
209 210 m_buffer.append(log.m_buffer);
210 211 }
211 212  
... ... @@ -229,7 +230,8 @@ GLog& GLog::operator<<(GLog& log)
229 230  
230 231 // Append all lines from file to this buffer
231 232 std::string line;
232   - while(std::getline(file,line)){
  233 + while(std::getline(file,line)) {
  234 + #pragma omp critical(GLog_insert_logger)
233 235 m_buffer.append(line+"\n");
234 236 }
235 237  
... ... @@ -471,11 +473,20 @@ void GLog::clear(void)
471 473 ***************************************************************************/
472 474 long int GLog::size(void) const
473 475 {
474   - // Determine the number of characters written to disk
475   - long int size = (m_file != NULL) ? std::ftell(m_file) : 0;
  476 + // Initialise size
  477 + long int size = 0;
476 478  
477   - // Add in buffer size
478   - size += m_buffer.size();
  479 + // Put size determination in OpenMP critical zone
  480 + #pragma omp critical(GLog_flush)
  481 + {
  482 +
  483 + // Determine the number of characters written to disk
  484 + size = (m_file != NULL) ? std::ftell(m_file) : 0;
  485 +
  486 + // Add in buffer size
  487 + size += m_buffer.size();
  488 +
  489 + } // end of OpenMP critical zone
479 490  
480 491 // Return total size
481 492 return size;
... ... @@ -653,15 +664,15 @@ void GLog::free_members(void)
653 664 ***************************************************************************/
654 665 void GLog::flush(const bool& force)
655 666 {
656   - // Check if buffer should be flushed
657   - bool flush = (force || m_buffer.size() > m_max_length);
  667 + // Put flushing in OpenMP critical zone
  668 + #pragma omp critical(GLog_flush)
  669 + {
  670 + // Check if buffer should be flushed
  671 + bool flush = (force || m_buffer.size() > m_max_length);
658 672  
659   - // Flush buffer
660   - if (flush) {
  673 + // Flush buffer
  674 + if (flush) {
661 675  
662   - // Put flushing in OpenMP critical zone
663   - #pragma omp critical(GLog_flush)
664   - {
665 676  
666 677 // Flush buffer until it is empty
667 678 while (m_buffer.size() > 0) {
... ... @@ -690,9 +701,9 @@ void GLog::flush(const bool& force)
690 701 // And now flush the kernel buffer
691 702 std::fflush(m_file);
692 703  
693   - } // end of OpenMP critical zone
  704 + } // endif: flush was required
694 705  
695   - } // endif: flush was required
  706 + } // end of OpenMP critical zone
696 707  
697 708 // Return
698 709 return;
... ...