SHARE
TWEET

Untitled

a guest Jun 15th, 2013 258 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <upc_relaxed.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. #define TOTALSIZE   800
  7.  
  8. //== declare the x, x_new, b arrays in the shared space with size of TOTALSIZE
  9. shared double x[TOTALSIZE];
  10. shared double x_new[TOTALSIZE];
  11. shared double b[TOTALSIZE];
  12.  
  13. void init();
  14.  
  15. int main(int argc, char **argv){
  16.      int j;
  17.  
  18.      init();
  19.      upc_barrier;
  20.  
  21.      //== add a for loop which goes through the elements in the x_new array
  22.      for( j=0; j<(TOTALSIZE)-1; j++ ){
  23.          //== insert an if statement to do the work sharing across the threads
  24.          if(THREADS == MYTHREAD){
  25.              x_new[j] = 0.5*( x[j-1] + x[j+1] + b[j] );
  26.          }
  27.      }
  28.  
  29.      if( MYTHREAD == 0 ){
  30.          printf("   b   |    x   | x_new\n");
  31.          printf("=============================\n");
  32.  
  33.          for( j=0; j<TOTALSIZE; j++ )
  34.              printf("%1.4f | %1.4f | %1.4f \n", b[j], x[j], x_new[j]);
  35.      }
  36.  
  37.      return 0;
  38.  }
  39.  
  40.  void init(){
  41.      int i;
  42.  
  43.      if( MYTHREAD == 0 ){
  44.          srand(time(NULL));
  45.  
  46.          for( i = 0; i<TOTALSIZE; i++ ){
  47.              b[i] = (double)rand() / RAND_MAX;
  48.              x[i] = (double)rand() / RAND_MAX;
  49.          }
  50.      }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top