From a2c378d30a852ad61daff57596a217d245e9f5ec Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 26 Jun 2019 09:29:48 +0200 Subject: [PATCH] Extend OpenMP thread safeness to all methods in ctool.cpp base class (#2912) --- NEWS | 5 +++-- configure.ac | 2 +- src/support/ctool.cpp | 60 +++++++++++++++++++++++++++++++++--------------------------- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/NEWS b/NEWS index d8f6850..458a5f1 100755 --- a/NEWS +++ b/NEWS @@ -31,8 +31,9 @@ None Base classes ------------ -Make ctool::create_ebounds() OpenMP thread save so that multiple threads can -call the method and load energy boudnary FITS files (#2912). +Make ctool::create_ebounds(), ctool::create_energies() and +ctool::save_event_list() methods OpenMP thread save so that multiple threads +can call the method at the same time (#2912). ctbin - CTA event binning diff --git a/configure.ac b/configure.ac index 1240082..52acfd1 100755 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ ############################################################################# # Configuration for ctools - tools for science analysis of CTA data # # ------------------------------------------------------------------------- # -# Copyright (C) 2011-2018 Juergen Knoedlseder # +# Copyright (C) 2011-2019 Juergen Knoedlseder # # ------------------------------------------------------------------------- # # # # This program is free software: you can redistribute it and/or modify # diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index 01ec034..8b8b6cc 100755 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -733,7 +733,7 @@ GEnergies ctool::create_energies(void) // If no extension name was provided then use default extension names if (!ebinfile.has_extname()) { - // Make loading of energy boundaries OpenMP thread save + // Make loading of energies OpenMP thread save #pragma omp critical(ctool_create_energies1) { @@ -773,7 +773,7 @@ GEnergies ctool::create_energies(void) // extension else { - // Make loading of energy boundaries OpenMP thread save + // Make loading of energies OpenMP thread save #pragma omp critical(ctool_create_energies2) { @@ -2229,34 +2229,40 @@ void ctool::save_event_list(const GCTAObservation* obs, } } - // Create output FITS file - GFits outfits; - - // Write observation into FITS file - obs->write(outfits, outevt, outgti); - - // Copy all extensions other than evtname and gtiname extensions - // from the input to the output event list. The evtname and - // gtiname extensions are written by the save method, all others - // that may eventually be present have to be copied over - // explicitly. - GFits infits(infile); - for (int extno = 1; extno < infits.size(); ++extno) { - GFitsHDU* hdu = infits.at(extno); - if (hdu->extname() != evtname && - hdu->extname() != gtiname && - hdu->extname() != outevt && - hdu->extname() != outgti) { - outfits.append(*hdu); + // Make writing of FITS file OpenMP thread save + #pragma omp critical(ctool_save_event_list) + { + + // Create output FITS file + GFits outfits; + + // Write observation into FITS file + obs->write(outfits, outevt, outgti); + + // Copy all extensions other than evtname and gtiname extensions + // from the input to the output event list. The evtname and + // gtiname extensions are written by the save method, all others + // that may eventually be present have to be copied over + // explicitly. + GFits infits(infile); + for (int extno = 1; extno < infits.size(); ++extno) { + GFitsHDU* hdu = infits.at(extno); + if (hdu->extname() != evtname && + hdu->extname() != gtiname && + hdu->extname() != outevt && + hdu->extname() != outgti) { + outfits.append(*hdu); + } } - } - // Close input file - infits.close(); + // Close input file + infits.close(); + + // Save file to disk and close it (we need both operations) + outfits.saveto(outname.url(), clobber()); + outfits.close(); - // Save file to disk and close it (we need both operations) - outfits.saveto(outname.url(), clobber()); - outfits.close(); + } // end: omp critical section } // endif: observation was unbinned -- libgit2 0.21.4