[3872] | 1 | //----------------------------------------------------------------
|
---|
| 2 | // Projet BAORadio - (C) LAL/IRFU 2008-2010
|
---|
| 3 | // Classes de threads de calcul de visibilites pour BAORadio
|
---|
| 4 | //----------------------------------------------------------------
|
---|
| 5 |
|
---|
| 6 | #include <stdlib.h>
|
---|
| 7 | #include <string.h>
|
---|
| 8 | #include <unistd.h>
|
---|
| 9 | #include <fstream>
|
---|
| 10 | #include <signal.h>
|
---|
| 11 |
|
---|
| 12 | #include "pexceptions.h"
|
---|
| 13 | #include "fioarr.h"
|
---|
| 14 | #include "matharr.h"
|
---|
| 15 | #include "timestamp.h"
|
---|
| 16 | #include "ctimer.h"
|
---|
| 17 |
|
---|
| 18 | #include "brviscalc.h"
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | //---------------------------------------------------------------------
|
---|
| 22 | // Classe de traitement - calcul de visibilite pour n fibres
|
---|
| 23 | //---------------------------------------------------------------------
|
---|
| 24 |
|
---|
| 25 | /* --Methode-- */
|
---|
| 26 | BRVisibilityCalculator::BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, size_t nthr)
|
---|
| 27 | : BRBaseProcessor(memgr), paralex_(*this, nthr), nparthr_(nthr),
|
---|
| 28 | outpath_(outpath), nmean_(nmean), nbcalc_(1), calcid_(0), vpdata_(2*memgr.NbFibres())
|
---|
| 29 | // , dtfos_(outpath+"visdt.fits", Fits_Create), visdt_(dtfos_, 1024, true);
|
---|
| 30 | {
|
---|
| 31 | DefineRank(1,0);
|
---|
| 32 |
|
---|
| 33 | uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
|
---|
[3909] | 34 | chanids_.SetSize(2*memgr_.NbFibres());
|
---|
| 35 | chanpairnumall_.SetSize(maxnpairs);
|
---|
| 36 | chanpairsall_.SetSize(maxnpairs,2);
|
---|
| 37 | for(size_t i=0; i<2*memgr_.NbFibres(); i++) vpdata_[i]=NULL;
|
---|
[3872] | 38 | SelectPairs();
|
---|
| 39 |
|
---|
| 40 | // visdt_.AddFloatColumn("mfc");
|
---|
| 41 | visdt_.AddDoubleColumn("mfc");
|
---|
| 42 | visdt_.AddDoubleColumn("mtt");
|
---|
| 43 | visdt_.AddIntegerColumn("jfreq");
|
---|
| 44 | visdt_.AddIntegerColumn("numch");
|
---|
| 45 | visdt_.AddFloatColumn("vre");
|
---|
| 46 | visdt_.AddFloatColumn("vim");
|
---|
[3920] | 47 | ActivateVisDTable();
|
---|
[3872] | 48 |
|
---|
| 49 | if (nmean_ < 1) nmean_=memgr_.NbPaquets();
|
---|
| 50 | if (nmean_ < 1) nmean_=1;
|
---|
| 51 |
|
---|
| 52 | cout << " BRVisibilityCalculator::/Info nmean=" << nmean_ << endl;
|
---|
| 53 |
|
---|
| 54 | totnbpaq_=0;
|
---|
| 55 | numfile_=0;
|
---|
| 56 | nb_flop_=0.;
|
---|
| 57 | moyfc_=moytt_=0.;
|
---|
| 58 |
|
---|
| 59 | fgallfibok=NULL;
|
---|
| 60 | fgcktt_=false;
|
---|
| 61 | setNameId("viscalc", 0);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /* --Methode-- */
|
---|
| 65 | BRVisibilityCalculator::~BRVisibilityCalculator()
|
---|
| 66 | {
|
---|
[3876] | 67 | if (totnbpaq_<1) return;
|
---|
[3920] | 68 | if (fgvisdt_) {
|
---|
| 69 | cout << " ~BRVisibilityCalculator - Visibility Datatable : " << endl;
|
---|
| 70 | cout << visdt_;
|
---|
[3876] | 71 |
|
---|
[3920] | 72 | string filename;
|
---|
| 73 | filename = outpath_+"visdt.ppf";
|
---|
| 74 | if (nbcalc_>1) {
|
---|
| 75 | char sbuff[32];
|
---|
| 76 | sprintf(sbuff,"visdt_%d.ppf",(int)calcid_);
|
---|
| 77 | filename = outpath_+sbuff;
|
---|
| 78 | }
|
---|
| 79 | POutPersist po(filename);
|
---|
| 80 | po << visdt_;
|
---|
[3872] | 81 | }
|
---|
[3920] | 82 | if (calcid_ == 0) {
|
---|
[3872] | 83 | if (fgcktt_) {
|
---|
| 84 | cout << " BRVisibilityCalculator - Check TimeTag done: TotNPaqProc= " << totnbpaq_ << endl;
|
---|
| 85 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
| 86 | cout << " BRTTCheck-Fiber[" << fib << "] NBadTT=" << vbadtt_[fib] << " NDiffTT>5="
|
---|
| 87 | << vndiff5tt_[fib] << " NotSameTT=" << vnsamett_[fib] << endl;
|
---|
| 88 | }
|
---|
| 89 | POutPersist pott(outpath_+"ttfcmtx.ppf");
|
---|
| 90 | pott << PPFNameTag("FC") << fcmtx_;
|
---|
| 91 | pott << PPFNameTag("TT") << ttmtx_;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /* --Methode-- */
|
---|
[3915] | 97 | void BRVisibilityCalculator::DefineRank(uint_4 nbc, uint_4 cid, uint_4 pair1, uint_4 nbpairs, bool fgpimp)
|
---|
[3872] | 98 | {
|
---|
| 99 | if ((nbc>6)||(cid>=nbc))
|
---|
| 100 | throw ParmError("BRVisibilityCalculator::DefineRank() NbCalc > 6 !");
|
---|
[3915] | 101 | uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
|
---|
| 102 | if ((pair1>=maxnpairs)||(nbpairs<1))
|
---|
| 103 | throw ParmError("BRVisibilityCalculator::DefineRank() (pair1>=maxnpairs)||(nbpairs<1) !");
|
---|
| 104 | maxnpairs-=pair1;
|
---|
| 105 | if (maxnpairs>nbpairs) maxnpairs=nbpairs;
|
---|
| 106 |
|
---|
[3872] | 107 | nbcalc_=nbc;
|
---|
| 108 | calcid_=cid;
|
---|
| 109 | if (nbcalc_>1) {
|
---|
[3915] | 110 | uint_4 npairspth=maxnpairs/nbcalc_; // nb de paires par thread
|
---|
[3872] | 111 | if (calcid_==(nbcalc_-1))
|
---|
[3915] | 112 | SelectPairs(calcid_*npairspth+pair1, maxnpairs-calcid_*npairspth, fgpimp);
|
---|
[3872] | 113 | else
|
---|
[3915] | 114 | SelectPairs(calcid_*npairspth+pair1, npairspth, fgpimp);
|
---|
[3872] | 115 | MemZaction mmzas[6]={MemZA_ProcA,MemZA_ProcB,MemZA_ProcC,MemZA_ProcD,MemZA_ProcE,MemZA_ProcF};
|
---|
| 116 | SetMemZAction(mmzas[calcid_]);
|
---|
| 117 | setNameId("viscalc_grp", calcid_);
|
---|
| 118 | }
|
---|
[3915] | 119 | else SelectPairs(pair1,maxnpairs, fgpimp);
|
---|
[3872] | 120 | return ;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /* --Methode-- */
|
---|
[3915] | 124 | uint_4 BRVisibilityCalculator::SelectPairs(uint_4 pair1, uint_4 nbpairs, bool fgpimp)
|
---|
[3872] | 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;
|
---|
[3915] | 131 |
|
---|
[3872] | 132 | pairst_=pair1;
|
---|
| 133 | nbpairs_=nbpairs;
|
---|
[3915] | 134 | fgpimp_=fgpimp;
|
---|
[3909] | 135 |
|
---|
[3915] | 136 | uint_4 nbvisicomp=0;
|
---|
| 137 | sa_size_t kpair=0;
|
---|
| 138 | for(size_t i=0; i<vpdata_.size(); i++) {
|
---|
| 139 | for(size_t j=i; j<vpdata_.size(); j++) {
|
---|
| 140 | kpair++;
|
---|
| 141 | if (kpair<(pairst_+1)) continue;
|
---|
| 142 | if (kpair>=(pairst_+nbpairs_+1)) break;
|
---|
| 143 | if (fgpimp_&&(i!=j)&&((i+j)%2==0)) continue; // calcul des visib avec numero pair-impair + autocorrel
|
---|
| 144 | nbvisicomp++;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
[3909] | 147 |
|
---|
[3915] | 148 | vismtx_.SetSize(nbvisicomp, paq.DataSize()/4);
|
---|
| 149 |
|
---|
| 150 | chanpairnum_.SetSize(nbvisicomp);
|
---|
| 151 | chanpairs_.SetSize(nbvisicomp,2);
|
---|
| 152 |
|
---|
| 153 | return nbvisicomp;
|
---|
[3872] | 154 | }
|
---|
| 155 |
|
---|
| 156 | /* --Methode-- */
|
---|
| 157 | int BRVisibilityCalculator::SelectFreqBinning(uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
|
---|
| 158 | {
|
---|
| 159 | jf1_=freq1; jf2_=freq2;
|
---|
| 160 | if ((jf1_<1)||(jf1_>=vismtx_.NCols())) jf1_=1;
|
---|
| 161 | if ((jf2_<1)||(jf2_>=vismtx_.NCols())||(jf2_<jf1_)) jf2_=vismtx_.NCols()-1;
|
---|
[3876] | 162 | if (nbfreq<1) nbfreq=(jf2_-jf1_);
|
---|
[3872] | 163 | djf_=(jf2_-jf1_)/nbfreq;
|
---|
[3876] | 164 | if (djf_<1) djf_=1;
|
---|
[3872] | 165 | cout << " BRVisibilityCalculator::SelectFreqBinning/Info JF1=" << jf1_
|
---|
| 166 | << " JF2=" << jf2_ << " DJF=" << djf_ << endl;
|
---|
| 167 |
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[3909] | 170 | /* --Methode-- */
|
---|
| 171 | void BRVisibilityCalculator::UpdateChanIds()
|
---|
| 172 | {
|
---|
[3872] | 173 |
|
---|
[3909] | 174 | for(size_t i=0; i<memgr_.NbFibres(); i++) {
|
---|
| 175 | chanids_(2*i)=memgr_.FiberId(i)*2-1;
|
---|
| 176 | chanids_(2*i+1)=memgr_.FiberId(i)*2;
|
---|
| 177 | }
|
---|
| 178 | sa_size_t k=0; // numero de ligne dans la matrice des visibilites
|
---|
| 179 | for(size_t i=0; i<vpdata_.size(); i++) {
|
---|
| 180 | for(size_t j=i; j<vpdata_.size(); j++) {
|
---|
| 181 | chanpairnumall_(k)=chanids_(i)*CHANPAIRCONVFAC+chanids_(j);
|
---|
| 182 | chanpairsall_(k,0)=chanids_(i); chanpairsall_(k,1)=chanids_(j); k++;
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 | sa_size_t kpair=0;
|
---|
| 186 | k=0; // numero de ligne dans la matrice des visibilites
|
---|
| 187 | for(size_t i=0; i<vpdata_.size(); i++) {
|
---|
| 188 | for(size_t j=i; j<vpdata_.size(); j++) {
|
---|
| 189 | kpair++;
|
---|
| 190 | if (kpair<(pairst_+1)) continue;
|
---|
| 191 | if (kpair>=(pairst_+nbpairs_+1)) break;
|
---|
[3915] | 192 | if (fgpimp_&&(i!=j)&&((i+j)%2==0)) continue; // calcul des visib avec numero pair-impair + autocorrel
|
---|
[3909] | 193 | chanpairnum_(k)=chanids_(i)*CHANPAIRCONVFAC+chanids_(j);
|
---|
| 194 | chanpairs_(k,0)=chanids_(i); chanpairs_(k,1)=chanids_(j); k++;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | string filename;
|
---|
| 199 | filename = outpath_+"chanum.ppf";
|
---|
| 200 | if (nbcalc_>1) {
|
---|
| 201 | char sbuff[32];
|
---|
| 202 | sprintf(sbuff,"chanum_%d.ppf",(int)calcid_);
|
---|
| 203 | filename = outpath_+sbuff;
|
---|
| 204 | }
|
---|
[3911] | 205 | POutPersist poc(filename);
|
---|
[3909] | 206 | poc << PPFNameTag("chanids") << chanids_;
|
---|
| 207 | poc << PPFNameTag("chanpairs") << chanpairs_;
|
---|
| 208 | poc << PPFNameTag("chanpairnum") << chanpairnum_;
|
---|
| 209 | poc << PPFNameTag("chanpairsall") << chanpairsall_;
|
---|
[3911] | 210 | poc << PPFNameTag("chanpairnumall") << chanpairnumall_;
|
---|
[3910] | 211 | cout << "BRVisibilityCalculator[" << calcid_ << "]::UpdateChanIds() Channel Ids/Pairs saved to PPF file "
|
---|
| 212 | << filename << endl;
|
---|
[3915] | 213 | cout << " ... NbVisib=NbChanPairs=" << chanpairs_.NRows() << " ChannelPairs= " ;
|
---|
[3910] | 214 | for(sa_size_t ir=0; ir<chanpairs_.NRows(); ir++) {
|
---|
[3911] | 215 | if (ir%10==0) cout << endl;
|
---|
[3910] | 216 | cout << "(" << chanpairs_(ir,0) << "," << chanpairs_(ir,1) << ") ";
|
---|
| 217 | }
|
---|
| 218 | cout << endl;
|
---|
[3909] | 219 | return;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
[3872] | 222 | /* --Methode-- */
|
---|
| 223 | int BRVisibilityCalculator::ActivateTimeTagCheck(uint_8 maxnpaq)
|
---|
| 224 | {
|
---|
| 225 | mindeltatt_=memgr_.PaqSize()/2;
|
---|
| 226 | if (mindeltatt_<1) mindeltatt_=1;
|
---|
| 227 | fcmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
|
---|
| 228 | ttmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
|
---|
| 229 | vlasttt_.resize(memgr_.NbFibres(), 0);
|
---|
| 230 | vbadtt_.resize(memgr_.NbFibres(), 0);
|
---|
| 231 | vnsamett_.resize(memgr_.NbFibres(), 0);
|
---|
| 232 | vndiff5tt_.resize(memgr_.NbFibres(), 0);
|
---|
| 233 |
|
---|
| 234 | fgcktt_=true;
|
---|
| 235 | cout << " BRVisibilityCalculator::ActivateTimeTagCheck() - TT/Fc matrix NCols=" << maxnpaq
|
---|
| 236 | << " MinDeltaTT=" << mindeltatt_ << endl;
|
---|
| 237 |
|
---|
| 238 | return 0;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | /* --Methode-- */
|
---|
| 243 | void BRVisibilityCalculator::run()
|
---|
| 244 | {
|
---|
| 245 | cout << " BRVisibilityCalculator[" << calcid_ << "/" << nbcalc_
|
---|
| 246 | << "]::run() - Starting " << " NFibers=" << memgr_.NbFibres()
|
---|
| 247 | << " NChan=" << 2*memgr_.NbFibres() << " NPairs=" << nbpairs_ << " First:" << pairst_ << endl;
|
---|
| 248 |
|
---|
| 249 | if (nparthr_ < 2) return BRBaseProcessor::run();
|
---|
| 250 | // Execution multithread parallele
|
---|
| 251 | setRC(1);
|
---|
| 252 | int rc=0;
|
---|
| 253 | try {
|
---|
| 254 | if ((nmean_%memgr_.NbPaquets())!=0) {
|
---|
| 255 | uint_4 mnmean = (nmean_/memgr_.NbPaquets()+1)*memgr_.NbPaquets();
|
---|
| 256 | cout << " BRVisibilityCalculator::run()/Info changing nmean=" << nmean_ << " to multiple of"
|
---|
| 257 | << " memgr_.NbPaquets() -> " << mnmean << endl;
|
---|
| 258 | nmean_=mnmean;
|
---|
| 259 | }
|
---|
| 260 | paralex_.SetParallelTask(*this);
|
---|
| 261 | cout << " BRVisibilityCalculator::run()/Info : starting ParallelExecutor with nThreads="
|
---|
| 262 | << paralex_.nThreads() << " ... " << endl;
|
---|
| 263 | paralex_.start();
|
---|
| 264 |
|
---|
| 265 | fgallfibok = new bool[memgr_.NbPaquets()];
|
---|
| 266 |
|
---|
| 267 | size_t paqsz=memgr_.PaqSize();
|
---|
| 268 | bool fgrun=true;
|
---|
| 269 | while (fgrun) {
|
---|
| 270 | if (stop_) break;
|
---|
| 271 | if (memgr_.GetRunState() == MemZR_Stopped) break;
|
---|
| 272 | int mid = memgr_.FindMemZoneId(mmact_); // (MemZA_ProcA);
|
---|
| 273 | // Byte* buffg = memgr_.GetMemZone(mid);
|
---|
| 274 | // if (buffg == NULL) {
|
---|
| 275 | if (mid < 0) {
|
---|
| 276 | cout << "BRVisibilityCalculator[" << calcid_ << "]::run()/ERROR FindMemZoneId("
|
---|
| 277 | << (int)mmact_ << ") ->" << mid << ") -> NULL" << endl;
|
---|
| 278 | setRC(7); fgrun=false;
|
---|
| 279 | break;
|
---|
| 280 | }
|
---|
[3909] | 281 | cts_=memgr_.GetAuxData(mid)->FillTime(); // get associated date/time (DATEOBS)
|
---|
[3910] | 282 | if (totnbpaq_==0) UpdateChanIds(); // Appele ici pour etre sur que le thread de remplissage a mis l'info a jour.
|
---|
[3909] | 283 |
|
---|
[3872] | 284 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
| 285 | fbuff_[fib] = memgr_.GetMemZone(mid,fib);
|
---|
| 286 | if (fbuff_[fib] == NULL) { // cela ne devrait pas arriver
|
---|
| 287 | cout << "BRVisibilityCalculator[" << calcid_ << "]::run()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
|
---|
| 288 | setRC(9); fgrun=false;
|
---|
| 289 | break;
|
---|
| 290 | }
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | if (totnbpaq_%nmean_ == 0) {
|
---|
| 294 | if (totnbpaq_ > 0) {
|
---|
| 295 | moyfc_/=nmean_;
|
---|
| 296 | moytt_/=nmean_;
|
---|
[3878] | 297 | UpdateVisMtxInfo(); // add/update keywords in the Info DVList
|
---|
[3872] | 298 | // ATTENTION : Matrice visibilites non moyennee
|
---|
| 299 | char nfile[48];
|
---|
| 300 | if (nbcalc_==1)
|
---|
| 301 | sprintf(nfile,"vismtx%d.ppf",numfile_);
|
---|
| 302 | else
|
---|
| 303 | sprintf(nfile,"vismtx_%d_%d.ppf",(int)calcid_,numfile_);
|
---|
| 304 | string flnm=outpath_+nfile;
|
---|
| 305 | POutPersist po(flnm);
|
---|
| 306 | po << vismtx_;
|
---|
[3895] | 307 | cout << numfile_ << "-BRVisCalc[" << calcid_ << "/" << nbcalc_ << "]::run() NPaqProc="
|
---|
| 308 | << totnbpaq_ << " TotMegaFLOP=" << (uint_8)TotNbMegaFLOP() << " -> VisibMtx in " << flnm << endl;
|
---|
| 309 |
|
---|
[3920] | 310 | if (fgvisdt_) FillVisibTable(moyfc_, moytt_);
|
---|
[3872] | 311 | numfile_++;
|
---|
| 312 | }
|
---|
| 313 | vismtx_ = complex<r_4>((r_4)0.,(r_4)0.);
|
---|
| 314 | moyfc_=moytt_=0.;
|
---|
[3909] | 315 | // first_tmstamp_.SetNow(); // Current date and time
|
---|
| 316 | first_tmstamp_=cts_; // Current date and time
|
---|
[3872] | 317 | }
|
---|
| 318 |
|
---|
| 319 | for(size_t jp=0; jp<memgr_.NbPaquets(); jp++) { // boucle sur les paquets d'une zone
|
---|
| 320 | fgallfibok[jp]=fgokallfibers_=true;
|
---|
| 321 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
| 322 | vpaq_[fib].Set(fbuff_[fib]+jp*paqsz);
|
---|
| 323 | vfgok_[fib] = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
|
---|
| 324 | if (!vfgok_[fib]) fgallfibok[jp]=fgokallfibers_=false;
|
---|
| 325 | }
|
---|
| 326 | if (fgokallfibers_) {
|
---|
| 327 | if (totprocnpaq_==0) {
|
---|
| 328 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
| 329 | fcfirst_[fib]=curfc_[fib];
|
---|
| 330 | ttfirst_[fib]=vpaq_[fib].TimeTag();
|
---|
| 331 | }
|
---|
| 332 | }
|
---|
| 333 | totprocnpaq_++;
|
---|
| 334 | moyfc_ += curfc_[0];
|
---|
| 335 | moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
|
---|
| 336 | if ((fgcktt_)&&(calcid_==0)) CheckTimeTag();
|
---|
[3895] | 337 | if (totnbpaq_%nmean_ == 0) {
|
---|
| 338 | first_fc_=curfc_[0];
|
---|
| 339 | first_tt_= (vpaq_[0].TimeTag()-ttfirst_[0]);
|
---|
| 340 | }
|
---|
[3872] | 341 | totnbpaq_++;
|
---|
| 342 | }
|
---|
| 343 | } // Fin de boucle sur les paquets
|
---|
[3895] | 344 |
|
---|
[3872] | 345 | // Execution parallele pour calcul des visibilites par bandes de frequence
|
---|
| 346 | int rcpex=paralex_.execute();
|
---|
| 347 | if (rcpex!=0) cout << " BRVisibilityCalculator[" << calcid_ << "]::run() / Error Rc[paralex_.execute()]=" << rcpex << endl;
|
---|
| 348 |
|
---|
| 349 | memgr_.FreeMemZone(mid, mmsta_); // (MemZS_ProcA);
|
---|
| 350 | } // Fin de boucle sur les zones a traiter
|
---|
| 351 | //------------------------------------
|
---|
| 352 | cout << " --------- END BRVisibilityCalculator[" << calcid_ << "]::run() , TotNbProcPaq=" << totprocnpaq_ << endl;
|
---|
| 353 | /*
|
---|
| 354 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) vpchk_[fib].Print();
|
---|
| 355 | cout << " ------------------------------------ " << endl;
|
---|
| 356 | */
|
---|
| 357 | delete[] fgallfibok;
|
---|
| 358 | }
|
---|
| 359 | catch (std::exception& exc) {
|
---|
| 360 | cout << " BRVisibilityCalculator[" << calcid_ << "]::run()/catched std::exception " << exc.what() << endl;
|
---|
| 361 | setRC(98);
|
---|
| 362 | return;
|
---|
| 363 | }
|
---|
| 364 | catch(...) {
|
---|
| 365 | cout << " BRVisibilityCalculator[" << calcid_ << "]::run()/catched unknown ... exception " << endl;
|
---|
| 366 | setRC(99);
|
---|
| 367 | return;
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | /* --Methode-- */
|
---|
| 373 | int BRVisibilityCalculator::Process()
|
---|
| 374 | {
|
---|
[3910] | 375 | if (totnbpaq_==0) UpdateChanIds(); // Appele ici pour etre sur que le thread de remplissage a mis l'info a jour.
|
---|
[3872] | 376 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
| 377 | vpdata_[2*fib] = vpaq_[fib].Data1C();
|
---|
| 378 | vpdata_[2*fib+1] = vpaq_[fib].Data2C();
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | if (totnbpaq_%nmean_ == 0) {
|
---|
| 382 | if (totnbpaq_ > 0) {
|
---|
| 383 | moyfc_/=nmean_;
|
---|
| 384 | moytt_/=nmean_;
|
---|
[3878] | 385 | UpdateVisMtxInfo(); // add/update keywords in the Info DVList
|
---|
[3872] | 386 | // ATTENTION : Matrice visibilites non moyennee
|
---|
| 387 | char nfile[48];
|
---|
| 388 | if (nbcalc_==1)
|
---|
| 389 | sprintf(nfile,"vismtx%d.ppf",numfile_);
|
---|
| 390 | else
|
---|
| 391 | sprintf(nfile,"vismtx_%d_%d.ppf",(int)calcid_,numfile_);
|
---|
| 392 | string flnm=outpath_+nfile;
|
---|
| 393 | POutPersist po(flnm);
|
---|
| 394 | po << vismtx_;
|
---|
[3895] | 395 | cout << numfile_ << "-BRVisCalc[" << calcid_ << "/" << nbcalc_ << "]::Process() NPaqProc="
|
---|
| 396 | << totnbpaq_ << " TotMegaFLOP=" << (uint_8)TotNbMegaFLOP() << " -> VisibMtx in " << flnm << endl;
|
---|
[3920] | 397 | if (fgvisdt_) FillVisibTable(moyfc_, moytt_);
|
---|
[3872] | 398 | numfile_++;
|
---|
| 399 | }
|
---|
| 400 | vismtx_ = complex<r_4>((r_4)0.,(r_4)0.);
|
---|
| 401 | moyfc_=moytt_=0.;
|
---|
[3878] | 402 | first_fc_=curfc_[0];
|
---|
| 403 | first_tt_= (vpaq_[0].TimeTag()-ttfirst_[0]);
|
---|
[3909] | 404 | // first_tmstamp_.SetNow(); // Current date and time
|
---|
| 405 | first_tmstamp_=cts_; // Current date and time
|
---|
[3872] | 406 | }
|
---|
| 407 |
|
---|
[3893] | 408 | // kpair=numero sequentiel de la paire: 0->(0,0), 1->(0,1), 2->(0,2), 3->(0,3), 4->(1,1), 5->(1,2) ...
|
---|
[3895] | 409 | sa_size_t kpair=0;
|
---|
| 410 | sa_size_t k=0; // numero de ligne dans la matrice des visibilites
|
---|
[3872] | 411 | for(size_t i=0; i<vpdata_.size(); i++) {
|
---|
| 412 | for(size_t j=i; j<vpdata_.size(); j++) {
|
---|
[3895] | 413 | kpair++;
|
---|
| 414 | if (kpair<(pairst_+1)) continue;
|
---|
| 415 | if (kpair>=(pairst_+nbpairs_+1)) break;
|
---|
[3915] | 416 | if (fgpimp_&&(i!=j)&&((i+j)%2==0)) continue; // calcul des visib avec numero pair-impair + autocorrel
|
---|
[3922] | 417 | TVector< complex<r_4> > vis = vismtx_.Row(k); k++;
|
---|
[3872] | 418 | for(sa_size_t f=1; f<vis.Size(); f++) {
|
---|
| 419 | vis(f) += complex<r_4>((r_4)vpdata_[i][f].realB(), (r_4)vpdata_[i][f].imagB()) *
|
---|
| 420 | complex<r_4>((r_4)vpdata_[j][f].realB(), -(r_4)vpdata_[j][f].imagB());
|
---|
| 421 | }
|
---|
[3895] | 422 | nb_flop_ += (8.*(r_8)(vis.Size()-1));
|
---|
[3872] | 423 | }
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | moyfc_ += curfc_[0];
|
---|
| 427 | moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
|
---|
| 428 | if ((fgcktt_)&&(calcid_==0)) CheckTimeTag();
|
---|
| 429 | totnbpaq_++;
|
---|
| 430 | return 0;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | /* --Methode-- */
|
---|
[3878] | 434 | void BRVisibilityCalculator::UpdateVisMtxInfo()
|
---|
| 435 | {
|
---|
| 436 | string ikey,ikdesc;
|
---|
| 437 | ikey="DATEOBS"; ikdesc=" Date/Time corresponding to TimeTagFirst";
|
---|
| 438 | vismtx_.Info().SetS(ikey,first_tmstamp_.ToString());
|
---|
| 439 | vismtx_.Info().SetComment(ikey,ikdesc);
|
---|
| 440 | ikey="FirstFC"; ikdesc="First FrameCounter";
|
---|
| 441 | vismtx_.Info().SetI(ikey,first_fc_);
|
---|
| 442 | vismtx_.Info().SetComment(ikey,ikdesc);
|
---|
| 443 | ikey="FirstTT"; ikdesc="First TimeTag";
|
---|
| 444 | vismtx_.Info().SetI(ikey,first_tt_);
|
---|
| 445 | vismtx_.Info().SetComment(ikey,ikdesc);
|
---|
| 446 | ikey="LastFC"; ikdesc="Last FrameCounter";
|
---|
| 447 | vismtx_.Info().SetI(ikey,curfc_[0]);
|
---|
| 448 | vismtx_.Info().SetComment(ikey,ikdesc);
|
---|
| 449 | ikey="LastTT"; ikdesc="Last TimeTag";
|
---|
| 450 | vismtx_.Info().SetI(ikey,vpaq_[0].TimeTag()-ttfirst_[0]);
|
---|
| 451 | vismtx_.Info().SetComment(ikey,ikdesc);
|
---|
| 452 | ikey="MeanFC"; ikdesc="Mean FrameCounter";
|
---|
| 453 | vismtx_.Info().SetD(ikey,moyfc_);
|
---|
| 454 | vismtx_.Info().SetComment(ikey,ikdesc);
|
---|
| 455 | ikey="MeanTT"; ikdesc="Mean TimeTag";
|
---|
| 456 | vismtx_.Info().SetD(ikey,moytt_);
|
---|
| 457 | vismtx_.Info().SetComment(ikey,ikdesc);
|
---|
| 458 | ikey="NPAQSUM"; ikdesc="Number of paquets summed";
|
---|
| 459 | vismtx_.Info().SetI(ikey,nmean_);
|
---|
| 460 | }
|
---|
| 461 |
|
---|
| 462 |
|
---|
| 463 | /* --Methode-- */
|
---|
[3872] | 464 | int BRVisibilityCalculator::execute(int tid)
|
---|
| 465 | {
|
---|
| 466 | vector<TwoByteComplex*> pvpdata(2*memgr_.NbFibres());
|
---|
| 467 | size_t paqsz=memgr_.PaqSize();
|
---|
| 468 | BRPaquet ppaq(paqsz);
|
---|
| 469 |
|
---|
[3895] | 470 |
|
---|
[3872] | 471 | sa_size_t fdelt = vismtx_.NCols()/nparthr_;
|
---|
| 472 | sa_size_t fdeb = tid*fdelt;
|
---|
| 473 | sa_size_t ffin = (tid+1)*fdelt;
|
---|
| 474 |
|
---|
| 475 | if (fdeb<1) fdeb=1;
|
---|
| 476 | if ((ffin>vismtx_.NCols())||(tid==(nparthr_-1))) ffin=vismtx_.NCols();
|
---|
| 477 |
|
---|
| 478 | for(size_t jp=0; jp<memgr_.NbPaquets(); jp++) { // boucle sur les paquets d'une zone
|
---|
| 479 | if (!fgallfibok[jp]) continue;
|
---|
| 480 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
| 481 | ppaq.Set(fbuff_[fib]+jp*paqsz);
|
---|
| 482 | pvpdata[2*fib] = ppaq.Data1C();
|
---|
| 483 | pvpdata[2*fib+1] = ppaq.Data2C();
|
---|
| 484 | }
|
---|
[3895] | 485 |
|
---|
| 486 |
|
---|
[3893] | 487 | // kpair=numero sequentiel de la paire: 0->(0,0), 1->(0,1), 2->(0,2), 3->(0,3), 4->(1,1), 5->(1,2) ...
|
---|
[3895] | 488 | sa_size_t kpair=0;
|
---|
| 489 | sa_size_t k=0; // numero de ligne dans la matrice des visibilites
|
---|
[3872] | 490 | for(size_t i=0; i<vpdata_.size(); i++) {
|
---|
| 491 | for(size_t j=i; j<vpdata_.size(); j++) {
|
---|
[3895] | 492 | kpair++;
|
---|
| 493 | if (kpair<(pairst_+1)) continue;
|
---|
| 494 | if (kpair>=(pairst_+nbpairs_+1)) break;
|
---|
[3915] | 495 | if (fgpimp_&&(i!=j)&&((i+j)%2==0)) continue; // calcul des visib avec numero pair-impair + autocorrel
|
---|
[3895] | 496 | TVector< complex<r_4> > vis = vismtx_.Row(k); k++;
|
---|
[3872] | 497 | for(sa_size_t f=fdeb; f<ffin; f++) {
|
---|
| 498 | vis(f) += complex<r_4>((r_4)pvpdata[i][f].realB(), (r_4)pvpdata[i][f].imagB()) *
|
---|
| 499 | complex<r_4>((r_4)pvpdata[j][f].realB(), -(r_4)pvpdata[j][f].imagB());
|
---|
| 500 | }
|
---|
[3895] | 501 | nb_flop_ += (8.*(r_8)(ffin-fdeb));
|
---|
[3872] | 502 | }
|
---|
| 503 | }
|
---|
| 504 |
|
---|
| 505 | } // Fin de boucle sur les paquets
|
---|
| 506 |
|
---|
| 507 | return 0;
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | /* --Methode-- */
|
---|
| 511 | int BRVisibilityCalculator::FillVisibTable(double fcm, double ttm)
|
---|
| 512 | {
|
---|
| 513 | double xnt[10];
|
---|
| 514 | xnt[0]=fcm; xnt[1]=ttm/1.25e8;
|
---|
| 515 |
|
---|
| 516 | if (djf_<2) {
|
---|
| 517 | for(sa_size_t rv=0; rv<vismtx_.NRows(); rv++) {
|
---|
| 518 | for(sa_size_t jf=jf1_; jf<jf2_; jf++) {
|
---|
| 519 | xnt[2]=jf;
|
---|
[3909] | 520 | xnt[3]=chanpairnumall_(rv+pairst_);
|
---|
[3872] | 521 | xnt[4]=vismtx_(rv,jf).real()/(r_4)(nmean_);
|
---|
| 522 | xnt[5]=vismtx_(rv,jf).imag()/(r_4)(nmean_);
|
---|
| 523 | visdt_.AddRow(xnt);
|
---|
| 524 | }
|
---|
| 525 | }
|
---|
| 526 | }
|
---|
| 527 | else {
|
---|
| 528 | for(sa_size_t rv=0; rv<vismtx_.NRows(); rv++) {
|
---|
| 529 | for(sa_size_t jf=jf1_; jf<jf2_; jf+=djf_) {
|
---|
| 530 | r_4 moyreal=0.;
|
---|
| 531 | r_4 moyimag=0.;
|
---|
| 532 | sa_size_t jjfmx=jf+djf_;
|
---|
| 533 | if (jjfmx > vismtx_.NCols()) jjfmx=vismtx_.NCols();
|
---|
| 534 | for(sa_size_t jjf=jf; jjf<jjfmx; jjf++) {
|
---|
| 535 | moyreal+=vismtx_(rv,jjf).real();
|
---|
| 536 | moyimag+=vismtx_(rv,jjf).imag();
|
---|
| 537 | }
|
---|
| 538 | xnt[2]=jf+djf_/2;
|
---|
[3909] | 539 | xnt[3]=chanpairnumall_(rv+pairst_);
|
---|
[3872] | 540 | xnt[4]=moyreal/(r_4)(nmean_*djf_);
|
---|
| 541 | xnt[5]=moyimag/(r_4)(nmean_*djf_);
|
---|
| 542 | visdt_.AddRow(xnt);
|
---|
| 543 | }
|
---|
| 544 | }
|
---|
| 545 | }
|
---|
| 546 | return 0;
|
---|
| 547 | }
|
---|
| 548 |
|
---|
| 549 | /* --Methode-- */
|
---|
| 550 | int BRVisibilityCalculator::CheckTimeTag()
|
---|
| 551 | {
|
---|
| 552 | if (totnbpaq_==0) {
|
---|
| 553 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
| 554 | vlasttt_[fib]=ttfirst_[fib];
|
---|
| 555 | if (ttmtx_.NCols()>0) {
|
---|
| 556 | fcmtx_(fib,totnbpaq_) = curfc_[fib];
|
---|
| 557 | ttmtx_(fib,totnbpaq_) = vlasttt_[fib];
|
---|
| 558 | }
|
---|
| 559 | }
|
---|
| 560 | return 0;
|
---|
| 561 | }
|
---|
| 562 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
| 563 | int_8 ld = (int_8)vpaq_[fib].TimeTag()-(int_8)vlasttt_[fib];
|
---|
| 564 | int_8 fd = (int_8)vpaq_[fib].TimeTag()-(int_8)ttfirst_[fib]-(int_8)vpaq_[0].TimeTag()+(int_8)ttfirst_[0];
|
---|
| 565 | /* if ( (ld < mindeltatt_) || (fd<-5) || (fd>5)) { vbadtt_[fib]++; vnsamett_[fib]++; }
|
---|
| 566 | else {
|
---|
| 567 | if (fd!=0) vnsamett_[fib]++;
|
---|
| 568 | }
|
---|
| 569 | */
|
---|
| 570 | if (ld < mindeltatt_) vbadtt_[fib]++;
|
---|
| 571 | else {
|
---|
| 572 | if (fd != 0) vnsamett_[fib]++;
|
---|
| 573 | if ((fd<-5)||(fd>5)) vndiff5tt_[fib]++;
|
---|
| 574 | }
|
---|
| 575 | vlasttt_[fib]=vpaq_[fib].TimeTag();
|
---|
| 576 | if (totnbpaq_<ttmtx_.NCols()) {
|
---|
| 577 | fcmtx_(fib,totnbpaq_) = curfc_[fib];
|
---|
| 578 | ttmtx_(fib,totnbpaq_) = vlasttt_[fib];
|
---|
| 579 | }
|
---|
| 580 | }
|
---|
| 581 | return 0;
|
---|
| 582 | }
|
---|
| 583 |
|
---|
| 584 | //-------------------------------------------------------------------------------
|
---|
| 585 | // Classe Groupe (ensemble) de Calculateur de Visibilites, tournant en parallele
|
---|
| 586 | //-------------------------------------------------------------------------------
|
---|
| 587 |
|
---|
| 588 | /* --Methode-- */
|
---|
[3915] | 589 | BRVisCalcGroup::BRVisCalcGroup(size_t nbcalc, RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean,
|
---|
| 590 | uint_4 pair1, uint_4 nbpairs, bool fgpimp, size_t nthr)
|
---|
[3872] | 591 | : tm_(false)
|
---|
| 592 | {
|
---|
| 593 | if ((nbcalc<1)||(nbcalc>6))
|
---|
| 594 | throw ParmError("BRVisCalcGroup::BRVisCalcGroup NbCalc > 6 !");
|
---|
| 595 | for(size_t i=0; i<nbcalc; i++) {
|
---|
| 596 | BRVisibilityCalculator * viscp=new BRVisibilityCalculator(memgr, outpath, nmean, nthr);
|
---|
[3915] | 597 | viscp->DefineRank(nbcalc, i, pair1, nbpairs, fgpimp);
|
---|
[3872] | 598 | viscalcp_.push_back(viscp);
|
---|
| 599 | }
|
---|
| 600 | }
|
---|
| 601 | /* --Methode-- */
|
---|
| 602 | BRVisCalcGroup::~BRVisCalcGroup()
|
---|
| 603 | {
|
---|
| 604 | for(size_t i=0; i<viscalcp_.size(); i++)
|
---|
| 605 | delete viscalcp_[i];
|
---|
| 606 | }
|
---|
| 607 | /* --Methode-- */
|
---|
| 608 | int BRVisCalcGroup::SelectFreqBinning(uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
|
---|
| 609 | {
|
---|
| 610 | int rc=0;
|
---|
| 611 | for(size_t i=0; i<viscalcp_.size(); i++)
|
---|
| 612 | rc=viscalcp_[i]->SelectFreqBinning(freq1, freq2, nbfreq);
|
---|
| 613 | return rc;
|
---|
| 614 | }
|
---|
| 615 | /* --Methode-- */
|
---|
[3920] | 616 | void BRVisCalcGroup::ActivateVisDTable(bool fgfdt)
|
---|
| 617 | {
|
---|
| 618 | for(size_t i=0; i<viscalcp_.size(); i++)
|
---|
| 619 | viscalcp_[i]->ActivateVisDTable(fgfdt);
|
---|
| 620 | }
|
---|
| 621 | /* --Methode-- */
|
---|
[3872] | 622 | void BRVisCalcGroup::start()
|
---|
| 623 | {
|
---|
| 624 | for(size_t i=0; i<viscalcp_.size(); i++)
|
---|
| 625 | viscalcp_[i]->start();
|
---|
| 626 | tm_.SplitQ();
|
---|
| 627 | }
|
---|
| 628 | /* --Methode-- */
|
---|
| 629 | void BRVisCalcGroup::join()
|
---|
| 630 | {
|
---|
| 631 | r_8 totflop=0.;
|
---|
| 632 | for(size_t i=0; i<viscalcp_.size(); i++) {
|
---|
| 633 | viscalcp_[i]->join();
|
---|
[3895] | 634 | // cout << " BRVisCalcGroup::join()/ VisibCalc[" << i << "]->TotNbMegaFLOP()="
|
---|
| 635 | // << viscalcp_[i]->TotNbFLOP()/1024e3 << endl;
|
---|
[3872] | 636 | totflop += viscalcp_[i]->TotNbFLOP();
|
---|
| 637 | }
|
---|
| 638 | tm_.SplitQ();
|
---|
| 639 | cout << " ----------------------------------------------------------" << endl;
|
---|
[3895] | 640 | cout << " BRVisCalcGroup::join() : Finished " << viscalcp_.size() << " VisibilityCalculator(s)" << endl;
|
---|
| 641 | cout << " ... Elaspsed time: " << tm_.PartialElapsedTimems()
|
---|
| 642 | << " ms (total:" << tm_.TotalElapsedTimems() << ")" << endl;
|
---|
| 643 | double mflopsrate=totflop/(r_8)tm_.PartialElapsedTimems()/(1024.);
|
---|
[3872] | 644 | cout << " ... TotalMegaFLOP= " << totflop/(1024.e3) << " @ "
|
---|
[3895] | 645 | << mflopsrate << " MFLOP/s" << " (=" << mflopsrate/(r_8)viscalcp_.size() << "/VisibCalcObject)" << endl;
|
---|
[3872] | 646 | cout << " ----------------------------------------------------------" << endl;
|
---|
| 647 | return;
|
---|
| 648 | }
|
---|