Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <upc_relaxed.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define TOTALSIZE 800
- //== declare the x, x_new, b arrays in the shared space with size of TOTALSIZE
- shared double x[TOTALSIZE];
- shared double x_new[TOTALSIZE];
- shared double b[TOTALSIZE];
- void init();
- int main(int argc, char **argv){
- int j;
- init();
- upc_barrier;
- //== add a for loop which goes through the elements in the x_new array
- for( j=0; j<(TOTALSIZE)-1; j++ ){
- //== insert an if statement to do the work sharing across the threads
- if(THREADS == MYTHREAD){
- x_new[j] = 0.5*( x[j-1] + x[j+1] + b[j] );
- }
- }
- if( MYTHREAD == 0 ){
- printf(" b | x | x_new\n");
- printf("=============================\n");
- for( j=0; j<TOTALSIZE; j++ )
- printf("%1.4f | %1.4f | %1.4f \n", b[j], x[j], x_new[j]);
- }
- return 0;
- }
- void init(){
- int i;
- if( MYTHREAD == 0 ){
- srand(time(NULL));
- for( i = 0; i<TOTALSIZE; i++ ){
- b[i] = (double)rand() / RAND_MAX;
- x[i] = (double)rand() / RAND_MAX;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement