1 : |
agomez |
1 |
#ifndef processmanager_h
|
2 : |
|
|
#define processmanager_h
|
3 : |
|
|
|
4 : |
|
|
#include "datastructure.h" |
5 : |
|
|
#include "netcommunication.h" |
6 : |
|
|
#include "commandlineinfo.h" |
7 : |
|
|
#include "mathfunc.h"
|
8 : |
|
|
#include "paramin.h" |
9 : |
|
|
|
10 : |
|
|
/* The class runtime provides functions to set time for beginning of
|
11 : |
|
|
* execution and compute estimated run time. New run time is measured
|
12 : |
|
|
* from execution of startRun() to stopRun(a) in seconds.
|
13 : |
|
|
* Estimated run time is calculated as: (execution time * a) + (new runtime * (1 - a))
|
14 : |
|
|
* if estimated run time is not equal to -1.0.
|
15 : |
|
|
* if execution time is equal to -1.0 then execution time is set to new run time.
|
16 : |
|
|
* If run time is less than 1 sec, run time = 0.
|
17 : |
|
|
* WARNING: Might need a more accurate time function - now using
|
18 : |
|
|
* difftime(time_t t1, time_t t2) which returns 0 when difference in seconds < 1.
|
19 : |
|
|
* but we do not know the accuracy of difftime */
|
20 : |
|
|
|
21 : |
|
|
class RunTime {
|
22 : |
|
|
private:
|
23 : |
|
|
time_t startExec;
|
24 : |
|
|
double execTime;
|
25 : |
|
|
public:
|
26 : |
|
|
RunTime();
|
27 : |
|
|
~RunTime();
|
28 : |
|
|
void startRun();
|
29 : |
|
|
void stopRun(double a);
|
30 : |
|
|
double getRunTime();
|
31 : |
|
|
time_t getStartTime();
|
32 : |
|
|
int isRunning();
|
33 : |
|
|
void setRunTime(double t);
|
34 : |
|
|
};
|
35 : |
|
|
|
36 : |
|
|
/* The class ProcessManager is a manager for a group of processes were
|
37 : |
|
|
* each process has a unique task id (tid).
|
38 : |
|
|
* It provides functions to get information about the general state of
|
39 : |
|
|
* the processes and how many processes are available.
|
40 : |
|
|
* The ProcessManager dispatches processes by FIFO order (The first free
|
41 : |
|
|
* process to arrive is dispatched first) */
|
42 : |
|
|
|
43 : |
|
|
class ProcessManager {
|
44 : |
|
|
protected:
|
45 : |
|
|
int errorNoProcesses;
|
46 : |
|
|
int errorWaitForProcesses;
|
47 : |
|
|
Queue* freeProcesses;
|
48 : |
|
|
int totalNumProc;
|
49 : |
|
|
int* procStat;
|
50 : |
|
|
int maxNumHosts;
|
51 : |
|
|
public:
|
52 : |
|
|
int* getStatus();
|
53 : |
|
|
ProcessManager();
|
54 : |
|
|
virtual ~ProcessManager();
|
55 : |
|
|
virtual void initializePM(int numProc);
|
56 : |
|
|
virtual void addProc(int id);
|
57 : |
|
|
virtual void addMoreProc(int id);
|
58 : |
|
|
int getNumFreeProc();
|
59 : |
|
|
int isFreeProc();
|
60 : |
|
|
virtual void setFreeProc(int id);
|
61 : |
|
|
int getTidToSend(NetCommunication* n);
|
62 : |
|
|
int checkForNewProcess(NetCommunication* n);
|
63 : |
|
|
virtual int getNextTidToSend(int numLeftToSend, NetCommunication* n);
|
64 : |
|
|
virtual void sent(int procID);
|
65 : |
|
|
int allReceived();
|
66 : |
|
|
int getStatus(int id);
|
67 : |
|
|
void setStatus(int id, int stat);
|
68 : |
|
|
void processDown(int id);
|
69 : |
|
|
int getNumGoodProc();
|
70 : |
|
|
void noProcessesRunning();
|
71 : |
|
|
void removeBadProc();
|
72 : |
|
|
int noAvailableProcesses();
|
73 : |
|
|
int waitForBetterProcesses();
|
74 : |
|
|
};
|
75 : |
|
|
|
76 : |
|
|
/* The class WorkLoadScheduler is a derived class of ProcessManager. It
|
77 : |
|
|
* keeps track of running time of processes and dispatches processes
|
78 : |
|
|
* based on workload and running time of processes.
|
79 : |
|
|
* Runtime is measured from: when master sends data until master receives
|
80 : |
|
|
* it not actual runtime of process.*/
|
81 : |
|
|
|
82 : |
|
|
class WorkLoadScheduler : public ProcessManager {
|
83 : |
|
|
private:
|
84 : |
|
|
double bestTime;
|
85 : |
|
|
double alpha;
|
86 : |
|
|
double hostMultiple;
|
87 : |
|
|
double besttimeMultiple;
|
88 : |
|
|
RunTime** runInfo;
|
89 : |
|
|
public:
|
90 : |
|
|
WorkLoadScheduler(CommandLineInfo* info);
|
91 : |
|
|
~WorkLoadScheduler();
|
92 : |
|
|
virtual void initializePM(int totalNumProc);
|
93 : |
|
|
virtual void addProc(int id);
|
94 : |
|
|
virtual void addMoreProc(int id);
|
95 : |
|
|
virtual void setFreeProc(int tid);
|
96 : |
|
|
virtual int getNextTidToSend(int numLeftToSend, NetCommunication* n);
|
97 : |
|
|
virtual void sent(int procID);
|
98 : |
|
|
int quickHostsAvailable();
|
99 : |
|
|
int quickBusyProcesses();
|
100 : |
|
|
};
|
101 : |
|
|
|
102 : |
|
|
#endif
|