sherpa is hosted by Hepforge, IPPP Durham
close Warning: Can't synchronize with repository "(default)" (/hepforge/svn/sherpa does not appear to be a Subversion repository.). Look in the Trac log for more information.

Ticket #104: ps_threading_1.patch

File ps_threading_1.patch, 3.8 KB (added by Stefan Hoeche, 13 years ago)
  • COMIX/Phasespace/PS_Channel.H

     
    3939    size_t m_s, m_n, m_b, m_e, m_i;
    4040    pthread_mutex_t m_s_mtx, m_t_mtx;
    4141    pthread_cond_t m_s_cnd, m_t_cnd;
     42    PSId_Map *p_psid;
     43    CId_Map *p_cid;
    4244    CDBG_PS_TID(PS_Channel *const psc):
    43       p_psc(psc), m_s(2), m_b(0), m_e(0) {}
     45      p_psc(psc), m_s(2), m_b(0), m_e(0),
     46      p_psid(new PSId_Map()), p_cid(new CId_Map()) {}
     47    ~CDBG_PS_TID() { delete p_psid; delete p_cid; }
    4448  };// end of struct CDBG_PS_TID
    4549
    4650  typedef std::vector<CDBG_PS_TID*> CDBG_PS_TID_Vector;
     
    7680
    7781    STCC_Map m_stccs;
    7882
    79     PSId_Map m_psid;
    80     CId_Map  m_cid;
     83    PSId_Map *p_psid;
     84    CId_Map  *p_cid;
    8185   
    8286#ifdef USING__Threading
    8387    CDBG_PS_TID_Vector m_cts;
    84     pthread_mutex_t    m_psid_mtx, m_cid_mtx, m_vgs_mtx, m_wvgs_mtx;
     88    pthread_mutex_t    m_vgs_mtx, m_wvgs_mtx;
    8589
    8690    static void *TGenerateWeight(void *arg);
     91
     92    CDBG_PS_TID *GetTId() const;
    8793#endif
    8894
    8995    const std::string      &GetPSId(const size_t &id);
  • COMIX/Phasespace/PS_Channel.C

     
    2424
    2525PS_Channel::PS_Channel(const size_t &_nin,const size_t &_nout,
    2626                       ATOOLS::Flavour *_fl,Process_Base *const xs):
    27   p_xs(xs), m_n(_nin+_nout), m_lid(1), m_rid(2), m_nopt(0)
     27  p_xs(xs), m_n(_nin+_nout), m_lid(1), m_rid(2), m_nopt(0),
     28  p_psid(new PSId_Map()), p_cid(new CId_Map())
    2829{
    2930  nin=_nin;
    3031  nout=_nout;
     
    8687        THROW(fatal_error,"Cannot create thread "+ToString(i));
    8788    }
    8889  }
    89   pthread_mutex_init(&m_psid_mtx,NULL);
    90   pthread_mutex_init(&m_cid_mtx,NULL);
    9190  pthread_mutex_init(&m_vgs_mtx,NULL);
    9291  pthread_mutex_init(&m_wvgs_mtx,NULL);
    9392#endif
     
    9897#ifdef USING__Threading
    9998  pthread_mutex_destroy(&m_wvgs_mtx);
    10099  pthread_mutex_destroy(&m_vgs_mtx);
    101   pthread_mutex_destroy(&m_cid_mtx);
    102   pthread_mutex_destroy(&m_psid_mtx);
    103100  for (size_t i(0);i<m_cts.size();++i) {
    104101    CDBG_PS_TID *tid(m_cts[i]);
    105102    tid->m_s=0;
     
    118115#endif
    119116  for (Vegas_Map::const_iterator vit(m_vmap.begin());
    120117       vit!=m_vmap.end();++vit) delete vit->second;
     118  delete p_psid;
     119  delete p_cid;
    121120}
    122121
    123 const std::string &PS_Channel::GetPSId(const size_t &id)
    124 {
    125   PSId_Map::const_iterator iit(m_psid.find(id));
    126   if (iit!=m_psid.end()) return iit->second;
    127122#ifdef USING__Threading
    128   pthread_mutex_lock(&m_psid_mtx);
     123CDBG_PS_TID *PS_Channel::GetTId() const
     124{
     125  pthread_t tid(pthread_self());
     126  for (size_t i(0);i<m_cts.size();++i)
     127    if (pthread_equal(tid,m_cts[i]->m_id)) return m_cts[i];
     128  return NULL;
     129}
    129130#endif
    130   m_psid[id]=PSId(id);
     131
     132const std::string &PS_Channel::GetPSId(const size_t &id)
     133{
     134  PSId_Map *psid(p_psid);
    131135#ifdef USING__Threading
    132   pthread_mutex_unlock(&m_psid_mtx);
     136  CDBG_PS_TID *tid(GetTId());
     137  if (tid) psid=tid->p_psid;
    133138#endif
    134   return m_psid[id];
     139  PSId_Map::const_iterator iit(psid->find(id));
     140  if (iit!=psid->end()) return iit->second;
     141  (*psid)[id]=PSId(id);
     142  return (*psid)[id];
    135143}
    136144
    137145const std::vector<int> &PS_Channel::GetCId(const size_t &id)
    138146{
    139   CId_Map::const_iterator iit(m_cid.find(id));
    140   if (iit!=m_cid.end()) return iit->second;
    141 #ifdef USING__Threading
    142   pthread_mutex_lock(&m_cid_mtx);
    143 #endif
    144   m_cid[id]=ID(id);
     147  CId_Map *cid(p_cid);
    145148#ifdef USING__Threading
    146   pthread_mutex_unlock(&m_cid_mtx);
     149  CDBG_PS_TID *tid(GetTId());
     150  if (tid) cid=tid->p_cid;
    147151#endif
    148   return m_cid[id];
     152  CId_Map::const_iterator iit(cid->find(id));
     153  if (iit!=cid->end()) return iit->second;
     154  (*cid)[id]=ID(id);
     155  return (*cid)[id];
    149156}
    150157
    151158size_t PS_Channel::SId(const size_t &id) const