/* L-29 MCS 572 Wed 29 March 2006: computing third powers with OpenMP
   This program computes the 3rd power of the first n numbers,
   used to illustrate the parallel for pragma.
   Compile with "cc_r -qsmp=omp -o pow3 pow3.c"
   and run, typing "pow3" at the command prompt. */

#include <stdio.h>

int main ( int argc, char *argv[] )
{
   int n,i,j;
   int *powers;

   printf("Give a number : "); scanf("%d",&n);

   powers = (int*) calloc(n,sizeof(int));

   #pragma omp parallel for   /* tell compiler to parallelize the for */
      for(i=0; i<n; i++)
      {
         powers[i] = i+2;
         for(j=0; j<2; j++) powers[i] *= (i+2);
      }
                              /* return to the sequential world */

   for(i=0; i<n; i++) printf("%d^%d = %d\n",i+2,3,powers[i]);

   return 0;
}
