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