Commit a2c378d30a852ad61daff57596a217d245e9f5ec
1 parent
4ceb2c5d
Extend OpenMP thread safeness to all methods in ctool.cpp base class (#2912)
Showing
3 changed files
with
37 additions
and
30 deletions
NEWS
| ... | ... | @@ -31,8 +31,9 @@ None |
| 31 | 31 | |
| 32 | 32 | Base classes |
| 33 | 33 | ------------ |
| 34 | -Make ctool::create_ebounds() OpenMP thread save so that multiple threads can | |
| 35 | -call the method and load energy boudnary FITS files (#2912). | |
| 34 | +Make ctool::create_ebounds(), ctool::create_energies() and | |
| 35 | +ctool::save_event_list() methods OpenMP thread save so that multiple threads | |
| 36 | +can call the method at the same time (#2912). | |
| 36 | 37 | |
| 37 | 38 | |
| 38 | 39 | ctbin - CTA event binning | ... | ... |
configure.ac
| 1 | 1 | ############################################################################# |
| 2 | 2 | # Configuration for ctools - tools for science analysis of CTA data # |
| 3 | 3 | # ------------------------------------------------------------------------- # |
| 4 | -# Copyright (C) 2011-2018 Juergen Knoedlseder # | |
| 4 | +# Copyright (C) 2011-2019 Juergen Knoedlseder # | |
| 5 | 5 | # ------------------------------------------------------------------------- # |
| 6 | 6 | # # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify # | ... | ... |
src/support/ctool.cpp
| ... | ... | @@ -733,7 +733,7 @@ GEnergies ctool::create_energies(void) |
| 733 | 733 | // If no extension name was provided then use default extension names |
| 734 | 734 | if (!ebinfile.has_extname()) { |
| 735 | 735 | |
| 736 | - // Make loading of energy boundaries OpenMP thread save | |
| 736 | + // Make loading of energies OpenMP thread save | |
| 737 | 737 | #pragma omp critical(ctool_create_energies1) |
| 738 | 738 | { |
| 739 | 739 | |
| ... | ... | @@ -773,7 +773,7 @@ GEnergies ctool::create_energies(void) |
| 773 | 773 | // extension |
| 774 | 774 | else { |
| 775 | 775 | |
| 776 | - // Make loading of energy boundaries OpenMP thread save | |
| 776 | + // Make loading of energies OpenMP thread save | |
| 777 | 777 | #pragma omp critical(ctool_create_energies2) |
| 778 | 778 | { |
| 779 | 779 | |
| ... | ... | @@ -2229,34 +2229,40 @@ void ctool::save_event_list(const GCTAObservation* obs, |
| 2229 | 2229 | } |
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | - // Create output FITS file | |
| 2233 | - GFits outfits; | |
| 2234 | - | |
| 2235 | - // Write observation into FITS file | |
| 2236 | - obs->write(outfits, outevt, outgti); | |
| 2237 | - | |
| 2238 | - // Copy all extensions other than evtname and gtiname extensions | |
| 2239 | - // from the input to the output event list. The evtname and | |
| 2240 | - // gtiname extensions are written by the save method, all others | |
| 2241 | - // that may eventually be present have to be copied over | |
| 2242 | - // explicitly. | |
| 2243 | - GFits infits(infile); | |
| 2244 | - for (int extno = 1; extno < infits.size(); ++extno) { | |
| 2245 | - GFitsHDU* hdu = infits.at(extno); | |
| 2246 | - if (hdu->extname() != evtname && | |
| 2247 | - hdu->extname() != gtiname && | |
| 2248 | - hdu->extname() != outevt && | |
| 2249 | - hdu->extname() != outgti) { | |
| 2250 | - outfits.append(*hdu); | |
| 2232 | + // Make writing of FITS file OpenMP thread save | |
| 2233 | + #pragma omp critical(ctool_save_event_list) | |
| 2234 | + { | |
| 2235 | + | |
| 2236 | + // Create output FITS file | |
| 2237 | + GFits outfits; | |
| 2238 | + | |
| 2239 | + // Write observation into FITS file | |
| 2240 | + obs->write(outfits, outevt, outgti); | |
| 2241 | + | |
| 2242 | + // Copy all extensions other than evtname and gtiname extensions | |
| 2243 | + // from the input to the output event list. The evtname and | |
| 2244 | + // gtiname extensions are written by the save method, all others | |
| 2245 | + // that may eventually be present have to be copied over | |
| 2246 | + // explicitly. | |
| 2247 | + GFits infits(infile); | |
| 2248 | + for (int extno = 1; extno < infits.size(); ++extno) { | |
| 2249 | + GFitsHDU* hdu = infits.at(extno); | |
| 2250 | + if (hdu->extname() != evtname && | |
| 2251 | + hdu->extname() != gtiname && | |
| 2252 | + hdu->extname() != outevt && | |
| 2253 | + hdu->extname() != outgti) { | |
| 2254 | + outfits.append(*hdu); | |
| 2255 | + } | |
| 2251 | 2256 | } |
| 2252 | - } | |
| 2253 | 2257 | |
| 2254 | - // Close input file | |
| 2255 | - infits.close(); | |
| 2258 | + // Close input file | |
| 2259 | + infits.close(); | |
| 2260 | + | |
| 2261 | + // Save file to disk and close it (we need both operations) | |
| 2262 | + outfits.saveto(outname.url(), clobber()); | |
| 2263 | + outfits.close(); | |
| 2256 | 2264 | |
| 2257 | - // Save file to disk and close it (we need both operations) | |
| 2258 | - outfits.saveto(outname.url(), clobber()); | |
| 2259 | - outfits.close(); | |
| 2265 | + } // end: omp critical section | |
| 2260 | 2266 | |
| 2261 | 2267 | } // endif: observation was unbinned |
| 2262 | 2268 | ... | ... |