You can always just flatten the do loops by hand and do manual indexing.
something like (this is not tested - use at your own peril :) )
r=2 ! the working range is -r to r
do i = 0, (2*r+1)**N - 1
do j = 1, N
i(j) = modulo(i,(2*r+1)**j)-r
enddo
...
enddo
the inner do loop is quite expensive, but you can pull it apart and make
it much more efficient.
I use this sort of stuff all the time to work on arbitrary dimensional
arrays. You can get it very efficient, to the point where it is as fast
as the hard wired do-loops. Once I get to a terminal with ssh access, I
can forward some code.
Stu.
> Hello all,
>
> This is not specifically a Fortran query, but I hope an interesting one.
> Take the following loop nest:
>
> DO i1=-1,1
> DO i2=-1,1
> ....
> DO iN=-1,1
> ....
> END DO
> ....
> END DO
>
> where N is a small number, say 2, 3, 4, 5 or so. I want to find a way to
> write the above code *without* nested DO loops, for a generic N, so that
> I do not need to write special cases for each N.
>
> Any ideas on a simple way to do this?
> Thanks,
> Aleksandar
>
>
--
Dr Stuart Midgley
[log in to unmask]
|