Commit 113f32e9485bd7a9cdba005747e37f2d025a483a

Authored by Jürgen Knödlseder
1 parent cf531cca

Correct for thread safety in ctobssim.

ctobssim was not fully thread save as the models were shared among the threads which led to concurrent memory access when evaluating the Monte Carlo cache. The models are now copied within the parallel section, avoiding concurrent memory access (#1258).
ChangeLog
1 -2014-06-26 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> 1 +2014-07-09 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
2 2
3 * Version 0.8.0 released 3 * Version 0.8.0 released
4 ======================== 4 ========================
5 5
6 Support energy dispersion in ctobssim, ctlike and ctmodel 6 Support energy dispersion in ctobssim, ctlike and ctmodel
  7 + Correct ctobssim for thread safety
7 Enhance documentation 8 Enhance documentation
8 9
9 10
@@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-08-00 @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-08-00
2 2
3 Author(s) : Juergen Knoedlseder 3 Author(s) : Juergen Knoedlseder
4 4
5 -26 June 2014 5 +9 July 2014
6 6
7 7
8 1. Introduction 8 1. Introduction
@@ -23,7 +23,10 @@ None @@ -23,7 +23,10 @@ None
23 23
24 4. ctobssim - CTA observation simulation 24 4. ctobssim - CTA observation simulation
25 ---------------------------------------- 25 ----------------------------------------
26 -None 26 +ctobssim was not fully thread save as the models were shared among the
  27 +threads which led to concurrent memory access when evaluating the Monte
  28 +Carlo cache. The models are now copied within the parallel section,
  29 +avoiding concurrent memory access (#1258).
27 30
28 ctobssim now also supports the handling of energy dispersion. Energy 31 ctobssim now also supports the handling of energy dispersion. Energy
29 dispersion can be switched on or off using the hidden edisp parameter. 32 dispersion can be switched on or off using the hidden edisp parameter.
src/ctobssim/ctobssim.cpp
@@ -305,6 +305,9 @@ void ctobssim::run(void) @@ -305,6 +305,9 @@ void ctobssim::run(void)
305 wrklog.cout(true); 305 wrklog.cout(true);
306 } 306 }
307 307
  308 + // Allocate and initialize copies for multi-threading
  309 + GModels models(m_obs.models());
  310 +
308 // Copy configuration from application logger to thread logger 311 // Copy configuration from application logger to thread logger
309 wrklog.date(log.date()); 312 wrklog.date(log.date());
310 wrklog.name(log.name()); 313 wrklog.name(log.name());
@@ -340,10 +343,10 @@ void ctobssim::run(void) @@ -340,10 +343,10 @@ void ctobssim::run(void)
340 int events_before = obs->events()->size(); 343 int events_before = obs->events()->size();
341 344
342 // Simulate source events 345 // Simulate source events
343 - simulate_source(obs, m_obs.models(), m_rans[i], &wrklog); 346 + simulate_source(obs, models, m_rans[i], &wrklog);
344 347
345 // Simulate source events 348 // Simulate source events
346 - simulate_background(obs, m_obs.models(), m_rans[i], &wrklog); 349 + simulate_background(obs, models, m_rans[i], &wrklog);
347 350
348 // Dump simulation results 351 // Dump simulation results
349 if (logNormal()) { 352 if (logNormal()) {