-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathHelix.pde
96 lines (77 loc) · 3 KB
/
Helix.pde
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
class Helix {
private final int SLOTS_PER_NODE = 16; // ranger=16, longhorn=16, lonestar=12, stampede=16
private int runningJobCnt = 0;
private ArrayList<Job> jobs;
private int maxSlotsIndex;
private float helixRadius;
private float x,y,z, deltaZ;
PShape helix;
Helix(ArrayList<Job> _jobs, int _maxSlotsIndex) {
jobs = _jobs;
maxSlotsIndex = _maxSlotsIndex;
helixRadius = 400;
deltaZ = 2;
}
public void createHelix() {
helix = createShape(GROUP);
x = 0; y = 0; z = 0;
float theta = 0;
for (int i=0; i<jobs.size(); i++) {
runningJobCnt++;
color jobColor = color(random(0, 255), random(0, 255), random(0, 255)); // color running jobs
float thisSphereRadius = calculateRadius(jobs.get(i).getSlots(), jobs.get(maxSlotsIndex).getSlots());
int nodesPerJob = jobs.get(i).getSlots()/SLOTS_PER_NODE;
if(nodesPerJob == 0) nodesPerJob = 1; // jobs with less than SLOTS_PER_NODE cores get rounded to 1 node
jobs.get(i).setStartCoordinates(x,y,z,theta);
jobs.get(i).setNodeCount(nodesPerJob);
jobs.get(i).setSphereRadius(thisSphereRadius);
for (int j=0; j<nodesPerJob; j++) {
// convert from polar to cartesian coordinates
x = helixRadius * cos(theta);
y = helixRadius * sin(theta);
z += deltaZ;
// create cyliner+orb pshape
PShape cylorb = createShape(GROUP);
cylorb.translate(x, y, z);
cylorb.rotateY(PI/2);
cylorb.rotateX(-theta);
// create orb pshape
PShape orb = createShape(SPHERE, thisSphereRadius);
orb.setStroke(false);
orb.setFill(jobColor);
cylorb.addChild(orb);
// create time cylinder
Cylinder timeCylinder = new Cylinder(jobColor, jobs.get(i).getQueueName(), jobs.get(i).getStartTime(), thisSphereRadius/5);
cylorb.addChild(timeCylinder.getCylinder());
helix.addChild(cylorb);
// distance between the radii of neighboring spheres dictates theta
if ((j == nodesPerJob-1) && (i != jobs.size()-1)) {
float nextSphereRadius = calculateRadius(jobs.get(i+1).getSlots(), jobs.get(maxSlotsIndex).getSlots());
theta += asin((thisSphereRadius+nextSphereRadius)/helixRadius);
}else {
theta += asin((thisSphereRadius*2)/helixRadius);
}
}
}
}
private float calculateRadius(int jobSlots, int _maxSlots) {
float minSlots = 1; // x0
float minRadius = 5; // y0
float maxSlots = _maxSlots; // x1
float maxRadius = 20; // y1
// interpolate sphere radius
return minRadius + (((jobSlots-minSlots)*maxRadius-(jobSlots-minSlots)*minRadius)/(maxSlots-minSlots));
}
public void displayHelix(){
shape(helix);
}
public float getHelixRadius() {
return helixRadius;
}
public float getDeltaZ() {
return deltaZ;
}
public int getRunningJobCount() {
return runningJobCnt;
}
}