Advertisement
Guest User

Untitled

a guest
Mar 26th, 2011
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. #include <omp.h>
  5.  
  6. int N;
  7. float * dataX;
  8. float * dataY;
  9.  
  10. void printVector (const float *p, const int N) {
  11.     for (int i=0; i<N; i++)
  12.     printf("%f\n",p[i]);
  13. }
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17.     if(argc <= 1)
  18.         printf("ERROR");
  19.     else
  20.     {
  21.         N = atoi(argv[1]);
  22.         dataX = (float*)malloc(N*sizeof(float));
  23.         dataY = (float*)malloc(N*sizeof(float));
  24.         // and fill with some arbitrary values
  25.        
  26.         for(int j=0;j<N;j++)
  27.         {
  28.           #pragma omp parallel for
  29.           for (int i=0; i<N; i++)
  30.           {
  31.               dataX[i] = 10;
  32.               dataY[i] = 20;
  33.           }
  34.  
  35.           #pragma omp parallel for
  36.           for (int i=0; i<N; i++)
  37.           {
  38.               dataY[i] = dataY[i] * dataX[i];
  39.           }
  40.         }
  41.         //printVector (dataY,N);
  42.  
  43.         free(dataX);
  44.         free(dataY);
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement