| [1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
|---|
| 2 | // Eric Aubourg
|
|---|
| 3 | // Christophe Magneville
|
|---|
| 4 | // Reza Ansari
|
|---|
| [2329] | 5 | // $Id: toimanager.cc,v 1.20 2003-02-24 14:14:51 cecile Exp $
|
|---|
| [1738] | 6 |
|
|---|
| [1365] | 7 | #include "toimanager.h"
|
|---|
| 8 | #include <limits.h>
|
|---|
| 9 | #include <pthread.h>
|
|---|
| [1759] | 10 | #include <iostream.h>
|
|---|
| [1704] | 11 | #include <unistd.h>
|
|---|
| [2187] | 12 | #include <map>
|
|---|
| [1365] | 13 |
|
|---|
| [1702] | 14 | #ifndef MAXINT
|
|---|
| 15 | #define MAXINT 2147483647
|
|---|
| 16 | #endif
|
|---|
| 17 |
|
|---|
| [1365] | 18 | TOIManager::TOIManager() {
|
|---|
| 19 | reqBegin = 0;
|
|---|
| [1702] | 20 | reqEnd = MAXINT;
|
|---|
| [2187] | 21 |
|
|---|
| 22 | // -----------ajout cgt vf 19/08/2002
|
|---|
| 23 | // par defaut TOISegmented
|
|---|
| 24 | selectTOISegmented(1024, 20);
|
|---|
| 25 | // ----------- fin ajout cgt
|
|---|
| 26 |
|
|---|
| [1365] | 27 | }
|
|---|
| 28 |
|
|---|
| 29 | TOIManager* TOIManager::instance = NULL;
|
|---|
| 30 |
|
|---|
| 31 | TOIManager* TOIManager::getManager() {
|
|---|
| 32 | if (instance == NULL) instance = new TOIManager();
|
|---|
| 33 | return instance;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| [2187] | 36 | // ajout vf 26/07/2002
|
|---|
| 37 |
|
|---|
| [2133] | 38 | // enregistrement d'un processeur dans la liste des processeurs pour une execution en groupe
|
|---|
| 39 |
|
|---|
| 40 | void TOIManager::registerProcessor(TOIProcessor* proc) {
|
|---|
| 41 |
|
|---|
| 42 | cout << "Adding processor to TOIManager for group execution" << endl;
|
|---|
| 43 | processors.push_back(proc);
|
|---|
| 44 |
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| [2187] | 48 | // demarrage de tous les processeurs et verification auto des samplenum pour chaque processeur parametre
|
|---|
| [2133] | 49 |
|
|---|
| 50 | void TOIManager::startAll() {
|
|---|
| [2187] | 51 | // verification des samplenum
|
|---|
| 52 | bool samples_ok=checkSamplesLimits(1);
|
|---|
| 53 | if (samples_ok) {
|
|---|
| 54 | cout << "All limits ok" << endl << "Starting processors" << endl;
|
|---|
| 55 | } else {
|
|---|
| 56 | cout << "One or more limits ajusted for execution" << endl << "Starting processors" << endl;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | // mise a jour des limites apres verification
|
|---|
| 60 | checkSamplesLimits(2);
|
|---|
| 61 | checkSamplesLimits(3);
|
|---|
| [2329] | 62 | cout<<"Fin checks"<<endl;
|
|---|
| 63 |
|
|---|
| [2187] | 64 |
|
|---|
| 65 | // debogage affichage des limites apres calcul
|
|---|
| [2204] | 66 | {for (vector<TOIProcessor*>::iterator i = processors.begin();
|
|---|
| [2133] | 67 | i != processors.end(); i++) {
|
|---|
| 68 | TOIProcessor* proc = *i;
|
|---|
| [2187] | 69 | proc->printLimits();
|
|---|
| 70 | }
|
|---|
| [2204] | 71 | }
|
|---|
| [2187] | 72 |
|
|---|
| 73 | // demarrage
|
|---|
| 74 | for (vector<TOIProcessor*>::iterator i = processors.begin();
|
|---|
| 75 | i != processors.end(); i++) {
|
|---|
| 76 | TOIProcessor* proc = *i;
|
|---|
| 77 | cout << "**********************" << endl;
|
|---|
| 78 | cout << "starting processor " << endl;
|
|---|
| [2133] | 79 | proc->start();
|
|---|
| 80 | cout << "processor started " << endl;
|
|---|
| 81 | }
|
|---|
| [2187] | 82 | cout << "**********************" << endl;
|
|---|
| [2133] | 83 | }
|
|---|
| 84 |
|
|---|
| [2187] | 85 | bool TOIManager::checkSamplesLimits(int pass)
|
|---|
| 86 | {
|
|---|
| 87 | bool processor_ok=true;
|
|---|
| 88 | bool samples_ok=true;
|
|---|
| 89 | for (vector<TOIProcessor*>::iterator i = processors.begin();
|
|---|
| 90 | i != processors.end(); i++) {
|
|---|
| 91 | TOIProcessor* proc = *i;
|
|---|
| 92 | cout << "testing processor limits " << endl;
|
|---|
| 93 | // test du processeur
|
|---|
| 94 |
|
|---|
| 95 | // test seulement pour les processor cle
|
|---|
| 96 | //if (proc->getRequested()) {
|
|---|
| 97 | processor_ok = proc->checkSampleLimits(pass);
|
|---|
| 98 | //}
|
|---|
| 99 |
|
|---|
| 100 | if (processor_ok) {
|
|---|
| 101 | cout << "processor limits ok " << endl;
|
|---|
| 102 | } else {
|
|---|
| 103 | cout << "processor limits ajusted" << endl;
|
|---|
| 104 | samples_ok = false;
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 | return samples_ok;
|
|---|
| 108 | }
|
|---|
| [2133] | 109 |
|
|---|
| [2187] | 110 | // fin ajout vf
|
|---|
| [2133] | 111 |
|
|---|
| [1702] | 112 | void TOIManager::setRequestedSample(int begin, int end) {
|
|---|
| [1365] | 113 | reqBegin = begin;
|
|---|
| 114 | reqEnd = end;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| [1702] | 117 | int TOIManager::getRequestedBegin() {
|
|---|
| [1365] | 118 | return reqBegin;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| [1702] | 121 | int TOIManager::getRequestedEnd() {
|
|---|
| [1365] | 122 | return reqEnd;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | void TOIManager::addThread(pthread_t* t) {
|
|---|
| 126 | // cout << "adding thread " << t << endl;
|
|---|
| 127 | threads.push_back(t);
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | void TOIManager::joinAll() {
|
|---|
| [2133] | 131 | waitForAll();
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | void TOIManager::waitForAll() {
|
|---|
| [1365] | 135 | for (vector<pthread_t*>::iterator i = threads.begin();
|
|---|
| 136 | i != threads.end(); i++) {
|
|---|
| 137 | pthread_t* pth = *i;
|
|---|
| 138 | cout << "joining thread " << pth << endl;
|
|---|
| 139 | pthread_join(*pth, NULL);
|
|---|
| 140 | cout << "thread joined " << pth << endl;
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| [1687] | 143 |
|
|---|
| 144 |
|
|---|
| [2187] | 145 | // -----------ajout cgt vf 19/08/2002
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 | void TOIManager::selectTOISegmented(int bufsz, int maxseg)
|
|---|
| 149 | {
|
|---|
| 150 | fgSegmented = true;
|
|---|
| 151 | segBuffsz = bufsz;
|
|---|
| 152 | segMaxseg = maxseg;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | void TOIManager::selectTOISeqBuffered(int wsz)
|
|---|
| 156 | {
|
|---|
| 157 | fgSegmented = false;
|
|---|
| 158 | segBuffsz = wsz;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | // methode connect de cgt simplifiee et corrigee
|
|---|
| [2220] | 162 | TOI& TOIManager::connect(TOIProcessor& prout, string out,
|
|---|
| 163 | TOIProcessor& prin, string in, string nom, int wbsz, bool withFlag)
|
|---|
| [2187] | 164 | {
|
|---|
| 165 | TOI* toi;
|
|---|
| 166 | if (nom.length() < 1) {
|
|---|
| 167 | char buff[128];
|
|---|
| 168 | sprintf(buff, "TOI%s_[%s-%s]", nom, in, out);
|
|---|
| 169 | nom = buff;
|
|---|
| 170 | }
|
|---|
| 171 | if (wbsz < 16) wbsz = segBuffsz;
|
|---|
| 172 |
|
|---|
| 173 | // ajout test pour eviter de creer 2 tois en sortie
|
|---|
| 174 | if ((toi=prout.getOutToi(out)) == NULL) {
|
|---|
| 175 | //cout << "toi cree" << endl;
|
|---|
| 176 | if (fgSegmented) toi = new TOISegmented(nom, wbsz, segMaxseg);
|
|---|
| 177 | else toi = new TOISeqBuffered(nom, wbsz);
|
|---|
| 178 | // on ajoute le toi de sortie
|
|---|
| 179 | prout.addOutput(out, toi);
|
|---|
| 180 | } else {
|
|---|
| 181 | //cout << "toi deja cree stop" << endl;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | if (withFlag) { // Si c'est un FITSTOIWriter
|
|---|
| 185 | FITSTOIWriter* ftw = dynamic_cast< FITSTOIWriter* >(&prin);
|
|---|
| 186 | if (ftw) ftw->addInput(in, toi, withFlag);
|
|---|
| 187 | else prin.addInput(in, toi);
|
|---|
| 188 | }
|
|---|
| 189 | else prin.addInput(in, toi);
|
|---|
| 190 | return(*toi);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 | TOI& TOIManager::connect(TOIProcessor& prout, const char* out,
|
|---|
| 195 | TOIProcessor& prin, const char* in, string nom, int wbsz, bool withFlag)
|
|---|
| 196 | {
|
|---|
| 197 | string outs = out;
|
|---|
| 198 | string ins = in;
|
|---|
| 199 | return connect(prout, outs, prin, ins, nom, wbsz, withFlag);
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | // ----------- fin ajout cgt
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| [1687] | 206 | // -----------------------------------------------------------------
|
|---|
| 207 | // Classe pour affichage de l'avancement des TOIProcessors
|
|---|
| 208 | // Reza 08/2001
|
|---|
| 209 | // -----------------------------------------------------------------
|
|---|
| 210 |
|
|---|
| 211 | RzProcSampleCounter::RzProcSampleCounter()
|
|---|
| 212 | {
|
|---|
| 213 | _msg = "SampleCounter/Info";
|
|---|
| 214 | _rate = 50;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | RzProcSampleCounter::~RzProcSampleCounter()
|
|---|
| 218 | {
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | long RzProcSampleCounter::PrintStats()
|
|---|
| 222 | {
|
|---|
| 223 | int istart = 0;
|
|---|
| 224 | int iend = 0;
|
|---|
| 225 | long dns_print = 1000;
|
|---|
| 226 | int dns_print_fac = _rate;
|
|---|
| 227 | int nbmax_dns_print = 2;
|
|---|
| 228 |
|
|---|
| 229 | TOIManager* mgr = TOIManager::getManager();
|
|---|
| 230 |
|
|---|
| [1999] | 231 | // istart = mgr->getRequestedBegin();
|
|---|
| 232 | // iend = mgr->getRequestedEnd();
|
|---|
| 233 | istart = SampleBegin();
|
|---|
| 234 | iend = SampleEnd();
|
|---|
| [1687] | 235 |
|
|---|
| 236 | dns_print = (iend-istart)/dns_print_fac;
|
|---|
| 237 | if (dns_print < 1000) dns_print = ((iend-istart) < 1000) ? (iend-istart) : 1000;
|
|---|
| 238 | if (dns_print < 1) dns_print = 1;
|
|---|
| 239 | nbmax_dns_print = (iend-istart)/dns_print;
|
|---|
| 240 |
|
|---|
| 241 | cout << "RzProcSampleCounter::PrintStats() InfoMessage=" << _msg
|
|---|
| 242 | << "\n ... " << _msg << " istart="
|
|---|
| 243 | << istart << " iend= " << iend << " dns_print= " << dns_print
|
|---|
| 244 | << " nbmax_dns_print= " << nbmax_dns_print << endl;
|
|---|
| 245 | // ------------------- Impression continu de stat ------------------------
|
|---|
| 246 | long nb_dns_print = 0;
|
|---|
| 247 | int nb_sleep = 0;
|
|---|
| 248 | long last_sample_count = 0;
|
|---|
| 249 | long processed_samples = 0;
|
|---|
| 250 | long total_sample_count = dns_print*nbmax_dns_print;
|
|---|
| 251 | bool alldone = false;
|
|---|
| [2077] | 252 | double fracperc = 0.;
|
|---|
| 253 | int fperc = 0;
|
|---|
| [1687] | 254 | while (!alldone) {
|
|---|
| 255 | processed_samples = ProcessedSampleCount();
|
|---|
| 256 | if ( (processed_samples-last_sample_count > dns_print) ||
|
|---|
| [1702] | 257 | (processed_samples > total_sample_count-10) ) {
|
|---|
| [1687] | 258 | last_sample_count = processed_samples;
|
|---|
| 259 | if (nb_dns_print == 0) cout << "\n";
|
|---|
| 260 | nb_dns_print++;
|
|---|
| [2077] | 261 | fracperc = (double)processed_samples*100./(double)total_sample_count;
|
|---|
| 262 | fperc = fracperc*100;
|
|---|
| [1687] | 263 | cout << ">>> " << _msg << ": ProcessedSampleCount()= " << last_sample_count
|
|---|
| [2077] | 264 | << " Frac done = " << (double)fperc/100. << " %" << endl;
|
|---|
| [1687] | 265 | if (last_sample_count > total_sample_count-10) alldone = true;
|
|---|
| 266 | nb_sleep = 0;
|
|---|
| 267 | }
|
|---|
| [2077] | 268 | else if ((nb_sleep+1)%5 == 0) {
|
|---|
| 269 | fracperc = (double)processed_samples*100./(double)total_sample_count;
|
|---|
| 270 | fperc = fracperc*100;
|
|---|
| [1687] | 271 | cout << "> " << _msg << ": ProcSamples()= " << processed_samples
|
|---|
| [2077] | 272 | << " Done = " << " %" << (double)fperc/100.
|
|---|
| [1702] | 273 | << " NbSleep(1) = " << nb_sleep << endl;
|
|---|
| [2077] | 274 | }
|
|---|
| [1687] | 275 | sleep(1); nb_sleep++;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | // -----------------------------------------------------------------------
|
|---|
| 279 |
|
|---|
| 280 | return last_sample_count;
|
|---|
| 281 |
|
|---|
| 282 | }
|
|---|
| [2187] | 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|