12.07.2015 Views

PGI User's Guide

PGI User's Guide

PGI User's Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Auto-Parallelization using -MconcurScalar Last ValuesDuring parallelization, scalars within loops often need to be privatized; that is, each execution thread has itsown independent copy of the scalar. Problems can arise if a privatized scalar is accessed outside the loop. Forexample, consider the following loop:38for (i = 1; i 5.0 ) t = x[i];}v = t;The value of t may not be computed on the last iteration of the loop. Normally, if a scalar is assigned withina loop and used following the loop, the <strong>PGI</strong> compilers save the last value of the scalar. However, if the loopis parallelized and the scalar is not assigned on every iteration, it may be difficult, without resorting to costlycritical sections, to determine on what iteration t is last assigned. Analysis allows the compiler to determinethat a scalar is assigned on each iteration and hence that the loop is safe to parallelize if the scalar is used later,as illustrated in the following example.for ( i = 1; i < n; i++) {if ( x[i] > 0.0 ) {t = 2.0;}else {t = 3.0;y[i] = ...t;}}v = t;where t is assigned on every iteration of the loop. However, there are cases where a scalar may be privatizable,but if it is used after the loop, it is unsafe to parallelize. Examine the following loop in which each use of twithin the loop is reached by a definition from the same iteration.for ( i = 1; i < N; i++ ){if( x[i] > 0.0 ){t = x[i];......y[i] = ...t;}}v = t;Here t is privatizable, but the use of t outside the loop may yield incorrect results, since the compiler maynot be able to detect on which iteration of the parallelized loop t is last assigned. The compiler detectsthe previous cases. When a scalar is used after the loop but is not defined on every iteration of the loop,parallelization does not occur.When the programmer knows that the scalar is assigned on the last iteration of the loop, the programmermay use a directive or pragma to let the compiler know the loop is safe to parallelize. The Fortran directivesafe_lastval informs the compiler that, for a given loop, all scalars are assigned in the last iteration of theloop; thus, it is safe to parallelize the loop. We could add the following line to any of our previous examples.cpgi$l safe_lastval

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!