ROOT  6.06/09
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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TProofNode //
15 // //
16 // PROOF worker node information //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 
20 #include "TProofNodes.h"
21 #include "TProof.h"
22 #include "TList.h"
23 #include "TMap.h"
24 #include "TObjString.h"
25 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Constructor
30 
32  : fProof(proof), fNodes(0), fActiveNodes(0),
33  fMaxWrksNode(-1), fMinWrksNode(-1),
34  fNNodes(0), fNWrks(0), fNActiveWrks(0), fNCores(0)
35 {
36  Build();
37 }
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Destructor
41 
43 {
44  if (fNodes) {
47  }
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Desctiption: Build the node list, which is a list of nodes whose members
52 /// in turn are lists of workers on the node.
53 /// Input: Nothing
54 /// Return: Nothing
55 
57 {
58  if (!fProof || !fProof->IsValid()) {
59  Warning("Build", "the PROOF instance is undefined or invalid! Cannot continue");
60  return;
61  }
62 
63  if (fNodes){
66  }
67  fNodes = new TMap;
69 
70  TList *slaves = fProof->GetListOfSlaveInfos();
71  TIter nxtslave(slaves);
72  TSlaveInfo *si = 0;
73  TList *node = 0;
74  TPair *pair = 0;
75  while ((si = (TSlaveInfo *)(nxtslave()))) {
76  TSlaveInfo *si_copy = (TSlaveInfo *)(si->Clone());
77  if (!(pair = (TPair *) fNodes->FindObject(si->GetName()))) {
78  node = new TList;
79  //si's are owned by the member fSlaveInfo of fProof
80  node->SetOwner(kTRUE);
81  node->SetName(si_copy->GetName());
82  node->Add(si_copy);
83  fNodes->Add(new TObjString(si->GetName()), node);
84  } else {
85  node = (TList *) pair->Value();
86  node->Add(si_copy);
87  }
88  }
89  // Update counters and created active nodes map
90  if (fActiveNodes){
93  }
94  fActiveNodes = new TMap;
96  TList *actnode = 0;
97  fMaxWrksNode = -1;
98  fMinWrksNode = -1;
99  fNNodes = 0;
100  fNWrks = 0;
101  fNActiveWrks = 0;
102  TIter nxk(fNodes);
103  TObject *key = 0;
104  while ((key = nxk()) != 0) {
105  node = dynamic_cast<TList *>(fNodes->GetValue(key));
106  if (node) {
107  fNNodes++;
108  // Number of cores
109  si = (TSlaveInfo *) node->First();
110  fNCores += si->fSysInfo.fCpus;
111  // Number of workers
112  fNWrks += node->GetSize();
113  if (fMinWrksNode == -1 || (node->GetSize() < fMinWrksNode)) {
114  fMinWrksNode = node->GetSize();
115  }
116  if (fMaxWrksNode == -1 || (node->GetSize() > fMaxWrksNode)) {
117  fMaxWrksNode = node->GetSize();
118  }
119  TIter nxw(node);
120  while ((si = (TSlaveInfo *) nxw())) {
121  if (si->fStatus == TSlaveInfo::kActive) {
122  fNActiveWrks++;
123  TSlaveInfo *si_copy = (TSlaveInfo *)(si->Clone());
124  actnode = dynamic_cast<TList *>(fActiveNodes->GetValue(key));
125  if (actnode) {
126  actnode->Add(si_copy);
127  } else {
128  actnode = new TList;
129  actnode->SetOwner(kTRUE);
130  actnode->SetName(si_copy->GetName());
131  actnode->Add(si_copy);
132  fActiveNodes->Add(new TObjString(si->GetName()), actnode);
133  }
134  }
135  }
136  } else {
137  Warning("Build", "could not get list for node '%s'", key->GetName());
138  }
139  }
140 
141  // Done
142  return;
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Description: Activate 'nwrks' workers; calls TProof::SetParallel and
147 /// rebuild the internal lists
148 /// Input: number of workers
149 /// Return: 0 is successful, <0 otherwise.
150 
152 {
153  Int_t nw = fProof->SetParallel(nwrks);
154  if (nw > 0) {
155  if (nw != nwrks)
156  Warning("ActivateWorkers", "requested %d got %d", nwrks, nw);
157  Build();
158  }
159  return nw;
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Description: Activate the same number of workers on all nodes.
164 /// Input: workers: string of the form "nx" where non-negative integer n
165 /// is the number of worker on each node to be activated.
166 /// Return: The number of active workers per node when the operation is
167 /// successful.
168 /// <0 otherwise.
169 
171 {
172  TString toactivate;
173  TString todeactivate;
174 
175  // The TProof::ActivateWorker/TProof::DeactivateWorker functions were fixed /
176  // improved starting with protocol version 33
177  Bool_t protocol33 = kTRUE;
178  if (fProof->GetRemoteProtocol() < 33 || fProof->GetClientProtocol() < 33) {
179  protocol33 = kFALSE;
180  // This resets the lists to avoid the problem fixed in protocol 33
181  fProof->SetParallel(0);
182  }
183 
184  //Make sure worker list is up-to-date
185  Build();
186 
187  TString sworkers = TString(workers).Strip(TString::kTrailing, 'x');
188  if (!sworkers.IsDigit()) {
189  Error("ActivateWorkers", "wrongly formatted argument: %s - cannot continue", workers);
190  return -1;
191  }
192  Int_t nworkersnode = sworkers.Atoi();
193  Int_t ret = nworkersnode;
194  TSlaveInfo *si = 0;
195  TList *node = 0;
196  TObject *key = 0;
197 
198  TIter nxk(fNodes);
199  while ((key = nxk()) != 0) {
200  if ((node = dynamic_cast<TList *>(fNodes->GetValue(key)))) {
201  TIter nxtworker(node);
202  Int_t nactiveworkers = 0;
203  while ((si = (TSlaveInfo *)(nxtworker()))) {
204  if (nactiveworkers < nworkersnode) {
205  if (si->fStatus == TSlaveInfo::kNotActive) {
206  if (protocol33) {
207  toactivate += TString::Format("%s,", si->GetOrdinal());
208  } else {
210  }
211  }
212  nactiveworkers++;
213  } else {
214  if (si->fStatus == TSlaveInfo::kActive) {
215  if (protocol33) {
216  todeactivate += TString::Format("%s,", si->GetOrdinal());
217  } else {
219  }
220  }
221  }
222  }
223  } else {
224  Warning("ActivateWorkers", "could not get list for node '%s'", key->GetName());
225  }
226  }
227 
228  if (!todeactivate.IsNull()) {
229  todeactivate.Remove(TString::kTrailing, ',');
230  if (fProof->DeactivateWorker(todeactivate) < 0) ret = -1;
231  }
232  if (!toactivate.IsNull()) {
233  toactivate.Remove(TString::kTrailing, ',');
234  if (fProof->ActivateWorker(toactivate) < 0) ret = -1;
235  }
236  if (ret < 0) {
237  Warning("ActivateWorkers", "could not get the requested number of workers per node (%d)",
238  nworkersnode);
239  return ret;
240  }
241 
242  // Rebuild
243  Build();
244 
245  // Build() destroyes fNodes so we need to re-create the iterator, resetting is not enough ...
246  TIter nxkn(fNodes);
247  while ((key = nxkn()) != 0) {
248  if ((node = dynamic_cast<TList *>(fNodes->GetValue(key)))) {
249  TIter nxtworker(node);
250  Int_t nactiveworkers = 0;
251  while ((si = (TSlaveInfo *)(nxtworker()))) {
252  if (si->fStatus == TSlaveInfo::kActive) nactiveworkers++;
253  }
254  if (nactiveworkers != nworkersnode) {
255  Warning("ActivateWorkers", "only %d (out of %d requested) workers "
256  "were activated on node %s",
257  nactiveworkers, nworkersnode, node->GetName());
258  ret = -1;
259  }
260  } else {
261  Warning("ActivateWorkers", "could not get list for node '%s'", key->GetName());
262  }
263  }
264 
265  // Done
266  return ret;
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// Description: Print node information.
271 
272 void TProofNodes::Print(Option_t* option) const
273 {
274  TIter nxk(fNodes);
275  TObject *key = 0;
276  while ((key = nxk()) != 0) {
277  TList *node = dynamic_cast<TList *>(fNodes->GetValue(key));
278  if (node) {
279  node->Print(option);
280  } else {
281  Warning("Print", "could not get list for node '%s'", key->GetName());
282  }
283  }
284 }
virtual ~TProofNodes()
Destructor.
Definition: TProofNodes.cxx:42
Bool_t IsValid() const
Definition: TProof.h:970
virtual const char * GetName() const
Return name of this collection.
Collectable string class.
Definition: TObjString.h:32
Int_t GetRemoteProtocol() const
Definition: TProof.h:946
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:52
const char * GetOrdinal() const
Definition: TProof.h:255
Basic string class.
Definition: TString.h:137
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
#define SafeDelete(p)
Definition: RConfig.h:436
void Print(Option_t *option="") const
Description: Print node information.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:203
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:2334
ESlaveStatus fStatus
Definition: TProof.h:245
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:234
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1964
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
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 'ord' is in the active list...
Definition: TProof.cxx:11920
TList * GetListOfSlaveInfos()
Returns list of TSlaveInfo's. In case of error return 0.
Definition: TProof.cxx:2316
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:213
A doubly linked list.
Definition: TList.h:47
ClassImp(TProofNodes) TProofNodes
Constructor.
Definition: TProofNodes.cxx:26
Int_t fCpus
Definition: TSystem.h:165
SysInfo_t fSysInfo
Definition: TProof.h:244
Int_t fMaxWrksNode
Definition: TProofNodes.h:35
TObject * Value() const
Definition: TMap.h:125
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:1069
Bool_t IsNull() const
Definition: TString.h:387
void SetName(const char *name)
Definition: TCollection.h:116
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:106
virtual Int_t GetSize() const
Definition: TCollection.h:95
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
Int_t ActivateWorkers(Int_t nwrks)
Description: Activate 'nwrks' 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
Definition: TProof.h:339
Int_t fNCores
Definition: TProofNodes.h:40
const char * GetName() const
Returns name of object.
Definition: TProof.h:254
Mother of all ROOT objects.
Definition: TObject.h:58
const char Int_t const char TProof * proof
Definition: TXSlave.cxx:46
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:556
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition: TString.cxx:1806
virtual void Add(TObject *obj)
Definition: TList.h:81
Int_t SetParallel(Int_t nodes=-1, Bool_t random=kFALSE)
Tell PROOF how many slaves to use in parallel.
Definition: TProof.cxx:7127
ClassImp(TSlaveInfo) Int_t TSlaveInfo const TSlaveInfo * si
Used to sort slaveinfos by ordinal.
Definition: TProof.cxx:167
Int_t GetClientProtocol() const
Definition: TProof.h:947
void Build()
Desctiption: Build the node list, which is a list of nodes whose members in turn are lists of workers...
Definition: TProofNodes.cxx:56
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 'ord' from the the active list.
Definition: TProof.cxx:11937
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904