This repository was archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMWDriver.h
3022 lines (2448 loc) · 73.5 KB
/
MWDriver.h
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// MWDriver.h
//
// TODO: replace print styles with stream operators
//
// This provides an implementation of the MW API defined by
// MWAbstractDriver. This design assumes:
// 1. Checkpointing is only done on the master
// 2.
//
#ifndef __MWDriver
#define __MWDriver
#include <string>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <map>
#include <list>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <cstdarg>
#include <cerrno>
#include <cstdio>
#include <netdb.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "MW.h"
#include "MWWorkerID.h"
#include "MWWorker.h"
#include "MWTask.h"
#include "MWGroup.h"
#ifdef MWSTATS
#include "MWStats.h"
#endif
template <class CommType>
class MWDriver : public MWAbstractDriver<CommType> {
friend class MWTask<CommType>;
public:
/**@name Main Routines */
//@{
///
MWDriver();
///
virtual ~MWDriver();
//@}
/**@name Worker Management */
//@{
///
int numWorkers() const
{return workers.size();}
///
int numActiveWorkers() const
{return active_workers.size();}
///
int numWorkers( int arch ) const;
///
int numWorkersInState( typename MWBase::MWworker_states ThisState ) const;
///
void printWorkers() const;
//@}
/**@name Task Management */
//@{
///
int numTasksTodo()
{return todo.size();}
///
int numTasksRunning()
{return running_tasks.size();}
///
int delete_tasks_greater_than( typename MWBase::MWKey );
///
int print_task_keys( void );
/// Returns the value (only) of the best key in the Todo list
typename MWBase::MWKey min_todo_keyval() {return 0.0;}
//{return min_element(todo.begin(), todo.last());}
/// Returns the best value (only) of the best key in the Running list.
typename MWBase::MWKey min_running_keyval( ) {return 0.0;}
//{return min_element(runningfirst(), running.last());}
//@}
/** @name Checkpoint Management */
//@{
///
void checkpoint();
///
bool checkpoint_data_exists();
///
void restart_from_ckpt();
///
void checkpoint_end();
//@}
#ifdef XML_OUTPUT
/** @name XML I/O Management */
//@{
///
void write_XML_status();
///
virtual char* get_XML_results_status(void );
//@}
#endif
protected:
/** @name Protected Main Routines */
//@{
/** A function to support the execution of MWDriver from a GUI
control panel. */
void ControlPanel ( );
///
bool send_task_to_worker( MWWorkerID<CommType> *w );
///
void rematch_tasks_to_workers( MWWorkerID<CommType> *nosend );
///
void call_hostaddlogic();
///
void terminate_workers();
/** This is called in both handle_hostdelete and handle_taskexit.
It removes the host from our records and cleans up
relevent pointers with the task it's running. */
void hostPostmortem ( MWWorkerID<CommType> *w );
#ifdef MWSTATS
///
void collect_statistics();
/** The instance of the stats class that takes workers and later
prints out relevant stats...
*/
MWStatistics<MWWorkerID<CommType>,CommType>* stats;
#endif
/// This returns the hostname
const char *getHostName ();
//@}
/**@name Protected MainLoop Management */
//@{
///
typename MWDriver<CommType>::MWReturn handle_worker_results( MWWorkerID<CommType>* w );
///
typename MWDriver<CommType>::MWReturn handle_benchmark( MWWorkerID<CommType> *w );
///
void handle_hostdel();
///
void handle_hostsuspend();
///
void handle_hostresume();
///
void handle_taskexit();
///
void handle_checksum ();
//@}
/** @name Protected Task Management
*/
//@{
/// Add a task to the list. The MWDriver assumes ownership of the task.
void addTask( MWTask<CommType>* task );
/** Add a bunch of tasks to the list. You do this by making
an array of pointers to MWTasks and giving that array to
this function. The MWDriver assumes ownership of the tasks. */
void addTasks( vector<MWTask<CommType>*>& tasklist)
{
for (size_t i=0; i<tasklist.size(); i++)
addTask(tasklist[i]);
}
/** Go through the list of timed out WORKING workers and reschedule tasks */
void reassign_tasks_timedout_workers(bool& busy);
/// This puts a (generally failed) task at the beginning of the list
void pushTask( MWTask<CommType> * );
/// Get the next task from the todo list.
virtual MWTask<CommType>* getNextTask( MWGroup& grp );
/// Removes a task from the set of running tasks
MWTask<CommType>* remove_running_task( int tasknum )
{
typename map<int,MWTask<CommType>*>::iterator iter = running_tasks.find(tasknum);
if (iter == running_tasks.end())
return 0;
MWTask<CommType>* tmp = iter->second;
running_tasks.erase(iter);
return tmp;
}
/// Print the tasks in the list of tasks to do
void print_running_tasks();
/** Add one task to the todo list; do NOT set the 'number' of
the task - useful in restarting from a checkpoint */
void ckpt_addTask(MWTask<CommType>* task)
{pushTask(task);}
/// returns the worker this task is assigned to, NULL if none.
MWWorkerID<CommType>* task_assigned( MWTask<CommType> *t )
{return t->worker;}
/// Assign a task to a worker and send a message to the worker.
void assign_task_to_worker ( MWWorkerID<CommType>* w, MWTask<CommType>* t );
/// Release a worker
void release_worker (MWWorkerID<CommType>* w, MWTask<CommType>* t)
{
t->worker=NULL;
w->runningtask=NULL;
}
/** MWDriver keeps a unique identifier for each task --
here's the counter */
int task_counter;
/** A map of tasknum to task object for running tasks.
* The todo list may be ordered in some arbitrary order. However, we
* frequently need to find a running task given its number. It might be
* more efficient to do this with a hash table, but they aren't part of the
* STL standard just yet. */
map<int,MWTask<CommType>*> running_tasks;
/** The list of tasks to do.
* This list may be reordered, so iterators pointing into it may become
* invalid.
*/
list<MWTask<CommType>*> todo;
//@}
/** @name Protected Worker Management
*/
//@{
///
bool worker_marked_for_removal(MWWorkerID<CommType>* w)
{return w->is_doomed();}
///
void worker_add ( MWWorkerID<CommType> *w );
/// Looks up information about a worker given its task ID
MWWorkerID<CommType> * worker_find( int tid, bool erase_flag=false )
{
typename map<int,MWWorkerID<CommType>*>::iterator iter = workers.find(tid);
if (iter == workers.end())
return 0;
MWWorkerID<CommType>* tmp = iter->second;
if (erase_flag)
workers.erase(iter);
return tmp;
}
///
typename MWDriver<CommType>::MWReturn worker_init( MWWorkerID<CommType> *w );
/// This function removes worker from the list, removes it and deletes
/// the structure.
void worker_terminate( MWWorkerID<CommType> *w );
/// Based on the worker ordering policy, reorder the workers list appropriately
void reorder_workers();
/** A map of host_id to worker object.
* The workers list may be ordered in some arbitrary order. However, we
* frequently need to find a worker given its id. It might be more efficient
* to do this with a hash table, but they aren't part of the STL standard
* just yet. */
map<int,MWWorkerID<CommType>*> workers;
/** The list of idle workers.
* This list may be reordered to prioritize the workers, so iterators
* into this list may become invalid. */
list<MWWorkerID<CommType>*> idle_workers;
/** The list of active workers.
* These will usually be running. If a running worker stops working, then
* the master will remove it. The running tasks are associated
* with these running workers, so we don't keep a seperate structure for them.
*/
list<MWWorkerID<CommType>*> active_workers;
/** Move this workere into the appropriate list (idle/active) based on
* its current state.
*/
void update_worker_state(MWWorkerID<CommType>* w);
/** A class that is used to record the state of a worker in the
* MWDriver.
*/
template <class CommType_>
class MWWorkerState {
public:
bool sflag;
typename list<MWWorkerID<CommType_>*>::iterator iter;
};
/** Maps worker id1's to a MWWorkerState object, which has info
* about whether a worker is recorded as idle or active.
*/
map<int,MWWorkerState<CommType>*> worker_state;
//@}
/** @name Protected Checkpointing Management */
//@{
/** The name of the checkpoint file */
string ckpt_filename;
//@}
#if defined( XML_OUTPUT )
/**@name XML and Status Methods.
This function is called by the CORBA layer to get the
XML status of the MWDriver.
*/
//@{
/// Returns the sum of the bench results for the currently working machines
double get_instant_pool_perf();
///
char* get_XML_status();
///
char* get_XML_job_information();
///
char* get_XML_problem_description();
///
char* get_XML_interface_remote_files();
///
char* get_XML_resources_status();
///
const char *xml_filename;
///
const char *xml_menus_filename;
///
const char *xml_jobinfo_filename;
///
const char *xml_pbdescrib_filename;
/// Set the current machine information
void get_machine_info();
/// Returns a pointer to the machine's Arch
char *get_Arch(){ return Arch; }
/// Returns a pointer to the machine's OpSys
char *get_OpSys(){ return OpSys; }
/// Returns a pointer to the machine's IPAddress
char *get_IPAddress(){ return IPAddress; }
///
double get_CondorLoadAvg(){ return CondorLoadAvg; }
///
double get_LoadAvg(){ return LoadAvg; }
///
int get_Memory(){return Memory;}
///
int get_Cpus(){return Cpus;}
///
int get_VirtualMemory(){return VirtualMemory;}
///
int get_Disk(){return Disk;}
///
int get_KFlops(){return KFlops;}
///
int get_Mips(){return Mips;}
///
char Arch[64];
///
char OpSys[64];
///
char IPAddress[64];
///
double CondorLoadAvg;
///
double LoadAvg;
///
int Memory;
///
int Cpus;
///
int VirtualMemory;
///
int Disk;
///
int KFlops;
///
int Mips;
/// Utility functions used by get_machine info
int check_for_int_val(char* name, char* key, char* value);
double check_for_float_val(char* name, char* key, char* value);
int check_for_string_val(char* name, char* key, char* value);
//@}
#endif
#ifdef NWSENABLED
/// The name of the machine the worker is running on.
char mach_name[64];
/// for measuring network connectivity
double defaultTimeInterval;
///
int defaultIterations;
///
int defaultPortNo;
time_t nws_measurement_period;
time_t next_nws_measurement_check;
int nws_nameserver_port;
int nws_memory_port;
int nws_sensor_port;
void do_nws_measurements ( );
void lookupWorkerAndsetConnectivity ( char *host, double latency );
void start_nws_daemons ( );
#endif
};
////--------------------------------------------------------
////
//// Main Routines
////
////--------------------------------------------------------
//============================================================================
//
//
template <class CommType>
MWDriver<CommType>::MWDriver()
: task_counter(0),
ckpt_filename("checkpoint")
{
#ifdef MWSTATS
stats = new MWStatistics<MWWorkerID<CommType>,CommType>();
#endif
#if defined( XML_OUTPUT )
xml_menus_filename = "menus";
xml_jobinfo_filename = "job_info";
xml_pbdescrib_filename = "pbdescrib";
xml_filename = "/u/m/e/metaneos/public/html/iMW/status.xml";
CondorLoadAvg = NO_VAL;
LoadAvg = NO_VAL;
Memory = NO_VAL;
Cpus = NO_VAL;
VirtualMemory = NO_VAL;
Disk = NO_VAL;
KFlops = NO_VAL;
Mips = NO_VAL;
memset(OpSys, 0, sizeof(OpSys));
memset(Arch, 0 , sizeof(Arch));
memset(mach_name, 0 , sizeof(mach_name));
get_machine_info();
#endif
#ifdef NWSENABLED
defaultTimeInterval = 10;
defaultIterations = 5;
defaultPortNo = 7;
nws_measurement_period = 60;
next_nws_measurement_check = time(0) + nws_measurement_period;
nws_nameserver_port = 8095;
nws_memory_port = 8195;
nws_sensor_port = 8295;
#endif
}
//============================================================================
//
//
template <class CommType>
MWDriver<CommType>::~MWDriver()
{
//
// Delete the workers
//
typename map<int,MWWorkerID<CommType>*>::iterator currWorker = workers.begin();
typename map<int,MWWorkerID<CommType>*>::iterator lastWorker = workers.end();
while (currWorker != lastWorker) {
delete currWorker->second;
++currWorker;
}
//
// Delete the tasks
//
typename map<int,MWTask<CommType>*>::iterator currTask = running_tasks.begin();
typename map<int,MWTask<CommType>*>::iterator lastTask = running_tasks.end();
while (currTask != lastTask) {
delete currTask->second;
++currTask;
}
#ifdef MWSTATS
if ( stats )
delete stats;
#endif
}
////--------------------------------------------------------
////
//// Worker Management
////
////--------------------------------------------------------
//============================================================================
//
// Note: this could be made more efficient by recording the
// exec class of a worker when adding/deleting. However, for now
// we assume that host add/deletion is relatively infrequent.
//
template <class CommType>
int MWDriver<CommType>::numWorkers( int ex_cl ) const
{
int count = 0;
typename map<int,MWWorkerID<CommType>*>::const_iterator curr = workers.begin();
typename map<int,MWWorkerID<CommType>*>::const_iterator last = workers.end();
while (curr != last) {
if (curr->second->get_exec_class() == ex_cl)
count++;
++curr;
}
return count;
}
//============================================================================
//
//
template <class CommType>
int MWDriver<CommType>::numWorkersInState( typename MWBase::MWworker_states ThisState ) const
{
int count = 0;
typename map<int,MWWorkerID<CommType>*>::const_iterator curr = workers.begin();
typename map<int,MWWorkerID<CommType>*>::const_iterator last = workers.end();
while (curr != last) {
// We handle the case WORKING separately such that
// we don't count the workers with no runningtask
if (ThisState == WORKING) {
if ( (curr->second->currentState() == ThisState) &&
(curr->second->runningtask != NULL) )
count++;
}
else {
if ( curr->second->currentState() == ThisState )
count++;
}
curr++;
}
return count;
}
//============================================================================
//
//
template <class CommType>
void MWDriver<CommType>::printWorkers() const
{
MWprintf ( 1, "---- List of Idle Workers follows: ----------------\n" );
typename list<MWWorkerID<CommType>*>::const_iterator curr = idle_workers.begin();
typename list<MWWorkerID<CommType>*>::const_iterator last = idle_workers.end();
while (curr != last) {
(*curr)->printself(91);
curr++;
}
MWprintf ( 1, "---- List of Active Workers follows: ----------------\n" );
curr = active_workers.begin();
last = active_workers.end();
while (curr != last) {
(*curr)->printself(91);
curr++;
}
MWprintf ( 1, "---- End worker list --- %d workers ------------\n",
workers.size() );
}
////--------------------------------------------------------
////
//// Task Management
////
////--------------------------------------------------------
//============================================================================
//
//
template <class CommType>
int MWDriver<CommType>::delete_tasks_greater_than( typename MWBase::MWKey key )
{
if ( ! TaskLess ) {
MWprintf( 10, " delete_task_worse_than: no task key "
"function defined!\n");
return -1;
}
typename list<MWTask<CommType>*>::iterator currTask = todo.begin();
typename list<MWTask<CommType>*>::iterator lastTask = todo.end();
while (currTask != lastTask) {
if ( (*TaskLess.keyFunc)( *currTask ) > key) {
todo.erase(currTask);
delete *currTask;
}
++currTask;
}
return 0;
}
//============================================================================
//
//
template <class CommType>
int MWDriver<CommType>::print_task_keys()
{
if ( ! TaskLess ) {
MWprintf( 10, " No key function assigned to tasks -- Can't print\n");
return -1;
}
MWprintf( 10, "Task Keys:\n");
typename list<MWTask<CommType>*>::iterator currTask = todo.begin();
typename list<MWTask<CommType>*>::iterator lastTask = todo.end();
while (currTask != lastTask) {
MWprintf( 10, " %f\t(%d)\n", (*TaskLess.keyFunc)(*currTask), (*currTask)->number );
++currTask;
}
return 0;
}
////--------------------------------------------------------
////
//// Checkpoint Management
////
////--------------------------------------------------------
//============================================================================
//
//
template <class CommType>
void MWDriver<CommType>::checkpoint()
{
int total;
ofstream ofstr;
/* We're going to write the checkpoint to a temporary file,
then move the file to "ckpt_filename" */
/* We're not going to use tempnam(), because it sometimes
gives us a filename in /var/tmp, which is bad for rename() */
const char *tempName = "mw_tmp_ckpt_file";
ofstr.open(tempName);
if ( !ofstr ) {
MWprintf ( 10, "Failed to open %s for writing! errno %d\n",
tempName, errno );
return;
}
//
// Write header
//
MWprintf ( 50, "Beginning checkpoint()\n" );
ofstr << "MWDriver Checkpoint File." << time(0) << endl;
//
// Write internal MWDriver state:
//
ofstr << task_counter << " "
<< checkpoint_frequency << " "
<< checkpoint_time_freq << " "
<< num_completed_tasks << endl;
ofstr << (int)suspensionPolicy << " "
<< (int)machine_ordering_policy << endl;
if ( bench_task ) {
ofstr << 1 << " ";
bench_task->write_ckpt_info ( ofstr );
}
else
ofstr << 0 << endl;
MWprintf ( 80, "Wrote internal MWDriver state.\n" );
//
// Write RMC state
//
RMC->write_checkpoint( ofstr );
MWprintf ( 80, "Wrote RMC state.\n" );
#ifdef MWSTATS
//
// Write worker stats
//
stats->write_checkpoint( ofstr, workers );
MWprintf ( 80, "Wrote the Worker stats.\n" );
#endif
//
// Write the user master's state:
//
write_master_state( ofstr );
MWprintf ( 80, "Wrote the user master's state.\n" );
//
// Write the number of work groups
//
ofstr << workGroupWorkerNum.size() << endl;
//
// Write active task info
//
int tempnum = 0;
typename list<MWWorkerID<CommType>*>::iterator w_curr = active_workers.begin();
typename list<MWWorkerID<CommType>*>::iterator w_last = active_workers.end();
while (w_curr != w_last) {
if ((*w_curr)->runningtask->taskType == MWTask<CommType>::NORMAL)
tempnum++;
w_curr++;
}
int num_tasks = tempnum + todo.size();
ofstr << "Tasks: " << num_tasks << endl;
total = 0;
w_curr = active_workers.begin();
w_last = active_workers.end();
while (w_curr != w_last) {
if ((*w_curr)->runningtask->taskType == MWTask<CommType>::NORMAL) {
ofstr << (*w_curr)->runningtask->number << " ";
(*w_curr)->runningtask->write_ckpt_info(ofstr);
(*w_curr)->runningtask->write_group_info(ofstr);
}
w_curr++;
}
//
// Write todo task info
//
typename list<MWTask<CommType>*>::iterator t_curr = todo.begin();
typename list<MWTask<CommType>*>::iterator t_last = todo.end();
while (t_curr != t_last) {
ofstr << (*t_curr)->number << " ";
(*t_curr)->write_ckpt_info(ofstr);
(*t_curr)->write_group_info(ofstr);
}
MWprintf ( 80, "Wrote task list.\n" );
ofstr.close();
/* Now we rename our temp file to the real thing. Atomicity! */
if ( rename( tempName, ckpt_filename.data() ) == -1 ) {
MWprintf ( 10, "rename( %s, %s ) failed! errno %d.\n",
tempName, ckpt_filename.data(), errno );
}
MWprintf ( 50, "Done checkpointing.\n" );
}
//============================================================================
//
//
template <class CommType>
bool MWDriver<CommType>::checkpoint_data_exists()
{
struct stat statbuf;
return (stat( ckpt_filename.data(), &statbuf ) == -1);
}
//============================================================================
//
//
template <class CommType>
void MWDriver<CommType>::restart_from_ckpt()
{
ifstream ifstr(ckpt_filename.data());
if ( !ifstr ) {
MWprintf ( 10, "Failed to open %s for reading! errno %d\n",
ckpt_filename.data(), errno );
return;
}
char buf[128];
time_t then;
ifstr >> buf >> buf >> buf >> then;
MWprintf ( 10, "This checkpoint made on %s\n", ctime( &then ) );
ifstr >> task_counter >> checkpoint_frequency >> checkpoint_time_freq
>> num_completed_tasks;
int susp_policy, mach_policy;
ifstr >> susp_policy >> mach_policy;
suspensionPolicy = (typename MWDriver<CommType>::MWSuspensionPolicy) susp_policy;
machine_ordering_policy = (typename MWDriver<CommType>::MWMachineOrderingPolicy) mach_policy;
int hasbench = 0;
ifstr >> hasbench;
if ( hasbench ) {
if (!bench_task)
bench_task = allocate_benchmark_task();
assert(bench_task != 0);
bench_task->read_ckpt_info( ifstr );
MWprintf ( 10, "Got benchmark task:\n" );
bench_task->printself( 10 );
}
MWprintf ( 10, "Read internal MW info.\n" );
RMC->read_checkpoint( ifstr );
MWprintf ( 10, "Read RMC state.\n" );
#ifdef MWSTATS
// read old stats
stats->read_checkpoint( ifstr );
#endif
MWprintf ( 10, "Read defunct workers' stats.\n" );
read_master_state( ifstr );
MWprintf ( 10, "Read the user master's state.\n" );
int MWworkGroups;
ifstr >> MWworkGroups;
setupWorkGroups(MWworkGroups);
int num_tasks;
ifstr >> buf >> num_tasks;
if ( strcmp( buf, "Tasks:" ) ) {
MWprintf ( 10, "Problem in reading Tasks separator. buf = %s\n", buf );
ifstr.close();
return;
}
MWTask<CommType> *t;
for (int i=0 ; i<num_tasks ; i++ ) {
t = allocate_task();
ifstr >> t->number;
t->read_ckpt_info( ifstr );
t->read_group_info ( ifstr );
t->printself( 80 );
ckpt_addTask( t );
}
MWprintf ( 10, "Read the task list.\n" );
ifstr.close();
MWprintf ( 10, "We are done restarting.\n" );
}
//============================================================================
//
//
template <class CommType>
void MWDriver<CommType>::checkpoint_end()
{
//
// Remove checkpoint file.
//
struct stat statbuf;
if ( stat( ckpt_filename.data(), &statbuf ) == 0 ) {
if ( unlink( ckpt_filename.data() ) != 0 )
MWprintf ( 10, "unlink %s failed! errno %d\n",
ckpt_filename.data(), errno );
}
}
////--------------------------------------------------------
////
//// Protected Main Routines
////
////--------------------------------------------------------
//
//============================================================================
//
template <class CommType>
void MWDriver<CommType>::ControlPanel ( )
{
typename MWBase::MWReturn ustat = OK;
RMC->hostadd ();
master_handle_msg();
MWWorkerID<CommType> *worker = allocate_workerID();
worker->go( 1, NULL );
master_handle_msg();
worker->ind_benchmark ( );
ustat = master_handle_msg();
while ( ( (!todo.empty()) || (active_workers.size() > 0) ) && ( ustat == OK ) ) {
ustat = worker->worker_mainloop_ind ( );
ustat = master_handle_msg();