Ticket #104: ps_threading_1.patch
File ps_threading_1.patch, 3.8 KB (added by , 14 years ago) |
---|
-
COMIX/Phasespace/PS_Channel.H
39 39 size_t m_s, m_n, m_b, m_e, m_i; 40 40 pthread_mutex_t m_s_mtx, m_t_mtx; 41 41 pthread_cond_t m_s_cnd, m_t_cnd; 42 PSId_Map *p_psid; 43 CId_Map *p_cid; 42 44 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; } 44 48 };// end of struct CDBG_PS_TID 45 49 46 50 typedef std::vector<CDBG_PS_TID*> CDBG_PS_TID_Vector; … … 76 80 77 81 STCC_Map m_stccs; 78 82 79 PSId_Map m_psid;80 CId_Map m_cid;83 PSId_Map *p_psid; 84 CId_Map *p_cid; 81 85 82 86 #ifdef USING__Threading 83 87 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; 85 89 86 90 static void *TGenerateWeight(void *arg); 91 92 CDBG_PS_TID *GetTId() const; 87 93 #endif 88 94 89 95 const std::string &GetPSId(const size_t &id); -
COMIX/Phasespace/PS_Channel.C
24 24 25 25 PS_Channel::PS_Channel(const size_t &_nin,const size_t &_nout, 26 26 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()) 28 29 { 29 30 nin=_nin; 30 31 nout=_nout; … … 86 87 THROW(fatal_error,"Cannot create thread "+ToString(i)); 87 88 } 88 89 } 89 pthread_mutex_init(&m_psid_mtx,NULL);90 pthread_mutex_init(&m_cid_mtx,NULL);91 90 pthread_mutex_init(&m_vgs_mtx,NULL); 92 91 pthread_mutex_init(&m_wvgs_mtx,NULL); 93 92 #endif … … 98 97 #ifdef USING__Threading 99 98 pthread_mutex_destroy(&m_wvgs_mtx); 100 99 pthread_mutex_destroy(&m_vgs_mtx); 101 pthread_mutex_destroy(&m_cid_mtx);102 pthread_mutex_destroy(&m_psid_mtx);103 100 for (size_t i(0);i<m_cts.size();++i) { 104 101 CDBG_PS_TID *tid(m_cts[i]); 105 102 tid->m_s=0; … … 118 115 #endif 119 116 for (Vegas_Map::const_iterator vit(m_vmap.begin()); 120 117 vit!=m_vmap.end();++vit) delete vit->second; 118 delete p_psid; 119 delete p_cid; 121 120 } 122 121 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;127 122 #ifdef USING__Threading 128 pthread_mutex_lock(&m_psid_mtx); 123 CDBG_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 } 129 130 #endif 130 m_psid[id]=PSId(id); 131 132 const std::string &PS_Channel::GetPSId(const size_t &id) 133 { 134 PSId_Map *psid(p_psid); 131 135 #ifdef USING__Threading 132 pthread_mutex_unlock(&m_psid_mtx); 136 CDBG_PS_TID *tid(GetTId()); 137 if (tid) psid=tid->p_psid; 133 138 #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]; 135 143 } 136 144 137 145 const std::vector<int> &PS_Channel::GetCId(const size_t &id) 138 146 { 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); 145 148 #ifdef USING__Threading 146 pthread_mutex_unlock(&m_cid_mtx); 149 CDBG_PS_TID *tid(GetTId()); 150 if (tid) cid=tid->p_cid; 147 151 #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]; 149 156 } 150 157 151 158 size_t PS_Channel::SId(const size_t &id) const