forked from mtorpey/smallgrp-to-csv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmallgrp_parallel.g
103 lines (93 loc) · 3.25 KB
/
smallgrp_parallel.g
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
97
98
99
100
101
102
103
LoadPackage("crisp");
write_smallgrp_csv := function(fname, order_range, nr_threads)
local out, funcs, nrgroups, groups_started, start_time, func, children,
range_index, size, nrgroupssize, id, time_so_far, time_per_gp,
time_left, child, G, string, subfname, i, line;
out := OutputTextFile(fname, false);
# Properties stored in smallgrp
funcs := [IsAbelian,
IsNilpotentGroup,
IsSupersolvableGroup,
IsSolvableGroup,
#RankPGroup,
#PClassPGroup,
LGLength,
FrattinifactorSize,
G -> FrattinifactorId(G)[2],
StructureDescription]; # this is the long one
nrgroups := Sum(order_range, NrSmallGroups);
groups_started := 0;
start_time := IO_gettimeofday().tv_sec;
AppendTo(out, "order,id");
for func in funcs do
AppendTo(out, ",", NameFunction(func));
od;
AppendTo(out, "\n");
children := [];
range_index := 1;
size := order_range[range_index];
nrgroupssize := NrSmallGroups(size);
id := 1;
while groups_started < nrgroups or Length(children) > 0 do
# Create new threads
while Length(children) < nr_threads and groups_started < nrgroups do
groups_started := groups_started + 1;
time_so_far := IO_gettimeofday().tv_sec - start_time;
time_per_gp := time_so_far / Maximum(1, groups_started - nr_threads);
time_left := time_per_gp * (nrgroups - groups_started + nr_threads/2);
time_left := Float(time_left);
Print("Starting group ", groups_started, " of ", nrgroups,
" (", Int(Float(groups_started / nrgroups * 100)), "%): [",
size, ", ", id, "], ",
Int(Round(time_left)), " seconds or ",
Int(Round(time_left/60)), " minutes or ",
Int(Round(time_left/3600)), " hours left. \r");
child := IO_fork();
if child = fail then
Error("cannot create children!");
elif child <> 0 then
# Parent
Add(children, child);
if id < nrgroupssize then
id := id + 1;
else
range_index := range_index + 1;
if range_index > Length(order_range) then
break; # no more groups!
fi;
size := order_range[range_index];
nrgroupssize := NrSmallGroups(size);
id := 1;
fi;
else
# Child
G := SmallGroup(size, id);
string := Concatenation(String(size), ",", String(id));
for func in funcs do
Append(string, ",");
Append(string, String(func(G)));
od;
Append(string, "\n");
subfname := Concatenation("output-", String(IO_getpid()), ".g");
FileString(subfname, string);
QUIT_GAP(0);
fi;
od;
# Wait for threads to finish
for i in [1 .. Length(children)] do
if IO_WaitPid(children[i], false) <> false then
# Finished!
child := Remove(children, i);
subfname := Concatenation("output-", String(child), ".g");
#Print("Got ", subfname, "\n");
line := StringFile(subfname);
RemoveFile(subfname);
AppendTo(out, line);
break;
fi;
od;
od;
CloseStream(out);
time_so_far := IO_gettimeofday().tv_sec - start_time;
return time_so_far;
end;