From 6b5fac3ee761668209bc5b84c268da15b70f226b Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 28 Jul 2017 13:26:34 +0200 Subject: [PATCH] Integrate code --- ChangeLog | 3 ++- NEWS | 6 ++++-- doc/source/admin/release_history/1.4.rst | 2 ++ src/ctbin/ctbin.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- src/ctbin/ctbin.hpp | 6 ++++-- 5 files changed, 71 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e4a816..edede34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,10 @@ -2017-07-03 +2017-07-28 * Version 1.4.0 released ======================== Install ctools header files (#2145) + Parallelize event binning in ctbin using OpenMP (#1970) 2017-06-23 diff --git a/NEWS b/NEWS index a2e9114..31760c2 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.4.0 -3 July 2017 +28 July 2017 Introduction @@ -37,7 +37,9 @@ None ctbin - CTA event binning ------------------------- -None +The loop over the observations was parallelized using OpenMP for faster +execution. In addition, the sky directions were cached for faster computation +of the weights (#1970). ctlike - Maximum likelihood fitting diff --git a/doc/source/admin/release_history/1.4.rst b/doc/source/admin/release_history/1.4.rst index f2200f3..355a205 100644 --- a/doc/source/admin/release_history/1.4.rst +++ b/doc/source/admin/release_history/1.4.rst @@ -23,6 +23,8 @@ Improvements * [`2145 `_] - Install C++ header files +* [`1970 `_] - + Parallelize :ref:`ctbin` using OpenMP New features diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index cbbc041..a362978 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -233,25 +233,33 @@ void ctbin::run(void) log_observations(NORMAL, m_obs, "Input observation"); // Write header into logger - log_header1(TERSE, gammalib::number("Find unbinned observation", m_obs.size())); + log_header1(TERSE, gammalib::number("Find unbinned observation", + m_obs.size())); // Find all unbinned CTA observations in m_obs std::vector obs_list(0); for (GCTAObservation* obs = first_unbinned_observation(); obs != NULL; obs = next_unbinned_observation()) { - std::string msg = " Including unbinned "+obs->instrument()+" observation"; - log_string(NORMAL, msg); + + // Push observation into list obs_list.push_back(obs); + + // Write message + std::string msg = " Including unbinned "+obs->instrument()+ + " observation"; + log_string(NORMAL, msg); } // Write header into logger log_header1(TERSE, gammalib::number("Bin observation", m_obs.size())); - + // Loop over all unbinned CTA observations in the container - #pragma omp parallel for - for (int oindx=0; oindxdir()); - GSkyDir dir = inst->dir(); + GCTAInstDir* inst = (GCTAInstDir*)&(event->dir()); + GSkyDir dir = inst->dir(); // Skip event if it is outside the RoI if (roi.centre().dir().dist_deg(dir) > roi.radius()) { @@ -564,32 +576,37 @@ void ctbin::fill_cube(GCTAObservation* obs) } // Fill event in skymap - #pragma omp critical + #pragma omp critical(ctbin_fill_cube) m_counts(pixel, iebin) += 1.0; - + + // Increment number of maps num_in_map++; } // endfor: looped over all events - #pragma omp critical + // Update time information + #pragma omp critical(ctbin_fill_cube) { // Append GTIs m_gti.extend(events->gti()); - + // Update ontime and livetime m_ontime += obs->ontime(); m_livetime += obs->livetime(); } - + // Log filling results - log_header3(TERSE, get_obs_header(obs)); - log_value(NORMAL, "Events in list", obs->events()->size()); - log_value(NORMAL, "Events in cube", num_in_map); - log_value(NORMAL, "Events outside RoI", num_outside_roi); - log_value(NORMAL, "Events with invalid WCS", num_invalid_wcs); - log_value(NORMAL, "Events outside cube area", num_outside_map); - log_value(NORMAL, "Events outside energy bins", num_outside_ebds); - + #pragma omp critical(ctbin_fill_cube) + { + log_header3(TERSE, get_obs_header(obs)); + log_value(NORMAL, "Events in list", obs->events()->size()); + log_value(NORMAL, "Events in cube", num_in_map); + log_value(NORMAL, "Events outside RoI", num_outside_roi); + log_value(NORMAL, "Events with invalid WCS", num_invalid_wcs); + log_value(NORMAL, "Events outside cube area", num_outside_map); + log_value(NORMAL, "Events outside energy bins", num_outside_ebds); + } + // Return return; } @@ -636,7 +653,7 @@ void ctbin::set_weights(GCTAObservation* obs) // Loop over all pixels in counts cube for (int pixel = 0; pixel < m_counts.npix(); ++pixel) { - + // Skip pixel if it is outside the RoI if (roi.centre().dir().dist_deg(m_dirs[pixel]) > roi.radius()) { continue; @@ -649,7 +666,9 @@ void ctbin::set_weights(GCTAObservation* obs) if (!usage[iebin]) { continue; } + // Signal that bin was filled + #pragma omp critical(ctbin_set_weights) m_weights(pixel, iebin) = 1.0; } // endfor: looped over energy layers of counts cube diff --git a/src/ctbin/ctbin.hpp b/src/ctbin/ctbin.hpp index 99c74f1..21cd9ab 100644 --- a/src/ctbin/ctbin.hpp +++ b/src/ctbin/ctbin.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbin - Event binning tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -102,7 +102,9 @@ protected: GCTAEventCube m_cube; //!< Events cube (for cube() method) double m_ontime; //!< Total ontime double m_livetime; //!< Total livetime - std::vector m_dirs; //!< Cached GSkyDir for each pixel in m_counts + + // Cache members + std::vector m_dirs; //!< Cached GSkyDir for each pixel in m_counts }; -- libgit2 0.21.4