The following example creates fifteen child processes and uses them simultaneously to compute the second integral homology of each of the 2328 groups of order 128. The final command shows that
H_2(G, Z)= Z_2^21
for the 2328-th group G in GAP's library of small groups. The penulimate command shows that the parallel computation achieves a speedup of 10.4 .
gap> Processes:=List([1..15],i->ChildProcess());; gap> fn:=function(i);return GroupHomology(SmallGroup(128,i),2);end;; gap> for p in Processes do > ChildPut(fn,"fn",p); > od; gap> Exec("date +%s");L:=ParallelList([1..2328],"fn",Processes);;Exec("date +%s"); 1716105545 1716105554 gap> Exec("date +%s");L1:=List([1..2328],fn);;Exec("date +%s"); 1716105586 1716105680 gap> speedup:=1.0*(680-586)/(554-545); 10.4444 gap> L[2328]; [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]
The function ParallelList() is built from HAP's six core functions for parallel computation.
The following commands use core functions to compute the product A=M× N of two random matrices by distributing the work over two processors.
gap> M:=RandomMat(10000,10000);; gap> N:=RandomMat(10000,10000);; gap> gap> s:=ChildProcess();; gap> gap> Exec("date +%s"); 1716109418 gap> Mtop:=M{[1..5000]};; gap> Mbottom:=M{[5001..10000]};; gap> ChildPut(Mtop,"Mtop",s); gap> ChildPut(N,"N",s); gap> NextAvailableChild([s]);; gap> ChildCommand("Atop:=Mtop*N;;",s);; gap> Abottom:=Mbottom*N;; gap> A:=ChildGet("Atop",s);; gap> Append(A,Abottom);; gap> Exec("date +%s"); 1716110143 gap> AA:=M*N;;Exec("date +%s"); 1716111389 gap> speedup:=1.0*(111389-110143)/(110143-109418); 1.71862
The next commands compute the product A=M× N of two random matrices by distributing the work over fifteen processors. The parallelization is very naive (the entire matrices M and N are communicated to all processes) and the computation achieves a speedup of 7.6.
gap> M:=RandomMat(15000,15000);; gap> N:=RandomMat(15000,15000);; gap> S:=List([1..15],i->ChildCreate());; gap> Exec("date +%s"); 1716156583 gap> ChildPutObj(M,"M",S); gap> ChildPutObj(N,"N",S); gap> for i in [1..15] do > cmd:=Concatenation("A:=M{[1..1000]+(",String(i),"-1)*1000}*N;"); > ChildCommand(cmd,S[i]); > od; gap> A:=[];; gap> for i in [1..15] do > C:=ChildGet("A",S[i]); > Append(A,C); > od; gap> Exec("date +%s"); 1716157489 gap> AA:=M*N;;Exec("date +%s"); 1716164405 gap> speedup:=1.0*(64405-57489)/(57489-56583); 7.63355
Section 5.8 illustrates an alternative method of computing the persitent Betti numbers of a filtered pure cubical complex. The method lends itself to parallelisation. However, the following parallel computation of persistent Betti numbers achieves only a speedup of 1.5 due to a significant time spent transferring data structures between processes. On the other hand, the persistent Betti function could be used to distribute computations over several computers. This might be useful for larger computations that require significant memory resources.
gap> file:=HapFile("data247.txt");; gap> Read(file);; gap> F:=ThickeningFiltration(T,25);; gap> S:=List([1..15],i->ChildCreate());; gap> N:=[0,1,2];; gap> Exec("date +%s");P:=ParallelPersistentBettiNumbers(F,N,S);;Exec("date +%s"); 1717160785 1717161285 gap> Exec("date +%s");Q:=PersistentBettiNumbersAlt(F,N);;Exec("date +%s"); 1717161528 1717162276 gap> speedup:=1.0*(1717162276-1717161528)/(1717161285-1717160785); 1.496
Here is a story of naive implementation design causing a serial algorithm to run much slower than it should!
In HAP the command XX=ContractedComplex(X) inputs an object X and outputs a potentially smaller object XX of the same datatype and same homotopy type (in the appropriate category). Here X can be a regular CW complex or a chain complex of free abelian groups or a chain complex of free ZG-modules. The object XX is obtained from X by finding a cell/basis element e^n whose boundary d(e^n) is a combination of cells/basis elements
d(e^n) = a_1e^n-1_1 + a_2e^n-1_2 + ... + a_te^n-1_t
where some coefficient, let's say a_1, is a unit. Then the pair (e^n,e^n-1_1) is deemed redundant: the cell/basis element e^n is dropped from XX and the cell/basis element e^n-1_1 is rewritten as
e^n-1_1 = -a_1^-1( a_2e^n-1_2 + ... + a_te^n-1_t ) .
The pair (e^n,e^n-1_1) can be viewed as a simple homotopy collapse e^n↘ e^n-1_1 [Whi50], or a marked face e^n-1_1 of an n-cell e^n in the theory of Poly T-complexes [Jon84][Jon88], or a discrete vector e^n-1 → e^n in discrete Morse theory [For02], or an acyclic matching (e^n,e^n-1_1) in algebraic Morse theory [Koz05][JW05][Sko06], or an homology reduction in effective homology [RS10], or as a quotient map of chain complexes f_∗: C^X_∗ ↠ C^XX_∗ = C^X_∗/⟨ e^n, d(e^n)⟩ where f_∗ is a quasi-isomorphism since its kernel is acyclic thanks to a_1 being a unit. The elimination of pairs can be repeated until no pair with a_1 a unit exists. The contracting homotopies on resolutions constructed using ResolutionFiniteGroup(G,n) [Ell04] arise from such a procedure with X the cellular chain complex of a (non-regular) CW complex and XX the chain complex of a point.
The following snippet (using version ≤ 1.79 of HAP) begins with the construction of a regular CW-complex Y with 157539 cells. It then constructs the cellular chain complex C_∗=C_∗(Y). Computing the homology of Y directly from C_∗ would be time consuming due to the large number of cells in Y. So, a version of the above elementary procedure is used to eliminate redundant generators from Y in order to obtain a smaller quasi-isomorphic chain complex D_∗ and this smaller complex is used to quickly obtain the homology. However, the construction of D_∗ takes over 170 seconds.
gap> #Using HAP version 1.79 or earlier gap> K:=ContractibleGcomplex("SL(3,Z)s");; gap> G:=HAPCongruenceSubgroupGamma0(3,101);; gap> Y:=GComplexToRegularCWComplex(K,G);; gap> C:=SparseChainComplexOfRegularCWComplex(Y); Chain complex of length 3 in characteristic 0 . gap> List([0..3],C!.dimension); [ 3679, 37565, 75083, 41212 ] gap> D:=ContractedComplex(C);time; Chain complex of length 3 in characteristic 0 . 170547 gap> List([0..3],D!.dimension); [ 1, 27, 78, 67 ] gap> List([0..3],n->Homology(D,n));time; [ [ 0 ], [ 25 ], [ 2, 2, 2, 2, 2 ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ] 26
The function ContractedComplex(C) in this example uses the same elementary cell/basis element removal technique described above as a slightly more elaborate implementation programmed some years earlier. The earlier implementation is (unnecessarily) restricted to chain complexes arising as cellular chain complexes of regular CW-complexes while the later implementation is aimed at arbitrary chain complexes of free abelian groups. The earlier implementation returns chain homotopy equivalences between the original and the simplified complexes. To ease the coding of the later implementation it was decided to output just the simplified chain complex and forget about the chain maps yielding the chain equivalence.
The following snippet illustrates the earlier implementation. It again begins with the construction of the regular CW-complex Y with 157539 cells. It then takes just over a second to construct a pair of chain equivalences f_1: C_∗(Y) → C_∗(Y') and f_2: C_∗(Y') → C_∗(Y) with Y' a homotopy equivalent non-regular CW-complex with fewer cells. It uses D_∗=C_∗(Y') to quickly compute the homology of Y.
gap> K:=ContractibleGcomplex("SL(3,Z)s");; gap> G:=HAPCongruenceSubgroupGamma0(3,101);; gap> Y:=GComplexToRegularCWComplex(K,G);; gap> f:=ChainComplexEquivalenceOfRegularCWComplex(Y);time; [ Chain Map between complexes of length 3 . , Chain Map between complexes of length 3 . ] 1192 gap> C:=Source(f[1]); Chain complex of length 3 in characteristic 0 . gap> List([0..3],C!.dimension); [ 3679, 37565, 75083, 41212 ] gap> D:=Target(f[1]); Chain complex of length 3 in characteristic 0 . gap> List([0..3],D!.dimension); [ 4, 15, 29, 33 ] gap> List([0..3],n->Homology(D,n));time; [ [ 0 ], [ 25 ], [ 2, 2, 2, 2, 2 ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ] 211
The takeaway from this story is that design of datatypes to be used in the implementation of an algorithm can significantly impact the speed of the implementation! This is a well established principle, illustrated forcefully by the story.
The decision to output chain maps C_∗ ↔ D_∗ leads to an implementation where all redundant generators in C_∗ first have to be identified, and enough information has to be retained to produce the chain maps. By using some computer representation of a discrete vector field, lazy evaluation can be used to evaluate the chain maps, and to evaluate them only on the non-redundant generators. The later decision to output just the complex D_∗ leads to an easier to implement process of eliminating each redundant generator in a boundary matrix as soon as it is found. This is eager evaluation and somewhat analogous to a gaussian elimination procedure for producing echelon form that updates a boundary matrix each time a suitable pivot is found; it is a bit easier to code but significantly slower on the given example than the earlier implementation.
A new implementation of ContractedComplex(C) was on the HAP to-do list (see 17.4-1).
Given recent advances in AI capability I decided to ask Claude to remove this item from the HAP to-do list. More precisely, I asked Claude to extend the implementation of ChainComplexEquivalenceOfRegularCWComplex(Y) to a function ChainComplexEquivalenceOfChainComplex(C) that applies to an arbitrary chain complex C of f.g. free abelian groups. (The difference is that coefficients in a boundary map can now be any integer rather than just -1, 0, 1. So when choosing a pair (e^n,e^n-1) to eliminate we need to check additionally that e^n-1 occurs with coefficient -1 or +1 and not -n or +n with n>1.) The following illustrates its impressive performance on the above example!
gap> K:=ContractibleGcomplex("SL(3,Z)s");; gap> G:=HAPCongruenceSubgroupGamma0(3,101);; gap> Y:=GComplexToRegularCWComplex(K,G);; gap> C:=SparseChainComplexOfRegularCWComplex(Y);; gap> f:=ChainComplexEquivalenceOfChainComplex(C);time; [ Chain Map between complexes of length 3 . , Chain Map between complexes of length 3 . ] 431 gap> C:=Source(f[1]); Sparse chain complex of length 3 in characteristic 0 . gap> List([0..3],C!.dimension); [ 3679, 37565, 75083, 41212 ] gap> D:=Target(f[1]); Sparse chain complex of length 3 in characteristic 0 . gap> List([0..3],D!.dimension); [ 3, 11, 26, 33 ] gap> List([0..3],n->Homology(D,n));time; [ [ 0 ], [ 25 ], [ 2, 2, 2, 2, 2 ], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ] 118
In version 1.80 of HAP the default functionality of ContractedComplex(X) has changed slightly. The functionality is unchanged if X is a regular CW-complex or a free ZG-resolution. The read.g file in HAP now has two master copies: readOriginal.g and readAIE.g. The functionality is unchanged if read.g equals the first of these. But if X is a chain complex and if read.g equals the second master copy, and this is the default setting, then the Claude AI generated lazy code discussed in the preceeding section is used to reduce the chain complex. However, for X a chain complex and r a positive integer or r=∞, the command ContractedComplex(X,r) runs the original eager code and only eliminates a pair (e^n,e^n-1) if the number of cells in the boundary d(e^n) counted with multiplicity is no greater than r.
generated by GAPDoc2HTML