Accelerating for-loop
I have a loop like
n = 3
M = MatrixSpace(Integers(n),n)
L = []
for m in M:
if condition:
L += [m]
In the case $n=3$, there are $3^{3^2} = 19683$ such matrices in M
, which the computers nowadays can do within a few seconds, but if $n=4$, there are already $4^{4^2} ≈ 4.3\cdot10^9$ matrices in M
to check, but I expect only about 100 hits (i.e. such m
for which the condition is true). Is there a faster way to make this possible, for example by parallelization?
If you parallelize with, say, 10 processors, it will only gain you a speed increase by a factor of 10. That won't help much when n=5. Maybe you should instead try to restrict the set of matrices using the condition: use the condition to construct a much smaller set of matrices: maybe only the ones satisfying it, or maybe a larger set than that but much smaller than the full matrix space.
There is some documentation for parallel computing in Sage here: https://doc.sagemath.org/html/en/refe...
You are right in principle, and that would be the proper (elegant) mathematical way, but knowing the result in the case
n=4
is already sufficient for me in my specific mathematical question. That's why I would like to try it via brute force as fast as possible.