1
# This file is part of DEAP.
3
# DEAP is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Lesser General Public License as
5
# published by the Free Software Foundation, either version 3 of
6
# the License, or (at your option) any later version.
8
# DEAP is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Lesser General Public License for more details.
13
# You should have received a copy of the GNU Lesser General Public
14
# License along with DEAP. If not, see <http://www.gnu.org/licenses/>.
16
DTM_TASK_STATE_IDLE = 0
17
DTM_TASK_STATE_RUNNING = 1
18
DTM_TASK_STATE_WAITING = 2
19
DTM_TASK_STATE_FINISH = 3
23
DTM_MSG_REQUEST_TASK = 2
25
DTM_MSG_ACK_RECEIVED_TASK = 4
32
class TaskContainer(object):
34
Contains all the information about a task (running or not)
36
__slots__ = ('tid', # Unique ID of the task
37
'creatorWid', # ID of the worker who creates this task
38
'creatorTid', # ID of the task who creates this task (parent)
39
'taskIndex', # Position into the parents task childs list
40
'taskRoute', # Worker path followed by the job before begin
41
'creationTime', # Time at the job creation
42
'target', # Target function (or callable object) of the task
43
'args', # Arguments (list)
44
'kwargs', # Key-worded arguments (dictionnary)
45
'threadObject', # Python representation of the thread
46
'taskState') # State of the task (DTM_TASK_*)
47
def __init__(self, **kwargs):
48
self.__setstate__(kwargs)
49
def __getstate__(self):
51
for a in self.__slots__:
52
d[a] = self.__getattribute__(a)
54
def __setstate__(self, state):
56
self.__setattr__(t, state[t])
57
def __lt__(self, other):
58
return self.creationTime < other.creationTime
60
class ResultContainer(object):
62
Used to store the result of a task so it can be sent
64
__slots__ = ('tid', # ID of the task which produced these results
65
'parentTid', # Parent ID (waiting for these results)
66
'taskIndex', # Position into the parents task childs list
67
'execTime', # Total execution time (NOT waiting time)
68
'success', # False if an exception occured
69
'result') # The result; if an exception occured, contains it
70
def __init__(self, **kwargs):
71
self.__setstate__(kwargs)
72
def __getstate__(self):
74
for a in self.__slots__:
75
d[a] = self.__getattribute__(a)
77
def __setstate__(self, state):
79
self.__setattr__(t, state[t])
81
class ExceptedResultContainer(object):
83
Keep the information of a result waited on the task creator side
85
__slots__ = ('tids', # List of IDs of the tasks which produce these results
86
'waitingOn', # Is the parent task waiting on this result?
87
'finished', # Boolean : is the task finished (i.e. result received)?
88
'success', # Boolean : False if unfinished or if an exception occured
89
'callbackFunc', # Callback function, FOR USE IN DTM, NO ARGUMENTS PASSED, or None
90
'result') # Result, or the exception occured
91
def __init__(self, **kwargs):
92
self.__setstate__(kwargs)
93
def __getstate__(self):
95
for a in self.__slots__:
96
d[a] = self.__getattribute__(a)
98
def __setstate__(self, state):
100
self.__setattr__(t, state[t])
102
class WaitInfoContainer(object):
104
Keep a track on the pending child tasks of a parent task.
106
__slots__ = ('threadObject', # Python representation of the thread
107
'eventObject', # threading.Event flag (to wake up the thread)
108
'waitBeginningTime', # Time when the thread started waiting (0 if not)
109
'tasksWaitingCount', # How many tasks are we waiting on
110
'waitingMode', # DTM_WAIT_* : waiting mode (None, One, Any, All)
111
'rWaitingDict') # List of ExceptedResultContainer, key : the first task ID
112
def __init__(self, **kwargs):
113
self.__setstate__(kwargs)
114
def __getstate__(self):
116
for a in self.__slots__:
117
d[a] = self.__getattribute__(a)
119
def __setstate__(self, state):
121
self.__setattr__(t, state[t])
123
class StatsContainer(object):
125
Contains stats about a target
127
__slots__ = ('rAvg', # RELATIVE average execution time
128
'rStdDev', # RELATIVE standard deviation of the exec time
129
'rSquareSum', # Square sum of the RELATIVE exec times
130
'execCount') # Number of executions
131
def __init__(self, **kwargs):
132
self.__setstate__(kwargs)
133
def __getstate__(self):
135
for a in self.__slots__:
136
d[a] = self.__getattribute__(a)
138
def __setstate__(self, state):
140
self.__setattr__(t, state[t])
142
class MessageContainer(object):
144
Generic message container
145
If msgType == DTM_MSG_EXIT:
146
msg = (Exit code, exit message)
147
If msgType == DTM_MSG_TASK:
148
msg = [TaskContainer, TaskContainer, TaskContainer, ...]
149
If msgType == DTM_MSG_REQUEST_TASK:
151
If msgType == DTM_MSG_RESULT:
152
msg = [ResultContainer, ResultContainer, ResultContainer, ...]
153
If msgType == DTM_MSG_ACK_RECEIVED_TASK:
156
__slots__ = ('msgType', # Message type (DTM_MSG_*)
157
'senderWid', # Worker id of the sender
158
'receiverWid', # Worker id of the receiver
159
'loadsDict', # Load dictionnary of the sender
160
'targetsStats', # Stats on the tasks of the sender
161
'prepTime', # Time when it was ready to send
162
'sendTime', # Time when sent
163
'ackNbr', # ACK number (optionnal for some operations)
164
'msg') # Message (varies with msgType)
165
def __init__(self, **kwargs):
166
self.__setstate__(kwargs)
167
def __getstate__(self):
169
for a in self.__slots__:
170
d[a] = self.__getattribute__(a)
172
def __setstate__(self, state):
174
self.__setattr__(t, state[t])