Logo ROOT   6.08/07
Reference Guide
TProofNodes.cxx
Go to the documentation of this file.
1 // @(#)root/proof:$Id$
2 // Author:
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TProofNodes
13 \ingroup proofbench
14 
15 PROOF worker node information
16 
17 */
18 
19 #include "TProofNodes.h"
20 #include "TProof.h"
21 #include "TList.h"
22 #include "TMap.h"
23 #include "TObjString.h"
24 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Constructor
29 
31  : fProof(proof), fNodes(0), fActiveNodes(0),
32  fMaxWrksNode(-1), fMinWrksNode(-1),
33  fNNodes(0), fNWrks(0), fNActiveWrks(0), fNCores(0)
34 {
35  Build();
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Destructor
40 
42 {
43  if (fNodes) {
46  }
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Desctiption: Build the node list, which is a list of nodes whose members
51 /// in turn are lists of workers on the node.
52 /// Input: Nothing
53 /// Return: Nothing
54 
56 {
57  if (!fProof || !fProof->IsValid()) {
58  Warning("Build", "the PROOF instance is undefined or invalid! Cannot continue");
59  return;
60  }
61 
62  if (fNodes){
65  }
66  fNodes = new TMap;
68 
69  TList *slaves = fProof->GetListOfSlaveInfos();
70  TIter nxtslave(slaves);
71  TSlaveInfo *si = 0;
72  TList *node = 0;
73  TPair *pair = 0;
74  while ((si = (TSlaveInfo *)(nxtslave()))) {
75  TSlaveInfo *si_copy = (TSlaveInfo *)(si->Clone());
76  if (!(pair = (TPair *) fNodes->FindObject(si->GetName()))) {
77  node = new TList;
78  //si's are owned by the member fSlaveInfo of fProof
79  node->SetOwner(kTRUE);
80  node->SetName(si_copy->GetName());
81  node->Add(si_copy);
82  fNodes->Add(new TObjString(si->GetName()), node);
83  } else {
84  node = (TList *) pair->Value();
85  node->Add(si_copy);
86  }
87  }
88  // Update counters and created active nodes map
89  if (fActiveNodes){
92  }
93  fActiveNodes = new TMap;
95  TList *actnode = 0;
96  fMaxWrksNode = -1;
97  fMinWrksNode = -1;
98  fNNodes = 0;
99  fNWrks = 0;
100  fNActiveWrks = 0;
101  TIter nxk(fNodes);
102  TObject *key = 0;
103  while ((key = nxk()) != 0) {
104  node = dynamic_cast<TList *>(fNodes->GetValue(key));
105  if (node) {
106  fNNodes++;
107  // Number of cores
108  si = (TSlaveInfo *) node->First();
109  fNCores += si->fSysInfo.fCpus;
110  // Number of workers
111  fNWrks += node->GetSize();
112  if (fMinWrksNode == -1 || (node->GetSize() < fMinWrksNode)) {
113  fMinWrksNode = node->GetSize();
114  }
115  if (fMaxWrksNode == -1 || (node->GetSize() > fMaxWrksNode)) {
116  fMaxWrksNode = node->GetSize();
117  }
118  TIter nxw(node);
119  while ((si = (TSlaveInfo *) nxw())) {
120  if (si->fStatus == TSlaveInfo::kActive) {
121  fNActiveWrks++;
122  TSlaveInfo *si_copy = (TSlaveInfo *)(si->Clone());
123  actnode = dynamic_cast<TList *>(fActiveNodes->GetValue(key));
124  if (actnode) {
125  actnode->Add(si_copy);
126  } else {
127  actnode = new TList;
128  actnode->SetOwner(kTRUE);
129  actnode->SetName(si_copy->GetName());
130  actnode->Add(si_copy);
131  fActiveNodes->Add(new TObjString(si->GetName()), actnode);
132  }
133  }
134  }
135  } else {
136  Warning("Build", "could not get list for node '%s'", key->GetName());
137  }
138  }
139 
140  // Done
141  return;
142 }
143 
144 ////////////////////////////////////////////////////////////////////////////////
145 /// Description: Activate 'nwrks' workers; calls TProof::SetParallel and
146 /// rebuild the internal lists
147 /// Input: number of workers
148 /// Return: 0 is successful, <0 otherwise.
149 
151 {
152  Int_t nw = fProof->SetParallel(nwrks);
153  if (nw > 0) {
154  if (nw != nwrks)
155  Warning("ActivateWorkers", "requested %d got %d", nwrks, nw);
156  Build();
157  }
158  return nw;
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Description: Activate the same number of workers on all nodes.
163 /// Input: workers: string of the form "nx" where non-negative integer n
164 /// is the number of worker on each node to be activated.
165 /// Return: The number of active workers per node when the operation is
166 /// successful.
167 /// <0 otherwise.
168 
170 {
171  TString toactivate;
172  TString todeactivate;
173 
174  // The TProof::ActivateWorker/TProof::DeactivateWorker functions were fixed /
175  // improved starting with protocol version 33
176  Bool_t protocol33 = kTRUE;
177  if (fProof->GetRemoteProtocol() < 33 || fProof->GetClientProtocol() < 33) {
178  protocol33 = kFALSE;
179  // This resets the lists to avoid the problem fixed in protocol 33
180  fProof->SetParallel(0);
181  }
182 
183  //Make sure worker list is up-to-date
184  Build();
185 
186  TString sworkers = TString(workers).Strip(TString::kTrailing, 'x');
187  if (!sworkers.IsDigit()) {
188  Error("ActivateWorkers", "wrongly formatted argument: %s - cannot continue", workers);
189  return -1;
190  }
191  Int_t nworkersnode = sworkers.Atoi();
192  Int_t ret = nworkersnode;
193  TSlaveInfo *si = 0;
194  TList *node = 0;
195  TObject *key = 0;
196 
197  TIter nxk(fNodes);
198  while ((key = nxk()) != 0) {
199  if ((node = dynamic_cast<TList *>(fNodes->GetValue(key)))) {
200  TIter nxtworker(node);
201  Int_t nactiveworkers = 0;
202  while ((si = (TSlaveInfo *)(nxtworker()))) {
203  if (nactiveworkers < nworkersnode) {
204  if (si->fStatus == TSlaveInfo::kNotActive) {
205  if (protocol33) {
206  toactivate += TString::Format("%s,", si->GetOrdinal());
207  } else {
209  }
210  }
211  nactiveworkers++;
212  } else {
213  if (si->fStatus == TSlaveInfo::kActive) {
214  if (protocol33) {
215  todeactivate += TString::Format("%s,", si->GetOrdinal());
216  } else {
218  }
219  }
220  }
221  }
222  } else {
223  Warning("ActivateWorkers", "could not get list for node '%s'", key->GetName());
224  }
225  }
226 
227  if (!todeactivate.IsNull()) {
228  todeactivate.Remove(TString::kTrailing, ',');
229  if (fProof->DeactivateWorker(todeactivate) < 0) ret = -1;
230  }
231  if (!toactivate.IsNull()) {
232  toactivate.Remove(TString::kTrailing, ',');
233  if (fProof->ActivateWorker(toactivate) < 0) ret = -1;
234  }
235  if (ret < 0) {
236  Warning("ActivateWorkers", "could not get the requested number of workers per node (%d)",
237  nworkersnode);
238  return ret;
239  }
240 
241  // Rebuild
242  Build();
243 
244  // Build() destroyes fNodes so we need to re-create the iterator, resetting is not enough ...
245  TIter nxkn(fNodes);
246  while ((key = nxkn()) != 0) {
247  if ((node = dynamic_cast<TList *>(fNodes->GetValue(key)))) {
248  TIter nxtworker(node);
249  Int_t nactiveworkers = 0;
250  while ((si = (TSlaveInfo *)(nxtworker()))) {
251  if (si->fStatus == TSlaveInfo::kActive) nactiveworkers++;
252  }
253  if (nactiveworkers != nworkersnode) {
254  Warning("ActivateWorkers", "only %d (out of %d requested) workers "
255  "were activated on node %s",
256  nactiveworkers, nworkersnode, node->GetName());
257  ret = -1;
258  }
259  } else {
260  Warning("ActivateWorkers", "could not get list for node '%s'", key->GetName());
261  }
262  }
263 
264  // Done
265  return ret;
266 }
267 
268 ////////////////////////////////////////////////////////////////////////////////
269 /// Description: Print node information.
270 
271 void TProofNodes::Print(Option_t* option) const
272 {
273  TIter nxk(fNodes);
274  TObject *key = 0;
275  while ((key = nxk()) != 0) {
276  TList *node = dynamic_cast<TList *>(fNodes->GetValue(key));
277  if (node) {
278  node->Print(option);
279  } else {
280  Warning("Print", "could not get list for node '%s'", key->GetName());
281  }
282  }
283 }
virtual ~TProofNodes()
Destructor.
Definition: TProofNodes.cxx:41
const char * GetName() const
Returns name of object.
Definition: TProof.h:261
Collectable string class.
Definition: TObjString.h:32
const char Option_t
Definition: RtypesCore.h:62
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Int_t fNNodes
Definition: TProofNodes.h:37
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
Definition: TMap.cxx:53
const char * GetOrdinal() const
Definition: TProof.h:262
Basic string class.
Definition: TString.h:137
Int_t GetClientProtocol() const
Definition: TProof.h:944
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Int_t fNWrks
Definition: TProofNodes.h:38
void Print(Option_t *option="") const
Description: Print node information.
#define SafeDelete(p)
Definition: RConfig.h:507
TMap * fNodes
Definition: TProofNodes.h:33
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
ESlaveStatus fStatus
Definition: TProof.h:252
Int_t fMinWrksNode
Definition: TProofNodes.h:36
Int_t ActivateWorker(const char *ord, Bool_t save=kTRUE)
Make sure that the worker identified by the ordinal number &#39;ord&#39; is in the active list...
Definition: TProof.cxx:11325
TList * GetListOfSlaveInfos()
Returns list of TSlaveInfo&#39;s. In case of error return 0.
Definition: TProof.cxx:2299
TObject * Value() const
Definition: TMap.h:125
A doubly linked list.
Definition: TList.h:47
Int_t fCpus
Definition: TSystem.h:165
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:557
SysInfo_t fSysInfo
Definition: TProof.h:251
Int_t fMaxWrksNode
Definition: TProofNodes.h:35
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
TProof * fProof
Definition: TProofNodes.h:32
TMap * fActiveNodes
Definition: TProofNodes.h:34
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1070
void SetName(const char *name)
Definition: TCollection.h:116
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:106
#define ClassImp(name)
Definition: Rtypes.h:279
Int_t ActivateWorkers(Int_t nwrks)
Description: Activate &#39;nwrks&#39; workers; calls TProof::SetParallel and rebuild the internal lists Input...
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:44
Int_t fNActiveWrks
Definition: TProofNodes.h:39
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition: TProof.h:346
Int_t fNCores
Definition: TProofNodes.h:40
Bool_t IsNull() const
Definition: TString.h:387
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:204
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:214
virtual void Add(TObject *obj)
Definition: TList.h:81
Int_t GetRemoteProtocol() const
Definition: TProof.h:943
Int_t SetParallel(Int_t nodes=-1, Bool_t random=kFALSE)
Tell PROOF how many slaves to use in parallel.
Definition: TProof.cxx:7112
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:235
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1965
void Build()
Desctiption: Build the node list, which is a list of nodes whose members in turn are lists of workers...
Definition: TProofNodes.cxx:55
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition: TString.cxx:1807
Bool_t IsValid() const
Definition: TProof.h:967
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
virtual Int_t GetSize() const
Definition: TCollection.h:95
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t DeactivateWorker(const char *ord, Bool_t save=kTRUE)
Remove the worker identified by the ordinal number &#39;ord&#39; from the the active list.
Definition: TProof.cxx:11342
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911
virtual const char * GetName() const
Return name of this collection.
PROOF worker node information.
Definition: TProofNodes.h:30