Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between perfectly nested loop and imperfectly nested loop?

In the context of parallel processing, what exactly does it mean to say that a loop is "perfectly" or "imperfectly" nested?

like image 527
Younes Nj Avatar asked Sep 03 '25 04:09

Younes Nj


1 Answers

See this: openmp g++ error: collapsed loops not perfectly nested.

A perfectly nested loop is one wherein all content is in the innermost loop. For instance,

foreach(var a in vals1)
{
    foreach (var b in vals2)
    {
        Console.WriteLine(a + b);
    }
}

As compared to an imperfectly nested one,

foreach(var a in vals1)
{
    Console.WriteLine("values for " + a);

    foreach (var b in vals2)
    {
        Console.WriteLine(a + b);
    }
}

Of course, I'm a C# guy and this is C# where nobody I know of uses such terms and it doesn't matter at all, but you see the point. Just consider this pseudo-code that compiles under the right circumstances.

like image 140
Matthew Haugen Avatar answered Sep 04 '25 23:09

Matthew Haugen