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