Why there isn't a three foreach loop?

49 views
Skip to first unread message

Gabriel Alves Cunha

unread,
May 22, 2020, 1:44:34 PM5/22/20
to Intel SPMD Program Compiler Users
for (int i = 0; i <= isize; ++i)
        foreach (j = 0 ... jsize, k = 0 ... ksize)
            if (foo())
                 bar();

foreach (i = 0 ... isize, j = 0 ... jsize, k = 0 ... ksize)
if (foo())
                bar();

Dmitry Babokin

unread,
May 22, 2020, 2:40:42 PM5/22/20
to ispc-...@googlegroups.com
We have it, for example here: https://github.com/ispc/ispc/blob/master/examples/aobench/ao.ispc#L216

Note, that tiled version is not much different. If you remove "_tiled" it will work as well.

If you are asking why writing the former version, not the later, it yields different code sequence. This way you guarantee that outer loops has uniform control flow and it's really outer loop. With foreach you cannot guarantee that. Though I think on practice the code should be the same.

Dmitry.

--
You received this message because you are subscribed to the Google Groups "Intel SPMD Program Compiler Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ispc-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ispc-users/b7ebaacf-4a01-4823-b08f-ab9e01d9017b%40googlegroups.com.

Gabriel Alves Cunha

unread,
May 22, 2020, 11:28:59 PM5/22/20
to Intel SPMD Program Compiler Users
Oh, goody. Thanks!!! I went back to the documentation and I see now that I've misread it...


Em sexta-feira, 22 de maio de 2020 15:40:42 UTC-3, Dmitry Babokin escreveu:
We have it, for example here: https://github.com/ispc/ispc/blob/master/examples/aobench/ao.ispc#L216

Note, that tiled version is not much different. If you remove "_tiled" it will work as well.

If you are asking why writing the former version, not the later, it yields different code sequence. This way you guarantee that outer loops has uniform control flow and it's really outer loop. With foreach you cannot guarantee that. Though I think on practice the code should be the same.

Dmitry.

On Fri, May 22, 2020 at 10:44 AM Gabriel Alves Cunha <gabrie...@gmail.com> wrote:
for (int i = 0; i <= isize; ++i)
        foreach (j = 0 ... jsize, k = 0 ... ksize)
            if (foo())
                 bar();

foreach (i = 0 ... isize, j = 0 ... jsize, k = 0 ... ksize)
if (foo())
                bar();

--
You received this message because you are subscribed to the Google Groups "Intel SPMD Program Compiler Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ispc-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages