#pragma block_loop

Description

Marks a block with a scope-unique identifier.

Syntax

Read syntax diagramSkip visual syntax diagram                                   .-,---------.
                                   V           |
>>-#--pragma--block_loop--(--n--,----name_list-+--)------------><

where:

n Is an integer expression the size of the iteration group.
name_list Is a unique identifier you can create using the #pragma loopid directive. If you do not specify name_list, blocking occurs on the first for loop or block_loop following the #pragma block_loop directive.

name is an identifier that is unique within the scoping unit.

Notes

For loop blocking to occur, a #pragma block_loop directive must precede a for loop.

If you specify unroll, unroll_and_fuse or stream_unroll directive for a blocking loop, the blocking loop is unrolled, unrolled and fused or steam unrolled respectively, if the blocking loop is actually created. Otherwise, this directive has no effect.

If you specify unroll_and_fuse or stream_unroll directive for a blocked loop, the directive is applied to the blocked loop after the blocking loop is created. If the blocking loop is not created, this directive is applied to the loop intended for blocking, as if the corresponding block_loop directive was not specified.

You must not specify #pragma block_loop more than once, or combine the directive with the nounroll, unroll, nounrollandfuse, unrollandfuse, or stream_unroll pragma directives for the same for loop. Also, You should not apply more than one unroll directive to a single block loop directive.

Processing of all block_loop directives is always completed before performing any unrolling indicated by any of the unroll directives

Examples of accurate use of the directive

Example 1 - Loop tiling

#pragma block_loop(50, mymainloop)
#pragma block_loop(20, myfirstloop, mysecondloop)
#pragma loopid(mymainloop)
  for (i=0; i < n; i++)
  {
#pragma loopid(myfirstloop)
    for (j=0; j < m; j++)
    {
#pragma loopid(mysecondloop)
      for (k=0; k < m; k++)
      {
         ...
      }
    }
  }

 

Example 2 - Loop tiling

#pragma block_loop(50, mymainloop)
#pragma block_loop(20, myfirstloop, mysecondloop)
#pragma loopid(mymainloop)
	for (i=0; i < n; n++)
	{
#pragma loopid(myfirdstloop)
		for (j=0; j < m; j++)
		{
#pragma loopid(mysecondloop)
			for (k=0; k < m; k++)
			{
				...
			}
		}
	}

Example 3 - Loop interchange

	for (i=0; i < n; i++)
	{
		for (j=0; j < n; j++)
		{
#pragma block_loop(1,myloop1)
			for (k=0; k < m; k++)
			{
#pragma loopid(myloop1)
				for (l=0; l < m; l++)
				{
					...
				}
			}
		}
	}

Example 4 - Loop tiling for multi-level memory hierarchy

 #pragma block_loop(l3factor, first_level_blocking)
   for (i=0; i < n; i++)
   {
 #pragma loopid(first_level_blocking)
 #pragma block_loop(l2factor, inner_space)
     for (j=0; j < n; j++)
     {
 #pragma loopid(inner_space)
       for (k=0; k < m; k++)
       {
         for (l=0; l < m; l++)
         {
           ...
         }
       }
     }
   }

Example 5 - Unroll-and-fuse of a blocking loop

#pragma unrollandfuse
#pragma block_loop(10)
   for (i = 0; i < N; ++i) {
   }
In this case, if the block loop directive is ignored, the unroll directives have no effect.

Example 6 -Unroll of a blocked loop

 #pragma block_loop(10)
 #pragma unroll(2)
   for (i = 0; i < N; ++i) {
   }
In this case, if the block loop directive is ignored, the unblocked loop is still subjected to unrolling. If blocking does happen, and after happens, the unroll directive is applied to the blocked loop.

Examples of inaccurate use of the directive

Example 1- Block_loop of an undefined loop identifier

 #pragma block_loop(50, myloop)
   for (i=0; i < n; i++)
   {
   }

Referencing myloop is not allowed, since it is not in the nest 
and may not be defined.

Example 2- Block_loop of a loop identifer not within the same loop nest

   for (i=0; i < n; i++)
   {
 #pragma loopid(myLoop)
     for (j=0; j < i; j++)
     {
       ...
     }
   }
 #pragma block_loop(myLoop)
   for (i=0; i < n; i++)
   {
     ...
   }

 Referencing myloop is not allowed, since it is defined in a different 
loop nest (nesting structure).

Example 3- Conflicting unroll directives specified for a blocking loop

 #pragma unrollandfuse(5)
 #pragma unroll(2)
   #pragma block_loop(10)
		for (i = 0; i < N; ++i) {
   	}

This is not allowed since the unroll directives are conflicting 
with each other.

Example 4- Conflicting unroll directives specified for a blocked loop

 #pragma block_loop(10)
 #pragma unroll(5)
 #pragma unroll(10)
   for (i = 0; i < N; ++i) {
   }

This is not allowed since there are two different unrolling factors 
specified for the same loop, and therefore the diretives are conflicting.

Related information