forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkMultiProcessController.cxx
799 lines (698 loc) · 23.9 KB
/
vtkMultiProcessController.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/*=========================================================================
Program: Visualization Toolkit
Module: vtkMultiProcessController.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This will be the default.
#include "vtkMultiProcessController.h"
#include "vtkByteSwap.h"
#include "vtkCollection.h"
#include "vtkCommand.h"
#include "vtkDummyController.h"
#include "vtkObjectFactory.h"
#include "vtkOutputWindow.h"
#include "vtkProcessGroup.h"
#include "vtkSubCommunicator.h"
#include "vtkToolkits.h"
#include "vtkProcess.h"
#include "vtkSmartPointer.h"
#include "vtkWeakPointer.h"
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
#include <list>
#include <vector>
#include <vtksys/hash_map.hxx>
//-----------------------------------------------------------------------------
// Stores internal members that cannot or should not be exposed in the header
// file (for example, because they use templated types).
class vtkMultiProcessController::vtkInternal
{
public:
vtksys::hash_map<int, vtkProcessFunctionType> MultipleMethod;
vtksys::hash_map<int, void *> MultipleData;
class vtkRMICallback
{
public:
unsigned long Id;
vtkRMIFunctionType Function;
void* LocalArgument;
};
typedef std::vector<vtkRMICallback> RMICallbackVector;
// key == tag, value == vector of vtkRMICallback instances.
typedef vtksys::hash_map<int, RMICallbackVector> RMICallbackMap;
RMICallbackMap RMICallbacks;
};
//----------------------------------------------------------------------------
// An RMI function that will break the "ProcessRMIs" loop.
static void vtkMultiProcessControllerBreakRMI(void *localArg,
void *remoteArg, int remoteArgLength,
int vtkNotUsed(remoteId))
{
(void)remoteArg;
(void)remoteArgLength;
vtkMultiProcessController *controller = (vtkMultiProcessController*)(localArg);
controller->SetBreakFlag(1);
}
// ----------------------------------------------------------------------------
// Single method used when launching a single process.
static void vtkMultiProcessControllerRun(vtkMultiProcessController *c,
void *arg)
{
vtkProcess *p=reinterpret_cast<vtkProcess *>(arg);
p->SetController(c);
p->Execute();
}
//----------------------------------------------------------------------------
vtkMultiProcessController::vtkMultiProcessController()
{
this->Internal = new vtkInternal;
this->RMICount = 1;
this->SingleMethod = 0;
this->SingleData = 0;
this->Communicator = 0;
this->RMICommunicator = 0;
this->BreakFlag = 0;
this->ForceDeepCopy = 1;
this->BroadcastTriggerRMI = false;
this->OutputWindow = 0;
// Define an rmi internally to exit from the processing loop.
this->AddRMI(vtkMultiProcessControllerBreakRMI, this, BREAK_RMI_TAG);
}
//----------------------------------------------------------------------------
// This is an old comment that I do not know is true:
// (We need to have a "GetNetReferenceCount" to avoid memory leaks.)
vtkMultiProcessController::~vtkMultiProcessController()
{
if ( this->OutputWindow &&
(this->OutputWindow == vtkOutputWindow::GetInstance()) )
{
vtkOutputWindow::SetInstance(0);
}
if (this->OutputWindow)
{
this->OutputWindow->Delete();
}
delete this->Internal;
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
vtkIndent nextIndent = indent.GetNextIndent();
os << indent << "Break flag: " << (this->BreakFlag ? "(yes)" : "(no)")
<< endl;
os << indent << "Force deep copy: " << (this->ForceDeepCopy ? "(yes)" : "(no)")
<< endl;
os << indent << "Output window: ";
os << indent << "BroadcastTriggerRMI: " <<
(this->BroadcastTriggerRMI ? "(yes)" : "(no)");
if (this->OutputWindow)
{
os << endl;
this->OutputWindow->PrintSelf(os, nextIndent);
}
else
{
os << "(none)" << endl;
}
os << indent << "Communicator: ";
if (this->Communicator)
{
os << endl;
this->Communicator->PrintSelf(os, nextIndent);
}
else
{
os << "(none)" << endl;
}
os << indent << "RMI communicator: ";
if (this->RMICommunicator)
{
os << endl;
this->RMICommunicator->PrintSelf(os, nextIndent);
}
else
{
os << "(none)" << endl;
}
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::SetNumberOfProcesses(int num)
{
if(this->Communicator)
{
this->Communicator->SetNumberOfProcesses(num);
}
else
{
vtkErrorMacro("Communicator not set.");
}
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::GetNumberOfProcesses()
{
if(this->Communicator)
{
return this->Communicator->GetNumberOfProcesses();
}
else
{
vtkErrorMacro("Communicator not set.");
return 0;
}
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::GetLocalProcessId()
{
if(this->Communicator)
{
return this->Communicator->GetLocalProcessId();
}
else
{
vtkErrorMacro("Communicator not set.");
return -1;
}
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::SetSingleMethod( vtkProcessFunctionType f,
void *data )
{
this->SingleMethod = f;
this->SingleData = data;
}
// ----------------------------------------------------------------------------
void vtkMultiProcessController::SetSingleProcessObject(vtkProcess *p)
{
this->SetSingleMethod(vtkMultiProcessControllerRun,p);
}
//----------------------------------------------------------------------------
// Set one of the user defined methods that will be run on NumberOfProcesses
// processes when MultipleMethodExecute is called. This method should be
// called with index = 0, 1, .., NumberOfProcesses-1 to set up all the
// required user defined methods
void vtkMultiProcessController::SetMultipleMethod( int index,
vtkProcessFunctionType f, void *data )
{
// You can only set the method for 0 through NumberOfProcesses-1
if ( index >= this->GetNumberOfProcesses() )
{
vtkErrorMacro( << "Can't set method " << index <<
" with a processes count of " << this->GetNumberOfProcesses() );
}
else
{
this->Internal->MultipleMethod[index] = f;
this->Internal->MultipleData[index] = data;
}
}
//-----------------------------------------------------------------------------
void vtkMultiProcessController::GetMultipleMethod(int index,
vtkProcessFunctionType &func,
void *&data)
{
if ( this->Internal->MultipleMethod.find(index)
!= this->Internal->MultipleMethod.end() )
{
func = this->Internal->MultipleMethod[index];
data = this->Internal->MultipleData[index];
}
else
{
func = NULL;
data = NULL;
}
}
//-----------------------------------------------------------------------------
vtkMultiProcessController *vtkMultiProcessController::CreateSubController(
vtkProcessGroup *group)
{
if (group->GetCommunicator() != this->Communicator)
{
vtkErrorMacro(<< "Invalid group for creating a sub controller.");
return NULL;
}
if (group->FindProcessId(this->GetLocalProcessId()) < 0)
{
// The group does not contain this process. Just return NULL.
return NULL;
}
vtkSubCommunicator *subcomm = vtkSubCommunicator::New();
subcomm->SetGroup(group);
// We only need a basic implementation of vtkMultiProcessController for the
// subgroup, so we just use vtkDummyController here. It's a bit of a misnomer
// and may lead to confusion, but I think it's better than creating yet
// another class we have to maintain.
vtkDummyController *subcontroller = vtkDummyController::New();
subcontroller->SetCommunicator(subcomm);
subcontroller->SetRMICommunicator(subcomm);
subcomm->Delete();
return subcontroller;
}
//-----------------------------------------------------------------------------
vtkMultiProcessController *vtkMultiProcessController::PartitionController(
int localColor,
int localKey)
{
vtkMultiProcessController *subController = NULL;
int numProc = this->GetNumberOfProcesses();
std::vector<int> allColors(numProc);
this->AllGather(&localColor, &allColors[0], 1);
std::vector<int> allKeys(numProc);
this->AllGather(&localKey, &allKeys[0], 1);
std::vector<bool> inPartition;
inPartition.assign(numProc, false);
for (int i = 0; i < numProc; i++)
{
if (inPartition[i]) continue;
int targetColor = allColors[i];
std::list<int> partitionIds; // Make sorted list, then put in group.
for (int j = i; j < numProc; j++)
{
if (allColors[j] != targetColor) continue;
inPartition[j] = true;
std::list<int>::iterator iter = partitionIds.begin();
while ((iter != partitionIds.end()) && (allKeys[*iter] <= allKeys[j]))
{
iter++;
}
partitionIds.insert(iter, j);
}
// Copy list into process group.
VTK_CREATE(vtkProcessGroup, group);
group->Initialize(this);
group->RemoveAllProcessIds();
for (std::list<int>::iterator iter = partitionIds.begin();
iter != partitionIds.end(); iter++)
{
group->AddProcessId(*iter);
}
// Use group to create controller.
vtkMultiProcessController *sc = this->CreateSubController(group);
if (sc)
{
subController = sc;
}
}
return subController;
}
//----------------------------------------------------------------------------
unsigned long vtkMultiProcessController::AddRMICallback(
vtkRMIFunctionType callback, void* localArg, int tag)
{
vtkInternal::vtkRMICallback callbackInfo;
callbackInfo.Id = this->RMICount++;
callbackInfo.Function = callback;
callbackInfo.LocalArgument = localArg;
this->Internal->RMICallbacks[tag].push_back(callbackInfo);
return callbackInfo.Id;
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::RemoveAllRMICallbacks(int tag)
{
vtkInternal::RMICallbackMap::iterator iter =
this->Internal->RMICallbacks.find(tag);
if (iter != this->Internal->RMICallbacks.end())
{
this->Internal->RMICallbacks.erase(iter);
}
}
//----------------------------------------------------------------------------
bool vtkMultiProcessController::RemoveRMICallback(unsigned long id)
{
vtkInternal::RMICallbackMap::iterator iterMap;
for (iterMap = this->Internal->RMICallbacks.begin();
iterMap != this->Internal->RMICallbacks.end(); ++iterMap)
{
vtkInternal::RMICallbackVector::iterator iterVec;
for (iterVec = iterMap->second.begin();
iterVec != iterMap->second.end(); ++iterVec)
{
if (iterVec->Id == id)
{
iterMap->second.erase(iterVec);
return true;
}
}
}
return false;
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::RemoveFirstRMI(int tag)
{
vtkInternal::RMICallbackMap::iterator iter =
this->Internal->RMICallbacks.find(tag);
if (iter != this->Internal->RMICallbacks.end())
{
if (iter->second.begin() != iter->second.end())
{
iter->second.erase(iter->second.begin());
return 1;
}
}
return 0;
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::RemoveRMI(unsigned long id)
{
return this->RemoveRMICallback(id)? 1 : 0;
}
//----------------------------------------------------------------------------
unsigned long vtkMultiProcessController::AddRMI(vtkRMIFunctionType f,
void *localArg, int tag)
{
// Remove any previously registered RMI handler for the tag.
this->RemoveAllRMICallbacks(tag);
return this->AddRMICallback(f, localArg, tag);
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::TriggerRMIOnAllChildren(
void *arg, int argLength, int rmiTag)
{
if( this->BroadcastTriggerRMI )
{
this->BroadcastTriggerRMIOnAllChildren(arg,argLength,rmiTag);
} // END if use broadcast method
else
{
int myid = this->GetLocalProcessId();
int childid = 2 * myid + 1;
int numProcs = this->GetNumberOfProcesses();
if (numProcs > childid)
{
this->TriggerRMIInternal(childid, arg, argLength, rmiTag, true);
}
childid++;
if (numProcs > childid)
{
this->TriggerRMIInternal(childid, arg, argLength, rmiTag, true);
}
} // END else
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::TriggerRMI(int remoteProcessId,
void *arg, int argLength,
int rmiTag)
{
if( this->BroadcastTriggerRMI )
{
vtkErrorMacro(
"TriggerRMI should not be called when BroadcastTriggerRMI is ON");
}
// Deal with sending RMI to ourself here for now.
if (remoteProcessId == this->GetLocalProcessId())
{
this->ProcessRMI(remoteProcessId, arg, argLength, rmiTag);
return;
}
this->TriggerRMIInternal(remoteProcessId, arg, argLength, rmiTag, false);
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::BroadcastTriggerRMIOnAllChildren(
void *arg, int argLength, int rmiTag)
{
// This is called by the root process, namely rank 0. The sattelite ranks
// call BroadcastProcessRMIs().
int triggerMessage[128];
triggerMessage[0] = rmiTag;
triggerMessage[1] = argLength;
// Note: We don't need to set the local process ID & propagate
// We send the header in Little Endian order.
vtkByteSwap::SwapLERange(triggerMessage, 2);
// If possible, send the data over a single broadcast
int buffer_size = sizeof(int)*(126 /*128-2*/);
if( (argLength >= 0) && (argLength < buffer_size) )
{
if( argLength > 0 )
{
memcpy(&triggerMessage[2],arg,argLength);
}
this->RMICommunicator->Broadcast(triggerMessage,128,0);
}
else
{
this->RMICommunicator->Broadcast(triggerMessage,128,0);
this->RMICommunicator->Broadcast(
reinterpret_cast<unsigned char*>(arg),argLength,0);
}
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::BroadcastProcessRMIs(
int vtkNotUsed(reportErrors), int dont_loop )
{
int triggerMessage[128];
int rmiTag;
int argLength;
unsigned char *arg = NULL;
int error = RMI_NO_ERROR;
this->InvokeEvent(vtkCommand::StartEvent);
do
{
this->RMICommunicator->Broadcast(triggerMessage,128,0);
#ifdef VTK_WORDS_BIGENDIAN
// Header is sent in little-endian form. We need to convert it to big
// endian.
vtkByteSwap::SwapLERange(triggerMessage, 2);
#endif
rmiTag = triggerMessage[0];
argLength = triggerMessage[1];
if( argLength > 0 )
{
arg = new unsigned char[ argLength ];
int buffer_size = sizeof(int)*(126 /*128-2*/);
if( argLength < buffer_size )
{
memcpy(arg,&triggerMessage[2],argLength);
} // END if message is inline
else
{
this->RMICommunicator->Broadcast(arg,argLength,0);
} // END else message was not inline
} // END if non-null arguments
this->ProcessRMI(0 /*we broadcast from rank 0*/, arg, argLength,rmiTag);
delete [] arg;
arg = NULL;
// check for break
if (this->BreakFlag)
{
this->BreakFlag = 0;
this->InvokeEvent(vtkCommand::EndEvent);
return error;
}
} while( !dont_loop );
this->InvokeEvent(vtkCommand::EndEvent);
return error;
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::TriggerRMIInternal(int remoteProcessId,
void* arg, int argLength, int rmiTag, bool propagate)
{
int triggerMessage[128];
triggerMessage[0] = rmiTag;
triggerMessage[1] = argLength;
// It is important for the remote process to know what process invoked it.
// Multiple processes might try to invoke the method at the same time.
// The remote method will know where to get additional args.
triggerMessage[2] = this->GetLocalProcessId();
// Pass the propagate flag.
triggerMessage[3] = propagate? 1 : 0;
// We send the header in Little Endian order.
vtkByteSwap::SwapLERange(triggerMessage, 4);
// If the message is small, we will try to get the message sent over using a
// single Send(), rather than two. This helps speed up communication
// significantly, since sending multiple small messages is generally slower
// than sending a single large message.
if (argLength >= 0 && static_cast<unsigned int>(argLength) < sizeof(int)*(128-4))
{
if (argLength > 0)
{
memcpy(&triggerMessage[4], arg, argLength);
}
int num_bytes = static_cast<int>(4*sizeof(int)) + argLength;
this->RMICommunicator->Send(reinterpret_cast<unsigned char*>(triggerMessage),
num_bytes, remoteProcessId, RMI_TAG);
}
else
{
this->RMICommunicator->Send(
reinterpret_cast<unsigned char*>(triggerMessage),
static_cast<int>(4*sizeof(int)), remoteProcessId, RMI_TAG);
if (argLength > 0)
{
this->RMICommunicator->Send((char*)arg, argLength, remoteProcessId,
RMI_ARG_TAG);
}
}
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::TriggerBreakRMIs()
{
int idx, num;
if( this->BroadcastTriggerRMI == 1 )
{
this->BroadcastTriggerRMIOnAllChildren(NULL,0,BREAK_RMI_TAG);
return;
}
if (this->GetLocalProcessId() != 0)
{
vtkErrorMacro("Break should be triggered from process 0.");
return;
}
num = this->GetNumberOfProcesses();
for (idx = 1; idx < num; ++idx)
{
this->TriggerRMI(idx, NULL, 0, BREAK_RMI_TAG);
}
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::ProcessRMIs()
{
return this->ProcessRMIs(1, 0);
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::ProcessRMIs(int reportErrors, int dont_loop)
{
if( this->BroadcastTriggerRMI )
{
return this->BroadcastProcessRMIs(reportErrors,dont_loop);
}
this->InvokeEvent(vtkCommand::StartEvent);
int triggerMessage[128];
unsigned char *arg = NULL;
int error = RMI_NO_ERROR;
do
{
if (!this->RMICommunicator->Receive(
reinterpret_cast<unsigned char*>(triggerMessage),
static_cast<vtkIdType>(128*sizeof(int)), ANY_SOURCE, RMI_TAG) ||
this->RMICommunicator->GetCount() < static_cast<int>(4*sizeof(int)))
{
if (reportErrors)
{
vtkErrorMacro("Could not receive RMI trigger message.");
}
error = RMI_TAG_ERROR;
break;
}
#ifdef VTK_WORDS_BIGENDIAN
// Header is sent in little-endian form. We need to convert it to big
// endian.
vtkByteSwap::SwapLERange(triggerMessage, 4);
#endif
if (triggerMessage[1] > 0)
{
arg = new unsigned char[triggerMessage[1]];
// If the message length is small enough, the TriggerRMIInternal() call
// packs the message data inline. So depending on the message length we
// use the inline data or make a second receive to fetch the data.
if (static_cast<unsigned int>(triggerMessage[1]) < sizeof(int)*(128-4))
{
int num_bytes = static_cast<int>(4 *sizeof(int)) + triggerMessage[1];
if (this->RMICommunicator->GetCount() != num_bytes)
{
if (reportErrors)
{
vtkErrorMacro("Could not receive the RMI argument in its entirety.");
}
error= RMI_ARG_ERROR;
break;
}
memcpy(arg, &triggerMessage[4], triggerMessage[1]);
}
else
{
if (!this->RMICommunicator->Receive((char*)(arg), triggerMessage[1],
triggerMessage[2], RMI_ARG_TAG) ||
this->RMICommunicator->GetCount() != triggerMessage[1])
{
if (reportErrors)
{
vtkErrorMacro("Could not receive RMI argument.");
}
error = RMI_ARG_ERROR;
break;
}
}
}
if (triggerMessage[3] == 1 && this->GetNumberOfProcesses() > 3)//propagate==true
{
this->TriggerRMIOnAllChildren(arg, triggerMessage[1], triggerMessage[0]);
}
this->ProcessRMI(triggerMessage[2], arg, triggerMessage[1],
triggerMessage[0]);
delete [] arg;
arg = NULL;
// check for break
if (this->BreakFlag)
{
this->BreakFlag = 0;
this->InvokeEvent(vtkCommand::EndEvent);
return error;
}
} while (!dont_loop);
this->InvokeEvent(vtkCommand::EndEvent);
return error;
}
//----------------------------------------------------------------------------
void vtkMultiProcessController::ProcessRMI(int remoteProcessId,
void *arg, int argLength,
int rmiTag)
{
// we build the list of callbacks to call and then invoke them to handle the
// case where the callback removes the callback.
std::vector<vtkInternal::vtkRMICallback> callbacks;
vtkInternal::RMICallbackMap::iterator iter =
this->Internal->RMICallbacks.find(rmiTag);
if (iter != this->Internal->RMICallbacks.end())
{
vtkInternal::RMICallbackVector::iterator iterVec;
for (iterVec = iter->second.begin();
iterVec != iter->second.end(); iterVec++)
{
if (iterVec->Function)
{
callbacks.push_back(*iterVec);
}
}
}
if (callbacks.size()==0)
{
vtkErrorMacro("Process " << this->GetLocalProcessId() <<
" Could not find RMI with tag " << rmiTag);
}
std::vector<vtkInternal::vtkRMICallback>::iterator citer;
for (citer = callbacks.begin(); citer != callbacks.end(); citer++)
{
(*citer->Function)(citer->LocalArgument, arg, argLength, remoteProcessId);
}
}
//============================================================================
// The intent is to give access to a processes controller from a static method.
static vtkWeakPointer<vtkMultiProcessController> VTK_GLOBAL_MULTI_PROCESS_CONTROLLER;
//----------------------------------------------------------------------------
vtkMultiProcessController *vtkMultiProcessController::GetGlobalController()
{
if (VTK_GLOBAL_MULTI_PROCESS_CONTROLLER == NULL)
{
return NULL;
}
return VTK_GLOBAL_MULTI_PROCESS_CONTROLLER->GetLocalController();
}
//----------------------------------------------------------------------------
// This can be overridden in the subclass to translate controllers.
vtkMultiProcessController *vtkMultiProcessController::GetLocalController()
{
return VTK_GLOBAL_MULTI_PROCESS_CONTROLLER;
}
//----------------------------------------------------------------------------
// This can be overridden in the subclass to translate controllers.
void vtkMultiProcessController::SetGlobalController(
vtkMultiProcessController *controller)
{
VTK_GLOBAL_MULTI_PROCESS_CONTROLLER = controller;
}