source: Sophya/trunk/ArchTOIPipe/Kernel/toimanager.cc@ 2228

Last change on this file since 2228 was 2220, checked in by aubourg, 23 years ago

vf_231002

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