-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathecmTask.py
More file actions
44 lines (33 loc) · 1.46 KB
/
ecmTask.py
File metadata and controls
44 lines (33 loc) · 1.46 KB
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
import random
class ECMTask:
def __str__(self):
return f"""ECMTask(type={self.type}, B1={self.B1}, B2Mult={self.B2Mult}, curvesPerCandidate={self.curvesPerCandidate},
candidateIds={self.candidateIds})"""
def __init__(self, obj, type):
assert type == "cpu" or type == "gpu"
self.type = type
self.B1 = int(obj["b1"])
self.B2Mult = int(obj["b2mult"])
if self.type == "cpu":
self.curvesPerCandidate = int(obj["curves"])
self.candidateIds = [int(obj["candidateId"])]
self.Ns = [int(obj["n"])]
elif self.type == "gpu":
self.curvesPerCandidate = int(obj["curvesPerCandidate"])
self.candidateIds = list(map(int, obj["candidateIds"]))
self.Ns = list(map(int, obj["ns"]))
assert len(self.candidateIds) == len(self.Ns)
if self.type == "cpu":
assert len(self.candidateIds) == 1
elif self.type == "gpu":
# Shuffle the candidate ids for a better chance of being the first to submit a factor
mapping = [i for i in range(len(self.candidateIds))]
random.shuffle(mapping)
self.candidateIds = [self.candidateIds[i] for i in mapping]
self.Ns = [self.Ns[i] for i in mapping]
self.B2 = self.B2Mult * self.B1
self.active = True
self.curvesRan = 0
self.startedAt = None
self.ongoing = False
self.taskRuntime = 0