Purpose
Specifying the collapse clause allows you to parallelize
multiple loops in a nest without introducing nested parallelism. This clause
is used with the for and parallel for pragmas.
Syntax

>>-COLLAPSE--(--n--)-------------------------------------------><
Rules
- Only one collapse clause is allowed on a worksharing for or parallel
for pragma.
- The specified number of loops must be present lexically. That is, none
of the loops can be in a called subroutine.
- The loops must form a rectangular iteration space and the bounds and stride
of each loop must be invariant over all the loops.
- If the loop indices are of different size, the index with the largest
size will be used for the collapsed loop.
- The loops must be perfectly nested; that is, there is no intervening code
nor any OpenMP pragma between the loops which are collapsed.
- The associated do-loops must be structured blocks. Their execution must
not be terminated by an break statement.
- If multiple loops are associated to the loop construct, only an iteration
of the innermost associated loop may be curtailed by a continue statement. If multiple loops
are associated to the loop construct, there must be no branches to any of
the loop termination statements except for the innermost associated loop.
- Ordered construct
- During execution of an iteration of a loop or a loop nest within a loop
region, the executing thread must not execute more than one ordered region
which binds to the same loop region. As a consequence, if multiple loops are
associated to the loop construct by a collapse clause, the ordered construct
has to be located inside all associated loops.
- Lastprivate clause
- When a lastprivate clause appears on the pragma that identifies a work-sharing
construct, the value of each new list item from the sequentially last iteration
of the associated loops, is assigned to the original list item even if a collapse
clause is associated with the loop
- Other SMP and performance pragmas
- stream_unroll,unroll,unrollandfuse,nounrollandfuse pragmas cannot be used for any of the loops
associated with the collapse clause loop nest.