Question
//thead.cc #include #include #include #include /* number of threads */ #define NUM_THREADS 8 /* value to size the arrays */ #define MAXNUM 80 /* define
//thead.cc #include #include #include #include /* number of threads */ #define NUM_THREADS 8 /* value to size the arrays */ #define MAXNUM 80 /* define the two arrays */ /* an array shared among threads */ int in[MAXNUM]; /* the internal array for merging */ int out[MAXNUM]; /* define a structure so that we can provide 2 values indicating the starting position * and the ending position of each portion of the array allocated to each thread */ struct input{ int beg, end; }; /* subroutine which takes locations and merges the results into "out[]" and then places the result into "in[]". Note that this routine uses two global vectors and this routine assumes that it can work with both of them */ void merge(int loc1,int loc2,int loc3,int loc4) { /* variable i is used to index in the first half variable j is used to index the second half variable inser is used to keep trak in the out[] vector in inserts */ int i,j,k,insert; insert=loc1; i=loc1; j=loc3; /* merge the two sublists -- we assume the lists are contiguous */ while ( (i <= loc2) && ( j <= loc4)) { if ( in[i] > in[j]) out[insert++]=in[j++]; else out[insert++]=in[i++]; } /* take care of any of the remainder in first segment */ for(k=i;k<=loc2;k++) out[insert++]=in[k]; /* take care of any of the remainder in second segment */ for(k=j;k<=loc4;k++) out[insert++]=in[k]; /* transfer the merged data back to the original vector */ for(i=loc1;i<=loc4;i++) in[i]=out[i]; } /* recursive calls to sort: break the vector up into single units. subroutine merge is then used to place the results back together */ void sort(int loc1, int loc2) { int mid; //printf("\t%d\t%d\t%d ", getpid(), loc1, loc2); /* base case */ if (loc1 >=loc2) return; /* recursive call, calculate mid point, and bisect the segment */ else { mid=((loc1 + loc2)/2); sort(loc1,mid); sort(mid+1,loc2); merge(loc1,mid,mid+1,loc2); } } /* helper subroutine to print out the results of the in[] vector, one line at a time */ void printar(int NUM) { int i; for(i=0;i
Help create 12 workloads. The workloads will be random integers (not including 0). The workloads will be sized 2,4,8,16,32,64,128,256,512,1024,2048,4096.
You will run your programs from shared.cc with each one of the 12 workloads to collect the data representing the amount of time (user time, system time, and total time) that each program takes to perform its task. To do that, you should use the UNIX facility called "time". An example of its usage:
time a.out Then help create a graph. The graph's x coordinate will be labeled "Workload Size". The y coordinate will be "Time (seconds)". For each graph, you will plot 3 lines. Amount of time taken for user time, amount of time taken for system, and total time (the summation of user and system time). You may use MS Excel.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started