Commit a766ae3b12776fb9db29eb7cd80de75a7d1f35e7
1 parent
a6a77595
Add hidden nthreads parameter to ctbin and ctmodel (#2421)
Showing
11 changed files
with
87 additions
and
14 deletions
ChangeLog
| ... | ... | @@ -10,7 +10,8 @@ |
| 10 | 10 | Add Exponential spectral model to science verification (#2454) |
| 11 | 11 | Fix bug when using precomputed model in csresspec (#2448) |
| 12 | 12 | Parallelise cslightcrv, csphasecrv, csspec, cssens, csphagen, cspull and |
| 13 | - cstsdist and add nthreads parameter to ctobssim, ctlike and cterror (#2421) | |
| 13 | + cstsdist and add nthreads parameter to ctobssim, ctbin, ctlike, cterror | |
| 14 | + and ctmodel (#2421) | |
| 14 | 15 | Keep existing library path in installation script on Mac OS X (#2420) |
| 15 | 16 | csphagen produces Xspec compliant data (#2404) |
| 16 | 17 | Add show_rmf.py example script | ... | ... |
NEWS
| ... | ... | @@ -49,6 +49,8 @@ of the filename is now done by the GApplicationPar class. |
| 49 | 49 | |
| 50 | 50 | ctbin - CTA event binning |
| 51 | 51 | ------------------------- |
| 52 | +Add hidden "nthreads" parameter to control parallel computations (#2421). | |
| 53 | + | |
| 52 | 54 | Copy the time reference from the first input observation (#2054). |
| 53 | 55 | |
| 54 | 56 | |
| ... | ... | @@ -94,7 +96,7 @@ None |
| 94 | 96 | |
| 95 | 97 | ctmodel - CTA counts cube modelling |
| 96 | 98 | ----------------------------------- |
| 97 | -None | |
| 99 | +Add hidden "nthreads" parameter to control parallel computations (#2421). | |
| 98 | 100 | |
| 99 | 101 | |
| 100 | 102 | ctobssim - CTA observation simulation | ... | ... |
cscripts/obsutils.py
| ... | ... | @@ -165,6 +165,7 @@ def sim(obs, log=False, debug=False, chatter=2, edisp=False, seed=0, |
| 165 | 165 | binning['binsz'] = binsz |
| 166 | 166 | binning['coordsys'] = coord |
| 167 | 167 | binning['proj'] = proj |
| 168 | + binning['nthreads'] = nthreads | |
| 168 | 169 | binning['chatter'] = chatter |
| 169 | 170 | binning['debug'] = debug |
| 170 | 171 | ... | ... |
doc/source/users/reference_manual/ctbin.rst
| ... | ... | @@ -85,6 +85,9 @@ General parameters |
| 85 | 85 | Standard parameters |
| 86 | 86 | ------------------- |
| 87 | 87 | |
| 88 | +``(nthreads = 0) [integer]`` | |
| 89 | + Number of parallel processes (0=use all available CPUs). | |
| 90 | + | |
| 88 | 91 | ``(publish = no) [boolean]`` |
| 89 | 92 | Specifies whether the counts cube should be published on VO Hub. |
| 90 | 93 | ... | ... |
doc/source/users/reference_manual/ctmodel.rst
| ... | ... | @@ -148,6 +148,9 @@ General parameters |
| 148 | 148 | Standard parameters |
| 149 | 149 | ------------------- |
| 150 | 150 | |
| 151 | +``(nthreads = 0) [integer]`` | |
| 152 | + Number of parallel processes (0=use all available CPUs). | |
| 153 | + | |
| 151 | 154 | ``(publish = no) [boolean]`` |
| 152 | 155 | Specifies whether the model cube should be published on VO Hub. |
| 153 | 156 | ... | ... |
pyext/ctobservation.i
| ... | ... | @@ -118,6 +118,7 @@ public: |
| 118 | 118 | // Protected methods |
| 119 | 119 | GCTAObservation* first_unbinned_observation(void); |
| 120 | 120 | GCTAObservation* next_unbinned_observation(void); |
| 121 | + void read_ogip_keywords(GFitsHDU* hdu) const; | |
| 121 | 122 | void write_ogip_keywords(GFitsHDU* hdu) const; |
| 122 | 123 | void set_obs_statistic(const std::string& statistic); |
| 123 | 124 | void save_events_fits(void); | ... | ... |
src/ctbin/ctbin.cpp
| ... | ... | @@ -473,6 +473,14 @@ void ctbin::get_parameters(void) |
| 473 | 473 | m_dirs[pix].radec(m_dirs[pix].ra(), m_dirs[pix].dec()); |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | + // Set number of OpenMP threads | |
| 477 | + #ifdef _OPENMP | |
| 478 | + int nthreads = (*this)["nthreads"].integer(); | |
| 479 | + if (nthreads > 0) { | |
| 480 | + omp_set_num_threads(nthreads); | |
| 481 | + } | |
| 482 | + #endif | |
| 483 | + | |
| 476 | 484 | // Write parameters into logger |
| 477 | 485 | log_parameters(TERSE); |
| 478 | 486 | ... | ... |
src/ctbin/ctbin.par
| ... | ... | @@ -43,9 +43,10 @@ yref, r, a, 22.51,-90,90, "Second coordinate of image center in degrees (DEC |
| 43 | 43 | # |
| 44 | 44 | # Standard parameters |
| 45 | 45 | #==================== |
| 46 | -publish, b, h, no,,, "Publish counts cube on VO Hub?" | |
| 47 | -chatter, i, h, 2,0,4, "Chattiness of output" | |
| 48 | -clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | |
| 49 | -debug, b, h, no,,, "Activate debugging mode?" | |
| 50 | -mode, s, h, ql,,, "Mode of automatic parameters" | |
| 51 | -logfile, f, h, ctbin.log,,, "Log filename" | |
| 46 | +nthreads, i, h, 0,0,1000, "Number of parallel processes (0=use all available CPUs)" | |
| 47 | +publish, b, h, no,,, "Publish counts cube on VO Hub?" | |
| 48 | +chatter, i, h, 2,0,4, "Chattiness of output" | |
| 49 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | |
| 50 | +debug, b, h, no,,, "Activate debugging mode?" | |
| 51 | +mode, s, h, ql,,, "Mode of automatic parameters" | |
| 52 | +logfile, f, h, ctbin.log,,, "Log filename" | ... | ... |
src/ctmodel/ctmodel.cpp
| ... | ... | @@ -590,6 +590,14 @@ void ctmodel::get_parameters(void) |
| 590 | 590 | |
| 591 | 591 | } // endif: cube was scheduled for appending |
| 592 | 592 | |
| 593 | + // Set number of OpenMP threads | |
| 594 | + #ifdef _OPENMP | |
| 595 | + int nthreads = (*this)["nthreads"].integer(); | |
| 596 | + if (nthreads > 0) { | |
| 597 | + omp_set_num_threads(nthreads); | |
| 598 | + } | |
| 599 | + #endif | |
| 600 | + | |
| 593 | 601 | // Write parameters into logger |
| 594 | 602 | log_parameters(TERSE); |
| 595 | 603 | ... | ... |
src/ctmodel/ctmodel.par
| ... | ... | @@ -62,9 +62,10 @@ yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DEC |
| 62 | 62 | # |
| 63 | 63 | # Standard parameters |
| 64 | 64 | #==================== |
| 65 | -publish, b, h, no,,, "Publish model cube on VO Hub?" | |
| 66 | -chatter, i, h, 2,0,4, "Chattiness of output" | |
| 67 | -clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | |
| 68 | -debug, b, h, no,,, "Activate debugging mode?" | |
| 69 | -mode, s, h, ql,,, "Mode of automatic parameters" | |
| 70 | -logfile, f, h, ctmodel.log,,, "Log filename" | |
| 65 | +nthreads, i, h, 0,0,1000, "Number of parallel processes (0=use all available CPUs)" | |
| 66 | +publish, b, h, no,,, "Publish model cube on VO Hub?" | |
| 67 | +chatter, i, h, 2,0,4, "Chattiness of output" | |
| 68 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | |
| 69 | +debug, b, h, no,,, "Activate debugging mode?" | |
| 70 | +mode, s, h, ql,,, "Mode of automatic parameters" | |
| 71 | +logfile, f, h, ctmodel.log,,, "Log filename" | ... | ... |
test/test_cscript.py
| ... | ... | @@ -189,6 +189,13 @@ class ctobservation_test(ctools.csobservation): |
| 189 | 189 | self._set_obs_statistic(statistic) |
| 190 | 190 | return gammalib.toupper(self.obs()[0].statistic()) |
| 191 | 191 | |
| 192 | + # Check read_ogip_keywords() and write_ogip_keywords methods | |
| 193 | + def check_ogip_keywords(self, hdu): | |
| 194 | + self._read_ogip_keywords(hdu) | |
| 195 | + self._write_ogip_keywords(hdu) | |
| 196 | + self._read_ogip_keywords(hdu) | |
| 197 | + return hdu | |
| 198 | + | |
| 192 | 199 | |
| 193 | 200 | # ======================= # |
| 194 | 201 | # ctlikelihood_test class # |
| ... | ... | @@ -665,6 +672,43 @@ class Test(test): |
| 665 | 672 | 'CSTAT', |
| 666 | 673 | 'Check set_obs_statistic("DEFAULT") for On/Off') |
| 667 | 674 | |
| 675 | + # Test read_ogip_keywords() method for empty header | |
| 676 | + hdu = empty.check_ogip_keywords(gammalib.GFitsBinTable()) | |
| 677 | + self.test_value(hdu.string('TELESCOP'), '', 'Check "TELESCOP" keyword') | |
| 678 | + self.test_value(hdu.string('DATE-OBS'), '2010-01-01', 'Check "DATE-OBS" keyword') | |
| 679 | + self.test_value(hdu.string('TIME-OBS'), '00:00:00', 'Check "TIME-OBS" keyword') | |
| 680 | + self.test_value(hdu.string('DATE-END'), '2010-01-01', 'Check "DATE-END" keyword') | |
| 681 | + self.test_value(hdu.string('TIME-END'), '00:00:00', 'Check "TIME-END" keyword') | |
| 682 | + self.test_value(hdu.real('TELAPSE'), 0.0, 'Check "TELAPSE" keyword') | |
| 683 | + self.test_value(hdu.real('ONTIME'), 0.0, 'Check "ONTIME" keyword') | |
| 684 | + self.test_value(hdu.real('LIVETIME'), 0.0, 'Check "LIVETIME" keyword') | |
| 685 | + self.test_value(hdu.real('EXPOSURE'), 0.0, 'Check "EXPOSURE" keyword') | |
| 686 | + self.test_value(hdu.real('DEADC'), 1.0, 'Check "DEADC" keyword') | |
| 687 | + | |
| 688 | + # Test read_ogip_keywords() method for filled header | |
| 689 | + table = gammalib.GFitsBinTable() | |
| 690 | + table.card('TELESCOP', 'CTA', 'Comment') | |
| 691 | + table.card('DATE-OBS', '2018-01-01', 'Comment') | |
| 692 | + table.card('TIME-OBS', '01:02:03', 'Comment') | |
| 693 | + table.card('DATE-END', '2018-02-05', 'Comment') | |
| 694 | + table.card('TIME-END', '21:12:05', 'Comment') | |
| 695 | + table.card('TELAPSE', 1234.0, 'Comment') | |
| 696 | + table.card('ONTIME', 2345.0, 'Comment') | |
| 697 | + table.card('LIVETIME', 2210.0, 'Comment') | |
| 698 | + table.card('EXPOSURE', 3001.0, 'Comment') | |
| 699 | + | |
| 700 | + hdu = empty.check_ogip_keywords(table) | |
| 701 | + self.test_value(hdu.string('TELESCOP'), 'CTA', 'Check "TELESCOP" keyword') | |
| 702 | + self.test_value(hdu.string('DATE-OBS'), '2018-01-01', 'Check "DATE-OBS" keyword') | |
| 703 | + self.test_value(hdu.string('TIME-OBS'), '01:02:03', 'Check "TIME-OBS" keyword') | |
| 704 | + self.test_value(hdu.string('DATE-END'), '2018-02-05', 'Check "DATE-END" keyword') | |
| 705 | + self.test_value(hdu.string('TIME-END'), '21:12:05', 'Check "TIME-END" keyword') | |
| 706 | + self.test_value(hdu.real('TELAPSE'), 1234.0, 'Check "TELAPSE" keyword') | |
| 707 | + self.test_value(hdu.real('ONTIME'), 2345.0, 'Check "ONTIME" keyword') | |
| 708 | + self.test_value(hdu.real('LIVETIME'), 2210.0, 'Check "LIVETIME" keyword') | |
| 709 | + self.test_value(hdu.real('EXPOSURE'), 3001.0, 'Check "EXPOSURE" keyword') | |
| 710 | + self.test_value(hdu.real('DEADC'), 2210.0/2345.0, 'Check "DEADC" keyword') | |
| 711 | + | |
| 668 | 712 | # Return |
| 669 | 713 | return |
| 670 | 714 | ... | ... |