Changeset 3776 in Sophya for trunk/AddOn/TAcq/brproc.cc


Ignore:
Timestamp:
May 18, 2010, 10:22:10 AM (15 years ago)
Author:
ansari
Message:

Ajout classes / modification pour permettre le calcul des visibilites ave plusieurs objets BRVisibilityCalculator s'executant en parallele, Reza 18/05/2010

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/AddOn/TAcq/brproc.cc

    r3774 r3776  
    3131
    3232/* --Methode-- */
    33 BRVisibilityCalculator::BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean,
    34                                                uint_4 freq1, uint_4 freq2, uint_4 nbfreq, size_t nthr)
    35   : BRBaseProcessor(memgr), paralex_(*this, nthr), nparthr_(nthr), outpath_(outpath), nmean_(nmean),
    36     numfreq1_(freq1), numfreq2_(freq2), nbinfreq_(nbfreq), vpdata_(2*memgr.NbFibres())
     33BRVisibilityCalculator::BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, size_t nthr)
     34  : BRBaseProcessor(memgr), paralex_(*this, nthr), nparthr_(nthr),
     35    outpath_(outpath), nmean_(nmean), nbcalc_(1), calcid_(0), vpdata_(2*memgr.NbFibres())
    3736    // , dtfos_(outpath+"visdt.fits", Fits_Create), visdt_(dtfos_, 1024, true);
    38 
    3937
    40   BRPaquet paq(memgr_.PaqSize());
    41 
    42   vismtx_.SetSize((2*memgr_.NbFibres()+1)*memgr_.NbFibres(), paq.DataSize()/4);
    43   chanum_.SetSize(vismtx_.NRows());
     38  DefineRank(1,0);
     39
     40  uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
     41  chanum_.SetSize(maxnpairs);
    4442  sa_size_t k=0;
    4543  for(size_t i=0; i<2*memgr_.NbFibres(); i++)  vpdata_[i]=NULL;
     
    4947    }
    5048  }
     49  SelectPairs();
     50
    5151  //  visdt_.AddFloatColumn("mfc");
    5252  visdt_.AddDoubleColumn("mfc");
     
    6060  if (nmean_ < 1)  nmean_=1;
    6161
     62  cout << " BRVisibilityCalculator::/Info  nmean=" << nmean_ << endl;
     63
    6264  totnbpaq_=0;
    6365  numfile_=0;
    6466  moyfc_=moytt_=0.;
    6567
    66   jf1_=numfreq1_; jf2_=numfreq2_;
     68  fgallfibok=NULL;
     69  fgcktt_=false;
     70}
     71
     72/* --Methode-- */
     73BRVisibilityCalculator::~BRVisibilityCalculator()
     74{
     75  cout << " BRVisibilityCalculator - Visibility Datatable : " << endl;
     76  cout << visdt_;
     77  string filename;
     78  filename = outpath_+"visdt.ppf";
     79  if (nbcalc_>1) {
     80    char sbuff[32];
     81    sprintf(sbuff,"visdt_%d",(int)calcid_);
     82    filename = outpath_+sbuff;
     83  }
     84  POutPersist po(filename);
     85  po << visdt_;
     86  if (calcid_ == 0) {
     87    POutPersist poc(outpath_+"chanum.ppf");
     88    poc << chanum_;
     89 
     90    if (fgcktt_) {
     91      cout << " BRVisibilityCalculator -  Check TimeTag done: TotNPaqProc= " << totnbpaq_ << endl;
     92      for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
     93        cout << " BRTTCheck-Fiber[" << fib << "] NBadTT=" << vbadtt_[fib] << " NDiffTT>5="
     94             << vndiff5tt_[fib] << "  NotSameTT=" << vnsamett_[fib] << endl;
     95      }
     96      POutPersist pott(outpath_+"ttfcmtx.ppf");
     97      pott << PPFNameTag("FC") << fcmtx_;
     98      pott << PPFNameTag("TT") << ttmtx_;     
     99    }
     100  }
     101}
     102
     103/* --Methode-- */
     104void BRVisibilityCalculator::DefineRank(uint_4 nbc, uint_4 cid)
     105{
     106  if ((nbc>4)||(cid>=nbc))
     107    throw ParmError("BRVisibilityCalculator::DefineRank() NbCalc > 4 !");
     108  nbcalc_=nbc;
     109  calcid_=cid;
     110  if (nbcalc_>1) {
     111    uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
     112    uint_4 npairs=maxnpairs/nbcalc_;
     113    if (calcid_==(nbcalc_-1))
     114      SelectPairs(calcid_*npairs, maxnpairs-calcid_*npairs);
     115    else
     116      SelectPairs(calcid_*npairs, npairs);
     117    MemZaction mmzas[4]={MemZA_ProcA,MemZA_ProcB,MemZA_ProcC,MemZA_ProcD};
     118    SetMemZAction(mmzas[calcid_]);
     119  }
     120  return ;
     121}
     122
     123/* --Methode-- */
     124uint_4 BRVisibilityCalculator::SelectPairs(uint_4 pair1, uint_4 nbpairs)
     125{
     126  BRPaquet paq(memgr_.PaqSize());
     127  uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
     128
     129  if (pair1 >= maxnpairs)  pair1=maxnpairs-1;
     130  if (nbpairs > maxnpairs-pair1)  nbpairs=maxnpairs-pair1;
     131  pairst_=pair1;
     132  nbpairs_=nbpairs;
     133  vismtx_.SetSize(nbpairs_, paq.DataSize()/4);
     134  return nbpairs_;
     135}
     136
     137/* --Methode-- */
     138int BRVisibilityCalculator::SelectFreqBinning(uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
     139{
     140  jf1_=freq1; jf2_=freq2;
    67141  if ((jf1_<1)||(jf1_>=vismtx_.NCols()))  jf1_=1;
    68142  if ((jf2_<1)||(jf2_>=vismtx_.NCols())||(jf2_<jf1_))  jf2_=vismtx_.NCols()-1;
    69   if (nbinfreq_<1) nbinfreq_=1;
    70   djf_=(jf2_-jf1_)/nbinfreq_;
     143  if (nbfreq<1) nbfreq=1;
     144  djf_=(jf2_-jf1_)/nbfreq;
    71145  if (djf_<1) djf_=0;
    72   xnt_ = new double[vismtx_.NRows()+20];
    73   for(int kk=0; kk<vismtx_.NRows(); kk++)  xnt_[kk]=0.;
    74 
    75   cout << " BRVisibilityCalculator/Info NMean= " << nmean_ << " JF1=" << jf1_
     146  cout << " BRVisibilityCalculator::SelectFreqBinning/Info  JF1=" << jf1_
    76147       << " JF2=" << jf2_ << " DJF=" << djf_ << endl;
    77148
    78   fgallfibok=NULL;
    79   fgcktt_=false;
    80 }
    81 
    82 /* --Methode-- */
    83 BRVisibilityCalculator::~BRVisibilityCalculator()
    84 {
    85   cout << " BRVisibilityCalculator - Visibility Datatable : " << endl;
    86   cout << visdt_;
    87   POutPersist po(outpath_+"visdt.ppf");
    88   po << visdt_;
    89   POutPersist poc(outpath_+"chanum.ppf");
    90   poc << chanum_;
    91 
    92   if (fgcktt_) {
    93     cout << " BRVisibilityCalculator -  Check TimeTag done: TotNPaqProc= " << totnbpaq_ << endl;
    94     for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
    95       cout << " BRTTCheck-Fiber[" << fib << "] NBadTT=" << vbadtt_[fib] << " NDiffTT>5="
    96            << vndiff5tt_[fib] << "  NotSameTT=" << vnsamett_[fib] << endl;
    97     }
    98     POutPersist pott(outpath_+"ttfcmtx.ppf");
    99     pott << PPFNameTag("FC") << fcmtx_;
    100     pott << PPFNameTag("TT") << ttmtx_;     
    101   }
    102   delete[] xnt_;
    103 }
     149}
     150
     151
     152/* --Methode-- */
     153int BRVisibilityCalculator::ActivateTimeTagCheck(uint_8 maxnpaq)
     154{
     155  mindeltatt_=memgr_.PaqSize()/2;
     156  if (mindeltatt_<1) mindeltatt_=1;
     157  fcmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
     158  ttmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
     159  vlasttt_.resize(memgr_.NbFibres(), 0);
     160  vbadtt_.resize(memgr_.NbFibres(), 0);
     161  vnsamett_.resize(memgr_.NbFibres(), 0);
     162  vndiff5tt_.resize(memgr_.NbFibres(), 0);
     163
     164  fgcktt_=true;
     165  cout << " BRVisibilityCalculator::ActivateTimeTagCheck() - TT/Fc matrix NCols=" << maxnpaq
     166       << " MinDeltaTT=" << mindeltatt_ << endl;
     167
     168  return 0;
     169}
     170
    104171
    105172/* --Methode-- */
    106173void BRVisibilityCalculator::run()
    107174{
     175  cout << " BRVisibilityCalculator[" << calcid_ << "/" << nbcalc_
     176       << "]::run() - Starting " << " NFibers=" << memgr_.NbFibres()
     177       << " NChan=" << 2*memgr_.NbFibres() << " NPairs=" << nbpairs_ << " First:" << pairst_ << endl;   
     178 
    108179  if (nparthr_ < 2)  return BRBaseProcessor::run();
    109180  // Execution multithread parallele
     
    111182  int rc=0;
    112183  try {
    113     cout << " BRVisibilityCalculator::run() - Starting " << " NFibers=" << memgr_.NbFibres()
    114          << " NChan=" << 2*memgr_.NbFibres() << endl;   
    115184    if ((nmean_%memgr_.NbPaquets())!=0) {
    116185      uint_4 mnmean = (nmean_/memgr_.NbPaquets()+1)*memgr_.NbPaquets();
     
    156225         
    157226          // ATTENTION : Matrice visibilites non moyennee
    158           char nfile[32];
    159           sprintf(nfile,"vismtx%d.ppf",numfile_);
     227          char nfile[48];
     228          if (nbcalc_==1)
     229            sprintf(nfile,"vismtx%d.ppf",numfile_);
     230          else
     231            sprintf(nfile,"vismtx_%d_%d.ppf",(int)calcid_,numfile_);
    160232          string flnm=outpath_+nfile;
    161233          POutPersist po(flnm);
     
    187259          moyfc_ += curfc_[0];
    188260          moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
    189           if (fgcktt_)  CheckTimeTag();
     261          if ((fgcktt_)&&(calcid_==0))  CheckTimeTag();
    190262          totnbpaq_++;
    191263        }
     
    220292
    221293/* --Methode-- */
    222 int BRVisibilityCalculator::ActivateTimeTagCheck(uint_8 maxnpaq)
    223 {
    224   mindeltatt_=memgr_.PaqSize()/2;
    225   if (mindeltatt_<1) mindeltatt_=1;
    226   fcmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
    227   ttmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
    228   vlasttt_.resize(memgr_.NbFibres(), 0);
    229   vbadtt_.resize(memgr_.NbFibres(), 0);
    230   vnsamett_.resize(memgr_.NbFibres(), 0);
    231   vndiff5tt_.resize(memgr_.NbFibres(), 0);
    232 
    233   fgcktt_=true;
    234   cout << " BRVisibilityCalculator::ActivateTimeTagCheck() - TT/Fc matrix NCols=" << maxnpaq
    235        << " MinDeltaTT=" << mindeltatt_ << endl;
    236 
    237   return 0;
    238 }
    239 
    240 /* --Methode-- */
    241294int BRVisibilityCalculator::Process()
    242295{
     
    256309
    257310      // ATTENTION : Matrice visibilites non moyennee
    258       char nfile[32];
    259       sprintf(nfile,"vismtx%d.ppf",numfile_);
     311      char nfile[48];
     312      if (nbcalc_==1)
     313        sprintf(nfile,"vismtx%d.ppf",numfile_);
     314      else
     315        sprintf(nfile,"vismtx_%d_%d.ppf",(int)calcid_,numfile_);
    260316      string flnm=outpath_+nfile;
    261317      POutPersist po(flnm);
     
    273329  for(size_t i=0; i<vpdata_.size(); i++) {
    274330    for(size_t j=i; j<vpdata_.size(); j++) {
     331      size_t kpair=i*vpdata_.size()+j;
     332      if (kpair<pairst_)  continue;
     333      if (kpair>=(pairst_+nbpairs_))  break;
    275334      TVector< complex<r_4> > vis = vismtx_.Row(k);   k++;
    276335      for(sa_size_t f=1; f<vis.Size(); f++) {
     
    283342  moyfc_ += curfc_[0];
    284343  moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
    285   if (fgcktt_)  CheckTimeTag();
     344  if ((fgcktt_)&&(calcid_==0))  CheckTimeTag();
    286345  totnbpaq_++;
    287346  return 0;
     
    312371    for(size_t i=0; i<vpdata_.size(); i++) {
    313372      for(size_t j=i; j<vpdata_.size(); j++) {
     373        size_t kpair=i*vpdata_.size()+j;
     374        if (kpair<pairst_)  continue;
     375        if (kpair>=(pairst_+nbpairs_))  break;
    314376        TVector< complex<r_4> > vis = vismtx_.Row(k);   k++;
    315377        for(sa_size_t f=fdeb; f<ffin; f++) {
     
    328390int BRVisibilityCalculator::FillVisibTable(double fcm, double ttm)
    329391{
    330   xnt_[0]=fcm;  xnt_[1]=ttm/1.25e8;
     392  double xnt[10];
     393  xnt[0]=fcm;  xnt[1]=ttm/1.25e8;
    331394
    332395  if (djf_<2) {
    333396    for(sa_size_t rv=0; rv<vismtx_.NRows(); rv++) {
    334397      for(sa_size_t jf=jf1_; jf<jf2_; jf++) {
    335         xnt_[2]=jf;
    336         xnt_[3]=chanum_(rv);
    337         xnt_[4]=vismtx_(rv,jf).real()/(r_4)(nmean_);
    338         xnt_[5]=vismtx_(rv,jf).imag()/(r_4)(nmean_);
    339         visdt_.AddRow(xnt_);
     398        xnt[2]=jf;
     399        xnt[3]=chanum_(rv+pairst_);
     400        xnt[4]=vismtx_(rv,jf).real()/(r_4)(nmean_);
     401        xnt[5]=vismtx_(rv,jf).imag()/(r_4)(nmean_);
     402        visdt_.AddRow(xnt);
    340403      }
    341404    }
     
    352415          moyimag+=vismtx_(rv,jjf).imag();
    353416        }
    354         xnt_[2]=jf+djf_/2;
    355         xnt_[3]=chanum_(rv);
    356         xnt_[4]=moyreal/(r_4)(nmean_*djf_);
    357         xnt_[5]=moyimag/(r_4)(nmean_*djf_);
    358         visdt_.AddRow(xnt_);
     417        xnt[2]=jf+djf_/2;
     418        xnt[3]=chanum_(rv+pairst_);
     419        xnt[4]=moyreal/(r_4)(nmean_*djf_);
     420        xnt[5]=moyimag/(r_4)(nmean_*djf_);
     421        visdt_.AddRow(xnt);
    359422      }
    360423    }
     
    396459  }
    397460  return 0;
     461}
     462
     463//-------------------------------------------------------------------------------
     464// Classe Groupe (ensemble) de Calculateur de Visibilites, tourant en parallele
     465//-------------------------------------------------------------------------------
     466
     467/* --Methode-- */
     468BRVisCalcGroup::BRVisCalcGroup(size_t nbcalc, RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, size_t nthr)
     469{
     470  if ((nbcalc<1)||(nbcalc>4))
     471    throw ParmError("BRVisCalcGroup::BRVisCalcGroup NbCalc > 4 !");
     472  for(size_t i=0; i<nbcalc; i++) {
     473    BRVisibilityCalculator * viscp=new BRVisibilityCalculator(memgr, outpath, nmean, nthr);
     474    viscp->DefineRank(nbcalc, i);
     475    viscalcp_.push_back(viscp);
     476  }
     477}
     478/* --Methode-- */
     479BRVisCalcGroup::~BRVisCalcGroup()
     480{
     481  for(size_t i=0; i<viscalcp_.size(); i++)
     482    delete viscalcp_[i];
     483}
     484/* --Methode-- */
     485int BRVisCalcGroup::SelectFreqBinning(uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
     486{
     487  int rc=0;
     488  for(size_t i=0; i<viscalcp_.size(); i++)
     489    rc=viscalcp_[i]->SelectFreqBinning(freq1, freq2, nbfreq);
     490  return rc;
     491}
     492/* --Methode-- */
     493void BRVisCalcGroup::start()
     494{
     495  for(size_t i=0; i<viscalcp_.size(); i++)
     496    viscalcp_[i]->start();
     497}
     498/* --Methode-- */
     499void BRVisCalcGroup::join()
     500{
     501  for(size_t i=0; i<viscalcp_.size(); i++)
     502    viscalcp_[i]->join();
    398503}
    399504
Note: See TracChangeset for help on using the changeset viewer.