Skip to content
Snippets Groups Projects
Commit b7c3b9c1 authored by Maël Madon's avatar Maël Madon
Browse files

rename and refac

parent b77eb662
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""SWF types and functions."""
from enum import Enum, unique
@unique
class SwfField(Enum):
"""Maps SWF columns and their meaning."""
JOB_ID = 1
SUBMIT_TIME = 2
WAIT_TIME = 3
RUN_TIME = 4
ALLOCATED_PROCESSOR_COUNT = 5
AVERAGE_CPU_TIME_USED = 6
USED_MEMORY = 7
REQUESTED_NUMBER_OF_PROCESSORS = 8
REQUESTED_TIME = 9
REQUESTED_MEMORY = 10
STATUS = 11
USER_ID = 12
GROUP_ID = 13
APPLICATION_ID = 14
QUEUD_ID = 15
PARTITION_ID = 16
PRECEDING_JOB_ID = 17
THINK_TIME_FROM_PRECEDING_JOB = 18
...@@ -8,7 +8,7 @@ import json ...@@ -8,7 +8,7 @@ import json
import re import re
import networkx as nx import networkx as nx
from swf import SwfField from workload import SwfField
# Global dictionnary # Global dictionnary
users = {} users = {}
...@@ -23,21 +23,21 @@ class Job: ...@@ -23,21 +23,21 @@ class Job:
class User: class User:
"""Class representing a user of the workload."""
def __init__(self, user_id): def __init__(self, user_id, no_dynamic_reduction=False):
self.id = user_id self.id = user_id
self.jobs = {} self.jobs = {}
# The (directed) dependancy graph # The (directed) dependancy graph
self.G = nx.DiGraph() self.G = nx.DiGraph()
def init_dyn_reduc(self): if not(no_dynamic_reduction):
"""Necessary data to keep track of to do dynamic transitive reduction""" # jobs submitted but not finished, at time t
# jobs submitted but not finished, at time t self.jobs_in_progress = set()
self.jobs_in_progress = set()
# jobs finished, constituting the minimal list
# jobs finished, constituting the minimal list # of dependencies for a job sumbitted at time t
# of dependencies for a job sumbitted at time t self.current_dep = set()
self.current_dep = set()
def add_job(self, job_id, submit_time, finish_time, no_dynamic_reduction): def add_job(self, job_id, submit_time, finish_time, no_dynamic_reduction):
# Add the job to the user's list # Add the job to the user's list
...@@ -76,9 +76,10 @@ class User: ...@@ -76,9 +76,10 @@ class User:
def dependancies_of(self, job): def dependancies_of(self, job):
"""Return the set of direct dependancies of the job.""" """Return the set of direct dependancies of the job."""
{self.jobs[n] for n in self.G.successors(job.id)} return {self.jobs[n] for n in self.G.successors(job.id)}
def export_dependancy_graph(self, output_folder, transitive_reduction): def export_dependancy_graph(self, output_folder, transitive_reduction):
"""Write the dependancy graph as a gml file, for each user."""
if transitive_reduction: if transitive_reduction:
self.G = nx.transitive_reduction(self.G) self.G = nx.transitive_reduction(self.G)
...@@ -88,9 +89,7 @@ class User: ...@@ -88,9 +89,7 @@ class User:
def build_dep_graph(job_id, submit_time, finish_time, user_id, def build_dep_graph(job_id, submit_time, finish_time, user_id,
no_dynamic_reduction): no_dynamic_reduction):
if user_id not in users: if user_id not in users:
users[user_id] = User(user_id) users[user_id] = User(user_id, no_dynamic_reduction)
if not no_dynamic_reduction:
(users[user_id]).init_dyn_reduc()
user = users[user_id] user = users[user_id]
user.add_job(job_id, submit_time, finish_time, no_dynamic_reduction) user.add_job(job_id, submit_time, finish_time, no_dynamic_reduction)
......
...@@ -9,7 +9,7 @@ import json ...@@ -9,7 +9,7 @@ import json
import re import re
from copy import deepcopy from copy import deepcopy
from swf import SwfField from workload import SwfField
# Global dictionnary # Global dictionnary
users = {} users = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment