Nested loop limit?
jdc at uwo.ca
Sun Jul 11 04:39:09 CEST 2004
Peter Hansen <peter at engcorp.com> writes:
> If you consider that statically nested for loops must in some
> way represent different dimensions, is it really possible that
> a problem can have more than 20 dimensions (or even nearly that
> many!) which must all be looped over simultaneously?
> But I'd be interested in any ("real world", as usual) example
> where it is true....
Well, in a computation in quantum gravity, I have the C code shown
below. It has exactly 20 nested for loops! There are of course
other ways to write it, but given the number of iterations, speed
is the bottom line. Unfortunately, this is only the simplest test
case of a larger problem...
I'm converting much of this project to python, but will probably
keep this part in C and wrap it with SWIG.
(I'm simultaneously embarrassed and proud of this code... :-)
#define l1(a) for(Label[a] = 0; Label[a] <= cutoff; Label[a]++)
#define l2(a,b,c,d) \
for(Label[a] = low3(Label[b],Label[c],Label[d]); \
Label[a] <= cutoff && Label[a] <= high3(Label[b],Label[c],Label[d]); \
sumF = 0.0;
sumFG = 0.0;
saveF = F();
sumF += saveF;
sumFG += saveF*obsv();
More information about the Python-list