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 #75: cps_threading_1.patch

File cps_threading_1.patch, 5.5 KB (added by Stefan Hoeche, 14 years ago)
  • COMIX/Phasespace/PS_Channel.C

     
    193193(const Current_Base *cur,const size_t &id)
    194194{
    195195  if (cur!=NULL) {
    196     CVegas_Map::const_iterator vit(m_pcmap.find(cur));
    197     if (vit!=m_pcmap.end()) return vit->second;
    198196#ifdef USING__Threading
    199197    pthread_mutex_lock(&m_vgs_mtx);
    200198#endif
    201     m_pcmap[cur]=GetVegas("P_"+cur->PSInfo());
     199    Vegas *vgs(NULL);
     200    CVegas_Map::const_iterator vit(m_pcmap.find(cur));
     201    if (vit!=m_pcmap.end()) vgs=vit->second;
     202    else vgs=m_pcmap[cur]=GetVegas("P_"+cur->PSInfo());
    202203#ifdef USING__Threading
    203204    pthread_mutex_unlock(&m_vgs_mtx);
    204205#endif
    205     return m_pcmap[cur];
     206    return vgs;
    206207  }
    207   IVegas_Map::const_iterator vit(m_pimap.find(id));
    208   if (vit!=m_pimap.end()) return vit->second;
    209208#ifdef USING__Threading
    210209  pthread_mutex_lock(&m_vgs_mtx);
    211210#endif
    212   m_pimap[id]=GetVegas("P_"+GetPSId(id));
     211  Vegas *vgs(NULL);
     212  IVegas_Map::const_iterator vit(m_pimap.find(id));
     213  if (vit!=m_pimap.end()) vgs=vit->second;
     214  else vgs=m_pimap[id]=GetVegas("P_"+GetPSId(id));
    213215#ifdef USING__Threading
    214216  pthread_mutex_unlock(&m_vgs_mtx);
    215217#endif
    216   return m_pimap[id];
     218  return vgs;
    217219}
    218220
    219221PHASIC::Vegas *PS_Channel::GetCVegas(const size_t &id,const size_t &n)
    220222{
    221   IVegas_Map::const_iterator vit(m_cimap.find(id));
    222   if (vit!=m_cimap.end()) return vit->second;
    223223#ifdef USING__Threading
    224224  pthread_mutex_lock(&m_vgs_mtx);
    225225#endif
    226   m_cimap[id]=GetVegas("C_"+GetPSId(id)+"_"+ToString(n),n);
     226  Vegas *vgs(NULL);
     227  IVegas_Map::const_iterator vit(m_cimap.find(id));
     228  if (vit!=m_cimap.end()) vgs=vit->second;
     229  else vgs=m_cimap[id]=GetVegas("C_"+GetPSId(id)+"_"+ToString(n),n);
    227230#ifdef USING__Threading
    228231  pthread_mutex_unlock(&m_vgs_mtx);
    229232#endif
    230   return m_cimap[id];
     233  return vgs;
    231234}
    232235
    233236PHASIC::Vegas *PS_Channel::GetSVegas
    234237(const size_t &id,const Current_Base *cur)
    235238{
     239#ifdef USING__Threading
     240  pthread_mutex_lock(&m_vgs_mtx);
     241#endif
     242  Vegas *vgs(NULL);
    236243  ICVegas_Map::const_iterator vit(m_sicmap.find(id));
    237244  if (vit!=m_sicmap.end()) {
    238245    CVegas_Map::const_iterator it(vit->second.find(cur));
    239     if (it!=vit->second.end()) return it->second;
     246    if (it!=vit->second.end()) vgs=it->second;
    240247  }
    241 #ifdef USING__Threading
    242   pthread_mutex_lock(&m_vgs_mtx);
    243 #endif
    244   m_sicmap[id][cur]=GetVegas("S_"+GetPSId(id)+"_"+cur->PSInfo());
     248  if (vgs==NULL) vgs=m_sicmap[id][cur]=
     249    GetVegas("S_"+GetPSId(id)+"_"+cur->PSInfo());
    245250#ifdef USING__Threading
    246251  pthread_mutex_unlock(&m_vgs_mtx);
    247252#endif
    248   return m_sicmap[id][cur];
     253  return vgs;
    249254}
    250255
    251256PHASIC::Vegas *PS_Channel::GetTVegas
    252257(const size_t &id,const Current_Base *cur)
    253258{
     259#ifdef USING__Threading
     260  pthread_mutex_lock(&m_vgs_mtx);
     261#endif
     262  Vegas *vgs(NULL);
    254263  ICVegas_Map::const_iterator vit(m_ticmap.find(id));
    255264  if (vit!=m_ticmap.end()) {
    256265    CVegas_Map::const_iterator it(vit->second.find(cur));
    257     if (it!=vit->second.end()) return it->second;
     266    if (it!=vit->second.end()) vgs=it->second;
    258267  }
    259 #ifdef USING__Threading
    260   pthread_mutex_lock(&m_vgs_mtx);
    261 #endif
    262   m_ticmap[id][cur]=GetVegas("T_"+GetPSId(id)+"_"+cur->PSInfo());
     268  if (vgs==NULL) vgs=m_ticmap[id][cur]=
     269    GetVegas("T_"+GetPSId(id)+"_"+cur->PSInfo());
    263270#ifdef USING__Threading
    264271  pthread_mutex_unlock(&m_vgs_mtx);
    265272#endif
    266   return m_ticmap[id][cur];
     273  return vgs;
    267274}
    268275
    269276bool PS_Channel::Zero(Vertex_Base *const vtx) const
  • PHASIC++/Channels/Vegas.C

     
    167167  return p_x;
    168168}
    169169
    170 double Vegas::GenerateWeight(const double* xy)
     170double Vegas::GenerateWeight(const double* xy) const
    171171{
    172172  if (m_on==0) return 1.;
    173   m_weight = m_nc;
     173  double weight = m_nc;
    174174  for (int i=0;i<m_dim;i++) {
    175175    size_t l(0), r(m_nd-1), c((l+r)/2);
    176176    double a(p_xi[i][c]);
     
    184184    int k(r);
    185185    p_ia[i] = k;
    186186    if (k==0) {
    187       m_weight *= p_xi[i][k];
     187      weight *= p_xi[i][k];
    188188    }
    189189    else {
    190       m_weight *= p_xi[i][k]-p_xi[i][k-1];
     190      weight *= p_xi[i][k]-p_xi[i][k-1];
    191191    }
    192192  }
    193   return m_weight;
     193  return weight;
    194194}
    195195
    196 double Vegas::GenerateBinWeight(int* xy)
     196double Vegas::GenerateBinWeight(int* xy) const
    197197{
    198198  if (m_on==0) return 1.;
    199   m_weight = m_nc;
     199  double weight = m_nc;
    200200  for (int i=0;i<m_dim;i++) {
    201201    int k(xy[i]);
    202202    p_ia[i] = k;
    203203    if (k==0) {
    204       m_weight *= p_xi[i][k];
     204      weight *= p_xi[i][k];
    205205    }
    206206    else {
    207       m_weight *= p_xi[i][k]-p_xi[i][k-1];
     207      weight *= p_xi[i][k]-p_xi[i][k-1];
    208208    }
    209209  }
    210   return m_weight;
     210  return weight;
    211211}
    212212
    213213double *Vegas::GetBinsMean(int *xy) const
  • PHASIC++/Channels/Vegas.H

     
    1212    int m_nd;
    1313    unsigned long m_nevt,m_nopt,m_snevt,m_cevt;
    1414    double m_alpha;
    15     double m_weight,m_sum,m_sum2;
     15    double m_sum,m_sum2;
    1616    double m_nc;
    1717    double **p_xi;
    1818    double *p_x,*p_xin,*p_r,*p_cx,*p_bm;
     
    2828    Vegas(int dim,int ndx,const std::string &,int=1);
    2929    ~Vegas();
    3030    double* GeneratePoint(const double * _ran);
    31     double GenerateWeight(const double *);
    32     double GenerateBinWeight(int *);
     31    double GenerateWeight(const double *) const;
     32    double GenerateBinWeight(int *) const;
    3333    void AddPoint(double,double *);
    3434    void AddBinPoint(double,int *);
    3535